@subwallet/extension-base 1.0.2-1 → 1.0.2-1b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +16 -34
- package/background/KoniTypes.js +6 -7
- package/background/errors/TransactionError.js +21 -1
- package/cjs/background/KoniTypes.js +6 -7
- package/cjs/background/errors/TransactionError.js +20 -0
- package/cjs/constants/index.js +8 -26
- package/cjs/koni/api/dotsama/balance.js +49 -224
- package/cjs/koni/api/dotsama/transfer.js +30 -29
- package/cjs/koni/api/nft/acala_nft/index.js +4 -1
- package/cjs/koni/api/nft/bit.country/index.js +4 -1
- package/cjs/koni/api/nft/evm_nft/index.js +7 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +4 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
- package/cjs/koni/api/nft/unique_nft/index.js +6 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
- package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
- package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
- package/cjs/koni/api/staking/bonding/astar.js +15 -13
- package/cjs/koni/api/staking/bonding/index.js +22 -10
- package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +119 -16
- package/cjs/koni/api/staking/bonding/utils.js +27 -8
- package/cjs/koni/api/tokens/wasm/index.js +5 -4
- package/cjs/koni/api/tokens/wasm/utils.js +63 -0
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +150 -47
- package/cjs/koni/background/handlers/Extension.js +106 -64
- package/cjs/koni/background/handlers/State.js +19 -21
- package/cjs/koni/background/handlers/Tabs.js +8 -1
- package/cjs/koni/background/subscription.js +32 -29
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/handler/light-client/index.js +2 -0
- package/cjs/services/chain-service/index.js +6 -7
- package/cjs/services/event-service/index.js +5 -1
- package/cjs/services/event-service/types.js +11 -1
- package/cjs/services/history-service/index.js +16 -10
- package/cjs/services/history-service/subsquid-multi-chain-history.js +12 -9
- package/cjs/services/price-service/coingecko.js +0 -1
- package/cjs/services/price-service/index.js +2 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +6 -2
- package/cjs/services/storage-service/DatabaseService.js +52 -33
- package/cjs/services/storage-service/db-stores/Nft.js +4 -17
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +23 -14
- package/cjs/utils/index.js +7 -14
- package/constants/index.d.ts +7 -13
- package/constants/index.js +7 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +22 -197
- package/koni/api/dotsama/transfer.js +5 -4
- package/koni/api/nft/acala_nft/index.js +3 -1
- package/koni/api/nft/bit.country/index.js +3 -1
- package/koni/api/nft/evm_nft/index.js +6 -3
- package/koni/api/nft/index.d.ts +1 -2
- package/koni/api/nft/index.js +3 -6
- package/koni/api/nft/karura_nft/index.js +3 -1
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +8 -1
- package/koni/api/nft/statemine_nft/index.js +3 -1
- package/koni/api/nft/unique_nft/index.js +5 -1
- package/koni/api/nft/wasm_nft/index.d.ts +0 -2
- package/koni/api/nft/wasm_nft/index.js +167 -109
- package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
- package/koni/api/nft/wasm_nft/utils.js +7 -5
- package/koni/api/staking/bonding/amplitude.d.ts +0 -1
- package/koni/api/staking/bonding/amplitude.js +15 -10
- package/koni/api/staking/bonding/astar.js +8 -6
- package/koni/api/staking/bonding/index.d.ts +4 -1
- package/koni/api/staking/bonding/index.js +23 -13
- package/koni/api/staking/bonding/paraChain.d.ts +3 -0
- package/koni/api/staking/bonding/paraChain.js +86 -5
- package/koni/api/staking/bonding/relayChain.d.ts +5 -1
- package/koni/api/staking/bonding/relayChain.js +118 -18
- package/koni/api/staking/bonding/utils.d.ts +3 -2
- package/koni/api/staking/bonding/utils.js +27 -9
- package/koni/api/tokens/wasm/index.js +5 -4
- package/koni/api/tokens/wasm/utils.d.ts +6 -0
- package/koni/api/tokens/wasm/utils.js +54 -0
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +151 -48
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +108 -67
- package/koni/background/handlers/State.d.ts +5 -6
- package/koni/background/handlers/State.js +19 -21
- package/koni/background/handlers/Tabs.js +8 -1
- package/koni/background/subscription.js +31 -30
- package/package.json +9 -4
- package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
- package/services/chain-service/handler/light-client/index.d.ts +17 -1
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +1041 -881
- package/services/chain-service/helper/psp34_abi.json +2963 -1807
- package/services/chain-service/index.js +6 -7
- package/services/event-service/index.js +5 -1
- package/services/event-service/types.d.ts +5 -9
- package/services/event-service/types.js +4 -1
- package/services/history-service/index.d.ts +1 -1
- package/services/history-service/index.js +16 -10
- package/services/history-service/subsquid-multi-chain-history.js +15 -11
- package/services/price-service/coingecko.js +0 -1
- package/services/price-service/index.js +2 -3
- package/services/request-service/handler/AuthRequestHandler.js +6 -2
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +52 -33
- package/services/storage-service/db-stores/Nft.d.ts +1 -2
- package/services/storage-service/db-stores/Nft.js +4 -16
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.js +23 -14
- package/utils/index.d.ts +1 -1
- package/utils/index.js +6 -12
package/cjs/utils/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -28,15 +27,14 @@ exports.isUrl = isUrl;
|
|
|
28
27
|
exports.isValidSubstrateAddress = exports.isValidProvider = void 0;
|
|
29
28
|
exports.mergeNetworkProviders = mergeNetworkProviders;
|
|
30
29
|
exports.parseIpfsLink = exports.notDef = exports.nonEmptyArr = void 0;
|
|
31
|
-
exports.parseNumberToDisplay = parseNumberToDisplay;
|
|
32
30
|
exports.parseRawNumber = parseRawNumber;
|
|
33
31
|
exports.reformatAddress = reformatAddress;
|
|
34
32
|
exports.sumBN = sumBN;
|
|
35
33
|
exports.toUnit = void 0;
|
|
36
34
|
exports.utf16ToString = utf16ToString;
|
|
35
|
+
exports.waitTimeout = waitTimeout;
|
|
37
36
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
38
37
|
var _constants = require("@subwallet/extension-base/constants");
|
|
39
|
-
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
40
38
|
var _util = require("@polkadot/util");
|
|
41
39
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
42
40
|
var _canDerive = require("./canDerive");
|
|
@@ -315,21 +313,16 @@ exports.filterAndSortingAccountByAuthType = filterAndSortingAccountByAuthType;
|
|
|
315
313
|
function parseRawNumber(value) {
|
|
316
314
|
return parseFloat(value.replaceAll(',', ''));
|
|
317
315
|
}
|
|
318
|
-
function parseNumberToDisplay(amount, decimals) {
|
|
319
|
-
if (!decimals) {
|
|
320
|
-
return '0';
|
|
321
|
-
}
|
|
322
|
-
const parsedAmount = parseRawNumber(amount.toString());
|
|
323
|
-
const bigN = new _bignumber.default(parsedAmount / 10 ** decimals);
|
|
324
|
-
const roundedString = bigN.toFixed(9);
|
|
325
|
-
const formattedString = parseFloat(roundedString); // remove excess zeros at the end
|
|
326
|
-
|
|
327
|
-
return formattedString.toString();
|
|
328
|
-
}
|
|
329
316
|
function isSameAddress(address1, address2) {
|
|
317
|
+
if ((0, _utilCrypto.isEthereumAddress)(address1)) {
|
|
318
|
+
return address1.toLowerCase() === address2.toLowerCase();
|
|
319
|
+
}
|
|
330
320
|
return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
|
|
331
321
|
}
|
|
332
322
|
|
|
333
323
|
function getDomainFromUrl(url) {
|
|
334
324
|
return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
|
|
325
|
+
}
|
|
326
|
+
async function waitTimeout(ms) {
|
|
327
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
335
328
|
}
|
package/constants/index.d.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
export declare const CRON_REFRESH_PRICE_INTERVAL = 30000;
|
|
2
|
-
export declare const DOTSAMA_API_TIMEOUT = 30000;
|
|
3
|
-
export declare const DOTSAMA_AUTO_CONNECT_MS = 3000;
|
|
4
|
-
export declare const DOTSAMA_MAX_CONTINUE_RETRY = 2;
|
|
5
2
|
export declare const CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = 60000;
|
|
6
3
|
export declare const CRON_AUTO_RECOVER_WEB3_INTERVAL = 90000;
|
|
7
4
|
export declare const ACALA_REFRESH_CROWDLOAN_INTERVAL = 300000;
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const SUBSCRIBE_BALANCE_FAST_INTERVAL = 9000;
|
|
12
|
-
export declare const CRON_REFRESH_NFT_INTERVAL = 900000;
|
|
5
|
+
export declare const ASTAR_REFRESH_BALANCE_INTERVAL = 60000;
|
|
6
|
+
export declare const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
|
|
7
|
+
export declare const CRON_REFRESH_NFT_INTERVAL = 7200000;
|
|
13
8
|
export declare const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
|
|
14
|
-
export declare const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL =
|
|
15
|
-
export declare const CRON_REFRESH_HISTORY_INTERVAL =
|
|
16
|
-
export declare const CRON_GET_API_MAP_STATUS =
|
|
17
|
-
export declare const CRON_REFRESH_STAKING_DATA = 30000;
|
|
9
|
+
export declare const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 300000;
|
|
10
|
+
export declare const CRON_REFRESH_HISTORY_INTERVAL = 900000;
|
|
11
|
+
export declare const CRON_GET_API_MAP_STATUS = 10000;
|
|
18
12
|
export declare const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
|
|
19
|
-
export declare const CRON_REFRESH_CHAIN_NOMINATOR_METADATA =
|
|
13
|
+
export declare const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
|
|
20
14
|
export declare const ALL_ACCOUNT_KEY = "ALL";
|
|
21
15
|
export declare const ALL_NETWORK_KEY = "all";
|
|
22
16
|
export declare const ALL_GENESIS_HASH: null;
|
package/constants/index.js
CHANGED
|
@@ -2,24 +2,18 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
export const CRON_REFRESH_PRICE_INTERVAL = 30000;
|
|
5
|
-
export const DOTSAMA_API_TIMEOUT = 30000;
|
|
6
|
-
export const DOTSAMA_AUTO_CONNECT_MS = 3000;
|
|
7
|
-
export const DOTSAMA_MAX_CONTINUE_RETRY = 2;
|
|
8
5
|
export const CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = 60000;
|
|
9
6
|
export const CRON_AUTO_RECOVER_WEB3_INTERVAL = 90000;
|
|
10
7
|
export const ACALA_REFRESH_CROWDLOAN_INTERVAL = 300000;
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
13
|
-
export const
|
|
14
|
-
export const SUBSCRIBE_BALANCE_FAST_INTERVAL = 9000;
|
|
15
|
-
export const CRON_REFRESH_NFT_INTERVAL = 900000;
|
|
8
|
+
export const ASTAR_REFRESH_BALANCE_INTERVAL = 60000;
|
|
9
|
+
export const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
|
|
10
|
+
export const CRON_REFRESH_NFT_INTERVAL = 7200000;
|
|
16
11
|
export const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
|
|
17
|
-
export const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL =
|
|
18
|
-
export const CRON_REFRESH_HISTORY_INTERVAL =
|
|
19
|
-
export const CRON_GET_API_MAP_STATUS =
|
|
20
|
-
export const CRON_REFRESH_STAKING_DATA = 30000;
|
|
12
|
+
export const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 300000;
|
|
13
|
+
export const CRON_REFRESH_HISTORY_INTERVAL = 900000;
|
|
14
|
+
export const CRON_GET_API_MAP_STATUS = 10000;
|
|
21
15
|
export const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
|
|
22
|
-
export const CRON_REFRESH_CHAIN_NOMINATOR_METADATA =
|
|
16
|
+
export const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
|
|
23
17
|
export const ALL_ACCOUNT_KEY = 'ALL';
|
|
24
18
|
export const ALL_NETWORK_KEY = 'all';
|
|
25
19
|
export const ALL_GENESIS_HASH = null;
|
|
@@ -4,4 +4,3 @@ import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain
|
|
|
4
4
|
export declare function subscribeBalance(addresses: string[], chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem) => void): () => void;
|
|
5
5
|
export declare function subscribeSubstrateBalance(addresses: string[], chainInfo: _ChainInfo, chain: string, networkAPI: _SubstrateApi, evmApiMap: Record<string, _EvmApi>, callBack: (rs: BalanceItem) => void): Promise<() => void>;
|
|
6
6
|
export declare function subscribeEVMBalance(chain: string, addresses: string[], evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem) => void, tokenInfo: _ChainAsset): () => void;
|
|
7
|
-
export declare function getFreeBalance(chain: string, address: string, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, tokenSlug?: string): Promise<string>;
|
|
@@ -7,12 +7,12 @@ import { ASTAR_REFRESH_BALANCE_INTERVAL, SUB_TOKEN_REFRESH_BALANCE_INTERVAL } fr
|
|
|
7
7
|
import { getEVMBalance } from '@subwallet/extension-base/koni/api/tokens/evm/balance';
|
|
8
8
|
import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/web3';
|
|
9
9
|
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
|
|
10
|
+
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
10
11
|
import { state } from '@subwallet/extension-base/koni/background/handlers';
|
|
11
|
-
import { _BALANCE_CHAIN_GROUP,
|
|
12
|
-
import { _checkSmartContractSupportByChain, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible,
|
|
12
|
+
import { _BALANCE_CHAIN_GROUP, _PURE_EVM_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
13
|
+
import { _checkSmartContractSupportByChain, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible, _isPureEvmChain, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
14
|
import { categoryAddresses, sumBN } from '@subwallet/extension-base/utils';
|
|
14
15
|
import { BN, BN_ZERO } from '@polkadot/util';
|
|
15
|
-
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
16
16
|
// main subscription
|
|
17
17
|
export function subscribeBalance(addresses, chainInfoMap, substrateApiMap, evmApiMap, callback) {
|
|
18
18
|
const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
|
|
@@ -95,11 +95,16 @@ async function subscribeWithSystemAccountPallet(addresses, chainInfo, networkAPI
|
|
|
95
95
|
let pooledStakingBalance = BN_ZERO;
|
|
96
96
|
if (_isSubstrateRelayChain(chainInfo) && networkAPI.query.nominationPools) {
|
|
97
97
|
const poolMemberDatas = await networkAPI.query.nominationPools.poolMembers.multi(addresses);
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
if (poolMemberDatas) {
|
|
99
|
+
for (const _poolMemberData of poolMemberDatas) {
|
|
100
|
+
const poolMemberData = _poolMemberData.toPrimitive();
|
|
101
|
+
if (poolMemberData) {
|
|
102
|
+
const pooledBalance = new BN(poolMemberData.points.toString());
|
|
103
|
+
pooledStakingBalance = pooledStakingBalance.add(pooledBalance);
|
|
104
|
+
Object.entries(poolMemberData.unbondingEras).forEach(([, amount]) => {
|
|
105
|
+
pooledStakingBalance = pooledStakingBalance.add(new BN(amount));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
}
|
|
@@ -120,7 +125,7 @@ async function subscribeWithSystemAccountPallet(addresses, chainInfo, networkAPI
|
|
|
120
125
|
const free = total.sub(locked);
|
|
121
126
|
callBack({
|
|
122
127
|
tokenSlug: chainNativeTokenSlug,
|
|
123
|
-
free: free.toString(),
|
|
128
|
+
free: free.gte(BN_ZERO) ? free.toString() : '0',
|
|
124
129
|
locked: locked.toString(),
|
|
125
130
|
state: APIItemState.READY,
|
|
126
131
|
substrateInfo: {
|
|
@@ -134,79 +139,6 @@ async function subscribeWithSystemAccountPallet(addresses, chainInfo, networkAPI
|
|
|
134
139
|
unsub();
|
|
135
140
|
};
|
|
136
141
|
}
|
|
137
|
-
|
|
138
|
-
// deprecated
|
|
139
|
-
// function subscribeDarwiniaBalance (addresses: string[], chainInfo: _ChainInfo, chain: string, networkAPI: ApiPromise, callBack: (rs: BalanceItem) => void) {
|
|
140
|
-
// const tokenMap = state.getAssetByChainAndAsset(chain, [_AssetType.LOCAL]);
|
|
141
|
-
// const nativeTokenSlug = _getChainNativeTokenSlug(chainInfo);
|
|
142
|
-
//
|
|
143
|
-
// let totalBalance: BN = new BN(0);
|
|
144
|
-
// let freeBalance: BN = new BN(0);
|
|
145
|
-
// let miscFrozen: BN = new BN(0);
|
|
146
|
-
// let reservedKtonBalance: BN = new BN(0);
|
|
147
|
-
// let totalKtonBalance: BN = new BN(0);
|
|
148
|
-
//
|
|
149
|
-
// const unsubProms = addresses.map((address) => {
|
|
150
|
-
// return networkAPI.derive.balances?.all(address, async (balance: DeriveBalancesAll) => {
|
|
151
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
152
|
-
// freeBalance = freeBalance.add(balance.availableBalance?.toBn() || new BN(0));
|
|
153
|
-
// miscFrozen = miscFrozen.add(balance.lockedBalance?.toBn() || new BN(0));
|
|
154
|
-
// totalBalance = totalBalance.add(balance.freeBalance?.toBn() || new BN(0));
|
|
155
|
-
//
|
|
156
|
-
// const _systemBalance = await networkAPI.query.system.account(address);
|
|
157
|
-
// const systemBalance = _systemBalance.toHuman() as unknown as AccountInfo;
|
|
158
|
-
//
|
|
159
|
-
// // @ts-ignore
|
|
160
|
-
// const rawTotalKton = (systemBalance.data?.freeKton as string).replaceAll(',', '');
|
|
161
|
-
// // @ts-ignore
|
|
162
|
-
// const rawReservedKton = (systemBalance.data?.reservedKton as string).replaceAll(',', '');
|
|
163
|
-
//
|
|
164
|
-
// // @ts-ignore
|
|
165
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
166
|
-
// totalKtonBalance = totalKtonBalance.add(new BN(rawTotalKton) || new BN(0));
|
|
167
|
-
// // @ts-ignore
|
|
168
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
169
|
-
// reservedKtonBalance = reservedKtonBalance.add(new BN(rawReservedKton) || new BN(0));
|
|
170
|
-
//
|
|
171
|
-
// if (Object.keys(tokenMap).length > 1) {
|
|
172
|
-
// for (const tokenInfo of Object.values(tokenMap)) {
|
|
173
|
-
// if (_BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol)) {
|
|
174
|
-
// const freeKton = totalKtonBalance.sub(reservedKtonBalance);
|
|
175
|
-
//
|
|
176
|
-
// callBack({
|
|
177
|
-
// free: freeKton.toString(),
|
|
178
|
-
// locked: reservedKtonBalance.toString(),
|
|
179
|
-
// state: APIItemState.READY,
|
|
180
|
-
// tokenSlug: tokenInfo.slug
|
|
181
|
-
// });
|
|
182
|
-
// break;
|
|
183
|
-
// }
|
|
184
|
-
// }
|
|
185
|
-
// }
|
|
186
|
-
//
|
|
187
|
-
// const free = totalBalance.sub(miscFrozen);
|
|
188
|
-
//
|
|
189
|
-
// callBack({
|
|
190
|
-
// tokenSlug: nativeTokenSlug,
|
|
191
|
-
// free: free.toString(),
|
|
192
|
-
// locked: miscFrozen.toString(),
|
|
193
|
-
// state: APIItemState.READY,
|
|
194
|
-
// substrateInfo: {
|
|
195
|
-
// miscFrozen: miscFrozen.toString()
|
|
196
|
-
// }
|
|
197
|
-
// });
|
|
198
|
-
// });
|
|
199
|
-
// });
|
|
200
|
-
//
|
|
201
|
-
// return () => {
|
|
202
|
-
// Promise.all(unsubProms).then((unsubs) => {
|
|
203
|
-
// unsubs.forEach((unsub) => {
|
|
204
|
-
// unsub && unsub();
|
|
205
|
-
// });
|
|
206
|
-
// }).catch(console.error);
|
|
207
|
-
// };
|
|
208
|
-
// }
|
|
209
|
-
|
|
210
142
|
function subscribeERC20Interval(addresses, chain, evmApiMap, callBack) {
|
|
211
143
|
let tokenList = {};
|
|
212
144
|
const erc20ContractMap = {};
|
|
@@ -250,10 +182,12 @@ function subscribePSP22Balance(addresses, chain, api, callBack) {
|
|
|
250
182
|
try {
|
|
251
183
|
const contract = psp22ContractMap[tokenInfo.slug];
|
|
252
184
|
const balances = await Promise.all(addresses.map(async address => {
|
|
185
|
+
var _balanceOf$output;
|
|
253
186
|
const _balanceOf = await contract.query['psp22::balanceOf'](address, {
|
|
254
|
-
gasLimit:
|
|
187
|
+
gasLimit: getDefaultWeightV2(api)
|
|
255
188
|
}, address);
|
|
256
|
-
|
|
189
|
+
const balanceObj = _balanceOf === null || _balanceOf === void 0 ? void 0 : (_balanceOf$output = _balanceOf.output) === null || _balanceOf$output === void 0 ? void 0 : _balanceOf$output.toPrimitive();
|
|
190
|
+
return _balanceOf.output ? balanceObj.ok || balanceObj.Ok : '0';
|
|
257
191
|
}));
|
|
258
192
|
free = sumBN(balances.map(bal => new BN(bal || 0)));
|
|
259
193
|
callBack({
|
|
@@ -263,10 +197,11 @@ function subscribePSP22Balance(addresses, chain, api, callBack) {
|
|
|
263
197
|
state: APIItemState.READY
|
|
264
198
|
});
|
|
265
199
|
} catch (err) {
|
|
266
|
-
console.
|
|
200
|
+
console.warn('Problem fetching ' + tokenInfo.slug + ' PSP-22 token balance', err); // TODO: error createType
|
|
267
201
|
}
|
|
268
202
|
});
|
|
269
203
|
};
|
|
204
|
+
|
|
270
205
|
tokenList = state.getAssetByChainAndAsset(chain, [_AssetType.PSP22]);
|
|
271
206
|
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
272
207
|
psp22ContractMap[slug] = getPSP22ContractPromise(api, _getContractAddressOfToken(tokenInfo));
|
|
@@ -396,11 +331,11 @@ async function subscribeAssetsAccountPallet(addresses, chain, api, callBack) {
|
|
|
396
331
|
balances.forEach(b => {
|
|
397
332
|
// @ts-ignore
|
|
398
333
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
|
|
399
|
-
const bdata = b === null || b === void 0 ? void 0 : b.
|
|
334
|
+
const bdata = b === null || b === void 0 ? void 0 : b.toHuman();
|
|
400
335
|
if (bdata) {
|
|
401
336
|
// @ts-ignore
|
|
402
337
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
|
|
403
|
-
const addressBalance = new BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance) || '0');
|
|
338
|
+
const addressBalance = new BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0');
|
|
404
339
|
|
|
405
340
|
// @ts-ignore
|
|
406
341
|
if (bdata !== null && bdata !== void 0 && bdata.isFrozen) {
|
|
@@ -454,114 +389,4 @@ export function subscribeEVMBalance(chain, addresses, evmApiMap, callback, token
|
|
|
454
389
|
clearInterval(interval);
|
|
455
390
|
unsub2 && unsub2();
|
|
456
391
|
};
|
|
457
|
-
}
|
|
458
|
-
export async function getFreeBalance(chain, address, substrateApiMap, evmApiMap, tokenSlug) {
|
|
459
|
-
const substrateApi = await substrateApiMap[chain].isReady;
|
|
460
|
-
const api = substrateApi.api;
|
|
461
|
-
const web3Api = evmApiMap[chain];
|
|
462
|
-
const tokenInfo = tokenSlug ? state.getAssetBySlug(tokenSlug) : state.getNativeTokenInfo(chain);
|
|
463
|
-
const chainInfo = state.getChainInfo(chain);
|
|
464
|
-
|
|
465
|
-
// Only EVM Address use with EVM network
|
|
466
|
-
if (Boolean(web3Api || _isChainEvmCompatible(chainInfo)) !== isEthereumAddress(address)) {
|
|
467
|
-
if (!isEthereumAddress(address)) {
|
|
468
|
-
return '0';
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// web3Api support mean isEthereum Network support
|
|
473
|
-
if (web3Api) {
|
|
474
|
-
if (_isNativeToken(tokenInfo)) {
|
|
475
|
-
var _web3Api$api;
|
|
476
|
-
return (await ((_web3Api$api = web3Api.api) === null || _web3Api$api === void 0 ? void 0 : _web3Api$api.eth.getBalance(address))) || '0';
|
|
477
|
-
} else {
|
|
478
|
-
if (_getContractAddressOfToken(tokenInfo).length > 0) {
|
|
479
|
-
return '0';
|
|
480
|
-
}
|
|
481
|
-
const contract = getERC20Contract(chain, _getContractAddressOfToken(tokenInfo), evmApiMap);
|
|
482
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
483
|
-
const free = await contract.methods.balanceOf(address).call();
|
|
484
|
-
|
|
485
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
|
|
486
|
-
return (free === null || free === void 0 ? void 0 : free.toString()) || '0';
|
|
487
|
-
}
|
|
488
|
-
} else {
|
|
489
|
-
var _balance$availableBal, _balance$availableBal2;
|
|
490
|
-
if (tokenSlug) {
|
|
491
|
-
if (_isSmartContractToken(tokenInfo)) {
|
|
492
|
-
if (_getContractAddressOfToken(tokenInfo).length > 0) {
|
|
493
|
-
return '0';
|
|
494
|
-
}
|
|
495
|
-
const contractPromise = getPSP22ContractPromise(api, _getContractAddressOfToken(tokenInfo));
|
|
496
|
-
const balanceOf = await contractPromise.query['psp22::balanceOf'](address, {
|
|
497
|
-
gasLimit: -1
|
|
498
|
-
}, address);
|
|
499
|
-
return balanceOf.output ? balanceOf.output.toString() : '0';
|
|
500
|
-
} else if (_BALANCE_CHAIN_GROUP.genshiro.includes(chain)) {
|
|
501
|
-
var _balance$asPositive;
|
|
502
|
-
const onChainInfo = _getTokenOnChainInfo(tokenInfo);
|
|
503
|
-
const balance = await api.query.eqBalances.account(address, onChainInfo);
|
|
504
|
-
|
|
505
|
-
// @ts-ignore
|
|
506
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
|
507
|
-
return ((_balance$asPositive = balance.asPositive) === null || _balance$asPositive === void 0 ? void 0 : _balance$asPositive.toString()) || '0';
|
|
508
|
-
} else if (_BALANCE_CHAIN_GROUP.equilibrium_parachain.includes(chain)) {
|
|
509
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
510
|
-
const balance = await api.query.system.account(address);
|
|
511
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
512
|
-
const balancesData = JSON.parse(balance.data.toString());
|
|
513
|
-
const balanceList = balancesData.v0.balance;
|
|
514
|
-
let freeTokenBalance;
|
|
515
|
-
const assetId = _getTokenOnChainAssetId(tokenInfo);
|
|
516
|
-
if (!_isNativeToken(tokenInfo)) {
|
|
517
|
-
// @ts-ignore
|
|
518
|
-
freeTokenBalance = balanceList.find(data => data[0] === assetId);
|
|
519
|
-
} else {
|
|
520
|
-
freeTokenBalance = balanceList[0];
|
|
521
|
-
}
|
|
522
|
-
return freeTokenBalance ? freeTokenBalance[1].positive.toString() : '0';
|
|
523
|
-
} else if (_BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol)) {
|
|
524
|
-
var _balance$data5, _balance$data5$freeKt;
|
|
525
|
-
// @ts-ignore
|
|
526
|
-
const balance = await api.query.system.account(address);
|
|
527
|
-
return ((_balance$data5 = balance.data) === null || _balance$data5 === void 0 ? void 0 : (_balance$data5$freeKt = _balance$data5.freeKton) === null || _balance$data5$freeKt === void 0 ? void 0 : _balance$data5$freeKt.toString()) || '0';
|
|
528
|
-
} else if (!_isNativeToken(tokenInfo) && _BALANCE_CHAIN_GROUP.statemine.includes(chain)) {
|
|
529
|
-
var _balanceInfo$balance;
|
|
530
|
-
const assetId = _getTokenOnChainAssetId(tokenInfo);
|
|
531
|
-
const balanceInfo = (await api.query.assets.account(assetId, address)).toHuman();
|
|
532
|
-
|
|
533
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
|
534
|
-
return (balanceInfo === null || balanceInfo === void 0 ? void 0 : (_balanceInfo$balance = balanceInfo.balance) === null || _balanceInfo$balance === void 0 ? void 0 : _balanceInfo$balance.replaceAll(',', '')) || '0';
|
|
535
|
-
} else if (!_isNativeToken(tokenInfo) || _BALANCE_CHAIN_GROUP.kintsugi.includes(chain)) {
|
|
536
|
-
var _balance$free;
|
|
537
|
-
const onChainInfo = _getTokenOnChainInfo(tokenInfo);
|
|
538
|
-
// @ts-ignore
|
|
539
|
-
const balance = await api.query.tokens.accounts(address, onChainInfo);
|
|
540
|
-
return ((_balance$free = balance.free) === null || _balance$free === void 0 ? void 0 : _balance$free.toString()) || '0';
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
if (_BALANCE_CHAIN_GROUP.kusama.includes(chain)) {
|
|
544
|
-
var _balance$data6, _balance$data7;
|
|
545
|
-
// @ts-ignore
|
|
546
|
-
const _balance = await api.query.system.account(address);
|
|
547
|
-
|
|
548
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
549
|
-
const balance = _balance.toHuman();
|
|
550
|
-
|
|
551
|
-
// @ts-ignore
|
|
552
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
553
|
-
const freeBalance = new BN((_balance$data6 = balance.data) === null || _balance$data6 === void 0 ? void 0 : _balance$data6.free.replaceAll(',', ''));
|
|
554
|
-
|
|
555
|
-
// @ts-ignore
|
|
556
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
557
|
-
const miscFrozen = new BN((_balance$data7 = balance.data) === null || _balance$data7 === void 0 ? void 0 : _balance$data7.miscFrozen.replaceAll(',', ''));
|
|
558
|
-
const transferable = freeBalance.sub(miscFrozen);
|
|
559
|
-
|
|
560
|
-
// @ts-ignore
|
|
561
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
|
562
|
-
return transferable.toString() || '0';
|
|
563
|
-
}
|
|
564
|
-
const balance = await api.derive.balances.all(address);
|
|
565
|
-
return ((_balance$availableBal = balance.availableBalance) === null || _balance$availableBal === void 0 ? void 0 : (_balance$availableBal2 = _balance$availableBal.toBn()) === null || _balance$availableBal2 === void 0 ? void 0 : _balance$availableBal2.toString()) || '0';
|
|
566
|
-
}
|
|
567
392
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
|
|
5
|
+
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
5
6
|
import { _BALANCE_TOKEN_GROUP, _TRANSFER_CHAIN_GROUP, _TRANSFER_NOT_SUPPORTED_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
7
|
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible, _isNativeToken, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
8
|
import { BN } from '@polkadot/util';
|
|
@@ -104,10 +105,10 @@ export const createTransferExtrinsic = async ({
|
|
|
104
105
|
|
|
105
106
|
if (_isTokenWasmSmartContract(tokenInfo) && api.query.contracts) {
|
|
106
107
|
const contractPromise = getPSP22ContractPromise(api, _getContractAddressOfToken(tokenInfo));
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
const gasLimit = await getWasmContractGasLimit(api, from, 'psp22::transfer', contractPromise, {}, [from, value, {}]);
|
|
110
|
+
|
|
111
|
+
// @ts-ignore
|
|
111
112
|
transfer = contractPromise.tx['psp22::transfer']({
|
|
112
113
|
gasLimit
|
|
113
114
|
}, to, value, {});
|
|
@@ -110,8 +110,10 @@ export class AcalaNftApi extends BaseNftApi {
|
|
|
110
110
|
};
|
|
111
111
|
params.updateItem(this.chain, parsedNft, address);
|
|
112
112
|
params.updateCollection(this.chain, parsedCollection);
|
|
113
|
-
// params.updateReady(true);
|
|
114
113
|
}));
|
|
114
|
+
Object.entries(collectionNftIds).forEach(([collectionId, nftIds]) => {
|
|
115
|
+
params.cleanUpNfts(this.chain, address, collectionId, nftIds);
|
|
116
|
+
});
|
|
115
117
|
} catch (e) {
|
|
116
118
|
console.error('Failed to fetch acala nft', e);
|
|
117
119
|
}
|
|
@@ -107,8 +107,10 @@ export class BitCountryNftApi extends BaseNftApi {
|
|
|
107
107
|
};
|
|
108
108
|
params.updateItem(this.chain, parsedNft, address);
|
|
109
109
|
params.updateCollection(this.chain, parsedCollection);
|
|
110
|
-
// params.updateReady(true);
|
|
111
110
|
}));
|
|
111
|
+
Object.entries(collectionNftIds).forEach(([collectionId, nftIds]) => {
|
|
112
|
+
params.cleanUpNfts(this.chain, address, collectionId, nftIds);
|
|
113
|
+
});
|
|
112
114
|
} catch (e) {
|
|
113
115
|
console.error('Failed to fetch bit.country nft', e);
|
|
114
116
|
}
|
|
@@ -75,6 +75,7 @@ export class EvmNftApi extends BaseNftApi {
|
|
|
75
75
|
const contract = new this.evmApi.api.eth.Contract(_ERC721_ABI, smartContract);
|
|
76
76
|
let ownItem = false;
|
|
77
77
|
let collectionImage;
|
|
78
|
+
const nftOwnerMap = {};
|
|
78
79
|
await Promise.all(this.addresses.map(async address => {
|
|
79
80
|
if (!isEthereumAddress(address)) {
|
|
80
81
|
return;
|
|
@@ -125,8 +126,9 @@ export class EvmNftApi extends BaseNftApi {
|
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
}));
|
|
129
|
+
nftOwnerMap[address] = nftIds;
|
|
128
130
|
} catch (e) {
|
|
129
|
-
console.error('
|
|
131
|
+
console.error('EVM NFT error', e);
|
|
130
132
|
}
|
|
131
133
|
}));
|
|
132
134
|
if (ownItem) {
|
|
@@ -138,10 +140,11 @@ export class EvmNftApi extends BaseNftApi {
|
|
|
138
140
|
originAsset: tokenInfo.slug
|
|
139
141
|
};
|
|
140
142
|
nftParams.updateCollection(this.chain, nftCollection);
|
|
141
|
-
|
|
143
|
+
Object.entries(nftOwnerMap).forEach(([owner, nftIds]) => {
|
|
144
|
+
nftParams.cleanUpNfts(this.chain, owner, smartContract, nftIds);
|
|
145
|
+
});
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
|
-
|
|
145
148
|
async handleNfts(params) {
|
|
146
149
|
if (!this.evmContracts || this.evmContracts.length === 0) {
|
|
147
150
|
return;
|
package/koni/api/nft/index.d.ts
CHANGED
|
@@ -17,6 +17,5 @@ export declare class NftHandler {
|
|
|
17
17
|
setAddresses(addresses: string[]): void;
|
|
18
18
|
private setupNftContracts;
|
|
19
19
|
private setupApi;
|
|
20
|
-
handleNfts(nftContracts: _ChainAsset[], updateItem: (chain: string, data: NftItem, owner: string) => void, updateCollection: (chain: string, data: NftCollection) => void): Promise<void>;
|
|
21
|
-
parseAssetId(id: string): string;
|
|
20
|
+
handleNfts(nftContracts: _ChainAsset[], updateItem: (chain: string, data: NftItem, owner: string) => void, updateCollection: (chain: string, data: NftCollection) => void, cleanUpNfts: (chain: string, owner: string, collectionId: string, nftIds: string[]) => void): Promise<void>;
|
|
22
21
|
}
|
package/koni/api/nft/index.js
CHANGED
|
@@ -124,18 +124,15 @@ export class NftHandler {
|
|
|
124
124
|
console.error('error setting up nft handlers', e);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
async handleNfts(nftContracts, updateItem, updateCollection) {
|
|
127
|
+
async handleNfts(nftContracts, updateItem, updateCollection, cleanUpNfts) {
|
|
128
128
|
this.setupApi();
|
|
129
129
|
this.setupNftContracts(nftContracts);
|
|
130
130
|
await Promise.all(this.handlers.map(async handler => {
|
|
131
131
|
await handler.fetchNfts({
|
|
132
132
|
updateItem,
|
|
133
|
-
updateCollection
|
|
133
|
+
updateCollection,
|
|
134
|
+
cleanUpNfts
|
|
134
135
|
});
|
|
135
136
|
}));
|
|
136
137
|
}
|
|
137
|
-
parseAssetId(id) {
|
|
138
|
-
const numberId = parseInt(id);
|
|
139
|
-
return numberId.toString();
|
|
140
|
-
}
|
|
141
138
|
}
|
|
@@ -114,8 +114,10 @@ export class KaruraNftApi extends BaseNftApi {
|
|
|
114
114
|
};
|
|
115
115
|
params.updateItem(this.chain, parsedNft, address);
|
|
116
116
|
params.updateCollection(this.chain, parsedCollection);
|
|
117
|
-
// params.updateReady(true);
|
|
118
117
|
}));
|
|
118
|
+
Object.entries(collectionNftIds).forEach(([collectionId, nftIds]) => {
|
|
119
|
+
params.cleanUpNfts(this.chain, address, collectionId, nftIds);
|
|
120
|
+
});
|
|
119
121
|
} catch (e) {
|
|
120
122
|
console.error('Failed to fetch karura nft', e);
|
|
121
123
|
}
|
package/koni/api/nft/nft.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain
|
|
|
3
3
|
export interface HandleNftParams {
|
|
4
4
|
updateItem: (chain: string, data: NftItem, owner: string) => void;
|
|
5
5
|
updateCollection: (chain: string, data: NftCollection) => void;
|
|
6
|
+
cleanUpNfts: (chain: string, owner: string, collectionId: string, nftIds: string[]) => void;
|
|
6
7
|
}
|
|
7
8
|
export declare abstract class BaseNftApi {
|
|
8
9
|
chain: string;
|
|
@@ -231,8 +231,15 @@ export class RmrkNftApi extends BaseNftApi {
|
|
|
231
231
|
image: allCollectionMeta[item.collectionId] ? this.parseUrl(allCollectionMeta[item.collectionId].image) : null,
|
|
232
232
|
chain: this.chain
|
|
233
233
|
};
|
|
234
|
+
const nftIds = [];
|
|
235
|
+
allNfts.forEach(nft => {
|
|
236
|
+
const nftCollectionId = nft === null || nft === void 0 ? void 0 : nft.collectionId;
|
|
237
|
+
if (nftCollectionId === item.collectionId) {
|
|
238
|
+
nftIds.push(nft === null || nft === void 0 ? void 0 : nft.id);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
234
241
|
params.updateCollection(this.chain, parsedCollection);
|
|
235
|
-
|
|
242
|
+
params.cleanUpNfts(this.chain, address, item.collectionId, nftIds);
|
|
236
243
|
});
|
|
237
244
|
} catch (e) {
|
|
238
245
|
console.error('Failed to fetch rmrk nft', e);
|
|
@@ -115,8 +115,10 @@ export default class StatemineNftApi extends BaseNftApi {
|
|
|
115
115
|
image: collectionMeta && collectionMeta.image ? this.parseUrl(collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image) : undefined
|
|
116
116
|
};
|
|
117
117
|
params.updateCollection(this.chain, parsedCollection);
|
|
118
|
-
// params.updateReady(true);
|
|
119
118
|
}));
|
|
119
|
+
Object.entries(collectionNftIds).forEach(([collectionId, nftIds]) => {
|
|
120
|
+
params.cleanUpNfts(this.chain, address, collectionId, nftIds);
|
|
121
|
+
});
|
|
120
122
|
} catch (e) {
|
|
121
123
|
console.error('Failed to fetch statemine nft', e);
|
|
122
124
|
}
|
|
@@ -133,6 +133,7 @@ export default class UniqueNftApi extends BaseNftApi {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
}));
|
|
136
|
+
const nftCollectionMap = {};
|
|
136
137
|
await Promise.all(allCollectionId.map(async collectionId => {
|
|
137
138
|
const collectionIdStr = collectionId.toString();
|
|
138
139
|
|
|
@@ -140,6 +141,7 @@ export default class UniqueNftApi extends BaseNftApi {
|
|
|
140
141
|
const collection = (await this.substrateApi.api.query.nft.collectionById(collectionId)).toJSON();
|
|
141
142
|
collectionMap[collectionIdStr] = collection;
|
|
142
143
|
const nftIds = Object.entries(nftMap).filter(item => item[1] === collectionId).map(item => item[0]);
|
|
144
|
+
nftCollectionMap[collectionIdStr] = nftIds;
|
|
143
145
|
const parsedCollection = {
|
|
144
146
|
collectionId: collectionIdStr,
|
|
145
147
|
chain: this.chain
|
|
@@ -166,10 +168,12 @@ export default class UniqueNftApi extends BaseNftApi {
|
|
|
166
168
|
}
|
|
167
169
|
params.updateItem(this.chain, parsedItem, address);
|
|
168
170
|
params.updateCollection(this.chain, parsedCollection);
|
|
169
|
-
// params.updateReady(true);
|
|
170
171
|
}
|
|
171
172
|
}));
|
|
172
173
|
}));
|
|
174
|
+
Object.entries(nftCollectionMap).forEach(([collectionId, nftIds]) => {
|
|
175
|
+
params.cleanUpNfts(this.chain, address, collectionId, nftIds);
|
|
176
|
+
});
|
|
173
177
|
} catch (e) {
|
|
174
178
|
console.error('Failed to fetch unique nft', e);
|
|
175
179
|
}
|
|
@@ -8,8 +8,6 @@ export declare class WasmNftApi extends BaseNftApi {
|
|
|
8
8
|
private parseFeaturedTokenUri;
|
|
9
9
|
private parseFeaturedNftImage;
|
|
10
10
|
private parseFeaturedCollectionImage;
|
|
11
|
-
private getCollectionAttributes;
|
|
12
|
-
private processOnChainMetadata;
|
|
13
11
|
private processOffChainMetadata;
|
|
14
12
|
private getItemsByCollection;
|
|
15
13
|
fetchNfts(params: HandleNftParams): Promise<number>;
|