@subwallet/extension-base 1.0.2-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 (120) hide show
  1. package/background/KoniTypes.d.ts +16 -34
  2. package/background/KoniTypes.js +6 -7
  3. package/background/errors/TransactionError.js +21 -1
  4. package/cjs/background/KoniTypes.js +6 -7
  5. package/cjs/background/errors/TransactionError.js +20 -0
  6. package/cjs/constants/index.js +8 -26
  7. package/cjs/koni/api/dotsama/balance.js +49 -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 +13 -9
  20. package/cjs/koni/api/staking/bonding/astar.js +15 -13
  21. package/cjs/koni/api/staking/bonding/index.js +22 -10
  22. package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
  23. package/cjs/koni/api/staking/bonding/relayChain.js +119 -16
  24. package/cjs/koni/api/staking/bonding/utils.js +27 -8
  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/polkadotXcm.js +1 -1
  28. package/cjs/koni/api/xcm/utils.js +18 -13
  29. package/cjs/koni/api/xcm/xTokens.js +1 -1
  30. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  31. package/cjs/koni/background/cron.js +150 -47
  32. package/cjs/koni/background/handlers/Extension.js +106 -64
  33. package/cjs/koni/background/handlers/State.js +19 -21
  34. package/cjs/koni/background/handlers/Tabs.js +8 -1
  35. package/cjs/koni/background/subscription.js +32 -29
  36. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  37. package/cjs/services/chain-service/handler/light-client/index.js +2 -0
  38. package/cjs/services/chain-service/index.js +6 -7
  39. package/cjs/services/event-service/index.js +5 -1
  40. package/cjs/services/event-service/types.js +11 -1
  41. package/cjs/services/history-service/index.js +16 -10
  42. package/cjs/services/history-service/subsquid-multi-chain-history.js +12 -9
  43. package/cjs/services/price-service/coingecko.js +0 -1
  44. package/cjs/services/price-service/index.js +2 -3
  45. package/cjs/services/request-service/handler/AuthRequestHandler.js +6 -2
  46. package/cjs/services/storage-service/DatabaseService.js +52 -33
  47. package/cjs/services/storage-service/db-stores/Nft.js +4 -17
  48. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  49. package/cjs/services/transaction-service/index.js +23 -14
  50. package/cjs/utils/index.js +7 -14
  51. package/constants/index.d.ts +7 -13
  52. package/constants/index.js +7 -13
  53. package/koni/api/dotsama/balance.d.ts +0 -1
  54. package/koni/api/dotsama/balance.js +22 -197
  55. package/koni/api/dotsama/transfer.js +5 -4
  56. package/koni/api/nft/acala_nft/index.js +3 -1
  57. package/koni/api/nft/bit.country/index.js +3 -1
  58. package/koni/api/nft/evm_nft/index.js +6 -3
  59. package/koni/api/nft/index.d.ts +1 -2
  60. package/koni/api/nft/index.js +3 -6
  61. package/koni/api/nft/karura_nft/index.js +3 -1
  62. package/koni/api/nft/nft.d.ts +1 -0
  63. package/koni/api/nft/rmrk_nft/index.js +8 -1
  64. package/koni/api/nft/statemine_nft/index.js +3 -1
  65. package/koni/api/nft/unique_nft/index.js +5 -1
  66. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  67. package/koni/api/nft/wasm_nft/index.js +167 -109
  68. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  69. package/koni/api/nft/wasm_nft/utils.js +7 -5
  70. package/koni/api/staking/bonding/amplitude.d.ts +0 -1
  71. package/koni/api/staking/bonding/amplitude.js +15 -10
  72. package/koni/api/staking/bonding/astar.js +8 -6
  73. package/koni/api/staking/bonding/index.d.ts +4 -1
  74. package/koni/api/staking/bonding/index.js +23 -13
  75. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  76. package/koni/api/staking/bonding/paraChain.js +86 -5
  77. package/koni/api/staking/bonding/relayChain.d.ts +5 -1
  78. package/koni/api/staking/bonding/relayChain.js +118 -18
  79. package/koni/api/staking/bonding/utils.d.ts +3 -2
  80. package/koni/api/staking/bonding/utils.js +27 -9
  81. package/koni/api/tokens/wasm/index.js +5 -4
  82. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  83. package/koni/api/tokens/wasm/utils.js +54 -0
  84. package/koni/api/xcm/polkadotXcm.js +2 -2
  85. package/koni/api/xcm/utils.d.ts +5 -6
  86. package/koni/api/xcm/utils.js +15 -10
  87. package/koni/api/xcm/xTokens.js +2 -2
  88. package/koni/api/xcm/xcmPallet.js +10 -9
  89. package/koni/background/cron.d.ts +6 -1
  90. package/koni/background/cron.js +151 -48
  91. package/koni/background/handlers/Extension.d.ts +2 -2
  92. package/koni/background/handlers/Extension.js +108 -67
  93. package/koni/background/handlers/State.d.ts +5 -6
  94. package/koni/background/handlers/State.js +19 -21
  95. package/koni/background/handlers/Tabs.js +8 -1
  96. package/koni/background/subscription.js +31 -30
  97. package/package.json +9 -4
  98. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  99. package/services/chain-service/handler/light-client/index.d.ts +17 -1
  100. package/services/chain-service/handler/light-client/index.js +1 -1
  101. package/services/chain-service/helper/psp22_abi.json +1041 -881
  102. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  103. package/services/chain-service/index.js +6 -7
  104. package/services/event-service/index.js +5 -1
  105. package/services/event-service/types.d.ts +5 -9
  106. package/services/event-service/types.js +4 -1
  107. package/services/history-service/index.d.ts +1 -1
  108. package/services/history-service/index.js +16 -10
  109. package/services/history-service/subsquid-multi-chain-history.js +15 -11
  110. package/services/price-service/coingecko.js +0 -1
  111. package/services/price-service/index.js +2 -3
  112. package/services/request-service/handler/AuthRequestHandler.js +6 -2
  113. package/services/storage-service/DatabaseService.d.ts +1 -0
  114. package/services/storage-service/DatabaseService.js +52 -33
  115. package/services/storage-service/db-stores/Nft.d.ts +1 -2
  116. package/services/storage-service/db-stores/Nft.js +4 -16
  117. package/services/transaction-service/event-parser/index.js +21 -49
  118. package/services/transaction-service/index.js +23 -14
  119. package/utils/index.d.ts +1 -1
  120. package/utils/index.js +6 -12
