@subwallet/extension-base 1.1.51-1 → 1.1.52-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 +1 -0
- package/cjs/koni/api/tokens/evm/balance.js +1 -2
- package/cjs/koni/api/tokens/evm/transfer.js +3 -5
- package/cjs/koni/api/tokens/evm/web3.js +3 -3
- package/cjs/koni/background/handlers/Extension.js +5 -4
- package/cjs/koni/background/handlers/State.js +21 -122
- package/cjs/koni/background/subscription.js +3 -63
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/BalanceMapImpl.js +2 -2
- package/cjs/services/balance-service/helpers/index.js +27 -0
- package/cjs/services/balance-service/helpers/subscribe/evm.js +33 -15
- package/cjs/services/balance-service/helpers/subscribe/{balance.js → index.js} +46 -29
- package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +34 -15
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +156 -72
- package/cjs/services/balance-service/index.js +371 -44
- package/cjs/services/chain-service/constants.js +2 -1
- package/cjs/services/chain-service/health-check/utils/asset-info.js +1 -3
- package/cjs/services/chain-service/index.js +60 -26
- package/cjs/services/chain-service/utils/index.js +10 -2
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +1 -1
- package/cjs/services/migration-service/scripts/AutoEnableChainsTokens.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +10 -1
- package/cjs/stores/DetectAccountBalance.js +18 -0
- package/cjs/utils/asset.js +19 -0
- package/cjs/utils/index.js +12 -0
- package/koni/api/tokens/evm/balance.d.ts +1 -1
- package/koni/api/tokens/evm/balance.js +1 -2
- package/koni/api/tokens/evm/transfer.d.ts +2 -2
- package/koni/api/tokens/evm/transfer.js +3 -5
- package/koni/api/tokens/evm/web3.d.ts +1 -1
- package/koni/api/tokens/evm/web3.js +2 -2
- package/koni/background/handlers/Extension.js +5 -4
- package/koni/background/handlers/State.d.ts +2 -13
- package/koni/background/handlers/State.js +21 -121
- package/koni/background/subscription.d.ts +1 -5
- package/koni/background/subscription.js +1 -60
- package/package.json +28 -13
- package/packageInfo.js +1 -1
- package/services/balance-service/BalanceMapImpl.js +1 -1
- package/services/balance-service/helpers/index.d.ts +2 -0
- package/services/balance-service/helpers/index.js +5 -0
- package/services/balance-service/helpers/subscribe/evm.d.ts +3 -5
- package/services/balance-service/helpers/subscribe/evm.js +31 -14
- package/services/balance-service/helpers/subscribe/{balance.d.ts → index.d.ts} +2 -2
- package/services/balance-service/helpers/subscribe/{balance.js → index.js} +41 -28
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.d.ts +3 -4
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +29 -13
- package/services/balance-service/helpers/subscribe/substrate/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/substrate/index.js +143 -67
- package/services/balance-service/index.d.ts +71 -4
- package/services/balance-service/index.js +372 -46
- package/services/chain-service/constants.js +2 -1
- package/services/chain-service/health-check/utils/asset-info.js +1 -3
- package/services/chain-service/index.d.ts +2 -1
- package/services/chain-service/index.js +61 -27
- package/services/chain-service/types.d.ts +1 -0
- package/services/chain-service/utils/index.js +10 -2
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +1 -1
- package/services/migration-service/scripts/AutoEnableChainsTokens.js +1 -1
- package/services/storage-service/DatabaseService.js +7 -1
- package/services/storage-service/databases/index.d.ts +1 -0
- package/stores/DetectAccountBalance.d.ts +5 -0
- package/stores/DetectAccountBalance.js +10 -0
- package/types/{balance.d.ts → balance/index.d.ts} +16 -0
- package/types/index.js +1 -1
- package/utils/asset.d.ts +2 -0
- package/utils/asset.js +12 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- /package/cjs/types/{balance.js → balance/index.js} +0 -0
- /package/types/{balance.js → balance/index.js} +0 -0
|
@@ -11,7 +11,7 @@ import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chai
|
|
|
11
11
|
import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
|
|
12
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
|
-
import { addLazy, fetchStaticData, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
|
|
14
|
+
import { addLazy, fetchStaticData, filterAssetsByChainAndType, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
|
|
15
15
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
16
16
|
import Web3 from 'web3';
|
|
17
17
|
import { logger as createLogger } from '@polkadot/util/logger';
|
|
@@ -271,13 +271,7 @@ export class ChainService {
|
|
|
271
271
|
return destinationTokenInfo;
|
|
272
272
|
}
|
|
273
273
|
getAssetByChainAndType(chainSlug, assetTypes) {
|
|
274
|
-
|
|
275
|
-
Object.values(this.getAssetRegistry()).forEach(assetInfo => {
|
|
276
|
-
if (assetTypes.includes(assetInfo.assetType) && assetInfo.originChain === chainSlug) {
|
|
277
|
-
result[assetInfo.slug] = assetInfo;
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
return result;
|
|
274
|
+
return filterAssetsByChainAndType(this.getAssetRegistry(), chainSlug, assetTypes);
|
|
281
275
|
}
|
|
282
276
|
getSmartContractNfts() {
|
|
283
277
|
const result = [];
|
|
@@ -454,7 +448,7 @@ export class ChainService {
|
|
|
454
448
|
stopCheckLatestChainData() {
|
|
455
449
|
clearInterval(this.refreshLatestChainDataTimeOut);
|
|
456
450
|
}
|
|
457
|
-
|
|
451
|
+
handleLatestChainData(latestChainInfo) {
|
|
458
452
|
try {
|
|
459
453
|
if (latestChainInfo && latestChainInfo.length > 0) {
|
|
460
454
|
const {
|
|
@@ -531,6 +525,17 @@ export class ChainService {
|
|
|
531
525
|
this.assetLogoMapSubject.next(logoMap);
|
|
532
526
|
}
|
|
533
527
|
}
|
|
528
|
+
if (latestAssetLogoMap) {
|
|
529
|
+
const latestAssetLogoPatch = JSON.stringify(latestAssetLogoMap);
|
|
530
|
+
if (this.assetLogoPatch !== latestAssetLogoPatch) {
|
|
531
|
+
const logoMap = {
|
|
532
|
+
...AssetLogoMap,
|
|
533
|
+
...latestAssetLogoMap
|
|
534
|
+
};
|
|
535
|
+
this.assetLogoPatch = latestAssetLogoPatch;
|
|
536
|
+
this.assetLogoMapSubject.next(logoMap);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
534
539
|
} catch (e) {
|
|
535
540
|
console.error('Error fetching latest asset data');
|
|
536
541
|
}
|
|
@@ -550,8 +555,6 @@ export class ChainService {
|
|
|
550
555
|
const chainState = chainStateMap[originChain];
|
|
551
556
|
if (!assetState) {
|
|
552
557
|
// If this asset not has asset setting, this token is not enabled before (not turned off before)
|
|
553
|
-
// @ts-ignore
|
|
554
|
-
// TODO: Merge issue detect balance to define manualTurnOff props
|
|
555
558
|
if (!chainState || !chainState.manualTurnOff) {
|
|
556
559
|
await this.updateAssetSetting(assetSlug, {
|
|
557
560
|
visible: true
|
|
@@ -567,7 +570,7 @@ export class ChainService {
|
|
|
567
570
|
}).catch(console.error);
|
|
568
571
|
}).catch(console.error);
|
|
569
572
|
this.fetchLatestChainData().then(latestChainInfo => {
|
|
570
|
-
this.
|
|
573
|
+
this.handleLatestChainData(latestChainInfo);
|
|
571
574
|
}).catch(console.error);
|
|
572
575
|
this.fetchLatestAssetRef().then(([latestAssetRef, latestAssetRefMap]) => {
|
|
573
576
|
this.handleLatestAssetRef(latestAssetRef, latestAssetRefMap);
|
|
@@ -644,7 +647,8 @@ export class ChainService {
|
|
|
644
647
|
this.dbService.updateChainStore({
|
|
645
648
|
...chainInfo,
|
|
646
649
|
active: true,
|
|
647
|
-
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
650
|
+
currentProvider: chainStateMap[chainSlug].currentProvider,
|
|
651
|
+
manualTurnOff: !!chainStateMap[chainSlug].manualTurnOff
|
|
648
652
|
}).catch(console.error);
|
|
649
653
|
chainStateMap[chainSlug].active = true;
|
|
650
654
|
await this.initApiForChain(chainInfo);
|
|
@@ -669,7 +673,8 @@ export class ChainService {
|
|
|
669
673
|
this.dbService.updateChainStore({
|
|
670
674
|
...chainInfo,
|
|
671
675
|
active: true,
|
|
672
|
-
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
676
|
+
currentProvider: chainStateMap[chainSlug].currentProvider,
|
|
677
|
+
manualTurnOff: !!chainStateMap[chainSlug].manualTurnOff
|
|
673
678
|
}).catch(console.error);
|
|
674
679
|
chainStateMap[chainSlug].active = true;
|
|
675
680
|
await this.initApiForChain(chainInfo);
|
|
@@ -696,13 +701,15 @@ export class ChainService {
|
|
|
696
701
|
}
|
|
697
702
|
this.lockChainInfoMap = true;
|
|
698
703
|
chainStateMap[chainSlug].active = false;
|
|
704
|
+
chainStateMap[chainSlug].manualTurnOff = true;
|
|
699
705
|
// Set disconnect state for inactive chain
|
|
700
706
|
this.updateChainConnectionStatus(chainSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
701
707
|
this.destroyApiForChain(chainInfo);
|
|
702
708
|
this.dbService.updateChainStore({
|
|
703
709
|
...chainInfo,
|
|
704
710
|
active: false,
|
|
705
|
-
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
711
|
+
currentProvider: chainStateMap[chainSlug].currentProvider,
|
|
712
|
+
manualTurnOff: true
|
|
706
713
|
}).catch(console.error);
|
|
707
714
|
this.updateChainStateMapSubscription();
|
|
708
715
|
this.lockChainInfoMap = false;
|
|
@@ -794,7 +801,8 @@ export class ChainService {
|
|
|
794
801
|
this.dataMap.chainStateMap[chainInfo.slug] = {
|
|
795
802
|
currentProvider: providerKey,
|
|
796
803
|
slug: chainInfo.slug,
|
|
797
|
-
active: _DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
|
|
804
|
+
active: _DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug),
|
|
805
|
+
manualTurnOff: false
|
|
798
806
|
};
|
|
799
807
|
this.updateChainConnectionStatus(chainInfo.slug, _ChainConnectionStatus.DISCONNECTED);
|
|
800
808
|
|
|
@@ -802,13 +810,15 @@ export class ChainService {
|
|
|
802
810
|
newStorageData.push({
|
|
803
811
|
...chainInfo,
|
|
804
812
|
active: _DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug),
|
|
805
|
-
currentProvider: providerKey
|
|
813
|
+
currentProvider: providerKey,
|
|
814
|
+
manualTurnOff: false
|
|
806
815
|
});
|
|
807
816
|
});
|
|
808
817
|
} else {
|
|
809
818
|
const mergedChainInfoMap = defaultChainInfoMap;
|
|
810
819
|
for (const [storedSlug, storedChainInfo] of Object.entries(storedChainSettingMap)) {
|
|
811
820
|
const chainInfo = defaultChainInfoMap[storedSlug];
|
|
821
|
+
const manualTurnOff = !!storedChainInfo.manualTurnOff;
|
|
812
822
|
|
|
813
823
|
// Network existed on change list
|
|
814
824
|
// check predefined chains first, keep setting for providers and currentProvider
|
|
@@ -847,13 +857,15 @@ export class ChainService {
|
|
|
847
857
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
848
858
|
currentProvider: selectedProvider,
|
|
849
859
|
slug: storedSlug,
|
|
850
|
-
active: canActive && storedChainInfo.active
|
|
860
|
+
active: canActive && storedChainInfo.active,
|
|
861
|
+
manualTurnOff
|
|
851
862
|
};
|
|
852
863
|
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
853
864
|
newStorageData.push({
|
|
854
865
|
...mergedChainInfoMap[storedSlug],
|
|
855
866
|
active: canActive && storedChainInfo.active,
|
|
856
|
-
currentProvider: selectedProvider
|
|
867
|
+
currentProvider: selectedProvider,
|
|
868
|
+
manualTurnOff
|
|
857
869
|
});
|
|
858
870
|
} else if (_isCustomChain(storedSlug)) {
|
|
859
871
|
var _storedChainInfo$subs, _storedChainInfo$evmI;
|
|
@@ -869,13 +881,15 @@ export class ChainService {
|
|
|
869
881
|
this.dataMap.chainStateMap[duplicatedDefaultSlug] = {
|
|
870
882
|
currentProvider: storedChainInfo.currentProvider,
|
|
871
883
|
slug: duplicatedDefaultSlug,
|
|
872
|
-
active: storedChainInfo.active
|
|
884
|
+
active: storedChainInfo.active,
|
|
885
|
+
manualTurnOff
|
|
873
886
|
};
|
|
874
887
|
this.updateChainConnectionStatus(duplicatedDefaultSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
875
888
|
newStorageData.push({
|
|
876
889
|
...mergedChainInfoMap[duplicatedDefaultSlug],
|
|
877
890
|
active: storedChainInfo.active,
|
|
878
|
-
currentProvider: storedChainInfo.currentProvider
|
|
891
|
+
currentProvider: storedChainInfo.currentProvider,
|
|
892
|
+
manualTurnOff
|
|
879
893
|
});
|
|
880
894
|
deprecatedChainMap[storedSlug] = duplicatedDefaultSlug;
|
|
881
895
|
deprecatedChains.push(storedSlug);
|
|
@@ -896,13 +910,16 @@ export class ChainService {
|
|
|
896
910
|
currentProvider: storedChainInfo.currentProvider,
|
|
897
911
|
// TODO: review
|
|
898
912
|
slug: storedSlug,
|
|
899
|
-
active: storedChainInfo.active
|
|
913
|
+
active: storedChainInfo.active,
|
|
914
|
+
manualTurnOff
|
|
900
915
|
};
|
|
901
916
|
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
902
917
|
newStorageData.push({
|
|
903
918
|
...mergedChainInfoMap[storedSlug],
|
|
904
919
|
active: storedChainInfo.active,
|
|
905
|
-
currentProvider: storedChainInfo.currentProvider
|
|
920
|
+
currentProvider: storedChainInfo.currentProvider,
|
|
921
|
+
// TODO: review
|
|
922
|
+
manualTurnOff
|
|
906
923
|
});
|
|
907
924
|
}
|
|
908
925
|
} else {
|
|
@@ -916,13 +933,15 @@ export class ChainService {
|
|
|
916
933
|
this.dataMap.chainStateMap[slug] = {
|
|
917
934
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
918
935
|
slug,
|
|
919
|
-
active: _DEFAULT_ACTIVE_CHAINS.includes(slug)
|
|
936
|
+
active: _DEFAULT_ACTIVE_CHAINS.includes(slug),
|
|
937
|
+
manualTurnOff: false
|
|
920
938
|
};
|
|
921
939
|
this.updateChainConnectionStatus(slug, _ChainConnectionStatus.DISCONNECTED);
|
|
922
940
|
newStorageData.push({
|
|
923
941
|
...mergedChainInfoMap[slug],
|
|
924
942
|
active: _DEFAULT_ACTIVE_CHAINS.includes(slug),
|
|
925
|
-
currentProvider: Object.keys(chainInfo.providers)[0]
|
|
943
|
+
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
944
|
+
manualTurnOff: false
|
|
926
945
|
});
|
|
927
946
|
}
|
|
928
947
|
});
|
|
@@ -1039,7 +1058,8 @@ export class ChainService {
|
|
|
1039
1058
|
this.dbService.updateChainStore({
|
|
1040
1059
|
...targetChainInfo,
|
|
1041
1060
|
active: targetChainState.active,
|
|
1042
|
-
currentProvider: targetChainState.currentProvider
|
|
1061
|
+
currentProvider: targetChainState.currentProvider,
|
|
1062
|
+
manualTurnOff: !targetChainState.active || !!targetChainState.manualTurnOff
|
|
1043
1063
|
}).then(() => {
|
|
1044
1064
|
this.eventService.emit('chain.updateState', chainSlug);
|
|
1045
1065
|
}).catch(e => this.logger.error(e));
|
|
@@ -1103,7 +1123,8 @@ export class ChainService {
|
|
|
1103
1123
|
chainStateMap[newChainSlug] = {
|
|
1104
1124
|
active: true,
|
|
1105
1125
|
currentProvider: params.chainEditInfo.currentProvider,
|
|
1106
|
-
slug: newChainSlug
|
|
1126
|
+
slug: newChainSlug,
|
|
1127
|
+
manualTurnOff: false
|
|
1107
1128
|
};
|
|
1108
1129
|
|
|
1109
1130
|
// const chainStatusMap = this.getChainStatusMap();
|
|
@@ -1138,6 +1159,7 @@ export class ChainService {
|
|
|
1138
1159
|
this.dbService.updateChainStore({
|
|
1139
1160
|
active: true,
|
|
1140
1161
|
currentProvider: params.chainEditInfo.currentProvider,
|
|
1162
|
+
manualTurnOff: false,
|
|
1141
1163
|
...chainInfo
|
|
1142
1164
|
}).then(() => {
|
|
1143
1165
|
this.eventService.emit('chain.add', newChainSlug);
|
|
@@ -1576,4 +1598,16 @@ export class ChainService {
|
|
|
1576
1598
|
});
|
|
1577
1599
|
return result;
|
|
1578
1600
|
}
|
|
1601
|
+
get detectBalanceChainSlugMap() {
|
|
1602
|
+
const result = {};
|
|
1603
|
+
const chainInfoMap = this.getChainInfoMap();
|
|
1604
|
+
for (const [key, chainInfo] of Object.entries(chainInfoMap)) {
|
|
1605
|
+
var _chainInfo$extraInfo;
|
|
1606
|
+
const chainBalanceSlug = ((_chainInfo$extraInfo = chainInfo.extraInfo) === null || _chainInfo$extraInfo === void 0 ? void 0 : _chainInfo$extraInfo.chainBalanceSlug) || '';
|
|
1607
|
+
if (chainBalanceSlug) {
|
|
1608
|
+
result[chainBalanceSlug] = key;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
return result;
|
|
1612
|
+
}
|
|
1579
1613
|
}
|
|
@@ -400,10 +400,11 @@ export function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
|
|
|
400
400
|
const currentChainStateMap = currentDataMap.chainStateMap;
|
|
401
401
|
const storedChainInfoList = [];
|
|
402
402
|
const needUpdateChainApiList = [];
|
|
403
|
-
|
|
403
|
+
for (const latestChainInfo of latestChainInfoList) {
|
|
404
404
|
const currentChainInfo = currentChainInfoMap[latestChainInfo.slug];
|
|
405
405
|
const currentChainState = currentChainStateMap[latestChainInfo.slug];
|
|
406
406
|
const currentChainProviderValue = currentChainInfo === null || currentChainInfo === void 0 ? void 0 : currentChainInfo.providers[currentChainState === null || currentChainState === void 0 ? void 0 : currentChainState.currentProvider];
|
|
407
|
+
let needUpdate = false;
|
|
407
408
|
if (currentChainInfo && currentChainState) {
|
|
408
409
|
const preservedProvider = {};
|
|
409
410
|
Object.entries(currentChainInfo.providers).forEach(([providerKey, providerValue]) => {
|
|
@@ -424,12 +425,19 @@ export function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
|
|
|
424
425
|
currentChainState.currentProvider = providerKey;
|
|
425
426
|
needUpdateChainApiList.push(currentChainInfo);
|
|
426
427
|
}
|
|
428
|
+
needUpdate = true;
|
|
429
|
+
}
|
|
430
|
+
if (currentChainInfo) {
|
|
431
|
+
needUpdate = true;
|
|
432
|
+
currentChainInfo.extraInfo = latestChainInfo.extraInfo;
|
|
433
|
+
}
|
|
434
|
+
if (needUpdate) {
|
|
427
435
|
storedChainInfoList.push({
|
|
428
436
|
...currentChainInfo,
|
|
429
437
|
...currentChainState
|
|
430
438
|
});
|
|
431
439
|
}
|
|
432
|
-
}
|
|
440
|
+
}
|
|
433
441
|
return {
|
|
434
442
|
storedChainInfoList,
|
|
435
443
|
needUpdateChainApiList
|
|
@@ -5,7 +5,7 @@ import fetch from 'cross-fetch';
|
|
|
5
5
|
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
6
6
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
7
7
|
const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
|
|
8
|
-
const ChainListVersion = '0.2.
|
|
8
|
+
const ChainListVersion = '0.2.54';
|
|
9
9
|
export async function fetchPatchData(slug) {
|
|
10
10
|
try {
|
|
11
11
|
const fetchPromise = fetch(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
|
|
@@ -192,7 +192,7 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
192
192
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
193
193
|
const inputTokenSlug = this.inputAsset;
|
|
194
194
|
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
195
|
-
const inputTokenContract = getERC20Contract(
|
|
195
|
+
const inputTokenContract = getERC20Contract(_getContractAddressOfToken(inputTokenInfo), evmApi);
|
|
196
196
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
197
197
|
const allowanceCall = inputTokenContract.methods.allowance(params.address, _getContractAddressOfToken(derivativeTokenInfo));
|
|
198
198
|
const [allowance, gasPrice] = await Promise.all([
|
|
@@ -257,7 +257,7 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
257
257
|
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
258
258
|
const derivativeTokenContractAddress = _getContractAddressOfToken(derivativeTokenInfo);
|
|
259
259
|
const evmApi = this.evmApi;
|
|
260
|
-
const inputTokenContract = getERC20Contract(
|
|
260
|
+
const inputTokenContract = getERC20Contract(_getContractAddressOfToken(inputTokenInfo), evmApi);
|
|
261
261
|
|
|
262
262
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
263
263
|
const approveCall = inputTokenContract.methods.approve(derivativeTokenContractAddress, MAX_INT); // TODO: need test
|
|
@@ -149,7 +149,7 @@ export default class ParaNativeStakingPoolHandler extends BaseParaNativeStakingP
|
|
|
149
149
|
for (const scheduledRequest of delegationScheduledRequests) {
|
|
150
150
|
if (reformatAddress(scheduledRequest.delegator, 0) === reformatAddress(address, 0)) {
|
|
151
151
|
// add network prefix
|
|
152
|
-
const isClaimable = scheduledRequest.whenExecutable - currentRound
|
|
152
|
+
const isClaimable = scheduledRequest.whenExecutable - currentRound <= 0;
|
|
153
153
|
const remainingEra = scheduledRequest.whenExecutable - currentRound;
|
|
154
154
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
155
155
|
const claimable = Object.values(scheduledRequest.action)[0];
|
|
@@ -6,7 +6,7 @@ import { keyring } from '@subwallet/ui-keyring';
|
|
|
6
6
|
export default class AutoEnableChainsTokens extends BaseMigrationJob {
|
|
7
7
|
async run() {
|
|
8
8
|
const accounts = keyring.getAccounts();
|
|
9
|
-
await this.state.autoEnableChains(accounts.map(({
|
|
9
|
+
await this.state.balanceService.autoEnableChains(accounts.map(({
|
|
10
10
|
address
|
|
11
11
|
}) => address));
|
|
12
12
|
}
|
|
@@ -11,6 +11,7 @@ import NominatorMetadataStore from '@subwallet/extension-base/services/storage-s
|
|
|
11
11
|
import YieldPoolStore from '@subwallet/extension-base/services/storage-service/db-stores/YieldPoolStore';
|
|
12
12
|
import YieldPositionStore from '@subwallet/extension-base/services/storage-service/db-stores/YieldPositionStore';
|
|
13
13
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
14
|
+
import keyring from '@subwallet/ui-keyring';
|
|
14
15
|
import { exportDB } from 'dexie-export-import';
|
|
15
16
|
import { logger as createLogger } from '@polkadot/util';
|
|
16
17
|
export const DEXIE_BACKUP_TABLES = ['chain', 'asset', 'migrations', 'transactions', 'campaign'];
|
|
@@ -63,7 +64,12 @@ export default class DatabaseService {
|
|
|
63
64
|
|
|
64
65
|
// Balance
|
|
65
66
|
async getStoredBalance() {
|
|
66
|
-
|
|
67
|
+
const addresses = keyring.getPairs().map(({
|
|
68
|
+
address
|
|
69
|
+
}) => address);
|
|
70
|
+
|
|
71
|
+
// Filter not exist address
|
|
72
|
+
return this.stores.balance.table.filter(obj => addresses.includes(obj.address)).toArray();
|
|
67
73
|
}
|
|
68
74
|
async updateBalanceStore(item) {
|
|
69
75
|
if (item.state === APIItemState.READY) {
|
|
@@ -15,6 +15,7 @@ export interface IBalance extends BalanceItem, DefaultAddressDoc {
|
|
|
15
15
|
export interface IChain extends _ChainInfo {
|
|
16
16
|
active: boolean;
|
|
17
17
|
currentProvider: string;
|
|
18
|
+
manualTurnOff: boolean;
|
|
18
19
|
}
|
|
19
20
|
export interface ICrowdloanItem extends CrowdloanItem, DefaultAddressDoc, DefaultChainDoc {
|
|
20
21
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DetectBalanceCache } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import SubscribableStore from '@subwallet/extension-base/stores/SubscribableStore';
|
|
3
|
+
export default class DetectAccountBalanceStore extends SubscribableStore<DetectBalanceCache> {
|
|
4
|
+
constructor();
|
|
5
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { EXTENSION_PREFIX } from '@subwallet/extension-base/defaults';
|
|
5
|
+
import SubscribableStore from '@subwallet/extension-base/stores/SubscribableStore';
|
|
6
|
+
export default class DetectAccountBalanceStore extends SubscribableStore {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(EXTENSION_PREFIX ? `${EXTENSION_PREFIX}DetectBalanceCache` : null);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
1
2
|
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
+
import { ApiPromise } from '@polkadot/api';
|
|
2
5
|
import { BN } from '@polkadot/util';
|
|
3
6
|
export interface TokenBalanceRaw {
|
|
4
7
|
reserved: BN;
|
|
@@ -37,3 +40,16 @@ export interface BalanceJson {
|
|
|
37
40
|
reset?: boolean;
|
|
38
41
|
details: BalanceMap;
|
|
39
42
|
}
|
|
43
|
+
export interface SubscribeBasePalletBalance {
|
|
44
|
+
addresses: string[];
|
|
45
|
+
assetMap: Record<string, _ChainAsset>;
|
|
46
|
+
chainInfo: _ChainInfo;
|
|
47
|
+
callback: (rs: BalanceItem[]) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface SubscribeSubstratePalletBalance extends SubscribeBasePalletBalance {
|
|
50
|
+
substrateApi: ApiPromise;
|
|
51
|
+
includeNativeToken?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface SubscribeEvmPalletBalance extends SubscribeBasePalletBalance {
|
|
54
|
+
evmApi: _EvmApi;
|
|
55
|
+
}
|
package/types/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export * from "./balance.js";
|
|
4
|
+
export * from "./balance/index.js";
|
|
5
5
|
export * from "./buy.js";
|
|
6
6
|
export * from "./campaigns/index.js";
|
|
7
7
|
export * from "./fee/index.js";
|
package/utils/asset.d.ts
ADDED
package/utils/asset.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export const filterAssetsByChainAndType = (chainAssetMap, chain, assetTypes) => {
|
|
5
|
+
const result = {};
|
|
6
|
+
Object.values(chainAssetMap).forEach(assetInfo => {
|
|
7
|
+
if (assetTypes.includes(assetInfo.assetType) && assetInfo.originChain === chain) {
|
|
8
|
+
result[assetInfo.slug] = assetInfo;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return result;
|
|
12
|
+
};
|
package/utils/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare const swParseIPFSUrl: (input: string) => string | undefined;
|
|
|
42
42
|
export declare function wait(milliseconds: number): Promise<void>;
|
|
43
43
|
export * from './account';
|
|
44
44
|
export * from './array';
|
|
45
|
+
export * from './asset';
|
|
45
46
|
export * from './environment';
|
|
46
47
|
export * from './eth';
|
|
47
48
|
export * from './number';
|
package/utils/index.js
CHANGED
|
File without changes
|
|
File without changes
|