@subwallet/extension-base 1.1.24-4 → 1.1.25-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -394,7 +394,15 @@ async function subscribeRelayChainPoolMemberMetadata(chainInfo, address, substra
394
394
  const currentEra = _currentEra.toString();
395
395
  const nominations = _nominations.toJSON();
396
396
  let stakingStatus = _KoniTypes.StakingStatus.NOT_EARNING;
397
- const poolName = (0, _utils.transformPoolName)(poolMetadata.isUtf8 ? poolMetadata.toUtf8() : poolMetadata.toString());
397
+ const getPoolName = () => {
398
+ if (poolMetadata.isUtf8) {
399
+ return poolMetadata.toUtf8();
400
+ } else {
401
+ const str = poolMetadata.toString();
402
+ return (0, _util.isHex)(str) ? (0, _util.hexToString)(str) : str;
403
+ }
404
+ };
405
+ const poolName = getPoolName();
398
406
  if (nominations) {
399
407
  const validatorList = nominations.targets;
400
408
  await Promise.all(validatorList.map(async validatorAddress => {
@@ -449,6 +457,10 @@ async function subscribeRelayChainPoolMemberMetadata(chainInfo, address, substra
449
457
  unstakings
450
458
  };
451
459
  }
460
+
461
+ /**
462
+ * Deprecated
463
+ * */
452
464
  async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi) {
453
465
  const chainApi = await substrateApi.isReady;
454
466
  const [_poolMemberInfo, _currentEra] = await Promise.all([chainApi.api.query.nominationPools.poolMembers(address), chainApi.api.query.staking.currentEra()]);
@@ -472,7 +484,15 @@ async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi)
472
484
  let stakingStatus = _KoniTypes.StakingStatus.NOT_EARNING;
473
485
  const _poolMetadata = await chainApi.api.query.nominationPools.metadata(poolMemberInfo.poolId);
474
486
  const poolMetadata = _poolMetadata.toPrimitive();
475
- const poolName = (0, _utils.transformPoolName)(poolMetadata.isUtf8 ? poolMetadata.toUtf8() : poolMetadata.toString());
487
+ const getPoolName = () => {
488
+ if (poolMetadata.isUtf8) {
489
+ return poolMetadata.toUtf8();
490
+ } else {
491
+ const str = poolMetadata.toString();
492
+ return (0, _util.isHex)(str) ? (0, _util.hexToString)(str) : str;
493
+ }
494
+ };
495
+ const poolName = getPoolName();
476
496
  const poolStashAccount = (0, _utils.parsePoolStashAddress)(chainApi.api, 0, poolMemberInfo.poolId, poolsPalletId);
477
497
  const _nominations = await chainApi.api.query.staking.nominators(poolStashAccount);
478
498
  const nominations = _nominations.toJSON();
@@ -105,8 +105,8 @@ async function parseIdentity(substrateApi, address, children) {
105
105
  const riot = (_identityInfo$info3 = identityInfo.info) === null || _identityInfo$info3 === void 0 ? void 0 : (_identityInfo$info3$r = _identityInfo$info3.riot) === null || _identityInfo$info3$r === void 0 ? void 0 : _identityInfo$info3$r.Raw;
106
106
  const twitter = (_identityInfo$info4 = identityInfo.info) === null || _identityInfo$info4 === void 0 ? void 0 : (_identityInfo$info4$t = _identityInfo$info4.twitter) === null || _identityInfo$info4$t === void 0 ? void 0 : _identityInfo$info4$t.Raw;
107
107
  const isReasonable = identityInfo.judgements.length > 0;
108
- if (displayName && !displayName.startsWith('0x')) {
109
- identity = displayName;
108
+ if (displayName) {
109
+ identity = (0, _util.isHex)(displayName) ? (0, _util.hexToString)(displayName) : displayName;
110
110
  } else {
111
111
  identity = twitter || web || riot;
112
112
  }
@@ -327,17 +327,22 @@ class KoniTabs {
327
327
  }
328
328
  }
329
329
  async getEvmCurrentAccount(url) {
330
- let getAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
331
330
  return await new Promise(resolve => {
332
331
  this.getAuthInfo(url).then(authInfo => {
333
332
  const allAccounts = this.#koniState.keyringService.accounts;
334
333
  const accountList = transformAccountsV2(allAccounts, false, authInfo, 'evm').map(a => a.address);
335
334
  let accounts = [];
336
335
  const address = this.#koniState.keyringService.currentAccount.address;
337
- if (address === _constants.ALL_ACCOUNT_KEY || !accountList.includes(address) || getAll) {
336
+ if (address === _constants.ALL_ACCOUNT_KEY || !address) {
338
337
  accounts = accountList;
339
- } else if (address && accountList.includes(address)) {
340
- accounts = [address];
338
+ } else {
339
+ if (accountList.includes(address)) {
340
+ const result = accountList.filter(adr => adr !== address);
341
+ result.unshift(address);
342
+ accounts = result;
343
+ } else {
344
+ accounts = accountList;
345
+ }
341
346
  }
342
347
  resolve(accounts);
343
348
  }).catch(console.error);
@@ -401,7 +406,7 @@ class KoniTabs {
401
406
  }
402
407
  }
403
408
  async getEvmPermission(url, id) {
404
- const accounts = await this.getEvmCurrentAccount(url, true);
409
+ const accounts = await this.getEvmCurrentAccount(url);
405
410
  return [{
406
411
  id: id,
407
412
  invoker: url,
@@ -784,7 +789,7 @@ class KoniTabs {
784
789
  });
785
790
  }
786
791
  async canUseAccount(address, url) {
787
- const allowedAccounts = await this.getEvmCurrentAccount(url, true);
792
+ const allowedAccounts = await this.getEvmCurrentAccount(url);
788
793
  return !!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase());
789
794
  }
790
795
  async evmSign(id, url, _ref20) {
@@ -792,7 +797,7 @@ class KoniTabs {
792
797
  method,
793
798
  params
794
799
  } = _ref20;
795
- const allowedAccounts = await this.getEvmCurrentAccount(url, true);
800
+ const allowedAccounts = await this.getEvmCurrentAccount(url);
796
801
  const signResult = await this.#koniState.evmSign(id, url, method, params, allowedAccounts);
797
802
  if (signResult) {
798
803
  return signResult;
@@ -814,7 +819,7 @@ class KoniTabs {
814
819
  if (!networkKey) {
815
820
  throw new Error('Network unavailable. Please switch network or manually add network to wallet');
816
821
  }
817
- const allowedAccounts = await this.getEvmCurrentAccount(url, true);
822
+ const allowedAccounts = await this.getEvmCurrentAccount(url);
818
823
  const transactionHash = await this.#koniState.evmSendTransaction(id, url, networkKey, allowedAccounts, transactionParams);
819
824
  if (!transactionHash) {
820
825
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.USER_REJECTED_REQUEST);
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.1.24-4'
16
+ version: '1.1.25-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -1,20 +1,49 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
7
+ exports.getAccountJsonByAddress = void 0;
6
8
  exports.subscribeBalance = subscribeBalance;
7
9
  var _types = require("@subwallet/chain-list/types");
8
10
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
11
  var _handlers = require("@subwallet/extension-base/koni/background/handlers");
10
12
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
11
13
  var _utils2 = require("@subwallet/extension-base/utils");
12
- var _account = require("@subwallet/extension-base/utils/account");
14
+ var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
13
15
  var _evm = require("./evm");
14
16
  var _substrate = require("./substrate");
15
17
  // Copyright 2019-2022 @subwallet/extension-base
16
18
  // SPDX-License-Identifier: Apache-2.0
17
19
 
20
+ /**
21
+ * @function getAccountJsonByAddress
22
+ * @desc Get account info by address
23
+ * <p>
24
+ * Note: Use on the background only
25
+ * </p>
26
+ * @param {string} address - Address
27
+ * @returns {AccountJson|null} - Account info or null if not found
28
+ */
29
+ const getAccountJsonByAddress = address => {
30
+ try {
31
+ const pair = _uiKeyring.default.getPair(address);
32
+ if (pair) {
33
+ return {
34
+ address: pair.address,
35
+ type: pair.type,
36
+ ...pair.meta
37
+ };
38
+ } else {
39
+ return null;
40
+ }
41
+ } catch (e) {
42
+ console.warn(e);
43
+ return null;
44
+ }
45
+ };
46
+ exports.getAccountJsonByAddress = getAccountJsonByAddress;
18
47
  const filterAddress = (addresses, chainInfo) => {
19
48
  const isEvmChain = (0, _utils._isChainEvmCompatible)(chainInfo);
20
49
  const [substrateAddresses, evmAddresses] = (0, _utils2.categoryAddresses)(addresses);
@@ -24,7 +53,7 @@ const filterAddress = (addresses, chainInfo) => {
24
53
  const fetchList = [];
25
54
  const unfetchList = [];
26
55
  substrateAddresses.forEach(address => {
27
- const account = (0, _account.getAccountJsonByAddress)(address);
56
+ const account = getAccountJsonByAddress(address);
28
57
  if (account) {
29
58
  if (account.isHardware) {
30
59
  const availGen = account.availableGenesisHashes || [];
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports.getAccountJsonByAddress = exports.convertSubjectInfoToAddresses = void 0;
6
+ exports.convertSubjectInfoToAddresses = void 0;
8
7
  exports.quickFormatAddressToCompare = quickFormatAddressToCompare;
9
8
  exports.simpleAddress = void 0;
10
9
  var _index = require("@subwallet/extension-base/utils/index");
11
- var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
12
10
  var _utilCrypto = require("@polkadot/util-crypto");
13
11
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
14
12
  // SPDX-License-Identifier: Apache-2.0
@@ -33,32 +31,4 @@ const convertSubjectInfoToAddresses = subjectInfo => {
33
31
  ...info.json.meta
34
32
  }));
35
33
  };
36
-
37
- /**
38
- * @function getAccountJsonByAddress
39
- * @desc Get account info by address
40
- * <p>
41
- * Note: Use on the background only
42
- * </p>
43
- * @param {string} address - Address
44
- * @returns {AccountJson|null} - Account info or null if not found
45
- */
46
- exports.convertSubjectInfoToAddresses = convertSubjectInfoToAddresses;
47
- const getAccountJsonByAddress = address => {
48
- try {
49
- const pair = _uiKeyring.default.getPair(address);
50
- if (pair) {
51
- return {
52
- address: pair.address,
53
- type: pair.type,
54
- ...pair.meta
55
- };
56
- } else {
57
- return null;
58
- }
59
- } catch (e) {
60
- console.warn(e);
61
- return null;
62
- }
63
- };
64
- exports.getAccountJsonByAddress = getAccountJsonByAddress;
34
+ exports.convertSubjectInfoToAddresses = convertSubjectInfoToAddresses;
@@ -31,6 +31,9 @@ export declare function subscribeRelayChainNominatorMetadata(chainInfo: _ChainIn
31
31
  * */
32
32
  export declare function getRelayChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
33
33
  export declare function subscribeRelayChainPoolMemberMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, poolMemberInfo: PalletNominationPoolsPoolMember): Promise<NominatorMetadata>;
34
+ /**
35
+ * Deprecated
36
+ * */
34
37
  export declare function getRelayChainPoolMemberMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
35
38
  export declare function getRelayValidatorsInfo(chain: string, substrateApi: _SubstrateApi, decimals: number, chainStakingMetadata: ChainStakingMetadata): Promise<ValidatorInfo[]>;
36
39
  export declare function getRelayPoolsInfo(chain: string, substrateApi: _SubstrateApi): Promise<NominationPoolInfo[]>;
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
5
5
  import { StakingStatus, StakingTxErrorType, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
6
- import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getCommission, getExistUnstakeErrorMessage, getMaxValidatorErrorMessage, getMinStakeErrorMessage, parseIdentity, parsePoolStashAddress, transformPoolName } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
6
+ import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getCommission, getExistUnstakeErrorMessage, getMaxValidatorErrorMessage, getMinStakeErrorMessage, parseIdentity, parsePoolStashAddress } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
7
7
  import { _STAKING_CHAIN_GROUP, _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
8
8
  import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
9
9
  import { reformatAddress } from '@subwallet/extension-base/utils';
@@ -369,7 +369,15 @@ export async function subscribeRelayChainPoolMemberMetadata(chainInfo, address,
369
369
  const currentEra = _currentEra.toString();
370
370
  const nominations = _nominations.toJSON();
371
371
  let stakingStatus = StakingStatus.NOT_EARNING;
372
- const poolName = transformPoolName(poolMetadata.isUtf8 ? poolMetadata.toUtf8() : poolMetadata.toString());
372
+ const getPoolName = () => {
373
+ if (poolMetadata.isUtf8) {
374
+ return poolMetadata.toUtf8();
375
+ } else {
376
+ const str = poolMetadata.toString();
377
+ return isHex(str) ? hexToString(str) : str;
378
+ }
379
+ };
380
+ const poolName = getPoolName();
373
381
  if (nominations) {
374
382
  const validatorList = nominations.targets;
375
383
  await Promise.all(validatorList.map(async validatorAddress => {
@@ -423,6 +431,10 @@ export async function subscribeRelayChainPoolMemberMetadata(chainInfo, address,
423
431
  unstakings
424
432
  };
425
433
  }
434
+
435
+ /**
436
+ * Deprecated
437
+ * */
426
438
  export async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi) {
427
439
  const chainApi = await substrateApi.isReady;
428
440
  const [_poolMemberInfo, _currentEra] = await Promise.all([chainApi.api.query.nominationPools.poolMembers(address), chainApi.api.query.staking.currentEra()]);
@@ -446,7 +458,15 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
446
458
  let stakingStatus = StakingStatus.NOT_EARNING;
447
459
  const _poolMetadata = await chainApi.api.query.nominationPools.metadata(poolMemberInfo.poolId);
448
460
  const poolMetadata = _poolMetadata.toPrimitive();
449
- const poolName = transformPoolName(poolMetadata.isUtf8 ? poolMetadata.toUtf8() : poolMetadata.toString());
461
+ const getPoolName = () => {
462
+ if (poolMetadata.isUtf8) {
463
+ return poolMetadata.toUtf8();
464
+ } else {
465
+ const str = poolMetadata.toString();
466
+ return isHex(str) ? hexToString(str) : str;
467
+ }
468
+ };
469
+ const poolName = getPoolName();
450
470
  const poolStashAccount = parsePoolStashAddress(chainApi.api, 0, poolMemberInfo.poolId, poolsPalletId);
451
471
  const _nominations = await chainApi.api.query.staking.nominators(poolStashAccount);
452
472
  const nominations = _nominations.toJSON();
@@ -75,8 +75,8 @@ export async function parseIdentity(substrateApi, address, children) {
75
75
  const riot = (_identityInfo$info3 = identityInfo.info) === null || _identityInfo$info3 === void 0 ? void 0 : (_identityInfo$info3$r = _identityInfo$info3.riot) === null || _identityInfo$info3$r === void 0 ? void 0 : _identityInfo$info3$r.Raw;
76
76
  const twitter = (_identityInfo$info4 = identityInfo.info) === null || _identityInfo$info4 === void 0 ? void 0 : (_identityInfo$info4$t = _identityInfo$info4.twitter) === null || _identityInfo$info4$t === void 0 ? void 0 : _identityInfo$info4$t.Raw;
77
77
  const isReasonable = identityInfo.judgements.length > 0;
78
- if (displayName && !displayName.startsWith('0x')) {
79
- identity = displayName;
78
+ if (displayName) {
79
+ identity = isHex(displayName) ? hexToString(displayName) : displayName;
80
80
  } else {
81
81
  identity = twitter || web || riot;
82
82
  }
@@ -285,17 +285,23 @@ export default class KoniTabs {
285
285
  return this.#koniState.authorizeUrlV2(url, request);
286
286
  }
287
287
  }
288
- async getEvmCurrentAccount(url, getAll = false) {
288
+ async getEvmCurrentAccount(url) {
289
289
  return await new Promise(resolve => {
290
290
  this.getAuthInfo(url).then(authInfo => {
291
291
  const allAccounts = this.#koniState.keyringService.accounts;
292
292
  const accountList = transformAccountsV2(allAccounts, false, authInfo, 'evm').map(a => a.address);
293
293
  let accounts = [];
294
294
  const address = this.#koniState.keyringService.currentAccount.address;
295
- if (address === ALL_ACCOUNT_KEY || !accountList.includes(address) || getAll) {
295
+ if (address === ALL_ACCOUNT_KEY || !address) {
296
296
  accounts = accountList;
297
- } else if (address && accountList.includes(address)) {
298
- accounts = [address];
297
+ } else {
298
+ if (accountList.includes(address)) {
299
+ const result = accountList.filter(adr => adr !== address);
300
+ result.unshift(address);
301
+ accounts = result;
302
+ } else {
303
+ accounts = accountList;
304
+ }
299
305
  }
300
306
  resolve(accounts);
301
307
  }).catch(console.error);
@@ -359,7 +365,7 @@ export default class KoniTabs {
359
365
  }
360
366
  }
361
367
  async getEvmPermission(url, id) {
362
- const accounts = await this.getEvmCurrentAccount(url, true);
368
+ const accounts = await this.getEvmCurrentAccount(url);
363
369
  return [{
364
370
  id: id,
365
371
  invoker: url,
@@ -735,14 +741,14 @@ export default class KoniTabs {
735
741
  });
736
742
  }
737
743
  async canUseAccount(address, url) {
738
- const allowedAccounts = await this.getEvmCurrentAccount(url, true);
744
+ const allowedAccounts = await this.getEvmCurrentAccount(url);
739
745
  return !!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase());
740
746
  }
741
747
  async evmSign(id, url, {
742
748
  method,
743
749
  params
744
750
  }) {
745
- const allowedAccounts = await this.getEvmCurrentAccount(url, true);
751
+ const allowedAccounts = await this.getEvmCurrentAccount(url);
746
752
  const signResult = await this.#koniState.evmSign(id, url, method, params, allowedAccounts);
747
753
  if (signResult) {
748
754
  return signResult;
@@ -763,7 +769,7 @@ export default class KoniTabs {
763
769
  if (!networkKey) {
764
770
  throw new Error('Network unavailable. Please switch network or manually add network to wallet');
765
771
  }
766
- const allowedAccounts = await this.getEvmCurrentAccount(url, true);
772
+ const allowedAccounts = await this.getEvmCurrentAccount(url);
767
773
  const transactionHash = await this.#koniState.evmSendTransaction(id, url, networkKey, allowedAccounts, transactionParams);
768
774
  if (!transactionHash) {
769
775
  throw new EvmProviderError(EvmProviderErrorType.USER_REJECTED_REQUEST);
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.1.24-4",
20
+ "version": "1.1.25-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -1363,10 +1363,10 @@
1363
1363
  "@sora-substrate/type-definitions": "^1.17.7",
1364
1364
  "@substrate/connect": "^0.7.26",
1365
1365
  "@subwallet/chain-list": "0.2.28",
1366
- "@subwallet/extension-base": "^1.1.24-4",
1367
- "@subwallet/extension-chains": "^1.1.24-4",
1368
- "@subwallet/extension-dapp": "^1.1.24-4",
1369
- "@subwallet/extension-inject": "^1.1.24-4",
1366
+ "@subwallet/extension-base": "^1.1.25-0",
1367
+ "@subwallet/extension-chains": "^1.1.25-0",
1368
+ "@subwallet/extension-dapp": "^1.1.25-0",
1369
+ "@subwallet/extension-inject": "^1.1.25-0",
1370
1370
  "@subwallet/keyring": "^0.1.1",
1371
1371
  "@subwallet/ui-keyring": "^0.1.1",
1372
1372
  "@walletconnect/sign-client": "^2.8.4",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.1.24-4'
10
+ version: '1.1.25-0'
11
11
  };
@@ -1,4 +1,15 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
+ import { AccountJson } from '@subwallet/extension-base/background/types';
2
3
  import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
3
4
  import { BalanceItem } from '@subwallet/extension-base/types';
5
+ /**
6
+ * @function getAccountJsonByAddress
7
+ * @desc Get account info by address
8
+ * <p>
9
+ * Note: Use on the background only
10
+ * </p>
11
+ * @param {string} address - Address
12
+ * @returns {AccountJson|null} - Account info or null if not found
13
+ */
14
+ export declare const getAccountJsonByAddress: (address: string) => AccountJson | null;
4
15
  export declare function subscribeBalance(addresses: string[], chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem[]) => void): () => void;
@@ -6,9 +6,36 @@ import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
6
6
  import { state } from '@subwallet/extension-base/koni/background/handlers';
7
7
  import { _getSubstrateGenesisHash, _isChainEvmCompatible, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
8
8
  import { categoryAddresses } from '@subwallet/extension-base/utils';
9
- import { getAccountJsonByAddress } from '@subwallet/extension-base/utils/account';
9
+ import keyring from '@subwallet/ui-keyring';
10
10
  import { subscribeEVMBalance } from "./evm.js";
11
11
  import { subscribeSubstrateBalance } from "./substrate/index.js";
12
+
13
+ /**
14
+ * @function getAccountJsonByAddress
15
+ * @desc Get account info by address
16
+ * <p>
17
+ * Note: Use on the background only
18
+ * </p>
19
+ * @param {string} address - Address
20
+ * @returns {AccountJson|null} - Account info or null if not found
21
+ */
22
+ export const getAccountJsonByAddress = address => {
23
+ try {
24
+ const pair = keyring.getPair(address);
25
+ if (pair) {
26
+ return {
27
+ address: pair.address,
28
+ type: pair.type,
29
+ ...pair.meta
30
+ };
31
+ } else {
32
+ return null;
33
+ }
34
+ } catch (e) {
35
+ console.warn(e);
36
+ return null;
37
+ }
38
+ };
12
39
  const filterAddress = (addresses, chainInfo) => {
13
40
  const isEvmChain = _isChainEvmCompatible(chainInfo);
14
41
  const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
@@ -1,15 +1,5 @@
1
- import { AccountJson, AddressJson } from '@subwallet/extension-base/background/types';
1
+ import { AddressJson } from '@subwallet/extension-base/background/types';
2
2
  import { SubjectInfo } from '@subwallet/ui-keyring/observable/types';
3
3
  export declare const simpleAddress: (address: string) => string;
4
4
  export declare function quickFormatAddressToCompare(address?: string): string | undefined;
5
5
  export declare const convertSubjectInfoToAddresses: (subjectInfo: SubjectInfo) => AddressJson[];
6
- /**
7
- * @function getAccountJsonByAddress
8
- * @desc Get account info by address
9
- * <p>
10
- * Note: Use on the background only
11
- * </p>
12
- * @param {string} address - Address
13
- * @returns {AccountJson|null} - Account info or null if not found
14
- */
15
- export declare const getAccountJsonByAddress: (address: string) => AccountJson | null;
package/utils/account.js CHANGED
@@ -2,7 +2,6 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { reformatAddress } from '@subwallet/extension-base/utils/index';
5
- import keyring from '@subwallet/ui-keyring';
6
5
  import { decodeAddress, encodeAddress, isAddress, isEthereumAddress } from '@polkadot/util-crypto';
7
6
  export const simpleAddress = address => {
8
7
  if (isEthereumAddress(address)) {
@@ -22,31 +21,4 @@ export const convertSubjectInfoToAddresses = subjectInfo => {
22
21
  type: info.type,
23
22
  ...info.json.meta
24
23
  }));
25
- };
26
-
27
- /**
28
- * @function getAccountJsonByAddress
29
- * @desc Get account info by address
30
- * <p>
31
- * Note: Use on the background only
32
- * </p>
33
- * @param {string} address - Address
34
- * @returns {AccountJson|null} - Account info or null if not found
35
- */
36
- export const getAccountJsonByAddress = address => {
37
- try {
38
- const pair = keyring.getPair(address);
39
- if (pair) {
40
- return {
41
- address: pair.address,
42
- type: pair.type,
43
- ...pair.meta
44
- };
45
- } else {
46
- return null;
47
- }
48
- } catch (e) {
49
- console.warn(e);
50
- return null;
51
- }
52
24
  };