@subwallet/extension-base 1.1.2-0 → 1.1.3-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +32 -4
- package/background/KoniTypes.js +2 -1
- package/cjs/background/KoniTypes.js +4 -2
- package/cjs/constants/i18n.js +10 -2
- package/cjs/koni/api/dotsama/transfer.js +6 -2
- package/cjs/koni/api/nft/acala_nft/index.js +0 -2
- package/cjs/koni/api/nft/bit.country/index.js +49 -18
- package/cjs/koni/api/nft/config.js +5 -3
- package/cjs/koni/api/nft/evm_nft/index.js +0 -5
- package/cjs/koni/api/nft/index.js +2 -3
- package/cjs/koni/api/nft/karura_nft/index.js +0 -2
- package/cjs/koni/api/nft/rmrk_nft/index.js +0 -4
- package/cjs/koni/api/nft/statemine_nft/index.js +0 -2
- package/cjs/koni/api/nft/unique_nft/index.js +0 -5
- package/cjs/koni/api/nft/wasm_nft/index.js +0 -5
- package/cjs/koni/api/staking/bonding/amplitude.js +6 -6
- package/cjs/koni/api/staking/bonding/astar.js +6 -6
- package/cjs/koni/api/staking/bonding/paraChain.js +5 -5
- package/cjs/koni/api/staking/bonding/relayChain.js +24 -14
- package/cjs/koni/api/staking/bonding/utils.js +1 -7
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/background/cron.js +2 -37
- package/cjs/koni/background/handlers/Extension.js +206 -137
- package/cjs/koni/background/handlers/State.js +72 -84
- package/cjs/koni/background/subscription.js +6 -88
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +8 -5
- package/cjs/services/chain-service/handler/SubstrateApi.js +8 -0
- package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +1 -1
- package/cjs/services/chain-service/handler/manta/manta-extension-sdk-empty.js +13 -0
- package/cjs/services/chain-service/index.js +11 -6
- package/cjs/services/request-service/handler/PopupHandler.js +2 -2
- package/cjs/services/request-service/helper/index.js +2 -26
- package/cjs/services/setting-service/constants.js +16 -6
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/storage-service/db-stores/Metadata.js +1 -1
- package/cjs/services/storage-service/db-stores/Nft.js +3 -0
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -2
- package/cjs/services/wallet-connect-service/constants.js +8 -5
- package/cjs/services/wallet-connect-service/index.js +50 -36
- package/cjs/utils/environment.js +32 -2
- package/cjs/utils/index.js +33 -5
- package/cjs/utils/registry.js +25 -0
- package/cjs/utils/translate.js +11 -0
- package/constants/i18n.d.ts +2 -1
- package/constants/i18n.js +8 -1
- package/koni/api/dotsama/transfer.js +6 -2
- package/koni/api/nft/acala_nft/index.js +0 -2
- package/koni/api/nft/bit.country/index.d.ts +1 -0
- package/koni/api/nft/bit.country/index.js +50 -19
- package/koni/api/nft/config.d.ts +2 -1
- package/koni/api/nft/config.js +2 -1
- package/koni/api/nft/evm_nft/index.js +0 -4
- package/koni/api/nft/index.d.ts +1 -1
- package/koni/api/nft/index.js +2 -3
- package/koni/api/nft/karura_nft/index.js +0 -2
- package/koni/api/nft/nft.d.ts +0 -1
- package/koni/api/nft/rmrk_nft/index.js +0 -4
- package/koni/api/nft/statemine_nft/index.js +0 -2
- package/koni/api/nft/unique_nft/index.js +0 -5
- package/koni/api/nft/wasm_nft/index.js +0 -4
- package/koni/api/staking/bonding/amplitude.js +6 -6
- package/koni/api/staking/bonding/astar.js +6 -6
- package/koni/api/staking/bonding/paraChain.js +5 -5
- package/koni/api/staking/bonding/relayChain.js +24 -14
- package/koni/api/staking/bonding/utils.js +1 -7
- package/koni/api/xcm/xTokens.js +1 -1
- package/koni/background/cron.d.ts +0 -5
- package/koni/background/cron.js +4 -39
- package/koni/background/handlers/Extension.d.ts +4 -0
- package/koni/background/handlers/Extension.js +97 -32
- package/koni/background/handlers/State.d.ts +8 -7
- package/koni/background/handlers/State.js +72 -84
- package/koni/background/subscription.d.ts +1 -4
- package/koni/background/subscription.js +9 -88
- package/package.json +22 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +2 -0
- package/services/chain-service/constants.js +8 -5
- package/services/chain-service/handler/SubstrateApi.js +8 -0
- package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +1 -1
- package/services/chain-service/handler/manta/MantaPrivateHandler.js +1 -1
- package/services/chain-service/handler/manta/manta-extension-sdk-empty.d.ts +4 -0
- package/services/chain-service/handler/manta/manta-extension-sdk-empty.js +5 -0
- package/services/chain-service/index.d.ts +2 -1
- package/services/chain-service/index.js +11 -6
- package/services/request-service/handler/PopupHandler.js +1 -1
- package/services/request-service/helper/index.d.ts +0 -2
- package/services/request-service/helper/index.js +0 -23
- package/services/request-service/types.d.ts +0 -1
- package/services/setting-service/constants.d.ts +6 -1
- package/services/setting-service/constants.js +10 -5
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/storage-service/db-stores/Metadata.js +1 -1
- package/services/storage-service/db-stores/Nft.d.ts +1 -0
- package/services/storage-service/db-stores/Nft.js +3 -0
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -2
- package/services/wallet-connect-service/constants.d.ts +2 -1
- package/services/wallet-connect-service/constants.js +5 -3
- package/services/wallet-connect-service/index.d.ts +0 -1
- package/services/wallet-connect-service/index.js +50 -36
- package/utils/environment.d.ts +4 -1
- package/utils/environment.js +28 -1
- package/utils/index.d.ts +3 -0
- package/utils/index.js +6 -2
- package/utils/registry.d.ts +4 -0
- package/utils/registry.js +18 -0
- package/utils/translate.d.ts +1 -0
- package/utils/translate.js +4 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { BIT_COUNTRY_IPFS_SERVER, BIT_COUNTRY_LAND_ESTATE_METADATA_API } from '@subwallet/extension-base/koni/api/nft/config';
|
|
5
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
6
6
|
import { isUrl } from '@subwallet/extension-base/utils';
|
|
7
7
|
import fetch from 'cross-fetch';
|
|
8
|
+
import { BN_ZERO, hexToBn } from '@polkadot/util';
|
|
8
9
|
export class BitCountryNftApi extends BaseNftApi {
|
|
9
10
|
constructor(api, addresses, chain) {
|
|
10
11
|
super(chain, api, addresses);
|
|
@@ -17,9 +18,9 @@ export class BitCountryNftApi extends BaseNftApi {
|
|
|
17
18
|
return input;
|
|
18
19
|
}
|
|
19
20
|
if (!input.includes('ipfs://')) {
|
|
20
|
-
return
|
|
21
|
+
return BIT_COUNTRY_IPFS_SERVER + input;
|
|
21
22
|
}
|
|
22
|
-
return
|
|
23
|
+
return BIT_COUNTRY_IPFS_SERVER + input.split('ipfs://')[1];
|
|
23
24
|
}
|
|
24
25
|
async getNfts(addresses) {
|
|
25
26
|
if (!this.substrateApi) {
|
|
@@ -48,7 +49,13 @@ export class BitCountryNftApi extends BaseNftApi {
|
|
|
48
49
|
if (!onChainMeta.metadata) {
|
|
49
50
|
return null;
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
|
|
53
|
+
// check if NFT is Land/Estate
|
|
54
|
+
if (onChainMeta.data.attributes['MetaverseId:']) {
|
|
55
|
+
return await fetch(`${BIT_COUNTRY_LAND_ESTATE_METADATA_API}/${assetId.classId}/${assetId.tokenId}/metadata.json`).then(resp => resp.json());
|
|
56
|
+
} else {
|
|
57
|
+
return await fetch(BIT_COUNTRY_IPFS_SERVER + onChainMeta.metadata).then(resp => resp.json());
|
|
58
|
+
}
|
|
52
59
|
}
|
|
53
60
|
async getCollectionDetails(collectionId) {
|
|
54
61
|
if (!this.substrateApi) {
|
|
@@ -58,7 +65,41 @@ export class BitCountryNftApi extends BaseNftApi {
|
|
|
58
65
|
if (!metadataCollection.metadata) {
|
|
59
66
|
return null;
|
|
60
67
|
}
|
|
61
|
-
|
|
68
|
+
if (metadataCollection.data.attributes['MetaverseId:']) {
|
|
69
|
+
const category = metadataCollection.data.attributes['Category:'];
|
|
70
|
+
const hexMetaverseId = metadataCollection.data.attributes['MetaverseId:'];
|
|
71
|
+
let metaverseId = BN_ZERO;
|
|
72
|
+
try {
|
|
73
|
+
metaverseId = hexToBn(hexMetaverseId);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.warn('Error parsing metaverse id', e);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
name: `${category} #${collectionId}`,
|
|
79
|
+
metaverseId: metaverseId.toString()
|
|
80
|
+
};
|
|
81
|
+
} else {
|
|
82
|
+
return await fetch(BIT_COUNTRY_IPFS_SERVER + metadataCollection.metadata).then(resp => resp.json());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
parseMetadata(data) {
|
|
86
|
+
const traitList = data !== null && data !== void 0 && data.traits ? data.traits : data === null || data === void 0 ? void 0 : data.attributes;
|
|
87
|
+
const propertiesMap = {};
|
|
88
|
+
if (traitList) {
|
|
89
|
+
traitList.forEach(traitMap => {
|
|
90
|
+
propertiesMap[traitMap.trait_type] = {
|
|
91
|
+
value: traitMap.value
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
name: data === null || data === void 0 ? void 0 : data.name,
|
|
97
|
+
image: data !== null && data !== void 0 && data.image_url ? this.parseUrl(data.image_url) : this.parseUrl(data === null || data === void 0 ? void 0 : data.image),
|
|
98
|
+
description: data === null || data === void 0 ? void 0 : data.description,
|
|
99
|
+
properties: propertiesMap,
|
|
100
|
+
externalUrl: data === null || data === void 0 ? void 0 : data.external_url,
|
|
101
|
+
chain: this.chain
|
|
102
|
+
};
|
|
62
103
|
}
|
|
63
104
|
async fetchNfts(params) {
|
|
64
105
|
try {
|
|
@@ -73,7 +114,6 @@ export class BitCountryNftApi extends BaseNftApi {
|
|
|
73
114
|
const assetIds = await this.getNfts([address]);
|
|
74
115
|
try {
|
|
75
116
|
if (!assetIds || assetIds.length === 0) {
|
|
76
|
-
params.cleanUpNfts(this.chain, address, [], [], true);
|
|
77
117
|
return;
|
|
78
118
|
}
|
|
79
119
|
const collectionIds = [];
|
|
@@ -86,18 +126,10 @@ export class BitCountryNftApi extends BaseNftApi {
|
|
|
86
126
|
}
|
|
87
127
|
nftIds.push(parsedTokenId);
|
|
88
128
|
const [tokenInfo, collectionMeta] = await Promise.all([this.getTokenDetails(assetId), this.getCollectionDetails(parsedClassId)]);
|
|
89
|
-
const parsedNft =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
|
|
94
|
-
description: tokenInfo && tokenInfo.description ? tokenInfo.description : collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.description,
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
96
|
-
image: tokenInfo && tokenInfo.image_url ? this.parseUrl(tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.image_url) : this.parseUrl(collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image_url),
|
|
97
|
-
collectionId: parsedClassId,
|
|
98
|
-
chain: this.chain,
|
|
99
|
-
owner: address
|
|
100
|
-
};
|
|
129
|
+
const parsedNft = this.parseMetadata(tokenInfo);
|
|
130
|
+
parsedNft.collectionId = parsedClassId;
|
|
131
|
+
parsedNft.id = parsedTokenId;
|
|
132
|
+
parsedNft.owner = address;
|
|
101
133
|
const parsedCollection = {
|
|
102
134
|
collectionId: parsedClassId,
|
|
103
135
|
chain: this.chain,
|
|
@@ -109,7 +141,6 @@ export class BitCountryNftApi extends BaseNftApi {
|
|
|
109
141
|
params.updateItem(this.chain, parsedNft, address);
|
|
110
142
|
params.updateCollection(this.chain, parsedCollection);
|
|
111
143
|
}));
|
|
112
|
-
params.cleanUpNfts(this.chain, address, collectionIds, nftIds);
|
|
113
144
|
} catch (e) {
|
|
114
145
|
console.error(`${this.chain}`, e);
|
|
115
146
|
}
|
package/koni/api/nft/config.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export declare const SINGULAR_V1_COLLECTION_ENDPOINT = "https://singular.rmrk.ap
|
|
|
6
6
|
export declare const SINGULAR_V2_COLLECTION_ENDPOINT = "https://singular.app/api/rmrk2/collection/";
|
|
7
7
|
export declare const KANARIA_EXTERNAL_SERVER = "https://kanaria.rmrk.app/catalogue/";
|
|
8
8
|
export declare const CLOUDFLARE_PINATA_SERVER = "https://cloudflare-ipfs.com/ipfs/";
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const BIT_COUNTRY_IPFS_SERVER = "https://ipfs-cdn.bit.country/";
|
|
10
|
+
export declare const BIT_COUNTRY_LAND_ESTATE_METADATA_API = "https://pioneer-api.bit.country/metadata/landTokenUriPioneer";
|
|
10
11
|
export declare const BIT_COUNTRY_THUMBNAIL_RESOLVER = "https://res.cloudinary.com/ddftctzph/image/upload/c_scale,q_100,w_250/production-ipfs/asset/";
|
|
11
12
|
export declare const CF_IPFS_GATEWAY = "https://cf-ipfs.com/ipfs/";
|
|
12
13
|
export declare const PINATA_IPFS_GATEWAY = "https://gateway.pinata.cloud/ipfs/";
|
package/koni/api/nft/config.js
CHANGED
|
@@ -10,7 +10,8 @@ export const SINGULAR_V1_COLLECTION_ENDPOINT = 'https://singular.rmrk.app/api/rm
|
|
|
10
10
|
export const SINGULAR_V2_COLLECTION_ENDPOINT = 'https://singular.app/api/rmrk2/collection/';
|
|
11
11
|
export const KANARIA_EXTERNAL_SERVER = 'https://kanaria.rmrk.app/catalogue/';
|
|
12
12
|
export const CLOUDFLARE_PINATA_SERVER = 'https://cloudflare-ipfs.com/ipfs/';
|
|
13
|
-
export const
|
|
13
|
+
export const BIT_COUNTRY_IPFS_SERVER = 'https://ipfs-cdn.bit.country/';
|
|
14
|
+
export const BIT_COUNTRY_LAND_ESTATE_METADATA_API = 'https://pioneer-api.bit.country/metadata/landTokenUriPioneer';
|
|
14
15
|
export const BIT_COUNTRY_THUMBNAIL_RESOLVER = 'https://res.cloudinary.com/ddftctzph/image/upload/c_scale,q_100,w_250/production-ipfs/asset/';
|
|
15
16
|
export const CF_IPFS_GATEWAY = 'https://cf-ipfs.com/ipfs/';
|
|
16
17
|
export const PINATA_IPFS_GATEWAY = 'https://gateway.pinata.cloud/ipfs/';
|
|
@@ -85,7 +85,6 @@ export class EvmNftApi extends BaseNftApi {
|
|
|
85
85
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
86
86
|
const balance = await contract.methods.balanceOf(address).call();
|
|
87
87
|
if (Number(balance) === 0) {
|
|
88
|
-
nftParams.cleanUpNfts(this.chain, address, [smartContract], []);
|
|
89
88
|
return;
|
|
90
89
|
}
|
|
91
90
|
const itemIndexes = [];
|
|
@@ -140,9 +139,6 @@ export class EvmNftApi extends BaseNftApi {
|
|
|
140
139
|
originAsset: tokenInfo.slug
|
|
141
140
|
};
|
|
142
141
|
nftParams.updateCollection(this.chain, nftCollection);
|
|
143
|
-
Object.entries(nftOwnerMap).forEach(([owner, nftIds]) => {
|
|
144
|
-
nftParams.cleanUpNfts(this.chain, owner, [smartContract], nftIds);
|
|
145
|
-
});
|
|
146
142
|
}
|
|
147
143
|
}
|
|
148
144
|
async handleNfts(params) {
|
package/koni/api/nft/index.d.ts
CHANGED
|
@@ -17,5 +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
|
|
20
|
+
handleNfts(nftContracts: _ChainAsset[], updateItem: (chain: string, data: NftItem, owner: string) => void, updateCollection: (chain: string, data: NftCollection) => void): Promise<void>;
|
|
21
21
|
}
|
package/koni/api/nft/index.js
CHANGED
|
@@ -123,14 +123,13 @@ export class NftHandler {
|
|
|
123
123
|
console.error(e);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
async handleNfts(nftContracts, updateItem, updateCollection
|
|
126
|
+
async handleNfts(nftContracts, updateItem, updateCollection) {
|
|
127
127
|
this.setupApi();
|
|
128
128
|
this.setupNftContracts(nftContracts);
|
|
129
129
|
await Promise.all(this.handlers.map(async handler => {
|
|
130
130
|
await handler.fetchNfts({
|
|
131
131
|
updateItem,
|
|
132
|
-
updateCollection
|
|
133
|
-
cleanUpNfts
|
|
132
|
+
updateCollection
|
|
134
133
|
});
|
|
135
134
|
}));
|
|
136
135
|
}
|
|
@@ -82,7 +82,6 @@ export class KaruraNftApi extends BaseNftApi {
|
|
|
82
82
|
const assetIds = await this.getNfts([address]);
|
|
83
83
|
try {
|
|
84
84
|
if (!assetIds || assetIds.length === 0) {
|
|
85
|
-
params.cleanUpNfts(this.chain, address, [], [], true);
|
|
86
85
|
return;
|
|
87
86
|
}
|
|
88
87
|
const collectionIds = [];
|
|
@@ -116,7 +115,6 @@ export class KaruraNftApi extends BaseNftApi {
|
|
|
116
115
|
params.updateItem(this.chain, parsedNft, address);
|
|
117
116
|
params.updateCollection(this.chain, parsedCollection);
|
|
118
117
|
}));
|
|
119
|
-
params.cleanUpNfts(this.chain, address, collectionIds, nftIds);
|
|
120
118
|
} catch (e) {
|
|
121
119
|
console.error(`${this.chain}`, e);
|
|
122
120
|
}
|
package/koni/api/nft/nft.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ 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[], ownNothing?: boolean) => void;
|
|
7
6
|
}
|
|
8
7
|
export declare abstract class BaseNftApi {
|
|
9
8
|
chain: string;
|
|
@@ -129,7 +129,6 @@ export class RmrkNftApi extends BaseNftApi {
|
|
|
129
129
|
const kusamaAddress = reformatAddress(address, 2);
|
|
130
130
|
allNfts = await this.getAllByAccount(kusamaAddress);
|
|
131
131
|
if (allNfts.length <= 0) {
|
|
132
|
-
params.cleanUpNfts(this.chain, address, [], [], true);
|
|
133
132
|
return;
|
|
134
133
|
}
|
|
135
134
|
const collectionInfoUrl = [];
|
|
@@ -237,9 +236,6 @@ export class RmrkNftApi extends BaseNftApi {
|
|
|
237
236
|
});
|
|
238
237
|
params.updateCollection(this.chain, parsedCollection);
|
|
239
238
|
});
|
|
240
|
-
const allCollectionIds = allCollections.map(item => item.collectionId);
|
|
241
|
-
const allNftIds = allNfts.map(nft => nft === null || nft === void 0 ? void 0 : nft.id);
|
|
242
|
-
params.cleanUpNfts(this.chain, address, allCollectionIds, allNftIds);
|
|
243
239
|
} catch (e) {
|
|
244
240
|
console.error(`${this.chain}`, e);
|
|
245
241
|
}
|
|
@@ -86,7 +86,6 @@ export default class StatemineNftApi extends BaseNftApi {
|
|
|
86
86
|
const assetIds = await this.getNfts([address]);
|
|
87
87
|
try {
|
|
88
88
|
if (!assetIds || assetIds.length === 0) {
|
|
89
|
-
params.cleanUpNfts(this.chain, address, [], [], true);
|
|
90
89
|
return;
|
|
91
90
|
}
|
|
92
91
|
const collectionIds = [];
|
|
@@ -117,7 +116,6 @@ export default class StatemineNftApi extends BaseNftApi {
|
|
|
117
116
|
};
|
|
118
117
|
params.updateCollection(this.chain, parsedCollection);
|
|
119
118
|
}));
|
|
120
|
-
params.cleanUpNfts(this.chain, address, collectionIds, nftIds);
|
|
121
119
|
} catch (e) {
|
|
122
120
|
console.error(`${this.chain}`, e);
|
|
123
121
|
}
|
|
@@ -133,8 +133,6 @@ export default class UniqueNftApi extends BaseNftApi {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
}));
|
|
136
|
-
const collectionIds = [];
|
|
137
|
-
let allNftIds = [];
|
|
138
136
|
await Promise.all(allCollectionId.map(async collectionId => {
|
|
139
137
|
const collectionIdStr = collectionId.toString();
|
|
140
138
|
|
|
@@ -142,8 +140,6 @@ export default class UniqueNftApi extends BaseNftApi {
|
|
|
142
140
|
const collection = (await this.substrateApi.api.query.nft.collectionById(collectionId)).toJSON();
|
|
143
141
|
collectionMap[collectionIdStr] = collection;
|
|
144
142
|
const nftIds = Object.entries(nftMap).filter(item => item[1] === collectionId).map(item => item[0]);
|
|
145
|
-
collectionIds.push(collectionIdStr);
|
|
146
|
-
allNftIds = allNftIds.concat(nftIds);
|
|
147
143
|
const parsedCollection = {
|
|
148
144
|
collectionId: collectionIdStr,
|
|
149
145
|
chain: this.chain
|
|
@@ -173,7 +169,6 @@ export default class UniqueNftApi extends BaseNftApi {
|
|
|
173
169
|
}
|
|
174
170
|
}));
|
|
175
171
|
}));
|
|
176
|
-
params.cleanUpNfts(this.chain, address, collectionIds, allNftIds);
|
|
177
172
|
} catch (e) {
|
|
178
173
|
console.error(`${this.chain}`, e);
|
|
179
174
|
}
|
|
@@ -324,7 +324,6 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
324
324
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
325
325
|
const balance = _balance.output ? balanceJson.ok || balanceJson.Ok : '0';
|
|
326
326
|
if (parseInt(balance) === 0) {
|
|
327
|
-
nftParams.cleanUpNfts(this.chain, address, [smartContract], []);
|
|
328
327
|
return;
|
|
329
328
|
}
|
|
330
329
|
const itemIndexes = [];
|
|
@@ -408,9 +407,6 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
408
407
|
originAsset: tokenInfo.slug
|
|
409
408
|
};
|
|
410
409
|
nftParams.updateCollection(this.chain, nftCollection);
|
|
411
|
-
Object.entries(nftOwnerMap).forEach(([owner, nftIds]) => {
|
|
412
|
-
nftParams.cleanUpNfts(this.chain, owner, [smartContract], nftIds);
|
|
413
|
-
});
|
|
414
410
|
}
|
|
415
411
|
}
|
|
416
412
|
async fetchNfts(params) {
|
|
@@ -89,14 +89,14 @@ export async function subscribeAmplitudeNominatorMetadata(chainInfo, address, su
|
|
|
89
89
|
const nearestUnstakingAmount = Object.values(unstakingInfo)[0];
|
|
90
90
|
const blockDuration = (_STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _STAKING_ERA_LENGTH_MAP.default) / blockPerRound; // in hours
|
|
91
91
|
|
|
92
|
-
const isClaimable = parseInt(nearestUnstakingBlock) - currentBlockNumber
|
|
93
|
-
const remainingBlock = parseInt(nearestUnstakingBlock) -
|
|
92
|
+
const isClaimable = parseInt(nearestUnstakingBlock) - currentBlockNumber < 0;
|
|
93
|
+
const remainingBlock = parseInt(nearestUnstakingBlock) - currentBlockNumber;
|
|
94
94
|
const waitingTime = remainingBlock * blockDuration;
|
|
95
95
|
unstakingList.push({
|
|
96
96
|
chain: chainInfo.slug,
|
|
97
97
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
98
98
|
claimable: nearestUnstakingAmount.toString(),
|
|
99
|
-
waitingTime
|
|
99
|
+
waitingTime,
|
|
100
100
|
validatorAddress: (delegatorState === null || delegatorState === void 0 ? void 0 : delegatorState.owner) || undefined
|
|
101
101
|
});
|
|
102
102
|
}
|
|
@@ -165,14 +165,14 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
|
|
|
165
165
|
const nearestUnstakingAmount = Object.values(unstakingInfo)[0];
|
|
166
166
|
const blockDuration = (_STAKING_ERA_LENGTH_MAP[chain] || _STAKING_ERA_LENGTH_MAP.default) / blockPerRound; // in hours
|
|
167
167
|
|
|
168
|
-
const isClaimable = parseInt(nearestUnstakingBlock) - currentBlockNumber
|
|
169
|
-
const remainingBlock = parseInt(nearestUnstakingBlock) -
|
|
168
|
+
const isClaimable = parseInt(nearestUnstakingBlock) - currentBlockNumber < 0;
|
|
169
|
+
const remainingBlock = parseInt(nearestUnstakingBlock) - currentBlockNumber;
|
|
170
170
|
const waitingTime = remainingBlock * blockDuration;
|
|
171
171
|
unstakingList.push({
|
|
172
172
|
chain,
|
|
173
173
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
174
174
|
claimable: nearestUnstakingAmount.toString(),
|
|
175
|
-
waitingTime
|
|
175
|
+
waitingTime,
|
|
176
176
|
validatorAddress: (delegatorState === null || delegatorState === void 0 ? void 0 : delegatorState.owner) || undefined
|
|
177
177
|
});
|
|
178
178
|
}
|
|
@@ -111,14 +111,14 @@ export async function subscribeAstarNominatorMetadata(chainInfo, address, substr
|
|
|
111
111
|
const unlockingChunks = ledger.unbondingInfo.unlockingChunks;
|
|
112
112
|
if (unlockingChunks.length > 0) {
|
|
113
113
|
for (const unlockingChunk of unlockingChunks) {
|
|
114
|
-
const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra)
|
|
115
|
-
const remainingEra = unlockingChunk.unlockEra -
|
|
114
|
+
const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra) < 0;
|
|
115
|
+
const remainingEra = unlockingChunk.unlockEra - parseInt(currentEra);
|
|
116
116
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
117
117
|
unstakingList.push({
|
|
118
118
|
chain: chainInfo.slug,
|
|
119
119
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
120
120
|
claimable: unlockingChunk.amount.toString(),
|
|
121
|
-
waitingTime
|
|
121
|
+
waitingTime
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -199,14 +199,14 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
199
199
|
const unlockingChunks = ledger.unbondingInfo.unlockingChunks;
|
|
200
200
|
if (unlockingChunks.length > 0) {
|
|
201
201
|
for (const unlockingChunk of unlockingChunks) {
|
|
202
|
-
const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra)
|
|
203
|
-
const remainingEra = unlockingChunk.unlockEra -
|
|
202
|
+
const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra) < 0;
|
|
203
|
+
const remainingEra = unlockingChunk.unlockEra - parseInt(currentEra);
|
|
204
204
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
|
|
205
205
|
unstakingList.push({
|
|
206
206
|
chain,
|
|
207
207
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
208
208
|
claimable: unlockingChunk.amount.toString(),
|
|
209
|
-
waitingTime
|
|
209
|
+
waitingTime
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
}
|
|
@@ -162,8 +162,8 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
|
|
|
162
162
|
for (const scheduledRequest of delegationScheduledRequests) {
|
|
163
163
|
if (reformatAddress(scheduledRequest.delegator, 0) === reformatAddress(address, 0)) {
|
|
164
164
|
// add network prefix
|
|
165
|
-
const isClaimable = scheduledRequest.whenExecutable - currentRound
|
|
166
|
-
const remainingEra = scheduledRequest.whenExecutable -
|
|
165
|
+
const isClaimable = scheduledRequest.whenExecutable - currentRound < 0;
|
|
166
|
+
const remainingEra = scheduledRequest.whenExecutable - currentRound;
|
|
167
167
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
168
168
|
const claimable = Object.values(scheduledRequest.action)[0];
|
|
169
169
|
unstakingMap[delegation.owner] = {
|
|
@@ -171,7 +171,7 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
|
|
|
171
171
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
172
172
|
validatorAddress: delegation.owner,
|
|
173
173
|
claimable: claimable.toString(),
|
|
174
|
-
waitingTime
|
|
174
|
+
waitingTime
|
|
175
175
|
};
|
|
176
176
|
hasUnstaking = true;
|
|
177
177
|
break; // only handle 1 scheduledRequest per collator
|
|
@@ -254,7 +254,7 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
|
|
|
254
254
|
for (const scheduledRequest of delegationScheduledRequests) {
|
|
255
255
|
if (reformatAddress(scheduledRequest.delegator, 0) === reformatAddress(address, 0)) {
|
|
256
256
|
// add network prefix
|
|
257
|
-
const isClaimable = scheduledRequest.whenExecutable - currentRound
|
|
257
|
+
const isClaimable = scheduledRequest.whenExecutable - currentRound < 0;
|
|
258
258
|
const remainingEra = scheduledRequest.whenExecutable - (currentRound + 1);
|
|
259
259
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
|
|
260
260
|
const claimable = Object.values(scheduledRequest.action)[0];
|
|
@@ -263,7 +263,7 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
|
|
|
263
263
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
264
264
|
validatorAddress: delegation.owner,
|
|
265
265
|
claimable: claimable.toString(),
|
|
266
|
-
waitingTime: waitingTime
|
|
266
|
+
waitingTime: waitingTime
|
|
267
267
|
};
|
|
268
268
|
hasUnstaking = true;
|
|
269
269
|
break; // only handle 1 scheduledRequest per collator
|
|
@@ -214,14 +214,14 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
217
|
-
const isClaimable = unlockingChunk.era - parseInt(currentEra)
|
|
218
|
-
const remainingEra = unlockingChunk.era -
|
|
217
|
+
const isClaimable = unlockingChunk.era - parseInt(currentEra) < 0;
|
|
218
|
+
const remainingEra = unlockingChunk.era - parseInt(currentEra);
|
|
219
219
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
|
|
220
220
|
unstakingList.push({
|
|
221
221
|
chain,
|
|
222
222
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
223
223
|
claimable: unlockingChunk.value.toString(),
|
|
224
|
-
waitingTime: waitingTime
|
|
224
|
+
waitingTime: waitingTime
|
|
225
225
|
});
|
|
226
226
|
});
|
|
227
227
|
return {
|
|
@@ -313,14 +313,14 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
316
|
-
const isClaimable = unlockingChunk.era - parseInt(currentEra)
|
|
317
|
-
const remainingEra = unlockingChunk.era -
|
|
316
|
+
const isClaimable = unlockingChunk.era - parseInt(currentEra) < 0;
|
|
317
|
+
const remainingEra = unlockingChunk.era - parseInt(currentEra);
|
|
318
318
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
|
|
319
319
|
unstakingList.push({
|
|
320
320
|
chain,
|
|
321
321
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
322
322
|
claimable: unlockingChunk.value.toString(),
|
|
323
|
-
waitingTime: waitingTime
|
|
323
|
+
waitingTime: waitingTime
|
|
324
324
|
});
|
|
325
325
|
});
|
|
326
326
|
return {
|
|
@@ -370,14 +370,14 @@ export async function subscribeRelayChainPoolMemberMetadata(chainInfo, address,
|
|
|
370
370
|
};
|
|
371
371
|
const unstakings = [];
|
|
372
372
|
Object.entries(poolMemberInfo.unbondingEras).forEach(([unlockingEra, amount]) => {
|
|
373
|
-
const isClaimable = parseInt(unlockingEra) - parseInt(currentEra)
|
|
374
|
-
const remainingEra = parseInt(unlockingEra) -
|
|
373
|
+
const isClaimable = parseInt(unlockingEra) - parseInt(currentEra) < 0;
|
|
374
|
+
const remainingEra = parseInt(unlockingEra) - parseInt(currentEra);
|
|
375
375
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
376
376
|
unstakings.push({
|
|
377
377
|
chain: chainInfo.slug,
|
|
378
378
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
379
379
|
claimable: amount.toString(),
|
|
380
|
-
waitingTime: waitingTime
|
|
380
|
+
waitingTime: waitingTime
|
|
381
381
|
});
|
|
382
382
|
});
|
|
383
383
|
const bnActiveStake = new BN(poolMemberInfo.points.toString());
|
|
@@ -447,14 +447,14 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
|
|
|
447
447
|
};
|
|
448
448
|
const unstakings = [];
|
|
449
449
|
Object.entries(poolMemberInfo.unbondingEras).forEach(([unlockingEra, amount]) => {
|
|
450
|
-
const isClaimable = parseInt(unlockingEra) - parseInt(currentEra)
|
|
451
|
-
const remainingEra = parseInt(unlockingEra) -
|
|
450
|
+
const isClaimable = parseInt(unlockingEra) - parseInt(currentEra) < 0;
|
|
451
|
+
const remainingEra = parseInt(unlockingEra) - parseInt(currentEra);
|
|
452
452
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
453
453
|
unstakings.push({
|
|
454
454
|
chain: chainInfo.slug,
|
|
455
455
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
456
456
|
claimable: amount.toString(),
|
|
457
|
-
waitingTime: waitingTime
|
|
457
|
+
waitingTime: waitingTime
|
|
458
458
|
});
|
|
459
459
|
});
|
|
460
460
|
const bnActiveStake = new BN(poolMemberInfo.points.toString());
|
|
@@ -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 {
|
|
@@ -189,13 +189,7 @@ export function getStakingAvailableActionsByNominator(nominatorMetadata, unclaim
|
|
|
189
189
|
}
|
|
190
190
|
if (nominatorMetadata.unstakings.length > 0) {
|
|
191
191
|
result.push(StakingAction.CANCEL_UNSTAKE);
|
|
192
|
-
|
|
193
|
-
for (const unstaking of nominatorMetadata.unstakings) {
|
|
194
|
-
if (unstaking.status === UnstakingStatus.CLAIMABLE) {
|
|
195
|
-
hasClaimable = true;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
192
|
+
const hasClaimable = nominatorMetadata.unstakings.some(unstaking => unstaking.status === UnstakingStatus.CLAIMABLE);
|
|
199
193
|
if (hasClaimable) {
|
|
200
194
|
result.push(StakingAction.WITHDRAW);
|
|
201
195
|
}
|
package/koni/api/xcm/xTokens.js
CHANGED
|
@@ -19,6 +19,6 @@ function getCurrencyId(tokenInfo) {
|
|
|
19
19
|
}
|
|
20
20
|
export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
21
21
|
const weightParam = ['pioneer'].includes(originChainInfo.slug) ? FOUR_INSTRUCTIONS_WEIGHT : getDestWeight();
|
|
22
|
-
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
22
|
+
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
23
23
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getDestMultilocation(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
24
24
|
}
|
|
@@ -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';
|
|
@@ -27,15 +26,11 @@ export declare class KoniCron {
|
|
|
27
26
|
syncMantaPay: () => void;
|
|
28
27
|
refreshNft: (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => () => void;
|
|
29
28
|
resetNft: (newAddress: string) => void;
|
|
30
|
-
resetStakingReward: () => void;
|
|
31
29
|
refreshStakingReward: (address: string) => () => void;
|
|
32
30
|
refreshStakingRewardFastInterval: (address: string) => () => void;
|
|
33
31
|
setStakingRewardReady: () => void;
|
|
34
32
|
checkNetworkAvailable: (serviceInfo: ServiceInfo) => boolean;
|
|
35
|
-
updateChainStakingMetadata: (chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
|
|
36
|
-
updateNominatorMetadata: (address: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
|
|
37
33
|
reloadNft(): Promise<boolean>;
|
|
38
34
|
reloadStaking(): Promise<boolean>;
|
|
39
35
|
private needUpdateNft;
|
|
40
|
-
private needUpdateStaking;
|
|
41
36
|
}
|