@subwallet/extension-base 1.0.4-0 → 1.0.5-1

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 (169) hide show
  1. package/background/KoniTypes.d.ts +37 -16
  2. package/background/KoniTypes.js +2 -0
  3. package/background/errors/TransactionError.js +4 -0
  4. package/background/handlers/State.d.ts +1 -1
  5. package/background/handlers/State.js +2 -8
  6. package/background/handlers/subscriptions.js +0 -1
  7. package/background/types.d.ts +2 -2
  8. package/cjs/background/KoniTypes.js +2 -0
  9. package/cjs/background/errors/TransactionError.js +4 -0
  10. package/cjs/background/handlers/State.js +1 -7
  11. package/cjs/background/handlers/subscriptions.js +0 -1
  12. package/cjs/constants/index.js +6 -6
  13. package/cjs/koni/api/coingecko.js +1 -4
  14. package/cjs/koni/api/dotsama/balance.js +7 -5
  15. package/cjs/koni/api/dotsama/crowdloan.js +0 -4
  16. package/cjs/koni/api/dotsama/transfer.js +0 -4
  17. package/cjs/koni/api/nft/acala_nft/index.js +1 -1
  18. package/cjs/koni/api/nft/bit.country/index.js +1 -1
  19. package/cjs/koni/api/nft/evm_nft/index.js +2 -3
  20. package/cjs/koni/api/nft/index.js +1 -2
  21. package/cjs/koni/api/nft/karura_nft/index.js +1 -1
  22. package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
  23. package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
  24. package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
  25. package/cjs/koni/api/nft/transfer.js +5 -5
  26. package/cjs/koni/api/nft/unique_nft/index.js +1 -1
  27. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  28. package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
  29. package/cjs/koni/api/staking/bonding/amplitude.js +9 -2
  30. package/cjs/koni/api/staking/bonding/astar.js +37 -13
  31. package/cjs/koni/api/staking/bonding/paraChain.js +10 -2
  32. package/cjs/koni/api/staking/bonding/relayChain.js +21 -4
  33. package/cjs/koni/api/staking/bonding/utils.js +4 -0
  34. package/cjs/koni/api/staking/relayChain.js +0 -1
  35. package/cjs/koni/api/staking/subsquidStaking.js +0 -2
  36. package/cjs/koni/api/tokens/wasm/index.js +0 -1
  37. package/cjs/koni/api/tokens/wasm/utils.js +0 -1
  38. package/cjs/koni/api/xcm/index.js +0 -1
  39. package/cjs/koni/background/cron.js +0 -45
  40. package/cjs/koni/background/handlers/Extension.js +204 -132
  41. package/cjs/koni/background/handlers/State.js +30 -3
  42. package/cjs/koni/background/handlers/Tabs.js +34 -2
  43. package/cjs/koni/background/handlers/index.js +3 -2
  44. package/cjs/koni/background/subscription.js +0 -26
  45. package/cjs/packageInfo.js +1 -1
  46. package/cjs/services/chain-service/constants.js +1 -1
  47. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  48. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -10
  49. package/cjs/services/chain-service/handler/light-client/index.js +9 -6
  50. package/cjs/services/chain-service/index.js +75 -28
  51. package/cjs/services/chain-service/utils.js +3 -0
  52. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +108 -0
  53. package/cjs/services/history-service/index.js +60 -5
  54. package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
  55. package/cjs/services/history-service/testChainMap.js +724 -0
  56. package/cjs/services/keyring-service/index.js +9 -2
  57. package/cjs/services/migration-service/index.js +7 -7
  58. package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +39 -0
  59. package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
  60. package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
  61. package/cjs/services/migration-service/scripts/index.js +7 -1
  62. package/cjs/services/price-service/coingecko.js +1 -1
  63. package/cjs/services/price-service/index.js +0 -4
  64. package/cjs/services/request-service/handler/AuthRequestHandler.js +8 -1
  65. package/cjs/services/request-service/handler/EvmRequestHandler.js +21 -0
  66. package/cjs/services/request-service/handler/MetadataRequestHandler.js +6 -0
  67. package/cjs/services/request-service/handler/SubstrateRequestHandler.js +6 -0
  68. package/cjs/services/request-service/index.js +6 -0
  69. package/cjs/services/setting-service/SettingService.js +4 -9
  70. package/cjs/services/setting-service/constants.js +18 -2
  71. package/cjs/services/storage-service/DatabaseService.js +16 -44
  72. package/cjs/services/storage-service/databases/index.js +1 -1
  73. package/cjs/services/storage-service/db-stores/BaseStore.js +3 -0
  74. package/cjs/services/transaction-service/constants.js +11 -0
  75. package/cjs/services/transaction-service/index.js +31 -9
  76. package/cjs/services/transaction-service/utils.js +25 -14
  77. package/constants/index.d.ts +1 -1
  78. package/constants/index.js +1 -1
  79. package/koni/api/coingecko.js +1 -4
  80. package/koni/api/dotsama/balance.js +7 -5
  81. package/koni/api/dotsama/crowdloan.js +0 -4
  82. package/koni/api/dotsama/transfer.js +0 -4
  83. package/koni/api/nft/acala_nft/index.js +1 -1
  84. package/koni/api/nft/bit.country/index.js +1 -1
  85. package/koni/api/nft/evm_nft/index.js +2 -3
  86. package/koni/api/nft/index.js +1 -2
  87. package/koni/api/nft/karura_nft/index.js +1 -1
  88. package/koni/api/nft/quartz_nft/index.js +1 -1
  89. package/koni/api/nft/rmrk_nft/index.js +2 -3
  90. package/koni/api/nft/statemine_nft/index.js +1 -1
  91. package/koni/api/nft/transfer.js +5 -5
  92. package/koni/api/nft/unique_nft/index.js +1 -1
  93. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  94. package/koni/api/nft/wasm_nft/index.js +1 -2
  95. package/koni/api/staking/bonding/amplitude.js +9 -2
  96. package/koni/api/staking/bonding/astar.d.ts +2 -1
  97. package/koni/api/staking/bonding/astar.js +36 -13
  98. package/koni/api/staking/bonding/paraChain.js +10 -2
  99. package/koni/api/staking/bonding/relayChain.js +21 -4
  100. package/koni/api/staking/bonding/utils.js +4 -0
  101. package/koni/api/staking/relayChain.js +0 -1
  102. package/koni/api/staking/subsquidStaking.js +0 -2
  103. package/koni/api/tokens/wasm/index.js +0 -1
  104. package/koni/api/tokens/wasm/utils.js +0 -1
  105. package/koni/api/xcm/index.js +0 -1
  106. package/koni/background/cron.js +0 -45
  107. package/koni/background/handlers/Extension.d.ts +3 -0
  108. package/koni/background/handlers/Extension.js +120 -51
  109. package/koni/background/handlers/State.d.ts +4 -1
  110. package/koni/background/handlers/State.js +30 -3
  111. package/koni/background/handlers/Tabs.d.ts +1 -0
  112. package/koni/background/handlers/Tabs.js +32 -1
  113. package/koni/background/handlers/index.js +3 -2
  114. package/koni/background/subscription.d.ts +0 -1
  115. package/koni/background/subscription.js +0 -26
  116. package/package.json +65 -39
  117. package/packageInfo.js +1 -1
  118. package/services/chain-service/constants.js +1 -1
  119. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  120. package/services/chain-service/handler/SubstrateChainHandler.js +3 -10
  121. package/services/chain-service/handler/light-client/index.js +8 -6
  122. package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
  123. package/services/chain-service/index.d.ts +2 -1
  124. package/services/chain-service/index.js +75 -28
  125. package/services/chain-service/utils.js +3 -0
  126. package/services/history-service/helpers/recoverHistoryStatus.d.ts +11 -0
  127. package/services/history-service/helpers/recoverHistoryStatus.js +98 -0
  128. package/services/history-service/index.d.ts +6 -0
  129. package/services/history-service/index.js +61 -6
  130. package/services/history-service/subsquid-multi-chain-history.js +3 -2
  131. package/services/history-service/testChainMap.d.ts +3 -0
  132. package/services/history-service/testChainMap.js +716 -0
  133. package/services/keyring-service/index.d.ts +1 -0
  134. package/services/keyring-service/index.js +9 -2
  135. package/services/migration-service/index.js +7 -7
  136. package/services/migration-service/scripts/MigrateAuthUrls.d.ts +4 -0
  137. package/services/migration-service/scripts/MigrateAuthUrls.js +31 -0
  138. package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
  139. package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
  140. package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
  141. package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
  142. package/services/migration-service/scripts/index.js +7 -1
  143. package/services/price-service/coingecko.js +1 -1
  144. package/services/price-service/index.js +0 -4
  145. package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
  146. package/services/request-service/handler/AuthRequestHandler.js +8 -1
  147. package/services/request-service/handler/EvmRequestHandler.d.ts +1 -0
  148. package/services/request-service/handler/EvmRequestHandler.js +21 -0
  149. package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -0
  150. package/services/request-service/handler/MetadataRequestHandler.js +6 -0
  151. package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
  152. package/services/request-service/handler/SubstrateRequestHandler.js +6 -0
  153. package/services/request-service/index.d.ts +1 -0
  154. package/services/request-service/index.js +6 -0
  155. package/services/setting-service/SettingService.d.ts +1 -0
  156. package/services/setting-service/SettingService.js +5 -10
  157. package/services/setting-service/constants.d.ts +4 -1
  158. package/services/setting-service/constants.js +14 -1
  159. package/services/storage-service/DatabaseService.d.ts +1 -0
  160. package/services/storage-service/DatabaseService.js +16 -44
  161. package/services/storage-service/databases/index.js +1 -1
  162. package/services/storage-service/db-stores/BaseStore.d.ts +1 -0
  163. package/services/storage-service/db-stores/BaseStore.js +3 -0
  164. package/services/transaction-service/constants.d.ts +1 -0
  165. package/services/transaction-service/constants.js +4 -0
  166. package/services/transaction-service/index.d.ts +2 -0
  167. package/services/transaction-service/index.js +32 -10
  168. package/services/transaction-service/utils.d.ts +1 -1
  169. package/services/transaction-service/utils.js +24 -13
