@subwallet/extension-base 1.1.24-3 → 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.
Files changed (42) hide show
  1. package/cjs/koni/api/staking/bonding/relayChain.js +22 -2
  2. package/cjs/koni/api/staking/bonding/utils.js +2 -2
  3. package/cjs/koni/background/handlers/Tabs.js +13 -8
  4. package/cjs/packageInfo.js +1 -1
  5. package/cjs/services/balance-service/helpers/subscribe/balance.js +31 -2
  6. package/cjs/services/chain-service/constants.js +1 -1
  7. package/cjs/services/chain-service/handler/EvmApi.js +6 -3
  8. package/cjs/services/migration-service/scripts/index.js +6 -4
  9. package/cjs/services/migration-service/scripts/{MigrateEthProvider.js → providers/MigrateEthProvider.js} +2 -2
  10. package/cjs/services/migration-service/scripts/providers/MigrateGeneralProvider.js +20 -0
  11. package/cjs/services/migration-service/scripts/providers/MigrateMultiProviders.js +21 -0
  12. package/cjs/services/migration-service/scripts/{MigrateProvider.js → providers/MigrateProvider.js} +1 -1
  13. package/cjs/services/migration-service/scripts/providers/MigrateProvidersV1M1P24.js +31 -0
  14. package/cjs/utils/account.js +2 -32
  15. package/koni/api/staking/bonding/relayChain.d.ts +3 -0
  16. package/koni/api/staking/bonding/relayChain.js +23 -3
  17. package/koni/api/staking/bonding/utils.js +2 -2
  18. package/koni/background/handlers/Tabs.js +14 -8
  19. package/package.json +36 -21
  20. package/packageInfo.js +1 -1
  21. package/services/balance-service/helpers/subscribe/balance.d.ts +11 -0
  22. package/services/balance-service/helpers/subscribe/balance.js +28 -1
  23. package/services/chain-service/constants.d.ts +1 -3
  24. package/services/chain-service/constants.js +1 -1
  25. package/services/chain-service/handler/EvmApi.d.ts +1 -0
  26. package/services/chain-service/handler/EvmApi.js +6 -3
  27. package/services/migration-service/scripts/index.js +6 -4
  28. package/services/migration-service/scripts/{MigrateEthProvider.js → providers/MigrateEthProvider.js} +2 -2
  29. package/services/migration-service/scripts/providers/MigrateGeneralProvider.d.ts +13 -0
  30. package/services/migration-service/scripts/providers/MigrateGeneralProvider.js +12 -0
  31. package/services/migration-service/scripts/providers/MigrateMultiProviders.d.ts +6 -0
  32. package/services/migration-service/scripts/providers/MigrateMultiProviders.js +13 -0
  33. package/services/migration-service/scripts/{MigrateProvider.js → providers/MigrateProvider.js} +1 -1
  34. package/services/migration-service/scripts/providers/MigrateProvidersV1M1P24.d.ts +5 -0
  35. package/services/migration-service/scripts/providers/MigrateProvidersV1M1P24.js +23 -0
  36. package/utils/account.d.ts +1 -11
  37. package/utils/account.js +0 -28
  38. package/cjs/services/migration-service/scripts/{MigratePioneerProvider.js → providers/MigratePioneerProvider.js} +0 -0
  39. package/services/migration-service/scripts/{MigrateEthProvider.d.ts → providers/MigrateEthProvider.d.ts} +2 -2
  40. /package/services/migration-service/scripts/{MigratePioneerProvider.d.ts → providers/MigratePioneerProvider.d.ts} +0 -0
  41. /package/services/migration-service/scripts/{MigratePioneerProvider.js → providers/MigratePioneerProvider.js} +0 -0
  42. /package/services/migration-service/scripts/{MigrateProvider.d.ts → providers/MigrateProvider.d.ts} +0 -0
