@subwallet/extension-base 1.1.48-0 → 1.1.50-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.
@@ -1744,6 +1744,8 @@ export interface KoniRequestSignatures {
1744
1744
  'pri(settings.saveLanguage)': [RequestChangeLanguage, boolean];
1745
1745
  'pri(settings.saveShowZeroBalance)': [RequestChangeShowZeroBalance, boolean];
1746
1746
  'pri(settings.saveShowBalance)': [RequestChangeShowBalance, boolean];
1747
+ 'pri(settings.logo.assets.subscribe)': [null, Record<string, string>, Record<string, string>];
1748
+ 'pri(settings.logo.chains.subscribe)': [null, Record<string, string>, Record<string, string>];
1747
1749
  'pri(yield.subscribePoolInfo)': [null, YieldPoolInfo[], YieldPoolInfo[]];
1748
1750
  'pri(yield.subscribeYieldPosition)': [null, YieldPositionInfo[], YieldPositionInfo[]];
1749
1751
  'pri(yield.subscribeYieldReward)': [null, EarningRewardJson, EarningRewardJson];
@@ -113,7 +113,7 @@ const IGNORE_QR_SIGNER = [];
113
113
  exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
114
114
  const XCM_MIN_AMOUNT_RATIO = 1.2;
115
115
  exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
116
- const XCM_FEE_RATIO = 1.2;
116
+ const XCM_FEE_RATIO = 2;
117
117
  exports.XCM_FEE_RATIO = XCM_FEE_RATIO;
118
118
  const GAS_PRICE_RATIO = 1 + 2 / 100;
119
119
  exports.GAS_PRICE_RATIO = GAS_PRICE_RATIO;
@@ -1944,7 +1944,7 @@ class KoniExtension {
1944
1944
  if (!destinationTokenInfo) {
1945
1945
  estimatedFee = '0';
1946
1946
  } else {
1947
- maxTransferable = maxTransferable.minus(new _bignumber.default(tokenInfo.minAmount || '0').multipliedBy(_constants.XCM_FEE_RATIO));
1947
+ maxTransferable = maxTransferable.minus(new _bignumber.default(tokenInfo.minAmount || '0').multipliedBy(_constants.XCM_MIN_AMOUNT_RATIO));
1948
1948
  const desChainInfo = chainInfoMap[destChain];
1949
1949
  const orgChainInfo = chainInfoMap[networkKey];
1950
1950
  const recipient = !(0, _utilCrypto.isEthereumAddress)(address) && (0, _utils2._isChainEvmCompatible)(desChainInfo) && !(0, _utils2._isChainEvmCompatible)(orgChainInfo) ? (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(address)) : address;
@@ -2001,10 +2001,10 @@ class KoniExtension {
2001
2001
  estimatedFee = '0';
2002
2002
  console.warn('Unable to estimate fee', e);
2003
2003
  }
2004
- maxTransferable = maxTransferable.minus(new _bignumber.default(estimatedFee));
2004
+ maxTransferable = maxTransferable.minus(new _bignumber.default(estimatedFee).multipliedBy(isXcmTransfer ? _constants.XCM_FEE_RATIO : 1));
2005
2005
  return {
2006
2006
  ...freeBalance,
2007
- value: maxTransferable.gt(_utils4.BN_ZERO) ? maxTransferable.toFixed() || '0' : '0'
2007
+ value: maxTransferable.gt(_utils4.BN_ZERO) ? maxTransferable.toFixed(0) || '0' : '0'
2008
2008
  };
2009
2009
  }
2010
2010
  }
@@ -3383,6 +3383,28 @@ class KoniExtension {
3383
3383
  assetLogoMap
3384
3384
  };
3385
3385
  }
3386
+ subscribeAssetLogoMap(id, port) {
3387
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3388
+ const subscription = this.#koniState.chainService.subscribeAssetLogoMap().subscribe(rs => {
3389
+ cb(rs);
3390
+ });
3391
+ port.onDisconnect.addListener(() => {
3392
+ subscription.unsubscribe();
3393
+ this.cancelSubscription(id);
3394
+ });
3395
+ return this.#koniState.chainService.getAssetLogoMap();
3396
+ }
3397
+ subscribeChainLogoMap(id, port) {
3398
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3399
+ const subscription = this.#koniState.chainService.subscribeChainLogoMap().subscribe(rs => {
3400
+ cb(rs);
3401
+ });
3402
+ port.onDisconnect.addListener(() => {
3403
+ subscription.unsubscribe();
3404
+ this.cancelSubscription(id);
3405
+ });
3406
+ return this.#koniState.chainService.getChainLogoMap();
3407
+ }
3386
3408
 
3387
3409
  // Phishing detect
3388
3410
 
