@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.
- package/background/KoniTypes.d.ts +25 -36
- package/background/KoniTypes.js +12 -7
- package/background/errors/TransactionError.js +21 -1
- package/cjs/background/KoniTypes.js +14 -8
- package/cjs/background/errors/TransactionError.js +20 -0
- package/cjs/constants/index.js +13 -28
- package/cjs/koni/api/dotsama/balance.js +60 -224
- package/cjs/koni/api/dotsama/transfer.js +30 -29
- package/cjs/koni/api/nft/acala_nft/index.js +4 -1
- package/cjs/koni/api/nft/bit.country/index.js +4 -1
- package/cjs/koni/api/nft/evm_nft/index.js +7 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +4 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
- package/cjs/koni/api/nft/unique_nft/index.js +6 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
- package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
- package/cjs/koni/api/staking/bonding/amplitude.js +18 -10
- package/cjs/koni/api/staking/bonding/astar.js +37 -238
- package/cjs/koni/api/staking/bonding/index.js +26 -14
- package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
- package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
- package/cjs/koni/api/staking/bonding/utils.js +55 -10
- package/cjs/koni/api/tokens/wasm/index.js +5 -4
- package/cjs/koni/api/tokens/wasm/utils.js +63 -0
- package/cjs/koni/api/xcm/index.js +0 -111
- package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +3 -5
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +179 -77
- package/cjs/koni/background/handlers/Extension.js +231 -195
- package/cjs/koni/background/handlers/State.js +147 -111
- package/cjs/koni/background/handlers/Tabs.js +48 -39
- package/cjs/koni/background/subscription.js +64 -56
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +5 -0
- package/cjs/services/chain-service/constants.js +1 -11
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/handler/light-client/index.js +2 -0
- package/cjs/services/chain-service/index.js +39 -6
- package/cjs/services/chain-service/utils.js +4 -0
- package/cjs/services/event-service/index.js +75 -0
- package/cjs/services/event-service/types.js +11 -0
- package/cjs/services/history-service/index.js +46 -21
- package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
- package/cjs/services/keyring-service/index.js +101 -0
- package/cjs/services/migration-service/index.js +13 -10
- package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
- package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
- package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
- package/cjs/services/migration-service/scripts/index.js +13 -4
- package/cjs/services/price-service/coingecko.js +15 -3
- package/cjs/services/price-service/index.js +15 -18
- package/cjs/services/request-service/constants.js +8 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/storage-service/DatabaseService.js +53 -34
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/cjs/services/storage-service/db-stores/Nft.js +8 -18
- package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
- package/cjs/services/subscan-service/index.js +107 -0
- package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
- package/cjs/services/subscan-service/types.js +1 -0
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +66 -22
- package/cjs/services/transaction-service/utils.js +4 -6
- package/cjs/utils/address.js +9 -1
- package/cjs/utils/index.js +30 -26
- package/constants/index.d.ts +8 -13
- package/constants/index.js +8 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +33 -197
- package/koni/api/dotsama/transfer.js +5 -4
- package/koni/api/nft/acala_nft/index.js +3 -1
- package/koni/api/nft/bit.country/index.js +3 -1
- package/koni/api/nft/evm_nft/index.js +6 -3
- package/koni/api/nft/index.d.ts +1 -2
- package/koni/api/nft/index.js +3 -6
- package/koni/api/nft/karura_nft/index.js +3 -1
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +8 -1
- package/koni/api/nft/statemine_nft/index.js +3 -1
- package/koni/api/nft/unique_nft/index.js +5 -1
- package/koni/api/nft/wasm_nft/index.d.ts +0 -2
- package/koni/api/nft/wasm_nft/index.js +167 -109
- package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
- package/koni/api/nft/wasm_nft/utils.js +7 -5
- package/koni/api/staking/bonding/amplitude.d.ts +1 -2
- package/koni/api/staking/bonding/amplitude.js +22 -13
- package/koni/api/staking/bonding/astar.d.ts +2 -11
- package/koni/api/staking/bonding/astar.js +39 -231
- package/koni/api/staking/bonding/index.d.ts +5 -2
- package/koni/api/staking/bonding/index.js +27 -17
- package/koni/api/staking/bonding/paraChain.d.ts +4 -1
- package/koni/api/staking/bonding/paraChain.js +101 -14
- package/koni/api/staking/bonding/relayChain.d.ts +6 -2
- package/koni/api/staking/bonding/relayChain.js +172 -17
- package/koni/api/staking/bonding/utils.d.ts +15 -2
- package/koni/api/staking/bonding/utils.js +53 -11
- package/koni/api/tokens/wasm/index.js +5 -4
- package/koni/api/tokens/wasm/utils.d.ts +6 -0
- package/koni/api/tokens/wasm/utils.js +54 -0
- package/koni/api/xcm/index.js +1 -112
- package/koni/api/xcm/polkadotXcm.js +3 -3
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +5 -7
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +179 -76
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +161 -125
- package/koni/background/handlers/State.d.ts +21 -20
- package/koni/background/handlers/State.js +144 -111
- package/koni/background/handlers/Tabs.js +30 -20
- package/koni/background/subscription.d.ts +1 -1
- package/koni/background/subscription.js +64 -58
- package/package.json +63 -18
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -0
- package/page/index.js +4 -0
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +0 -9
- package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
- package/services/chain-service/handler/light-client/index.d.ts +17 -1
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +1041 -881
- package/services/chain-service/helper/psp34_abi.json +2963 -1807
- package/services/chain-service/index.d.ts +6 -4
- package/services/chain-service/index.js +40 -9
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +3 -0
- package/services/event-service/index.d.ts +22 -0
- package/services/event-service/index.js +63 -0
- package/services/event-service/types.d.ts +28 -0
- package/services/event-service/types.js +4 -0
- package/services/history-service/index.d.ts +5 -3
- package/services/history-service/index.js +46 -21
- package/services/history-service/subsquid-multi-chain-history.js +22 -13
- package/services/keyring-service/index.d.ts +19 -0
- package/services/keyring-service/index.js +93 -0
- package/services/migration-service/index.js +11 -9
- package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
- package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
- package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
- package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
- package/services/migration-service/scripts/MigrateSettings.js +23 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
- package/services/migration-service/scripts/index.d.ts +1 -0
- package/services/migration-service/scripts/index.js +10 -3
- package/services/price-service/coingecko.js +15 -3
- package/services/price-service/index.d.ts +5 -3
- package/services/price-service/index.js +15 -18
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +6 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
- package/services/request-service/handler/AuthRequestHandler.js +44 -13
- package/services/request-service/index.d.ts +7 -1
- package/services/request-service/index.js +3 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +53 -34
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/services/storage-service/db-stores/Nft.d.ts +3 -3
- package/services/storage-service/db-stores/Nft.js +8 -17
- package/services/storage-service/db-stores/Transaction.js +10 -7
- package/services/subscan-service/index.d.ts +20 -0
- package/services/subscan-service/index.js +99 -0
- package/services/subscan-service/subscan-chain-map.d.ts +5 -0
- package/services/subscan-service/subscan-chain-map.js +63 -0
- package/services/subscan-service/types.d.ts +27 -0
- package/services/subscan-service/types.js +1 -0
- package/services/transaction-service/event-parser/index.d.ts +2 -2
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.d.ts +4 -2
- package/services/transaction-service/index.js +66 -22
- package/services/transaction-service/utils.js +5 -6
- package/utils/address.d.ts +1 -0
- package/utils/address.js +9 -2
- package/utils/index.d.ts +2 -1
- package/utils/index.js +26 -23
- package/cjs/background/errors/EvmRpcError.js +0 -21
- package/cjs/background/errors/SubWalletProviderError.js +0 -17
- package/cjs/constants/ethereum.js +0 -19
- package/cjs/errors/SubWalletProviderError.js +0 -17
- package/cjs/koni/api/xcm/astar.js +0 -160
- package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
- package/cjs/koni/api/xcm/statemintXcm.js +0 -197
- package/cjs/koni/api/xcm/substrateXcm.js +0 -213
- package/cjs/koni/migration/Base.js +0 -20
- package/cjs/koni/migration/index.js +0 -45
- package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
- package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
- package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
- package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
- package/cjs/koni/migration/scripts/index.js +0 -22
- package/cjs/koni/page/index.js +0 -16
- package/cjs/services/asset-service/index.js +0 -91
- package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
- package/cjs/stores/Balance.js +0 -18
- package/cjs/stores/Crowdloan.js +0 -18
- package/cjs/stores/CustomEvmToken.js +0 -18
- package/cjs/stores/NetworkMap.js +0 -18
- package/cjs/stores/Nft.js +0 -18
- package/cjs/stores/NftCollection.js +0 -18
- package/cjs/stores/Price.js +0 -18
- package/cjs/stores/Staking.js +0 -18
- package/cjs/stores/StakingReward.js +0 -18
- package/cjs/utils/eth/parseTransactionData.js +0 -284
- package/koni/page/index.d.ts +0 -2
- package/koni/page/index.js +0 -9
- /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
package/koni/background/cron.js
CHANGED
|
@@ -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,80 +50,115 @@ export class KoniCron {
|
|
|
47
50
|
delete this.cronMap[key];
|
|
48
51
|
});
|
|
49
52
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
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
|
+
|
|
66
73
|
start = () => {
|
|
67
74
|
if (this.status === 'running') {
|
|
68
75
|
return;
|
|
69
76
|
}
|
|
70
77
|
this.logger.log('Starting cron jobs');
|
|
71
|
-
this.state.
|
|
72
|
-
|
|
78
|
+
const currentAccountInfo = this.state.keyringService.currentAccount;
|
|
79
|
+
if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
83
|
+
this.resetNft(currentAccountInfo.address);
|
|
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);
|
|
86
|
+
this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
87
|
+
this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
88
|
+
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
89
|
+
this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
90
|
+
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
91
|
+
} else {
|
|
92
|
+
this.setStakingRewardReady();
|
|
93
|
+
}
|
|
94
|
+
const commonReloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'asset.updateState'];
|
|
95
|
+
this.eventHandler = (events, eventTypes) => {
|
|
96
|
+
var _serviceInfo$currentA;
|
|
97
|
+
const serviceInfo = this.state.getServiceInfo();
|
|
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) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.logger.log('ServiceInfo updated, Cron restarting...', eventTypes);
|
|
114
|
+
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
115
|
+
if (!address) {
|
|
73
116
|
return;
|
|
74
117
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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');
|
|
136
|
+
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
137
|
+
// only add cron job if there's at least 1 active network
|
|
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);
|
|
83
145
|
} else {
|
|
84
146
|
this.setStakingRewardReady();
|
|
85
147
|
}
|
|
86
|
-
}
|
|
87
|
-
this.
|
|
88
|
-
next: serviceInfo => {
|
|
89
|
-
var _serviceInfo$currentA;
|
|
90
|
-
this.logger.log('ServiceInfo updated, restarting...');
|
|
91
|
-
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
92
|
-
if (!address) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
this.resetStakingReward();
|
|
96
|
-
this.resetNft(address);
|
|
97
|
-
this.removeCron('refreshNft');
|
|
98
|
-
this.removeCron('refreshStakingReward');
|
|
99
|
-
this.removeCron('refreshPoolingStakingReward');
|
|
100
|
-
this.removeCron('refreshPrice');
|
|
101
|
-
this.removeCron('checkStatusApiMap');
|
|
102
|
-
this.removeCron('recoverApiMap');
|
|
103
|
-
this.removeCron('updateChainStakingMetadata');
|
|
104
|
-
this.removeCron('updateNominatorMetadata');
|
|
105
|
-
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
106
|
-
// only add cron job if there's at least 1 active network
|
|
107
|
-
this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
108
|
-
this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
109
|
-
this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
110
|
-
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
111
|
-
this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
112
|
-
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
113
|
-
} else {
|
|
114
|
-
this.setStakingRewardReady();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
148
|
+
};
|
|
149
|
+
this.state.eventService.onLazy(this.eventHandler);
|
|
118
150
|
this.status = 'running';
|
|
119
151
|
};
|
|
120
152
|
stop = () => {
|
|
121
153
|
if (this.status === 'stopped') {
|
|
122
154
|
return;
|
|
123
155
|
}
|
|
156
|
+
|
|
157
|
+
// Unsubscribe events
|
|
158
|
+
if (this.eventHandler) {
|
|
159
|
+
this.state.eventService.offLazy(this.eventHandler);
|
|
160
|
+
this.eventHandler = undefined;
|
|
161
|
+
}
|
|
124
162
|
if (this.serviceSubscription) {
|
|
125
163
|
this.serviceSubscription.unsubscribe();
|
|
126
164
|
this.serviceSubscription = undefined;
|
|
@@ -129,7 +167,38 @@ export class KoniCron {
|
|
|
129
167
|
this.removeAllCrons();
|
|
130
168
|
this.status = 'stopped';
|
|
131
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
|
+
};
|
|
132
200
|
recoverApiMap = () => {
|
|
201
|
+
var _this$subscriptions;
|
|
133
202
|
const apiMap = this.state.getApiMap();
|
|
134
203
|
for (const [networkKey, apiProp] of Object.entries(apiMap.substrate)) {
|
|
135
204
|
if (!apiProp.isApiConnected) {
|
|
@@ -141,37 +210,33 @@ export class KoniCron {
|
|
|
141
210
|
this.state.refreshWeb3Api(key);
|
|
142
211
|
});
|
|
143
212
|
}
|
|
144
|
-
|
|
213
|
+
const {
|
|
145
214
|
address
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
((_this$subscriptions = this.subscriptions) === null || _this$subscriptions === void 0 ? void 0 : _this$subscriptions.subscribeBalancesAndCrowdloans) && this.subscriptions.subscribeBalancesAndCrowdloans(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
149
|
-
});
|
|
215
|
+
} = this.state.keyringService.currentAccount;
|
|
216
|
+
((_this$subscriptions = this.subscriptions) === null || _this$subscriptions === void 0 ? void 0 : _this$subscriptions.subscribeBalancesAndCrowdloans) && this.subscriptions.subscribeBalancesAndCrowdloans(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
150
217
|
};
|
|
151
218
|
refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
|
|
152
219
|
return () => {
|
|
153
|
-
|
|
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.
|
|
159
|
-
this.state.resetNft(newAddress).catch(e => this.logger.warn(e));
|
|
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
|
-
|
|
168
|
-
this.subscriptions.subscribeStakingReward(address).
|
|
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
|
-
|
|
174
|
-
this.subscriptions.subscribeStakingRewardFastInterval(address).
|
|
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
|
-
|
|
186
|
-
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).
|
|
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
|
-
|
|
192
|
-
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).
|
|
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
|
|
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
|
}
|