@@ -1,7 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { FOUR_INSTRUCTIONS_WEIGHT, getReceiverLocation, NETWORK_USE_UNLIMITED_WEIGHT, POLKADOT_UNLIMITED_WEIGHT } from '@subwallet/extension-base/koni/api/xcm/utils';
4
+ import { FOUR_INSTRUCTIONS_WEIGHT, getDestWeight, getReceiverLocation } from '@subwallet/extension-base/koni/api/xcm/utils';
5
5
  import { _XCM_TYPE } from '@subwallet/extension-base/services/chain-service/constants';
6
6
  import { _getSubstrateParaId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType, _getXcmTransferType, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
7
7
  function getCurrencyId(tokenInfo) {
@@ -48,6 +48,6 @@ function getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo,
48
48
  };
49
49
  }
50
50
  export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
51
- const weightParam = NETWORK_USE_UNLIMITED_WEIGHT.includes(originChainInfo.slug) ? POLKADOT_UNLIMITED_WEIGHT : FOUR_INSTRUCTIONS_WEIGHT;
51
+ const weightParam = ['pioneer'].includes(originChainInfo.slug) ? FOUR_INSTRUCTIONS_WEIGHT : getDestWeight();
52
52
  return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo, recipientAddress), weightParam);
53
53
  }
@@ -1,11 +1,11 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { FOUR_INSTRUCTIONS_WEIGHT, getBeneficiary, NETWORK_USE_UNLIMITED_WEIGHT, POLKADOT_UNLIMITED_WEIGHT } from '@subwallet/extension-base/koni/api/xcm/utils';
4
+ import { getBeneficiary, getDestWeight } from '@subwallet/extension-base/koni/api/xcm/utils';
5
5
  import { _getSubstrateParaId } from '@subwallet/extension-base/services/chain-service/utils';
