Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions packages/extension-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"is-buffer": "^2.0.5",
"joi": "^17.13.3",
"json-rpc-engine": "^6.1.0",
"loglevel": "^1.8.1",
"manta-extension-sdk": "^1.1.0",
"moment": "^2.29.4",
"protobufjs": "^7.5.4",
Expand Down
8 changes: 6 additions & 2 deletions packages/extension-base/src/background/handlers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Copyright 2019-2022 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { createLogger } from '@subwallet/extension-base/utils/logger';

const backgroundHelpersLogger = createLogger('BackgroundHelpers');

export function withErrorLog (fn: () => unknown): void {
try {
const p = fn();

if (p && typeof p === 'object' && typeof (p as Promise<unknown>).catch === 'function') {
(p as Promise<unknown>).catch(console.error);
(p as Promise<unknown>).catch((e) => backgroundHelpersLogger.error('Error in withErrorLog promise', e));
}
} catch (e) {
console.error(e);
backgroundHelpersLogger.error('Error in withErrorLog', e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

import type { MessageTypesWithSubscriptions, SubscriptionMessageTypes } from '../types';

import { createLogger } from '@subwallet/extension-base/utils/logger';

type Subscriptions = Record<string, chrome.runtime.Port>;

const subscriptions: Subscriptions = {};
const subscriptionsLogger = createLogger('Subscriptions');

// return a subscription callback, that will send the data to the caller via the port
export function createSubscription<TMessageType extends MessageTypesWithSubscriptions> (id: string, port: chrome.runtime.Port): (data: SubscriptionMessageTypes[TMessageType]) => void {
Expand All @@ -27,6 +30,6 @@ export function unsubscribe (id: string): void {
if (subscriptions[id]) {
delete subscriptions[id];
} else {
console.error(`Unable to unsubscribe from ${id}`);
subscriptionsLogger.error(`Unable to unsubscribe from ${id}`);
}
}
6 changes: 5 additions & 1 deletion packages/extension-base/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ export const getSupportTokenPayFeeChain = () => {
return Object.values(_SUPPORT_TOKEN_PAY_FEE_GROUP).flat();
};

import { createLogger } from '@subwallet/extension-base/utils/logger';

const constantsLogger = createLogger('Constants');

export const isChainSupportTokenPayFee = (chainSlug: string): boolean => {
if (!chainSlug) {
console.error('You must provide chain slug!');
constantsLogger.error('You must provide chain slug!');

return false;
}
Expand Down
17 changes: 10 additions & 7 deletions packages/extension-base/src/core/logic-validation/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import { BN_ZERO, combineEthFee, createPromiseHandler, isSameAddress, reformatAd
import { validateAddressNetwork } from '@subwallet/extension-base/utils/cardano';
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
import { getId } from '@subwallet/extension-base/utils/getId';
import { createLogger } from '@subwallet/extension-base/utils/logger';
import { isCardanoAddress, isCardanoBaseAddress, isCardanoRewardAddress, isSubstrateAddress } from '@subwallet/keyring';
import { KeyringPair } from '@subwallet/keyring/types';

const logicValidationLogger = createLogger('LogicValidation');
import { getBitcoinAddressInfo } from '@subwallet/keyring/utils';
import { isBitcoinAddress } from '@subwallet/keyring/utils/address/validate';
import { keyring } from '@subwallet/ui-keyring';
Expand Down Expand Up @@ -262,7 +265,7 @@ export async function validationConnectMiddleware (koni: KoniState, url: string,
const [message, name] = convertErrorMessage(message_);
const error = new EvmProviderError(EvmProviderErrorType.CHAIN_DISCONNECTED, message, undefined, name);

console.error(error);
logicValidationLogger.error('Validation error: chain disconnected', error);
errors.push(error);
};

Expand Down Expand Up @@ -356,7 +359,7 @@ export async function validationEvmDataTransactionMiddleware (koni: KoniState, u
const [message, name] = convertErrorMessage(message_);
const error = new TransactionError(BasicTxErrorType.INVALID_PARAMS, message, undefined, name);

console.error(error);
logicValidationLogger.error('Validation error: invalid params', error);
errors.push(error);
};

Expand Down Expand Up @@ -555,7 +558,7 @@ export async function validationEvmSignMessageMiddleware (koni: KoniState, url:
const [message, name] = convertErrorMessage(message_);
const error = new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, message, undefined, name);

console.error(error);
logicValidationLogger.error('Validation error: invalid params in evm signature', error);
errors.push(error);
};

Expand Down Expand Up @@ -614,7 +617,7 @@ export async function validationEvmSignMessageMiddleware (koni: KoniState, url:
throw new Error('Unsupported action');
}
} catch (e) {
console.error(e);
logicValidationLogger.error('Error in validationEvmSignMessageMiddleware', e);
handleError((e as Error).message);
}
} else {
Expand Down Expand Up @@ -760,7 +763,7 @@ export async function validationCardanoSignDataMiddleware (koni: KoniState, url:
const [message, name] = convertErrorMessage(message_);
const error = new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, message, undefined, name);

console.error(error);
logicValidationLogger.error('Validation error: invalid request in cardano signature', error);
errors.push(error);
};

Expand Down Expand Up @@ -823,7 +826,7 @@ export async function validationBitcoinConnectMiddleware (koni: KoniState, url:
const [message, name] = convertErrorMessage(message_);
const error = new TransactionError(BasicTxErrorType.INVALID_PARAMS, message, undefined, name);

console.error(error);
logicValidationLogger.error('Validation error: invalid params', error);
errors.push(error);
};

Expand Down Expand Up @@ -1074,7 +1077,7 @@ export async function validationBitcoinSendTransactionMiddleware (koni: KoniStat
const [message, name] = [t('bg.TRANSACTION.core.validation.request.enableChainOnExtension', { replace: { chain: chainInfo.name } }), t('bg.TRANSACTION.core.validation.request.networkNotEnabled')];
const error = new BitcoinProviderError(BitcoinProviderErrorType.INVALID_PARAMS, message, undefined, name);

console.error(error);
logicValidationLogger.error('Validation error: network not enabled for bitcoin transaction', error);
errors.push(error);
} else {
handleError(message);
Expand Down
6 changes: 5 additions & 1 deletion packages/extension-base/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { getBitcoinAddressInfo, validateBitcoinAddress } from '@subwallet/keyrin
import { AnyJson } from '@polkadot/types/types';
import { isEthereumAddress } from '@polkadot/util-crypto';

import { createLogger } from '@subwallet/extension-base/utils/logger';

const coreUtilsLogger = createLogger('CoreUtils');

export function getStrictMode (type: string, extrinsicType?: ExtrinsicType) {
if (type === BalanceAccountType.FrameSystemAccountInfo) {
return !extrinsicType || ![ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType);
Expand Down Expand Up @@ -235,7 +239,7 @@ export const _isSufficientToken = async (tokenInfo: _ChainAsset, substrateApi: _
}
}
} catch (e) {
console.error(e);
coreUtilsLogger.error('Error in core utils', e);
}
}

Expand Down
11 changes: 7 additions & 4 deletions packages/extension-base/src/koni/api/coingecko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

import { CurrencyJson, CurrencyType, ExchangeRateJSON, PriceJson } from '@subwallet/extension-base/background/KoniTypes';
import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';
import { createLogger } from '@subwallet/extension-base/utils/logger';
import axios, { AxiosResponse } from 'axios';

const coingeckoLogger = createLogger('Coingecko');

interface GeckoItem {
id: string,
name: string,
Expand Down Expand Up @@ -46,7 +49,7 @@ export const getTokenPrice = async (priceIds: Set<string>, currencyCode: Currenc
}

if (rs?.status !== 200) {
console.warn('Failed to get token price');
coingeckoLogger.warn('Failed to get token price');
}

return rs;
Expand All @@ -58,11 +61,11 @@ export const getTokenPrice = async (priceIds: Set<string>, currencyCode: Currenc
try {
rs = await axios.get('https://api-cache.subwallet.app/exchange-rate');
} catch (e) {
console.warn('Failed to get exchange rate');
coingeckoLogger.warn('Failed to get exchange rate', e);
}

if (rs?.status !== 200) {
console.warn('Failed to get exchange rate');
coingeckoLogger.warn('Failed to get exchange rate - invalid status');
}

return rs;
Expand Down Expand Up @@ -109,7 +112,7 @@ export const getTokenPrice = async (priceIds: Set<string>, currencyCode: Currenc
price24hMap
} as PriceJson;
} catch (err) {
console.error(err);
coingeckoLogger.error('Error fetching price data', err);
throw err;
}
};
7 changes: 5 additions & 2 deletions packages/extension-base/src/koni/api/dotsama/crowdloan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import registry from '@subwallet/extension-base/koni/api/dotsama/typeRegistry';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { fetchJson, getAddressesByChainType, reformatAddress } from '@subwallet/extension-base/utils';
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
import { createLogger } from '@subwallet/extension-base/utils/logger';

import { DeriveOwnContributions } from '@polkadot/api-derive/types';

const crowdloanLogger = createLogger('Crowdloan');
import { BN } from '@polkadot/util';

const STATUS_MAP: Record<_FundStatus, CrowdloanParaState> = {
Expand Down Expand Up @@ -74,7 +77,7 @@ function getRPCCrowdloan (parentAPI: _SubstrateApi, fundInfo: _CrowdloanFund, he
.then((unsub) => {
unsub();
})
.catch(console.error);
.catch((e) => crowdloanLogger.error('Error unsubscribing from crowdloan', e));
};
}

Expand Down Expand Up @@ -109,7 +112,7 @@ export const subscribeAcalaContributeInterval = (polkadotAddresses: string[], fu
};

callback(rs);
}).catch(console.error);
}).catch((e) => crowdloanLogger.error('Error fetching Acala contribution info', e));
};

