@subwallet/extension-base 1.0.2-1b → 1.0.2-2
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 +34 -16
- package/background/KoniTypes.js +7 -6
- package/background/errors/TransactionError.js +1 -21
- package/cjs/background/KoniTypes.js +7 -6
- package/cjs/background/errors/TransactionError.js +0 -20
- package/cjs/constants/index.js +26 -8
- package/cjs/koni/api/dotsama/balance.js +224 -49
- package/cjs/koni/api/dotsama/transfer.js +29 -30
- package/cjs/koni/api/nft/acala_nft/index.js +1 -4
- package/cjs/koni/api/nft/bit.country/index.js +1 -4
- package/cjs/koni/api/nft/evm_nft/index.js +3 -7
- package/cjs/koni/api/nft/index.js +6 -3
- package/cjs/koni/api/nft/karura_nft/index.js +1 -4
- package/cjs/koni/api/nft/rmrk_nft/index.js +1 -8
- package/cjs/koni/api/nft/statemine_nft/index.js +1 -4
- package/cjs/koni/api/nft/unique_nft/index.js +1 -6
- package/cjs/koni/api/nft/wasm_nft/index.js +111 -169
- package/cjs/koni/api/nft/wasm_nft/utils.js +7 -11
- package/cjs/koni/api/staking/bonding/amplitude.js +9 -13
- package/cjs/koni/api/staking/bonding/astar.js +13 -15
- package/cjs/koni/api/staking/bonding/index.js +10 -22
- package/cjs/koni/api/staking/bonding/paraChain.js +2 -85
- package/cjs/koni/api/staking/bonding/relayChain.js +16 -119
- package/cjs/koni/api/staking/bonding/utils.js +8 -27
- package/cjs/koni/api/tokens/wasm/index.js +4 -5
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +13 -18
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +6 -9
- package/cjs/koni/background/cron.js +47 -150
- package/cjs/koni/background/handlers/Extension.js +64 -106
- package/cjs/koni/background/handlers/State.js +21 -19
- package/cjs/koni/background/handlers/Tabs.js +1 -8
- package/cjs/koni/background/subscription.js +29 -32
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +8 -13
- package/cjs/services/chain-service/handler/light-client/index.js +0 -2
- package/cjs/services/chain-service/index.js +7 -6
- package/cjs/services/event-service/index.js +1 -5
- package/cjs/services/event-service/types.js +1 -11
- package/cjs/services/history-service/index.js +10 -16
- package/cjs/services/history-service/subsquid-multi-chain-history.js +9 -12
- package/cjs/services/price-service/coingecko.js +1 -0
- package/cjs/services/price-service/index.js +3 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/cjs/services/storage-service/DatabaseService.js +33 -52
- package/cjs/services/storage-service/db-stores/Nft.js +17 -4
- package/cjs/services/transaction-service/event-parser/index.js +48 -20
- package/cjs/services/transaction-service/index.js +14 -23
- package/cjs/utils/index.js +14 -7
- package/constants/index.d.ts +13 -7
- package/constants/index.js +13 -7
- package/koni/api/dotsama/balance.d.ts +1 -0
- package/koni/api/dotsama/balance.js +197 -22
- package/koni/api/dotsama/transfer.js +4 -5
- package/koni/api/nft/acala_nft/index.js +1 -3
- package/koni/api/nft/bit.country/index.js +1 -3
- package/koni/api/nft/evm_nft/index.js +3 -6
- package/koni/api/nft/index.d.ts +2 -1
- package/koni/api/nft/index.js +6 -3
- package/koni/api/nft/karura_nft/index.js +1 -3
- package/koni/api/nft/nft.d.ts +0 -1
- package/koni/api/nft/rmrk_nft/index.js +1 -8
- package/koni/api/nft/statemine_nft/index.js +1 -3
- package/koni/api/nft/unique_nft/index.js +1 -5
- package/koni/api/nft/wasm_nft/index.d.ts +2 -0
- package/koni/api/nft/wasm_nft/index.js +109 -167
- package/koni/api/nft/wasm_nft/utils.d.ts +5 -7
- package/koni/api/nft/wasm_nft/utils.js +5 -7
- package/koni/api/staking/bonding/amplitude.d.ts +1 -0
- package/koni/api/staking/bonding/amplitude.js +10 -15
- package/koni/api/staking/bonding/astar.js +6 -8
- package/koni/api/staking/bonding/index.d.ts +1 -4
- package/koni/api/staking/bonding/index.js +13 -23
- package/koni/api/staking/bonding/paraChain.d.ts +0 -3
- package/koni/api/staking/bonding/paraChain.js +5 -86
- package/koni/api/staking/bonding/relayChain.d.ts +1 -5
- package/koni/api/staking/bonding/relayChain.js +18 -118
- package/koni/api/staking/bonding/utils.d.ts +2 -3
- package/koni/api/staking/bonding/utils.js +9 -27
- package/koni/api/tokens/wasm/index.js +4 -5
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +6 -5
- package/koni/api/xcm/utils.js +10 -15
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +9 -10
- package/koni/background/cron.d.ts +1 -6
- package/koni/background/cron.js +48 -151
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +67 -108
- package/koni/background/handlers/State.d.ts +6 -5
- package/koni/background/handlers/State.js +21 -19
- package/koni/background/handlers/Tabs.js +1 -8
- package/koni/background/subscription.js +30 -31
- package/package.json +8 -13
- package/packageInfo.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +9 -14
- package/services/chain-service/handler/light-client/index.d.ts +1 -17
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +881 -1041
- package/services/chain-service/helper/psp34_abi.json +1808 -2964
- package/services/chain-service/index.js +7 -6
- package/services/event-service/index.js +1 -5
- package/services/event-service/types.d.ts +9 -5
- package/services/event-service/types.js +1 -4
- package/services/history-service/index.d.ts +1 -1
- package/services/history-service/index.js +10 -16
- package/services/history-service/subsquid-multi-chain-history.js +11 -15
- package/services/price-service/coingecko.js +1 -0
- package/services/price-service/index.js +3 -2
- package/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/services/storage-service/DatabaseService.d.ts +0 -1
- package/services/storage-service/DatabaseService.js +33 -52
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +16 -4
- package/services/transaction-service/event-parser/index.js +49 -21
- package/services/transaction-service/index.js +14 -23
- package/utils/index.d.ts +1 -1
- package/utils/index.js +12 -6
- package/cjs/koni/api/tokens/wasm/utils.js +0 -63
- package/koni/api/tokens/wasm/utils.d.ts +0 -6
- package/koni/api/tokens/wasm/utils.js +0 -54
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.POLKADOT_UNLIMITED_WEIGHT = exports.POLKADOT_LIMITED_WEIGHT = exports.NETWORK_USE_UNLIMITED_WEIGHT = exports.FOUR_INSTRUCTIONS_WEIGHT = void 0;
|
|
7
7
|
exports.getBeneficiary = getBeneficiary;
|
|
8
|
-
exports.getDestWeight = getDestWeight;
|
|
9
8
|
exports.getReceiverLocation = getReceiverLocation;
|
|
10
9
|
var _chainList = require("@subwallet/chain-list");
|
|
11
10
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
@@ -13,18 +12,20 @@ var _utilCrypto = require("@polkadot/util-crypto");
|
|
|
13
12
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
14
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
14
|
|
|
16
|
-
const FOUR_INSTRUCTIONS_WEIGHT =
|
|
17
|
-
exports.FOUR_INSTRUCTIONS_WEIGHT = FOUR_INSTRUCTIONS_WEIGHT;
|
|
18
|
-
const FOUR_INSTRUCTIONS_LIMITED_WEIGHT = {
|
|
15
|
+
const FOUR_INSTRUCTIONS_WEIGHT = {
|
|
19
16
|
Limited: 5000000000
|
|
20
17
|
};
|
|
18
|
+
exports.FOUR_INSTRUCTIONS_WEIGHT = FOUR_INSTRUCTIONS_WEIGHT;
|
|
19
|
+
const POLKADOT_LIMITED_WEIGHT = 1000000000;
|
|
20
|
+
exports.POLKADOT_LIMITED_WEIGHT = POLKADOT_LIMITED_WEIGHT;
|
|
21
|
+
const POLKADOT_UNLIMITED_WEIGHT = 'Unlimited';
|
|
21
22
|
|
|
22
23
|
// get multilocation for destination chain from a parachain
|
|
23
|
-
exports.
|
|
24
|
+
exports.POLKADOT_UNLIMITED_WEIGHT = POLKADOT_UNLIMITED_WEIGHT;
|
|
24
25
|
function getReceiverLocation(originChainInfo, destinationChainInfo, toAddress) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
if (destinationChainInfo.slug === _chainList.COMMON_CHAIN_SLUGS.ASTAR_EVM || destinationChainInfo.slug === 'astarEvm') {
|
|
28
|
+
const ss58Address = (0, _utilCrypto.evmToAddress)(toAddress, (0, _utils._getChainSubstrateAddressPrefix)(destinationChainInfo));
|
|
28
29
|
return {
|
|
29
30
|
AccountId32: {
|
|
30
31
|
network: 'Any',
|
|
@@ -48,10 +49,9 @@ function getReceiverLocation(originChainInfo, destinationChainInfo, toAddress) {
|
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
51
|
function getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress) {
|
|
51
|
-
let version = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'V1';
|
|
52
52
|
const receiverLocation = getReceiverLocation(originChainInfo, destinationChainInfo, recipientAddress);
|
|
53
53
|
return {
|
|
54
|
-
|
|
54
|
+
V1: {
|
|
55
55
|
parents: 0,
|
|
56
56
|
interior: {
|
|
57
57
|
X1: receiverLocation
|
|
@@ -59,10 +59,5 @@ function getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress)
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// return api.tx.xTokens.transfer.meta.args[3].type.toString() ===
|
|
65
|
-
// 'XcmV2WeightLimit'
|
|
66
|
-
// ? 'Unlimited'
|
|
67
|
-
// : FOUR_INSTRUCTIONS_WEIGHT;
|
|
68
|
-
}
|
|
62
|
+
const NETWORK_USE_UNLIMITED_WEIGHT = ['acala', 'karura', 'statemint', 'moonriver'];
|
|
63
|
+
exports.NETWORK_USE_UNLIMITED_WEIGHT = NETWORK_USE_UNLIMITED_WEIGHT;
|
|
@@ -54,6 +54,6 @@ function getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo,
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
57
|
-
const weightParam =
|
|
57
|
+
const weightParam = _utils.NETWORK_USE_UNLIMITED_WEIGHT.includes(originChainInfo.slug) ? _utils.POLKADOT_UNLIMITED_WEIGHT : _utils.FOUR_INSTRUCTIONS_WEIGHT;
|
|
58
58
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo, recipientAddress), weightParam);
|
|
59
59
|
}
|
|
@@ -10,9 +10,8 @@ var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
|
10
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
11
|
|
|
12
12
|
function getDestinationChainLocation(destinationChainInfo) {
|
|
13
|
-
let version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'V1';
|
|
14
13
|
return {
|
|
15
|
-
|
|
14
|
+
V1: {
|
|
16
15
|
parents: 0,
|
|
17
16
|
interior: {
|
|
18
17
|
X1: {
|
|
@@ -23,10 +22,9 @@ function getDestinationChainLocation(destinationChainInfo) {
|
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
24
|
function getTokenLocation(sendingValue) {
|
|
26
|
-
let version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'V2';
|
|
27
25
|
return {
|
|
28
26
|
// always native token of relaychain
|
|
29
|
-
|
|
27
|
+
V1: [{
|
|
30
28
|
id: {
|
|
31
29
|
Concrete: {
|
|
32
30
|
parents: 0,
|
|
@@ -42,11 +40,10 @@ function getTokenLocation(sendingValue) {
|
|
|
42
40
|
|
|
43
41
|
// this pallet is only used by Relaychains
|
|
44
42
|
function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
45
|
-
const weightParam = (
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const tokenLocation = getTokenLocation(value, xcmVer);
|
|
43
|
+
const weightParam = _utils.NETWORK_USE_UNLIMITED_WEIGHT.includes(originChainInfo.slug) ? _utils.POLKADOT_UNLIMITED_WEIGHT : _utils.FOUR_INSTRUCTIONS_WEIGHT;
|
|
44
|
+
const destination = getDestinationChainLocation(destinationChainInfo);
|
|
45
|
+
const beneficiary = (0, _utils.getBeneficiary)(originChainInfo, destinationChainInfo, recipientAddress);
|
|
46
|
+
const tokenLocation = getTokenLocation(value);
|
|
50
47
|
let method = 'limitedReserveTransferAssets';
|
|
51
48
|
if (['statemint', 'statemine'].includes(destinationChainInfo.slug)) {
|
|
52
49
|
method = 'limitedTeleportAssets';
|
|
@@ -5,9 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.KoniCron = void 0;
|
|
7
7
|
var _constants = require("@subwallet/extension-base/constants");
|
|
8
|
-
var _types = require("@subwallet/extension-base/services/chain-service/types");
|
|
9
|
-
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
10
|
-
var _utils2 = require("@subwallet/extension-base/utils");
|
|
11
8
|
var _rxjs = require("rxjs");
|
|
12
9
|
var _util = require("@polkadot/util");
|
|
13
10
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -61,26 +58,21 @@ class KoniCron {
|
|
|
61
58
|
delete this.cronMap[key];
|
|
62
59
|
});
|
|
63
60
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// } else {
|
|
80
|
-
// this.setStakingRewardReady();
|
|
81
|
-
// }
|
|
82
|
-
// };
|
|
83
|
-
|
|
61
|
+
init = () => {
|
|
62
|
+
const currentAccountInfo = this.state.keyringService.currentAccount;
|
|
63
|
+
if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
67
|
+
this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap());
|
|
68
|
+
this.refreshStakingReward(currentAccountInfo.address);
|
|
69
|
+
this.refreshStakingRewardFastInterval(currentAccountInfo.address);
|
|
70
|
+
this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
|
|
71
|
+
this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
|
|
72
|
+
} else {
|
|
73
|
+
this.setStakingRewardReady();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
84
76
|
start = () => {
|
|
85
77
|
if (this.status === 'running') {
|
|
86
78
|
return;
|
|
@@ -93,7 +85,6 @@ class KoniCron {
|
|
|
93
85
|
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
94
86
|
this.resetNft(currentAccountInfo.address);
|
|
95
87
|
this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), _constants.CRON_REFRESH_NFT_INTERVAL);
|
|
96
|
-
this.addCron('checkStatusApiMap', this.updateApiMapStatus, _constants.CRON_GET_API_MAP_STATUS);
|
|
97
88
|
this.addCron('recoverApiMap', this.recoverApiMap, _constants.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
98
89
|
this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
99
90
|
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
@@ -102,74 +93,46 @@ class KoniCron {
|
|
|
102
93
|
} else {
|
|
103
94
|
this.setStakingRewardReady();
|
|
104
95
|
}
|
|
105
|
-
const
|
|
106
|
-
this.
|
|
96
|
+
const reloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'chain.update', 'chain.enable', 'asset.update', 'asset.enable', 'transaction.done', 'transaction.failed'];
|
|
97
|
+
this.state.eventService.onLazy((events, eventTypes) => {
|
|
107
98
|
var _serviceInfo$currentA;
|
|
108
99
|
const serviceInfo = this.state.getServiceInfo();
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
const stakingSubmitted = eventTypes.includes('transaction.submitStaking');
|
|
112
|
-
const updatedChains = [];
|
|
113
|
-
if (chainUpdated) {
|
|
114
|
-
events.forEach(event => {
|
|
115
|
-
if (event.type === 'chain.updateState') {
|
|
116
|
-
const updatedData = event.data;
|
|
117
|
-
updatedChains.push(updatedData[0]);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
if (!commonReload && !chainUpdated && !stakingSubmitted) {
|
|
100
|
+
const needReload = eventTypes.some(eT => reloadEvents.includes(eT));
|
|
101
|
+
if (!needReload) {
|
|
122
102
|
return;
|
|
123
103
|
}
|
|
124
|
-
this.logger.log('ServiceInfo updated,
|
|
104
|
+
this.logger.log('ServiceInfo updated, restarting...');
|
|
125
105
|
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
126
106
|
if (!address) {
|
|
127
107
|
return;
|
|
128
108
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.resetStakingReward();
|
|
139
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshStakingReward');
|
|
140
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshPoolingStakingReward');
|
|
141
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('updateNominatorMetadata');
|
|
142
|
-
needUpdateStaking && this.removeCron('updateChainStakingMetadata');
|
|
143
|
-
|
|
144
|
-
// Chains
|
|
145
|
-
chainUpdated && this.removeCron('checkStatusApiMap');
|
|
146
|
-
chainUpdated && this.removeCron('recoverApiMap');
|
|
109
|
+
this.resetStakingReward();
|
|
110
|
+
this.resetNft(address);
|
|
111
|
+
this.removeCron('refreshNft');
|
|
112
|
+
this.removeCron('refreshStakingReward');
|
|
113
|
+
this.removeCron('refreshPoolingStakingReward');
|
|
114
|
+
this.removeCron('checkStatusApiMap');
|
|
115
|
+
this.removeCron('recoverApiMap');
|
|
116
|
+
this.removeCron('updateChainStakingMetadata');
|
|
117
|
+
this.removeCron('updateNominatorMetadata');
|
|
147
118
|
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
148
119
|
// only add cron job if there's at least 1 active network
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
needUpdateStaking && this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), _constants.CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
120
|
+
this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), _constants.CRON_REFRESH_NFT_INTERVAL);
|
|
121
|
+
this.addCron('recoverApiMap', this.recoverApiMap, _constants.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
122
|
+
this.addCron('refreshStakingReward', this.refreshStakingReward(address), _constants.CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
123
|
+
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
124
|
+
this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), _constants.CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
125
|
+
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), _constants.CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
156
126
|
} else {
|
|
157
127
|
this.setStakingRewardReady();
|
|
158
128
|
}
|
|
159
|
-
};
|
|
160
|
-
this.state.eventService.onLazy(this.eventHandler);
|
|
129
|
+
});
|
|
161
130
|
this.status = 'running';
|
|
162
131
|
};
|
|
163
132
|
stop = () => {
|
|
164
133
|
if (this.status === 'stopped') {
|
|
165
134
|
return;
|
|
166
135
|
}
|
|
167
|
-
|
|
168
|
-
// Unsubscribe events
|
|
169
|
-
if (this.eventHandler) {
|
|
170
|
-
this.state.eventService.offLazy(this.eventHandler);
|
|
171
|
-
this.eventHandler = undefined;
|
|
172
|
-
}
|
|
173
136
|
if (this.serviceSubscription) {
|
|
174
137
|
this.serviceSubscription.unsubscribe();
|
|
175
138
|
this.serviceSubscription = undefined;
|
|
@@ -178,36 +141,6 @@ class KoniCron {
|
|
|
178
141
|
this.removeAllCrons();
|
|
179
142
|
this.status = 'stopped';
|
|
180
143
|
};
|
|
181
|
-
updateApiMapStatus = () => {
|
|
182
|
-
const apiMap = this.state.getApiMap();
|
|
183
|
-
const networkMap = this.state.getChainStateMap();
|
|
184
|
-
for (const [key, substrateApi] of Object.entries(apiMap.substrate)) {
|
|
185
|
-
let status = _types._ChainConnectionStatus.CONNECTING;
|
|
186
|
-
if (substrateApi.isApiConnected) {
|
|
187
|
-
status = _types._ChainConnectionStatus.CONNECTED;
|
|
188
|
-
}
|
|
189
|
-
if (!networkMap[key].connectionStatus) {
|
|
190
|
-
this.state.updateChainConnectionStatus(key, status);
|
|
191
|
-
} else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== status) {
|
|
192
|
-
this.state.updateChainConnectionStatus(key, status);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
for (const [key, evmApi] of Object.entries(apiMap.evm)) {
|
|
196
|
-
evmApi.api.eth.net.isListening().then(() => {
|
|
197
|
-
if (!networkMap[key].connectionStatus) {
|
|
198
|
-
this.state.updateChainConnectionStatus(key, _types._ChainConnectionStatus.CONNECTED);
|
|
199
|
-
} else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _types._ChainConnectionStatus.CONNECTED) {
|
|
200
|
-
this.state.updateChainConnectionStatus(key, _types._ChainConnectionStatus.CONNECTED);
|
|
201
|
-
}
|
|
202
|
-
}).catch(() => {
|
|
203
|
-
if (!networkMap[key].connectionStatus) {
|
|
204
|
-
this.state.updateChainConnectionStatus(key, _types._ChainConnectionStatus.CONNECTING);
|
|
205
|
-
} else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _types._ChainConnectionStatus.CONNECTING) {
|
|
206
|
-
this.state.updateChainConnectionStatus(key, _types._ChainConnectionStatus.CONNECTING);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
144
|
recoverApiMap = () => {
|
|
212
145
|
var _this$subscriptions;
|
|
213
146
|
const apiMap = this.state.getApiMap();
|
|
@@ -228,26 +161,28 @@ class KoniCron {
|
|
|
228
161
|
};
|
|
229
162
|
refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
|
|
230
163
|
return () => {
|
|
231
|
-
|
|
164
|
+
this.logger.log('Refresh Nft state');
|
|
232
165
|
this.subscriptions.subscribeNft(address, apiMap.substrate, apiMap.evm, smartContractNfts, chainInfoMap);
|
|
233
166
|
};
|
|
234
167
|
};
|
|
235
168
|
resetNft = newAddress => {
|
|
169
|
+
this.logger.log('Reset Nft state');
|
|
236
170
|
this.state.resetNft(newAddress);
|
|
237
171
|
};
|
|
238
172
|
resetStakingReward = () => {
|
|
173
|
+
this.logger.log('Reset Staking Reward State');
|
|
239
174
|
this.state.resetStakingReward();
|
|
240
175
|
};
|
|
241
176
|
refreshStakingReward = address => {
|
|
242
177
|
return () => {
|
|
243
|
-
|
|
244
|
-
this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
|
|
178
|
+
this.logger.log('Fetching staking reward data');
|
|
179
|
+
this.subscriptions.subscribeStakingReward(address).then(() => this.logger.log('Refresh staking reward state')).catch(this.logger.error);
|
|
245
180
|
};
|
|
246
181
|
};
|
|
247
182
|
refreshStakingRewardFastInterval = address => {
|
|
248
183
|
return () => {
|
|
249
|
-
|
|
250
|
-
this.subscriptions.subscribeStakingRewardFastInterval(address).catch(this.logger.error);
|
|
184
|
+
this.logger.log('Fetching staking reward data with fast interval');
|
|
185
|
+
this.subscriptions.subscribeStakingRewardFastInterval(address).then(() => this.logger.log('Refresh staking reward state with fast interval')).catch(this.logger.error);
|
|
251
186
|
};
|
|
252
187
|
};
|
|
253
188
|
setStakingRewardReady = () => {
|
|
@@ -258,53 +193,15 @@ class KoniCron {
|
|
|
258
193
|
};
|
|
259
194
|
updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
260
195
|
return () => {
|
|
261
|
-
|
|
262
|
-
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
196
|
+
this.logger.log('Fetching chain staking metadata');
|
|
197
|
+
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).then(() => this.logger.log('Updated chain staking metadata')).catch(this.logger.error);
|
|
263
198
|
};
|
|
264
199
|
};
|
|
265
200
|
updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
266
201
|
return () => {
|
|
267
|
-
|
|
268
|
-
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
202
|
+
this.logger.log('Fetching nominator data', address);
|
|
203
|
+
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).then(() => this.logger.log('Updated nominator data', address)).catch(this.logger.error);
|
|
269
204
|
};
|
|
270
205
|
};
|
|
271
|
-
async reloadNft() {
|
|
272
|
-
const address = this.state.keyringService.currentAccount.address;
|
|
273
|
-
const serviceInfo = this.state.getServiceInfo();
|
|
274
|
-
console.debug('Hard refresh NFT for', address);
|
|
275
|
-
this.resetNft(address);
|
|
276
|
-
this.removeCron('refreshNft');
|
|
277
|
-
this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), _constants.CRON_REFRESH_NFT_INTERVAL);
|
|
278
|
-
await (0, _utils2.waitTimeout)(1800);
|
|
279
|
-
return true;
|
|
280
|
-
}
|
|
281
|
-
async reloadStaking() {
|
|
282
|
-
const address = this.state.keyringService.currentAccount.address;
|
|
283
|
-
console.debug('Hard refresh staking meta for', address);
|
|
284
|
-
this.resetStakingReward();
|
|
285
|
-
this.removeCron('refreshStakingReward');
|
|
286
|
-
this.removeCron('refreshPoolingStakingReward');
|
|
287
|
-
this.removeCron('updateNominatorMetadata');
|
|
288
|
-
this.addCron('refreshStakingReward', this.refreshStakingReward(address), _constants.CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
289
|
-
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
290
|
-
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), _constants.CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
291
|
-
await (0, _utils2.waitTimeout)(1800);
|
|
292
|
-
return true;
|
|
293
|
-
}
|
|
294
|
-
needUpdateNft(chainInfoMap, updatedChains) {
|
|
295
|
-
if (updatedChains && updatedChains.length > 0) {
|
|
296
|
-
return updatedChains.some(updatedChain => {
|
|
297
|
-
const chainInfo = chainInfoMap[updatedChain];
|
|
298
|
-
return (0, _utils._isChainSupportNativeNft)(chainInfo) || (0, _utils._isChainSupportEvmNft)(chainInfo) || (0, _utils._isChainSupportWasmNft)(chainInfo);
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
needUpdateStaking(chainInfoMap, updatedChains) {
|
|
304
|
-
if (updatedChains && updatedChains.length > 0) {
|
|
305
|
-
return updatedChains.some(updatedChain => (0, _utils._isChainSupportSubstrateStaking)(chainInfoMap[updatedChain]));
|
|
306
|
-
}
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
206
|
}
|
|
310
207
|
exports.KoniCron = KoniCron;
|