@subwallet/extension-base 1.1.32-0 → 1.1.33-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/background/KoniTypes.d.ts +2 -0
  2. package/background/KoniTypes.js +1 -0
  3. package/cjs/background/KoniTypes.js +1 -0
  4. package/cjs/koni/api/staking/bonding/amplitude.js +97 -63
  5. package/cjs/koni/api/staking/paraChain.js +31 -5
  6. package/cjs/koni/api/xcm/xTokens.js +1 -1
  7. package/cjs/koni/background/handlers/Tabs.js +19 -2
  8. package/cjs/packageInfo.js +1 -1
  9. package/cjs/services/campaign-service/index.js +19 -0
  10. package/cjs/services/chain-service/constants.js +5 -3
  11. package/cjs/services/history-service/index.js +12 -8
  12. package/cjs/services/storage-service/DatabaseService.js +3 -0
  13. package/cjs/services/storage-service/db-stores/Campaign.js +9 -3
  14. package/cjs/services/transaction-service/index.js +58 -13
  15. package/cjs/utils/fetchEvmChainInfo.js +20 -0
  16. package/cjs/utils/index.js +24 -0
  17. package/koni/api/staking/bonding/amplitude.d.ts +1 -1
  18. package/koni/api/staking/bonding/amplitude.js +98 -64
  19. package/koni/api/staking/bonding/utils.d.ts +4 -0
  20. package/koni/api/staking/paraChain.js +31 -5
  21. package/koni/api/xcm/xTokens.js +1 -1
  22. package/koni/background/handlers/Tabs.js +20 -3
  23. package/package.json +11 -6
  24. package/packageInfo.js +1 -1
  25. package/services/campaign-service/index.js +19 -0
  26. package/services/chain-service/constants.d.ts +1 -0
  27. package/services/chain-service/constants.js +5 -3
  28. package/services/event-service/types.d.ts +1 -0
  29. package/services/history-service/index.js +12 -8
  30. package/services/storage-service/DatabaseService.d.ts +1 -0
  31. package/services/storage-service/DatabaseService.js +3 -0
  32. package/services/storage-service/db-stores/Campaign.js +9 -3
  33. package/services/transaction-service/index.d.ts +1 -0
  34. package/services/transaction-service/index.js +45 -1
  35. package/services/transaction-service/types.d.ts +1 -0
  36. package/utils/fetchEvmChainInfo.d.ts +17 -0
  37. package/utils/fetchEvmChainInfo.js +14 -0
  38. package/utils/index.d.ts +2 -0
  39. package/utils/index.js +3 -1
@@ -283,6 +283,12 @@ export default class TransactionService {
283
283
  errors: [...data.errors, new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]
284
284
  });
285
285
  });
286
+ emitter.on('timeout', data => {
287
+ this.onTimeOut({
288
+ ...data,
289
+ errors: [...data.errors, new TransactionError(BasicTxErrorType.TIMEOUT)]
290
+ });
291
+ });
286
292
 
287
293
  // Todo: handle any event with transaction.eventsHandler
288
294
 
@@ -645,6 +651,44 @@ export default class TransactionService {
645
651
  }
646
652
  this.eventService.emit('transaction.failed', transaction);
647
653
  }
654
+ onTimeOut({
655
+ blockHash,
656
+ blockNumber,
657
+ errors,
658
+ extrinsicHash,
659
+ id
660
+ }) {
661
+ const transaction = this.getTransaction(id);
662
+ const nextStatus = ExtrinsicStatus.TIMEOUT;
663
+ if (transaction) {
664
+ this.updateTransaction(id, {
665
+ status: nextStatus,
666
+ errors,
667
+ extrinsicHash
668
+ });
669
+ this.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
670
+ extrinsicHash: extrinsicHash || transaction.extrinsicHash,
671
+ status: nextStatus,
672
+ blockNumber: blockNumber || 0,
673
+ blockHash: blockHash || ''
674
+ }).catch(console.error);
675
+ const info = isHex(transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash) ? transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash : getBaseTransactionInfo(transaction, this.chainService.getChainInfoMap());
676
+ this.notificationService.notify({
677
+ type: NotificationType.ERROR,
678
+ title: t('Transaction timed out'),
679
+ message: t('Transaction {{info}} timed out', {
680
+ replace: {
681
+ info
682
+ }
683
+ }),
684
+ action: {
685
+ url: this.getTransactionLink(id)
686
+ },
687
+ notifyViaBrowser: true
688
+ });
689
+ }
690
+ this.eventService.emit('transaction.timeout', transaction);
691
+ }
648
692
  generateHashPayload(chain, transaction) {
649
693
  var _transaction$nonce;
650
694
  const chainInfo = this.chainService.getChainInfoByKey(chain);
@@ -943,7 +987,7 @@ export default class TransactionService {
943
987
  const transaction = this.getTransaction(eventData.id);
944
988
  if (transaction.status !== ExtrinsicStatus.SUCCESS && transaction.status !== ExtrinsicStatus.FAIL) {
945
989
  eventData.errors.push(new TransactionError(BasicTxErrorType.TIMEOUT, t('Transaction timeout')));
946
- emitter.emit('error', eventData);
990
+ emitter.emit('timeout', eventData);
947
991
  clearTimeout(timeout);
948
992
  }
949
993
  }, TRANSACTION_TIMEOUT);
@@ -49,5 +49,6 @@ export interface TransactionEventMap {
49
49
  extrinsicHash: (response: TransactionEventResponse) => void;
50
50
  error: (response: TransactionEventResponse) => void;
51
51
  success: (response: TransactionEventResponse) => void;
52
+ timeout: (response: TransactionEventResponse) => void;
52
53
  }
53
54
  export {};
@@ -0,0 +1,17 @@
1
+ export interface OnlineEvmChainInfo {
2
+ chain: string;
3
+ name: string;
4
+ chainId: number;
5
+ nativeCurrency: {
6
+ name: string;
7
+ symbol: string;
8
+ decimals: number;
9
+ };
10
+ rpc: string[];
11
+ explorers: {
12
+ name: string;
13
+ url: string;
14
+ standard: string;
15
+ }[];
16
+ }
17
+ export declare function getEVMChainInfo(chainId: number): Promise<OnlineEvmChainInfo>;
@@ -0,0 +1,14 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ const onlineMap = {};
5
+ export async function getEVMChainInfo(chainId) {
6
+ if (Object.keys(onlineMap).length === 0) {
7
+ const rs = await fetch('https://chainid.network/chains.json');
8
+ const data = await rs.json();
9
+ data.forEach(item => {
10
+ onlineMap[item.chainId] = item;
11
+ });
12
+ }
13
+ return onlineMap[chainId];
14
+ }
package/utils/index.d.ts CHANGED
@@ -46,3 +46,5 @@ export * from './environment';
46
46
  export * from './lazy';
47
47
  export * from './registry';
48
48
  export * from './translate';
49
+ export * from './fetchStaticData';
50
+ export * from './fetchEvmChainInfo';
package/utils/index.js CHANGED
@@ -299,4 +299,6 @@ export * from "./array.js";
299
299
  export * from "./environment.js";
300
300
  export * from "./lazy.js";
301
301
  export * from "./registry.js";
302
- export * from "./translate.js";
302
+ export * from "./translate.js";
303
+ export * from "./fetchStaticData.js";
304
+ export * from "./fetchEvmChainInfo.js";