6
- function getDestinationChainLocation(destinationChainInfo) {
6
+ function getDestinationChainLocation(destinationChainInfo, version = 'V1') {
7
7
  return {
8
- V1: {
8
+ [version]: {
9
9
  parents: 0,
10
10
  interior: {
11
11
  X1: {
@@ -15,10 +15,10 @@ function getDestinationChainLocation(destinationChainInfo) {
15
15
  }
16
16
  };
17
17
  }
18
- function getTokenLocation(sendingValue) {
18
+ function getTokenLocation(sendingValue, version = 'V2') {
19
19
  return {
20
20
  // always native token of relaychain
21
- V1: [{
21
+ [version]: [{
22
22
  id: {
23
23
  Concrete: {
24
24
  parents: 0,
@@ -34,10 +34,11 @@ function getTokenLocation(sendingValue) {
34
34
 
35
35
  // this pallet is only used by Relaychains
36
36
  export function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
37
- const weightParam = NETWORK_USE_UNLIMITED_WEIGHT.includes(originChainInfo.slug) ? POLKADOT_UNLIMITED_WEIGHT : FOUR_INSTRUCTIONS_WEIGHT;
38
- const destination = getDestinationChainLocation(destinationChainInfo);
39
- const beneficiary = getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress);
40
- const tokenLocation = getTokenLocation(value);
37
+ const weightParam = getDestWeight();
38
+ const xcmVer = ['kusama'].includes(originChainInfo.slug) ? 'V2' : 'V1';
39
+ const destination = getDestinationChainLocation(destinationChainInfo, xcmVer);
40
+ const beneficiary = getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress, xcmVer);
41
+ const tokenLocation = getTokenLocation(value, xcmVer);
41
42
  let method = 'limitedReserveTransferAssets';
42
43
  if (['statemint', 'statemine'].includes(destinationChainInfo.slug)) {
43
44
  method = 'limitedTeleportAssets';
@@ -15,15 +15,16 @@ export declare class KoniCron {
15
15
  constructor(state: KoniState, subscriptions: KoniSubscription, dbService: DatabaseService);
16
16
  private cronMap;
17
17
  private subjectMap;
18
+ private eventHandler?;
18
19
  getCron: (name: string) => any;
19
20
  getSubjectMap: (name: string) => any;
20
21
  addCron: (name: string, callback: (param?: any) => void, interval: number, runFirst?: boolean) => void;
21
22
  addSubscribeCron: <T>(name: string, callback: (subject: Subject<T>) => void, interval: number) => void;
22
23
  removeCron: (name: string) => void;
23
24
  removeAllCrons: () => void;
24
- init: () => void;
25
25
  start: () => void;
26
26
  stop: () => void;
27
+ updateApiMapStatus: () => void;
27
28
  recoverApiMap: () => void;
28
29
  refreshNft: (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => () => void;
29
30
  resetNft: (newAddress: string) => void;
@@ -34,4 +35,8 @@ export declare class KoniCron {
34
35
  checkNetworkAvailable: (serviceInfo: ServiceInfo) => boolean;
35
36
  updateChainStakingMetadata: (chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
36
37
  updateNominatorMetadata: (address: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
38
+ reloadNft(): Promise<boolean>;
39
+ reloadStaking(): Promise<boolean>;
40
+ private needUpdateNft;
41
+ private needUpdateStaking;
37
42
  }
@@ -1,7 +1,10 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, CRON_REFRESH_CHAIN_NOMINATOR_METADATA, CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL } from '@subwallet/extension-base/constants';
4
+ import { CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, CRON_GET_API_MAP_STATUS, CRON_REFRESH_CHAIN_NOMINATOR_METADATA, CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL } from '@subwallet/extension-base/constants';
5
+ import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
6
+ import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportSubstrateStaking, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
7
+ import { waitTimeout } from '@subwallet/extension-base/utils';
5
8
  import { Subject } from 'rxjs';
6
9
  import { logger as createLogger } from '@polkadot/util';
7
10
  export class KoniCron {
@@ -47,21 +50,26 @@ export class KoniCron {
47
50
  delete this.cronMap[key];
48
51
  });
49
52
  };
50
- init = () => {
51
- const currentAccountInfo = this.state.keyringService.currentAccount;
52
- if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
53
- return;
54
- }
55
- if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
56
- this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap());
57
- this.refreshStakingReward(currentAccountInfo.address);
58
- this.refreshStakingRewardFastInterval(currentAccountInfo.address);
59
- this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
60
- this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
61
- } else {
62
- this.setStakingRewardReady();
63
- }
64
- };
53
+
54
+ // init = () => {
55
+ // const currentAccountInfo = this.state.keyringService.currentAccount;
56
+ //
57
+ // if (!currentAccountInfo?.address) {
58
+ // return;
59
+ // }
60
+ //
61
+ // if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
62
+ // this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap());
63
+ // this.updateApiMapStatus();
64
+ // this.refreshStakingReward(currentAccountInfo.address);
65
+ // this.refreshStakingRewardFastInterval(currentAccountInfo.address);
66
+ // // this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
67
+ // this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
68
+ // } else {
69
+ // this.setStakingRewardReady();
70
+ // }
71
+ // };
72
+
65
73
  start = () => {
66
74
  if (this.status === 'running') {
67
75
  return;
@@ -74,6 +82,7 @@ export class KoniCron {
74
82
  if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
75
83
  this.resetNft(currentAccountInfo.address);
76
84
  this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
85
+ this.addCron('checkStatusApiMap', this.updateApiMapStatus, CRON_GET_API_MAP_STATUS);
77
86
  this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
78
87
  this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
79
88
  this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
@@ -82,46 +91,74 @@ export class KoniCron {
82
91
  } else {
83
92
  this.setStakingRewardReady();
84
93
  }
85
- const reloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'chain.update', 'chain.enable', 'asset.update', 'asset.enable', 'transaction.done', 'transaction.failed'];
86
- this.state.eventService.onLazy((events, eventTypes) => {
94
+ const commonReloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'asset.updateState'];
95
+ this.eventHandler = (events, eventTypes) => {
87
96
  var _serviceInfo$currentA;
88
97
  const serviceInfo = this.state.getServiceInfo();
89
- const needReload = eventTypes.some(eT => reloadEvents.includes(eT));
90
- if (!needReload) {
98
+ const commonReload = eventTypes.some(eventType => commonReloadEvents.includes(eventType));
99
+ const chainUpdated = eventTypes.includes('chain.updateState');
100
+ const stakingSubmitted = eventTypes.includes('transaction.submitStaking');
101
+ const updatedChains = [];
102
+ if (chainUpdated) {
103
+ events.forEach(event => {
104
+ if (event.type === 'chain.updateState') {
105
+ const updatedData = event.data;
106
+ updatedChains.push(updatedData[0]);
107
+ }
108
+ });
109
+ }
110
+ if (!commonReload && !chainUpdated && !stakingSubmitted) {
91
111
  return;
92
112
  }
93
- this.logger.log('ServiceInfo updated, restarting...');
113
+ this.logger.log('ServiceInfo updated, Cron restarting...', eventTypes);
94
114
  const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
95
115
  if (!address) {
96
116
  return;
97
117
  }
98
- this.resetStakingReward();
99
- this.resetNft(address);
100
- this.removeCron('refreshNft');
101
- this.removeCron('refreshStakingReward');
102
- this.removeCron('refreshPoolingStakingReward');
103
- this.removeCron('checkStatusApiMap');
104
- this.removeCron('recoverApiMap');
105
- this.removeCron('updateChainStakingMetadata');
106
- this.removeCron('updateNominatorMetadata');
118
+ const chainInfoMap = serviceInfo.chainInfoMap;
119
+ const needUpdateNft = this.needUpdateNft(chainInfoMap, updatedChains);
120
+ const needUpdateStaking = this.needUpdateStaking(chainInfoMap, updatedChains);
121
+
122
+ // NFT
123
+ (commonReload || needUpdateNft) && this.resetNft(address);
124
+ (commonReload || needUpdateNft) && this.removeCron('refreshNft');
125
+
126
+ // Staking
127
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.resetStakingReward();
128
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshStakingReward');
129
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshPoolingStakingReward');
130
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('updateNominatorMetadata');
131
+ needUpdateStaking && this.removeCron('updateChainStakingMetadata');
132
+
133
+ // Chains
134
+ chainUpdated && this.removeCron('checkStatusApiMap');
135
+ chainUpdated && this.removeCron('recoverApiMap');
107
136
  if (this.checkNetworkAvailable(serviceInfo)) {
108
137
  // only add cron job if there's at least 1 active network
109
- this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
110
- this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
111
- this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
112
- this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
113
- this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
114
- this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
138
+ (commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
139
+ chainUpdated && this.addCron('checkStatusApiMap', this.updateApiMapStatus, CRON_GET_API_MAP_STATUS);
140
+ chainUpdated && this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
141
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
142
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
143
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
144
+ needUpdateStaking && this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
115
145
  } else {
116
146
  this.setStakingRewardReady();
117
147
  }
118
- });
148
+ };
149
+ this.state.eventService.onLazy(this.eventHandler);
119
150
  this.status = 'running';
120
151
  };
121
152
  stop = () => {
122
153
  if (this.status === 'stopped') {
123
154
  return;
124
155
  }
156
+
157
+ // Unsubscribe events
158
+ if (this.eventHandler) {
159
+ this.state.eventService.offLazy(this.eventHandler);
160
+ this.eventHandler = undefined;
161
+ }
125
162
  if (this.serviceSubscription) {
126
163
  this.serviceSubscription.unsubscribe();
127
164
  this.serviceSubscription = undefined;
@@ -130,6 +167,36 @@ export class KoniCron {
130
167
  this.removeAllCrons();
131
168
  this.status = 'stopped';
132
169
  };
170
+ updateApiMapStatus = () => {
171
+ const apiMap = this.state.getApiMap();
172
+ const networkMap = this.state.getChainStateMap();
173
+ for (const [key, substrateApi] of Object.entries(apiMap.substrate)) {
174
+ let status = _ChainConnectionStatus.CONNECTING;
175
+ if (substrateApi.isApiConnected) {
176
+ status = _ChainConnectionStatus.CONNECTED;
177
+ }
178
+ if (!networkMap[key].connectionStatus) {
179
+ this.state.updateChainConnectionStatus(key, status);
180
+ } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== status) {
181
+ this.state.updateChainConnectionStatus(key, status);
182
+ }
183
+ }
184
+ for (const [key, evmApi] of Object.entries(apiMap.evm)) {
185
+ evmApi.api.eth.net.isListening().then(() => {
186
+ if (!networkMap[key].connectionStatus) {
187
+ this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTED);
188
+ } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _ChainConnectionStatus.CONNECTED) {
189
+ this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTED);
190
+ }
191
+ }).catch(() => {
192
+ if (!networkMap[key].connectionStatus) {
193
+ this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTING);
194
+ } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _ChainConnectionStatus.CONNECTING) {
195
+ this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTING);
196
+ }
197
+ });
198
+ }
199
+ };
133
200
  recoverApiMap = () => {
134
201
  var _this$subscriptions;
135
202
  const apiMap = this.state.getApiMap();
@@ -150,28 +217,26 @@ export class KoniCron {
150
217
  };
151
218
  refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
152
219
  return () => {
153
- this.logger.log('Refresh Nft state');
220
+ console.debug('Refresh NFT state');
154
221
  this.subscriptions.subscribeNft(address, apiMap.substrate, apiMap.evm, smartContractNfts, chainInfoMap);
155
222
  };
156
223
  };
157
224
  resetNft = newAddress => {
158
- this.logger.log('Reset Nft state');
159
225
  this.state.resetNft(newAddress);
160
226
  };
161
227
  resetStakingReward = () => {
162
- this.logger.log('Reset Staking Reward State');
163
228
  this.state.resetStakingReward();
164
229
  };
165
230
  refreshStakingReward = address => {
166
231
  return () => {
167
- this.logger.log('Fetching staking reward data');
168
- this.subscriptions.subscribeStakingReward(address).then(() => this.logger.log('Refresh staking reward state')).catch(this.logger.error);
232
+ console.debug('Refresh staking reward state');
233
+ this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
169
234
  };
170
235
  };
171
236
  refreshStakingRewardFastInterval = address => {
172
237
  return () => {
173
- this.logger.log('Fetching staking reward data with fast interval');
174
- this.subscriptions.subscribeStakingRewardFastInterval(address).then(() => this.logger.log('Refresh staking reward state with fast interval')).catch(this.logger.error);
238
+ console.debug('Refresh staking reward data with fast interval');
239
+ this.subscriptions.subscribeStakingRewardFastInterval(address).catch(this.logger.error);
175
240
  };
176
241
  };
177
242
  setStakingRewardReady = () => {
@@ -182,14 +247,52 @@ export class KoniCron {
182
247
  };
183
248
  updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
184
249
  return () => {
185
- this.logger.log('Fetching chain staking metadata');
186
- this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).then(() => this.logger.log('Updated chain staking metadata')).catch(this.logger.error);
250
+ console.debug('Fetching chain staking metadata');
251
+ this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
187
252
  };
188
253
  };
189
254
  updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
190
255
  return () => {
191
- this.logger.log('Fetching nominator data', address);
192
- this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).then(() => this.logger.log('Updated nominator data', address)).catch(this.logger.error);
256
+ console.debug('Fetching nominator data for', address);
257
+ this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
193
258
  };
194
259
  };
260
+ async reloadNft() {
261
+ const address = this.state.keyringService.currentAccount.address;
262
+ const serviceInfo = this.state.getServiceInfo();
263
+ console.debug('Hard refresh NFT for', address);
264
+ this.resetNft(address);
265
+ this.removeCron('refreshNft');
266
+ this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
267
+ await waitTimeout(1800);
268
+ return true;
269
+ }
270
+ async reloadStaking() {
271
+ const address = this.state.keyringService.currentAccount.address;
272
+ console.debug('Hard refresh staking meta for', address);
273
+ this.resetStakingReward();
274
+ this.removeCron('refreshStakingReward');
275
+ this.removeCron('refreshPoolingStakingReward');
276
+ this.removeCron('updateNominatorMetadata');
277
+ this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
278
+ this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
279
+ this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
280
+ await waitTimeout(1800);
281
+ return true;
282
+ }
283
+ needUpdateNft(chainInfoMap, updatedChains) {
284
+ if (updatedChains && updatedChains.length > 0) {
285
+ return updatedChains.some(updatedChain => {
286
+ const chainInfo = chainInfoMap[updatedChain];
287
+ return _isChainSupportNativeNft(chainInfo) || _isChainSupportEvmNft(chainInfo) || _isChainSupportWasmNft(chainInfo);
288
+ });
289
+ }
290
+ return false;
291
+ }
292
+ needUpdateStaking(chainInfoMap, updatedChains) {
293
+ if (updatedChains && updatedChains.length > 0) {
294
+ return updatedChains.some(updatedChain => _isChainSupportSubstrateStaking(chainInfoMap[updatedChain]));
295
+ }
296
+ return false;
297
+ }
195
298
  }
@@ -40,7 +40,6 @@ export default class KoniExtension {
40
40
  private accountsGetAllWithCurrentAddress;
41
41
  private accountsGetAll;
42
42
  private saveRecentAccountId;
43
- private triggerAccountsSubscription;
44
43
  private _getAuthListV2;
45
44
  private authorizeSubscribeV2;
46
45
  private getAuthListV2;
@@ -154,7 +153,7 @@ export default class KoniExtension {
154
153
  private submitStakeWithdrawal;
155
154
  private submitStakeClaimReward;
156
155
  private submitCancelStakeWithdrawal;
157
- private submitPoolingBonding;
156
+ private submitPoolBonding;
158
157
  private submitPoolingUnbonding;
159
158
  private parseContractInput;
160
159
  private submitTuringStakeCompounding;
@@ -179,5 +178,6 @@ export default class KoniExtension {
179
178
  private getTransaction;
180
179
  private subscribeTransactions;
181
180
  private subscribeNotifications;
181
+ private reloadCron;
182
182
  handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
183
183
  }