@subwallet/extension-base 1.0.2-2 → 1.0.3-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +56 -40
- package/background/KoniTypes.js +11 -9
- package/background/errors/TransactionError.js +25 -1
- package/background/types.d.ts +10 -5
- package/cjs/background/KoniTypes.js +11 -9
- package/cjs/background/errors/TransactionError.js +24 -0
- package/cjs/constants/index.js +8 -26
- package/cjs/koni/api/dotsama/balance.js +49 -224
- package/cjs/koni/api/dotsama/transfer.js +34 -39
- package/cjs/koni/api/nft/acala_nft/index.js +7 -7
- package/cjs/koni/api/nft/bit.country/index.js +7 -6
- package/cjs/koni/api/nft/evm_nft/index.js +8 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +7 -6
- package/cjs/koni/api/nft/rmrk_nft/index.js +11 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +7 -6
- package/cjs/koni/api/nft/unique_nft/index.js +5 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +170 -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 +122 -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 +171 -61
- package/cjs/koni/background/handlers/Extension.js +391 -207
- package/cjs/koni/background/handlers/State.js +49 -34
- package/cjs/koni/background/handlers/Tabs.js +50 -17
- package/cjs/koni/background/subscription.js +53 -28
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/base/types.js +20 -0
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/index.js +73 -49
- 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 +101 -50
- package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
- package/cjs/services/keyring-service/index.js +11 -13
- package/cjs/services/migration-service/scripts/MigrateImportedToken.js +2 -1
- package/cjs/services/price-service/coingecko.js +0 -1
- package/cjs/services/price-service/index.js +71 -24
- package/cjs/services/request-service/handler/AuthRequestHandler.js +13 -7
- package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
- package/cjs/services/request-service/index.js +14 -5
- package/cjs/services/storage-service/DatabaseService.js +66 -34
- package/cjs/services/storage-service/db-stores/Nft.js +7 -15
- package/cjs/services/storage-service/db-stores/Transaction.js +6 -10
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +104 -48
- package/cjs/services/transaction-service/utils.js +10 -8
- package/cjs/utils/address.js +10 -1
- package/cjs/utils/index.js +9 -15
- package/cjs/utils/promise.js +26 -0
- 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 +11 -16
- package/koni/api/nft/acala_nft/index.js +7 -7
- package/koni/api/nft/bit.country/index.js +7 -6
- package/koni/api/nft/evm_nft/index.js +7 -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 +7 -6
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +11 -1
- package/koni/api/nft/statemine_nft/index.js +7 -6
- 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 +168 -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 +121 -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 +172 -62
- package/koni/background/handlers/Extension.d.ts +9 -3
- package/koni/background/handlers/Extension.js +306 -126
- package/koni/background/handlers/State.d.ts +5 -6
- package/koni/background/handlers/State.js +51 -34
- package/koni/background/handlers/Tabs.js +50 -17
- package/koni/background/subscription.d.ts +2 -0
- package/koni/background/subscription.js +51 -29
- package/package.json +29 -14
- package/packageInfo.js +1 -1
- package/services/base/types.d.ts +34 -0
- package/services/base/types.js +15 -0
- package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
- 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 +5 -2
- package/services/chain-service/index.js +68 -45
- package/services/chain-service/types.d.ts +1 -0
- 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 +28 -7
- package/services/history-service/index.js +101 -50
- package/services/history-service/subsquid-multi-chain-history.js +16 -12
- package/services/keyring-service/index.d.ts +4 -2
- package/services/keyring-service/index.js +11 -13
- package/services/migration-service/scripts/MigrateImportedToken.js +2 -1
- package/services/price-service/coingecko.js +0 -1
- package/services/price-service/index.d.ts +22 -1
- package/services/price-service/index.js +71 -24
- package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
- package/services/request-service/handler/AuthRequestHandler.js +13 -7
- package/services/request-service/handler/EvmRequestHandler.js +8 -12
- package/services/request-service/index.d.ts +3 -1
- package/services/request-service/index.js +14 -5
- package/services/storage-service/DatabaseService.d.ts +2 -0
- package/services/storage-service/DatabaseService.js +66 -34
- package/services/storage-service/db-stores/Nft.d.ts +2 -2
- package/services/storage-service/db-stores/Nft.js +7 -14
- package/services/storage-service/db-stores/Transaction.d.ts +2 -0
- package/services/storage-service/db-stores/Transaction.js +6 -10
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.d.ts +2 -0
- package/services/transaction-service/index.js +86 -32
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +10 -8
- package/utils/address.d.ts +3 -0
- package/utils/address.js +8 -1
- package/utils/index.d.ts +2 -2
- package/utils/index.js +7 -13
- package/utils/promise.d.ts +6 -0
- package/utils/promise.js +20 -0
package/koni/api/xcm/xTokens.js
CHANGED
|
@@ -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,
|
|
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 =
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
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
|
}
|
package/koni/background/cron.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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 { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportSubstrateStaking, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import { waitTimeout } from '@subwallet/extension-base/utils';
|
|
5
7
|
import { Subject } from 'rxjs';
|
|
6
8
|
import { logger as createLogger } from '@polkadot/util';
|
|
7
9
|
export class KoniCron {
|
|
@@ -47,33 +49,95 @@ export class KoniCron {
|
|
|
47
49
|
delete this.cronMap[key];
|
|
48
50
|
});
|
|
49
51
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
|
|
53
|
+
// init = () => {
|
|
54
|
+
// const currentAccountInfo = this.state.keyringService.currentAccount;
|
|
55
|
+
//
|
|
56
|
+
// if (!currentAccountInfo?.address) {
|
|
57
|
+
// return;
|
|
58
|
+
// }
|
|
59
|
+
//
|
|
60
|
+
// if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
61
|
+
// this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap());
|
|
62
|
+
// this.updateApiMapStatus();
|
|
63
|
+
// this.refreshStakingReward(currentAccountInfo.address);
|
|
64
|
+
// this.refreshStakingRewardFastInterval(currentAccountInfo.address);
|
|
65
|
+
// // this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
|
|
66
|
+
// this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
|
|
67
|
+
// } else {
|
|
68
|
+
// this.setStakingRewardReady();
|
|
69
|
+
// }
|
|
70
|
+
// };
|
|
71
|
+
|
|
65
72
|
start = () => {
|
|
66
73
|
if (this.status === 'running') {
|
|
67
74
|
return;
|
|
68
75
|
}
|
|
69
|
-
this.logger.log('Starting cron jobs');
|
|
70
76
|
const currentAccountInfo = this.state.keyringService.currentAccount;
|
|
77
|
+
const commonReloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'asset.updateState'];
|
|
78
|
+
this.eventHandler = (events, eventTypes) => {
|
|
79
|
+
var _serviceInfo$currentA;
|
|
80
|
+
const serviceInfo = this.state.getServiceInfo();
|
|
81
|
+
const commonReload = eventTypes.some(eventType => commonReloadEvents.includes(eventType));
|
|
82
|
+
const chainUpdated = eventTypes.includes('chain.updateState');
|
|
83
|
+
const stakingSubmitted = eventTypes.includes('transaction.submitStaking');
|
|
84
|
+
const updatedChains = [];
|
|
85
|
+
if (chainUpdated) {
|
|
86
|
+
events.forEach(event => {
|
|
87
|
+
if (event.type === 'chain.updateState') {
|
|
88
|
+
const updatedData = event.data;
|
|
89
|
+
updatedChains.push(updatedData[0]);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (!commonReload && !chainUpdated && !stakingSubmitted) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.logger.log('ServiceInfo updated, Cron restarting...', eventTypes);
|
|
97
|
+
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
98
|
+
if (!address) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const chainInfoMap = serviceInfo.chainInfoMap;
|
|
102
|
+
const needUpdateNft = this.needUpdateNft(chainInfoMap, updatedChains);
|
|
103
|
+
const needUpdateStaking = this.needUpdateStaking(chainInfoMap, updatedChains);
|
|
104
|
+
|
|
105
|
+
// NFT
|
|
106
|
+
(commonReload || needUpdateNft) && this.resetNft(address);
|
|
107
|
+
(commonReload || needUpdateNft) && this.removeCron('refreshNft');
|
|
108
|
+
|
|
109
|
+
// Staking
|
|
110
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.resetStakingReward();
|
|
111
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshStakingReward');
|
|
112
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshPoolingStakingReward');
|
|
113
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('updateNominatorMetadata');
|
|
114
|
+
needUpdateStaking && this.removeCron('updateChainStakingMetadata');
|
|
115
|
+
|
|
116
|
+
// Chains
|
|
117
|
+
chainUpdated && this.removeCron('checkStatusApiMap');
|
|
118
|
+
chainUpdated && this.removeCron('recoverApiMap');
|
|
119
|
+
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
120
|
+
// only add cron job if there's at least 1 active network
|
|
121
|
+
(commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
122
|
+
chainUpdated && this.addCron('checkStatusApiMap', this.updateApiMapStatus, CRON_GET_API_MAP_STATUS, false);
|
|
123
|
+
chainUpdated && this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
124
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
125
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
126
|
+
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
127
|
+
needUpdateStaking && this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
128
|
+
} else {
|
|
129
|
+
this.setStakingRewardReady();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
this.state.eventService.onLazy(this.eventHandler);
|
|
71
133
|
if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
|
|
72
134
|
return;
|
|
73
135
|
}
|
|
136
|
+
this.logger.log('Starting cron jobs');
|
|
74
137
|
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
75
138
|
this.resetNft(currentAccountInfo.address);
|
|
76
139
|
this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
140
|
+
this.addCron('checkStatusApiMap', this.updateApiMapStatus, CRON_GET_API_MAP_STATUS);
|
|
77
141
|
this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
|
|
78
142
|
this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
79
143
|
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
@@ -82,46 +146,18 @@ export class KoniCron {
|
|
|
82
146
|
} else {
|
|
83
147
|
this.setStakingRewardReady();
|
|
84
148
|
}
|
|
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) => {
|
|
87
|
-
var _serviceInfo$currentA;
|
|
88
|
-
const serviceInfo = this.state.getServiceInfo();
|
|
89
|
-
const needReload = eventTypes.some(eT => reloadEvents.includes(eT));
|
|
90
|
-
if (!needReload) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
this.logger.log('ServiceInfo updated, restarting...');
|
|
94
|
-
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
95
|
-
if (!address) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
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');
|
|
107
|
-
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
108
|
-
// 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);
|
|
115
|
-
} else {
|
|
116
|
-
this.setStakingRewardReady();
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
149
|
this.status = 'running';
|
|
120
150
|
};
|
|
121
151
|
stop = () => {
|
|
122
152
|
if (this.status === 'stopped') {
|
|
123
153
|
return;
|
|
124
154
|
}
|
|
155
|
+
|
|
156
|
+
// Unsubscribe events
|
|
157
|
+
if (this.eventHandler) {
|
|
158
|
+
this.state.eventService.offLazy(this.eventHandler);
|
|
159
|
+
this.eventHandler = undefined;
|
|
160
|
+
}
|
|
125
161
|
if (this.serviceSubscription) {
|
|
126
162
|
this.serviceSubscription.unsubscribe();
|
|
127
163
|
this.serviceSubscription = undefined;
|
|
@@ -130,6 +166,44 @@ export class KoniCron {
|
|
|
130
166
|
this.removeAllCrons();
|
|
131
167
|
this.status = 'stopped';
|
|
132
168
|
};
|
|
169
|
+
updateApiMapStatus = () => {
|
|
170
|
+
this.state.chainService.updateApiMapStatus().catch(console.error);
|
|
171
|
+
// const apiMap = this.state.getApiMap();
|
|
172
|
+
// const networkMap = this.state.getChainStateMap();
|
|
173
|
+
//
|
|
174
|
+
// for (const [key, substrateApi] of Object.entries(apiMap.substrate)) {
|
|
175
|
+
// let status: _ChainConnectionStatus = _ChainConnectionStatus.CONNECTING;
|
|
176
|
+
//
|
|
177
|
+
// if (substrateApi.isApiConnected) {
|
|
178
|
+
// status = _ChainConnectionStatus.CONNECTED;
|
|
179
|
+
// }
|
|
180
|
+
//
|
|
181
|
+
// if (!networkMap[key].connectionStatus) {
|
|
182
|
+
// this.state.updateChainConnectionStatus(key, status);
|
|
183
|
+
// } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== status) {
|
|
184
|
+
// this.state.updateChainConnectionStatus(key, status);
|
|
185
|
+
// }
|
|
186
|
+
// }
|
|
187
|
+
//
|
|
188
|
+
// for (const [key, evmApi] of Object.entries(apiMap.evm)) {
|
|
189
|
+
// evmApi.api.eth.net.isListening()
|
|
190
|
+
// .then(() => {
|
|
191
|
+
// if (!networkMap[key].connectionStatus) {
|
|
192
|
+
// this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTED);
|
|
193
|
+
// } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _ChainConnectionStatus.CONNECTED) {
|
|
194
|
+
// this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTED);
|
|
195
|
+
// }
|
|
196
|
+
// })
|
|
197
|
+
// .catch(() => {
|
|
198
|
+
// if (!networkMap[key].connectionStatus) {
|
|
199
|
+
// this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTING);
|
|
200
|
+
// } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _ChainConnectionStatus.CONNECTING) {
|
|
201
|
+
// this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTING);
|
|
202
|
+
// }
|
|
203
|
+
// });
|
|
204
|
+
// }
|
|
205
|
+
};
|
|
206
|
+
|
|
133
207
|
recoverApiMap = () => {
|
|
134
208
|
var _this$subscriptions;
|
|
135
209
|
const apiMap = this.state.getApiMap();
|
|
@@ -150,28 +224,26 @@ export class KoniCron {
|
|
|
150
224
|
};
|
|
151
225
|
refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
|
|
152
226
|
return () => {
|
|
153
|
-
|
|
227
|
+
console.debug('Refresh NFT state');
|
|
154
228
|
this.subscriptions.subscribeNft(address, apiMap.substrate, apiMap.evm, smartContractNfts, chainInfoMap);
|
|
155
229
|
};
|
|
156
230
|
};
|
|
157
231
|
resetNft = newAddress => {
|
|
158
|
-
this.logger.log('Reset Nft state');
|
|
159
232
|
this.state.resetNft(newAddress);
|
|
160
233
|
};
|
|
161
234
|
resetStakingReward = () => {
|
|
162
|
-
this.logger.log('Reset Staking Reward State');
|
|
163
235
|
this.state.resetStakingReward();
|
|
164
236
|
};
|
|
165
237
|
refreshStakingReward = address => {
|
|
166
238
|
return () => {
|
|
167
|
-
|
|
168
|
-
this.subscriptions.subscribeStakingReward(address).
|
|
239
|
+
console.debug('Refresh staking reward state');
|
|
240
|
+
this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
|
|
169
241
|
};
|
|
170
242
|
};
|
|
171
243
|
refreshStakingRewardFastInterval = address => {
|
|
172
244
|
return () => {
|
|
173
|
-
|
|
174
|
-
this.subscriptions.subscribeStakingRewardFastInterval(address).
|
|
245
|
+
console.debug('Refresh staking reward data with fast interval');
|
|
246
|
+
this.subscriptions.subscribeStakingRewardFastInterval(address).catch(this.logger.error);
|
|
175
247
|
};
|
|
176
248
|
};
|
|
177
249
|
setStakingRewardReady = () => {
|
|
@@ -182,14 +254,52 @@ export class KoniCron {
|
|
|
182
254
|
};
|
|
183
255
|
updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
184
256
|
return () => {
|
|
185
|
-
|
|
186
|
-
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).
|
|
257
|
+
console.debug('Fetching chain staking metadata');
|
|
258
|
+
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
187
259
|
};
|
|
188
260
|
};
|
|
189
261
|
updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
190
262
|
return () => {
|
|
191
|
-
|
|
192
|
-
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).
|
|
263
|
+
console.debug('Fetching nominator data for', address);
|
|
264
|
+
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
193
265
|
};
|
|
194
266
|
};
|
|
267
|
+
async reloadNft() {
|
|
268
|
+
const address = this.state.keyringService.currentAccount.address;
|
|
269
|
+
const serviceInfo = this.state.getServiceInfo();
|
|
270
|
+
console.debug('Hard refresh NFT for', address);
|
|
271
|
+
this.resetNft(address);
|
|
272
|
+
this.removeCron('refreshNft');
|
|
273
|
+
this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
274
|
+
await waitTimeout(1800);
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
async reloadStaking() {
|
|
278
|
+
const address = this.state.keyringService.currentAccount.address;
|
|
279
|
+
console.debug('Hard refresh staking meta for', address);
|
|
280
|
+
this.resetStakingReward();
|
|
281
|
+
this.removeCron('refreshStakingReward');
|
|
282
|
+
this.removeCron('refreshPoolingStakingReward');
|
|
283
|
+
this.removeCron('updateNominatorMetadata');
|
|
284
|
+
this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
285
|
+
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
286
|
+
this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
|
|
287
|
+
await waitTimeout(1800);
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
needUpdateNft(chainInfoMap, updatedChains) {
|
|
291
|
+
if (updatedChains && updatedChains.length > 0) {
|
|
292
|
+
return updatedChains.some(updatedChain => {
|
|
293
|
+
const chainInfo = chainInfoMap[updatedChain];
|
|
294
|
+
return _isChainSupportNativeNft(chainInfo) || _isChainSupportEvmNft(chainInfo) || _isChainSupportWasmNft(chainInfo);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
needUpdateStaking(chainInfoMap, updatedChains) {
|
|
300
|
+
if (updatedChains && updatedChains.length > 0) {
|
|
301
|
+
return updatedChains.some(updatedChain => _isChainSupportSubstrateStaking(chainInfoMap[updatedChain]));
|
|
302
|
+
}
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
195
305
|
}
|
|
@@ -39,8 +39,10 @@ export default class KoniExtension {
|
|
|
39
39
|
private checkPublicAndSecretKey;
|
|
40
40
|
private accountsGetAllWithCurrentAddress;
|
|
41
41
|
private accountsGetAll;
|
|
42
|
-
private
|
|
43
|
-
private
|
|
42
|
+
private subscribeAddresses;
|
|
43
|
+
private saveRecentAccount;
|
|
44
|
+
private editContactAccount;
|
|
45
|
+
private deleteContactAccount;
|
|
44
46
|
private _getAuthListV2;
|
|
45
47
|
private authorizeSubscribeV2;
|
|
46
48
|
private getAuthListV2;
|
|
@@ -108,6 +110,7 @@ export default class KoniExtension {
|
|
|
108
110
|
private getStaking;
|
|
109
111
|
private subscribeStaking;
|
|
110
112
|
private subscribeHistory;
|
|
113
|
+
private addContact;
|
|
111
114
|
private validateTransfer;
|
|
112
115
|
private makeTransfer;
|
|
113
116
|
private validateCrossChainTransfer;
|
|
@@ -124,6 +127,7 @@ export default class KoniExtension {
|
|
|
124
127
|
private deleteCustomAsset;
|
|
125
128
|
private validateCustomAsset;
|
|
126
129
|
private getAddressFreeBalance;
|
|
130
|
+
private transferGetMaxTransferable;
|
|
127
131
|
private subscribeAddressFreeBalance;
|
|
128
132
|
private transferCheckReferenceCount;
|
|
129
133
|
private transferCheckSupporting;
|
|
@@ -154,7 +158,7 @@ export default class KoniExtension {
|
|
|
154
158
|
private submitStakeWithdrawal;
|
|
155
159
|
private submitStakeClaimReward;
|
|
156
160
|
private submitCancelStakeWithdrawal;
|
|
157
|
-
private
|
|
161
|
+
private submitPoolBonding;
|
|
158
162
|
private submitPoolingUnbonding;
|
|
159
163
|
private parseContractInput;
|
|
160
164
|
private submitTuringStakeCompounding;
|
|
@@ -179,5 +183,7 @@ export default class KoniExtension {
|
|
|
179
183
|
private getTransaction;
|
|
180
184
|
private subscribeTransactions;
|
|
181
185
|
private subscribeNotifications;
|
|
186
|
+
private reloadCron;
|
|
187
|
+
private getLogoMap;
|
|
182
188
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
|
|
183
189
|
}
|