@@ -45,4 +45,6 @@ export default class TransactionService {
45
45
  generateHashPayload(chain: string, transaction: TransactionConfig): HexString;
46
46
  private signAndSendEvmTransaction;
47
47
  private signAndSendSubstrateTransaction;
48
+ private handleTransactionTimeout;
49
+ resetWallet(): void;
48
50
  }
@@ -8,9 +8,10 @@ import { TransactionWarning } from '@subwallet/extension-base/background/warning
8
8
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
9
9
  import { _getChainNativeTokenBasicInfo, _getEvmChainId } from '@subwallet/extension-base/services/chain-service/utils';
10
10
  import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
11
+ import { TRANSACTION_TIMEOUT } from '@subwallet/extension-base/services/transaction-service/constants';
11
12
  import { parseTransferEventLogs, parseXcmEventLogs } from '@subwallet/extension-base/services/transaction-service/event-parser';
12
13
  import { getTransactionId, isSubstrateTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
13
- import { getTransactionLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
14
+ import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
14
15
  import { anyNumberToBN } from '@subwallet/extension-base/utils/eth';
15
16
  import { parseTxAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
16
17
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
@@ -269,7 +270,7 @@ export default class TransactionService {
269
270
  getTransactionLink(id) {
270
271
  const transaction = this.getTransaction(id);
271
272
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
272
- return getTransactionLink(chainInfo, transaction.extrinsicHash);
273
+ return getExplorerLink(chainInfo, transaction.extrinsicHash, 'tx');
273
274
  }
274
275
  transactionToHistories(id, eventLogs) {
275
276
  const transaction = this.getTransaction(id);
@@ -455,7 +456,7 @@ export default class TransactionService {
455
456
  onSigned({
456
457
  id
457
458
  }) {
458
- console.log(`Transaction "${id}" is signed`);
459
+ console.debug(`Transaction "${id}" is signed`);
459
460
  }
460
461
  onSend({
461
462
  id
@@ -467,22 +468,24 @@ export default class TransactionService {
467
468
 
468
469
  // Create Input History Transaction History
469
470
  this.historyService.insertHistories(this.transactionToHistories(id)).catch(console.error);
470
- console.log(`Transaction "${id}" is sent`);
471
+ console.debug(`Transaction "${id}" is sent`);
471
472
  }
472
473
  onHasTransactionHash({
474
+ blockHash,
473
475
  extrinsicHash,
474
476
  id
475
477
  }) {
476
478
  // Write processing transaction history
477
479
  const updateData = {
478
480
  extrinsicHash,
479
- status: ExtrinsicStatus.PROCESSING
481
+ status: ExtrinsicStatus.PROCESSING,
482
+ blockHash: blockHash || ''
480
483
  };
481
484
  this.updateTransaction(id, updateData);
482
485
 
483
486
  // In this case transaction id is the same as extrinsic hash and will change after below update
484
487
  this.historyService.updateHistoryByExtrinsicHash(id, updateData).catch(console.error);
485
- console.log(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
488
+ console.debug(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
486
489
  }
487
490
  handlePostProcessing(id) {
488
491
  // must be done after success/failure to make sure the transaction is finalized
@@ -519,7 +522,6 @@ export default class TransactionService {
519
522
  this.updateTransaction(id, {
520
523
  status: ExtrinsicStatus.SUCCESS
521
524
  });
522
- console.log('Transaction completed', id, transaction.extrinsicHash);
523
525
 
524
526
  // Write success transaction history
525
527
  this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
@@ -551,7 +553,6 @@ export default class TransactionService {
551
553
  status: nextStatus,
552
554
  errors
553
555
  });
554
- console.log('Transaction failed', id, transaction.extrinsicHash);
555
556
 
556
557
  // Write failed transaction history
557
558
  this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
@@ -570,8 +571,6 @@ export default class TransactionService {
570
571
  });
571
572
  }
572
573
  this.eventService.emit('transaction.failed', transaction);
573
- // Log transaction errors
574
- console.error(errors);
575
574
  }
576
575
  generateHashPayload(chain, transaction) {
577
576
  const chainInfo = this.chainService.getChainInfoByKey(chain);
@@ -680,6 +679,7 @@ export default class TransactionService {
680
679
  emitter.emit('signed', eventData);
681
680
 
682
681
  // Send transaction
682
+ this.handleTransactionTimeout(emitter, eventData);
683
683
  emitter.emit('send', eventData); // This event is needed after sending transaction with queue
684
684
  signedTransaction && web3Api.eth.sendSignedTransaction(signedTransaction).once('transactionHash', hash => {
685
685
  eventData.extrinsicHash = hash;
@@ -734,7 +734,9 @@ export default class TransactionService {
734
734
  emitter.emit('signed', eventData);
735
735
 
736
736
  // Send transaction
737
+ this.handleTransactionTimeout(emitter, eventData);
737
738
  emitter.emit('send', eventData); // This event is needed after sending transaction with queue
739
+
738
740
  rs.send(txState => {
739
741
  // handle events, logs, history
740
742
  if (!txState || !txState.status) {
@@ -744,6 +746,7 @@ export default class TransactionService {
744
746
  eventData.eventLogs = txState.events;
745
747
  if (!eventData.extrinsicHash || eventData.extrinsicHash === '') {
746
748
  eventData.extrinsicHash = txState.txHash.toHex();
749
+ eventData.blockHash = txState.status.asInBlock.toHex();
747
750
  emitter.emit('extrinsicHash', eventData);
748
751
  }
749
752
  }
@@ -779,4 +782,23 @@ export default class TransactionService {
779
782
  });
780
783
  return emitter;
781
784
  }
785
+ handleTransactionTimeout(emitter, eventData) {
786
+ const timeout = setTimeout(() => {
787
+ const transaction = this.getTransaction(eventData.id);
788
+ if (transaction.status !== ExtrinsicStatus.SUCCESS && transaction.status !== ExtrinsicStatus.FAIL) {
789
+ eventData.errors.push(new TransactionError(BasicTxErrorType.TIMEOUT, 'Transaction timeout'));
790
+ emitter.emit('error', eventData);
791
+ clearTimeout(timeout);
792
+ }
793
+ }, TRANSACTION_TIMEOUT);
794
+ emitter.once('success', () => {
795
+ clearTimeout(timeout);
796
+ });
797
+ emitter.once('error', () => {
798
+ clearTimeout(timeout);
799
+ });
800
+ }
801
+ resetWallet() {
802
+ this.transactionSubject.next({});
803
+ }
782
804
  }
@@ -1,4 +1,4 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { ExtrinsicDataTypeMap, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
3
3
  export declare function parseTransactionData<T extends ExtrinsicType>(data: unknown): ExtrinsicDataTypeMap[T];
4
- export declare function getTransactionLink(chainInfo: _ChainInfo, extrinsicHash: string): string | undefined;
4
+ export declare function getExplorerLink(chainInfo: _ChainInfo, value: string, type: 'account' | 'tx'): string | undefined;
@@ -8,19 +8,30 @@ export function parseTransactionData(data) {
8
8
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
9
9
  return data;
10
10
  }
11
- export function getTransactionLink(chainInfo, extrinsicHash) {
12
- if (extrinsicHash.startsWith('0x')) {
13
- const explorerLink = _getBlockExplorerFromChain(chainInfo);
14
- if (_isPureEvmChain(chainInfo)) {
15
- if (explorerLink) {
16
- return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
17
- }
18
- } else {
19
- const explorerLink = _getBlockExplorerFromChain(chainInfo);
20
- if (explorerLink) {
21
- return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
22
- }
23
- }
11
+ function getBlockExplorerAccountRoute(explorerLink) {
12
+ if (explorerLink.includes('explorer.subspace.network')) {
13
+ return 'accounts';
14
+ }
15
+ if (explorerLink.includes('subscan.io')) {
16
+ return 'account';
17
+ }
18
+ return 'address';
19
+ }
20
+ function getBlockExplorerTxRoute(chainInfo) {
21
+ if (_isPureEvmChain(chainInfo)) {
22
+ return 'tx';
23
+ }
24
+ return 'extrinsic';
25
+ }
26
+ export function getExplorerLink(chainInfo, value, type) {
27
+ const explorerLink = _getBlockExplorerFromChain(chainInfo);
28
+ if (explorerLink && type === 'account') {
29
+ const route = getBlockExplorerAccountRoute(explorerLink);
30
+ return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
31
+ }
32
+ if (explorerLink && value.startsWith('0x')) {
33
+ const route = getBlockExplorerTxRoute(chainInfo);
34
+ return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
24
35
  }
25
36
  return undefined;
26
37
  }