@subwallet/extension-base 1.0.1 → 1.0.2-1b

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 (220) hide show
  1. package/background/KoniTypes.d.ts +25 -36
  2. package/background/KoniTypes.js +12 -7
  3. package/background/errors/TransactionError.js +21 -1
  4. package/cjs/background/KoniTypes.js +14 -8
  5. package/cjs/background/errors/TransactionError.js +20 -0
  6. package/cjs/constants/index.js +13 -28
  7. package/cjs/koni/api/dotsama/balance.js +60 -224
  8. package/cjs/koni/api/dotsama/transfer.js +30 -29
  9. package/cjs/koni/api/nft/acala_nft/index.js +4 -1
  10. package/cjs/koni/api/nft/bit.country/index.js +4 -1
  11. package/cjs/koni/api/nft/evm_nft/index.js +7 -3
  12. package/cjs/koni/api/nft/index.js +3 -6
  13. package/cjs/koni/api/nft/karura_nft/index.js +4 -1
  14. package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
  15. package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
  16. package/cjs/koni/api/nft/unique_nft/index.js +6 -1
  17. package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
  18. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  19. package/cjs/koni/api/staking/bonding/amplitude.js +18 -10
  20. package/cjs/koni/api/staking/bonding/astar.js +37 -238
  21. package/cjs/koni/api/staking/bonding/index.js +26 -14
  22. package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
  23. package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
  24. package/cjs/koni/api/staking/bonding/utils.js +55 -10
  25. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  26. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  27. package/cjs/koni/api/xcm/index.js +0 -111
  28. package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +3 -5
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +179 -77
  33. package/cjs/koni/background/handlers/Extension.js +231 -195
  34. package/cjs/koni/background/handlers/State.js +147 -111
  35. package/cjs/koni/background/handlers/Tabs.js +48 -39
  36. package/cjs/koni/background/subscription.js +64 -56
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/page/index.js +5 -0
  39. package/cjs/services/chain-service/constants.js +1 -11
  40. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  41. package/cjs/services/chain-service/handler/light-client/index.js +2 -0
  42. package/cjs/services/chain-service/index.js +39 -6
  43. package/cjs/services/chain-service/utils.js +4 -0
  44. package/cjs/services/event-service/index.js +75 -0
  45. package/cjs/services/event-service/types.js +11 -0
  46. package/cjs/services/history-service/index.js +46 -21
  47. package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
  48. package/cjs/services/keyring-service/index.js +101 -0
  49. package/cjs/services/migration-service/index.js +13 -10
  50. package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
  51. package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
  52. package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
  53. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
  54. package/cjs/services/migration-service/scripts/index.js +13 -4
  55. package/cjs/services/price-service/coingecko.js +15 -3
  56. package/cjs/services/price-service/index.js +15 -18
  57. package/cjs/services/request-service/constants.js +8 -2
  58. package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
  59. package/cjs/services/request-service/index.js +3 -0
  60. package/cjs/services/storage-service/DatabaseService.js +53 -34
  61. package/cjs/services/storage-service/databases/index.js +1 -1
  62. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  63. package/cjs/services/storage-service/db-stores/Nft.js +8 -18
  64. package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
  65. package/cjs/services/subscan-service/index.js +107 -0
  66. package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
  67. package/cjs/services/subscan-service/types.js +1 -0
  68. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  69. package/cjs/services/transaction-service/index.js +66 -22
  70. package/cjs/services/transaction-service/utils.js +4 -6
  71. package/cjs/utils/address.js +9 -1
  72. package/cjs/utils/index.js +30 -26
  73. package/constants/index.d.ts +8 -13
  74. package/constants/index.js +8 -13
  75. package/koni/api/dotsama/balance.d.ts +0 -1
  76. package/koni/api/dotsama/balance.js +33 -197
  77. package/koni/api/dotsama/transfer.js +5 -4
  78. package/koni/api/nft/acala_nft/index.js +3 -1
  79. package/koni/api/nft/bit.country/index.js +3 -1
  80. package/koni/api/nft/evm_nft/index.js +6 -3
  81. package/koni/api/nft/index.d.ts +1 -2
  82. package/koni/api/nft/index.js +3 -6
  83. package/koni/api/nft/karura_nft/index.js +3 -1
  84. package/koni/api/nft/nft.d.ts +1 -0
  85. package/koni/api/nft/rmrk_nft/index.js +8 -1
  86. package/koni/api/nft/statemine_nft/index.js +3 -1
  87. package/koni/api/nft/unique_nft/index.js +5 -1
  88. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  89. package/koni/api/nft/wasm_nft/index.js +167 -109
  90. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  91. package/koni/api/nft/wasm_nft/utils.js +7 -5
  92. package/koni/api/staking/bonding/amplitude.d.ts +1 -2
  93. package/koni/api/staking/bonding/amplitude.js +22 -13
  94. package/koni/api/staking/bonding/astar.d.ts +2 -11
  95. package/koni/api/staking/bonding/astar.js +39 -231
  96. package/koni/api/staking/bonding/index.d.ts +5 -2
  97. package/koni/api/staking/bonding/index.js +27 -17
  98. package/koni/api/staking/bonding/paraChain.d.ts +4 -1
  99. package/koni/api/staking/bonding/paraChain.js +101 -14
  100. package/koni/api/staking/bonding/relayChain.d.ts +6 -2
  101. package/koni/api/staking/bonding/relayChain.js +172 -17
  102. package/koni/api/staking/bonding/utils.d.ts +15 -2
  103. package/koni/api/staking/bonding/utils.js +53 -11
  104. package/koni/api/tokens/wasm/index.js +5 -4
  105. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  106. package/koni/api/tokens/wasm/utils.js +54 -0
  107. package/koni/api/xcm/index.js +1 -112
  108. package/koni/api/xcm/polkadotXcm.js +3 -3
  109. package/koni/api/xcm/utils.d.ts +5 -6
  110. package/koni/api/xcm/utils.js +15 -10
  111. package/koni/api/xcm/xTokens.js +5 -7
  112. package/koni/api/xcm/xcmPallet.js +10 -9
  113. package/koni/background/cron.d.ts +6 -1
  114. package/koni/background/cron.js +179 -76
  115. package/koni/background/handlers/Extension.d.ts +2 -2
  116. package/koni/background/handlers/Extension.js +161 -125
  117. package/koni/background/handlers/State.d.ts +21 -20
  118. package/koni/background/handlers/State.js +144 -111
  119. package/koni/background/handlers/Tabs.js +30 -20
  120. package/koni/background/subscription.d.ts +1 -1
  121. package/koni/background/subscription.js +64 -58
  122. package/package.json +63 -18
  123. package/packageInfo.js +1 -1
  124. package/page/index.d.ts +2 -0
  125. package/page/index.js +4 -0
  126. package/services/chain-service/constants.d.ts +0 -1
  127. package/services/chain-service/constants.js +0 -9
  128. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  129. package/services/chain-service/handler/light-client/index.d.ts +17 -1
  130. package/services/chain-service/handler/light-client/index.js +1 -1
  131. package/services/chain-service/helper/psp22_abi.json +1041 -881
  132. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  133. package/services/chain-service/index.d.ts +6 -4
  134. package/services/chain-service/index.js +40 -9
  135. package/services/chain-service/utils.d.ts +1 -0
  136. package/services/chain-service/utils.js +3 -0
  137. package/services/event-service/index.d.ts +22 -0
  138. package/services/event-service/index.js +63 -0
  139. package/services/event-service/types.d.ts +28 -0
  140. package/services/event-service/types.js +4 -0
  141. package/services/history-service/index.d.ts +5 -3
  142. package/services/history-service/index.js +46 -21
  143. package/services/history-service/subsquid-multi-chain-history.js +22 -13
  144. package/services/keyring-service/index.d.ts +19 -0
  145. package/services/keyring-service/index.js +93 -0
  146. package/services/migration-service/index.js +11 -9
  147. package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
  148. package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
  149. package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
  150. package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
  151. package/services/migration-service/scripts/MigrateSettings.js +23 -0
  152. package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
  153. package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
  154. package/services/migration-service/scripts/index.d.ts +1 -0
  155. package/services/migration-service/scripts/index.js +10 -3
  156. package/services/price-service/coingecko.js +15 -3
  157. package/services/price-service/index.d.ts +5 -3
  158. package/services/price-service/index.js +15 -18
  159. package/services/request-service/constants.d.ts +1 -0
  160. package/services/request-service/constants.js +6 -1
  161. package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
  162. package/services/request-service/handler/AuthRequestHandler.js +44 -13
  163. package/services/request-service/index.d.ts +7 -1
  164. package/services/request-service/index.js +3 -0
  165. package/services/storage-service/DatabaseService.d.ts +1 -0
  166. package/services/storage-service/DatabaseService.js +53 -34
  167. package/services/storage-service/databases/index.js +1 -1
  168. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
  169. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  170. package/services/storage-service/db-stores/Nft.d.ts +3 -3
  171. package/services/storage-service/db-stores/Nft.js +8 -17
  172. package/services/storage-service/db-stores/Transaction.js +10 -7
  173. package/services/subscan-service/index.d.ts +20 -0
  174. package/services/subscan-service/index.js +99 -0
  175. package/services/subscan-service/subscan-chain-map.d.ts +5 -0
  176. package/services/subscan-service/subscan-chain-map.js +63 -0
  177. package/services/subscan-service/types.d.ts +27 -0
  178. package/services/subscan-service/types.js +1 -0
  179. package/services/transaction-service/event-parser/index.d.ts +2 -2
  180. package/services/transaction-service/event-parser/index.js +21 -49
  181. package/services/transaction-service/index.d.ts +4 -2
  182. package/services/transaction-service/index.js +66 -22
  183. package/services/transaction-service/utils.js +5 -6
  184. package/utils/address.d.ts +1 -0
  185. package/utils/address.js +9 -2
  186. package/utils/index.d.ts +2 -1
  187. package/utils/index.js +26 -23
  188. package/cjs/background/errors/EvmRpcError.js +0 -21
  189. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  190. package/cjs/constants/ethereum.js +0 -19
  191. package/cjs/errors/SubWalletProviderError.js +0 -17
  192. package/cjs/koni/api/xcm/astar.js +0 -160
  193. package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
  194. package/cjs/koni/api/xcm/statemintXcm.js +0 -197
  195. package/cjs/koni/api/xcm/substrateXcm.js +0 -213
  196. package/cjs/koni/migration/Base.js +0 -20
  197. package/cjs/koni/migration/index.js +0 -45
  198. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
  199. package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
  200. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
  201. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
  202. package/cjs/koni/migration/scripts/index.js +0 -22
  203. package/cjs/koni/page/index.js +0 -16
  204. package/cjs/services/asset-service/index.js +0 -91
  205. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
  206. package/cjs/stores/Balance.js +0 -18
  207. package/cjs/stores/Crowdloan.js +0 -18
  208. package/cjs/stores/CustomEvmToken.js +0 -18
  209. package/cjs/stores/NetworkMap.js +0 -18
  210. package/cjs/stores/Nft.js +0 -18
  211. package/cjs/stores/NftCollection.js +0 -18
  212. package/cjs/stores/Price.js +0 -18
  213. package/cjs/stores/Staking.js +0 -18
  214. package/cjs/stores/StakingReward.js +0 -18
  215. package/cjs/utils/eth/parseTransactionData.js +0 -284
  216. package/koni/page/index.d.ts +0 -2
  217. package/koni/page/index.js +0 -9
  218. /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
  219. /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
  220. /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
