@subwallet/extension-base 1.3.78-0 → 1.3.80-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 +16 -6
- package/cjs/core/logic-validation/index.js +0 -12
- package/cjs/core/substrate/system-pallet.js +3 -0
- package/cjs/koni/api/nft/index.js +0 -14
- package/cjs/koni/background/cron.js +0 -17
- package/cjs/koni/background/handlers/Extension.js +13 -7
- package/cjs/koni/background/handlers/State.js +24 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +49 -21
- package/cjs/services/balance-service/index.js +2 -2
- package/cjs/services/balance-service/transfer/xcm/utils.js +9 -9
- package/cjs/services/chain-service/constants.js +6 -2
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +13 -13
- package/cjs/services/earning-service/handlers/native-staking/tao.js +16 -10
- package/cjs/services/earning-service/handlers/special.js +12 -4
- package/cjs/services/nft-service/index.js +219 -150
- package/cjs/services/nft-service/multi-chain-nft-fetcher.js +145 -0
- package/cjs/services/nft-service/nft-handlers/base-nft-handler.js +28 -0
- package/cjs/services/nft-service/nft-handlers/evm/evm-nft-handler.js +179 -0
- package/cjs/services/nft-service/nft-handlers/registry.js +37 -0
- package/cjs/services/nft-service/nft-handlers/unique/unique-nft-handler.js +187 -0
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/swap-service/handler/asset-hub/handler.js +7 -4
- package/cjs/services/swap-service/handler/asset-hub/router.js +2 -66
- package/cjs/services/swap-service/handler/base-handler.js +4 -3
- package/cjs/services/swap-service/handler/hydradx-handler.js +9 -5
- package/cjs/services/swap-service/index.js +5 -4
- package/cjs/types/swap/index.js +4 -9
- package/cjs/utils/account/common.js +44 -8
- package/core/logic-validation/index.d.ts +0 -1
- package/core/logic-validation/index.js +0 -1
- package/core/substrate/system-pallet.js +3 -0
- package/koni/api/nft/index.js +1 -15
- package/koni/background/cron.d.ts +0 -1
- package/koni/background/cron.js +1 -18
- package/koni/background/handlers/Extension.d.ts +4 -0
- package/koni/background/handlers/Extension.js +13 -7
- package/koni/background/handlers/State.d.ts +8 -2
- package/koni/background/handlers/State.js +24 -6
- package/package.json +31 -11
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +1 -1
- package/services/balance-service/helpers/process.js +48 -21
- package/services/balance-service/index.js +2 -2
- package/services/balance-service/transfer/xcm/utils.js +9 -9
- package/services/chain-service/constants.d.ts +3 -0
- package/services/chain-service/constants.js +3 -0
- package/services/earning-service/handlers/native-staking/dtao.js +12 -13
- package/services/earning-service/handlers/native-staking/tao.d.ts +2 -1
- package/services/earning-service/handlers/native-staking/tao.js +15 -10
- package/services/earning-service/handlers/special.js +13 -5
- package/services/nft-service/index.d.ts +42 -6
- package/services/nft-service/index.js +219 -151
- package/services/nft-service/multi-chain-nft-fetcher.d.ts +13 -0
- package/services/nft-service/multi-chain-nft-fetcher.js +138 -0
- package/services/nft-service/nft-handlers/base-nft-handler.d.ts +13 -0
- package/services/nft-service/nft-handlers/base-nft-handler.js +21 -0
- package/services/nft-service/nft-handlers/evm/evm-nft-handler.d.ts +9 -0
- package/services/nft-service/nft-handlers/evm/evm-nft-handler.js +171 -0
- package/services/nft-service/nft-handlers/registry.d.ts +11 -0
- package/services/nft-service/nft-handlers/registry.js +29 -0
- package/services/nft-service/nft-handlers/unique/unique-nft-handler.d.ts +12 -0
- package/services/nft-service/nft-handlers/unique/unique-nft-handler.js +177 -0
- package/services/storage-service/DatabaseService.d.ts +1 -1
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/swap-service/handler/asset-hub/handler.js +7 -4
- package/services/swap-service/handler/asset-hub/router.d.ts +0 -4
- package/services/swap-service/handler/asset-hub/router.js +1 -64
- package/services/swap-service/handler/base-handler.js +4 -3
- package/services/swap-service/handler/hydradx-handler.js +9 -5
- package/services/swap-service/index.js +5 -4
- package/types/swap/index.d.ts +7 -35
- package/types/swap/index.js +3 -8
- package/types/yield/actions/join/step.d.ts +1 -0
- package/types/yield/actions/join/submit.d.ts +2 -1
- package/utils/account/common.d.ts +22 -1
- package/utils/account/common.js +44 -8
- package/cjs/core/logic-validation/swap.js +0 -235
- package/core/logic-validation/swap.d.ts +0 -26
- package/core/logic-validation/swap.js +0 -219
package/cjs/types/swap/index.js
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports._SUPPORTED_SWAP_PROVIDERS = exports.SwapStepType = exports.SwapProviderId = exports.SwapFeeType = exports.SwapErrorType = exports.SIMPLE_SWAP_SLIPPAGE = exports.DynamicSwapType = exports.CHAINFLIP_SLIPPAGE =
|
|
6
|
+
exports._SUPPORTED_SWAP_PROVIDERS = exports.SwapStepType = exports.SwapProviderId = exports.SwapFeeType = exports.SwapErrorType = exports.SIMPLE_SWAP_SLIPPAGE = exports.DynamicSwapType = exports.CHAINFLIP_SLIPPAGE = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
// core
|
|
10
9
|
let SwapErrorType;
|
|
11
10
|
exports.SwapErrorType = SwapErrorType;
|
|
12
11
|
(function (SwapErrorType) {
|
|
@@ -50,7 +49,6 @@ exports.SwapProviderId = SwapProviderId;
|
|
|
50
49
|
})(SwapProviderId || (exports.SwapProviderId = SwapProviderId = {}));
|
|
51
50
|
const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET, SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB, SwapProviderId.SIMPLE_SWAP, SwapProviderId.UNISWAP, SwapProviderId.KYBER, SwapProviderId.OPTIMEX, SwapProviderId.OPTIMEX_TESTNET, SwapProviderId.BITTENSOR, SwapProviderId.BITTENSOR_TESTNET];
|
|
52
51
|
exports._SUPPORTED_SWAP_PROVIDERS = _SUPPORTED_SWAP_PROVIDERS;
|
|
53
|
-
// process handling
|
|
54
52
|
let SwapFeeType;
|
|
55
53
|
exports.SwapFeeType = SwapFeeType;
|
|
56
54
|
(function (SwapFeeType) {
|
|
@@ -59,18 +57,15 @@ exports.SwapFeeType = SwapFeeType;
|
|
|
59
57
|
SwapFeeType["WALLET_FEE"] = "WALLET_FEE";
|
|
60
58
|
})(SwapFeeType || (exports.SwapFeeType = SwapFeeType = {})); // todo: will be more
|
|
61
59
|
// parameters & responses
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use interface `SwapRequestV2` instead.
|
|
62
|
+
*/
|
|
62
63
|
let DynamicSwapType;
|
|
63
64
|
exports.DynamicSwapType = DynamicSwapType;
|
|
64
65
|
(function (DynamicSwapType) {
|
|
65
66
|
DynamicSwapType["SWAP"] = "SWAP";
|
|
66
67
|
DynamicSwapType["BRIDGE"] = "BRIDGE";
|
|
67
68
|
})(DynamicSwapType || (exports.DynamicSwapType = DynamicSwapType = {}));
|
|
68
|
-
let BridgeStepPosition;
|
|
69
|
-
exports.BridgeStepPosition = BridgeStepPosition;
|
|
70
|
-
(function (BridgeStepPosition) {
|
|
71
|
-
BridgeStepPosition[BridgeStepPosition["FIRST"] = 0] = "FIRST";
|
|
72
|
-
BridgeStepPosition[BridgeStepPosition["AFTER_SWAP"] = 1] = "AFTER_SWAP";
|
|
73
|
-
})(BridgeStepPosition || (exports.BridgeStepPosition = BridgeStepPosition = {}));
|
|
74
69
|
const CHAINFLIP_SLIPPAGE = 0.02; // Example: 0.01 for 1%
|
|
75
70
|
exports.CHAINFLIP_SLIPPAGE = CHAINFLIP_SLIPPAGE;
|
|
76
71
|
const SIMPLE_SWAP_SLIPPAGE = 0.05;
|
|
@@ -54,17 +54,53 @@ function reformatAddress(address) {
|
|
|
54
54
|
return address;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @private
|
|
60
|
+
* Reformats a wallet address based on the provided chain information.
|
|
61
|
+
*
|
|
62
|
+
* This function checks the chain type (Substrate, TON, Cardano, or others)
|
|
63
|
+
* and applies the corresponding formatting logic:
|
|
64
|
+
* 1. **Substrate**: Reformats the Substrate address using the chain's specific prefix.
|
|
65
|
+
* If the current `address` is an EVM address, it attempts to use the `alternativeAddress`
|
|
66
|
+
* (which is currently **always** expected to be the Substrate address) for Substrate
|
|
67
|
+
* formatting, as direct EVM-to-Substrate reformatting is not possible here.
|
|
68
|
+
* 2. **TON/Cardano**: Uses a simple prefix logic based on whether the chain is a testnet or a mainnet.
|
|
69
|
+
* 3. **Default (EVM/Others)**: Returns the original address without reformatting.
|
|
70
|
+
*
|
|
71
|
+
* @param address The current wallet address string.
|
|
72
|
+
* @param chainInfo An object containing chain details (e.g., chain type, testnet status, prefix).
|
|
73
|
+
* @param alternativeAddress An optional alternative address, which is currently expected to be the Substrate
|
|
74
|
+
* address associated with the account. It is used as a fallback for Substrate formatting when the main `address` is EVM.
|
|
75
|
+
* @returns The reformatted wallet address, or the original address if no reformatting is needed or possible.
|
|
76
|
+
*
|
|
77
|
+
* @todo This function currently lacks logic to reformat a Substrate address into an EVM address format.
|
|
78
|
+
*/
|
|
79
|
+
const _reformatAddressWithChain = (address, chainInfo, alternativeAddress) => {
|
|
58
80
|
const chainType = (0, _utils._chainInfoToAccountChainType)(chainInfo);
|
|
59
81
|
if (chainType === _types.AccountChainType.SUBSTRATE) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
const addressPrefix = (0, _utils._getChainSubstrateAddressPrefix)(chainInfo);
|
|
83
|
+
if (addressPrefix < 0) {
|
|
84
|
+
// not a valid address prefix for substrate chain type
|
|
85
|
+
return address;
|
|
86
|
+
}
|
|
87
|
+
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
88
|
+
if (alternativeAddress) {
|
|
89
|
+
// reformat using alternativeAddress of that account. Because can not reformat from evm address to substrate address
|
|
90
|
+
return reformatAddress(alternativeAddress, addressPrefix);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// can not reformat without substrateAddress info
|
|
94
|
+
return address;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// reformat as usual with substrate address
|
|
98
|
+
return reformatAddress(address, addressPrefix);
|
|
99
|
+
}
|
|
100
|
+
if (chainType === _types.AccountChainType.TON || chainType === _types.AccountChainType.CARDANO) {
|
|
101
|
+
return reformatAddress(address, chainInfo.isTestnet ? 0 : 1);
|
|
67
102
|
}
|
|
103
|
+
return address;
|
|
68
104
|
};
|
|
69
105
|
exports._reformatAddressWithChain = _reformatAddressWithChain;
|
|
70
106
|
const getAccountChainTypeForAddress = address => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
2
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
3
|
import BigN from 'bignumber.js';
|
|
4
|
-
export * from './swap';
|
|
5
4
|
export * from './request';
|
|
6
5
|
export * from './earning';
|
|
7
6
|
export * from './transfer';
|
|
@@ -5,7 +5,6 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
5
5
|
import { _getTokenMinAmount, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { BasicTxErrorType } from '@subwallet/extension-base/types';
|
|
7
7
|
import { t } from 'i18next';
|
|
8
|
-
export * from "./swap.js";
|
|
9
8
|
export * from "./request.js";
|
|
10
9
|
export * from "./earning.js";
|
|
11
10
|
export * from "./transfer.js";
|
|
@@ -43,6 +43,9 @@ function _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMo
|
|
|
43
43
|
if (strictMode) {
|
|
44
44
|
return bnExistentialDeposit;
|
|
45
45
|
}
|
|
46
|
+
if (accountInfo.data.free.toString() === existentialDeposit) {
|
|
47
|
+
return BigInt(0);
|
|
48
|
+
}
|
|
46
49
|
return _canAccountBeReaped(accountInfo) ? BigInt(0) : bnExistentialDeposit; // account for ED here will go better with max transfer logic
|
|
47
50
|
}
|
|
48
51
|
function _getSystemPalletTransferableV2(accountInfo, existentialDeposit, strictMode) {
|
package/koni/api/nft/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { UniqueNftApi } from '@subwallet/extension-base/koni/api/nft/unique_netw
|
|
|
14
14
|
import { VaraNftApi } from '@subwallet/extension-base/koni/api/nft/vara_nft';
|
|
15
15
|
import { WasmNftApi } from '@subwallet/extension-base/koni/api/nft/wasm_nft';
|
|
16
16
|
import { _NFT_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
17
|
-
import {
|
|
17
|
+
import { _isChainSupportNativeNft, _isChainSupportWasmNft, _isSupportOrdinal } from '@subwallet/extension-base/services/chain-service/utils';
|
|
18
18
|
import { getAddressesByChainType, targetIsWeb } from '@subwallet/extension-base/utils';
|
|
19
19
|
import AssetHubNftsPalletApi from "./assethub_nft/index.js";
|
|
20
20
|
import { RariNftApi } from "./rari/index.js";
|
|
@@ -33,8 +33,6 @@ function createSubstrateNftApi(chain, substrateApi, addresses) {
|
|
|
33
33
|
return [new AssetHubUniquesPalletApi(substrateApi, substrateAddresses, chain), new AssetHubNftsPalletApi(substrateApi, substrateAddresses, chain)];
|
|
34
34
|
} else if (_NFT_CHAIN_GROUP.statemint.includes(chain)) {
|
|
35
35
|
return [new AssetHubUniquesPalletApi(substrateApi, substrateAddresses, chain), new AssetHubNftsPalletApi(substrateApi, substrateAddresses, chain)];
|
|
36
|
-
} else if (_NFT_CHAIN_GROUP.unique_network.includes(chain)) {
|
|
37
|
-
return [new UniqueNftApi(chain, substrateAddresses)];
|
|
38
36
|
} else if (_NFT_CHAIN_GROUP.unique_evm.includes(chain)) {
|
|
39
37
|
return [new UniqueNftApi(chain, evmAddresses)];
|
|
40
38
|
} else if (_NFT_CHAIN_GROUP.bitcountry.includes(chain)) {
|
|
@@ -56,10 +54,6 @@ function createWasmNftApi(chain, apiProps, addresses) {
|
|
|
56
54
|
const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
|
|
57
55
|
return new WasmNftApi(apiProps, substrateAddresses, chain);
|
|
58
56
|
}
|
|
59
|
-
function createWeb3NftApi(chain, evmApi, addresses) {
|
|
60
|
-
const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
|
|
61
|
-
return new EvmNftApi(evmApi, evmAddresses, chain);
|
|
62
|
-
}
|
|
63
57
|
const createOrdinalApi = (chain, subscanChain, addresses) => {
|
|
64
58
|
return new OrdinalNftApi(addresses, chain, subscanChain);
|
|
65
59
|
};
|
|
@@ -128,14 +122,6 @@ export class NftHandler {
|
|
|
128
122
|
}
|
|
129
123
|
}
|
|
130
124
|
}
|
|
131
|
-
if (_isChainSupportEvmNft(chainInfo)) {
|
|
132
|
-
if (this.evmApiMap[chain]) {
|
|
133
|
-
const handler = createWeb3NftApi(chain, this.evmApiMap[chain], evmAddresses);
|
|
134
|
-
if (handler) {
|
|
135
|
-
this.handlers.push(handler);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
125
|
if (chain === 'unique_evm') {
|
|
140
126
|
const handlers = createSubstrateNftApi(chain, null, evmAddresses);
|
|
141
127
|
if (handlers && !!handlers.length) {
|
|
@@ -29,7 +29,6 @@ export declare class KoniCron {
|
|
|
29
29
|
refreshNft: (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => () => void;
|
|
30
30
|
resetNft: (newAddress: string) => void;
|
|
31
31
|
checkNetworkAvailable: (serviceInfo: ServiceInfo) => boolean;
|
|
32
|
-
detectEvmCollectionNft: (address: string) => () => void;
|
|
33
32
|
reloadNft(): Promise<boolean>;
|
|
34
33
|
reloadStaking(): Promise<boolean>;
|
|
35
34
|
private needUpdateNft;
|
package/koni/background/cron.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_MKT_CAMPAIGN_INTERVAL, CRON_REFRESH_NFT_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
|
|
5
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';
|
|
@@ -87,7 +87,6 @@ export class KoniCron {
|
|
|
87
87
|
// NFT
|
|
88
88
|
(commonReload || needUpdateNft) && this.resetNft(address);
|
|
89
89
|
(commonReload || needUpdateNft) && this.removeCron('refreshNft');
|
|
90
|
-
(commonReload || needUpdateNft) && this.removeCron('detectNft');
|
|
91
90
|
commonReload && this.removeCron('refreshPoolingStakingReward');
|
|
92
91
|
if (mktCampaignNeedReload) {
|
|
93
92
|
this.removeCron('fetchMktCampaignData');
|
|
@@ -103,7 +102,6 @@ export class KoniCron {
|
|
|
103
102
|
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
104
103
|
// only add cron jobs if there's at least 1 active network
|
|
105
104
|
(commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
106
|
-
(commonReload || needUpdateNft) && this.addCron('detectNft', this.detectEvmCollectionNft(address), CRON_NFT_DETECT_INTERVAL);
|
|
107
105
|
reloadMantaPay && this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
108
106
|
}
|
|
109
107
|
};
|
|
@@ -116,8 +114,6 @@ export class KoniCron {
|
|
|
116
114
|
if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
|
|
117
115
|
this.resetNft(currentAccountInfo.proxyId);
|
|
118
116
|
this.addCron('refreshNft', this.refreshNft(currentAccountInfo.proxyId, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
119
|
-
this.addCron('detectNft', this.detectEvmCollectionNft(currentAccountInfo.proxyId), CRON_NFT_DETECT_INTERVAL);
|
|
120
|
-
// this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
121
117
|
this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
122
118
|
}
|
|
123
119
|
this.status = 'running';
|
|
@@ -166,25 +162,12 @@ export class KoniCron {
|
|
|
166
162
|
checkNetworkAvailable = serviceInfo => {
|
|
167
163
|
return Object.keys(serviceInfo.chainApiMap.substrate).length > 0 || Object.keys(serviceInfo.chainApiMap.evm).length > 0;
|
|
168
164
|
};
|
|
169
|
-
detectEvmCollectionNft = address => {
|
|
170
|
-
return () => {
|
|
171
|
-
let addresses = [];
|
|
172
|
-
addresses = this.state.keyringService.context.getDecodedAddresses();
|
|
173
|
-
if (!addresses.length) {
|
|
174
|
-
console.warn('[Cron] No decoded addresses found for ALL_ACCOUNT_KEY');
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
this.state.nftDetectionService.fetchEvmCollectionsWithPreview(addresses).catch(err => console.warn(`[Cron] NFT detection failed for ${address}:`, err));
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
165
|
async reloadNft() {
|
|
181
166
|
const address = this.state.keyringService.context.currentAccount.proxyId;
|
|
182
167
|
const serviceInfo = this.state.getServiceInfo();
|
|
183
168
|
this.resetNft(address);
|
|
184
169
|
this.removeCron('refreshNft');
|
|
185
|
-
this.removeCron('detectNft');
|
|
186
170
|
this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
187
|
-
this.addCron('detectNft', this.detectEvmCollectionNft(address), CRON_NFT_DETECT_INTERVAL);
|
|
188
171
|
await waitTimeout(1800);
|
|
189
172
|
return true;
|
|
190
173
|
}
|
|
@@ -117,6 +117,7 @@ export default class KoniExtension {
|
|
|
117
117
|
private getNft;
|
|
118
118
|
private subscribeNft;
|
|
119
119
|
private handleGetNftFullList;
|
|
120
|
+
private handleGetNftDetail;
|
|
120
121
|
private getStakingReward;
|
|
121
122
|
private subscribeStakingReward;
|
|
122
123
|
private getStaking;
|
|
@@ -297,6 +298,9 @@ export default class KoniExtension {
|
|
|
297
298
|
private subscribeBuyTokens;
|
|
298
299
|
private subscribeBuyServices;
|
|
299
300
|
private subscribeSwapPairs;
|
|
301
|
+
/**
|
|
302
|
+
* @deprecated Use function `handleSwapRequestV2` instead.
|
|
303
|
+
*/
|
|
300
304
|
private handleSwapRequest;
|
|
301
305
|
private handleSwapRequestV2;
|
|
302
306
|
private getLatestSwapQuote;
|
|
@@ -962,7 +962,7 @@ export default class KoniExtension {
|
|
|
962
962
|
this.#koniState.eventService.emit('asset.updateState', params.tokenSlug);
|
|
963
963
|
return true;
|
|
964
964
|
} catch (e) {
|
|
965
|
-
console.error(e);
|
|
965
|
+
console.error('[updateAssetSetting] Error:', e);
|
|
966
966
|
return false;
|
|
967
967
|
}
|
|
968
968
|
}
|
|
@@ -1150,7 +1150,10 @@ export default class KoniExtension {
|
|
|
1150
1150
|
return this.getNft();
|
|
1151
1151
|
}
|
|
1152
1152
|
async handleGetNftFullList(request) {
|
|
1153
|
-
return this.#koniState.
|
|
1153
|
+
return this.#koniState.nftService.fetchFullListNftOfACollection(request);
|
|
1154
|
+
}
|
|
1155
|
+
async handleGetNftDetail(request) {
|
|
1156
|
+
return this.#koniState.nftService.fetchNftDetail(request);
|
|
1154
1157
|
}
|
|
1155
1158
|
getStakingReward() {
|
|
1156
1159
|
return new Promise((resolve, reject) => {
|
|
@@ -4540,7 +4543,8 @@ export default class KoniExtension {
|
|
|
4540
4543
|
...this.createPassConfirmationParams(isPassConfirmation),
|
|
4541
4544
|
eventsHandler,
|
|
4542
4545
|
step,
|
|
4543
|
-
xcmFeeDryRun: extrinsicType === ExtrinsicType.TRANSFER_XCM ? submitData.xcmStepFee : undefined
|
|
4546
|
+
xcmFeeDryRun: extrinsicType === ExtrinsicType.TRANSFER_XCM ? submitData.xcmStepFee : undefined,
|
|
4547
|
+
xcmDestinationFee: submitData.xcmDestinationFee
|
|
4544
4548
|
});
|
|
4545
4549
|
}
|
|
4546
4550
|
async handleYieldLeave(params) {
|
|
@@ -4920,6 +4924,10 @@ export default class KoniExtension {
|
|
|
4920
4924
|
ready = true;
|
|
4921
4925
|
return this.#koniState.swapService.getSwapPairs();
|
|
4922
4926
|
}
|
|
4927
|
+
|
|
4928
|
+
/**
|
|
4929
|
+
* @deprecated Use function `handleSwapRequestV2` instead.
|
|
4930
|
+
*/
|
|
4923
4931
|
async handleSwapRequest(request) {
|
|
4924
4932
|
// @ts-ignore
|
|
4925
4933
|
return Promise.resolve(null);
|
|
@@ -5652,16 +5660,14 @@ export default class KoniExtension {
|
|
|
5652
5660
|
return this.getCrowdloanContributions(request);
|
|
5653
5661
|
case 'pri(crowdloan.getSubscription)':
|
|
5654
5662
|
return this.subscribeCrowdloan(id, port);
|
|
5655
|
-
case 'pri(nft.getNft)':
|
|
5656
|
-
return await this.getNft();
|
|
5657
5663
|
case 'pri(nft.getSubscription)':
|
|
5658
5664
|
return await this.subscribeNft(id, port);
|
|
5659
|
-
case 'pri(nftCollection.getNftCollection)':
|
|
5660
|
-
return await this.getNftCollection();
|
|
5661
5665
|
case 'pri(nftCollection.getSubscription)':
|
|
5662
5666
|
return await this.subscribeNftCollection(id, port);
|
|
5663
5667
|
case 'pri(nft.getFullList)':
|
|
5664
5668
|
return await this.handleGetNftFullList(request);
|
|
5669
|
+
case 'pri(nft.getNftdetail)':
|
|
5670
|
+
return await this.handleGetNftDetail(request);
|
|
5665
5671
|
case 'pri(staking.getStaking)':
|
|
5666
5672
|
return this.getStaking();
|
|
5667
5673
|
case 'pri(staking.getSubscription)':
|
|
@@ -20,7 +20,7 @@ import MigrationService from '@subwallet/extension-base/services/migration-servi
|
|
|
20
20
|
import MintCampaignService from '@subwallet/extension-base/services/mint-campaign-service';
|
|
21
21
|
import MktCampaignService from '@subwallet/extension-base/services/mkt-campaign-service';
|
|
22
22
|
import { MultisigService } from '@subwallet/extension-base/services/multisig-service';
|
|
23
|
-
import NftService from '@subwallet/extension-base/services/nft-service';
|
|
23
|
+
import { NftService } from '@subwallet/extension-base/services/nft-service';
|
|
24
24
|
import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
|
|
25
25
|
import OpenGovService from '@subwallet/extension-base/services/open-gov';
|
|
26
26
|
import { PriceService } from '@subwallet/extension-base/services/price-service';
|
|
@@ -48,6 +48,11 @@ export default class KoniState {
|
|
|
48
48
|
private externalRequest;
|
|
49
49
|
private crowdloanMap;
|
|
50
50
|
private crowdloanSubject;
|
|
51
|
+
/**
|
|
52
|
+
* TODO: Remove this subject once NFT migration to the service layer is completed.
|
|
53
|
+
* The state manager should not handle the internal state of the NFT service.
|
|
54
|
+
* The NFT service will manage its own state independently.
|
|
55
|
+
*/
|
|
51
56
|
private nftSubject;
|
|
52
57
|
private mantaPayConfigSubject;
|
|
53
58
|
isMantaPayEnabled: boolean;
|
|
@@ -77,7 +82,7 @@ export default class KoniState {
|
|
|
77
82
|
readonly mintCampaignService: MintCampaignService;
|
|
78
83
|
readonly campaignService: CampaignService;
|
|
79
84
|
readonly mktCampaignService: MktCampaignService;
|
|
80
|
-
readonly
|
|
85
|
+
readonly nftService: NftService;
|
|
81
86
|
readonly buyService: BuyService;
|
|
82
87
|
readonly earningService: EarningService;
|
|
83
88
|
readonly feeService: FeeService;
|
|
@@ -273,6 +278,7 @@ export default class KoniState {
|
|
|
273
278
|
onAccountAdd(): void;
|
|
274
279
|
onAccountRemove(): void;
|
|
275
280
|
reloadNft(): Promise<boolean>;
|
|
281
|
+
reloadNftV2(): Promise<void>;
|
|
276
282
|
reloadStaking(): Promise<boolean>;
|
|
277
283
|
reloadBalance(): Promise<boolean>;
|
|
278
284
|
approvePassPhishingPage(_url: string): Promise<boolean>;
|
|
@@ -29,7 +29,7 @@ import MigrationService from '@subwallet/extension-base/services/migration-servi
|
|
|
29
29
|
import MintCampaignService from '@subwallet/extension-base/services/mint-campaign-service';
|
|
30
30
|
import MktCampaignService from '@subwallet/extension-base/services/mkt-campaign-service';
|
|
31
31
|
import { MultisigService } from '@subwallet/extension-base/services/multisig-service';
|
|
32
|
-
import NftService from '@subwallet/extension-base/services/nft-service';
|
|
32
|
+
import { NftService } from '@subwallet/extension-base/services/nft-service';
|
|
33
33
|
import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
|
|
34
34
|
import OpenGovService from '@subwallet/extension-base/services/open-gov';
|
|
35
35
|
import { PriceService } from '@subwallet/extension-base/services/price-service';
|
|
@@ -79,6 +79,12 @@ export default class KoniState {
|
|
|
79
79
|
externalRequest = {};
|
|
80
80
|
crowdloanMap = generateDefaultCrowdloanMap();
|
|
81
81
|
crowdloanSubject = new Subject();
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* TODO: Remove this subject once NFT migration to the service layer is completed.
|
|
85
|
+
* The state manager should not handle the internal state of the NFT service.
|
|
86
|
+
* The NFT service will manage its own state independently.
|
|
87
|
+
*/
|
|
82
88
|
nftSubject = new Subject();
|
|
83
89
|
mantaPayConfigSubject = new Subject();
|
|
84
90
|
isMantaPayEnabled = false;
|
|
@@ -115,13 +121,13 @@ export default class KoniState {
|
|
|
115
121
|
this.requestService = new RequestService(this.chainService, this.settingService, this.keyringService, this.transactionService);
|
|
116
122
|
this.priceService = new PriceService(this.dbService, this.eventService, this.chainService);
|
|
117
123
|
this.balanceService = new BalanceService(this);
|
|
124
|
+
this.nftService = new NftService(this);
|
|
118
125
|
this.historyService = new HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService, this.subscanService);
|
|
119
126
|
this.mintCampaignService = new MintCampaignService(this);
|
|
120
127
|
this.walletConnectService = new WalletConnectService(this, this.requestService);
|
|
121
128
|
this.migrationService = new MigrationService(this, this.eventService);
|
|
122
129
|
this.campaignService = new CampaignService(this);
|
|
123
130
|
this.mktCampaignService = new MktCampaignService(this);
|
|
124
|
-
this.nftDetectionService = new NftService(this);
|
|
125
131
|
this.buyService = new BuyService(this);
|
|
126
132
|
this.earningService = new EarningService(this);
|
|
127
133
|
this.swapService = new SwapService(this);
|
|
@@ -232,6 +238,7 @@ export default class KoniState {
|
|
|
232
238
|
this.mktCampaignService.init();
|
|
233
239
|
this.eventService.emit('chain.ready', true);
|
|
234
240
|
await this.balanceService.init();
|
|
241
|
+
await this.nftService.init();
|
|
235
242
|
await this.earningService.init();
|
|
236
243
|
await this.swapService.init();
|
|
237
244
|
await this.inappNotificationService.init();
|
|
@@ -387,6 +394,7 @@ export default class KoniState {
|
|
|
387
394
|
return this.dbService.getAllNftCollection(this.activeChainSlugs);
|
|
388
395
|
}
|
|
389
396
|
subscribeNftCollection() {
|
|
397
|
+
// TODO: Move this logic to the NFT service once migration is complete.
|
|
390
398
|
const getChains = () => this.activeChainSlugs;
|
|
391
399
|
return this.dbService.stores.nftCollection.subscribeNftCollection(getChains);
|
|
392
400
|
}
|
|
@@ -1768,7 +1776,7 @@ export default class KoniState {
|
|
|
1768
1776
|
this.campaignService.stop();
|
|
1769
1777
|
await Promise.all([this.cron.stop(), this.subscription.stop()]);
|
|
1770
1778
|
await this.pauseAllNetworks(undefined, 'IDLE mode');
|
|
1771
|
-
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.earningService.stop(), this.swapService.stop(), this.inappNotificationService.stop(), this.openGovService.stop(), this.multisigService.stop()]);
|
|
1779
|
+
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.nftService.stop(), this.earningService.stop(), this.swapService.stop(), this.inappNotificationService.stop(), this.openGovService.stop(), this.multisigService.stop()]);
|
|
1772
1780
|
|
|
1773
1781
|
// Complete sleeping
|
|
1774
1782
|
sleeping.resolve();
|
|
@@ -1824,7 +1832,7 @@ export default class KoniState {
|
|
|
1824
1832
|
this.generalStatus = ServiceStatus.STARTING_FULL;
|
|
1825
1833
|
const startingFull = createPromiseHandler();
|
|
1826
1834
|
this.waitStartingFull = startingFull.promise;
|
|
1827
|
-
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start(), this.swapService.start(), this.inappNotificationService.start(), this.openGovService.start(), this.multisigService.start()]);
|
|
1835
|
+
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.nftService.start(), this.earningService.start(), this.swapService.start(), this.inappNotificationService.start(), this.openGovService.start(), this.multisigService.start()]);
|
|
1828
1836
|
this.eventService.emit('general.start_full', true);
|
|
1829
1837
|
this.waitStartingFull = null;
|
|
1830
1838
|
this.generalStatus = ServiceStatus.STARTED_FULL;
|
|
@@ -1885,9 +1893,19 @@ export default class KoniState {
|
|
|
1885
1893
|
});
|
|
1886
1894
|
}
|
|
1887
1895
|
async reloadNft() {
|
|
1888
|
-
const
|
|
1896
|
+
const currentProxyId = this.keyringService.context.currentAccount.proxyId;
|
|
1897
|
+
const currentAddress = this.keyringService.context.addressesByProxyId(currentProxyId);
|
|
1889
1898
|
await this.dbService.removeNftsByAddress(currentAddress);
|
|
1890
|
-
|
|
1899
|
+
await this.cron.reloadNft();
|
|
1900
|
+
await this.reloadNftV2();
|
|
1901
|
+
return true;
|
|
1902
|
+
}
|
|
1903
|
+
async reloadNftV2() {
|
|
1904
|
+
// TODO: Recheck: Uncomment this block when migration is complete
|
|
1905
|
+
// const currentAddress = this.keyringService.context.currentAccount.proxyId;
|
|
1906
|
+
//
|
|
1907
|
+
// await this.dbService.removeNftsByAddress(currentAddress);
|
|
1908
|
+
await this.nftService.forceReload();
|
|
1891
1909
|
}
|
|
1892
1910
|
async reloadStaking() {
|
|
1893
1911
|
await this.earningService.reloadEarning(true);
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.80-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -194,11 +194,6 @@
|
|
|
194
194
|
"require": "./cjs/core/logic-validation/request.js",
|
|
195
195
|
"default": "./core/logic-validation/request.js"
|
|
196
196
|
},
|
|
197
|
-
"./core/logic-validation/swap": {
|
|
198
|
-
"types": "./core/logic-validation/swap.d.ts",
|
|
199
|
-
"require": "./cjs/core/logic-validation/swap.js",
|
|
200
|
-
"default": "./core/logic-validation/swap.js"
|
|
201
|
-
},
|
|
202
197
|
"./core/logic-validation/transfer": {
|
|
203
198
|
"types": "./core/logic-validation/transfer.d.ts",
|
|
204
199
|
"require": "./cjs/core/logic-validation/transfer.js",
|
|
@@ -1756,6 +1751,31 @@
|
|
|
1756
1751
|
"require": "./cjs/services/nft-service/index.js",
|
|
1757
1752
|
"default": "./services/nft-service/index.js"
|
|
1758
1753
|
},
|
|
1754
|
+
"./services/nft-service/multi-chain-nft-fetcher": {
|
|
1755
|
+
"types": "./services/nft-service/multi-chain-nft-fetcher.d.ts",
|
|
1756
|
+
"require": "./cjs/services/nft-service/multi-chain-nft-fetcher.js",
|
|
1757
|
+
"default": "./services/nft-service/multi-chain-nft-fetcher.js"
|
|
1758
|
+
},
|
|
1759
|
+
"./services/nft-service/nft-handlers/base-nft-handler": {
|
|
1760
|
+
"types": "./services/nft-service/nft-handlers/base-nft-handler.d.ts",
|
|
1761
|
+
"require": "./cjs/services/nft-service/nft-handlers/base-nft-handler.js",
|
|
1762
|
+
"default": "./services/nft-service/nft-handlers/base-nft-handler.js"
|
|
1763
|
+
},
|
|
1764
|
+
"./services/nft-service/nft-handlers/evm/evm-nft-handler": {
|
|
1765
|
+
"types": "./services/nft-service/nft-handlers/evm/evm-nft-handler.d.ts",
|
|
1766
|
+
"require": "./cjs/services/nft-service/nft-handlers/evm/evm-nft-handler.js",
|
|
1767
|
+
"default": "./services/nft-service/nft-handlers/evm/evm-nft-handler.js"
|
|
1768
|
+
},
|
|
1769
|
+
"./services/nft-service/nft-handlers/registry": {
|
|
1770
|
+
"types": "./services/nft-service/nft-handlers/registry.d.ts",
|
|
1771
|
+
"require": "./cjs/services/nft-service/nft-handlers/registry.js",
|
|
1772
|
+
"default": "./services/nft-service/nft-handlers/registry.js"
|
|
1773
|
+
},
|
|
1774
|
+
"./services/nft-service/nft-handlers/unique/unique-nft-handler": {
|
|
1775
|
+
"types": "./services/nft-service/nft-handlers/unique/unique-nft-handler.d.ts",
|
|
1776
|
+
"require": "./cjs/services/nft-service/nft-handlers/unique/unique-nft-handler.js",
|
|
1777
|
+
"default": "./services/nft-service/nft-handlers/unique/unique-nft-handler.js"
|
|
1778
|
+
},
|
|
1759
1779
|
"./services/notification-service/NotificationService": {
|
|
1760
1780
|
"types": "./services/notification-service/NotificationService.d.ts",
|
|
1761
1781
|
"require": "./cjs/services/notification-service/NotificationService.js",
|
|
@@ -3027,12 +3047,12 @@
|
|
|
3027
3047
|
"@snowbridge/registry": "^0.2.0",
|
|
3028
3048
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
3029
3049
|
"@substrate/connect": "^0.8.9",
|
|
3030
|
-
"@subwallet-monorepos/subwallet-services-sdk": "0.1.
|
|
3050
|
+
"@subwallet-monorepos/subwallet-services-sdk": "0.1.17-beta.2",
|
|
3031
3051
|
"@subwallet/chain-list": "0.2.127",
|
|
3032
|
-
"@subwallet/extension-base": "^1.3.
|
|
3033
|
-
"@subwallet/extension-chains": "^1.3.
|
|
3034
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
3035
|
-
"@subwallet/extension-inject": "^1.3.
|
|
3052
|
+
"@subwallet/extension-base": "^1.3.80-0",
|
|
3053
|
+
"@subwallet/extension-chains": "^1.3.80-0",
|
|
3054
|
+
"@subwallet/extension-dapp": "^1.3.80-0",
|
|
3055
|
+
"@subwallet/extension-inject": "^1.3.80-0",
|
|
3036
3056
|
"@subwallet/keyring": "^0.1.14",
|
|
3037
3057
|
"@subwallet/ui-keyring": "^0.1.14",
|
|
3038
3058
|
"@ton/core": "^0.56.3",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.3.
|
|
10
|
+
version: '1.3.80-0'
|
|
11
11
|
};
|
|
@@ -11,4 +11,4 @@ export interface RequestOptimalTransferProcess {
|
|
|
11
11
|
}
|
|
12
12
|
export declare function getDefaultTransferProcess(): CommonOptimalTransferPath;
|
|
13
13
|
export declare function getSnowbridgeTransferProcessFromEvm(address: string, evmApi: _EvmApi, tokenInfo: _ChainAsset, amount: string): Promise<CommonOptimalTransferPath>;
|
|
14
|
-
export declare function getAcrossbridgeTransferProcessFromEvm(SpokePoolAddress: string): Promise<CommonOptimalTransferPath>;
|
|
14
|
+
export declare function getAcrossbridgeTransferProcessFromEvm(SpokePoolAddress: string, address: string, tokenInfo: _ChainAsset, evmApi: _EvmApi, amount: string): Promise<CommonOptimalTransferPath>;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
|
+
import { getERC20Allowance } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
6
|
+
import { getSnowBridgeGatewayContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
7
|
+
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
8
|
import { CommonStepType, DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
|
|
9
|
+
import BigN from 'bignumber.js';
|
|
6
10
|
export function getDefaultTransferProcess() {
|
|
7
11
|
return {
|
|
8
12
|
totalFee: [MOCK_STEP_FEE, MOCK_STEP_FEE],
|
|
@@ -22,18 +26,25 @@ export async function getSnowbridgeTransferProcessFromEvm(address, evmApi, token
|
|
|
22
26
|
totalFee: [MOCK_STEP_FEE],
|
|
23
27
|
steps: [DEFAULT_FIRST_STEP]
|
|
24
28
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
try {
|
|
30
|
+
const allowance = await getERC20Allowance(getSnowBridgeGatewayContract(evmApi.chainSlug), address, _getContractAddressOfToken(tokenInfo), evmApi);
|
|
31
|
+
if (!allowance || new BigN(allowance).lt(amount)) {
|
|
32
|
+
result.steps.push({
|
|
33
|
+
id: result.steps.length,
|
|
34
|
+
type: CommonStepType.TOKEN_APPROVAL,
|
|
35
|
+
name: 'Approve spending'
|
|
36
|
+
});
|
|
37
|
+
result.totalFee.push(MOCK_STEP_FEE);
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error(e);
|
|
41
|
+
result.steps.push({
|
|
42
|
+
id: result.steps.length,
|
|
43
|
+
type: CommonStepType.TOKEN_APPROVAL,
|
|
44
|
+
name: 'Approve spending'
|
|
45
|
+
});
|
|
46
|
+
result.totalFee.push(MOCK_STEP_FEE);
|
|
47
|
+
}
|
|
37
48
|
result.steps.push({
|
|
38
49
|
id: result.steps.length,
|
|
39
50
|
type: CommonStepType.TRANSFER,
|
|
@@ -42,20 +53,36 @@ export async function getSnowbridgeTransferProcessFromEvm(address, evmApi, token
|
|
|
42
53
|
result.totalFee.push(MOCK_STEP_FEE);
|
|
43
54
|
return Promise.resolve(result);
|
|
44
55
|
}
|
|
45
|
-
export async function getAcrossbridgeTransferProcessFromEvm(SpokePoolAddress) {
|
|
56
|
+
export async function getAcrossbridgeTransferProcessFromEvm(SpokePoolAddress, address, tokenInfo, evmApi, amount) {
|
|
46
57
|
const result = {
|
|
47
58
|
totalFee: [MOCK_STEP_FEE],
|
|
48
59
|
steps: [DEFAULT_FIRST_STEP]
|
|
49
60
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
try {
|
|
62
|
+
const allowance = await getERC20Allowance(SpokePoolAddress, address, _getContractAddressOfToken(tokenInfo), evmApi);
|
|
63
|
+
if (!allowance || new BigN(allowance).lt(amount)) {
|
|
64
|
+
result.steps.push({
|
|
65
|
+
id: result.steps.length,
|
|
66
|
+
type: CommonStepType.TOKEN_APPROVAL,
|
|
67
|
+
name: 'Approve spending',
|
|
68
|
+
metadata: {
|
|
69
|
+
SpokePoolAddress
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
result.totalFee.push(MOCK_STEP_FEE);
|
|
56
73
|
}
|
|
57
|
-
})
|
|
58
|
-
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error(e);
|
|
76
|
+
result.steps.push({
|
|
77
|
+
id: result.steps.length,
|
|
78
|
+
type: CommonStepType.TOKEN_APPROVAL,
|
|
79
|
+
name: 'Approve spending',
|
|
80
|
+
metadata: {
|
|
81
|
+
SpokePoolAddress
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
result.totalFee.push(MOCK_STEP_FEE);
|
|
85
|
+
}
|
|
59
86
|
result.steps.push({
|
|
60
87
|
id: result.steps.length,
|
|
61
88
|
type: CommonStepType.TRANSFER,
|