@subwallet/extension-base 1.0.6-1 → 1.0.7-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.
@@ -902,6 +902,11 @@ export interface AddNetworkRequestExternal {
902
902
  chainName: string;
903
903
  blockExplorerUrls?: string[];
904
904
  requestId?: string;
905
+ nativeCurrency: {
906
+ name: string;
907
+ symbol: string;
908
+ decimals: number;
909
+ };
905
910
  }
906
911
  export interface AddNetworkExternalRequest {
907
912
  chainId: string;
@@ -918,6 +923,8 @@ export interface AddTokenRequestExternal {
918
923
  name: string;
919
924
  symbol: string;
920
925
  decimals: number;
926
+ validated: boolean;
927
+ contractError: boolean;
921
928
  }
922
929
  export interface ConfirmationDefinitions {
923
930
  addNetworkRequest: [ConfirmationsQueueItem<_NetworkUpsertParams>, ConfirmationResult<null>];
@@ -32,7 +32,7 @@ async function isArtZeroFeaturedCollection(networkKey, contractAddress) {
32
32
  const urlencoded = new URLSearchParams();
33
33
  urlencoded.append('collection_address', contractAddress);
34
34
  const collectionInfoPromise = new Promise(function (resolve) {
35
- (0, _crossFetch.default)(`${networkKey === 'alephTest' ? _utils.ART_ZERO_TESTNET_COLLECTION_API : _utils.ART_ZERO_COLLECTION_API}`, {
35
+ (0, _crossFetch.default)((0, _utils.collectionApiFromArtZero)(networkKey), {
36
36
  method: 'POST',
37
37
  headers: {
38
38
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -55,6 +55,20 @@ class WasmNftApi extends _nft.BaseNftApi {
55
55
  setSmartContractNfts(wasmContracts) {
56
56
  this.wasmContracts = wasmContracts;
57
57
  }
58
+ async isAttributeStoredOnChain(contractPromise) {
59
+ var _this$substrateApi, _onChainAttributeCoun;
60
+ if (!contractPromise.query['psp34Traits::getAttributeCount']) {
61
+ return false;
62
+ }
63
+
64
+ // @ts-ignore
65
+ const _onChainAttributeCount = await contractPromise.query['psp34Traits::getAttributeCount'](this.addresses[0], {
66
+ gasLimit: (0, _utils2.getDefaultWeightV2)((_this$substrateApi = this.substrateApi) === null || _this$substrateApi === void 0 ? void 0 : _this$substrateApi.api)
67
+ });
68
+ const _attributeCount = _onChainAttributeCount === null || _onChainAttributeCount === void 0 ? void 0 : (_onChainAttributeCoun = _onChainAttributeCount.output) === null || _onChainAttributeCoun === void 0 ? void 0 : _onChainAttributeCoun.toJSON();
69
+ const onChainAttributeCount = _onChainAttributeCount.output ? (_attributeCount === null || _attributeCount === void 0 ? void 0 : _attributeCount.ok) || (_attributeCount === null || _attributeCount === void 0 ? void 0 : _attributeCount.Ok) : '0';
70
+ return parseInt(onChainAttributeCount) !== 0;
71
+ }
58
72
  parseFeaturedTokenUri(tokenUri) {
59
73
  if (!tokenUri || tokenUri.length === 0) {
60
74
  return undefined;
@@ -78,7 +92,7 @@ class WasmNftApi extends _nft.BaseNftApi {
78
92
  if (!parsedTokenUri) {
79
93
  return undefined;
80
94
  }
81
- const nftItemImageSrc = `${this.chain === 'alephTest' ? _utils.ART_ZERO_TESTNET_IMAGE_API : _utils.ART_ZERO_IMAGE_API}?input=${parsedTokenUri}&size=500`;
95
+ const nftItemImageSrc = `${(0, _utils.itemImageApiFromArtZero)(this.chain)}?input=${parsedTokenUri}&size=500`;
82
96
  const collectionImageUrl = await (0, _axios.default)(nftItemImageSrc, {
83
97
  method: 'GET'
84
98
  });
@@ -87,7 +101,7 @@ class WasmNftApi extends _nft.BaseNftApi {
87
101
  async parseFeaturedCollectionImage(smartContract) {
88
102
  const urlencoded = new URLSearchParams();
89
103
  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, {
104
+ const resp = await (0, _crossFetch.default)((0, _utils.collectionDetailApiFromArtZero)(this.chain), {
91
105
  method: 'POST',
92
106
  headers: {
93
107
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -106,7 +120,7 @@ class WasmNftApi extends _nft.BaseNftApi {
106
120
  if (!parsedCollectionImage) {
107
121
  return;
108
122
  }
109
- const collectionImageSrc = `${this.chain === 'alephTest' ? _utils.ART_ZERO_TESTNET_IMAGE_API : _utils.ART_ZERO_IMAGE_API}?input=${parsedCollectionImage}&size=500`;
123
+ const collectionImageSrc = `${(0, _utils.itemImageApiFromArtZero)(this.chain)}?input=${parsedCollectionImage}&size=500`;
110
124
  const collectionImageUrl = await (0, _axios.default)(collectionImageSrc, {
111
125
  method: 'GET'
112
126
  });
@@ -189,8 +203,55 @@ class WasmNftApi extends _nft.BaseNftApi {
189
203
  // return nftItem;
190
204
  // }
191
205
 
206
+ async processOnChainMetadata(tokenId, isFeatured, tokenUri) {
207
+ const nftItem = {
208
+ chain: '',
209
+ collectionId: '',
210
+ id: '',
211
+ owner: '',
212
+ name: tokenId
213
+ };
214
+ let itemDetail = false;
215
+ if (isFeatured) {
216
+ const parsedTokenUri = this.parseFeaturedTokenUri(tokenUri);
217
+ if (parsedTokenUri) {
218
+ const resp = await (0, _crossFetch.default)(`${(0, _utils.ipfsApiFromArtZero)(this.chain)}?input=${parsedTokenUri}`);
219
+ itemDetail = resp && resp.ok && (await resp.json());
220
+ }
221
+ } else {
222
+ const parsedTokenUri = this.parseFeaturedTokenUri(tokenUri);
223
+ const detailUrl = this.parseUrl(parsedTokenUri);
224
+ if (detailUrl) {
225
+ const resp = await (0, _crossFetch.default)(detailUrl);
226
+ itemDetail = resp && resp.ok && (await resp.json());
227
+ }
228
+ }
229
+ if (!itemDetail) {
230
+ return nftItem;
231
+ }
232
+ nftItem.name = itemDetail.name;
233
+ nftItem.description = itemDetail.description;
234
+ const rawImageSrc = itemDetail.image ? itemDetail.image : itemDetail.image_url;
235
+ if (isFeatured) {
236
+ nftItem.image = await this.parseFeaturedNftImage(rawImageSrc);
237
+ nftItem.externalUrl = (0, _utils.externalUrlOnArtZero)(this.chain);
238
+ } else {
239
+ nftItem.image = this.parseUrl(rawImageSrc);
240
+ }
241
+ const propertiesMap = {};
242
+ const traitList = itemDetail.attributes ? itemDetail.attributes : itemDetail.traits;
243
+ if (traitList) {
244
+ traitList.forEach(traitMap => {
245
+ propertiesMap[traitMap.trait_type] = {
246
+ value: traitMap.value
247
+ };
248
+ });
249
+ nftItem.properties = propertiesMap;
250
+ }
251
+ return nftItem;
252
+ }
192
253
  async processOffChainMetadata(contractPromise, address, tokenId, isFeatured) {
193
- var _this$substrateApi;
254
+ var _this$substrateApi2;
194
255
  const nftItem = {
195
256
  chain: '',
196
257
  collectionId: '',
@@ -199,7 +260,7 @@ class WasmNftApi extends _nft.BaseNftApi {
199
260
  name: tokenId
200
261
  };
201
262
  const _tokenUri = await contractPromise.query['psp34Traits::tokenUri'](address, {
202
- gasLimit: (0, _utils2.getDefaultWeightV2)((_this$substrateApi = this.substrateApi) === null || _this$substrateApi === void 0 ? void 0 : _this$substrateApi.api)
263
+ gasLimit: (0, _utils2.getDefaultWeightV2)((_this$substrateApi2 = this.substrateApi) === null || _this$substrateApi2 === void 0 ? void 0 : _this$substrateApi2.api)
203
264
  }, tokenId);
204
265
  if (_tokenUri.output) {
205
266
  let itemDetail = false;
@@ -210,7 +271,7 @@ class WasmNftApi extends _nft.BaseNftApi {
210
271
  if (isFeatured) {
211
272
  const parsedTokenUri = this.parseFeaturedTokenUri(tokenUri);
212
273
  if (parsedTokenUri) {
213
- const resp = await (0, _crossFetch.default)(`${this.chain === 'alephTest' ? _utils.ART_ZERO_TESTNET_IPFS_API : _utils.ART_ZERO_IPFS_API}?input=${parsedTokenUri}`);
274
+ const resp = await (0, _crossFetch.default)(`${(0, _utils.ipfsApiFromArtZero)(this.chain)}?input=${parsedTokenUri}`);
214
275
  itemDetail = resp && resp.ok && (await resp.json());
215
276
  }
216
277
  } else {
@@ -230,7 +291,7 @@ class WasmNftApi extends _nft.BaseNftApi {
230
291
  const rawImageSrc = itemDetail.image ? itemDetail.image : itemDetail.image_url;
231
292
  if (isFeatured) {
232
293
  nftItem.image = await this.parseFeaturedNftImage(rawImageSrc);
233
- nftItem.externalUrl = _utils.ART_ZERO_EXTERNAL_URL;
294
+ nftItem.externalUrl = (0, _utils.externalUrlOnArtZero)(this.chain);
234
295
  } else {
235
296
  nftItem.image = this.parseUrl(rawImageSrc);
236
297
  }
@@ -247,19 +308,19 @@ class WasmNftApi extends _nft.BaseNftApi {
247
308
  }
248
309
  return nftItem;
249
310
  }
250
- async getItemsByCollection(contractPromise, tokenInfo, collectionName, nftParams, isFeatured) {
311
+ async getItemsByCollection(contractPromise, tokenInfo, collectionName, nftParams, isFeatured, isAttributeOnChain) {
251
312
  let ownItem = false;
252
313
  let collectionImage;
253
314
  const smartContract = (0, _utils3._getContractAddressOfToken)(tokenInfo);
254
315
  const nftOwnerMap = {};
255
316
  await Promise.all(this.addresses.map(async address => {
256
- var _this$substrateApi2, _balance$output;
317
+ var _this$substrateApi3, _balance$output;
257
318
  if ((0, _utilCrypto.isEthereumAddress)(address)) {
258
319
  return;
259
320
  }
260
321
  const nftIds = [];
261
322
  const _balance = await contractPromise.query['psp34::balanceOf'](address, {
262
- gasLimit: (0, _utils2.getDefaultWeightV2)((_this$substrateApi2 = this.substrateApi) === null || _this$substrateApi2 === void 0 ? void 0 : _this$substrateApi2.api)
323
+ gasLimit: (0, _utils2.getDefaultWeightV2)((_this$substrateApi3 = this.substrateApi) === null || _this$substrateApi3 === void 0 ? void 0 : _this$substrateApi3.api)
263
324
  }, address);
264
325
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
265
326
  const balanceJson = _balance === null || _balance === void 0 ? void 0 : (_balance$output = _balance.output) === null || _balance$output === void 0 ? void 0 : _balance$output.toJSON();
@@ -275,9 +336,9 @@ class WasmNftApi extends _nft.BaseNftApi {
275
336
  }
276
337
  try {
277
338
  await Promise.all(itemIndexes.map(async i => {
278
- var _this$substrateApi3;
339
+ var _this$substrateApi4;
279
340
  const _tokenByIndexResp = await contractPromise.query['psp34Enumerable::ownersTokenByIndex'](address, {
280
- gasLimit: (0, _utils2.getDefaultWeightV2)((_this$substrateApi3 = this.substrateApi) === null || _this$substrateApi3 === void 0 ? void 0 : _this$substrateApi3.api)
341
+ gasLimit: (0, _utils2.getDefaultWeightV2)((_this$substrateApi4 = this.substrateApi) === null || _this$substrateApi4 === void 0 ? void 0 : _this$substrateApi4.api)
281
342
  }, address, i);
282
343
  if (_tokenByIndexResp.output) {
283
344
  const rawTokenId = _tokenByIndexResp.output.toHuman();
@@ -285,18 +346,47 @@ class WasmNftApi extends _nft.BaseNftApi {
285
346
  const tokenIdObj = rawTokenId.Ok.Ok || rawTokenId.ok.ok; // capital O, not normal o
286
347
  const tokenId = Object.values(tokenIdObj)[0].replaceAll(',', '');
287
348
  nftIds.push(tokenId);
288
- const nftItem = await this.processOffChainMetadata(contractPromise, address, tokenId, isFeatured);
289
- nftItem.collectionId = smartContract;
290
- nftItem.chain = this.chain;
291
- nftItem.type = _types._AssetType.PSP34;
292
- nftItem.id = tokenId;
293
- nftItem.owner = address;
294
- nftItem.onChainOption = tokenIdObj;
295
- nftItem.originAsset = tokenInfo.slug;
296
- nftParams.updateItem(this.chain, nftItem, address);
297
- ownItem = true;
298
- if (!isFeatured && !collectionImage && nftItem.image) {
299
- collectionImage = nftItem.image; // No default collection image
349
+ let tokenUri;
350
+ try {
351
+ if (isAttributeOnChain) {
352
+ var _this$substrateApi5, _tokenUri$output;
353
+ const _tokenUri = await contractPromise.query['psp34Traits::getAttributes'](address, {
354
+ gasLimit: (0, _utils2.getDefaultWeightV2)((_this$substrateApi5 = this.substrateApi) === null || _this$substrateApi5 === void 0 ? void 0 : _this$substrateApi5.api)
355
+ }, tokenIdObj, ['metadata']);
356
+ const tokenUriObj = (_tokenUri$output = _tokenUri.output) === null || _tokenUri$output === void 0 ? void 0 : _tokenUri$output.toJSON();
357
+ tokenUri = (tokenUriObj.ok || tokenUriObj.Ok)[0];
358
+ }
359
+ } catch (e) {
360
+ console.debug(e);
361
+ }
362
+ if (!tokenUri) {
363
+ const nftItem = await this.processOffChainMetadata(contractPromise, address, tokenId, isFeatured);
364
+ nftItem.collectionId = smartContract;
365
+ nftItem.chain = this.chain;
366
+ nftItem.type = _types._AssetType.PSP34;
367
+ nftItem.id = tokenId;
368
+ nftItem.owner = address;
369
+ nftItem.onChainOption = tokenIdObj;
370
+ nftItem.originAsset = tokenInfo.slug;
371
+ nftParams.updateItem(this.chain, nftItem, address);
372
+ ownItem = true;
373
+ if (!isFeatured && !collectionImage && nftItem.image) {
374
+ collectionImage = nftItem.image; // No default collection image
375
+ }
376
+ } else {
377
+ const nftItem = await this.processOnChainMetadata(tokenId, false, tokenUri);
378
+ nftItem.collectionId = smartContract;
379
+ nftItem.chain = this.chain;
380
+ nftItem.type = _types._AssetType.PSP34;
381
+ nftItem.id = tokenId;
382
+ nftItem.owner = address;
383
+ nftItem.onChainOption = tokenIdObj;
384
+ nftItem.originAsset = tokenInfo.slug;
385
+ nftParams.updateItem(this.chain, nftItem, address);
386
+ ownItem = true;
387
+ if (!isFeatured && !collectionImage && nftItem.image) {
388
+ collectionImage = nftItem.image; // No default collection image
389
+ }
300
390
  }
301
391
  }
302
392
  }));
@@ -336,17 +426,17 @@ class WasmNftApi extends _nft.BaseNftApi {
336
426
  return 1;
337
427
  }
338
428
  async handleNfts(params) {
339
- var _this$substrateApi4;
429
+ var _this$substrateApi6;
340
430
  if (!this.wasmContracts || this.wasmContracts.length === 0) {
341
431
  return;
342
432
  }
343
433
  await this.connect(); // might not be necessary
344
434
 
345
- const apiPromise = (_this$substrateApi4 = this.substrateApi) === null || _this$substrateApi4 === void 0 ? void 0 : _this$substrateApi4.api;
435
+ const apiPromise = (_this$substrateApi6 = this.substrateApi) === null || _this$substrateApi6 === void 0 ? void 0 : _this$substrateApi6.api;
346
436
  await Promise.all(this.wasmContracts.map(async tokenInfo => {
347
437
  const contractPromise = (0, _wasm.getPSP34ContractPromise)(apiPromise, (0, _utils3._getContractAddressOfToken)(tokenInfo));
348
- const isCollectionFeatured = await isArtZeroFeaturedCollection(this.chain, (0, _utils3._getContractAddressOfToken)(tokenInfo));
349
- return await this.getItemsByCollection(contractPromise, tokenInfo, tokenInfo.name, params, isCollectionFeatured);
438
+ const [isAttributeOnChain, isCollectionFeatured] = await Promise.all([this.isAttributeStoredOnChain(contractPromise), isArtZeroFeaturedCollection(this.chain, (0, _utils3._getContractAddressOfToken)(tokenInfo))]);
439
+ return await this.getItemsByCollection(contractPromise, tokenInfo, tokenInfo.name, params, isCollectionFeatured, isAttributeOnChain);
350
440
  }));
351
441
  }
352
442
  }
@@ -3,21 +3,82 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ART_ZERO_TESTNET_IPFS_API = exports.ART_ZERO_TESTNET_IMAGE_API = exports.ART_ZERO_TESTNET_COLLECTION_API = exports.ART_ZERO_IPFS_API = exports.ART_ZERO_IMAGE_API = exports.ART_ZERO_EXTERNAL_URL = exports.ART_ZERO_COLLECTION_API = void 0;
6
+ exports.ASTAR_ART_ZERO_TESTNET_IPFS_API = exports.ASTAR_ART_ZERO_TESTNET_IMAGE_API = exports.ASTAR_ART_ZERO_TESTNET_COLLECTION_API = exports.ASTAR_ART_ZERO_IPFS_API = exports.ASTAR_ART_ZERO_IMAGE_API = exports.ASTAR_ART_ZERO_EXTERNAL_URL = exports.ASTAR_ART_ZERO_COLLECTION_API = exports.ART_ZERO_TESTNET_IPFS_API = exports.A0_ART_ZERO_TESTNET_IMAGE_API = exports.A0_ART_ZERO_TESTNET_COLLECTION_API = exports.A0_ART_ZERO_IPFS_API = exports.A0_ART_ZERO_IMAGE_API = exports.A0_ART_ZERO_EXTERNAL_URL = exports.A0_ART_ZERO_COLLECTION_API = void 0;
7
+ exports.collectionApiFromArtZero = collectionApiFromArtZero;
8
+ exports.collectionDetailApiFromArtZero = collectionDetailApiFromArtZero;
9
+ exports.externalUrlOnArtZero = externalUrlOnArtZero;
10
+ exports.ipfsApiFromArtZero = ipfsApiFromArtZero;
11
+ exports.itemImageApiFromArtZero = itemImageApiFromArtZero;
7
12
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
8
13
  // SPDX-License-Identifier: Apache-2.0
9
14
 
10
- const ART_ZERO_TESTNET_IMAGE_API = 'https://a0-test-api.artzero.io/getImage';
11
- exports.ART_ZERO_TESTNET_IMAGE_API = ART_ZERO_TESTNET_IMAGE_API;
15
+ const A0_ART_ZERO_TESTNET_IMAGE_API = 'https://a0-test-api.artzero.io/getImage';
16
+ exports.A0_ART_ZERO_TESTNET_IMAGE_API = A0_ART_ZERO_TESTNET_IMAGE_API;
17
+ const ASTAR_ART_ZERO_TESTNET_IMAGE_API = 'https://astar-test-api.artzero.io/getImage';
18
+ exports.ASTAR_ART_ZERO_TESTNET_IMAGE_API = ASTAR_ART_ZERO_TESTNET_IMAGE_API;
12
19
  const ART_ZERO_TESTNET_IPFS_API = 'https://a0-test-api.artzero.io/getJSON';
13
20
  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';
17
- exports.ART_ZERO_IMAGE_API = ART_ZERO_IMAGE_API;
18
- const ART_ZERO_IPFS_API = 'https://a0-api.artzero.io/getJSON';
19
- exports.ART_ZERO_IPFS_API = ART_ZERO_IPFS_API;
20
- const ART_ZERO_COLLECTION_API = 'https://a0-api.artzero.io/getCollectionByAddress';
21
- exports.ART_ZERO_COLLECTION_API = ART_ZERO_COLLECTION_API;
22
- const ART_ZERO_EXTERNAL_URL = 'https://a0.artzero.io/#/marketplace';
23
- exports.ART_ZERO_EXTERNAL_URL = ART_ZERO_EXTERNAL_URL;
21
+ const ASTAR_ART_ZERO_TESTNET_IPFS_API = 'https://astar-test-api.artzero.io/getJSON';
22
+ exports.ASTAR_ART_ZERO_TESTNET_IPFS_API = ASTAR_ART_ZERO_TESTNET_IPFS_API;
23
+ const A0_ART_ZERO_TESTNET_COLLECTION_API = 'https://a0-test-api.artzero.io/getCollectionByAddress';
24
+ exports.A0_ART_ZERO_TESTNET_COLLECTION_API = A0_ART_ZERO_TESTNET_COLLECTION_API;
25
+ const ASTAR_ART_ZERO_TESTNET_COLLECTION_API = 'https://astar-test-api.artzero.io/getCollectionByAddress';
26
+ exports.ASTAR_ART_ZERO_TESTNET_COLLECTION_API = ASTAR_ART_ZERO_TESTNET_COLLECTION_API;
27
+ const A0_ART_ZERO_IMAGE_API = 'https://a0-api.artzero.io/getImage';
28
+ exports.A0_ART_ZERO_IMAGE_API = A0_ART_ZERO_IMAGE_API;
29
+ const ASTAR_ART_ZERO_IMAGE_API = 'https://astar-api.artzero.io/getImage';
30
+ exports.ASTAR_ART_ZERO_IMAGE_API = ASTAR_ART_ZERO_IMAGE_API;
31
+ const A0_ART_ZERO_IPFS_API = 'https://a0-api.artzero.io/getJSON';
32
+ exports.A0_ART_ZERO_IPFS_API = A0_ART_ZERO_IPFS_API;
33
+ const ASTAR_ART_ZERO_IPFS_API = 'https://astar-api.artzero.io/getJSON';
34
+ exports.ASTAR_ART_ZERO_IPFS_API = ASTAR_ART_ZERO_IPFS_API;
35
+ const A0_ART_ZERO_COLLECTION_API = 'https://a0-api.artzero.io/getCollectionByAddress';
36
+ exports.A0_ART_ZERO_COLLECTION_API = A0_ART_ZERO_COLLECTION_API;
37
+ const ASTAR_ART_ZERO_COLLECTION_API = 'https://astar-api.artzero.io/getCollectionByAddress';
38
+ exports.ASTAR_ART_ZERO_COLLECTION_API = ASTAR_ART_ZERO_COLLECTION_API;
39
+ const A0_ART_ZERO_EXTERNAL_URL = 'https://a0.artzero.io/#/marketplace';
40
+ exports.A0_ART_ZERO_EXTERNAL_URL = A0_ART_ZERO_EXTERNAL_URL;
41
+ const ASTAR_ART_ZERO_EXTERNAL_URL = 'https://astar.artzero.io/#/marketplace';
42
+ exports.ASTAR_ART_ZERO_EXTERNAL_URL = ASTAR_ART_ZERO_EXTERNAL_URL;
43
+ function collectionApiFromArtZero(chain) {
44
+ if (chain === 'alephTest') {
45
+ return A0_ART_ZERO_TESTNET_COLLECTION_API;
46
+ }
47
+ if (chain === 'astar') {
48
+ return ASTAR_ART_ZERO_COLLECTION_API;
49
+ }
50
+ return A0_ART_ZERO_COLLECTION_API;
51
+ }
52
+ function itemImageApiFromArtZero(chain) {
53
+ if (chain === 'alephTest') {
54
+ return A0_ART_ZERO_TESTNET_IMAGE_API;
55
+ }
56
+ if (chain === 'astar') {
57
+ return ASTAR_ART_ZERO_IMAGE_API;
58
+ }
59
+ return A0_ART_ZERO_IMAGE_API;
60
+ }
61
+ function collectionDetailApiFromArtZero(chain) {
62
+ if (chain === 'alephTest') {
63
+ return A0_ART_ZERO_TESTNET_COLLECTION_API;
64
+ }
65
+ if (chain === 'astar') {
66
+ return ASTAR_ART_ZERO_COLLECTION_API;
67
+ }
68
+ return A0_ART_ZERO_COLLECTION_API;
69
+ }
70
+ function ipfsApiFromArtZero(chain) {
71
+ if (chain === 'alephTest') {
72
+ return ART_ZERO_TESTNET_IPFS_API;
73
+ }
74
+ if (chain === 'astar') {
75
+ return ASTAR_ART_ZERO_IPFS_API;
76
+ }
77
+ return A0_ART_ZERO_IPFS_API;
78
+ }
79
+ function externalUrlOnArtZero(chain) {
80
+ if (chain === 'astar') {
81
+ return ASTAR_ART_ZERO_EXTERNAL_URL;
82
+ }
83
+ return A0_ART_ZERO_EXTERNAL_URL;
84
+ }
@@ -1370,6 +1370,7 @@ class KoniState {
1370
1370
  await this.priceService.stop();
1371
1371
  }
1372
1372
  async wakeup() {
1373
+ await this.eventService.waitChainReady;
1373
1374
  await this.resumeAllNetworks();
1374
1375
  this.cron.start();
1375
1376
  this.subscription.start();
@@ -14,6 +14,7 @@ var _RequestBytesSign = _interopRequireDefault(require("@subwallet/extension-bas
14
14
  var _RequestExtrinsicSign = _interopRequireDefault(require("@subwallet/extension-base/background/RequestExtrinsicSign"));
15
15
  var _constants = require("@subwallet/extension-base/constants");
16
16
  var _defaults = require("@subwallet/extension-base/defaults");
17
+ var _types2 = require("@subwallet/extension-base/services/chain-service/handler/types");
17
18
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
18
19
  var _constants2 = require("@subwallet/extension-base/services/setting-service/constants");
19
20
  var _utils2 = require("@subwallet/extension-base/utils");
@@ -405,7 +406,7 @@ class KoniTabs {
405
406
  return null;
406
407
  }
407
408
  async addEvmToken(id, url, _ref13) {
408
- var _input$type, _input$options, _input$options2;
409
+ var _input$type, _input$options, _input$options2, _input$options3, _input$options4, _input$options5;
409
410
  let {
410
411
  params
411
412
  } = _ref13;
@@ -423,28 +424,42 @@ class KoniTabs {
423
424
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INTERNAL_ERROR, 'Current chain is not available');
424
425
  }
425
426
  const tokenType = _tokenType === 'erc20' ? _types._AssetType.ERC20 : _types._AssetType.ERC721;
426
- const validate = await this.#koniState.validateCustomAsset({
427
+ const tokenInfo = {
428
+ slug: '',
429
+ type: tokenType,
430
+ name: (input === null || input === void 0 ? void 0 : (_input$options3 = input.options) === null || _input$options3 === void 0 ? void 0 : _input$options3.symbol) || '',
431
+ contractAddress: input.options.address,
432
+ symbol: (input === null || input === void 0 ? void 0 : (_input$options4 = input.options) === null || _input$options4 === void 0 ? void 0 : _input$options4.symbol) || '',
433
+ decimals: (input === null || input === void 0 ? void 0 : (_input$options5 = input.options) === null || _input$options5 === void 0 ? void 0 : _input$options5.decimals) || 0,
434
+ originChain: chain,
435
+ contractError: false,
436
+ validated: false
437
+ };
438
+ this.#koniState.validateCustomAsset({
427
439
  type: tokenType,
428
440
  contractAddress: input.options.address,
429
441
  originChain: chain
442
+ }).then(validate => {
443
+ if (validate.contractError) {
444
+ tokenInfo.contractError = true;
445
+ } else {
446
+ tokenInfo.slug = validate === null || validate === void 0 ? void 0 : validate.existedSlug;
447
+ tokenInfo.name = validate.name;
448
+ tokenInfo.symbol = validate.symbol;
449
+ tokenInfo.decimals = validate.decimals;
450
+ }
451
+ }).catch(() => {
452
+ tokenInfo.contractError = true;
453
+ }).finally(() => {
454
+ tokenInfo.validated = true;
455
+ this.#koniState.requestService.updateConfirmation(id, 'addTokenRequest', tokenInfo);
430
456
  });
431
457
 
432
458
  // Below code is comment because we will handle exited token in the ui-view
433
459
  // if (validate.isExist) {
434
460
  // throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, 'Current token is existed');
435
461
  // } else
436
- if (validate.contractError) {
437
- throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Contract address is invalid');
438
- }
439
- const tokenInfo = {
440
- slug: validate === null || validate === void 0 ? void 0 : validate.existedSlug,
441
- type: tokenType,
442
- name: validate.name,
443
- contractAddress: input.options.address,
444
- symbol: validate.symbol,
445
- decimals: validate.decimals,
446
- originChain: chain
447
- };
462
+
448
463
  return await this.#koniState.addTokenConfirm(id, url, tokenInfo);
449
464
  }
450
465
  async addEvmChain(id, url, _ref14) {
@@ -457,6 +472,10 @@ class KoniTabs {
457
472
  blockExplorerUrls,
458
473
  chainId,
459
474
  chainName,
475
+ nativeCurrency: {
476
+ decimals,
477
+ symbol
478
+ },
460
479
  rpcUrls
461
480
  } = input[0];
462
481
  if (chainId) {
@@ -507,12 +526,19 @@ class KoniTabs {
507
526
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INTERNAL_ERROR, 'Currently HTTP provider for EVM network');
508
527
  }
509
528
  const provider = filteredUrls[0];
510
- const chainInfo = await this.#koniState.validateCustomChain(provider);
511
- if (!chainInfo.success) {
512
- throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Invalid provider');
513
- }
529
+ const chainInfo = {
530
+ existentialDeposit: '0',
531
+ genesisHash: '',
532
+ success: true,
533
+ addressPrefix: '',
534
+ evmChainId: chainIdNum,
535
+ decimals: decimals,
536
+ symbol: symbol,
537
+ paraId: null,
538
+ name: chainName
539
+ };
514
540
  const newProviderKey = (0, _utils._generateCustomProviderKey)(0);
515
- return await this.#koniState.addNetworkConfirm(id, url, {
541
+ const networkData = {
516
542
  mode: 'insert',
517
543
  chainSpec: {
518
544
  evmChainId: chainInfo.evmChainId,
@@ -532,8 +558,31 @@ class KoniTabs {
532
558
  symbol: chainInfo.symbol,
533
559
  chainType: 'EVM',
534
560
  name: chainInfo.name
561
+ },
562
+ unconfirmed: true
563
+ };
564
+ this.#koniState.validateCustomChain(provider).then(res => {
565
+ if (!res.success) {
566
+ networkData.providerError = res.error;
567
+ } else {
568
+ networkData.chainSpec = {
569
+ evmChainId: res.evmChainId,
570
+ decimals: res.decimals,
571
+ existentialDeposit: res.existentialDeposit,
572
+ genesisHash: res.genesisHash,
573
+ paraId: res.paraId,
574
+ addressPrefix: res.addressPrefix ? parseInt(res.addressPrefix) : 0
575
+ };
576
+ networkData.chainEditInfo.symbol = res.symbol;
577
+ networkData.chainEditInfo.name = res.name;
535
578
  }
579
+ }).catch(() => {
580
+ networkData.providerError = _types2._CHAIN_VALIDATION_ERROR.NONE;
581
+ }).finally(() => {
582
+ networkData.unconfirmed = false;
583
+ this.#koniState.requestService.updateConfirmation(id, 'addNetworkRequest', networkData);
536
584
  });
585
+ return await this.#koniState.addNetworkConfirm(id, url, networkData);
537
586
  } else {
538
587
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Invalid provider');
539
588
  }
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.0.6-1'
16
+ version: '1.0.7-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -665,17 +665,19 @@ class ChainService {
665
665
  parsedStoredAssetRegistry[storedAsset.slug] = storedAsset;
666
666
  }
667
667
  });
668
- for (const assetInfo of Object.values(parsedStoredAssetRegistry)) {
668
+ for (const storedAssetInfo of Object.values(parsedStoredAssetRegistry)) {
669
669
  let duplicated = false;
670
670
  for (const defaultChainAsset of Object.values(latestAssetRegistry)) {
671
671
  // case merge custom asset with default asset
672
- if ((0, _utils._isEqualSmartContractAsset)(assetInfo, defaultChainAsset)) {
672
+ if ((0, _utils._isEqualSmartContractAsset)(storedAssetInfo, defaultChainAsset)) {
673
673
  duplicated = true;
674
674
  break;
675
675
  }
676
676
  }
677
677
  if (!duplicated) {
678
- mergedAssetRegistry[assetInfo.slug] = assetInfo;
678
+ mergedAssetRegistry[storedAssetInfo.slug] = storedAssetInfo;
679
+ } else {
680
+ deprecatedAssets.push(storedAssetInfo.slug);
679
681
  }
680
682
  }
681
683
  this.dataMap.assetRegistry = mergedAssetRegistry;
@@ -19,8 +19,8 @@ class MigrationService {
19
19
  async run() {
20
20
  const keys = Object.keys(_scripts.default).sort((a, b) => a.localeCompare(b));
21
21
 
22
- // Await timeout 2s
23
- await new Promise(resolve => setTimeout(resolve, 2000));
22
+ // Await timeout 1s
23
+ await new Promise(resolve => setTimeout(resolve, 1000));
24
24
  for (let i = 0; i < keys.length; i++) {
25
25
  try {
26
26
  const JobClass = _scripts.default[keys[i]];
@@ -81,6 +81,29 @@ class EvmRequestHandler {
81
81
  this.#requestService.updateIconV2();
82
82
  return promise;
83
83
  }
84
+ updateConfirmation(id, type, payload) {
85
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
86
+ let validator = arguments.length > 4 ? arguments[4] : undefined;
87
+ const confirmations = this.confirmationsQueueSubject.getValue();
88
+ const confirmationType = confirmations[type];
89
+
90
+ // Check duplicate request
91
+ const exists = confirmationType[id];
92
+ if (!exists) {
93
+ throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Request does not exist');
94
+ }
95
+ const payloadJson = JSON.stringify(payload);
96
+ confirmationType[id] = {
97
+ ...exists,
98
+ payload,
99
+ payloadJson,
100
+ ...options
101
+ };
102
+ if (validator) {
103
+ this.confirmationsPromiseMap[id].validator = validator;
104
+ }
105
+ this.confirmationsQueueSubject.next(confirmations);
106
+ }
84
107
  async signMessage(confirmation) {
85
108
  const {
86
109
  account,
@@ -164,6 +164,11 @@ class RequestService {
164
164
  async completeConfirmation(request) {
165
165
  return await this.#evmRequestHandler.completeConfirmation(request);
166
166
  }
167
+ updateConfirmation(id, type, payload) {
168
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
169
+ let validator = arguments.length > 4 ? arguments[4] : undefined;
170
+ return this.#evmRequestHandler.updateConfirmation(id, type, payload, options, validator);
171
+ }
167
172
 
168
173
  // General methods
169
174
  get numRequests() {
@@ -5,9 +5,11 @@ export declare class WasmNftApi extends BaseNftApi {
5
5
  private wasmContracts;
6
6
  constructor(api: _SubstrateApi | null, addresses: string[], chain: string);
7
7
  setSmartContractNfts(wasmContracts: _ChainAsset[]): void;
8
+ private isAttributeStoredOnChain;
8
9
  private parseFeaturedTokenUri;
9
10
  private parseFeaturedNftImage;
10
11
  private parseFeaturedCollectionImage;
12
+ private processOnChainMetadata;
11
13
  private processOffChainMetadata;
12
14
  private getItemsByCollection;
13
15
  fetchNfts(params: HandleNftParams): Promise<number>;