@subwallet/extension-base 1.0.2-2 → 1.0.2-3

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 (134) hide show
  1. package/background/KoniTypes.d.ts +46 -38
  2. package/background/KoniTypes.js +8 -8
  3. package/background/errors/TransactionError.js +25 -1
  4. package/background/types.d.ts +10 -5
  5. package/cjs/background/KoniTypes.js +8 -8
  6. package/cjs/background/errors/TransactionError.js +24 -0
  7. package/cjs/constants/index.js +8 -26
  8. package/cjs/koni/api/dotsama/balance.js +49 -224
  9. package/cjs/koni/api/dotsama/transfer.js +34 -39
  10. package/cjs/koni/api/nft/acala_nft/index.js +7 -7
  11. package/cjs/koni/api/nft/bit.country/index.js +7 -6
  12. package/cjs/koni/api/nft/evm_nft/index.js +8 -3
  13. package/cjs/koni/api/nft/index.js +3 -6
  14. package/cjs/koni/api/nft/karura_nft/index.js +7 -6
  15. package/cjs/koni/api/nft/rmrk_nft/index.js +11 -1
  16. package/cjs/koni/api/nft/statemine_nft/index.js +7 -6
  17. package/cjs/koni/api/nft/unique_nft/index.js +5 -1
  18. package/cjs/koni/api/nft/wasm_nft/index.js +170 -111
  19. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  20. package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
  21. package/cjs/koni/api/staking/bonding/astar.js +15 -13
  22. package/cjs/koni/api/staking/bonding/index.js +22 -10
  23. package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
  24. package/cjs/koni/api/staking/bonding/relayChain.js +122 -16
  25. package/cjs/koni/api/staking/bonding/utils.js +27 -8
  26. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  27. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  28. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +1 -1
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +171 -61
  33. package/cjs/koni/background/handlers/Extension.js +382 -207
  34. package/cjs/koni/background/handlers/State.js +41 -33
  35. package/cjs/koni/background/handlers/Tabs.js +50 -17
  36. package/cjs/koni/background/subscription.js +32 -29
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  39. package/cjs/services/chain-service/index.js +59 -45
  40. package/cjs/services/event-service/index.js +5 -1
  41. package/cjs/services/event-service/types.js +11 -1
  42. package/cjs/services/history-service/index.js +19 -13
  43. package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
  44. package/cjs/services/keyring-service/index.js +11 -13
  45. package/cjs/services/price-service/coingecko.js +0 -1
  46. package/cjs/services/price-service/index.js +2 -3
  47. package/cjs/services/request-service/handler/AuthRequestHandler.js +13 -7
  48. package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
  49. package/cjs/services/request-service/index.js +14 -5
  50. package/cjs/services/storage-service/DatabaseService.js +56 -34
  51. package/cjs/services/storage-service/db-stores/Nft.js +7 -15
  52. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  53. package/cjs/services/transaction-service/index.js +26 -15
  54. package/cjs/utils/address.js +10 -1
  55. package/cjs/utils/index.js +9 -15
  56. package/constants/index.d.ts +7 -13
  57. package/constants/index.js +7 -13
  58. package/koni/api/dotsama/balance.d.ts +0 -1
  59. package/koni/api/dotsama/balance.js +22 -197
  60. package/koni/api/dotsama/transfer.js +11 -16
  61. package/koni/api/nft/acala_nft/index.js +7 -7
  62. package/koni/api/nft/bit.country/index.js +7 -6
  63. package/koni/api/nft/evm_nft/index.js +7 -3
  64. package/koni/api/nft/index.d.ts +1 -2
  65. package/koni/api/nft/index.js +3 -6
  66. package/koni/api/nft/karura_nft/index.js +7 -6
  67. package/koni/api/nft/nft.d.ts +1 -0
  68. package/koni/api/nft/rmrk_nft/index.js +11 -1
  69. package/koni/api/nft/statemine_nft/index.js +7 -6
  70. package/koni/api/nft/unique_nft/index.js +5 -1
  71. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  72. package/koni/api/nft/wasm_nft/index.js +168 -109
  73. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  74. package/koni/api/nft/wasm_nft/utils.js +7 -5
  75. package/koni/api/staking/bonding/amplitude.d.ts +0 -1
  76. package/koni/api/staking/bonding/amplitude.js +15 -10
  77. package/koni/api/staking/bonding/astar.js +8 -6
  78. package/koni/api/staking/bonding/index.d.ts +4 -1
  79. package/koni/api/staking/bonding/index.js +23 -13
  80. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  81. package/koni/api/staking/bonding/paraChain.js +86 -5
  82. package/koni/api/staking/bonding/relayChain.d.ts +5 -1
  83. package/koni/api/staking/bonding/relayChain.js +121 -18
  84. package/koni/api/staking/bonding/utils.d.ts +3 -2
  85. package/koni/api/staking/bonding/utils.js +27 -9
  86. package/koni/api/tokens/wasm/index.js +5 -4
  87. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  88. package/koni/api/tokens/wasm/utils.js +54 -0
  89. package/koni/api/xcm/polkadotXcm.js +2 -2
  90. package/koni/api/xcm/utils.d.ts +5 -6
  91. package/koni/api/xcm/utils.js +15 -10
  92. package/koni/api/xcm/xTokens.js +2 -2
  93. package/koni/api/xcm/xcmPallet.js +10 -9
  94. package/koni/background/cron.d.ts +6 -1
  95. package/koni/background/cron.js +172 -62
  96. package/koni/background/handlers/Extension.d.ts +8 -3
  97. package/koni/background/handlers/Extension.js +297 -126
  98. package/koni/background/handlers/State.d.ts +5 -6
  99. package/koni/background/handlers/State.js +43 -33
  100. package/koni/background/handlers/Tabs.js +50 -17
  101. package/koni/background/subscription.js +31 -30
  102. package/package.json +18 -13
  103. package/packageInfo.js +1 -1
  104. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  105. package/services/chain-service/helper/psp22_abi.json +1041 -881
  106. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  107. package/services/chain-service/index.d.ts +3 -2
  108. package/services/chain-service/index.js +53 -40
  109. package/services/chain-service/types.d.ts +1 -0
  110. package/services/event-service/index.js +5 -1
  111. package/services/event-service/types.d.ts +5 -9
  112. package/services/event-service/types.js +4 -1
  113. package/services/history-service/index.d.ts +4 -2
  114. package/services/history-service/index.js +19 -13
  115. package/services/history-service/subsquid-multi-chain-history.js +16 -12
  116. package/services/keyring-service/index.d.ts +4 -2
  117. package/services/keyring-service/index.js +11 -13
  118. package/services/price-service/coingecko.js +0 -1
  119. package/services/price-service/index.js +2 -3
  120. package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
  121. package/services/request-service/handler/AuthRequestHandler.js +13 -7
  122. package/services/request-service/handler/EvmRequestHandler.js +8 -12
  123. package/services/request-service/index.d.ts +3 -1
  124. package/services/request-service/index.js +14 -5
  125. package/services/storage-service/DatabaseService.d.ts +1 -0
  126. package/services/storage-service/DatabaseService.js +56 -34
  127. package/services/storage-service/db-stores/Nft.d.ts +2 -2
  128. package/services/storage-service/db-stores/Nft.js +7 -14
  129. package/services/transaction-service/event-parser/index.js +21 -49
  130. package/services/transaction-service/index.js +26 -15
  131. package/utils/address.d.ts +3 -0
  132. package/utils/address.js +8 -1
  133. package/utils/index.d.ts +2 -2
  134. package/utils/index.js +7 -13