@@ -4483,6 +4505,10 @@ class KoniExtension {
4483
4505
  return await this.reloadCron(request);
4484
4506
  case 'pri(settings.getLogoMaps)':
4485
4507
  return await this.getLogoMap();
4508
+ case 'pri(settings.logo.assets.subscribe)':
4509
+ return this.subscribeAssetLogoMap(id, port);
4510
+ case 'pri(settings.logo.chains.subscribe)':
4511
+ return this.subscribeChainLogoMap(id, port);
4486
4512
 
4487
4513
  /// Wallet Connect
4488
4514
  case 'pri(walletConnect.connect)':
@@ -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.1.48-0'
16
+ version: '1.1.50-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -284,22 +284,19 @@ async function subscribeAssetsAccountPallet(addresses, chain, api, callBack) {
284
284
  // Get Token Balance
285
285
  return await api.query.assets.account.multi(addresses.map(address => [assetIndex, address]), balances => {
286
286
  const items = balances.map((balance, index) => {
287
- // @ts-ignore
288
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
289
- const bdata = balance === null || balance === void 0 ? void 0 : balance.toHuman();
287
+ const bdata = balance === null || balance === void 0 ? void 0 : balance.toPrimitive();
290
288
  let frozen = _util.BN_ZERO;
291
289
  let total = _util.BN_ZERO;
292
290
  if (bdata) {
293
291
  // @ts-ignore
294
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
295
292
  const addressBalance = new _util.BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0');
296
293
 
297
294
  // @ts-ignore
298
- if (bdata !== null && bdata !== void 0 && bdata.isFrozen) {
295
+ if (bdata !== null && bdata !== void 0 && bdata.isFrozen || ['Blocked', 'Frozen'].includes(bdata === null || bdata === void 0 ? void 0 : bdata.status)) {
296
+ // Status 'Frozen' and 'Blocked' are for frozen balance
299
297
  frozen = addressBalance;
300
- } else {
301
- total = addressBalance;
302
298
  }
299
+ total = addressBalance;
303
300
  }
304
301
  const free = total.sub(frozen);
305
302
  return {
@@ -40,7 +40,7 @@ const _BALANCE_CHAIN_GROUP = {
40
40
  genshiro: ['genshiro_testnet', 'genshiro'],
41
41
  equilibrium_parachain: ['equilibrium_parachain'],
42
42
  bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'pendulum', 'amplitude', 'continuum_network'],
43
- statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala'],
43
+ statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala', 'shibuya'],
44
44
  kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
45
45
  // perhaps there are some runtime updates
46
46
  centrifuge: ['centrifuge'],
@@ -42,6 +42,10 @@ class ChainService {
42
42
  assetRegistrySubject = new _rxjs.Subject();
43
43
  multiChainAssetMapSubject = new _rxjs.Subject();
44
44
  xcmRefMapSubject = new _rxjs.Subject();
45
+ assetLogoMapSubject = new _rxjs.BehaviorSubject(_chainList.AssetLogoMap);
46
+ chainLogoMapSubject = new _rxjs.BehaviorSubject(_chainList.ChainLogoMap);
47
+ assetMapPatch = JSON.stringify({});
48
+ assetLogoPatch = JSON.stringify({});
45
49
 
46
50
  // Todo: Update to new store indexed DB
47
51
  store = new _AssetSetting.default();
@@ -451,27 +455,12 @@ class ChainService {
451
455
  this.xcmRefMapSubject.next(this.xcmRefMap);
452
456
  await this.initApis();
453
457
  await this.initAssetSettings();
454
- await this.initAssetRefMap();
458
+ this.initAssetRefMap();
459
+ await this.autoEnableTokens();
455
460
  this.checkLatestData();
456
461
  }
457
- async initAssetRefMap() {
458
- try {
459
- const fetchPromise = this.fetchLatestBlockedAssetRef();
460
- const timeout = new Promise(resolve => {
461
- const id = setTimeout(() => {
462
- clearTimeout(id);
463
- resolve(null);
464
- }, 1000);
465
- });
466
- const disabledAssetRefs = (await Promise.race([timeout, fetchPromise])) || null;
467
- if (disabledAssetRefs) {
468
- this.handleLatestBlockedAssetRef(disabledAssetRefs);
469
- } else {
470
- this.dataMap.assetRefMap = _chainList.AssetRefMap;
471
- }
472
- } catch (e) {
473
- this.dataMap.assetRefMap = _chainList.AssetRefMap;
474
- }
462
+ initAssetRefMap() {
463
+ this.dataMap.assetRefMap = _chainList.AssetRefMap;
475
464
  }
476
465
  checkLatestData() {
477
466
  clearInterval(this.refreshLatestChainDataTimeOut);
@@ -500,10 +489,15 @@ class ChainService {
500
489
  console.error('Error fetching latest chain data');
501
490
  }
502
491
  }
503
- handleLatestBlockedAssetRef(latestBlockedAssetRefList) {
492
+ handleLatestAssetRef(latestBlockedAssetRefList, latestAssetRefMap) {
504
493
  const updatedAssetRefMap = {
505
494
  ..._chainList.AssetRefMap
506
495
  };
496
+ if (latestAssetRefMap) {
497
+ for (const [assetRefKey, assetRef] of Object.entries(latestAssetRefMap)) {
498
+ updatedAssetRefMap[assetRefKey] = assetRef;
499
+ }
500
+ }
507
501
  latestBlockedAssetRefList.forEach(blockedAssetRef => {
508
502
  delete updatedAssetRefMap[blockedAssetRef];
509
503
  });
@@ -526,12 +520,77 @@ class ChainService {
526
520
  }
527
521
  this.logger.log('Finished updating latest price IDs');
528
522
  }
523
+ handleLatestAssetData(_latestAssetInfo, _latestAssetLogoMap) {
524
+ try {
525
+ let needUpdate = false;
526
+ const latestAssetInfo = _latestAssetInfo || {};
527
+ const latestAssetLogoMap = _latestAssetLogoMap || {};
528
+ const latestAssetPatch = JSON.stringify(latestAssetInfo);
529
+ const latestAssetLogoPatch = JSON.stringify(latestAssetLogoMap);
530
+ if (this.assetMapPatch !== latestAssetPatch) {
531
+ needUpdate = true;
532
+ const assetRegistry = {
533
+ ..._chainList.ChainAssetMap,
534
+ ...latestAssetInfo
535
+ };
536
+ this.assetMapPatch = latestAssetPatch;
537
+ this.dataMap.assetRegistry = assetRegistry;
538
+ this.assetRegistrySubject.next(assetRegistry);
539
+ }
540
+ if (this.assetLogoPatch !== latestAssetLogoPatch) {
541
+ const logoMap = {
542
+ ..._chainList.AssetLogoMap,
543
+ ...latestAssetLogoMap
544
+ };
545
+ this.assetLogoPatch = latestAssetLogoPatch;
546
+ this.assetLogoMapSubject.next(logoMap);
547
+ }
548
+ if (needUpdate) {
549
+ this.autoEnableTokens().then(() => {
550
+ this.eventService.emit('asset.updateState', '');
551
+ }).catch(console.error);
552
+ }
553
+ } catch (e) {
554
+ console.error('Error fetching latest asset data');
555
+ }
556
+ this.logger.log('Finished updating latest asset');
557
+ }
558
+ async autoEnableTokens() {
559
+ const autoEnableTokens = Object.values(this.dataMap.assetRegistry).filter(asset => (0, _utils._isAssetAutoEnable)(asset));
560
+ const assetSettings = this.assetSettingSubject.value;
561
+ const chainStateMap = this.getChainStateMap();
562
+ for (const asset of autoEnableTokens) {
563
+ const {
564
+ originChain,
565
+ slug: assetSlug
566
+ } = asset;
567
+ const assetState = assetSettings[assetSlug];
568
+ const chainState = chainStateMap[originChain];
569
+ if (!assetState) {
570
+ // If this asset not has asset setting, this token is not enabled before (not turned off before)
571
+ // @ts-ignore
572
+ // TODO: Merge issue detect balance to define manualTurnOff props
573
+ if (!chainState || !chainState.manualTurnOff) {
574
+ await this.updateAssetSetting(assetSlug, {
575
+ visible: true
576
+ });
577
+ }
578
+ }
579
+ }
580
+ }
529
581
  handleLatestData() {
582
+ this.fetchLatestAssetData().then(_ref6 => {
583
+ let [latestAssetInfo, latestAssetLogoMap] = _ref6;
584
+ this.eventService.waitAssetReady.then(() => {
585
+ this.handleLatestAssetData(latestAssetInfo, latestAssetLogoMap);
586
+ }).catch(console.error);
587
+ }).catch(console.error);
530
588
  this.fetchLatestChainData().then(latestChainInfo => {
531
589
  this.handleLatestProviderData(latestChainInfo);
532
590
  }).catch(console.error);
533
- this.fetchLatestBlockedAssetRef().then(latestAssetRef => {
534
- this.handleLatestBlockedAssetRef(latestAssetRef);
591
+ this.fetchLatestAssetRef().then(_ref7 => {
592
+ let [latestAssetRef, latestAssetRefMap] = _ref7;
593
+ this.handleLatestAssetRef(latestAssetRef, latestAssetRefMap);
535
594
  }).catch(console.error);
536
595
  this.fetchLatestPriceIdsData().then(latestPriceIds => {
537
596
  this.handleLatestPriceId(latestPriceIds);
@@ -540,12 +599,12 @@ class ChainService {
540
599
  async initApis() {
541
600
  const chainInfoMap = this.getChainInfoMap();
542
601
  const chainStateMap = this.getChainStateMap();
543
- await Promise.all(Object.entries(chainInfoMap).filter(_ref6 => {
602
+ await Promise.all(Object.entries(chainInfoMap).filter(_ref8 => {
544
603
  var _chainStateMap$slug;
545
- let [slug] = _ref6;
604
+ let [slug] = _ref8;
546
605
  return (_chainStateMap$slug = chainStateMap[slug]) === null || _chainStateMap$slug === void 0 ? void 0 : _chainStateMap$slug.active;
547
- }).map(_ref7 => {
548
- let [, chainInfo] = _ref7;
606
+ }).map(_ref9 => {
607
+ let [, chainInfo] = _ref9;
549
608
  try {
550
609
  return this.initApiForChain(chainInfo);
551
610
  } catch (e) {
@@ -727,12 +786,16 @@ class ChainService {
727
786
  // }
728
787
  }
729
788
 
789
+ async fetchLatestAssetData() {
790
+ return await Promise.all([(0, _utils.fetchPatchData)('ChainAsset.json'), (0, _utils.fetchPatchData)('AssetLogoMap.json')]);
791
+ }
792
+
730
793
  // @ts-ignore
731
794
  async fetchLatestPriceIdsData() {
732
795
  return await (0, _utils2.fetchStaticData)('chain-assets/price-map');
733
796
  }
734
- async fetchLatestBlockedAssetRef() {
735
- return await (0, _utils2.fetchStaticData)('chain-assets/disabled-xcm-channels');
797
+ async fetchLatestAssetRef() {
798
+ return await Promise.all([(0, _utils2.fetchStaticData)('chain-assets/disabled-xcm-channels'), (0, _utils.fetchPatchData)('AssetRef.json')]);
736
799
  }
737
800
  async initChains() {
738
801
  const storedChainSettings = await this.dbService.getAllChainStore();
@@ -870,8 +933,8 @@ class ChainService {
870
933
  }
871
934
 
872
935
  // Fill in the missing chainState and storageData (new chains never before seen)
873
- Object.entries(mergedChainInfoMap).forEach(_ref8 => {
874
- let [slug, chainInfo] = _ref8;
936
+ Object.entries(mergedChainInfoMap).forEach(_ref10 => {
937
+ let [slug, chainInfo] = _ref10;
875
938
  if (!(slug in this.dataMap.chainStateMap)) {
876
939
  this.dataMap.chainStateMap[slug] = {
877
940
  currentProvider: Object.keys(chainInfo.providers)[0],
@@ -1467,11 +1530,17 @@ class ChainService {
1467
1530
  subscribeAssetSettings() {
1468
1531
  return this.assetSettingSubject;
1469
1532
  }
1470
- async getChainLogoMap() {
1471
- return Promise.resolve(_chainList.ChainLogoMap);
1533
+ getAssetLogoMap() {
1534
+ return this.assetLogoMapSubject.value;
1535
+ }
1536
+ subscribeAssetLogoMap() {
1537
+ return this.assetLogoMapSubject;
1538
+ }
1539
+ getChainLogoMap() {
1540
+ return this.chainLogoMapSubject.value;
1472
1541
  }
1473
- async getAssetLogoMap() {
1474
- return Promise.resolve(_chainList.AssetLogoMap);
1542
+ subscribeChainLogoMap() {
1543
+ return this.chainLogoMapSubject;
1475
1544
  }
1476
1545
  resetWallet(resetAll) {
1477
1546
  if (resetAll) {
@@ -3,6 +3,78 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ _isCustomChain: true,
8
+ _isCustomAsset: true,
9
+ _getCustomAssets: true,
10
+ _isEqualContractAddress: true,
11
+ _isEqualSmartContractAsset: true,
12
+ _isPureEvmChain: true,
13
+ _isPureSubstrateChain: true,
14
+ _getOriginChainOfAsset: true,
15
+ _getContractAddressOfToken: true,
16
+ _isTokenTransferredByEvm: true,
17
+ _checkSmartContractSupportByChain: true,
18
+ _getTokenOnChainAssetId: true,
19
+ _getTokenOnChainInfo: true,
20
+ _isBridgedToken: true,
21
+ _getTokenMinAmount: true,
22
+ _isChainEvmCompatible: true,
23
+ _isNativeToken: true,
24
+ _isNativeTokenBySlug: true,
25
+ _isSmartContractToken: true,
26
+ _isSubstrateChain: true,
27
+ _getEvmChainId: true,
28
+ _getSubstrateParaId: true,
29
+ _getSubstrateRelayParent: true,
30
+ _getSubstrateGenesisHash: true,
31
+ _isChainSupportSubstrateStaking: true,
32
+ _isChainEnabled: true,
33
+ _getChainSubstrateAddressPrefix: true,
34
+ _isChainSupportNativeNft: true,
35
+ _isChainSupportEvmNft: true,
36
+ _isChainSupportWasmNft: true,
37
+ _isSupportOrdinal: true,
38
+ _getNftTypesSupportedByChain: true,
39
+ _getTokenTypesSupportedByChain: true,
40
+ _getChainNativeTokenBasicInfo: true,
41
+ _getChainNativeTokenSlug: true,
42
+ _isLocalToken: true,
43
+ _isTokenEvmSmartContract: true,
44
+ _isTokenWasmSmartContract: true,
45
+ _isAssetSmartContractNft: true,
46
+ _parseAssetRefKey: true,
47
+ _isXcmPathSupported: true,
48
+ _getXcmAssetType: true,
49
+ _getXcmAssetId: true,
50
+ _getXcmAssetMultilocation: true,
51
+ _getXcmTransferType: true,
52
+ _isSubstrateRelayChain: true,
53
+ _isSubstrateParaChain: true,
54
+ _getEvmAbiExplorer: true,
55
+ _isAssetValuable: true,
56
+ _getMultiChainAsset: true,
57
+ _getAssetPriceId: true,
58
+ _getMultiChainAssetPriceId: true,
59
+ _getAssetSymbol: true,
60
+ _getMultiChainAssetSymbol: true,
61
+ _getAssetOriginChain: true,
62
+ _getChainName: true,
63
+ _getAssetDecimals: true,
64
+ _getBlockExplorerFromChain: true,
65
+ _parseMetadataForSmartContractAsset: true,
66
+ _isChainTestNet: true,
67
+ _isAssetFungibleToken: true,
68
+ _isAssetAutoEnable: true,
69
+ _getCrowdloanUrlFromChain: true,
70
+ _isCustomProvider: true,
71
+ _generateCustomProviderKey: true,
72
+ findChainInfoByHalfGenesisHash: true,
73
+ findChainInfoByChainId: true,
74
+ _isMantaZkAsset: true,
75
+ randomizeProvider: true,
76
+ updateLatestChainInfo: true
77
+ };
6
78
  exports._checkSmartContractSupportByChain = _checkSmartContractSupportByChain;
7
79
  exports._generateCustomProviderKey = _generateCustomProviderKey;
8
80
  exports._getAssetDecimals = _getAssetDecimals;
@@ -35,6 +107,7 @@ exports._getXcmAssetId = _getXcmAssetId;
35
107
  exports._getXcmAssetMultilocation = _getXcmAssetMultilocation;
36
108
  exports._getXcmAssetType = _getXcmAssetType;
37
109
  exports._getXcmTransferType = _getXcmTransferType;
110
+ exports._isAssetAutoEnable = void 0;
38
111
  exports._isAssetFungibleToken = _isAssetFungibleToken;
39
112
  exports._isAssetSmartContractNft = _isAssetSmartContractNft;
40
113
  exports._isAssetValuable = _isAssetValuable;
@@ -75,6 +148,18 @@ var _types = require("@subwallet/chain-list/types");
75
148
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
76
149
  var _types2 = require("@subwallet/extension-base/services/chain-service/types");
77
150
  var _utilCrypto = require("@polkadot/util-crypto");
151
+ var _patch = require("./patch");
152
+ Object.keys(_patch).forEach(function (key) {
153
+ if (key === "default" || key === "__esModule") return;
154
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
155
+ if (key in exports && exports[key] === _patch[key]) return;
156
+ Object.defineProperty(exports, key, {
157
+ enumerable: true,
158
+ get: function () {
159
+ return _patch[key];
160
+ }
161
+ });
162
+ });
78
163
  // Copyright 2019-2022 @subwallet/extension-base
79
164
  // SPDX-License-Identifier: Apache-2.0
80
165
 
@@ -404,6 +489,10 @@ function _isChainTestNet(chainInfo) {
404
489
  function _isAssetFungibleToken(chainAsset) {
405
490
  return ![_types._AssetType.ERC721, _types._AssetType.PSP34, _types._AssetType.UNKNOWN].includes(chainAsset.assetType);
406
491
  }
492
+ const _isAssetAutoEnable = chainAsset => {
493
+ return chainAsset.metadata ? !!chainAsset.metadata.autoEnable : false;
494
+ };
495
+ exports._isAssetAutoEnable = _isAssetAutoEnable;
407
496
  function _getCrowdloanUrlFromChain(chainInfo) {
408
497
  var _chainInfo$substrateI13;
409
498
  return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI13 = chainInfo.substrateInfo) === null || _chainInfo$substrateI13 === void 0 ? void 0 : _chainInfo$substrateI13.crowdloanUrl) || '';
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.fetchPatchData = fetchPatchData;
8
+ var _packageInfo = require("@subwallet/chain-list/packageInfo");
9
+ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
10
+ // Copyright 2019-2022 @subwallet/extension-base
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
14
+ const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
15
+ const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
16
+ async function fetchPatchData(slug) {
17
+ try {
18
+ const fetchPromise = (0, _crossFetch.default)(`${fetchDomain}/patch/${_packageInfo.packageInfo.version}/${slug}`);
19
+ const timeout = new Promise(resolve => {
20
+ const id = setTimeout(() => {
21
+ clearTimeout(id);
22
+ resolve(null);
23
+ }, 1000);
24
+ });
25
+ const rs = await Promise.race([timeout, fetchPromise]);
26
+ if (!rs) {
27
+ return null;
28
+ }
29
+ return await rs.json();
30
+ } catch (e) {
31
+ return null;
32
+ }
33
+ }
@@ -23,7 +23,7 @@ export declare const ALL_GENESIS_HASH: null;
23
23
  export declare const IGNORE_GET_SUBSTRATE_FEATURES_LIST: string[];
24
24
  export declare const IGNORE_QR_SIGNER: string[];
25
25
  export declare const XCM_MIN_AMOUNT_RATIO = 1.2;
26
- export declare const XCM_FEE_RATIO = 1.2;
26
+ export declare const XCM_FEE_RATIO = 2;
27
27
  export declare const GAS_PRICE_RATIO: number;
28
28
  export declare const NETWORK_MULTI_GAS_FEE: string[];
29
29
  export declare const ORDINAL_COLLECTION = "__Ordinal__";
@@ -26,7 +26,7 @@ export const ALL_GENESIS_HASH = null;
26
26
  export const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
27
27
  export const IGNORE_QR_SIGNER = [];
28
28
  export const XCM_MIN_AMOUNT_RATIO = 1.2;
29
- export const XCM_FEE_RATIO = 1.2;
29
+ export const XCM_FEE_RATIO = 2;
30
30
  export const GAS_PRICE_RATIO = 1 + 2 / 100;
31
31
  export const NETWORK_MULTI_GAS_FEE = ['*'];
32
32
  export const ORDINAL_COLLECTION = '__Ordinal__';
@@ -195,6 +195,8 @@ export default class KoniExtension {
195
195
  private subscribeNotifications;
196
196
  private reloadCron;
197
197
  private getLogoMap;
198
+ private subscribeAssetLogoMap;
199
+ private subscribeChainLogoMap;
198
200
  private passPhishingPage;
199
201
  private connectWalletConnect;
200
202
  private connectWCSubscribe;
@@ -1886,7 +1886,7 @@ export default class KoniExtension {
1886
1886
  if (!destinationTokenInfo) {
1887
1887
  estimatedFee = '0';
1888
1888
  } else {
1889
- maxTransferable = maxTransferable.minus(new BigN(tokenInfo.minAmount || '0').multipliedBy(XCM_FEE_RATIO));
1889
+ maxTransferable = maxTransferable.minus(new BigN(tokenInfo.minAmount || '0').multipliedBy(XCM_MIN_AMOUNT_RATIO));
1890
1890
  const desChainInfo = chainInfoMap[destChain];
1891
1891
  const orgChainInfo = chainInfoMap[networkKey];
1892
1892
  const recipient = !isEthereumAddress(address) && _isChainEvmCompatible(desChainInfo) && !_isChainEvmCompatible(orgChainInfo) ? u8aToHex(addressToEvm(address)) : address;
@@ -1943,10 +1943,10 @@ export default class KoniExtension {
1943
1943
  estimatedFee = '0';
1944
1944
  console.warn('Unable to estimate fee', e);
1945
1945
  }
1946
- maxTransferable = maxTransferable.minus(new BigN(estimatedFee));
1946
+ maxTransferable = maxTransferable.minus(new BigN(estimatedFee).multipliedBy(isXcmTransfer ? XCM_FEE_RATIO : 1));
1947
1947
  return {
1948
1948
  ...freeBalance,
1949
- value: maxTransferable.gt(BN_ZERO) ? maxTransferable.toFixed() || '0' : '0'
1949
+ value: maxTransferable.gt(BN_ZERO) ? maxTransferable.toFixed(0) || '0' : '0'
1950
1950
  };
1951
1951
  }
1952
1952
  }
@@ -3294,6 +3294,28 @@ export default class KoniExtension {
3294
3294
  assetLogoMap
3295
3295
  };
3296
3296
  }
3297
+ subscribeAssetLogoMap(id, port) {
3298
+ const cb = createSubscription(id, port);
3299
+ const subscription = this.#koniState.chainService.subscribeAssetLogoMap().subscribe(rs => {
3300
+ cb(rs);
3301
+ });
3302
+ port.onDisconnect.addListener(() => {
3303
+ subscription.unsubscribe();
3304
+ this.cancelSubscription(id);
3305
+ });
3306
+ return this.#koniState.chainService.getAssetLogoMap();
3307
+ }
3308
+ subscribeChainLogoMap(id, port) {
3309
+ const cb = createSubscription(id, port);
3310
+ const subscription = this.#koniState.chainService.subscribeChainLogoMap().subscribe(rs => {
3311
+ cb(rs);
3312
+ });
3313
+ port.onDisconnect.addListener(() => {
3314
+ subscription.unsubscribe();
3315
+ this.cancelSubscription(id);
3316
+ });
3317
+ return this.#koniState.chainService.getChainLogoMap();
3318
+ }
3297
3319
 
3298
3320
  // Phishing detect
3299
3321
 
@@ -4379,6 +4401,10 @@ export default class KoniExtension {
4379
4401
  return await this.reloadCron(request);
4380
4402
  case 'pri(settings.getLogoMaps)':
4381
4403
  return await this.getLogoMap();
4404
+ case 'pri(settings.logo.assets.subscribe)':
4405
+ return this.subscribeAssetLogoMap(id, port);
4406
+ case 'pri(settings.logo.chains.subscribe)':
4407
+ return this.subscribeChainLogoMap(id, port);
4382
4408
 
4383
4409
  /// Wallet Connect
4384
4410
  case 'pri(walletConnect.connect)':
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.1.48-0",
20
+ "version": "1.1.50-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -714,9 +714,14 @@
714
714
  "default": "./services/chain-service/types.js"
715
715
  },
716
716
  "./services/chain-service/utils": {
717
- "types": "./services/chain-service/utils.d.ts",
718
- "require": "./cjs/services/chain-service/utils.js",
719
- "default": "./services/chain-service/utils.js"
717
+ "types": "./services/chain-service/utils/index.d.ts",
718
+ "require": "./cjs/services/chain-service/utils/index.js",
719
+ "default": "./services/chain-service/utils/index.js"
720
+ },
721
+ "./services/chain-service/utils/patch": {
722
+ "types": "./services/chain-service/utils/patch.d.ts",
723
+ "require": "./cjs/services/chain-service/utils/patch.js",
724
+ "default": "./services/chain-service/utils/patch.js"
720
725
  },
721
726
  "./services/earning-service/constants": {
722
727
  "types": "./services/earning-service/constants/index.d.ts",
@@ -1796,11 +1801,11 @@
1796
1801
  "@reduxjs/toolkit": "^1.9.1",
1797
1802
  "@sora-substrate/type-definitions": "^1.17.7",
1798
1803
  "@substrate/connect": "^0.7.26",
1799
- "@subwallet/chain-list": "0.2.52",
1800
- "@subwallet/extension-base": "^1.1.48-0",
1801
- "@subwallet/extension-chains": "^1.1.48-0",
1802
- "@subwallet/extension-dapp": "^1.1.48-0",
1803
- "@subwallet/extension-inject": "^1.1.48-0",
1804
+ "@subwallet/chain-list": "0.2.53",
1805
+ "@subwallet/extension-base": "^1.1.50-0",
1806
+ "@subwallet/extension-chains": "^1.1.50-0",
1807
+ "@subwallet/extension-dapp": "^1.1.50-0",
1808
+ "@subwallet/extension-inject": "^1.1.50-0",
1804
1809
  "@subwallet/keyring": "^0.1.3",
1805
1810
  "@subwallet/ui-keyring": "^0.1.3",
1806
1811
  "@walletconnect/sign-client": "^2.8.4",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.1.48-0'
10
+ version: '1.1.50-0'
11
11
  };
@@ -276,22 +276,19 @@ async function subscribeAssetsAccountPallet(addresses, chain, api, callBack) {
276
276
  // Get Token Balance
277
277
  return await api.query.assets.account.multi(addresses.map(address => [assetIndex, address]), balances => {
278
278
  const items = balances.map((balance, index) => {
279
- // @ts-ignore
280
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
281
- const bdata = balance === null || balance === void 0 ? void 0 : balance.toHuman();
279
+ const bdata = balance === null || balance === void 0 ? void 0 : balance.toPrimitive();
282
280
  let frozen = BN_ZERO;
283
281
  let total = BN_ZERO;
284
282
  if (bdata) {
285
283
  // @ts-ignore
286
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
287
284
  const addressBalance = new BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0');
288
285
 
289
286
  // @ts-ignore
290
- if (bdata !== null && bdata !== void 0 && bdata.isFrozen) {
287
+ if (bdata !== null && bdata !== void 0 && bdata.isFrozen || ['Blocked', 'Frozen'].includes(bdata === null || bdata === void 0 ? void 0 : bdata.status)) {
288
+ // Status 'Frozen' and 'Blocked' are for frozen balance
291
289
  frozen = addressBalance;
292
- } else {
293
- total = addressBalance;
294
290
  }
291
+ total = addressBalance;
295
292
  }
296
293
  const free = total.sub(frozen);
297
294
  return {
@@ -29,7 +29,7 @@ export const _BALANCE_CHAIN_GROUP = {
29
29
  genshiro: ['genshiro_testnet', 'genshiro'],
30
30
  equilibrium_parachain: ['equilibrium_parachain'],
31
31
  bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'pendulum', 'amplitude', 'continuum_network'],
32
- statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala'],
32
+ statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala', 'shibuya'],
33
33
  kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
34
34
  // perhaps there are some runtime updates
35
35
  centrifuge: ['centrifuge'],
@@ -23,6 +23,10 @@ export declare class ChainService {
23
23
  private assetRegistrySubject;
24
24
  private multiChainAssetMapSubject;
25
25
  private xcmRefMapSubject;
26
+ private assetLogoMapSubject;
27
+ private chainLogoMapSubject;
28
+ private assetMapPatch;
29
+ private assetLogoPatch;
26
30
  private store;
27
31
  private assetSettingSubject;
28
32
  private logger;
@@ -76,12 +80,14 @@ export declare class ChainService {
76
80
  deleteAssetsByChain(chainSlug: string): void;
77
81
  deleteCustomAssets(targetAssets: string[]): void;
78
82
  init(): Promise<void>;
79
- initAssetRefMap(): Promise<void>;
83
+ initAssetRefMap(): void;
80
84
  checkLatestData(): void;
81
85
  stopCheckLatestChainData(): void;
82
86
  handleLatestProviderData(latestChainInfo: _ChainInfo[]): void;
83
- handleLatestBlockedAssetRef(latestBlockedAssetRefList: string[]): void;
87
+ handleLatestAssetRef(latestBlockedAssetRefList: string[], latestAssetRefMap: Record<string, _AssetRef> | null): void;
84
88
  handleLatestPriceId(latestPriceIds: Record<string, string | null>): void;
89
+ handleLatestAssetData(_latestAssetInfo: Record<string, _ChainAsset> | null, _latestAssetLogoMap: Record<string, string> | null): void;
90
+ autoEnableTokens(): Promise<void>;
85
91
  handleLatestData(): void;
86
92
  private initApis;
87
93
  private initApiForChain;
@@ -92,8 +98,9 @@ export declare class ChainService {
92
98
  disableChain(chainSlug: string): boolean;
93
99
  private checkExistedPredefinedChain;
94
100
  private fetchLatestChainData;
101
+ private fetchLatestAssetData;
95
102
  private fetchLatestPriceIdsData;
96
- private fetchLatestBlockedAssetRef;
103
+ private fetchLatestAssetRef;
97
104
  private initChains;
98
105
  private initAssetRegistry;
99
106
  private updateChainStateMapSubscription;
@@ -122,8 +129,10 @@ export declare class ChainService {
122
129
  updateAssetSetting(assetSlug: string, assetSetting: AssetSetting, autoEnableNativeToken?: boolean): Promise<boolean | undefined>;
123
130
  updateAssetSettingByChain(chainSlug: string, visible: boolean): Promise<void>;
124
131
  subscribeAssetSettings(): BehaviorSubject<Record<string, AssetSetting>>;
125
- getChainLogoMap(): Promise<Record<string, string>>;
126
- getAssetLogoMap(): Promise<Record<string, string>>;
132
+ getAssetLogoMap(): Record<string, string>;
133
+ subscribeAssetLogoMap(): BehaviorSubject<Record<string, string>>;
134
+ getChainLogoMap(): Record<string, string>;
135
+ subscribeChainLogoMap(): BehaviorSubject<Record<string, string>>;
127
136
  resetWallet(resetAll: boolean): void;
128
137
  getMetadata(chain: string): import("dexie").PromiseExtended<IMetadataItem | undefined>;
129
138
  upsertMetadata(chain: string, metadata: IMetadataItem): import("dexie").PromiseExtended<unknown>;
@@ -9,7 +9,7 @@ import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-se
9
9
  import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler';
10
10
  import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
11
11
  import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
12
- import { _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
12
+ import { _isAssetAutoEnable, _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, fetchPatchData, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
13
13
  import AssetSettingStore from '@subwallet/extension-base/stores/AssetSetting';
14
14
  import { addLazy, fetchStaticData, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
15
15
  import { BehaviorSubject, Subject } from 'rxjs';
@@ -35,6 +35,10 @@ export class ChainService {
35
35
  assetRegistrySubject = new Subject();
36
36
  multiChainAssetMapSubject = new Subject();
37
37
  xcmRefMapSubject = new Subject();
38
+ assetLogoMapSubject = new BehaviorSubject(AssetLogoMap);
39
+ chainLogoMapSubject = new BehaviorSubject(ChainLogoMap);
40
+ assetMapPatch = JSON.stringify({});
41
+ assetLogoPatch = JSON.stringify({});
38
42
 
39
43
  // Todo: Update to new store indexed DB
40
44
  store = new AssetSettingStore();
@@ -435,27 +439,12 @@ export class ChainService {
435
439
  this.xcmRefMapSubject.next(this.xcmRefMap);
436
440
  await this.initApis();
437
441
  await this.initAssetSettings();
438
- await this.initAssetRefMap();
442
+ this.initAssetRefMap();
443
+ await this.autoEnableTokens();
439
444
  this.checkLatestData();
440
445
  }
441
- async initAssetRefMap() {
442
- try {
443
- const fetchPromise = this.fetchLatestBlockedAssetRef();
444
- const timeout = new Promise(resolve => {
445
- const id = setTimeout(() => {
446
- clearTimeout(id);
447
- resolve(null);
448
- }, 1000);
449
- });
450
- const disabledAssetRefs = (await Promise.race([timeout, fetchPromise])) || null;
451
- if (disabledAssetRefs) {
452
- this.handleLatestBlockedAssetRef(disabledAssetRefs);
453
- } else {
454
- this.dataMap.assetRefMap = AssetRefMap;
455
- }
456
- } catch (e) {
457
- this.dataMap.assetRefMap = AssetRefMap;
458
- }
446
+ initAssetRefMap() {
447
+ this.dataMap.assetRefMap = AssetRefMap;
459
448
  }
460
449
  checkLatestData() {
461
450
  clearInterval(this.refreshLatestChainDataTimeOut);
@@ -484,10 +473,15 @@ export class ChainService {
484
473
  console.error('Error fetching latest chain data');
485
474
  }
486
475
  }
487
- handleLatestBlockedAssetRef(latestBlockedAssetRefList) {
476
+ handleLatestAssetRef(latestBlockedAssetRefList, latestAssetRefMap) {
488
477
  const updatedAssetRefMap = {
489
478
  ...AssetRefMap
490
479
  };
480
+ if (latestAssetRefMap) {
481
+ for (const [assetRefKey, assetRef] of Object.entries(latestAssetRefMap)) {
482
+ updatedAssetRefMap[assetRefKey] = assetRef;
483
+ }
484
+ }
491
485
  latestBlockedAssetRefList.forEach(blockedAssetRef => {
492
486
  delete updatedAssetRefMap[blockedAssetRef];
493
487
  });
@@ -509,12 +503,75 @@ export class ChainService {
509
503
  }
510
504
  this.logger.log('Finished updating latest price IDs');
511
505
  }
506
+ handleLatestAssetData(_latestAssetInfo, _latestAssetLogoMap) {
507
+ try {
508
+ let needUpdate = false;
509
+ const latestAssetInfo = _latestAssetInfo || {};
510
+ const latestAssetLogoMap = _latestAssetLogoMap || {};
511
+ const latestAssetPatch = JSON.stringify(latestAssetInfo);
512
+ const latestAssetLogoPatch = JSON.stringify(latestAssetLogoMap);
513
+ if (this.assetMapPatch !== latestAssetPatch) {
514
+ needUpdate = true;
515
+ const assetRegistry = {
516
+ ...ChainAssetMap,
517
+ ...latestAssetInfo
518
+ };
519
+ this.assetMapPatch = latestAssetPatch;
520
+ this.dataMap.assetRegistry = assetRegistry;
521
+ this.assetRegistrySubject.next(assetRegistry);
522
+ }
523
+ if (this.assetLogoPatch !== latestAssetLogoPatch) {
524
+ const logoMap = {
525
+ ...AssetLogoMap,
526
+ ...latestAssetLogoMap
527
+ };
528
+ this.assetLogoPatch = latestAssetLogoPatch;
529
+ this.assetLogoMapSubject.next(logoMap);
530
+ }
531
+ if (needUpdate) {
532
+ this.autoEnableTokens().then(() => {
533
+ this.eventService.emit('asset.updateState', '');
534
+ }).catch(console.error);
535
+ }
536
+ } catch (e) {
537
+ console.error('Error fetching latest asset data');
538
+ }
539
+ this.logger.log('Finished updating latest asset');
540
+ }
541
+ async autoEnableTokens() {
542
+ const autoEnableTokens = Object.values(this.dataMap.assetRegistry).filter(asset => _isAssetAutoEnable(asset));
543
+ const assetSettings = this.assetSettingSubject.value;
544
+ const chainStateMap = this.getChainStateMap();
545
+ for (const asset of autoEnableTokens) {
546
+ const {
547
+ originChain,
548
+ slug: assetSlug
549
+ } = asset;
550
+ const assetState = assetSettings[assetSlug];
551
+ const chainState = chainStateMap[originChain];
552
+ if (!assetState) {
553
+ // If this asset not has asset setting, this token is not enabled before (not turned off before)
554
+ // @ts-ignore
555
+ // TODO: Merge issue detect balance to define manualTurnOff props
556
+ if (!chainState || !chainState.manualTurnOff) {
557
+ await this.updateAssetSetting(assetSlug, {
558
+ visible: true
559
+ });
560
+ }
561
+ }
562
+ }
563
+ }
512
564
  handleLatestData() {
565
+ this.fetchLatestAssetData().then(([latestAssetInfo, latestAssetLogoMap]) => {
566
+ this.eventService.waitAssetReady.then(() => {
567
+ this.handleLatestAssetData(latestAssetInfo, latestAssetLogoMap);
568
+ }).catch(console.error);
569
+ }).catch(console.error);
513
570
  this.fetchLatestChainData().then(latestChainInfo => {
514
571
  this.handleLatestProviderData(latestChainInfo);
515
572
  }).catch(console.error);
516
- this.fetchLatestBlockedAssetRef().then(latestAssetRef => {
517
- this.handleLatestBlockedAssetRef(latestAssetRef);
573
+ this.fetchLatestAssetRef().then(([latestAssetRef, latestAssetRefMap]) => {
574
+ this.handleLatestAssetRef(latestAssetRef, latestAssetRefMap);
518
575
  }).catch(console.error);
519
576
  this.fetchLatestPriceIdsData().then(latestPriceIds => {
520
577
  this.handleLatestPriceId(latestPriceIds);
@@ -708,12 +765,16 @@ export class ChainService {
708
765
  // }
709
766
  }
710
767
 
768
+ async fetchLatestAssetData() {
769
+ return await Promise.all([fetchPatchData('ChainAsset.json'), fetchPatchData('AssetLogoMap.json')]);
770
+ }
771
+
711
772
  // @ts-ignore
712
773
  async fetchLatestPriceIdsData() {
713
774
  return await fetchStaticData('chain-assets/price-map');
714
775
  }
715
- async fetchLatestBlockedAssetRef() {
716
- return await fetchStaticData('chain-assets/disabled-xcm-channels');
776
+ async fetchLatestAssetRef() {
777
+ return await Promise.all([fetchStaticData('chain-assets/disabled-xcm-channels'), fetchPatchData('AssetRef.json')]);
717
778
  }
718
779
  async initChains() {
719
780
  const storedChainSettings = await this.dbService.getAllChainStore();
@@ -1446,11 +1507,17 @@ export class ChainService {
1446
1507
  subscribeAssetSettings() {
1447
1508
  return this.assetSettingSubject;
1448
1509
  }
1449
- async getChainLogoMap() {
1450
- return Promise.resolve(ChainLogoMap);
1510
+ getAssetLogoMap() {
1511
+ return this.assetLogoMapSubject.value;
1512
+ }
1513
+ subscribeAssetLogoMap() {
1514
+ return this.assetLogoMapSubject;
1515
+ }
1516
+ getChainLogoMap() {
1517
+ return this.chainLogoMapSubject.value;
1451
1518
  }
1452
- async getAssetLogoMap() {
1453
- return Promise.resolve(AssetLogoMap);
1519
+ subscribeChainLogoMap() {
1520
+ return this.chainLogoMapSubject;
1454
1521
  }
1455
1522
  resetWallet(resetAll) {
1456
1523
  if (resetAll) {
@@ -63,6 +63,7 @@ export declare function _getBlockExplorerFromChain(chainInfo: _ChainInfo): strin
63
63
  export declare function _parseMetadataForSmartContractAsset(contractAddress: string): Record<string, string>;
64
64
  export declare function _isChainTestNet(chainInfo: _ChainInfo): boolean;
65
65
  export declare function _isAssetFungibleToken(chainAsset: _ChainAsset): boolean;
66
+ export declare const _isAssetAutoEnable: (chainAsset: _ChainAsset) => boolean;
66
67
  export declare function _getCrowdloanUrlFromChain(chainInfo: _ChainInfo): string;
67
68
  export declare function _isCustomProvider(providerKey: string): boolean;
68
69
  export declare function _generateCustomProviderKey(index: number): string;
@@ -77,3 +78,4 @@ export declare function updateLatestChainInfo(currentDataMap: _DataMap, latestCh
77
78
  storedChainInfoList: IChain[];
78
79
  needUpdateChainApiList: _ChainInfo[];
79
80
  };
81
+ export * from './patch';
@@ -330,6 +330,9 @@ export function _isChainTestNet(chainInfo) {
330
330
  export function _isAssetFungibleToken(chainAsset) {
331
331
  return ![_AssetType.ERC721, _AssetType.PSP34, _AssetType.UNKNOWN].includes(chainAsset.assetType);
332
332
  }
333
+ export const _isAssetAutoEnable = chainAsset => {
334
+ return chainAsset.metadata ? !!chainAsset.metadata.autoEnable : false;
335
+ };
333
336
  export function _getCrowdloanUrlFromChain(chainInfo) {
334
337
  var _chainInfo$substrateI13;
335
338
  return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI13 = chainInfo.substrateInfo) === null || _chainInfo$substrateI13 === void 0 ? void 0 : _chainInfo$substrateI13.crowdloanUrl) || '';
@@ -431,4 +434,5 @@ export function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
431
434
  storedChainInfoList,
432
435
  needUpdateChainApiList
433
436
  };
434
- }
437
+ }
438
+ export * from "./patch.js";
@@ -0,0 +1 @@
1
+ export declare function fetchPatchData<T>(slug: string): Promise<T | null>;
@@ -0,0 +1,26 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { packageInfo as chainListInfo } from '@subwallet/chain-list/packageInfo';
5
+ import fetch from 'cross-fetch';
6
+ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
7
+ const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
8
+ const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
9
+ export async function fetchPatchData(slug) {
10
+ try {
11
+ const fetchPromise = fetch(`${fetchDomain}/patch/${chainListInfo.version}/${slug}`);
12
+ const timeout = new Promise(resolve => {
13
+ const id = setTimeout(() => {
14
+ clearTimeout(id);
15
+ resolve(null);
16
+ }, 1000);
17
+ });
18
+ const rs = await Promise.race([timeout, fetchPromise]);
19
+ if (!rs) {
20
+ return null;
21
+ }
22
+ return await rs.json();
23
+ } catch (e) {
24
+ return null;
25
+ }
26
+ }