getContributeInfo();
Expand Down
8 changes: 6 additions & 2 deletions packages/extension-base/src/koni/api/dotsama/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { resolveAddressToDomain, resolveDomainToAddress, SupportedChainId } from

import { ApiPromise } from '@polkadot/api';

import { createLogger } from '@subwallet/extension-base/utils/logger';

const domainResolverLogger = createLogger('DomainResolver');

export const ENS_SUFFIX = '.eth';
export const TZERO_ID_SUFFIX = '.tzero';

Expand Down Expand Up @@ -42,7 +46,7 @@ export async function resolveAzeroDomainToAddress (domain: string, chain: string
);

if (primaryDomains.error) {
console.debug(primaryDomains.error);
domainResolverLogger.debug('Error resolving domain to address', primaryDomains.error);
}

return primaryDomains?.address || undefined;
Expand All @@ -64,7 +68,7 @@ export async function resolveAzeroAddressToDomain (address: string, chain: strin
);

if (primaryDomains.error) {
console.debug(primaryDomains.error);
domainResolverLogger.debug('Error resolving address to domain', primaryDomains.error);
}

return primaryDomains?.primaryDomain || undefined;
Expand Down
5 changes: 4 additions & 1 deletion packages/extension-base/src/koni/api/nft/acala_nft/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { getRandomIpfsGateway } from '@subwallet/extension-base/koni/api/nft/con
import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { isUrl } from '@subwallet/extension-base/utils';
import { createLogger } from '@subwallet/extension-base/utils/logger';

