@subwallet/extension-base 1.0.2-1b → 1.0.2-2
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 +34 -16
- package/background/KoniTypes.js +7 -6
- package/background/errors/TransactionError.js +1 -21
- package/cjs/background/KoniTypes.js +7 -6
- package/cjs/background/errors/TransactionError.js +0 -20
- package/cjs/constants/index.js +26 -8
- package/cjs/koni/api/dotsama/balance.js +224 -49
- package/cjs/koni/api/dotsama/transfer.js +29 -30
- package/cjs/koni/api/nft/acala_nft/index.js +1 -4
- package/cjs/koni/api/nft/bit.country/index.js +1 -4
- package/cjs/koni/api/nft/evm_nft/index.js +3 -7
- package/cjs/koni/api/nft/index.js +6 -3
- package/cjs/koni/api/nft/karura_nft/index.js +1 -4
- package/cjs/koni/api/nft/rmrk_nft/index.js +1 -8
- package/cjs/koni/api/nft/statemine_nft/index.js +1 -4
- package/cjs/koni/api/nft/unique_nft/index.js +1 -6
- package/cjs/koni/api/nft/wasm_nft/index.js +111 -169
- package/cjs/koni/api/nft/wasm_nft/utils.js +7 -11
- package/cjs/koni/api/staking/bonding/amplitude.js +9 -13
- package/cjs/koni/api/staking/bonding/astar.js +13 -15
- package/cjs/koni/api/staking/bonding/index.js +10 -22
- package/cjs/koni/api/staking/bonding/paraChain.js +2 -85
- package/cjs/koni/api/staking/bonding/relayChain.js +16 -119
- package/cjs/koni/api/staking/bonding/utils.js +8 -27
- package/cjs/koni/api/tokens/wasm/index.js +4 -5
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +13 -18
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +6 -9
- package/cjs/koni/background/cron.js +47 -150
- package/cjs/koni/background/handlers/Extension.js +64 -106
- package/cjs/koni/background/handlers/State.js +21 -19
- package/cjs/koni/background/handlers/Tabs.js +1 -8
- package/cjs/koni/background/subscription.js +29 -32
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +8 -13
- package/cjs/services/chain-service/handler/light-client/index.js +0 -2
- package/cjs/services/chain-service/index.js +7 -6
- package/cjs/services/event-service/index.js +1 -5
- package/cjs/services/event-service/types.js +1 -11
- package/cjs/services/history-service/index.js +10 -16
- package/cjs/services/history-service/subsquid-multi-chain-history.js +9 -12
- package/cjs/services/price-service/coingecko.js +1 -0
- package/cjs/services/price-service/index.js +3 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/cjs/services/storage-service/DatabaseService.js +33 -52
- package/cjs/services/storage-service/db-stores/Nft.js +17 -4
- package/cjs/services/transaction-service/event-parser/index.js +48 -20
- package/cjs/services/transaction-service/index.js +14 -23
- package/cjs/utils/index.js +14 -7
- package/constants/index.d.ts +13 -7
- package/constants/index.js +13 -7
- package/koni/api/dotsama/balance.d.ts +1 -0
- package/koni/api/dotsama/balance.js +197 -22
- package/koni/api/dotsama/transfer.js +4 -5
- package/koni/api/nft/acala_nft/index.js +1 -3
- package/koni/api/nft/bit.country/index.js +1 -3
- package/koni/api/nft/evm_nft/index.js +3 -6
- package/koni/api/nft/index.d.ts +2 -1
- package/koni/api/nft/index.js +6 -3
- package/koni/api/nft/karura_nft/index.js +1 -3
- package/koni/api/nft/nft.d.ts +0 -1
- package/koni/api/nft/rmrk_nft/index.js +1 -8
- package/koni/api/nft/statemine_nft/index.js +1 -3
- package/koni/api/nft/unique_nft/index.js +1 -5
- package/koni/api/nft/wasm_nft/index.d.ts +2 -0
- package/koni/api/nft/wasm_nft/index.js +109 -167
- package/koni/api/nft/wasm_nft/utils.d.ts +5 -7
- package/koni/api/nft/wasm_nft/utils.js +5 -7
- package/koni/api/staking/bonding/amplitude.d.ts +1 -0
- package/koni/api/staking/bonding/amplitude.js +10 -15
- package/koni/api/staking/bonding/astar.js +6 -8
- package/koni/api/staking/bonding/index.d.ts +1 -4
- package/koni/api/staking/bonding/index.js +13 -23
- package/koni/api/staking/bonding/paraChain.d.ts +0 -3
- package/koni/api/staking/bonding/paraChain.js +5 -86
- package/koni/api/staking/bonding/relayChain.d.ts +1 -5
- package/koni/api/staking/bonding/relayChain.js +18 -118
- package/koni/api/staking/bonding/utils.d.ts +2 -3
- package/koni/api/staking/bonding/utils.js +9 -27
- package/koni/api/tokens/wasm/index.js +4 -5
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +6 -5
- package/koni/api/xcm/utils.js +10 -15
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +9 -10
- package/koni/background/cron.d.ts +1 -6
- package/koni/background/cron.js +48 -151
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +67 -108
- package/koni/background/handlers/State.d.ts +6 -5
- package/koni/background/handlers/State.js +21 -19
- package/koni/background/handlers/Tabs.js +1 -8
- package/koni/background/subscription.js +30 -31
- package/package.json +8 -13
- package/packageInfo.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +9 -14
- package/services/chain-service/handler/light-client/index.d.ts +1 -17
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +881 -1041
- package/services/chain-service/helper/psp34_abi.json +1808 -2964
- package/services/chain-service/index.js +7 -6
- package/services/event-service/index.js +1 -5
- package/services/event-service/types.d.ts +9 -5
- package/services/event-service/types.js +1 -4
- package/services/history-service/index.d.ts +1 -1
- package/services/history-service/index.js +10 -16
- package/services/history-service/subsquid-multi-chain-history.js +11 -15
- package/services/price-service/coingecko.js +1 -0
- package/services/price-service/index.js +3 -2
- package/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/services/storage-service/DatabaseService.d.ts +0 -1
- package/services/storage-service/DatabaseService.js +33 -52
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +16 -4
- package/services/transaction-service/event-parser/index.js +49 -21
- package/services/transaction-service/index.js +14 -23
- package/utils/index.d.ts +1 -1
- package/utils/index.js +12 -6
- package/cjs/koni/api/tokens/wasm/utils.js +0 -63
- package/koni/api/tokens/wasm/utils.d.ts +0 -6
- package/koni/api/tokens/wasm/utils.js +0 -54
|
@@ -122,11 +122,8 @@ class KaruraNftApi extends _nft.BaseNftApi {
|
|
|
122
122
|
};
|
|
123
123
|
params.updateItem(this.chain, parsedNft, address);
|
|
124
124
|
params.updateCollection(this.chain, parsedCollection);
|
|
125
|
+
// params.updateReady(true);
|
|
125
126
|
}));
|
|
126
|
-
Object.entries(collectionNftIds).forEach(_ref2 => {
|
|
127
|
-
let [collectionId, nftIds] = _ref2;
|
|
128
|
-
params.cleanUpNfts(this.chain, address, collectionId, nftIds);
|
|
129
|
-
});
|
|
130
127
|
} catch (e) {
|
|
131
128
|
console.error('Failed to fetch karura nft', e);
|
|
132
129
|
}
|
|
@@ -238,15 +238,8 @@ class RmrkNftApi extends _nft.BaseNftApi {
|
|
|
238
238
|
image: allCollectionMeta[item.collectionId] ? this.parseUrl(allCollectionMeta[item.collectionId].image) : null,
|
|
239
239
|
chain: this.chain
|
|
240
240
|
};
|
|
241
|
-
const nftIds = [];
|
|
242
|
-
allNfts.forEach(nft => {
|
|
243
|
-
const nftCollectionId = nft === null || nft === void 0 ? void 0 : nft.collectionId;
|
|
244
|
-
if (nftCollectionId === item.collectionId) {
|
|
245
|
-
nftIds.push(nft === null || nft === void 0 ? void 0 : nft.id);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
241
|
params.updateCollection(this.chain, parsedCollection);
|
|
249
|
-
params.
|
|
242
|
+
// params.updateReady(true);
|
|
250
243
|
});
|
|
251
244
|
} catch (e) {
|
|
252
245
|
console.error('Failed to fetch rmrk nft', e);
|
|
@@ -122,11 +122,8 @@ class StatemineNftApi extends _nft.BaseNftApi {
|
|
|
122
122
|
image: collectionMeta && collectionMeta.image ? this.parseUrl(collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image) : undefined
|
|
123
123
|
};
|
|
124
124
|
params.updateCollection(this.chain, parsedCollection);
|
|
125
|
+
// params.updateReady(true);
|
|
125
126
|
}));
|
|
126
|
-
Object.entries(collectionNftIds).forEach(_ref => {
|
|
127
|
-
let [collectionId, nftIds] = _ref;
|
|
128
|
-
params.cleanUpNfts(this.chain, address, collectionId, nftIds);
|
|
129
|
-
});
|
|
130
127
|
} catch (e) {
|
|
131
128
|
console.error('Failed to fetch statemine nft', e);
|
|
132
129
|
}
|
|
@@ -141,7 +141,6 @@ class UniqueNftApi extends _nft.BaseNftApi {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}));
|
|
144
|
-
const nftCollectionMap = {};
|
|
145
144
|
await Promise.all(allCollectionId.map(async collectionId => {
|
|
146
145
|
const collectionIdStr = collectionId.toString();
|
|
147
146
|
|
|
@@ -149,7 +148,6 @@ class UniqueNftApi extends _nft.BaseNftApi {
|
|
|
149
148
|
const collection = (await this.substrateApi.api.query.nft.collectionById(collectionId)).toJSON();
|
|
150
149
|
collectionMap[collectionIdStr] = collection;
|
|
151
150
|
const nftIds = Object.entries(nftMap).filter(item => item[1] === collectionId).map(item => item[0]);
|
|
152
|
-
nftCollectionMap[collectionIdStr] = nftIds;
|
|
153
151
|
const parsedCollection = {
|
|
154
152
|
collectionId: collectionIdStr,
|
|
155
153
|
chain: this.chain
|
|
@@ -176,13 +174,10 @@ class UniqueNftApi extends _nft.BaseNftApi {
|
|
|
176
174
|
}
|
|
177
175
|
params.updateItem(this.chain, parsedItem, address);
|
|
178
176
|
params.updateCollection(this.chain, parsedCollection);
|
|
177
|
+
// params.updateReady(true);
|
|
179
178
|
}
|
|
180
179
|
}));
|
|
181
180
|
}));
|
|
182
|
-
Object.entries(nftCollectionMap).forEach(_ref => {
|
|
183
|
-
let [collectionId, nftIds] = _ref;
|
|
184
|
-
params.cleanUpNfts(this.chain, address, collectionId, nftIds);
|
|
185
|
-
});
|
|
186
181
|
} catch (e) {
|
|
187
182
|
console.error('Failed to fetch unique nft', e);
|
|
188
183
|
}
|
|
@@ -9,44 +9,12 @@ var _types = require("@subwallet/chain-list/types");
|
|
|
9
9
|
var _nft = require("@subwallet/extension-base/koni/api/nft/nft");
|
|
10
10
|
var _utils = require("@subwallet/extension-base/koni/api/nft/wasm_nft/utils");
|
|
11
11
|
var _wasm = require("@subwallet/extension-base/koni/api/tokens/wasm");
|
|
12
|
-
var _utils2 = require("@subwallet/extension-base/
|
|
13
|
-
var _utils3 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
14
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
12
|
+
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
15
13
|
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
16
14
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
17
15
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
18
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
19
17
|
|
|
20
|
-
// interface CollectionAttributes {
|
|
21
|
-
// storedOnChain: boolean,
|
|
22
|
-
// attributeList: string[] // list of attribute names
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
async function isArtZeroFeaturedCollection(networkKey, contractAddress) {
|
|
26
|
-
const timeout = new Promise(resolve => {
|
|
27
|
-
const id = setTimeout(() => {
|
|
28
|
-
clearTimeout(id);
|
|
29
|
-
resolve(null);
|
|
30
|
-
}, 3000);
|
|
31
|
-
});
|
|
32
|
-
const urlencoded = new URLSearchParams();
|
|
33
|
-
urlencoded.append('collection_address', contractAddress);
|
|
34
|
-
const collectionInfoPromise = new Promise(function (resolve) {
|
|
35
|
-
(0, _crossFetch.default)(`${networkKey === 'alephTest' ? _utils.ART_ZERO_TESTNET_COLLECTION_API : _utils.ART_ZERO_COLLECTION_API}`, {
|
|
36
|
-
method: 'POST',
|
|
37
|
-
headers: {
|
|
38
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
39
|
-
},
|
|
40
|
-
body: urlencoded
|
|
41
|
-
}).then(resp => {
|
|
42
|
-
resolve(resp.json());
|
|
43
|
-
}).catch(console.error);
|
|
44
|
-
});
|
|
45
|
-
const collectionInfo = await Promise.race([timeout, collectionInfoPromise]);
|
|
46
|
-
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
return collectionInfo !== null && (collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.status) !== 'FAILED';
|
|
49
|
-
}
|
|
50
18
|
class WasmNftApi extends _nft.BaseNftApi {
|
|
51
19
|
wasmContracts = [];
|
|
52
20
|
constructor(api, addresses, chain) {
|
|
@@ -59,40 +27,31 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
59
27
|
if (!tokenUri || tokenUri.length === 0) {
|
|
60
28
|
return undefined;
|
|
61
29
|
}
|
|
62
|
-
if (tokenUri.startsWith('/ipfs/')) {
|
|
63
|
-
return tokenUri;
|
|
64
|
-
}
|
|
65
|
-
if (tokenUri.startsWith('ipfs://')) {
|
|
66
|
-
return `/ipfs/${tokenUri.split('ipfs://')[1]}`;
|
|
67
|
-
}
|
|
68
30
|
if (!tokenUri.includes('ipfs://') && !tokenUri.includes('ipfs://ipfs/')) {
|
|
69
|
-
return
|
|
31
|
+
return `ipfs://${tokenUri}`;
|
|
70
32
|
}
|
|
71
33
|
if (tokenUri.includes('ipfs://ipfs/')) {
|
|
72
|
-
return
|
|
34
|
+
return `ipfs://${tokenUri}`;
|
|
73
35
|
}
|
|
74
36
|
return tokenUri;
|
|
75
37
|
}
|
|
76
|
-
|
|
38
|
+
parseFeaturedNftImage(tokenUri) {
|
|
77
39
|
const parsedTokenUri = this.parseFeaturedTokenUri(tokenUri);
|
|
78
40
|
if (!parsedTokenUri) {
|
|
79
41
|
return undefined;
|
|
80
42
|
}
|
|
81
|
-
|
|
82
|
-
const collectionImageUrl = await (0, _axios.default)(nftItemImageSrc, {
|
|
83
|
-
method: 'GET'
|
|
84
|
-
});
|
|
85
|
-
return collectionImageUrl.data;
|
|
43
|
+
return `${_utils.ART_ZERO_IMAGE_API}?input=${parsedTokenUri}&size=500`;
|
|
86
44
|
}
|
|
87
45
|
async parseFeaturedCollectionImage(smartContract) {
|
|
88
|
-
const
|
|
89
|
-
urlencoded.append('collection_address', smartContract);
|
|
90
|
-
const resp = await (0, _crossFetch.default)(this.chain === 'alephTest' ? _utils.ART_ZERO_TESTNET_COLLECTION_API : _utils.ART_ZERO_COLLECTION_API, {
|
|
46
|
+
const resp = await (0, _crossFetch.default)(_utils.ART_ZERO_COLLECTION_API, {
|
|
91
47
|
method: 'POST',
|
|
92
48
|
headers: {
|
|
93
|
-
|
|
49
|
+
Accept: 'application/json',
|
|
50
|
+
'Content-Type': 'application/json'
|
|
94
51
|
},
|
|
95
|
-
body:
|
|
52
|
+
body: JSON.stringify({
|
|
53
|
+
collection_address: smartContract
|
|
54
|
+
})
|
|
96
55
|
});
|
|
97
56
|
const result = resp && resp.ok && (await resp.json());
|
|
98
57
|
if (!result) {
|
|
@@ -106,91 +65,82 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
106
65
|
if (!parsedCollectionImage) {
|
|
107
66
|
return;
|
|
108
67
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
68
|
+
return `${_utils.ART_ZERO_IMAGE_API}?input=${parsedCollectionImage}`;
|
|
69
|
+
}
|
|
70
|
+
async getCollectionAttributes(contractPromise) {
|
|
71
|
+
const _onChainAttributeCount = await contractPromise.query['psp34Traits::getAttributeCount'](this.addresses[0], {
|
|
72
|
+
gasLimit: -1
|
|
112
73
|
});
|
|
113
|
-
|
|
74
|
+
const onChainAttributeCount = _onChainAttributeCount.output ? _onChainAttributeCount.output.toString() : '0';
|
|
75
|
+
if (parseInt(onChainAttributeCount) === 0) {
|
|
76
|
+
return {
|
|
77
|
+
storedOnChain: false,
|
|
78
|
+
attributeList: []
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const attributeList = [];
|
|
82
|
+
const attributeIndexes = [];
|
|
83
|
+
for (let i = 0; i < parseInt(onChainAttributeCount); i++) {
|
|
84
|
+
attributeIndexes.push(i);
|
|
85
|
+
}
|
|
86
|
+
await Promise.all(attributeIndexes.map(async i => {
|
|
87
|
+
const _attributeByIndex = await contractPromise.query['psp34Traits::getAttributeName'](this.addresses[0], {
|
|
88
|
+
gasLimit: -1
|
|
89
|
+
}, i);
|
|
90
|
+
if (_attributeByIndex.output) {
|
|
91
|
+
const attributeName = _attributeByIndex.output.toString();
|
|
92
|
+
if (attributeName !== '') {
|
|
93
|
+
attributeList.push(attributeName);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
return {
|
|
98
|
+
storedOnChain: true,
|
|
99
|
+
attributeList
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async processOnChainMetadata(contractPromise, address, tokenIdObj, collectionAttributes, isFeatured) {
|
|
103
|
+
const nftItem = {
|
|
104
|
+
chain: '',
|
|
105
|
+
collectionId: '',
|
|
106
|
+
id: '',
|
|
107
|
+
owner: ''
|
|
108
|
+
};
|
|
109
|
+
const _attributeValues = await contractPromise.query['psp34Traits::getAttributes'](address, {
|
|
110
|
+
gasLimit: -1
|
|
111
|
+
}, tokenIdObj, collectionAttributes);
|
|
112
|
+
if (_attributeValues.output) {
|
|
113
|
+
const attributeValues = _attributeValues.output.toHuman();
|
|
114
|
+
const attributeDict = {};
|
|
115
|
+
for (let i = 0; i < collectionAttributes.length; i++) {
|
|
116
|
+
const attributeName = collectionAttributes[i];
|
|
117
|
+
const attributeValue = attributeValues[i] ? attributeValues[i] : '';
|
|
118
|
+
if (attributeName.toLowerCase() === 'nft_name') {
|
|
119
|
+
nftItem.name = attributeValue;
|
|
120
|
+
} else if (attributeName.toLowerCase() === 'description') {
|
|
121
|
+
nftItem.description = attributeValue;
|
|
122
|
+
} else if (attributeName.toLowerCase() === 'avatar') {
|
|
123
|
+
if (isFeatured) {
|
|
124
|
+
nftItem.image = this.parseFeaturedNftImage(attributeValue);
|
|
125
|
+
} else {
|
|
126
|
+
nftItem.image = this.parseUrl(attributeValue);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
if (attributeValue !== '') {
|
|
130
|
+
attributeDict[attributeName] = {
|
|
131
|
+
value: attributeValue
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
nftItem.properties = attributeDict;
|
|
137
|
+
}
|
|
138
|
+
if (isFeatured) {
|
|
139
|
+
nftItem.externalUrl = _utils.ART_ZERO_EXTERNAL_URL;
|
|
140
|
+
}
|
|
141
|
+
return nftItem;
|
|
114
142
|
}
|
|
115
|
-
|
|
116
|
-
// private async getCollectionAttributes (contractPromise: ContractPromise): Promise<CollectionAttributes> {
|
|
117
|
-
// const _onChainAttributeCount = await contractPromise.query['psp34Traits::getAttributeCount'](this.addresses[0], { gasLimit: getDefaultWeightV2(this.substrateApi?.api as ApiPromise) });
|
|
118
|
-
// const onChainAttributeCount = _onChainAttributeCount.output ? _onChainAttributeCount.output.toString() : '0';
|
|
119
|
-
//
|
|
120
|
-
// if (parseInt(onChainAttributeCount) === 0) {
|
|
121
|
-
// return {
|
|
122
|
-
// storedOnChain: false,
|
|
123
|
-
// attributeList: []
|
|
124
|
-
// };
|
|
125
|
-
// }
|
|
126
|
-
//
|
|
127
|
-
// const attributeList: string[] = [];
|
|
128
|
-
// const attributeIndexes: number[] = [];
|
|
129
|
-
//
|
|
130
|
-
// for (let i = 0; i < parseInt(onChainAttributeCount); i++) {
|
|
131
|
-
// attributeIndexes.push(i);
|
|
132
|
-
// }
|
|
133
|
-
//
|
|
134
|
-
// await Promise.all(attributeIndexes.map(async (i) => {
|
|
135
|
-
// const _attributeByIndex = await contractPromise.query['psp34Traits::getAttributeName'](this.addresses[0], { gasLimit: getDefaultWeightV2(this.substrateApi?.api as ApiPromise) }, i);
|
|
136
|
-
//
|
|
137
|
-
// if (_attributeByIndex.output) {
|
|
138
|
-
// const attributeName = _attributeByIndex.output.toString();
|
|
139
|
-
//
|
|
140
|
-
// if (attributeName !== '') {
|
|
141
|
-
// attributeList.push(attributeName);
|
|
142
|
-
// }
|
|
143
|
-
// }
|
|
144
|
-
// }));
|
|
145
|
-
//
|
|
146
|
-
// return {
|
|
147
|
-
// storedOnChain: true,
|
|
148
|
-
// attributeList
|
|
149
|
-
// };
|
|
150
|
-
// }
|
|
151
|
-
|
|
152
|
-
// private async processOnChainMetadata (contractPromise: ContractPromise, address: string, tokenIdObj: Record<string, string>, collectionAttributes: string[], isFeatured: boolean): Promise<NftItem> {
|
|
153
|
-
// const nftItem: NftItem = { chain: '', collectionId: '', id: '', owner: '' };
|
|
154
|
-
// const _attributeValues = await contractPromise.query['psp34Traits::getAttributes'](address, { gasLimit: getDefaultWeightV2(this.substrateApi?.api as ApiPromise) }, tokenIdObj, collectionAttributes);
|
|
155
|
-
//
|
|
156
|
-
// if (_attributeValues.output) {
|
|
157
|
-
// const attributeValues = _attributeValues.output.toHuman() as string[];
|
|
158
|
-
//
|
|
159
|
-
// const attributeDict: Record<string, any> = {};
|
|
160
|
-
//
|
|
161
|
-
// for (let i = 0; i < collectionAttributes.length; i++) {
|
|
162
|
-
// const attributeName = collectionAttributes[i];
|
|
163
|
-
// const attributeValue = attributeValues[i] ? attributeValues[i] : '';
|
|
164
|
-
//
|
|
165
|
-
// if (attributeName.toLowerCase() === 'nft_name') {
|
|
166
|
-
// nftItem.name = attributeValue;
|
|
167
|
-
// } else if (attributeName.toLowerCase() === 'description') {
|
|
168
|
-
// nftItem.description = attributeValue;
|
|
169
|
-
// } else if (attributeName.toLowerCase() === 'avatar') {
|
|
170
|
-
// if (isFeatured) {
|
|
171
|
-
// nftItem.image = await this.parseFeaturedNftImage(attributeValue);
|
|
172
|
-
// } else {
|
|
173
|
-
// nftItem.image = this.parseUrl(attributeValue);
|
|
174
|
-
// }
|
|
175
|
-
// } else {
|
|
176
|
-
// if (attributeValue !== '') {
|
|
177
|
-
// attributeDict[attributeName] = { value: attributeValue };
|
|
178
|
-
// }
|
|
179
|
-
// }
|
|
180
|
-
// }
|
|
181
|
-
//
|
|
182
|
-
// nftItem.properties = attributeDict;
|
|
183
|
-
// }
|
|
184
|
-
//
|
|
185
|
-
// if (isFeatured) {
|
|
186
|
-
// nftItem.externalUrl = ART_ZERO_EXTERNAL_URL;
|
|
187
|
-
// }
|
|
188
|
-
//
|
|
189
|
-
// return nftItem;
|
|
190
|
-
// }
|
|
191
|
-
|
|
192
143
|
async processOffChainMetadata(contractPromise, address, tokenId, isFeatured) {
|
|
193
|
-
var _this$substrateApi;
|
|
194
144
|
const nftItem = {
|
|
195
145
|
chain: '',
|
|
196
146
|
collectionId: '',
|
|
@@ -199,23 +149,19 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
199
149
|
name: tokenId
|
|
200
150
|
};
|
|
201
151
|
const _tokenUri = await contractPromise.query['psp34Traits::tokenUri'](address, {
|
|
202
|
-
gasLimit:
|
|
152
|
+
gasLimit: -1
|
|
203
153
|
}, tokenId);
|
|
204
154
|
if (_tokenUri.output) {
|
|
205
155
|
let itemDetail = false;
|
|
206
|
-
|
|
207
|
-
const _tokenUriObj = _tokenUri.output.toJSON();
|
|
208
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
209
|
-
const tokenUri = _tokenUriObj.Ok || _tokenUriObj.ok;
|
|
156
|
+
const tokenUri = _tokenUri.output.toString();
|
|
210
157
|
if (isFeatured) {
|
|
211
158
|
const parsedTokenUri = this.parseFeaturedTokenUri(tokenUri);
|
|
212
159
|
if (parsedTokenUri) {
|
|
213
|
-
const resp = await (0, _crossFetch.default)(`${
|
|
160
|
+
const resp = await (0, _crossFetch.default)(`${_utils.ART_ZERO_IPFS_API}?input=${parsedTokenUri}`);
|
|
214
161
|
itemDetail = resp && resp.ok && (await resp.json());
|
|
215
162
|
}
|
|
216
163
|
} else {
|
|
217
|
-
const
|
|
218
|
-
const detailUrl = this.parseUrl(parsedTokenUri);
|
|
164
|
+
const detailUrl = this.parseUrl(tokenUri);
|
|
219
165
|
if (detailUrl) {
|
|
220
166
|
const resp = await (0, _crossFetch.default)(detailUrl);
|
|
221
167
|
itemDetail = resp && resp.ok && (await resp.json());
|
|
@@ -230,7 +176,7 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
230
176
|
nftItem.externalUrl = itemDetail.external_url;
|
|
231
177
|
const rawImageSrc = itemDetail.image ? itemDetail.image : itemDetail.image_url;
|
|
232
178
|
if (isFeatured) {
|
|
233
|
-
nftItem.image =
|
|
179
|
+
nftItem.image = this.parseFeaturedNftImage(rawImageSrc);
|
|
234
180
|
nftItem.externalUrl = _utils.ART_ZERO_EXTERNAL_URL;
|
|
235
181
|
} else {
|
|
236
182
|
nftItem.image = this.parseUrl(rawImageSrc);
|
|
@@ -248,24 +194,20 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
248
194
|
}
|
|
249
195
|
return nftItem;
|
|
250
196
|
}
|
|
251
|
-
async getItemsByCollection(contractPromise, tokenInfo, collectionName, nftParams
|
|
197
|
+
async getItemsByCollection(contractPromise, collectionAttributes, isMetadataOnchain, tokenInfo, collectionName, nftParams) {
|
|
252
198
|
let ownItem = false;
|
|
253
199
|
let collectionImage;
|
|
254
|
-
const smartContract = (0,
|
|
255
|
-
const
|
|
200
|
+
const smartContract = (0, _utils2._getContractAddressOfToken)(tokenInfo);
|
|
201
|
+
const isFeatured = _utils.ART_ZERO_CONTRACTS.includes(smartContract);
|
|
256
202
|
await Promise.all(this.addresses.map(async address => {
|
|
257
|
-
var _this$substrateApi2, _balance$output;
|
|
258
203
|
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
259
204
|
return;
|
|
260
205
|
}
|
|
261
206
|
const nftIds = [];
|
|
262
207
|
const _balance = await contractPromise.query['psp34::balanceOf'](address, {
|
|
263
|
-
gasLimit:
|
|
208
|
+
gasLimit: -1
|
|
264
209
|
}, address);
|
|
265
|
-
|
|
266
|
-
const balanceJson = _balance === null || _balance === void 0 ? void 0 : (_balance$output = _balance.output) === null || _balance$output === void 0 ? void 0 : _balance$output.toJSON();
|
|
267
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
268
|
-
const balance = _balance.output ? balanceJson.ok || balanceJson.Ok : '0';
|
|
210
|
+
const balance = _balance.output ? _balance.output.toString() : '0';
|
|
269
211
|
if (parseInt(balance) === 0) {
|
|
270
212
|
return;
|
|
271
213
|
}
|
|
@@ -275,17 +217,20 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
275
217
|
}
|
|
276
218
|
try {
|
|
277
219
|
await Promise.all(itemIndexes.map(async i => {
|
|
278
|
-
var _this$substrateApi3;
|
|
279
220
|
const _tokenByIndexResp = await contractPromise.query['psp34Enumerable::ownersTokenByIndex'](address, {
|
|
280
|
-
gasLimit:
|
|
221
|
+
gasLimit: -1
|
|
281
222
|
}, address, i);
|
|
282
223
|
if (_tokenByIndexResp.output) {
|
|
283
224
|
const rawTokenId = _tokenByIndexResp.output.toHuman();
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
const tokenId = Object.values(tokenIdObj)[0].replaceAll(',', '');
|
|
225
|
+
const tokenIdObj = rawTokenId.Ok;
|
|
226
|
+
const tokenId = Object.values(tokenIdObj)[0];
|
|
287
227
|
nftIds.push(tokenId);
|
|
288
|
-
|
|
228
|
+
let nftItem;
|
|
229
|
+
if (isMetadataOnchain) {
|
|
230
|
+
nftItem = await this.processOnChainMetadata(contractPromise, address, tokenIdObj, collectionAttributes, isFeatured);
|
|
231
|
+
} else {
|
|
232
|
+
nftItem = await this.processOffChainMetadata(contractPromise, address, tokenId, isFeatured);
|
|
233
|
+
}
|
|
289
234
|
nftItem.collectionId = smartContract;
|
|
290
235
|
nftItem.chain = this.chain;
|
|
291
236
|
nftItem.type = _types._AssetType.PSP34;
|
|
@@ -300,8 +245,6 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
300
245
|
}
|
|
301
246
|
}
|
|
302
247
|
}));
|
|
303
|
-
|
|
304
|
-
nftOwnerMap[address] = nftIds;
|
|
305
248
|
} catch (e) {
|
|
306
249
|
console.error(`error parsing item for ${this.chain} nft`, e);
|
|
307
250
|
}
|
|
@@ -321,10 +264,6 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
321
264
|
originAsset: tokenInfo.slug
|
|
322
265
|
};
|
|
323
266
|
nftParams.updateCollection(this.chain, nftCollection);
|
|
324
|
-
Object.entries(nftOwnerMap).forEach(_ref => {
|
|
325
|
-
let [owner, nftIds] = _ref;
|
|
326
|
-
nftParams.cleanUpNfts(this.chain, owner, smartContract, nftIds);
|
|
327
|
-
});
|
|
328
267
|
}
|
|
329
268
|
}
|
|
330
269
|
async fetchNfts(params) {
|
|
@@ -336,17 +275,20 @@ class WasmNftApi extends _nft.BaseNftApi {
|
|
|
336
275
|
return 1;
|
|
337
276
|
}
|
|
338
277
|
async handleNfts(params) {
|
|
339
|
-
var _this$
|
|
278
|
+
var _this$substrateApi;
|
|
340
279
|
if (!this.wasmContracts || this.wasmContracts.length === 0) {
|
|
341
280
|
return;
|
|
342
281
|
}
|
|
343
282
|
await this.connect(); // might not be necessary
|
|
344
283
|
|
|
345
|
-
const apiPromise = (_this$
|
|
284
|
+
const apiPromise = (_this$substrateApi = this.substrateApi) === null || _this$substrateApi === void 0 ? void 0 : _this$substrateApi.api;
|
|
346
285
|
await Promise.all(this.wasmContracts.map(async tokenInfo => {
|
|
347
|
-
const contractPromise = (0, _wasm.getPSP34ContractPromise)(apiPromise, (0,
|
|
348
|
-
const
|
|
349
|
-
|
|
286
|
+
const contractPromise = (0, _wasm.getPSP34ContractPromise)(apiPromise, (0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
287
|
+
const {
|
|
288
|
+
attributeList,
|
|
289
|
+
storedOnChain
|
|
290
|
+
} = await this.getCollectionAttributes(contractPromise);
|
|
291
|
+
return await this.getItemsByCollection(contractPromise, attributeList, storedOnChain, tokenInfo, tokenInfo.name, params);
|
|
350
292
|
}));
|
|
351
293
|
}
|
|
352
294
|
}
|
|
@@ -3,21 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.ART_ZERO_IPFS_API = exports.ART_ZERO_IMAGE_API = exports.ART_ZERO_EXTERNAL_URL = exports.ART_ZERO_CONTRACTS = exports.ART_ZERO_COLLECTION_API = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
exports.
|
|
12
|
-
const
|
|
13
|
-
exports.ART_ZERO_TESTNET_IPFS_API = ART_ZERO_TESTNET_IPFS_API;
|
|
14
|
-
const ART_ZERO_TESTNET_COLLECTION_API = 'https://a0-test-api.artzero.io/getCollectionByAddress';
|
|
15
|
-
exports.ART_ZERO_TESTNET_COLLECTION_API = ART_ZERO_TESTNET_COLLECTION_API;
|
|
16
|
-
const ART_ZERO_IMAGE_API = 'https://a0-api.artzero.io/getImage';
|
|
10
|
+
const ART_ZERO_CONTRACTS = ['5Hg1xe6JAGZj92wxtj1ykAfQpwwRNqzAnvhZ3TuXZEmLU1Vw'];
|
|
11
|
+
exports.ART_ZERO_CONTRACTS = ART_ZERO_CONTRACTS;
|
|
12
|
+
const ART_ZERO_IMAGE_API = 'https://api.artzero.io/getImage';
|
|
17
13
|
exports.ART_ZERO_IMAGE_API = ART_ZERO_IMAGE_API;
|
|
18
|
-
const ART_ZERO_IPFS_API = 'https://
|
|
14
|
+
const ART_ZERO_IPFS_API = 'https://api.artzero.io/getJSON';
|
|
19
15
|
exports.ART_ZERO_IPFS_API = ART_ZERO_IPFS_API;
|
|
20
|
-
const ART_ZERO_COLLECTION_API = 'https://
|
|
16
|
+
const ART_ZERO_COLLECTION_API = 'https://api.artzero.io/getCollectionByAddress';
|
|
21
17
|
exports.ART_ZERO_COLLECTION_API = ART_ZERO_COLLECTION_API;
|
|
22
|
-
const ART_ZERO_EXTERNAL_URL = 'https://
|
|
18
|
+
const ART_ZERO_EXTERNAL_URL = 'https://artzero.io/demotestnet/#/marketplace';
|
|
23
19
|
exports.ART_ZERO_EXTERNAL_URL = ART_ZERO_EXTERNAL_URL;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getAmplitudeBondingExtrinsic = getAmplitudeBondingExtrinsic;
|
|
7
|
+
exports.getAmplitudeCancelWithdrawalExtrinsic = getAmplitudeCancelWithdrawalExtrinsic;
|
|
7
8
|
exports.getAmplitudeClaimRewardExtrinsic = getAmplitudeClaimRewardExtrinsic;
|
|
8
9
|
exports.getAmplitudeCollatorsInfo = getAmplitudeCollatorsInfo;
|
|
9
10
|
exports.getAmplitudeNominatorMetadata = getAmplitudeNominatorMetadata;
|
|
@@ -51,31 +52,24 @@ async function getAmplitudeNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
51
52
|
const nominationList = [];
|
|
52
53
|
const unstakingList = [];
|
|
53
54
|
const [_delegatorState, _unstakingInfo] = await Promise.all([chainApi.api.query.parachainStaking.delegatorState(address), chainApi.api.query.parachainStaking.unstaking(address)]);
|
|
54
|
-
const minDelegatorStake = chainApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
55
55
|
const delegatorState = _delegatorState.toPrimitive();
|
|
56
56
|
const unstakingInfo = _unstakingInfo.toPrimitive();
|
|
57
|
-
console.log('unstakingInfo ampe', unstakingInfo, !!unstakingInfo);
|
|
58
57
|
if (!delegatorState && !unstakingInfo) {
|
|
59
58
|
return;
|
|
60
59
|
}
|
|
61
60
|
let activeStake = '0';
|
|
62
61
|
if (delegatorState) {
|
|
63
62
|
// delegatorState can be null while unstaking all
|
|
64
|
-
const identityInfo =
|
|
65
|
-
const identity =
|
|
63
|
+
const identityInfo = (await chainApi.api.query.identity.identityOf(delegatorState.owner)).toPrimitive();
|
|
64
|
+
const identity = (0, _utils.parseIdentity)(identityInfo);
|
|
66
65
|
activeStake = delegatorState.amount.toString();
|
|
67
|
-
const bnActiveStake = new _util.BN(activeStake);
|
|
68
|
-
let delegationStatus = _KoniTypes.StakingStatus.NOT_EARNING;
|
|
69
|
-
if (bnActiveStake.gt(_util.BN_ZERO) && bnActiveStake.gte(new _util.BN(minDelegatorStake))) {
|
|
70
|
-
delegationStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
71
|
-
}
|
|
72
66
|
nominationList.push({
|
|
73
|
-
status:
|
|
67
|
+
status: _KoniTypes.StakingStatus.NOT_EARNING,
|
|
74
68
|
chain,
|
|
75
69
|
validatorAddress: delegatorState.owner,
|
|
76
70
|
activeStake: delegatorState.amount.toString(),
|
|
77
71
|
validatorMinStake: '0',
|
|
78
|
-
hasUnstaking: !!unstakingInfo
|
|
72
|
+
hasUnstaking: !!unstakingInfo,
|
|
79
73
|
validatorIdentity: identity
|
|
80
74
|
});
|
|
81
75
|
}
|
|
@@ -103,11 +97,9 @@ async function getAmplitudeNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
103
97
|
if (nominationList.length === 0 && unstakingList.length === 0) {
|
|
104
98
|
return;
|
|
105
99
|
}
|
|
106
|
-
const stakingStatus = (0, _utils.getStakingStatusByNominations)(new _util.BN(activeStake), nominationList);
|
|
107
100
|
return {
|
|
108
101
|
chain,
|
|
109
102
|
type: _KoniTypes.StakingType.NOMINATED,
|
|
110
|
-
status: stakingStatus,
|
|
111
103
|
address: address,
|
|
112
104
|
activeStake: activeStake,
|
|
113
105
|
nominations: nominationList,
|
|
@@ -188,4 +180,8 @@ async function getAmplitudeWithdrawalExtrinsic(substrateApi, address) {
|
|
|
188
180
|
async function getAmplitudeClaimRewardExtrinsic(substrateApi) {
|
|
189
181
|
const chainApi = await substrateApi.isReady;
|
|
190
182
|
return chainApi.api.tx.utility.batch([chainApi.api.tx.parachainStaking.incrementDelegatorRewards(), chainApi.api.tx.parachainStaking.claimRewards()]);
|
|
183
|
+
}
|
|
184
|
+
async function getAmplitudeCancelWithdrawalExtrinsic(substrateApi) {
|
|
185
|
+
const chainApi = await substrateApi.isReady;
|
|
186
|
+
return chainApi.api.tx.parachainStaking.cancelLeaveCandidates();
|
|
191
187
|
}
|