@@ -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-3'
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 || [];
@@ -247,7 +247,7 @@ exports._XCM_TYPE = _XCM_TYPE;
247
247
  const _DEFAULT_ACTIVE_CHAINS = [..._chainList._DEFAULT_CHAINS, 'vara_network'];
248
248
  exports._DEFAULT_ACTIVE_CHAINS = _DEFAULT_ACTIVE_CHAINS;
249
249
  const EVM_PASS_CONNECT_STATUS = {
250
- acala: ['acala_evm', 'karura_evm']
250
+ arbitrum_one: ['*']
251
251
  };
252
252
  exports.EVM_PASS_CONNECT_STATUS = EVM_PASS_CONNECT_STATUS;
253
253
  const EVM_REFORMAT_DECIMALS = {
@@ -14,7 +14,6 @@ var _web = _interopRequireDefault(require("web3"));
14
14
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
15
15
  // SPDX-License-Identifier: Apache-2.0
16
16
 
17
- const acalaEvmNetworks = _constants.EVM_PASS_CONNECT_STATUS.acala;
18
17
  class EvmApi {
19
18
  apiRetry = 0;
20
19
  isApiConnectedSubject = new _rxjs.BehaviorSubject(false);
@@ -74,10 +73,14 @@ class EvmApi {
74
73
  this.intervalCheckApi = this.createIntervalCheckApi();
75
74
  this.connect();
76
75
  }
76
+ get ignoreNetListen() {
77
+ const ignoreRpc = _constants.EVM_PASS_CONNECT_STATUS[this.chainSlug];
78
+ return ignoreRpc ? ignoreRpc.includes('*') || ignoreRpc.includes(this.apiUrl) : false;
79
+ }
77
80
  createIntervalCheckApi() {
78
81
  this.clearIntervalCheckApi();
79
82
  return setInterval(() => {
80
- if (!acalaEvmNetworks.includes(this.chainSlug)) {
83
+ if (!this.ignoreNetListen) {
81
84
  this.api.eth.net.isListening().then(() => {
82
85
  this.onConnect();
83
86
  }).catch(() => {
@@ -98,7 +101,7 @@ class EvmApi {
98
101
  this.updateConnectionStatus(_types._ChainConnectionStatus.CONNECTING);
99
102
 
100
103
  // Check if api is ready
101
- if (!acalaEvmNetworks.includes(this.chainSlug)) {
104
+ if (!this.ignoreNetListen) {
102
105
  this.api.eth.net.isListening().then(() => {
103
106
  this.isApiReadyOnce = true;
104
107
  this.onConnect();
@@ -5,17 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.EVERYTIME = void 0;
8
- var _DeleteChain = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/DeleteChain"));
8
+ var _MigrateEthProvider = _interopRequireDefault(require("./providers/MigrateEthProvider"));
9
+ var _MigratePioneerProvider = _interopRequireDefault(require("./providers/MigratePioneerProvider"));
10
+ var _MigrateProvidersV1M1P = _interopRequireDefault(require("./providers/MigrateProvidersV1M1P24"));
9
11
  var _AutoEnableChainsTokens = _interopRequireDefault(require("./AutoEnableChainsTokens"));
12
+ var _DeleteChain = _interopRequireDefault(require("./DeleteChain"));
10
13
  var _EnableVaraChain = _interopRequireDefault(require("./EnableVaraChain"));
11
14
  var _MigrateAuthUrls = _interopRequireDefault(require("./MigrateAuthUrls"));
12
15
  var _MigrateAutoLock = _interopRequireDefault(require("./MigrateAutoLock"));
13
16
  var _MigrateChainPatrol = _interopRequireDefault(require("./MigrateChainPatrol"));
14
- var _MigrateEthProvider = _interopRequireDefault(require("./MigrateEthProvider"));
15
17
  var _MigrateImportedToken = _interopRequireDefault(require("./MigrateImportedToken"));
16
18
  var _MigrateLedgerAccount = _interopRequireDefault(require("./MigrateLedgerAccount"));
17
19
  var _MigrateNetworkSettings = _interopRequireDefault(require("./MigrateNetworkSettings"));
18
- var _MigratePioneerProvider = _interopRequireDefault(require("./MigratePioneerProvider"));
19
20
  var _MigrateSettings = _interopRequireDefault(require("./MigrateSettings"));
20
21
  var _MigrateTokenDecimals = _interopRequireDefault(require("./MigrateTokenDecimals"));
21
22
  var _MigrateTransactionHistory = _interopRequireDefault(require("./MigrateTransactionHistory"));
@@ -40,7 +41,8 @@ var _default = {
40
41
  '1.1.7': _DeleteChain.default,
41
42
  '1.1.13-01': _MigrateTokenDecimals.default,
42
43
  '1.1.17-01': _MigratePioneerProvider.default,
43
- '1.1.17-03': _EnableVaraChain.default
44
+ '1.1.17-03': _EnableVaraChain.default,
45
+ '1.1.24-01': _MigrateProvidersV1M1P.default
44
46
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
45
47
  };
46
48
  exports.default = _default;
@@ -10,8 +10,8 @@ var _MigrateProvider = _interopRequireDefault(require("./MigrateProvider"));
10
10
  // SPDX-License-Identifier: Apache-2.0
11
11
 
12
12
  class MigrateEthProvider extends _MigrateProvider.default {
13
- newProvider = 'ethereum';
13
+ slug = 'ethereum';
14
14
  oldProvider = 'Cloudflare';
15
- slug = 'Llamarpc';
15
+ newProvider = 'Llamarpc';
16
16
  }
17
17
  exports.default = MigrateEthProvider;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _MigrateProvider = _interopRequireDefault(require("./MigrateProvider"));
9
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
10
+ // SPDX-License-Identifier: Apache-2.0
11
+
12
+ class MigrateGeneralProvider extends _MigrateProvider.default {
13
+ constructor(state, target) {
14
+ super(state);
15
+ this.slug = target.slug;
16
+ this.oldProvider = target.oldProvider;
17
+ this.newProvider = target.newProvider;
18
+ }
19
+ }
20
+ exports.default = MigrateGeneralProvider;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
9
+ var _MigrateGeneralProvider = _interopRequireDefault(require("./MigrateGeneralProvider"));
10
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class MigrateMultiProviders extends _Base.default {
14
+ async run() {
15
+ for (const target of this.targets) {
16
+ const migration = new _MigrateGeneralProvider.default(this.state, target);
17
+ await migration.run();
18
+ }
19
+ }
20
+ }
21
+ exports.default = MigrateMultiProviders;
@@ -14,7 +14,7 @@ class MigrateProvider extends _Base.default {
14
14
  const state = this.state;
15
15
  const chainState = state.getChainStateByKey(this.slug);
16
16
  const chainInfo = state.getChainInfo(this.slug);
17
- if (chainState && chainState.active && chainState.currentProvider === this.oldProvider) {
17
+ if (chainState && chainState.active && chainInfo.providers[this.newProvider] && chainState.currentProvider === this.oldProvider) {
18
18
  await state.upsertChainInfo({
19
19
  mode: 'update',
20
20
  chainEditInfo: {
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _MigrateMultiProviders = _interopRequireDefault(require("./MigrateMultiProviders"));
9
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
10
+ // SPDX-License-Identifier: Apache-2.0
11
+
12
+ class MigrateProvidersV1M1P24 extends _MigrateMultiProviders.default {
13
+ targets = [{
14
+ slug: 'polkadot',
15
+ oldProvider: 'Parity',
16
+ newProvider: 'Dwellir'
17
+ }, {
18
+ slug: 'kusama',
19
+ oldProvider: 'Parity',
20
+ newProvider: 'Dwellir'
21
+ }, {
22
+ slug: 'moonbeam',
23
+ oldProvider: 'OnFinality',
24
+ newProvider: 'Moonbeam Foundation'
25
+ }, {
26
+ slug: 'moonbase',
27
+ oldProvider: 'OnFinality',
28
+ newProvider: 'Moonbeam Foundation'
29
+ }];
30
+ }
31
+ exports.default = MigrateProvidersV1M1P24;
@@ -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-3",
20
+ "version": "1.1.25-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -773,11 +773,6 @@
773
773
  "require": "./cjs/services/migration-service/scripts/MigrateChainPatrol.js",
774
774
  "default": "./services/migration-service/scripts/MigrateChainPatrol.js"
775
775
  },
776
- "./services/migration-service/scripts/MigrateEthProvider": {
777
- "types": "./services/migration-service/scripts/MigrateEthProvider.d.ts",
778
- "require": "./cjs/services/migration-service/scripts/MigrateEthProvider.js",
779
- "default": "./services/migration-service/scripts/MigrateEthProvider.js"
780
- },
781
776
  "./services/migration-service/scripts/MigrateImportedToken": {
782
777
  "types": "./services/migration-service/scripts/MigrateImportedToken.d.ts",
783
778
  "require": "./cjs/services/migration-service/scripts/MigrateImportedToken.js",
@@ -793,16 +788,6 @@
793
788
  "require": "./cjs/services/migration-service/scripts/MigrateNetworkSettings.js",
794
789
  "default": "./services/migration-service/scripts/MigrateNetworkSettings.js"
795
790
  },
796
- "./services/migration-service/scripts/MigratePioneerProvider": {
797
- "types": "./services/migration-service/scripts/MigratePioneerProvider.d.ts",
798
- "require": "./cjs/services/migration-service/scripts/MigratePioneerProvider.js",
799
- "default": "./services/migration-service/scripts/MigratePioneerProvider.js"
800
- },
801
- "./services/migration-service/scripts/MigrateProvider": {
802
- "types": "./services/migration-service/scripts/MigrateProvider.d.ts",
803
- "require": "./cjs/services/migration-service/scripts/MigrateProvider.js",
804
- "default": "./services/migration-service/scripts/MigrateProvider.js"
805
- },
806
791
  "./services/migration-service/scripts/MigrateSettings": {
807
792
  "types": "./services/migration-service/scripts/MigrateSettings.d.ts",
808
793
  "require": "./cjs/services/migration-service/scripts/MigrateSettings.js",
@@ -823,6 +808,36 @@
823
808
  "require": "./cjs/services/migration-service/scripts/MigrateWalletReference.js",
824
809
  "default": "./services/migration-service/scripts/MigrateWalletReference.js"
825
810
  },
811
+ "./services/migration-service/scripts/providers/MigrateEthProvider": {
812
+ "types": "./services/migration-service/scripts/providers/MigrateEthProvider.d.ts",
813
+ "require": "./cjs/services/migration-service/scripts/providers/MigrateEthProvider.js",
814
+ "default": "./services/migration-service/scripts/providers/MigrateEthProvider.js"
815
+ },
816
+ "./services/migration-service/scripts/providers/MigrateGeneralProvider": {
817
+ "types": "./services/migration-service/scripts/providers/MigrateGeneralProvider.d.ts",
818
+ "require": "./cjs/services/migration-service/scripts/providers/MigrateGeneralProvider.js",
819
+ "default": "./services/migration-service/scripts/providers/MigrateGeneralProvider.js"
820
+ },
821
+ "./services/migration-service/scripts/providers/MigrateMultiProviders": {
822
+ "types": "./services/migration-service/scripts/providers/MigrateMultiProviders.d.ts",
823
+ "require": "./cjs/services/migration-service/scripts/providers/MigrateMultiProviders.js",
824
+ "default": "./services/migration-service/scripts/providers/MigrateMultiProviders.js"
825
+ },
826
+ "./services/migration-service/scripts/providers/MigratePioneerProvider": {
827
+ "types": "./services/migration-service/scripts/providers/MigratePioneerProvider.d.ts",
828
+ "require": "./cjs/services/migration-service/scripts/providers/MigratePioneerProvider.js",
829
+ "default": "./services/migration-service/scripts/providers/MigratePioneerProvider.js"
830
+ },
831
+ "./services/migration-service/scripts/providers/MigrateProvider": {
832
+ "types": "./services/migration-service/scripts/providers/MigrateProvider.d.ts",
833
+ "require": "./cjs/services/migration-service/scripts/providers/MigrateProvider.js",
834
+ "default": "./services/migration-service/scripts/providers/MigrateProvider.js"
835
+ },
836
+ "./services/migration-service/scripts/providers/MigrateProvidersV1M1P24": {
837
+ "types": "./services/migration-service/scripts/providers/MigrateProvidersV1M1P24.d.ts",
838
+ "require": "./cjs/services/migration-service/scripts/providers/MigrateProvidersV1M1P24.js",
839
+ "default": "./services/migration-service/scripts/providers/MigrateProvidersV1M1P24.js"
840
+ },
826
841
  "./services/notification-service/NotificationService": {
827
842
  "types": "./services/notification-service/NotificationService.d.ts",
828
843
  "require": "./cjs/services/notification-service/NotificationService.js",
@@ -1347,11 +1362,11 @@
1347
1362
  "@reduxjs/toolkit": "^1.9.1",
1348
1363
  "@sora-substrate/type-definitions": "^1.17.7",
1349
1364
  "@substrate/connect": "^0.7.26",
1350
- "@subwallet/chain-list": "0.2.27",
1351
- "@subwallet/extension-base": "^1.1.24-3",
1352
- "@subwallet/extension-chains": "^1.1.24-3",
1353
- "@subwallet/extension-dapp": "^1.1.24-3",
1354
- "@subwallet/extension-inject": "^1.1.24-3",
1365
+ "@subwallet/chain-list": "0.2.28",
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",
1355
1370
  "@subwallet/keyring": "^0.1.1",
1356
1371
  "@subwallet/ui-keyring": "^0.1.1",
1357
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-3'
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);
@@ -90,9 +90,7 @@ export declare const _XCM_TYPE: {
90
90
  PR: string;
91
91
  };
92
92
  export declare const _DEFAULT_ACTIVE_CHAINS: string[];
93
- export declare const EVM_PASS_CONNECT_STATUS: {
94
- acala: string[];
95
- };
93
+ export declare const EVM_PASS_CONNECT_STATUS: Record<string, string[]>;
96
94
  export declare const EVM_REFORMAT_DECIMALS: {
97
95
  acala: string[];
98
96
  };
@@ -224,7 +224,7 @@ export const _XCM_TYPE = {
224
224
 
225
225
  export const _DEFAULT_ACTIVE_CHAINS = [..._DEFAULT_CHAINS, 'vara_network'];
226
226
  export const EVM_PASS_CONNECT_STATUS = {
227
- acala: ['acala_evm', 'karura_evm']
227
+ arbitrum_one: ['*']
228
228
  };
229
229
  export const EVM_REFORMAT_DECIMALS = {
230
230
  acala: ['acala_evm', 'karura_evm']
@@ -28,6 +28,7 @@ export declare class EvmApi implements _EvmApi {
28
28
  recoverConnect(): Promise<void>;
29
29
  private createProvider;
30
30
  constructor(chainSlug: string, apiUrl: string, { providerName }?: _ApiOptions);
31
+ get ignoreNetListen(): boolean;
31
32
  createIntervalCheckApi(): NodeJS.Timer;
32
33
  clearIntervalCheckApi(): void;
33
34
  connect(): void;
@@ -7,7 +7,6 @@ import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain
7
7
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
8
8
  import { BehaviorSubject } from 'rxjs';
9
9
  import Web3 from 'web3';
10
- const acalaEvmNetworks = EVM_PASS_CONNECT_STATUS.acala;
11
10
  export class EvmApi {
12
11
  apiRetry = 0;
13
12
  isApiConnectedSubject = new BehaviorSubject(false);
@@ -66,10 +65,14 @@ export class EvmApi {
66
65
  this.intervalCheckApi = this.createIntervalCheckApi();
67
66
  this.connect();
68
67
  }
68
+ get ignoreNetListen() {
69
+ const ignoreRpc = EVM_PASS_CONNECT_STATUS[this.chainSlug];
70
+ return ignoreRpc ? ignoreRpc.includes('*') || ignoreRpc.includes(this.apiUrl) : false;
71
+ }
69
72
  createIntervalCheckApi() {
70
73
  this.clearIntervalCheckApi();
71
74
  return setInterval(() => {
72
- if (!acalaEvmNetworks.includes(this.chainSlug)) {
75
+ if (!this.ignoreNetListen) {
73
76
  this.api.eth.net.isListening().then(() => {
74
77
  this.onConnect();
75
78
  }).catch(() => {
@@ -90,7 +93,7 @@ export class EvmApi {
90
93
  this.updateConnectionStatus(_ChainConnectionStatus.CONNECTING);
91
94
 
92
95
  // Check if api is ready
93
- if (!acalaEvmNetworks.includes(this.chainSlug)) {
96
+ if (!this.ignoreNetListen) {
94
97
  this.api.eth.net.isListening().then(() => {
95
98
  this.isApiReadyOnce = true;
96
99
  this.onConnect();
@@ -1,17 +1,18 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import DeleteChain from '@subwallet/extension-base/services/migration-service/scripts/DeleteChain';
4
+ import MigrateEthProvider from "./providers/MigrateEthProvider.js";
5
+ import MigratePioneerProvider from "./providers/MigratePioneerProvider.js";
6
+ import MigrateProvidersV1M1P24 from "./providers/MigrateProvidersV1M1P24.js";
5
7
  import AutoEnableChainsTokens from "./AutoEnableChainsTokens.js";
8
+ import DeleteChain from "./DeleteChain.js";
6
9
  import EnableVaraChain from "./EnableVaraChain.js";
7
10
  import MigrateAuthUrls from "./MigrateAuthUrls.js";
8
11
  import MigrateAutoLock from "./MigrateAutoLock.js";
9
12
  import MigrateChainPatrol from "./MigrateChainPatrol.js";
10
- import MigrateEthProvider from "./MigrateEthProvider.js";
11
13
  import MigrateImportedToken from "./MigrateImportedToken.js";
12
14
  import MigrateLedgerAccount from "./MigrateLedgerAccount.js";
13
15
  import MigrateNetworkSettings from "./MigrateNetworkSettings.js";
14
- import MigratePioneerProvider from "./MigratePioneerProvider.js";
15
16
  import MigrateSettings from "./MigrateSettings.js";
16
17
  import MigrateTokenDecimals from "./MigrateTokenDecimals.js";
17
18
  import MigrateTransactionHistory from "./MigrateTransactionHistory.js";
@@ -32,6 +33,7 @@ export default {
32
33
  '1.1.7': DeleteChain,
33
34
  '1.1.13-01': MigrateTokenDecimals,
34
35
  '1.1.17-01': MigratePioneerProvider,
35
- '1.1.17-03': EnableVaraChain
36
+ '1.1.17-03': EnableVaraChain,
37
+ '1.1.24-01': MigrateProvidersV1M1P24
36
38
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
37
39
  };
@@ -3,7 +3,7 @@
3
3
 
4
4
  import MigrateProvider from "./MigrateProvider.js";
5
5
  export default class MigrateEthProvider extends MigrateProvider {
6
- newProvider = 'ethereum';
6
+ slug = 'ethereum';
7
7
  oldProvider = 'Cloudflare';
8
- slug = 'Llamarpc';
8
+ newProvider = 'Llamarpc';
9
9
  }
@@ -0,0 +1,13 @@
1
+ import State from '@subwallet/extension-base/koni/background/handlers/State';
2
+ import MigrateProvider from './MigrateProvider';
3
+ export interface MigrateProviderTarget {
4
+ slug: string;
5
+ oldProvider: string;
6
+ newProvider: string;
7
+ }
8
+ export default class MigrateGeneralProvider extends MigrateProvider {
9
+ readonly newProvider: string;
10
+ readonly oldProvider: string;
11
+ readonly slug: string;
12
+ constructor(state: State, target: MigrateProviderTarget);
13
+ }
@@ -0,0 +1,12 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import MigrateProvider from "./MigrateProvider.js";
5
+ export default class MigrateGeneralProvider extends MigrateProvider {
6
+ constructor(state, target) {
7
+ super(state);
8
+ this.slug = target.slug;
9
+ this.oldProvider = target.oldProvider;
10
+ this.newProvider = target.newProvider;
11
+ }
12
+ }
@@ -0,0 +1,6 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ import { MigrateProviderTarget } from './MigrateGeneralProvider';
3
+ export default abstract class MigrateMultiProviders extends BaseMigrationJob {
4
+ abstract targets: MigrateProviderTarget[];
5
+ run(): Promise<void>;
6
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
5
+ import MigrateGeneralProvider from "./MigrateGeneralProvider.js";
6
+ export default class MigrateMultiProviders extends BaseMigrationJob {
7
+ async run() {
8
+ for (const target of this.targets) {
9
+ const migration = new MigrateGeneralProvider(this.state, target);
10
+ await migration.run();
11
+ }
12
+ }
13
+ }
@@ -7,7 +7,7 @@ export default class MigrateProvider extends BaseMigrationJob {
7
7
  const state = this.state;
8
8
  const chainState = state.getChainStateByKey(this.slug);
9
9
  const chainInfo = state.getChainInfo(this.slug);
10
- if (chainState && chainState.active && chainState.currentProvider === this.oldProvider) {
10
+ if (chainState && chainState.active && chainInfo.providers[this.newProvider] && chainState.currentProvider === this.oldProvider) {
11
11
  await state.upsertChainInfo({
12
12
  mode: 'update',
13
13
  chainEditInfo: {
@@ -0,0 +1,5 @@
1
+ import { MigrateProviderTarget } from './MigrateGeneralProvider';
2
+ import MigrateMultiProviders from './MigrateMultiProviders';
3
+ export default class MigrateProvidersV1M1P24 extends MigrateMultiProviders {
4
+ targets: MigrateProviderTarget[];
5
+ }
@@ -0,0 +1,23 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import MigrateMultiProviders from "./MigrateMultiProviders.js";
5
+ export default class MigrateProvidersV1M1P24 extends MigrateMultiProviders {
6
+ targets = [{
7
+ slug: 'polkadot',
8
+ oldProvider: 'Parity',
9
+ newProvider: 'Dwellir'
10
+ }, {
11
+ slug: 'kusama',
12
+ oldProvider: 'Parity',
13
+ newProvider: 'Dwellir'
14
+ }, {
15
+ slug: 'moonbeam',
16
+ oldProvider: 'OnFinality',
17
+ newProvider: 'Moonbeam Foundation'
18
+ }, {
19
+ slug: 'moonbase',
20
+ oldProvider: 'OnFinality',
21
+ newProvider: 'Moonbeam Foundation'
22
+ }];
23
+ }
@@ -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
  };
@@ -1,6 +1,6 @@
1
1
  import MigrateProvider from './MigrateProvider';
2
2
  export default class MigrateEthProvider extends MigrateProvider {
3
- newProvider: string;
4
- oldProvider: string;
5
3
  slug: string;
4
+ oldProvider: string;
5
+ newProvider: string;
6
6
  }