const acalaNftLogger = createLogger('AcalaNft');

interface AssetId {
classId: string | number,
Expand Down Expand Up @@ -157,7 +160,7 @@ export class AcalaNftApi extends BaseNftApi {
params.updateCollection(this.chain, parsedCollection);
}));
} catch (e) {
console.error(`${this.chain}`, e);
acalaNftLogger.error(`Error handling NFTs for chain ${this.chain}`, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { AssetHubNftType, NftCollection, NftItem } from '@subwallet/extension-ba
import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { isUrl } from '@subwallet/extension-base/utils';
import { createLogger } from '@subwallet/extension-base/utils/logger';

const assethubNftLogger = createLogger('AssethubNft');

interface AssetId {
classId: string | number,
Expand Down Expand Up @@ -199,7 +202,7 @@ export default class AssetHubNftsPalletApi extends BaseNftApi {
params.updateCollection(this.chain, parsedCollection);
}));
} catch (e) {
console.error(`${this.chain}`, e);
assethubNftLogger.error(`Error handling NFTs for chain ${this.chain}`, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { AssetHubNftType, NftCollection, NftItem } from '@subwallet/extension-ba
import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { isUrl } from '@subwallet/extension-base/utils';
import { createLogger } from '@subwallet/extension-base/utils/logger';

const assethubUniqueLogger = createLogger('AssethubUnique');

interface AssetId {
classId: string | number,
Expand Down Expand Up @@ -167,7 +170,7 @@ export default class AssetHubUniquesPalletApi extends BaseNftApi {
params.updateCollection(this.chain, parsedCollection);
}));
} catch (e) {
console.error(`${this.chain}`, e);
assethubUniqueLogger.error(`Error handling NFTs for chain ${this.chain}`, e);
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/extension-base/src/koni/api/nft/bit.country/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import { BIT_AVATAR_API, BIT_COUNTRY_IPFS_SERVER, BIT_COUNTRY_LAND_ESTATE_METADA
import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { isUrl } from '@subwallet/extension-base/utils';
import { createLogger } from '@subwallet/extension-base/utils/logger';

import { BN_ZERO, hexToBn } from '@polkadot/util';

const bitCountryNftLogger = createLogger('BitCountryNft');

interface AssetId {
classId: string | number,
tokenId: string | number,
Expand Down Expand Up @@ -126,7 +129,7 @@ export class BitCountryNftApi extends BaseNftApi {
try {
metaverseId = hexToBn(hexMetaverseId);
} catch (e) {
console.warn('Error parsing metaverse id', e);
bitCountryNftLogger.warn('Error parsing metaverse id', e);
}

return {
Expand Down Expand Up @@ -217,7 +220,7 @@ export class BitCountryNftApi extends BaseNftApi {
params.updateCollection(this.chain, parsedCollection);
}));
} catch (e) {
console.error(`${this.chain}`, e);
bitCountryNftLogger.error(`Error handling NFTs for chain ${this.chain}`, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import { COLLECT_ID } from '@subwallet/extension-base/koni/api/nft/blobinscripti
import { ALC, getNftDetail, NftResponse, RemarkData, transferPayload } from '@subwallet/extension-base/koni/api/nft/blobinscription/types';
import { AVAIL_LIGHT_CLIENT_NFT } from '@subwallet/extension-base/koni/api/nft/config';
import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
import { createLogger } from '@subwallet/extension-base/utils/logger';

import { hexToString } from '@polkadot/util';

const blobInscriptionLogger = createLogger('BlobInscription');

export class BlobInscriptionApi extends BaseNftApi {
endpoint = AVAIL_LIGHT_CLIENT_NFT;

Expand Down Expand Up @@ -162,7 +165,7 @@ export class BlobInscriptionApi extends BaseNftApi {
}
}));
} catch (error) {
console.error('Failed to fetch blob inscription', error);
blobInscriptionLogger.error('Failed to fetch blob inscription', error);
}
}

Expand Down
Loading