@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.
- package/background/KoniTypes.d.ts +16 -34
- package/background/KoniTypes.js +6 -7
- package/background/errors/TransactionError.js +21 -1
- package/cjs/background/KoniTypes.js +6 -7
- package/cjs/background/errors/TransactionError.js +20 -0
- package/cjs/constants/index.js +8 -26
- package/cjs/koni/api/dotsama/balance.js +49 -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 +13 -9
- package/cjs/koni/api/staking/bonding/astar.js +15 -13
- package/cjs/koni/api/staking/bonding/index.js +22 -10
- package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +119 -16
- package/cjs/koni/api/staking/bonding/utils.js +27 -8
- 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/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +150 -47
- package/cjs/koni/background/handlers/Extension.js +106 -64
- package/cjs/koni/background/handlers/State.js +19 -21
- package/cjs/koni/background/handlers/Tabs.js +8 -1
- package/cjs/koni/background/subscription.js +32 -29
- 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 +6 -7
- package/cjs/services/event-service/index.js +5 -1
- package/cjs/services/event-service/types.js +11 -1
- package/cjs/services/history-service/index.js +16 -10
- package/cjs/services/history-service/subsquid-multi-chain-history.js +12 -9
- package/cjs/services/price-service/coingecko.js +0 -1
- package/cjs/services/price-service/index.js +2 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +6 -2
- package/cjs/services/storage-service/DatabaseService.js +52 -33
- package/cjs/services/storage-service/db-stores/Nft.js +4 -17
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +23 -14
- package/cjs/utils/index.js +7 -14
- package/constants/index.d.ts +7 -13
- package/constants/index.js +7 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +22 -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 +0 -1
- package/koni/api/staking/bonding/amplitude.js +15 -10
- package/koni/api/staking/bonding/astar.js +8 -6
- package/koni/api/staking/bonding/index.d.ts +4 -1
- package/koni/api/staking/bonding/index.js +23 -13
- package/koni/api/staking/bonding/paraChain.d.ts +3 -0
- package/koni/api/staking/bonding/paraChain.js +86 -5
- package/koni/api/staking/bonding/relayChain.d.ts +5 -1
- package/koni/api/staking/bonding/relayChain.js +118 -18
- package/koni/api/staking/bonding/utils.d.ts +3 -2
- package/koni/api/staking/bonding/utils.js +27 -9
- 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/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +151 -48
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +108 -67
- package/koni/background/handlers/State.d.ts +5 -6
- package/koni/background/handlers/State.js +19 -21
- package/koni/background/handlers/Tabs.js +8 -1
- package/koni/background/subscription.js +31 -30
- package/package.json +9 -4
- 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.js +6 -7
- package/services/event-service/index.js +5 -1
- package/services/event-service/types.d.ts +5 -9
- package/services/event-service/types.js +4 -1
- package/services/history-service/index.d.ts +1 -1
- package/services/history-service/index.js +16 -10
- package/services/history-service/subsquid-multi-chain-history.js +15 -11
- package/services/price-service/coingecko.js +0 -1
- package/services/price-service/index.js +2 -3
- package/services/request-service/handler/AuthRequestHandler.js +6 -2
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +52 -33
- package/services/storage-service/db-stores/Nft.d.ts +1 -2
- package/services/storage-service/db-stores/Nft.js +4 -16
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.js +23 -14
- package/utils/index.d.ts +1 -1
- package/utils/index.js +6 -12
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultWeightV2 = getDefaultWeightV2;
|
|
7
|
+
exports.getWasmContractGasLimit = getWasmContractGasLimit;
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
const MAX_CALL_WEIGHT = '5000000000000';
|
|
13
|
+
const DEFAULT_REF_TIME = '1000000000000';
|
|
14
|
+
const toContractAbiMessage = (contractPromise, message) => {
|
|
15
|
+
const value = contractPromise.abi.messages.find(m => m.method === message);
|
|
16
|
+
if (!value) {
|
|
17
|
+
const messages = contractPromise === null || contractPromise === void 0 ? void 0 : contractPromise.abi.messages.map(m => m.method).join(', ');
|
|
18
|
+
const error = `"${message}" not found in metadata.spec.messages: [${messages}]`;
|
|
19
|
+
console.error(error);
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
error
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
ok: true,
|
|
27
|
+
value
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
async function getWasmContractGasLimit(api, callerAddress, message, contract) {
|
|
31
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
32
|
+
let args = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
33
|
+
try {
|
|
34
|
+
var _abiMessage$value;
|
|
35
|
+
const abiMessage = toContractAbiMessage(contract, message);
|
|
36
|
+
if (!abiMessage.ok) {
|
|
37
|
+
return getDefaultWeightV2(api, true);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
const {
|
|
42
|
+
gasLimit,
|
|
43
|
+
storageDepositLimit,
|
|
44
|
+
value
|
|
45
|
+
} = options;
|
|
46
|
+
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
const {
|
|
49
|
+
gasRequired
|
|
50
|
+
} = await api.call.contractsApi.call(callerAddress, contract.address, value !== null && value !== void 0 ? value : new _util.BN(0), gasLimit !== null && gasLimit !== void 0 ? gasLimit : null, storageDepositLimit !== null && storageDepositLimit !== void 0 ? storageDepositLimit : null, abiMessage === null || abiMessage === void 0 ? void 0 : (_abiMessage$value = abiMessage.value) === null || _abiMessage$value === void 0 ? void 0 : _abiMessage$value.toU8a(args));
|
|
51
|
+
return gasRequired;
|
|
52
|
+
} catch {
|
|
53
|
+
return getDefaultWeightV2(api, true);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function getDefaultWeightV2(apiPromise, isFallback) {
|
|
57
|
+
const proofSize = isFallback ? 3407872 : MAX_CALL_WEIGHT; // TODO: handle error better
|
|
58
|
+
const refTime = isFallback ? 32490000000 : DEFAULT_REF_TIME;
|
|
59
|
+
return apiPromise.registry.createType('WeightV2', {
|
|
60
|
+
refTime,
|
|
61
|
+
proofSize
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -42,7 +42,7 @@ function getAssetLocation(tokenInfo, sendingValue) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
45
|
-
const weightParam = _utils.
|
|
45
|
+
const weightParam = (0, _utils.getDestWeight)();
|
|
46
46
|
const beneficiary = (0, _utils.getBeneficiary)(originChainInfo, destinationChainInfo, recipientAddress);
|
|
47
47
|
const destination = getDestinationChainLocation(destinationChainInfo);
|
|
48
48
|
const assetLocation = getAssetLocation(tokenInfo, value);
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.FOUR_INSTRUCTIONS_WEIGHT = exports.FOUR_INSTRUCTIONS_LIMITED_WEIGHT = void 0;
|
|
7
7
|
exports.getBeneficiary = getBeneficiary;
|
|
8
|
+
exports.getDestWeight = getDestWeight;
|
|
8
9
|
exports.getReceiverLocation = getReceiverLocation;
|
|
9
10
|
var _chainList = require("@subwallet/chain-list");
|
|
10
11
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
@@ -12,20 +13,18 @@ var _utilCrypto = require("@polkadot/util-crypto");
|
|
|
12
13
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
13
14
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
15
|
|
|
15
|
-
const FOUR_INSTRUCTIONS_WEIGHT =
|
|
16
|
+
const FOUR_INSTRUCTIONS_WEIGHT = 5000000000;
|
|
17
|
+
exports.FOUR_INSTRUCTIONS_WEIGHT = FOUR_INSTRUCTIONS_WEIGHT;
|
|
18
|
+
const FOUR_INSTRUCTIONS_LIMITED_WEIGHT = {
|
|
16
19
|
Limited: 5000000000
|
|
17
20
|
};
|
|
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';
|
|
22
21
|
|
|
23
22
|
// get multilocation for destination chain from a parachain
|
|
24
|
-
exports.
|
|
23
|
+
exports.FOUR_INSTRUCTIONS_LIMITED_WEIGHT = FOUR_INSTRUCTIONS_LIMITED_WEIGHT;
|
|
25
24
|
function getReceiverLocation(originChainInfo, destinationChainInfo, toAddress) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if (destinationChainInfo.slug === _chainList.COMMON_CHAIN_SLUGS.ASTAR_EVM) {
|
|
26
|
+
const ss58Address = (0, _utilCrypto.evmToAddress)(toAddress, 2006); // TODO: shouldn't pass addressPrefix directly
|
|
27
|
+
|
|
29
28
|
return {
|
|
30
29
|
AccountId32: {
|
|
31
30
|
network: 'Any',
|
|
@@ -49,9 +48,10 @@ function getReceiverLocation(originChainInfo, destinationChainInfo, toAddress) {
|
|
|
49
48
|
};
|
|
50
49
|
}
|
|
51
50
|
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
|
+
[version]: {
|
|
55
55
|
parents: 0,
|
|
56
56
|
interior: {
|
|
57
57
|
X1: receiverLocation
|
|
@@ -59,5 +59,10 @@ function getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress)
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
function getDestWeight() {
|
|
63
|
+
return 'Unlimited';
|
|
64
|
+
// return api.tx.xTokens.transfer.meta.args[3].type.toString() ===
|
|
65
|
+
// 'XcmV2WeightLimit'
|
|
66
|
+
// ? 'Unlimited'
|
|
67
|
+
// : FOUR_INSTRUCTIONS_WEIGHT;
|
|
68
|
+
}
|
|
@@ -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 = ['pioneer'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
|
|
58
58
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo, recipientAddress), weightParam);
|
|
59
59
|
}
|
|
@@ -10,8 +10,9 @@ 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';
|
|
13
14
|
return {
|
|
14
|
-
|
|
15
|
+
[version]: {
|
|
15
16
|
parents: 0,
|
|
16
17
|
interior: {
|
|
17
18
|
X1: {
|
|
@@ -22,9 +23,10 @@ function getDestinationChainLocation(destinationChainInfo) {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
function getTokenLocation(sendingValue) {
|
|
26
|
+
let version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'V2';
|
|
25
27
|
return {
|
|
26
28
|
// always native token of relaychain
|
|
27
|
-
|
|
29
|
+
[version]: [{
|
|
28
30
|
id: {
|
|
29
31
|
Concrete: {
|
|
30
32
|
parents: 0,
|
|
@@ -40,10 +42,11 @@ function getTokenLocation(sendingValue) {
|
|
|
40
42
|
|
|
41
43
|
// this pallet is only used by Relaychains
|
|
42
44
|
function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
43
|
-
const weightParam = _utils.
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
45
|
+
const weightParam = (0, _utils.getDestWeight)();
|
|
46
|
+
const xcmVer = ['kusama'].includes(originChainInfo.slug) ? 'V2' : 'V1';
|
|
47
|
+
const destination = getDestinationChainLocation(destinationChainInfo, xcmVer);
|
|
48
|
+
const beneficiary = (0, _utils.getBeneficiary)(originChainInfo, destinationChainInfo, recipientAddress, xcmVer);
|
|
49
|
+
const tokenLocation = getTokenLocation(value, xcmVer);
|
|
47
50
|
let method = 'limitedReserveTransferAssets';
|
|
48
51
|
if (['statemint', 'statemine'].includes(destinationChainInfo.slug)) {
|
|
49
52
|
method = 'limitedTeleportAssets';
|
|
@@ -5,6 +5,9 @@ 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");
|
|
8
11
|
var _rxjs = require("rxjs");
|
|
9
12
|
var _util = require("@polkadot/util");
|
|
10
13
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -58,21 +61,26 @@ class KoniCron {
|
|
|
58
61
|
delete this.cronMap[key];
|
|
59
62
|
});
|
|
60
63
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
|
|
65
|
+
// init = () => {
|
|
66
|
+
// const currentAccountInfo = this.state.keyringService.currentAccount;
|
|
67
|
+
//
|
|
68
|
+
// if (!currentAccountInfo?.address) {
|
|
69
|
+
// return;
|
|
70
|
+
// }
|
|
71
|
+
//
|
|
72
|
+
// if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
73
|
+
// this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap());
|
|
74
|
+
// this.updateApiMapStatus();
|
|
75
|
+
// this.refreshStakingReward(currentAccountInfo.address);
|
|
76
|
+
// this.refreshStakingRewardFastInterval(currentAccountInfo.address);
|
|
77
|
+
// // this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
|
|
78
|
+
// this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
|
|
79
|
+
// } else {
|
|
80
|
+
// this.setStakingRewardReady();
|
|
81
|
+
// }
|
|
82
|
+
// };
|
|
83
|
+
|
|
76
84
|
start = () => {
|
|
77
85
|
if (this.status === 'running') {
|
|
78
86
|
return;
|
|
@@ -85,6 +93,7 @@ class KoniCron {
|
|
|
85
93
|
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
86
94
|
this.resetNft(currentAccountInfo.address);
|
|
87
95
|
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);
|
|
88
97
|
this.addCron('recoverApiMap', this.recoverApiMap, _constants.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
89
98
|
this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
90
99
|
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
@@ -93,46 +102,74 @@ class KoniCron {
|
|
|
93
102
|
} else {
|
|
94
103
|
this.setStakingRewardReady();
|
|
95
104
|
}
|
|
96
|
-
const
|
|
97
|
-
this.
|
|
105
|
+
const commonReloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'asset.updateState'];
|
|
106
|
+
this.eventHandler = (events, eventTypes) => {
|
|
98
107
|
var _serviceInfo$currentA;
|
|
99
108
|
const serviceInfo = this.state.getServiceInfo();
|
|
100
|
-
const
|
|
101
|
-
|
|
109
|
+
const commonReload = eventTypes.some(eventType => commonReloadEvents.includes(eventType));
|
|
110
|
+
const chainUpdated = eventTypes.includes('chain.updateState');
|
|
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) {
|
|
102
122
|
return;
|
|
103
123
|
}
|
|
104
|
-
this.logger.log('ServiceInfo updated, restarting...');
|
|
124
|
+
this.logger.log('ServiceInfo updated, Cron restarting...', eventTypes);
|
|
105
125
|
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
106
126
|
if (!address) {
|
|
107
127
|
return;
|
|
108
128
|
}
|
|
109
|
-
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
this.removeCron('
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
const chainInfoMap = serviceInfo.chainInfoMap;
|
|
130
|
+
const needUpdateNft = this.needUpdateNft(chainInfoMap, updatedChains);
|
|
131
|
+
const needUpdateStaking = this.needUpdateStaking(chainInfoMap, updatedChains);
|
|
132
|
+
|
|
133
|
+
// NFT
|
|
134
|
+
(commonReload || needUpdateNft) && this.resetNft(address);
|
|
135
|
+
(commonReload || needUpdateNft) && this.removeCron('refreshNft');
|
|
136
|
+
|
|
137
|
+
// Staking
|
|
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');
|
|
118
147
|
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
119
148
|
// only add cron job if there's at least 1 active network
|
|
120
|
-
this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), _constants.CRON_REFRESH_NFT_INTERVAL);
|
|
121
|
-
this.addCron('
|
|
122
|
-
this.addCron('
|
|
123
|
-
this.addCron('
|
|
124
|
-
this.addCron('
|
|
125
|
-
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), _constants.CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
149
|
+
(commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), _constants.CRON_REFRESH_NFT_INTERVAL);
|
|
150
|
+
chainUpdated && this.addCron('checkStatusApiMap', this.updateApiMapStatus, _constants.CRON_GET_API_MAP_STATUS);
|
|
151
|
+
chainUpdated && this.addCron('recoverApiMap', this.recoverApiMap, _constants.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
152
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshStakingReward', this.refreshStakingReward(address), _constants.CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
153
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
154
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), _constants.CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
155
|
+
needUpdateStaking && this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), _constants.CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
126
156
|
} else {
|
|
127
157
|
this.setStakingRewardReady();
|
|
128
158
|
}
|
|
129
|
-
}
|
|
159
|
+
};
|
|
160
|
+
this.state.eventService.onLazy(this.eventHandler);
|
|
130
161
|
this.status = 'running';
|
|
131
162
|
};
|
|
132
163
|
stop = () => {
|
|
133
164
|
if (this.status === 'stopped') {
|
|
134
165
|
return;
|
|
135
166
|
}
|
|
167
|
+
|
|
168
|
+
// Unsubscribe events
|
|
169
|
+
if (this.eventHandler) {
|
|
170
|
+
this.state.eventService.offLazy(this.eventHandler);
|
|
171
|
+
this.eventHandler = undefined;
|
|
172
|
+
}
|
|
136
173
|
if (this.serviceSubscription) {
|
|
137
174
|
this.serviceSubscription.unsubscribe();
|
|
138
175
|
this.serviceSubscription = undefined;
|
|
@@ -141,6 +178,36 @@ class KoniCron {
|
|
|
141
178
|
this.removeAllCrons();
|
|
142
179
|
this.status = 'stopped';
|
|
143
180
|
};
|
|
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
|
+
};
|
|
144
211
|
recoverApiMap = () => {
|
|
145
212
|
var _this$subscriptions;
|
|
146
213
|
const apiMap = this.state.getApiMap();
|
|
@@ -161,28 +228,26 @@ class KoniCron {
|
|
|
161
228
|
};
|
|
162
229
|
refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
|
|
163
230
|
return () => {
|
|
164
|
-
|
|
231
|
+
console.debug('Refresh NFT state');
|
|
165
232
|
this.subscriptions.subscribeNft(address, apiMap.substrate, apiMap.evm, smartContractNfts, chainInfoMap);
|
|
166
233
|
};
|
|
167
234
|
};
|
|
168
235
|
resetNft = newAddress => {
|
|
169
|
-
this.logger.log('Reset Nft state');
|
|
170
236
|
this.state.resetNft(newAddress);
|
|
171
237
|
};
|
|
172
238
|
resetStakingReward = () => {
|
|
173
|
-
this.logger.log('Reset Staking Reward State');
|
|
174
239
|
this.state.resetStakingReward();
|
|
175
240
|
};
|
|
176
241
|
refreshStakingReward = address => {
|
|
177
242
|
return () => {
|
|
178
|
-
|
|
179
|
-
this.subscriptions.subscribeStakingReward(address).
|
|
243
|
+
console.debug('Refresh staking reward state');
|
|
244
|
+
this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
|
|
180
245
|
};
|
|
181
246
|
};
|
|
182
247
|
refreshStakingRewardFastInterval = address => {
|
|
183
248
|
return () => {
|
|
184
|
-
|
|
185
|
-
this.subscriptions.subscribeStakingRewardFastInterval(address).
|
|
249
|
+
console.debug('Refresh staking reward data with fast interval');
|
|
250
|
+
this.subscriptions.subscribeStakingRewardFastInterval(address).catch(this.logger.error);
|
|
186
251
|
};
|
|
187
252
|
};
|
|
188
253
|
setStakingRewardReady = () => {
|
|
@@ -193,15 +258,53 @@ class KoniCron {
|
|
|
193
258
|
};
|
|
194
259
|
updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
195
260
|
return () => {
|
|
196
|
-
|
|
197
|
-
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).
|
|
261
|
+
console.debug('Fetching chain staking metadata');
|
|
262
|
+
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
198
263
|
};
|
|
199
264
|
};
|
|
200
265
|
updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
201
266
|
return () => {
|
|
202
|
-
|
|
203
|
-
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).
|
|
267
|
+
console.debug('Fetching nominator data for', address);
|
|
268
|
+
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
204
269
|
};
|
|
205
270
|
};
|
|
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
|
+
}
|
|
206
309
|
}
|
|
207
310
|
exports.KoniCron = KoniCron;
|