@subwallet/extension-base 1.0.13-0 → 1.1.1-dev.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 +37 -0
- package/background/KoniTypes.js +8 -1
- package/background/handlers/Extension.js +17 -2
- package/background/types.d.ts +6 -1
- package/bundle-polkadot-extension-base.js +20 -0
- package/cjs/background/KoniTypes.js +10 -2
- package/cjs/background/handlers/Extension.js +22 -6
- package/cjs/constants/index.js +7 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/balance.js +5 -0
- package/cjs/koni/api/dotsama/transfer.js +6 -0
- package/cjs/koni/api/staking/bonding/astar.js +2 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +12 -2
- package/cjs/koni/api/staking/bonding/utils.js +2 -2
- package/cjs/koni/background/cron.js +13 -37
- package/cjs/koni/background/handlers/Extension.js +324 -147
- package/cjs/koni/background/handlers/State.js +224 -51
- package/cjs/koni/background/subscription.js +9 -86
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +10 -4
- package/cjs/services/chain-service/handler/SubstrateApi.js +2 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -1
- package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +147 -0
- package/cjs/services/chain-service/helper/erc20_abi.json +224 -0
- package/cjs/services/chain-service/helper/erc721_abi.json +384 -0
- package/cjs/services/chain-service/helper/psp22_abi.json +1127 -0
- package/cjs/services/chain-service/helper/psp34_abi.json +3144 -0
- package/cjs/services/chain-service/helper/test_erc721_abi.json +393 -0
- package/cjs/services/chain-service/index.js +54 -5
- package/cjs/services/chain-service/utils.js +6 -1
- package/cjs/services/event-service/types.js +3 -1
- package/cjs/services/storage-service/DatabaseService.js +31 -1
- package/cjs/services/storage-service/databases/index.js +3 -0
- package/cjs/services/storage-service/db-stores/MantaPay.js +40 -0
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/lazy.js +52 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +2 -0
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/balance.js +6 -1
- package/koni/api/dotsama/transfer.js +7 -1
- package/koni/api/staking/bonding/astar.d.ts +1 -1
- package/koni/api/staking/bonding/astar.js +1 -1
- package/koni/api/staking/bonding/relayChain.js +12 -2
- package/koni/api/staking/bonding/utils.js +3 -3
- package/koni/background/cron.d.ts +1 -5
- package/koni/background/cron.js +15 -39
- package/koni/background/handlers/Extension.d.ts +5 -0
- package/koni/background/handlers/Extension.js +186 -11
- package/koni/background/handlers/State.d.ts +15 -3
- package/koni/background/handlers/State.js +226 -50
- package/koni/background/subscription.d.ts +1 -4
- package/koni/background/subscription.js +11 -87
- package/package.json +23 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +3 -0
- package/services/chain-service/constants.js +5 -2
- package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
- package/services/chain-service/handler/SubstrateApi.js +2 -1
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +3 -1
- package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +30 -0
- package/services/chain-service/handler/manta/MantaPrivateHandler.js +140 -0
- package/services/chain-service/handler/types.d.ts +2 -0
- package/services/chain-service/index.d.ts +7 -3
- package/services/chain-service/index.js +56 -7
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/event-service/types.d.ts +3 -0
- package/services/event-service/types.js +3 -1
- package/services/storage-service/DatabaseService.d.ts +10 -1
- package/services/storage-service/DatabaseService.js +31 -1
- package/services/storage-service/databases/index.d.ts +2 -0
- package/services/storage-service/databases/index.js +3 -0
- package/services/storage-service/db-stores/MantaPay.d.ts +9 -0
- package/services/storage-service/db-stores/MantaPay.js +32 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +2 -1
- package/utils/lazy.d.ts +2 -0
- package/utils/lazy.js +43 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addLazy = addLazy;
|
|
7
|
+
exports.removeLazy = removeLazy;
|
|
8
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
9
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
11
|
+
const lazyMap = {};
|
|
12
|
+
function removeLazy(key) {
|
|
13
|
+
if (lazyMap[key]) {
|
|
14
|
+
clearTimeout(lazyMap[key].timeout);
|
|
15
|
+
delete lazyMap[key];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Add or update new lazy thread
|
|
20
|
+
function addLazy(key, callback) {
|
|
21
|
+
let lazyTime = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 300;
|
|
22
|
+
let maxLazyTime = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3000;
|
|
23
|
+
const existed = lazyMap[key];
|
|
24
|
+
const now = new Date().getTime();
|
|
25
|
+
if (existed) {
|
|
26
|
+
clearTimeout(existed.timeout);
|
|
27
|
+
lazyMap[key] = {
|
|
28
|
+
...existed,
|
|
29
|
+
callback
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Fire callback if last fire is too long
|
|
33
|
+
if (now - existed.lastFire >= maxLazyTime) {
|
|
34
|
+
callback();
|
|
35
|
+
lazyMap[key].lastFire = now;
|
|
36
|
+
} else {
|
|
37
|
+
lazyMap[key].timeout = setTimeout(() => {
|
|
38
|
+
// This will be fire in the last call of lazy thread
|
|
39
|
+
callback();
|
|
40
|
+
lazyMap[key].lastFire = new Date().getTime();
|
|
41
|
+
removeLazy(key);
|
|
42
|
+
}, lazyTime);
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
// Fire callback immediately in the first time
|
|
46
|
+
callback();
|
|
47
|
+
lazyMap[key] = {
|
|
48
|
+
callback,
|
|
49
|
+
lastFire: now
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
package/constants/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare const CRON_GET_API_MAP_STATUS = 10000;
|
|
|
12
12
|
export declare const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
|
|
13
13
|
export declare const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
|
|
14
14
|
export declare const CRON_RECOVER_HISTORY_INTERVAL = 30000;
|
|
15
|
+
export declare const CRON_SYNC_MANTA_PAY = 300000;
|
|
16
|
+
export declare const MANTA_PAY_BALANCE_INTERVAL = 30000;
|
|
15
17
|
export declare const ALL_ACCOUNT_KEY = "ALL";
|
|
16
18
|
export declare const ALL_NETWORK_KEY = "all";
|
|
17
19
|
export declare const ALL_GENESIS_HASH: null;
|
package/constants/index.js
CHANGED
|
@@ -15,6 +15,8 @@ export const CRON_GET_API_MAP_STATUS = 10000;
|
|
|
15
15
|
export const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
|
|
16
16
|
export const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
|
|
17
17
|
export const CRON_RECOVER_HISTORY_INTERVAL = 30000;
|
|
18
|
+
export const CRON_SYNC_MANTA_PAY = 300000;
|
|
19
|
+
export const MANTA_PAY_BALANCE_INTERVAL = 30000;
|
|
18
20
|
export const ALL_ACCOUNT_KEY = 'ALL';
|
|
19
21
|
export const ALL_NETWORK_KEY = 'all';
|
|
20
22
|
export const ALL_GENESIS_HASH = null;
|
package/defaults.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const ALLOWED_PATH: readonly ["/", "/settings/security", "/accounts/connect-ledger", "/accounts/restore-json", "/accounts/new-seed-phrase"];
|
|
1
|
+
declare const ALLOWED_PATH: readonly ["/", "/settings/security", "/accounts/connect-ledger", "/accounts/restore-json", "/accounts/detail", "/accounts/new-seed-phrase"];
|
|
2
2
|
declare const PHISHING_PAGE_REDIRECT = "/phishing-page-detected";
|
|
3
3
|
declare const EXTENSION_PREFIX: string;
|
|
4
4
|
declare const PORT_MOBILE: string;
|
package/defaults.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @polkadot/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
const ALLOWED_PATH = ['/', '/settings/security', '/accounts/connect-ledger', '/accounts/restore-json', '/accounts/new-seed-phrase'];
|
|
4
|
+
const ALLOWED_PATH = ['/', '/settings/security', '/accounts/connect-ledger', '/accounts/restore-json', '/accounts/detail', '/accounts/new-seed-phrase'];
|
|
5
5
|
const PHISHING_PAGE_REDIRECT = '/phishing-page-detected';
|
|
6
6
|
const EXTENSION_PREFIX = process.env.EXTENSION_PREFIX || '';
|
|
7
7
|
const PORT_MOBILE = `${EXTENSION_PREFIX}mobile`;
|
|
@@ -9,7 +9,7 @@ import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/
|
|
|
9
9
|
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
|
|
10
10
|
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
11
11
|
import { state } from '@subwallet/extension-base/koni/background/handlers';
|
|
12
|
-
import { _BALANCE_CHAIN_GROUP, _PURE_EVM_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
12
|
+
import { _BALANCE_CHAIN_GROUP, _MANTA_ZK_CHAIN_GROUP, _PURE_EVM_CHAINS, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
13
13
|
import { _checkSmartContractSupportByChain, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible, _isPureEvmChain, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
14
|
import { categoryAddresses, sumBN } from '@subwallet/extension-base/utils';
|
|
15
15
|
import BigN from 'bignumber.js';
|
|
@@ -324,6 +324,11 @@ async function subscribeTokensAccountsPallet(addresses, chain, api, callBack, in
|
|
|
324
324
|
}
|
|
325
325
|
async function subscribeAssetsAccountPallet(addresses, chain, api, callBack) {
|
|
326
326
|
const tokenMap = state.getAssetByChainAndAsset(chain, [_AssetType.LOCAL]);
|
|
327
|
+
Object.values(tokenMap).forEach(token => {
|
|
328
|
+
if (_MANTA_ZK_CHAIN_GROUP.includes(token.originChain) && token.symbol.startsWith(_ZK_ASSET_PREFIX)) {
|
|
329
|
+
delete tokenMap[token.slug];
|
|
330
|
+
}
|
|
331
|
+
});
|
|
327
332
|
const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
|
|
328
333
|
try {
|
|
329
334
|
const assetIndex = _getTokenOnChainAssetId(tokenInfo);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
|
|
5
5
|
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
6
|
-
import { _BALANCE_TOKEN_GROUP, _TRANSFER_CHAIN_GROUP, _TRANSFER_NOT_SUPPORTED_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
|
+
import { _BALANCE_TOKEN_GROUP, _MANTA_ZK_CHAIN_GROUP, _TRANSFER_CHAIN_GROUP, _TRANSFER_NOT_SUPPORTED_CHAINS, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible, _isNativeToken, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
8
|
import { BN } from '@polkadot/util';
|
|
9
9
|
function isRefCount(accountInfo) {
|
|
@@ -34,6 +34,12 @@ export async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMa
|
|
|
34
34
|
supportTransferAll: true
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
if (tokenInfo.symbol.startsWith(_ZK_ASSET_PREFIX) && _MANTA_ZK_CHAIN_GROUP.includes(tokenInfo.originChain)) {
|
|
38
|
+
return {
|
|
39
|
+
supportTransfer: false,
|
|
40
|
+
supportTransferAll: false
|
|
41
|
+
};
|
|
42
|
+
}
|
|
37
43
|
if (_TRANSFER_NOT_SUPPORTED_CHAINS.includes(networkKey)) {
|
|
38
44
|
return {
|
|
39
45
|
supportTransfer: false,
|
|
@@ -12,4 +12,4 @@ export declare function getAstarBondingExtrinsic(substrateApi: _SubstrateApi, am
|
|
|
12
12
|
export declare function getAstarUnbondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappAddress: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
13
13
|
export declare function getAstarWithdrawalExtrinsic(substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
14
14
|
export declare function getAstarClaimRewardExtrinsic(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function getCompoundWithdrawable(nominatorMetadata: NominatorMetadata): UnstakingInfo;
|
|
@@ -351,7 +351,7 @@ export async function getAstarClaimRewardExtrinsic(substrateApi, address) {
|
|
|
351
351
|
}
|
|
352
352
|
return apiPromise.api.tx.utility.batch(transactions);
|
|
353
353
|
}
|
|
354
|
-
export function
|
|
354
|
+
export function getCompoundWithdrawable(nominatorMetadata) {
|
|
355
355
|
const unstakingInfo = {
|
|
356
356
|
chain: nominatorMetadata.chain,
|
|
357
357
|
status: UnstakingStatus.CLAIMABLE,
|
|
@@ -588,17 +588,27 @@ export async function getRelayBondingExtrinsic(substrateApi, amount, targetValid
|
|
|
588
588
|
const binaryAmount = new BN(amount);
|
|
589
589
|
let bondTx;
|
|
590
590
|
let nominateTx;
|
|
591
|
+
const _params = chainApi.api.tx.staking.bond.toJSON();
|
|
592
|
+
const paramsCount = _params.args.length;
|
|
591
593
|
const validatorParamList = targetValidators.map(validator => {
|
|
592
594
|
return validator.address;
|
|
593
595
|
});
|
|
594
596
|
if (!nominatorMetadata) {
|
|
595
|
-
|
|
597
|
+
if (paramsCount === 2) {
|
|
598
|
+
bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
|
|
599
|
+
} else {
|
|
600
|
+
bondTx = chainApi.api.tx.staking.bond(address, binaryAmount, bondDest);
|
|
601
|
+
}
|
|
596
602
|
nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
|
|
597
603
|
return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
|
|
598
604
|
}
|
|
599
605
|
if (!nominatorMetadata.isBondedBefore) {
|
|
600
606
|
// first time
|
|
601
|
-
|
|
607
|
+
if (paramsCount === 2) {
|
|
608
|
+
bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
|
|
609
|
+
} else {
|
|
610
|
+
bondTx = chainApi.api.tx.staking.bond(nominatorMetadata.address, binaryAmount, bondDest);
|
|
611
|
+
}
|
|
602
612
|
nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
|
|
603
613
|
return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
|
|
604
614
|
} else {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
-
import {
|
|
5
|
+
import { getCompoundWithdrawable } from '@subwallet/extension-base/koni/api/staking/bonding/astar';
|
|
6
6
|
import { _KNOWN_CHAIN_INFLATION_PARAMS, _STAKING_CHAIN_GROUP, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
8
8
|
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
@@ -218,8 +218,8 @@ export function isActionFromValidator(stakingType, chain) {
|
|
|
218
218
|
export function getWithdrawalInfo(nominatorMetadata) {
|
|
219
219
|
const unstakings = nominatorMetadata.unstakings;
|
|
220
220
|
let result;
|
|
221
|
-
if (_STAKING_CHAIN_GROUP.astar.includes(nominatorMetadata.chain)) {
|
|
222
|
-
return
|
|
221
|
+
if (_STAKING_CHAIN_GROUP.astar.includes(nominatorMetadata.chain) || _STAKING_CHAIN_GROUP.relay.includes(nominatorMetadata.chain)) {
|
|
222
|
+
return getCompoundWithdrawable(nominatorMetadata);
|
|
223
223
|
}
|
|
224
224
|
for (const unstaking of unstakings) {
|
|
225
225
|
if (unstaking.status === UnstakingStatus.CLAIMABLE) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { ApiMap, ServiceInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { KoniSubscription } from '@subwallet/extension-base/koni/background/subscription';
|
|
4
|
-
import { _ChainState, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
4
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
6
5
|
import { Subject } from 'rxjs';
|
|
7
6
|
import KoniState from './handlers/State';
|
|
@@ -24,17 +23,14 @@ export declare class KoniCron {
|
|
|
24
23
|
removeAllCrons: () => void;
|
|
25
24
|
start: () => Promise<void>;
|
|
26
25
|
stop: () => Promise<void>;
|
|
26
|
+
syncMantaPay: () => void;
|
|
27
27
|
refreshNft: (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => () => void;
|
|
28
28
|
resetNft: (newAddress: string) => void;
|
|
29
|
-
resetStakingReward: () => void;
|
|
30
29
|
refreshStakingReward: (address: string) => () => void;
|
|
31
30
|
refreshStakingRewardFastInterval: (address: string) => () => void;
|
|
32
31
|
setStakingRewardReady: () => void;
|
|
33
32
|
checkNetworkAvailable: (serviceInfo: ServiceInfo) => boolean;
|
|
34
|
-
updateChainStakingMetadata: (chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
|
|
35
|
-
updateNominatorMetadata: (address: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
|
|
36
33
|
reloadNft(): Promise<boolean>;
|
|
37
34
|
reloadStaking(): Promise<boolean>;
|
|
38
35
|
private needUpdateNft;
|
|
39
|
-
private needUpdateStaking;
|
|
40
36
|
}
|
package/koni/background/cron.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { _isChainSupportEvmNft, _isChainSupportNativeNft,
|
|
4
|
+
import { CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { waitTimeout } from '@subwallet/extension-base/utils';
|
|
7
7
|
import { Subject } from 'rxjs';
|
|
8
8
|
import { logger as createLogger } from '@polkadot/util';
|
|
@@ -61,7 +61,7 @@ export class KoniCron {
|
|
|
61
61
|
const serviceInfo = this.state.getServiceInfo();
|
|
62
62
|
const commonReload = eventTypes.some(eventType => commonReloadEvents.includes(eventType));
|
|
63
63
|
const chainUpdated = eventTypes.includes('chain.updateState');
|
|
64
|
-
const
|
|
64
|
+
const reloadMantaPay = eventTypes.includes('mantaPay.submitTransaction') || eventTypes.includes('mantaPay.enable');
|
|
65
65
|
const updatedChains = [];
|
|
66
66
|
if (chainUpdated) {
|
|
67
67
|
events.forEach(event => {
|
|
@@ -71,7 +71,7 @@ export class KoniCron {
|
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
-
if (!commonReload && !chainUpdated && !
|
|
74
|
+
if (!commonReload && !chainUpdated && !reloadMantaPay) {
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
@@ -80,25 +80,19 @@ export class KoniCron {
|
|
|
80
80
|
}
|
|
81
81
|
const chainInfoMap = serviceInfo.chainInfoMap;
|
|
82
82
|
const needUpdateNft = this.needUpdateNft(chainInfoMap, updatedChains);
|
|
83
|
-
|
|
83
|
+
|
|
84
|
+
// MantaPay
|
|
85
|
+
reloadMantaPay && this.removeCron('syncMantaPay');
|
|
84
86
|
|
|
85
87
|
// NFT
|
|
86
88
|
(commonReload || needUpdateNft) && this.resetNft(address);
|
|
87
89
|
(commonReload || needUpdateNft) && this.removeCron('refreshNft');
|
|
88
90
|
|
|
89
|
-
// Staking
|
|
90
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.resetStakingReward();
|
|
91
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshStakingReward');
|
|
92
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshPoolingStakingReward');
|
|
93
|
-
needUpdateStaking && this.removeCron('updateChainStakingMetadata');
|
|
94
|
-
|
|
95
91
|
// Chains
|
|
96
92
|
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
97
93
|
// only add cron job if there's at least 1 active network
|
|
98
94
|
(commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
99
|
-
|
|
100
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
101
|
-
needUpdateStaking && this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
95
|
+
reloadMantaPay && this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
102
96
|
} else {
|
|
103
97
|
this.setStakingRewardReady();
|
|
104
98
|
}
|
|
@@ -112,7 +106,7 @@ export class KoniCron {
|
|
|
112
106
|
this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
113
107
|
this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
114
108
|
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
115
|
-
this.addCron('
|
|
109
|
+
this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
116
110
|
} else {
|
|
117
111
|
this.setStakingRewardReady();
|
|
118
112
|
}
|
|
@@ -136,6 +130,11 @@ export class KoniCron {
|
|
|
136
130
|
this.status = 'stopped';
|
|
137
131
|
return Promise.resolve();
|
|
138
132
|
};
|
|
133
|
+
syncMantaPay = () => {
|
|
134
|
+
if (this.state.isMantaPayEnabled) {
|
|
135
|
+
this.state.syncMantaPay().catch(console.warn);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
139
138
|
refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
|
|
140
139
|
return () => {
|
|
141
140
|
this.subscriptions.subscribeNft(address, apiMap.substrate, apiMap.evm, smartContractNfts, chainInfoMap);
|
|
@@ -144,9 +143,6 @@ export class KoniCron {
|
|
|
144
143
|
resetNft = newAddress => {
|
|
145
144
|
this.state.resetNft(newAddress);
|
|
146
145
|
};
|
|
147
|
-
resetStakingReward = () => {
|
|
148
|
-
this.state.resetStakingReward();
|
|
149
|
-
};
|
|
150
146
|
refreshStakingReward = address => {
|
|
151
147
|
return () => {
|
|
152
148
|
this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
|
|
@@ -163,16 +159,6 @@ export class KoniCron {
|
|
|
163
159
|
checkNetworkAvailable = serviceInfo => {
|
|
164
160
|
return Object.keys(serviceInfo.chainApiMap.substrate).length > 0 || Object.keys(serviceInfo.chainApiMap.evm).length > 0;
|
|
165
161
|
};
|
|
166
|
-
updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
167
|
-
return () => {
|
|
168
|
-
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
172
|
-
return () => {
|
|
173
|
-
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
162
|
async reloadNft() {
|
|
177
163
|
const address = this.state.keyringService.currentAccount.address;
|
|
178
164
|
const serviceInfo = this.state.getServiceInfo();
|
|
@@ -184,11 +170,7 @@ export class KoniCron {
|
|
|
184
170
|
}
|
|
185
171
|
async reloadStaking() {
|
|
186
172
|
const address = this.state.keyringService.currentAccount.address;
|
|
187
|
-
|
|
188
|
-
this.removeCron('refreshStakingReward');
|
|
189
|
-
this.removeCron('refreshPoolingStakingReward');
|
|
190
|
-
this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
191
|
-
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
173
|
+
console.log('reload staking', address);
|
|
192
174
|
await waitTimeout(1800);
|
|
193
175
|
return true;
|
|
194
176
|
}
|
|
@@ -201,10 +183,4 @@ export class KoniCron {
|
|
|
201
183
|
}
|
|
202
184
|
return false;
|
|
203
185
|
}
|
|
204
|
-
needUpdateStaking(chainInfoMap, updatedChains) {
|
|
205
|
-
if (updatedChains && updatedChains.length > 0) {
|
|
206
|
-
return updatedChains.some(updatedChain => _isChainSupportSubstrateStaking(chainInfoMap[updatedChain]));
|
|
207
|
-
}
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
186
|
}
|
|
@@ -194,5 +194,10 @@ export default class KoniExtension {
|
|
|
194
194
|
private rejectWalletConnectSession;
|
|
195
195
|
private subscribeWalletConnectSessions;
|
|
196
196
|
private disconnectWalletConnectSession;
|
|
197
|
+
private enableMantaPay;
|
|
198
|
+
private initSyncMantaPay;
|
|
199
|
+
private disableMantaPay;
|
|
200
|
+
private subscribeMantaPayConfig;
|
|
201
|
+
private subscribeMantaPaySyncState;
|
|
197
202
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
|
|
198
203
|
}
|