@subwallet/extension-base 1.1.49-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.
- package/background/KoniTypes.d.ts +2 -0
- package/cjs/koni/background/handlers/Extension.js +26 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/index.js +103 -34
- package/cjs/services/chain-service/{utils.js → utils/index.js} +89 -0
- package/cjs/services/chain-service/utils/patch.js +33 -0
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +26 -0
- package/package.json +14 -9
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/index.d.ts +14 -5
- package/services/chain-service/index.js +96 -29
- package/services/chain-service/{utils.d.ts → utils/index.d.ts} +2 -0
- package/services/chain-service/{utils.js → utils/index.js} +5 -1
- package/services/chain-service/utils/patch.d.ts +1 -0
- package/services/chain-service/utils/patch.js +26 -0
|
@@ -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];
|
|
@@ -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)':
|
package/cjs/packageInfo.js
CHANGED
|
@@ -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
|
-
|
|
458
|
+
this.initAssetRefMap();
|
|
459
|
+
await this.autoEnableTokens();
|
|
455
460
|
this.checkLatestData();
|
|
456
461
|
}
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
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.
|
|
534
|
-
|
|
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(
|
|
602
|
+
await Promise.all(Object.entries(chainInfoMap).filter(_ref8 => {
|
|
544
603
|
var _chainStateMap$slug;
|
|
545
|
-
let [slug] =
|
|
604
|
+
let [slug] = _ref8;
|
|
546
605
|
return (_chainStateMap$slug = chainStateMap[slug]) === null || _chainStateMap$slug === void 0 ? void 0 : _chainStateMap$slug.active;
|
|
547
|
-
}).map(
|
|
548
|
-
let [, chainInfo] =
|
|
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
|
|
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(
|
|
874
|
-
let [slug, chainInfo] =
|
|
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
|
-
|
|
1471
|
-
return
|
|
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
|
-
|
|
1474
|
-
return
|
|
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
|
+
}
|
|
@@ -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;
|
|
@@ -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.
|
|
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.
|
|
1800
|
-
"@subwallet/extension-base": "^1.1.
|
|
1801
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1802
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1803
|
-
"@subwallet/extension-inject": "^1.1.
|
|
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.
|
|
10
|
+
version: '1.1.50-0'
|
|
11
11
|
};
|
|
@@ -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():
|
|
83
|
+
initAssetRefMap(): void;
|
|
80
84
|
checkLatestData(): void;
|
|
81
85
|
stopCheckLatestChainData(): void;
|
|
82
86
|
handleLatestProviderData(latestChainInfo: _ChainInfo[]): void;
|
|
83
|
-
|
|
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
|
|
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
|
-
|
|
126
|
-
|
|
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
|
-
|
|
442
|
+
this.initAssetRefMap();
|
|
443
|
+
await this.autoEnableTokens();
|
|
439
444
|
this.checkLatestData();
|
|
440
445
|
}
|
|
441
|
-
|
|
442
|
-
|
|
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
|
-
|
|
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.
|
|
517
|
-
this.
|
|
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
|
|
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
|
-
|
|
1450
|
-
return
|
|
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
|
-
|
|
1453
|
-
return
|
|
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
|
+
}
|