@@ -1,6 +1,7 @@
1
1
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
2
2
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
3
3
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
4
+ import { EventService } from '@subwallet/extension-base/services/event-service';
4
5
  import { HistoryService } from '@subwallet/extension-base/services/history-service';
5
6
  import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
6
7
  import RequestService from '@subwallet/extension-base/services/request-service';
@@ -11,6 +12,7 @@ import { TransactionConfig } from 'web3-core';
11
12
  import { HexString } from '@polkadot/util/types';
12
13
  export default class TransactionService {
13
14
  private readonly chainService;
15
+ private readonly eventService;
14
16
  private readonly databaseService;
15
17
  private readonly requestService;
16
18
  private readonly balanceService;
@@ -18,7 +20,7 @@ export default class TransactionService {
18
20
  private readonly notificationService;
19
21
  private readonly transactionSubject;
20
22
  private get transactions();
21
- constructor(chainService: ChainService, requestService: RequestService, balanceService: BalanceService, historyService: HistoryService, notificationService: NotificationService, databaseService: DatabaseService);
23
+ constructor(chainService: ChainService, eventService: EventService, requestService: RequestService, balanceService: BalanceService, historyService: HistoryService, notificationService: NotificationService, databaseService: DatabaseService);
22
24
  private get allTransactions();
23
25
  private get processingTransactions();
24
26
  getTransaction(id: string): SWTransaction;
@@ -33,7 +35,7 @@ export default class TransactionService {
33
35
  private removeTransaction;
34
36
  private updateTransaction;
35
37
  private getTransactionLink;
36
- private transactionToHistory;
38
+ private transactionToHistories;
37
39
  private onHasTransactionHash;
38
40
  private handlePostProcessing;
39
41
  private onSuccess;
@@ -24,8 +24,9 @@ export default class TransactionService {
24
24
  get transactions() {
25
25
  return this.transactionSubject.getValue();
26
26
  }
27
- constructor(chainService, requestService, balanceService, historyService, notificationService, databaseService) {
27
+ constructor(chainService, eventService, requestService, balanceService, historyService, notificationService, databaseService) {
28
28
  this.chainService = chainService;
29
+ this.eventService = eventService;
29
30
  this.requestService = requestService;
30
31
  this.balanceService = balanceService;
31
32
  this.historyService = historyService;
@@ -265,9 +266,10 @@ export default class TransactionService {
265
266
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
266
267
  return getTransactionLink(chainInfo, transaction.extrinsicHash);
267
268
  }
268
- transactionToHistory(id, eventLogs) {
269
+ transactionToHistories(id, eventLogs) {
269
270
  const transaction = this.getTransaction(id);
270
271
  const historyItem = {
272
+ origin: 'app',
271
273
  chain: transaction.chain,
272
274
  direction: TransactionDirection.SEND,
273
275
  type: transaction.extrinsicType,
@@ -280,8 +282,8 @@ export default class TransactionService {
280
282
  time: transaction.createdAt.getTime(),
281
283
  fee: transaction.estimateFee,
282
284
  blockNumber: 0,
283
- // TODO: to be added later
284
- blockHash: '' // TODO: to be added later
285
+ // Will be added in next step
286
+ blockHash: '' // Will be added in next step
285
287
  };
286
288
 
287
289
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
@@ -330,6 +332,12 @@ export default class TransactionService {
330
332
  decimals: sendingTokenInfo.decimals || 0,
331
333
  symbol: sendingTokenInfo.symbol
332
334
  };
335
+
336
+ // @ts-ignore
337
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
338
+ historyItem.additionalInfo = {
339
+ destinationChain: (inputData === null || inputData === void 0 ? void 0 : inputData.destinationNetworkKey) || ''
340
+ };
333
341
  eventLogs && parseXcmEventLogs(historyItem, eventLogs, transaction.chain, sendingTokenInfo, chainInfo);
334
342
  }
335
343
  break;
@@ -396,15 +404,41 @@ export default class TransactionService {
396
404
  {
397
405
  const data = parseTransactionData(transaction.data);
398
406
  historyItem.to = data.validatorAddress || '';
407
+ historyItem.amount = {
408
+ ...baseNativeAmount,
409
+ value: data.unstakingInfo.claimable || '0'
410
+ };
411
+ break;
412
+ }
413
+ case ExtrinsicType.STAKING_CANCEL_UNSTAKE:
414
+ {
415
+ const data = parseTransactionData(transaction.data);
416
+ historyItem.amount = {
417
+ ...baseNativeAmount,
418
+ value: data.selectedUnstaking.claimable || '0'
419
+ };
420
+ break;
399
421
  }
400
- break;
401
422
  case ExtrinsicType.EVM_EXECUTE:
402
423
  // Todo: Update historyItem.to
403
424
  break;
404
425
  case ExtrinsicType.UNKNOWN:
405
426
  break;
406
427
  }
407
- return historyItem;
428
+ try {
429
+ // Return one more history record if transaction send to account in the wallets
430
+ const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && keyring.getPair(historyItem.to);
431
+ if (toAccount) {
432
+ return [historyItem, {
433
+ ...historyItem,
434
+ address: toAccount.address,
435
+ direction: TransactionDirection.RECEIVED
436
+ }];
437
+ }
438
+ } catch (e) {
439
+ console.warn(e);
440
+ }
441
+ return [historyItem];
408
442
  }
409
443
  onHasTransactionHash({
410
444
  eventLogs,
@@ -416,24 +450,33 @@ export default class TransactionService {
416
450
  extrinsicHash,
417
451
  status: ExtrinsicStatus.PROCESSING
418
452
  });
419
- this.historyService.insertHistory(this.transactionToHistory(id, eventLogs)).catch(console.error);
453
+ this.historyService.insertHistories(this.transactionToHistories(id, eventLogs)).catch(console.error);
420
454
  console.log(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
421
455
  }
422
456
  handlePostProcessing(id) {
423
457
  // must be done after success/failure to make sure the transaction is finalized
424
458
  const transaction = this.getTransaction(id);
425
- switch (transaction.extrinsicType) {
426
- case ExtrinsicType.SEND_NFT:
427
- {
428
- const inputData = parseTransactionData(transaction.data);
429
- const sender = keyring.getAccount(inputData.senderAddress);
430
- const recipient = keyring.getAccount(inputData.recipientAddress);
431
- sender && this.databaseService.handleNftTransfer(transaction.chain, [sender.address, ALL_ACCOUNT_KEY], inputData.nftItem).catch(console.error);
432
- recipient && this.databaseService.addNft(recipient.address, {
433
- ...inputData.nftItem,
434
- owner: recipient.address
435
- }).catch(console.error);
436
- }
459
+ if (transaction.extrinsicType === ExtrinsicType.SEND_NFT) {
460
+ const inputData = parseTransactionData(transaction.data);
461
+ try {
462
+ const sender = keyring.getPair(inputData.senderAddress);
463
+ sender && this.databaseService.handleNftTransfer(transaction.chain, [sender.address, ALL_ACCOUNT_KEY], inputData.nftItem).then(() => {
464
+ this.eventService.emit('transaction.transferNft', undefined);
465
+ }).catch(console.error);
466
+ } catch (e) {
467
+ console.error(e);
468
+ }
469
+ try {
470
+ const recipient = keyring.getPair(inputData.recipientAddress);
471
+ recipient && this.databaseService.addNft(recipient.address, {
472
+ ...inputData.nftItem,
473
+ owner: recipient.address
474
+ }).catch(console.error);
475
+ } catch (e) {
476
+ console.error(e);
477
+ }
478
+ } else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) {
479
+ this.eventService.emit('transaction.submitStaking', transaction.chain);
437
480
  }
438
481
  }
439
482
  onSuccess({
@@ -448,7 +491,7 @@ export default class TransactionService {
448
491
  console.log('Transaction completed', id, transaction.extrinsicHash);
449
492
 
450
493
  // Write success transaction history
451
- this.historyService.updateHistory(transaction.chain, transaction.extrinsicHash, {
494
+ this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
452
495
  status: ExtrinsicStatus.SUCCESS,
453
496
  blockNumber: blockNumber || 0,
454
497
  blockHash: blockHash || ''
@@ -462,6 +505,7 @@ export default class TransactionService {
462
505
  },
463
506
  notifyViaBrowser: true
464
507
  });
508
+ this.eventService.emit('transaction.done', transaction);
465
509
  }
466
510
  onFailed({
467
511
  blockHash,
@@ -478,7 +522,7 @@ export default class TransactionService {
478
522
  console.log('Transaction failed', id, transaction.extrinsicHash);
479
523
 
480
524
  // Write failed transaction history
481
- this.historyService.updateHistory(transaction.chain, transaction.extrinsicHash, {
525
+ this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
482
526
  status: ExtrinsicStatus.FAIL,
483
527
  blockNumber: blockNumber || 0,
484
528
  blockHash: blockHash || ''
@@ -493,7 +537,7 @@ export default class TransactionService {
493
537
  notifyViaBrowser: true
494
538
  });
495
539
  }
496
-
540
+ this.eventService.emit('transaction.failed', transaction);
497
541
  // Log transaction errors
498
542
  console.error(errors);
499
543
  }
@@ -1,22 +1,21 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { _getBlockExplorerFromChain, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
5
+
4
6
  // @ts-ignore
5
7
  export function parseTransactionData(data) {
6
- // @ts-ignore
7
8
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
8
9
  return data;
9
10
  }
10
11
  export function getTransactionLink(chainInfo, extrinsicHash) {
11
- if (chainInfo.evmInfo) {
12
- var _chainInfo$evmInfo;
13
- const explorerLink = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.blockExplorer;
12
+ const explorerLink = _getBlockExplorerFromChain(chainInfo);
13
+ if (_isPureEvmChain(chainInfo)) {
14
14
  if (explorerLink) {
15
15
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
16
16
  }
17
17
  } else {
18
- var _chainInfo$substrateI;
19
- const explorerLink = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI = chainInfo.substrateInfo) === null || _chainInfo$substrateI === void 0 ? void 0 : _chainInfo$substrateI.blockExplorer;
18
+ const explorerLink = _getBlockExplorerFromChain(chainInfo);
20
19
  if (explorerLink) {
21
20
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
22
21
  }
@@ -1 +1,2 @@
1
1
  export declare const simpleAddress: (address: string) => string;
2
+ export declare function quickFormatAddressToCompare(address?: string): string | undefined;
package/utils/address.js CHANGED
@@ -1,10 +1,17 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { decodeAddress, encodeAddress, isEthereumAddress } from '@polkadot/util-crypto';
4
+ import { reformatAddress } from '@subwallet/extension-base/utils/index';
5
+ import { decodeAddress, encodeAddress, isAddress, isEthereumAddress } from '@polkadot/util-crypto';
5
6
  export const simpleAddress = address => {
6
7
  if (isEthereumAddress(address)) {
7
8
  return address;
8
9
  }
9
10
  return encodeAddress(decodeAddress(address));
10
- };
11
+ };
12
+ export function quickFormatAddressToCompare(address) {
13
+ if (!isAddress(address)) {
14
+ return address;
15
+ }
16
+ return reformatAddress(address, 42).toLowerCase();
17
+ }
package/utils/index.d.ts CHANGED
@@ -34,5 +34,6 @@ export declare function mergeNetworkProviders(customNetwork: NetworkJson, predef
34
34
  };
35
35
  export declare const filterAndSortingAccountByAuthType: (accounts: AccountJson[], accountAuthType: AccountAuthType, sorting?: boolean) => AccountJson[];
36
36
  export declare function parseRawNumber(value: string): number;
37
- export declare function parseNumberToDisplay(amount: BN, decimals: number | undefined): string;
38
37
  export declare function isSameAddress(address1: string, address2: string): boolean;
38
+ export declare function getDomainFromUrl(url: string): string;
39
+ export declare function waitTimeout(ms: number): Promise<void>;
package/utils/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  import { CrowdloanParaState } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
6
- import BigNumber from 'bignumber.js';
7
6
  import { BN, hexToU8a, isHex } from '@polkadot/util';
8
7
  import { decodeAddress, encodeAddress, ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
9
8
  export { canDerive } from "./canDerive.js";
@@ -15,20 +14,25 @@ export function isAccountAll(address) {
15
14
  return address === ALL_ACCOUNT_KEY;
16
15
  }
17
16
  export function reformatAddress(address, networkPrefix, isEthereum = false) {
18
- if (isEthereumAddress(address)) {
19
- return address;
20
- }
21
- if (isAccountAll(address)) {
22
- return address;
23
- }
24
- const publicKey = decodeAddress(address);
25
- if (isEthereum) {
26
- return ethereumEncode(publicKey);
27
- }
28
- if (networkPrefix < 0) {
17
+ try {
18
+ if (isEthereumAddress(address)) {
19
+ return address;
20
+ }
21
+ if (isAccountAll(address)) {
22
+ return address;
23
+ }
24
+ const publicKey = decodeAddress(address);
25
+ if (isEthereum) {
26
+ return ethereumEncode(publicKey);
27
+ }
28
+ if (networkPrefix < 0) {
29
+ return address;
30
+ }
31
+ return encodeAddress(publicKey, networkPrefix);
32
+ } catch (e) {
33
+ console.warn('Get error while reformat address', address, e);
29
34
  return address;
30
35
  }
31
- return encodeAddress(publicKey, networkPrefix);
32
36
  }
33
37
  export function filterAddressByNetworkKey(addresses, networkKey, isEthereum) {
34
38
  if (isEthereum) {
@@ -259,17 +263,16 @@ export const filterAndSortingAccountByAuthType = (accounts, accountAuthType, sor
259
263
  export function parseRawNumber(value) {
260
264
  return parseFloat(value.replaceAll(',', ''));
261
265
  }
262
- export function parseNumberToDisplay(amount, decimals) {
263
- if (!decimals) {
264
- return '0';
266
+ export function isSameAddress(address1, address2) {
267
+ if (isEthereumAddress(address1)) {
268
+ return address1.toLowerCase() === address2.toLowerCase();
265
269
  }
266
- const parsedAmount = parseRawNumber(amount.toString());
267
- const bigN = new BigNumber(parsedAmount / 10 ** decimals);
268
- const roundedString = bigN.toFixed(9);
269
- const formattedString = parseFloat(roundedString); // remove excess zeros at the end
270
+ return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
271
+ }
270
272
 
271
- return formattedString.toString();
273
+ export function getDomainFromUrl(url) {
274
+ return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
272
275
  }
273
- export function isSameAddress(address1, address2) {
274
- return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
276
+ export async function waitTimeout(ms) {
277
+ return new Promise(resolve => setTimeout(resolve, ms));
275
278
  }
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.EvmRpcError = void 0;
7
- var _ethereum = require("@subwallet/extension-base/constants/ethereum");
8
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
9
- // SPDX-License-Identifier: Apache-2.0
10
-
11
- class EvmRpcError extends Error {
12
- constructor(type, message, data) {
13
- const [code, prefix] = _ethereum.EVM_PROVIDER_RPC_ERRORS_MAP[type];
14
- const finalMessage = message ? `${prefix}: ${message}` : prefix;
15
- super(finalMessage);
16
- this.code = code;
17
- this.message = finalMessage;
18
- this.data = data;
19
- }
20
- }
21
- exports.EvmRpcError = EvmRpcError;
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SubWalletProviderError = void 0;
7
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
8
- // SPDX-License-Identifier: Apache-2.0
9
-
10
- class SubWalletProviderError extends Error {
11
- constructor(message, code, data) {
12
- super(message);
13
- this.code = code;
14
- this.data = data;
15
- }
16
- }
17
- exports.SubWalletProviderError = SubWalletProviderError;
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.EVM_PROVIDER_RPC_ERRORS_MAP = void 0;
7
- // Copyright 2019-2022 @subwallet/extension-base authors & contributors
8
- // SPDX-License-Identifier: Apache-2.0
9
-
10
- const EVM_PROVIDER_RPC_ERRORS_MAP = {
11
- USER_REJECTED_REQUEST: [4001, 'User Rejected Request'],
12
- UNAUTHORIZED: [4100, 'Unauthorized'],
13
- UNSUPPORTED_METHOD: [4200, 'Unsupported Method'],
14
- DISCONNECTED: [4900, 'Disconnected'],
15
- CHAIN_DISCONNECTED: [4901, 'Chain Disconnected'],
16
- INVALID_PARAMS: [-32602, 'Invalid Params'],
17
- INTERNAL_ERROR: [-32603, 'Internal Error']
18
- };
19
- exports.EVM_PROVIDER_RPC_ERRORS_MAP = EVM_PROVIDER_RPC_ERRORS_MAP;
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SubWalletProviderError = void 0;
7
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
8
- // SPDX-License-Identifier: Apache-2.0
9
-
10
- class SubWalletProviderError extends Error {
11
- constructor(message, code, data) {
12
- super(message);
13
- this.code = code;
14
- this.data = data;
15
- }
16
- }
17
- exports.SubWalletProviderError = SubWalletProviderError;
@@ -1,160 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.astarEstimateCrossChainFee = astarEstimateCrossChainFee;
7
- exports.astarGetXcmExtrinsic = astarGetXcmExtrinsic;
8
- var _utils = require("@subwallet/extension-base/services/chain-service/utils");
9
- var _utilCrypto = require("@polkadot/util-crypto");
10
- // Copyright 2019-2022 @subwallet/extension-base
11
- // SPDX-License-Identifier: Apache-2.0
12
-
13
- // const ASSET_TO_LOCATION_MAP: Record<string, Record<string, Record<string, any>>> = {
14
- // astar: {
15
- // '18446744073709551617': { // aUSD
16
- // parents: 1, interior: { X2: [{ Parachain: 2000 }, { GeneralKey: '0x0001' }] }
17
- // },
18
- // '340282366920938463463374607431768211455': { // DOT
19
- // parents: 1, interior: 'Here'
20
- // }
21
- // },
22
- // shiden: {
23
- // '18446744073709551616': { // aUSD
24
- // parents: 1, interior: { X2: [{ Parachain: 2000 }, { GeneralKey: '0x0081' }] }
25
- // },
26
- // '340282366920938463463374607431768211455': {
27
- // parents: 1, interior: 'Here'
28
- // }
29
- // }
30
- // };
31
-
32
- async function astarEstimateCrossChainFee(originNetworkKey, destinationNetworkKey, recipient, sender, sendingValue, substrateApiMap, originTokenInfo, chainInfoMap) {
33
- const substrateApi = await substrateApiMap[originNetworkKey].isReady;
34
- const destinationChainInfo = chainInfoMap[destinationNetworkKey];
35
-
36
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
37
- const assetLocation = (0, _utils._getXcmAssetMultilocation)(originTokenInfo);
38
- let receiverLocation = {
39
- AccountId32: {
40
- network: 'Any',
41
- id: (0, _utilCrypto.decodeAddress)(recipient)
42
- }
43
- };
44
- let destinationChainLocation = {
45
- V1: {
46
- // find the destination chain
47
- parents: 1,
48
- interior: {
49
- X1: {
50
- Parachain: (0, _utils._getSubstrateParaId)(destinationChainInfo)
51
- }
52
- }
53
- }
54
- };
55
- if ((0, _utils._isChainEvmCompatible)(destinationChainInfo)) {
56
- receiverLocation = {
57
- AccountKey20: {
58
- network: 'Any',
59
- id: recipient
60
- }
61
- };
62
- }
63
- if ((0, _utils._isSubstrateRelayChain)(destinationChainInfo)) {
64
- // check if sending to relaychain
65
- destinationChainLocation = {
66
- V1: {
67
- // find the destination chain
68
- parents: 1,
69
- interior: 'Here'
70
- }
71
- };
72
- }
73
- const extrinsic = substrateApi.api.tx.polkadotXcm.reserveWithdrawAssets(destinationChainLocation, {
74
- V1: {
75
- // find the receiver
76
- parents: 0,
77
- // parents for beneficiary is always 0
78
- interior: {
79
- X1: receiverLocation
80
- }
81
- }
82
- }, {
83
- V1: [
84
- // find the asset
85
- {
86
- id: {
87
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
88
- Concrete: assetLocation
89
- },
90
- fun: {
91
- Fungible: sendingValue
92
- }
93
- }]
94
- }, 0);
95
- console.log('astar xcm tx here', extrinsic.toHex());
96
- const paymentInfo = await extrinsic.paymentInfo(sender);
97
- return paymentInfo.partialFee.toString();
98
- }
99
- function astarGetXcmExtrinsic(originNetworkKey, destinationNetworkKey, recipient, sendingValue, api, originTokenInfo, chainInfoMap) {
100
- const destinationChainInfo = chainInfoMap[destinationNetworkKey];
101
-
102
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
103
- const assetLocation = (0, _utils._getXcmAssetMultilocation)(originTokenInfo);
104
- let receiverLocation = {
105
- AccountId32: {
106
- network: 'Any',
107
- id: (0, _utilCrypto.decodeAddress)(recipient)
108
- }
109
- };
110
- let destinationChainLocation = {
111
- V1: {
112
- // find the destination chain
113
- parents: 1,
114
- interior: {
115
- X1: {
116
- Parachain: (0, _utils._getSubstrateParaId)(destinationChainInfo)
117
- }
118
- }
119
- }
120
- };
121
- if ((0, _utils._isChainEvmCompatible)(destinationChainInfo)) {
122
- receiverLocation = {
123
- AccountKey20: {
124
- network: 'Any',
125
- id: recipient
126
- }
127
- };
128
- }
129
- if ((0, _utils._isSubstrateRelayChain)(destinationChainInfo)) {
130
- destinationChainLocation = {
131
- V1: {
132
- // find the destination chain
133
- parents: 1,
134
- interior: 'Here'
135
- }
136
- };
137
- }
138
- return api.tx.polkadotXcm.reserveWithdrawAssets(destinationChainLocation, {
139
- V1: {
140
- // find the receiver
141
- parents: 0,
142
- // parents for beneficiary is always 0
143
- interior: {
144
- X1: receiverLocation
145
- }
146
- }
147
- }, {
148
- V1: [
149
- // find the asset
150
- {
151
- id: {
152
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
153
- Concrete: assetLocation
154
- },
155
- fun: {
156
- Fungible: sendingValue
157
- }
158
- }]
159
- }, 0);
160
- }
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.moonbeamEstimateCrossChainFee = moonbeamEstimateCrossChainFee;
7
- exports.moonbeamGetXcmExtrinsic = moonbeamGetXcmExtrinsic;
8
- var _chainList = require("@subwallet/chain-list");
9
- var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
10
- var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
11
- var _util = require("@polkadot/util");
12
- // Copyright 2019-2022 @subwallet/extension-base
13
- // SPDX-License-Identifier: Apache-2.0
14
-
15
- // enum MOON_ASSET_TYPES {
16
- // ForeignAsset = 'ForeignAsset',
17
- // SelfReserve = 'SelfReserve',
18
- // LocalAssetReserve = 'LocalAssetReserve',
19
- // }
20
-
21
- // const TOKEN_TYPE_MAP: Record<string, Record<string, string>> = {
22
- // moonbase: {
23
- // xcKAR: MOON_ASSET_TYPES.ForeignAsset,
24
- // xcUNIT: MOON_ASSET_TYPES.ForeignAsset,
25
- // xcBSX: MOON_ASSET_TYPES.ForeignAsset,
26
- // xcBNC: MOON_ASSET_TYPES.ForeignAsset,
27
- // xcKMA: MOON_ASSET_TYPES.ForeignAsset,
28
- // xcCSM: MOON_ASSET_TYPES.ForeignAsset,
29
- // xckUSD: MOON_ASSET_TYPES.ForeignAsset,
30
- // xcPHA: MOON_ASSET_TYPES.ForeignAsset,
31
- // xcKINT: MOON_ASSET_TYPES.ForeignAsset,
32
- // xckBTC: MOON_ASSET_TYPES.ForeignAsset,
33
- // xcLIT: MOON_ASSET_TYPES.ForeignAsset,
34
- // xcHKO: MOON_ASSET_TYPES.ForeignAsset,
35
- // xcMRMRK: MOON_ASSET_TYPES.ForeignAsset
36
- // },
37
- // moonriver: {
38
- // xcKSM: MOON_ASSET_TYPES.ForeignAsset,
39
- // xcBNC: MOON_ASSET_TYPES.ForeignAsset,
40
- // xcKMA: MOON_ASSET_TYPES.ForeignAsset,
41
- // xcCSM: MOON_ASSET_TYPES.ForeignAsset,
42
- // xcHKO: MOON_ASSET_TYPES.ForeignAsset,
43
- // xcKAR: MOON_ASSET_TYPES.ForeignAsset,
44
- // xcAUSD: MOON_ASSET_TYPES.ForeignAsset,
45
- // xcPHA: MOON_ASSET_TYPES.ForeignAsset,
46
- // xcKINT: MOON_ASSET_TYPES.ForeignAsset,
47
- // xckBTC: MOON_ASSET_TYPES.ForeignAsset,
48
- // xcRMRK: MOON_ASSET_TYPES.ForeignAsset,
49
- // xcUSDT: MOON_ASSET_TYPES.ForeignAsset
50
- // },
51
- // moonbeam: {
52
- // xcDOT: MOON_ASSET_TYPES.ForeignAsset,
53
- // xcaUSD: MOON_ASSET_TYPES.ForeignAsset,
54
- // xcACA: MOON_ASSET_TYPES.ForeignAsset,
55
- // xcINTR: MOON_ASSET_TYPES.ForeignAsset,
56
- // xciBTC: MOON_ASSET_TYPES.ForeignAsset
57
- // }
58
- // };
59
-
60
- async function moonbeamEstimateCrossChainFee(originNetworkKey, destinationNetworkKey, recipient, sender, sendingValue, substrateApiMap, originTokenInfo, chainInfoMap) {
61
- const substrateApi = await substrateApiMap[originNetworkKey].isReady;
62
- const tokenType = (0, _utils2._getXcmAssetType)(originTokenInfo);
63
- const assetId = (0, _utils2._getXcmAssetId)(originTokenInfo);
64
- const weightParam = originNetworkKey === _chainList.COMMON_CHAIN_SLUGS.MOONRIVER ? _utils.POLKADOT_UNLIMITED_WEIGHT : _utils.FOUR_INSTRUCTIONS_WEIGHT;
65
- const extrinsic = substrateApi.api.tx.xTokens.transfer({
66
- [tokenType]: new _util.BN(assetId)
67
- }, sendingValue, (0, _utils.getMultiLocationFromParachain)(originNetworkKey, destinationNetworkKey, chainInfoMap, recipient), weightParam);
68
- console.log('moon xcm tx here', extrinsic.toHex());
69
- const paymentInfo = await extrinsic.paymentInfo(sender);
70
- const fee = paymentInfo.partialFee.toString();
71
- return fee;
72
- }
73
- function moonbeamGetXcmExtrinsic(originNetworkKey, destinationNetworkKey, recipient, sendingValue, api, originTokenInfo, chainInfoMap) {
74
- const tokenType = (0, _utils2._getXcmAssetType)(originTokenInfo);
75
- const assetId = (0, _utils2._getXcmAssetId)(originTokenInfo);
76
- const weightParam = originNetworkKey === 'moonriver' ? _utils.POLKADOT_UNLIMITED_WEIGHT : _utils.FOUR_INSTRUCTIONS_WEIGHT;
77
- return api.tx.xTokens.transfer({
78
- [tokenType]: new _util.BN(assetId)
79
- }, sendingValue, (0, _utils.getMultiLocationFromParachain)(originNetworkKey, destinationNetworkKey, chainInfoMap, recipient), weightParam);
80
- }