@@ -31,7 +31,6 @@ export default class KoniState {
31
31
  private readonly unsubscriptionMap;
32
32
  private readonly accountRefStore;
33
33
  private externalRequest;
34
- private serviceInfoSubject;
35
34
  private balanceMap;
36
35
  private balanceSubject;
37
36
  private crowdloanMap;
@@ -109,8 +108,8 @@ export default class KoniState {
109
108
  subscribeNftCollection(): import("dexie").Observable<NftCollection[]>;
110
109
  resetNft(newAddress: string): void;
111
110
  updateNftData(network: string, nftData: NftItem, address: string, callback?: (nftData: NftItem) => void): void;
112
- removeNfts(chain: string, address: string, collectionId: string, nftIds: string[]): import("dexie").PromiseExtended<number>;
113
111
  deleteNftCollection(chain: string, collectionId: string): Promise<void>;
112
+ cleanUpNfts(chain: string, owner: string, collectionId: string[], nftIds: string[], ownNothing?: boolean): void;
114
113
  getNft(): Promise<NftJson | undefined>;
115
114
  subscribeNft(): Subject<NftJson>;
116
115
  resetStakingReward(): void;
@@ -141,7 +140,7 @@ export default class KoniState {
141
140
  private removeInactiveChainBalances;
142
141
  getBalance(reset?: boolean): BalanceJson;
143
142
  getStoredBalance(address: string): Promise<Record<string, BalanceItem>>;
144
- switchAccount(newAddress: string): Promise<void>;
143
+ handleSwitchAccount(newAddress: string): Promise<void>;
145
144
  resetBalanceMap(newAddress: string): Promise<void>;
146
145
  resetCrowdloanMap(newAddress: string): Promise<void>;
147
146
  resetStaking(newAddress: string): void;
@@ -153,7 +152,6 @@ export default class KoniState {
153
152
  setCrowdloanItem(networkKey: string, item: CrowdloanItem): void;
154
153
  private updateCrowdloanStore;
155
154
  subscribeCrowdloan(): Subject<CrowdloanJson>;
156
- getAllPriceIds(): string[];
157
155
  getSmartContractNfts(): _ChainAsset[];
158
156
  getChainInfoMap(): Record<string, _ChainInfo>;
159
157
  getChainStateMap(): Record<string, _ChainState>;
@@ -182,7 +180,6 @@ export default class KoniState {
182
180
  disableChain(chainSlug: string): Promise<boolean>;
183
181
  enableChain(chainSlug: string, enableTokens?: boolean): Promise<boolean>;
184
182
  resetDefaultChains(): boolean;
185
- updateNetworkStatus(networkKey: string, status: _ChainConnectionStatus): void;
186
183
  getSubstrateApiMap(): Record<string, import("@subwallet/extension-base/services/chain-service/types")._SubstrateApi>;
187
184
  getSubstrateApi(networkKey: string): import("@subwallet/extension-base/services/chain-service/types")._SubstrateApi;
188
185
  getEvmApiMap(): Record<string, import("@subwallet/extension-base/services/chain-service/types")._EvmApi>;
@@ -190,7 +187,6 @@ export default class KoniState {
190
187
  getApiMap(): ApiMap;
191
188
  refreshSubstrateApi(key: string): boolean;
192
189
  refreshWeb3Api(key: string): void;
193
- subscribeServiceInfo(): Subject<ServiceInfo>;
194
190
  getServiceInfo(): ServiceInfo;
195
191
  getExternalRequestMap(): Record<string, ExternalRequestPromise>;
196
192
  setExternalRequestMap(id: string, value: ExternalRequestPromise): void;
@@ -219,8 +215,11 @@ export default class KoniState {
219
215
  wakeup(): Promise<void>;
220
216
  cancelSubscription(id: string): boolean;
221
217
  createUnsubscriptionHandle(id: string, unsubscribe: () => void): void;
218
+ updateChainConnectionStatus(chain: string, status: _ChainConnectionStatus): void;
222
219
  autoEnableChains(addresses: string[]): Promise<void>;
223
220
  onAccountAdd(): void;
224
221
  onAccountRemove(): void;
222
+ reloadNft(): Promise<boolean>;
223
+ reloadStaking(): Promise<boolean>;
225
224
  }
226
225
  export {};
@@ -27,7 +27,6 @@ import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
27
27
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
28
28
  import { decodePair } from '@subwallet/keyring/pair/decode';
29
29
  import { keyring } from '@subwallet/ui-keyring';
30
- import { accounts } from '@subwallet/ui-keyring/observable/accounts';
31
30
  import SimpleKeyring from 'eth-simple-keyring';
32
31
  import { Subject } from 'rxjs';
33
32
  import { assert, BN, hexStripPrefix, hexToU8a, isHex, logger as createLogger, u8aToHex } from '@polkadot/util';
@@ -59,7 +58,6 @@ export default class KoniState {
59
58
  unsubscriptionMap = {};
60
59
  accountRefStore = new AccountRefStore();
61
60
  externalRequest = {};
62
- serviceInfoSubject = new Subject();
63
61
  balanceMap = {};
64
62
  balanceSubject = new Subject();
65
63
  crowdloanMap = generateDefaultCrowdloanMap();
@@ -85,10 +83,10 @@ export default class KoniState {
85
83
  this.notificationService = new NotificationService();
86
84
  this.chainService = new ChainService(this.dbService, this.eventService);
87
85
  this.settingService = new SettingService();
88
- this.requestService = new RequestService(this.chainService, this.settingService);
86
+ this.requestService = new RequestService(this.chainService, this.settingService, this.keyringService);
89
87
  this.priceService = new PriceService(this.dbService, this.eventService, this.chainService);
90
88
  this.balanceService = new BalanceService(this.chainService);
91
- this.historyService = new HistoryService(this.dbService, this.chainService, this.eventService);
89
+ this.historyService = new HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService);
92
90
  this.transactionService = new TransactionService(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
93
91
  this.migrationService = new MigrationService(this);
94
92
  this.subscription = new KoniSubscription(this, this.dbService);
@@ -253,7 +251,7 @@ export default class KoniState {
253
251
  return this.requestService.getAuthList();
254
252
  }
255
253
  getAddressList(value = false) {
256
- const addressList = Object.keys(accounts.subject.value);
254
+ const addressList = Object.keys(this.keyringService.accounts);
257
255
  return addressList.reduce((addressList, v) => ({
258
256
  ...addressList,
259
257
  [v]: value
@@ -296,7 +294,7 @@ export default class KoniState {
296
294
  return addresses;
297
295
  }
298
296
  async getPooledStakingRecordsByAddress(addresses) {
299
- return await this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
297
+ return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
300
298
  }
301
299
 
302
300
  // TODO: delete later
@@ -354,12 +352,12 @@ export default class KoniState {
354
352
  this.dbService.addNft(address, nftData).catch(e => this.logger.warn(e));
355
353
  callback && callback(nftData);
356
354
  }
357
- removeNfts(chain, address, collectionId, nftIds) {
358
- return this.dbService.removeNfts(chain, address, collectionId, nftIds);
359
- }
360
355
  deleteNftCollection(chain, collectionId) {
361
356
  return this.dbService.deleteNftCollection(chain, collectionId);
362
357
  }
358
+ cleanUpNfts(chain, owner, collectionId, nftIds, ownNothing) {
359
+ this.dbService.cleanUpNft(chain, owner, collectionId, nftIds, ownNothing).catch(e => this.logger.warn(e));
360
+ }
363
361
  async getNft() {
364
362
  const addresses = this.getDecodedAddresses();
365
363
  if (!addresses.length) {
@@ -446,7 +444,7 @@ export default class KoniState {
446
444
  if (address === ALL_ACCOUNT_KEY) {
447
445
  const pairs = keyring.getAccounts();
448
446
  const pair = pairs[0];
449
- const pairGenesisHash = pair.meta.genesisHash;
447
+ const pairGenesisHash = (pair === null || pair === void 0 ? void 0 : pair.meta.genesisHash) || '';
450
448
  if (pairs.length > 1 || !pair) {
451
449
  result.allGenesisHash = currentGenesisHash || undefined;
452
450
  } else {
@@ -531,7 +529,11 @@ export default class KoniState {
531
529
  isApproved
532
530
  }) => {
533
531
  if (isApproved) {
534
- await this.upsertChainInfo(networkData);
532
+ if (networkData.mode === 'insert') {
533
+ await this.upsertChainInfo(networkData);
534
+ } else {
535
+ // TODO: update existed network (need more discussion)
536
+ }
535
537
  return null;
536
538
  } else {
537
539
  throw new EvmProviderError(EvmProviderErrorType.USER_REJECTED_REQUEST);
@@ -656,7 +658,7 @@ export default class KoniState {
656
658
  const items = await this.dbService.stores.balance.getBalanceMapByAddress(address);
657
659
  return items || {};
658
660
  }
659
- async switchAccount(newAddress) {
661
+ async handleSwitchAccount(newAddress) {
660
662
  await Promise.all([this.resetBalanceMap(newAddress), this.resetCrowdloanMap(newAddress)]);
661
663
  }
662
664
  async resetBalanceMap(newAddress) {
@@ -737,9 +739,6 @@ export default class KoniState {
737
739
  subscribeCrowdloan() {
738
740
  return this.crowdloanSubject;
739
741
  }
740
- getAllPriceIds() {
741
- return this.chainService.getAllPriceIds();
742
- }
743
742
  getSmartContractNfts() {
744
743
  return this.chainService.getSmartContractNfts();
745
744
  }
@@ -797,7 +796,9 @@ export default class KoniState {
797
796
  await this.chainService.updateAssetSetting(tokenSlug, {
798
797
  visible: true
799
798
  });
800
- this.eventService.emit('asset.update', tokenSlug);
799
+ this.eventService.emit('asset.updateState', tokenSlug);
800
+ } else {
801
+ this.eventService.emit('asset.updateState', tokenSlug);
801
802
  }
802
803
  }
803
804
  deleteCustomAssets(targetTokens) {
@@ -824,6 +825,7 @@ export default class KoniState {
824
825
  await this.chainService.updateAssetSetting(newNativeTokenSlug, {
825
826
  visible: true
826
827
  });
828
+ this.eventService.emit('asset.updateState', newNativeTokenSlug);
827
829
  }
828
830
  return true;
829
831
  }
@@ -866,13 +868,6 @@ export default class KoniState {
866
868
  const defaultChains = this.getDefaultNetworkKeys();
867
869
  return this.chainService.resetChainInfoMap(defaultChains);
868
870
  }
869
- updateNetworkStatus(networkKey, status) {
870
- const chainState = this.chainService.getChainStateByKey(networkKey);
871
- if (chainState.connectionStatus === status) {
872
- return;
873
- }
874
- this.chainService.setChainConnectionStatus(networkKey, status);
875
- }
876
871
  getSubstrateApiMap() {
877
872
  return this.chainService.getSubstrateApiMap();
878
873
  }
@@ -898,9 +893,6 @@ export default class KoniState {
898
893
  refreshWeb3Api(key) {
899
894
  this.chainService.refreshEvmApi(key);
900
895
  }
901
- subscribeServiceInfo() {
902
- return this.serviceInfoSubject;
903
- }
904
896
  getServiceInfo() {
905
897
  return {
906
898
  chainInfoMap: this.chainService.getChainInfoMap(),
@@ -998,7 +990,10 @@ export default class KoniState {
998
990
  if (!chainId) {
999
991
  return [undefined, undefined];
1000
992
  }
1001
- const rs = Object.entries(this.chainService.getChainInfoMap()).find(([networkKey, chainInfo]) => _getEvmChainId(chainInfo) === chainId);
993
+ const rs = Object.entries(this.chainService.getChainInfoMap()).find(([networkKey, chainInfo]) => {
994
+ var _chainInfo$evmInfo;
995
+ return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) === chainId;
996
+ });
1002
997
  if (rs) {
1003
998
  return rs;
1004
999
  } else {
@@ -1232,17 +1227,23 @@ export default class KoniState {
1232
1227
  account: account,
1233
1228
  canSign: true
1234
1229
  };
1230
+ const eType = transaction.value ? ExtrinsicType.TRANSFER_BALANCE : ExtrinsicType.EVM_EXECUTE;
1231
+ const transactionData = {
1232
+ ...transaction
1233
+ };
1234
+ if (eType === ExtrinsicType.TRANSFER_BALANCE) {
1235
+ // @ts-ignore
1236
+ transactionData.tokenSlug = this.chainService.getNativeTokenInfo(networkKey).slug;
1237
+ }
1235
1238
 
1236
- // Todo: Convert this to handle transaction
1239
+ // Custom handle this instead of general handler transaction
1237
1240
  const transactionEmitter = await this.transactionService.addTransaction({
1238
1241
  transaction: requestPayload,
1239
1242
  address: requestPayload.from,
1240
1243
  chain: networkKey,
1241
1244
  url,
1242
- data: {
1243
- ...transaction
1244
- },
1245
- extrinsicType: transaction.value ? ExtrinsicType.TRANSFER_BALANCE : ExtrinsicType.EVM_EXECUTE,
1245
+ data: transactionData,
1246
+ extrinsicType: eType,
1246
1247
  chainType: ChainType.EVM
1247
1248
  });
1248
1249
 
@@ -1339,6 +1340,9 @@ export default class KoniState {
1339
1340
  createUnsubscriptionHandle(id, unsubscribe) {
1340
1341
  this.unsubscriptionMap[id] = unsubscribe;
1341
1342
  }
1343
+ updateChainConnectionStatus(chain, status) {
1344
+ this.chainService.setChainConnectionStatus(chain, status);
1345
+ }
1342
1346
  async autoEnableChains(addresses) {
1343
1347
  const assetMap = this.chainService.getAssetRegistry();
1344
1348
  const promiseList = addresses.map(address => {
@@ -1364,7 +1368,7 @@ export default class KoniState {
1364
1368
  var _currentAssetSettings;
1365
1369
  const chain = SUBSCAN_CHAIN_MAP_REVERSE[network];
1366
1370
  const chainInfo = chain ? chainMap[chain] : null;
1367
- const balanceIsEmpty = (!balance || balance === '0') && !locked && locked === '0' && (!bonded || bonded === '0');
1371
+ const balanceIsEmpty = (!balance || balance === '0') && (!locked || locked === '0') && (!bonded || bonded === '0');
1368
1372
 
1369
1373
  // Cancel if chain is not supported or is testnet or balance is 0
1370
1374
  if (!chainInfo || chainInfo.isTestnet || balanceIsEmpty) {
@@ -1409,4 +1413,10 @@ export default class KoniState {
1409
1413
  stores.staking.removeAllByAddress(address).catch(console.error);
1410
1414
  });
1411
1415
  }
1416
+ async reloadNft() {
1417
+ return await this.cron.reloadNft();
1418
+ }
1419
+ async reloadStaking() {
1420
+ return await this.cron.reloadStaking();
1421
+ }
1412
1422
  }
@@ -13,7 +13,6 @@ import { PHISHING_PAGE_REDIRECT } from '@subwallet/extension-base/defaults';
13
13
  import { _generateCustomProviderKey } from '@subwallet/extension-base/services/chain-service/utils';
14
14
  import { canDerive } from '@subwallet/extension-base/utils';
15
15
  import keyring from '@subwallet/ui-keyring';
16
- import { accounts as accountsObservable } from '@subwallet/ui-keyring/observable/accounts';
17
16
  import Web3 from 'web3';
18
17
  import { checkIfDenied } from '@polkadot/phishing';
19
18
  import { assert, isNumber } from '@polkadot/util';
@@ -182,13 +181,13 @@ export default class KoniTabs {
182
181
  anyType
183
182
  }) {
184
183
  const authInfo = await this.getAuthInfo(url);
185
- return transformAccountsV2(accountsObservable.subject.getValue(), anyType, authInfo, accountAuthType);
184
+ return transformAccountsV2(this.#koniState.keyringService.accounts, anyType, authInfo, accountAuthType);
186
185
  }
187
186
  accountsSubscribeV2(url, {
188
187
  accountAuthType
189
188
  }, id, port) {
190
189
  const cb = createSubscription(id, port);
191
- const subscription = accountsObservable.subject.subscribe(accounts => {
190
+ const subscription = this.#koniState.keyringService.accountSubject.subscribe(accounts => {
192
191
  this.getAuthInfo(url).then(authInfo => {
193
192
  cb(transformAccountsV2(accounts, false, authInfo, accountAuthType));
194
193
  }).catch(console.error);
@@ -213,7 +212,7 @@ export default class KoniTabs {
213
212
  async getEvmCurrentAccount(url, getAll = false) {
214
213
  return await new Promise(resolve => {
215
214
  this.getAuthInfo(url).then(authInfo => {
216
- const allAccounts = accountsObservable.subject.getValue();
215
+ const allAccounts = this.#koniState.keyringService.accounts;
217
216
  const accountList = transformAccountsV2(allAccounts, false, authInfo, 'evm').map(a => a.address);
218
217
  let accounts = [];
219
218
  const address = this.#koniState.keyringService.currentAccount.address;
@@ -250,18 +249,25 @@ export default class KoniTabs {
250
249
  slug
251
250
  } = currentEvmNetwork;
252
251
  const evmApi = this.#koniState.getEvmApi(slug);
253
- const web3 = evmApi.api;
254
- if (web3.currentProvider instanceof Web3.providers.WebsocketProvider) {
252
+ const web3 = evmApi === null || evmApi === void 0 ? void 0 : evmApi.api;
253
+ if ((web3 === null || web3 === void 0 ? void 0 : web3.currentProvider) instanceof Web3.providers.WebsocketProvider) {
255
254
  if (!web3.currentProvider.connected) {
256
255
  console.log(`[Web3] ${slug} is disconnected, trying to connect...`);
257
256
  this.#koniState.refreshWeb3Api(slug);
257
+ let checkingNum = 0;
258
258
  const poll = resolve => {
259
+ checkingNum += 1;
259
260
  if (web3.currentProvider.connected) {
260
261
  console.log(`Network [${slug}] is connected.`);
261
262
  resolve(true);
262
263
  } else {
263
264
  console.log(`Connecting to network [${slug}]`);
264
- setTimeout(() => poll(resolve), 400);
265
+ if (checkingNum < 10) {
266
+ setTimeout(() => poll(resolve), 900);
267
+ } else {
268
+ console.log(`Max retry, stop checking [${slug}]`);
269
+ resolve(false);
270
+ }
265
271
  }
266
272
  };
267
273
  await new Promise(poll);
@@ -329,12 +335,16 @@ export default class KoniTabs {
329
335
  contractAddress: input.options.address,
330
336
  originChain: chain
331
337
  });
332
- if (validate.isExist) {
333
- throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, 'Current token is existed');
334
- } else if (validate.contractError) {
338
+
339
+ // Below code is comment because we will handle exited token in the ui-view
340
+ // if (validate.isExist) {
341
+ // throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, 'Current token is existed');
342
+ // } else
343
+ if (validate.contractError) {
335
344
  throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Contract address is invalid');
336
345
  }
337
346
  const tokenInfo = {
347
+ slug: validate === null || validate === void 0 ? void 0 : validate.existedSlug,
338
348
  type: tokenType,
339
349
  name: validate.name,
340
350
  contractAddress: input.options.address,
@@ -357,16 +367,38 @@ export default class KoniTabs {
357
367
  } = input[0];
358
368
  if (chainId) {
359
369
  const chainIdNum = parseInt(chainId, 16);
360
- const [networkKey] = this.#koniState.findNetworkKeyByChainId(chainIdNum);
361
- if (networkKey) {
370
+ const [existedNetworkSlug, existedChainInfo] = this.#koniState.findNetworkKeyByChainId(chainIdNum);
371
+ if (existedNetworkSlug && existedChainInfo && existedChainInfo !== null && existedChainInfo !== void 0 && existedChainInfo.evmInfo) {
372
+ const evmInfo = existedChainInfo.evmInfo;
373
+ const substrateInfo = existedChainInfo.substrateInfo;
374
+ const chainState = this.#koniState.getChainStateByKey(existedNetworkSlug);
375
+ await this.#koniState.addNetworkConfirm(id, url, {
376
+ mode: 'update',
377
+ chainSpec: {
378
+ evmChainId: evmInfo.evmChainId,
379
+ decimals: evmInfo.decimals,
380
+ existentialDeposit: evmInfo.existentialDeposit,
381
+ genesisHash: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.genesisHash) || '',
382
+ paraId: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.paraId) || null,
383
+ addressPrefix: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.addressPrefix) || 0
384
+ },
385
+ chainEditInfo: {
386
+ blockExplorer: blockExplorerUrls === null || blockExplorerUrls === void 0 ? void 0 : blockExplorerUrls[0],
387
+ slug: existedNetworkSlug,
388
+ currentProvider: chainState.currentProvider,
389
+ providers: existedChainInfo.providers,
390
+ symbol: evmInfo.symbol,
391
+ chainType: 'EVM',
392
+ name: existedChainInfo.name
393
+ }
394
+ });
362
395
  return await this.switchEvmChain(id, url, {
363
396
  method: 'wallet_switchEthereumChain',
364
397
  params: [{
365
398
  chainId
366
399
  }]
367
400
  });
368
- }
369
- if (rpcUrls && chainName) {
401
+ } else if (rpcUrls && chainName) {
370
402
  const filteredUrls = rpcUrls.filter(targetString => {
371
403
  let url;
372
404
  try {
@@ -407,6 +439,8 @@ export default class KoniTabs {
407
439
  name: chainInfo.name
408
440
  }
409
441
  });
442
+ } else {
443
+ throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Invalid provider');
410
444
  }
411
445
  }
412
446
  }
@@ -661,9 +695,8 @@ export default class KoniTabs {
661
695
  if (e.code) {
662
696
  throw e;
663
697
  } else {
664
- // @ts-ignore
665
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
666
- throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, e.message);
698
+ console.error(e);
699
+ throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, e === null || e === void 0 ? void 0 : e.toString());
667
700
  }
668
701
  }
669
702
  }
@@ -11,6 +11,7 @@ import { getAmplitudeUnclaimedStakingReward } from '@subwallet/extension-base/ko
11
11
  import { nftHandler } from '@subwallet/extension-base/koni/background/handlers';
12
12
  import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
13
13
  import { _isChainEnabled, _isChainEvmCompatible, _isChainSupportSubstrateStaking, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
14
+ import { COMMON_RELOAD_EVENTS } from '@subwallet/extension-base/services/event-service/types';
14
15
  import { logger as createLogger } from '@polkadot/util';
15
16
  import { isEthereumAddress } from '@polkadot/util-crypto';
16
17
  export class KoniSubscription {
@@ -58,30 +59,28 @@ export class KoniSubscription {
58
59
  this.subscribeBalancesAndCrowdloans(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
59
60
  this.subscribeStakingOnChain(currentAddress, this.state.getSubstrateApiMap());
60
61
  }
61
- if (!this.eventHandler) {
62
- const reloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'chain.update', 'chain.enable', 'asset.update', 'asset.enable', 'transaction.done', 'transaction.failed'];
63
- this.eventHandler = (events, eventTypes) => {
64
- var _serviceInfo$currentA;
65
- const serviceInfo = this.state.getServiceInfo();
66
- const needReload = eventTypes.some(eT => reloadEvents.includes(eT));
67
- if (!needReload) {
68
- return;
69
- }
70
- this.logger.log('ServiceInfo updated, restarting...');
71
- const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
72
- if (!address) {
73
- return;
74
- }
75
- this.subscribeBalancesAndCrowdloans(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
76
- this.subscribeStakingOnChain(address, serviceInfo.chainApiMap.substrate);
77
- };
78
- this.state.eventService.onLazy(this.eventHandler);
79
- }
62
+ this.eventHandler = (events, eventTypes) => {
63
+ var _serviceInfo$currentA;
64
+ const serviceInfo = this.state.getServiceInfo();
65
+ const needReload = eventTypes.some(eventType => COMMON_RELOAD_EVENTS.includes(eventType));
66
+ if (!needReload) {
67
+ return;
68
+ }
69
+ this.logger.log('ServiceInfo updated, restarting...');
70
+ const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
71
+ if (!address) {
72
+ return;
73
+ }
74
+ this.subscribeBalancesAndCrowdloans(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
75
+ this.subscribeStakingOnChain(address, serviceInfo.chainApiMap.substrate);
76
+ };
77
+ this.state.eventService.onLazy(this.eventHandler);
80
78
  }
81
79
  stop() {
82
80
  this.logger.log('Stopping subscription');
83
81
  if (this.eventHandler) {
84
82
  this.state.eventService.offLazy(this.eventHandler);
83
+ this.eventHandler = undefined;
85
84
  }
86
85
  this.stopAllSubscription();
87
86
  }
@@ -107,7 +106,7 @@ export class KoniSubscription {
107
106
  });
108
107
  }
109
108
  subscribeBalancesAndCrowdloans(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
110
- this.state.switchAccount(address).then(() => {
109
+ this.state.handleSwitchAccount(address).then(() => {
111
110
  const addresses = this.state.getDecodedAddresses(address);
112
111
  if (!addresses.length) {
113
112
  return;
@@ -178,9 +177,7 @@ export class KoniSubscription {
178
177
  nftHandler.setDotSamaApiMap(substrateApiMap);
179
178
  nftHandler.setWeb3ApiMap(evmApiMap);
180
179
  nftHandler.setAddresses(addresses);
181
- nftHandler.handleNfts(smartContractNfts, (...args) => this.state.updateNftData(...args), (...args) => this.state.setNftCollection(...args)).then(() => {
182
- this.logger.log('nft state updated');
183
- }).catch(this.logger.log);
180
+ nftHandler.handleNfts(smartContractNfts, (...args) => this.state.updateNftData(...args), (...args) => this.state.setNftCollection(...args), (...args) => this.state.cleanUpNfts(...args)).catch(this.logger.log);
184
181
  }
185
182
  async subscribeStakingReward(address) {
186
183
  const addresses = this.state.getDecodedAddresses(address);
@@ -197,7 +194,6 @@ export class KoniSubscription {
197
194
  });
198
195
  const result = await getNominationStakingRewardData(addresses, targetNetworkMap);
199
196
  this.state.updateStakingReward(result, 'slowInterval');
200
- this.logger.log('Set staking reward state done', result);
201
197
  }
202
198
  async subscribeStakingRewardFastInterval(address) {
203
199
  const addresses = this.state.getDecodedAddresses(address);
@@ -226,15 +222,21 @@ export class KoniSubscription {
226
222
  const [poolingStakingRewards, amplitudeUnclaimedStakingRewards] = await Promise.all([getPoolingStakingRewardData(pooledAddresses, targetChainMap, this.state.getSubstrateApiMap()), getAmplitudeUnclaimedStakingReward(this.state.getSubstrateApiMap(), addresses, chainInfoMap, activeNetworks)]);
227
223
  const result = [...poolingStakingRewards, ...amplitudeUnclaimedStakingRewards];
228
224
  this.state.updateStakingReward(result, 'fastInterval');
229
- this.logger.log('Set staking reward state with fast interval done', result);
230
225
  }
231
226
  async fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap) {
232
- await Promise.all(Object.values(chainInfoMap).map(async chainInfo => {
227
+ const filteredChainInfoMap = {};
228
+ Object.values(chainInfoMap).forEach(chainInfo => {
233
229
  const chainState = chainStateMap[chainInfo.slug];
234
230
  if (chainState !== null && chainState !== void 0 && chainState.active && _isChainSupportSubstrateStaking(chainInfo)) {
235
- const chainStakingMetadata = await getChainStakingMetadata(chainInfo.slug, substrateApiMap[chainInfo.slug]);
236
- this.state.updateChainStakingMetadata(chainStakingMetadata);
231
+ filteredChainInfoMap[chainInfo.slug] = chainInfo;
237
232
  }
233
+ });
234
+ if (Object.values(filteredChainInfoMap).length === 0) {
235
+ return;
236
+ }
237
+ await Promise.all(Object.values(filteredChainInfoMap).map(async chainInfo => {
238
+ const chainStakingMetadata = await getChainStakingMetadata(chainInfo, substrateApiMap[chainInfo.slug]);
239
+ this.state.updateChainStakingMetadata(chainStakingMetadata);
238
240
  }));
239
241
  }
240
242
  async fetchNominatorMetadata(currentAddress, chainInfoMap, chainStateMap, substrateApiMap) {
@@ -249,8 +251,7 @@ export class KoniSubscription {
249
251
  if (currentAddress === ALL_ACCOUNT_KEY) {
250
252
  addresses = await this.state.getStakingOwnersByChains(Object.keys(filteredChainInfoMap));
251
253
  }
252
- const validAddresses = addresses.filter(address => !isEthereumAddress(address));
253
- await Promise.all(validAddresses.map(async address => {
254
+ await Promise.all(addresses.map(async address => {
254
255
  const isEvmAddress = isEthereumAddress(address);
255
256
  await Promise.all(Object.values(filteredChainInfoMap).map(async chainInfo => {
256
257
  if (isEvmAddress && !_isChainEvmCompatible(chainInfo)) {
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.0.2-2",
20
+ "version": "1.0.2-3",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -369,6 +369,11 @@
369
369
  "require": "./cjs/koni/api/tokens/wasm/index.js",
370
370
  "default": "./koni/api/tokens/wasm/index.js"
371
371
  },
372
+ "./koni/api/tokens/wasm/utils": {
373
+ "types": "./koni/api/tokens/wasm/utils.d.ts",
374
+ "require": "./cjs/koni/api/tokens/wasm/utils.js",
375
+ "default": "./koni/api/tokens/wasm/utils.js"
376
+ },
372
377
  "./koni/api/xcm": {
373
378
  "types": "./koni/api/xcm/index.d.ts",
374
379
  "require": "./cjs/koni/api/xcm/index.js",
@@ -1634,7 +1639,7 @@
1634
1639
  "@polkadot/hw-ledger": "^10.1.9",
1635
1640
  "@polkadot/keyring": "^10.2.1",
1636
1641
  "@polkadot/networks": "^10.2.1",
1637
- "@polkadot/phishing": "^0.20.3",
1642
+ "@polkadot/phishing": "^0.21.1",
1638
1643
  "@polkadot/react-identicon": "^2.9.14",
1639
1644
  "@polkadot/react-qr": "^2.9.14",
1640
1645
  "@polkadot/rpc-provider": "^9.10.3",
@@ -1651,12 +1656,12 @@
1651
1656
  "@sora-substrate/type-definitions": "^1.12.4",
1652
1657
  "@subsocial/types": "^0.6.8",
1653
1658
  "@substrate/connect": "^0.7.18",
1654
- "@subwallet/chain-list": "^0.0.27",
1655
- "@subwallet/extension-base": "^1.0.2-2",
1656
- "@subwallet/extension-chains": "^1.0.2-2",
1657
- "@subwallet/extension-dapp": "^1.0.2-2",
1658
- "@subwallet/extension-inject": "^1.0.2-2",
1659
- "@subwallet/keyring": "^0.0.4",
1659
+ "@subwallet/chain-list": "^0.0.32",
1660
+ "@subwallet/extension-base": "^1.0.2-3",
1661
+ "@subwallet/extension-chains": "^1.0.2-3",
1662
+ "@subwallet/extension-dapp": "^1.0.2-3",
1663
+ "@subwallet/extension-inject": "^1.0.2-3",
1664
+ "@subwallet/keyring": "^0.0.5",
1660
1665
  "@subwallet/ui-keyring": "^0.0.3",
1661
1666
  "@unique-nft/types": "^0.6.0-4",
1662
1667
  "@zeitgeistpm/type-defs": "^0.10.0",
@@ -1687,10 +1692,10 @@
1687
1692
  "protobufjs": "^7.1.2",
1688
1693
  "rlp": "^3.0.0",
1689
1694
  "rxjs": "^7.8.0",
1690
- "web3": "^1.8.1",
1691
- "web3-core": "^1.8.1",
1692
- "web3-core-helpers": "^1.8.1",
1693
- "web3-eth-contract": "^1.8.1",
1694
- "web3-utils": "^1.8.1"
1695
+ "web3": "^1.9.0",
1696
+ "web3-core": "^1.9.0",
1697
+ "web3-core-helpers": "^1.9.0",
1698
+ "web3-eth-contract": "^1.9.0",
1699
+ "web3-utils": "^1.9.0"
1695
1700
  }
1696
1701
  }
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.0.2-2'
10
+ version: '1.0.2-3'
11
11
  };