@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
|
@@ -286,13 +286,7 @@ class ChainService {
|
|
|
286
286
|
return destinationTokenInfo;
|
|
287
287
|
}
|
|
288
288
|
getAssetByChainAndType(chainSlug, assetTypes) {
|
|
289
|
-
|
|
290
|
-
Object.values(this.getAssetRegistry()).forEach(assetInfo => {
|
|
291
|
-
if (assetTypes.includes(assetInfo.assetType) && assetInfo.originChain === chainSlug) {
|
|
292
|
-
result[assetInfo.slug] = assetInfo;
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
return result;
|
|
289
|
+
return (0, _utils2.filterAssetsByChainAndType)(this.getAssetRegistry(), chainSlug, assetTypes);
|
|
296
290
|
}
|
|
297
291
|
getSmartContractNfts() {
|
|
298
292
|
const result = [];
|
|
@@ -470,7 +464,7 @@ class ChainService {
|
|
|
470
464
|
stopCheckLatestChainData() {
|
|
471
465
|
clearInterval(this.refreshLatestChainDataTimeOut);
|
|
472
466
|
}
|
|
473
|
-
|
|
467
|
+
handleLatestChainData(latestChainInfo) {
|
|
474
468
|
try {
|
|
475
469
|
if (latestChainInfo && latestChainInfo.length > 0) {
|
|
476
470
|
const {
|
|
@@ -548,6 +542,17 @@ class ChainService {
|
|
|
548
542
|
this.assetLogoMapSubject.next(logoMap);
|
|
549
543
|
}
|
|
550
544
|
}
|
|
545
|
+
if (latestAssetLogoMap) {
|
|
546
|
+
const latestAssetLogoPatch = JSON.stringify(latestAssetLogoMap);
|
|
547
|
+
if (this.assetLogoPatch !== latestAssetLogoPatch) {
|
|
548
|
+
const logoMap = {
|
|
549
|
+
..._chainList.AssetLogoMap,
|
|
550
|
+
...latestAssetLogoMap
|
|
551
|
+
};
|
|
552
|
+
this.assetLogoPatch = latestAssetLogoPatch;
|
|
553
|
+
this.assetLogoMapSubject.next(logoMap);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
551
556
|
} catch (e) {
|
|
552
557
|
console.error('Error fetching latest asset data');
|
|
553
558
|
}
|
|
@@ -567,8 +572,6 @@ class ChainService {
|
|
|
567
572
|
const chainState = chainStateMap[originChain];
|
|
568
573
|
if (!assetState) {
|
|
569
574
|
// If this asset not has asset setting, this token is not enabled before (not turned off before)
|
|
570
|
-
// @ts-ignore
|
|
571
|
-
// TODO: Merge issue detect balance to define manualTurnOff props
|
|
572
575
|
if (!chainState || !chainState.manualTurnOff) {
|
|
573
576
|
await this.updateAssetSetting(assetSlug, {
|
|
574
577
|
visible: true
|
|
@@ -585,7 +588,7 @@ class ChainService {
|
|
|
585
588
|
}).catch(console.error);
|
|
586
589
|
}).catch(console.error);
|
|
587
590
|
this.fetchLatestChainData().then(latestChainInfo => {
|
|
588
|
-
this.
|
|
591
|
+
this.handleLatestChainData(latestChainInfo);
|
|
589
592
|
}).catch(console.error);
|
|
590
593
|
this.fetchLatestAssetRef().then(_ref7 => {
|
|
591
594
|
let [latestAssetRef, latestAssetRefMap] = _ref7;
|
|
@@ -665,7 +668,8 @@ class ChainService {
|
|
|
665
668
|
this.dbService.updateChainStore({
|
|
666
669
|
...chainInfo,
|
|
667
670
|
active: true,
|
|
668
|
-
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
671
|
+
currentProvider: chainStateMap[chainSlug].currentProvider,
|
|
672
|
+
manualTurnOff: !!chainStateMap[chainSlug].manualTurnOff
|
|
669
673
|
}).catch(console.error);
|
|
670
674
|
chainStateMap[chainSlug].active = true;
|
|
671
675
|
await this.initApiForChain(chainInfo);
|
|
@@ -690,7 +694,8 @@ class ChainService {
|
|
|
690
694
|
this.dbService.updateChainStore({
|
|
691
695
|
...chainInfo,
|
|
692
696
|
active: true,
|
|
693
|
-
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
697
|
+
currentProvider: chainStateMap[chainSlug].currentProvider,
|
|
698
|
+
manualTurnOff: !!chainStateMap[chainSlug].manualTurnOff
|
|
694
699
|
}).catch(console.error);
|
|
695
700
|
chainStateMap[chainSlug].active = true;
|
|
696
701
|
await this.initApiForChain(chainInfo);
|
|
@@ -717,13 +722,15 @@ class ChainService {
|
|
|
717
722
|
}
|
|
718
723
|
this.lockChainInfoMap = true;
|
|
719
724
|
chainStateMap[chainSlug].active = false;
|
|
725
|
+
chainStateMap[chainSlug].manualTurnOff = true;
|
|
720
726
|
// Set disconnect state for inactive chain
|
|
721
727
|
this.updateChainConnectionStatus(chainSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
722
728
|
this.destroyApiForChain(chainInfo);
|
|
723
729
|
this.dbService.updateChainStore({
|
|
724
730
|
...chainInfo,
|
|
725
731
|
active: false,
|
|
726
|
-
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
732
|
+
currentProvider: chainStateMap[chainSlug].currentProvider,
|
|
733
|
+
manualTurnOff: true
|
|
727
734
|
}).catch(console.error);
|
|
728
735
|
this.updateChainStateMapSubscription();
|
|
729
736
|
this.lockChainInfoMap = false;
|
|
@@ -815,7 +822,8 @@ class ChainService {
|
|
|
815
822
|
this.dataMap.chainStateMap[chainInfo.slug] = {
|
|
816
823
|
currentProvider: providerKey,
|
|
817
824
|
slug: chainInfo.slug,
|
|
818
|
-
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
|
|
825
|
+
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug),
|
|
826
|
+
manualTurnOff: false
|
|
819
827
|
};
|
|
820
828
|
this.updateChainConnectionStatus(chainInfo.slug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
821
829
|
|
|
@@ -823,13 +831,15 @@ class ChainService {
|
|
|
823
831
|
newStorageData.push({
|
|
824
832
|
...chainInfo,
|
|
825
833
|
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug),
|
|
826
|
-
currentProvider: providerKey
|
|
834
|
+
currentProvider: providerKey,
|
|
835
|
+
manualTurnOff: false
|
|
827
836
|
});
|
|
828
837
|
});
|
|
829
838
|
} else {
|
|
830
839
|
const mergedChainInfoMap = defaultChainInfoMap;
|
|
831
840
|
for (const [storedSlug, storedChainInfo] of Object.entries(storedChainSettingMap)) {
|
|
832
841
|
const chainInfo = defaultChainInfoMap[storedSlug];
|
|
842
|
+
const manualTurnOff = !!storedChainInfo.manualTurnOff;
|
|
833
843
|
|
|
834
844
|
// Network existed on change list
|
|
835
845
|
// check predefined chains first, keep setting for providers and currentProvider
|
|
@@ -868,13 +878,15 @@ class ChainService {
|
|
|
868
878
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
869
879
|
currentProvider: selectedProvider,
|
|
870
880
|
slug: storedSlug,
|
|
871
|
-
active: canActive && storedChainInfo.active
|
|
881
|
+
active: canActive && storedChainInfo.active,
|
|
882
|
+
manualTurnOff
|
|
872
883
|
};
|
|
873
884
|
this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
874
885
|
newStorageData.push({
|
|
875
886
|
...mergedChainInfoMap[storedSlug],
|
|
876
887
|
active: canActive && storedChainInfo.active,
|
|
877
|
-
currentProvider: selectedProvider
|
|
888
|
+
currentProvider: selectedProvider,
|
|
889
|
+
manualTurnOff
|
|
878
890
|
});
|
|
879
891
|
} else if ((0, _utils._isCustomChain)(storedSlug)) {
|
|
880
892
|
var _storedChainInfo$subs, _storedChainInfo$evmI;
|
|
@@ -890,13 +902,15 @@ class ChainService {
|
|
|
890
902
|
this.dataMap.chainStateMap[duplicatedDefaultSlug] = {
|
|
891
903
|
currentProvider: storedChainInfo.currentProvider,
|
|
892
904
|
slug: duplicatedDefaultSlug,
|
|
893
|
-
active: storedChainInfo.active
|
|
905
|
+
active: storedChainInfo.active,
|
|
906
|
+
manualTurnOff
|
|
894
907
|
};
|
|
895
908
|
this.updateChainConnectionStatus(duplicatedDefaultSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
896
909
|
newStorageData.push({
|
|
897
910
|
...mergedChainInfoMap[duplicatedDefaultSlug],
|
|
898
911
|
active: storedChainInfo.active,
|
|
899
|
-
currentProvider: storedChainInfo.currentProvider
|
|
912
|
+
currentProvider: storedChainInfo.currentProvider,
|
|
913
|
+
manualTurnOff
|
|
900
914
|
});
|
|
901
915
|
deprecatedChainMap[storedSlug] = duplicatedDefaultSlug;
|
|
902
916
|
deprecatedChains.push(storedSlug);
|
|
@@ -917,13 +931,16 @@ class ChainService {
|
|
|
917
931
|
currentProvider: storedChainInfo.currentProvider,
|
|
918
932
|
// TODO: review
|
|
919
933
|
slug: storedSlug,
|
|
920
|
-
active: storedChainInfo.active
|
|
934
|
+
active: storedChainInfo.active,
|
|
935
|
+
manualTurnOff
|
|
921
936
|
};
|
|
922
937
|
this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
923
938
|
newStorageData.push({
|
|
924
939
|
...mergedChainInfoMap[storedSlug],
|
|
925
940
|
active: storedChainInfo.active,
|
|
926
|
-
currentProvider: storedChainInfo.currentProvider
|
|
941
|
+
currentProvider: storedChainInfo.currentProvider,
|
|
942
|
+
// TODO: review
|
|
943
|
+
manualTurnOff
|
|
927
944
|
});
|
|
928
945
|
}
|
|
929
946
|
} else {
|
|
@@ -938,13 +955,15 @@ class ChainService {
|
|
|
938
955
|
this.dataMap.chainStateMap[slug] = {
|
|
939
956
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
940
957
|
slug,
|
|
941
|
-
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug)
|
|
958
|
+
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug),
|
|
959
|
+
manualTurnOff: false
|
|
942
960
|
};
|
|
943
961
|
this.updateChainConnectionStatus(slug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
944
962
|
newStorageData.push({
|
|
945
963
|
...mergedChainInfoMap[slug],
|
|
946
964
|
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug),
|
|
947
|
-
currentProvider: Object.keys(chainInfo.providers)[0]
|
|
965
|
+
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
966
|
+
manualTurnOff: false
|
|
948
967
|
});
|
|
949
968
|
}
|
|
950
969
|
});
|
|
@@ -1061,7 +1080,8 @@ class ChainService {
|
|
|
1061
1080
|
this.dbService.updateChainStore({
|
|
1062
1081
|
...targetChainInfo,
|
|
1063
1082
|
active: targetChainState.active,
|
|
1064
|
-
currentProvider: targetChainState.currentProvider
|
|
1083
|
+
currentProvider: targetChainState.currentProvider,
|
|
1084
|
+
manualTurnOff: !targetChainState.active || !!targetChainState.manualTurnOff
|
|
1065
1085
|
}).then(() => {
|
|
1066
1086
|
this.eventService.emit('chain.updateState', chainSlug);
|
|
1067
1087
|
}).catch(e => this.logger.error(e));
|
|
@@ -1125,7 +1145,8 @@ class ChainService {
|
|
|
1125
1145
|
chainStateMap[newChainSlug] = {
|
|
1126
1146
|
active: true,
|
|
1127
1147
|
currentProvider: params.chainEditInfo.currentProvider,
|
|
1128
|
-
slug: newChainSlug
|
|
1148
|
+
slug: newChainSlug,
|
|
1149
|
+
manualTurnOff: false
|
|
1129
1150
|
};
|
|
1130
1151
|
|
|
1131
1152
|
// const chainStatusMap = this.getChainStatusMap();
|
|
@@ -1160,6 +1181,7 @@ class ChainService {
|
|
|
1160
1181
|
this.dbService.updateChainStore({
|
|
1161
1182
|
active: true,
|
|
1162
1183
|
currentProvider: params.chainEditInfo.currentProvider,
|
|
1184
|
+
manualTurnOff: false,
|
|
1163
1185
|
...chainInfo
|
|
1164
1186
|
}).then(() => {
|
|
1165
1187
|
this.eventService.emit('chain.add', newChainSlug);
|
|
@@ -1599,5 +1621,17 @@ class ChainService {
|
|
|
1599
1621
|
});
|
|
1600
1622
|
return result;
|
|
1601
1623
|
}
|
|
1624
|
+
get detectBalanceChainSlugMap() {
|
|
1625
|
+
const result = {};
|
|
1626
|
+
const chainInfoMap = this.getChainInfoMap();
|
|
1627
|
+
for (const [key, chainInfo] of Object.entries(chainInfoMap)) {
|
|
1628
|
+
var _chainInfo$extraInfo;
|
|
1629
|
+
const chainBalanceSlug = ((_chainInfo$extraInfo = chainInfo.extraInfo) === null || _chainInfo$extraInfo === void 0 ? void 0 : _chainInfo$extraInfo.chainBalanceSlug) || '';
|
|
1630
|
+
if (chainBalanceSlug) {
|
|
1631
|
+
result[chainBalanceSlug] = key;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
return result;
|
|
1635
|
+
}
|
|
1602
1636
|
}
|
|
1603
1637
|
exports.ChainService = ChainService;
|
|
@@ -562,10 +562,11 @@ function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
|
|
|
562
562
|
const currentChainStateMap = currentDataMap.chainStateMap;
|
|
563
563
|
const storedChainInfoList = [];
|
|
564
564
|
const needUpdateChainApiList = [];
|
|
565
|
-
|
|
565
|
+
for (const latestChainInfo of latestChainInfoList) {
|
|
566
566
|
const currentChainInfo = currentChainInfoMap[latestChainInfo.slug];
|
|
567
567
|
const currentChainState = currentChainStateMap[latestChainInfo.slug];
|
|
568
568
|
const currentChainProviderValue = currentChainInfo === null || currentChainInfo === void 0 ? void 0 : currentChainInfo.providers[currentChainState === null || currentChainState === void 0 ? void 0 : currentChainState.currentProvider];
|
|
569
|
+
let needUpdate = false;
|
|
569
570
|
if (currentChainInfo && currentChainState) {
|
|
570
571
|
const preservedProvider = {};
|
|
571
572
|
Object.entries(currentChainInfo.providers).forEach(_ref => {
|
|
@@ -587,12 +588,19 @@ function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
|
|
|
587
588
|
currentChainState.currentProvider = providerKey;
|
|
588
589
|
needUpdateChainApiList.push(currentChainInfo);
|
|
589
590
|
}
|
|
591
|
+
needUpdate = true;
|
|
592
|
+
}
|
|
593
|
+
if (currentChainInfo) {
|
|
594
|
+
needUpdate = true;
|
|
595
|
+
currentChainInfo.extraInfo = latestChainInfo.extraInfo;
|
|
596
|
+
}
|
|
597
|
+
if (needUpdate) {
|
|
590
598
|
storedChainInfoList.push({
|
|
591
599
|
...currentChainInfo,
|
|
592
600
|
...currentChainState
|
|
593
601
|
});
|
|
594
602
|
}
|
|
595
|
-
}
|
|
603
|
+
}
|
|
596
604
|
return {
|
|
597
605
|
storedChainInfoList,
|
|
598
606
|
needUpdateChainApiList
|
|
@@ -12,7 +12,7 @@ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
|
12
12
|
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
13
13
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
14
14
|
const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
|
|
15
|
-
const ChainListVersion = '0.2.
|
|
15
|
+
const ChainListVersion = '0.2.54';
|
|
16
16
|
async function fetchPatchData(slug) {
|
|
17
17
|
try {
|
|
18
18
|
const fetchPromise = (0, _crossFetch.default)(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
|
|
@@ -201,7 +201,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
201
201
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
202
202
|
const inputTokenSlug = this.inputAsset;
|
|
203
203
|
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
204
|
-
const inputTokenContract = (0, _web.getERC20Contract)(
|
|
204
|
+
const inputTokenContract = (0, _web.getERC20Contract)((0, _utils._getContractAddressOfToken)(inputTokenInfo), evmApi);
|
|
205
205
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
206
206
|
const allowanceCall = inputTokenContract.methods.allowance(params.address, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo));
|
|
207
207
|
const [allowance, gasPrice] = await Promise.all([
|
|
@@ -266,7 +266,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
266
266
|
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
267
267
|
const derivativeTokenContractAddress = (0, _utils._getContractAddressOfToken)(derivativeTokenInfo);
|
|
268
268
|
const evmApi = this.evmApi;
|
|
269
|
-
const inputTokenContract = (0, _web.getERC20Contract)(
|
|
269
|
+
const inputTokenContract = (0, _web.getERC20Contract)((0, _utils._getContractAddressOfToken)(inputTokenInfo), evmApi);
|
|
270
270
|
|
|
271
271
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
272
272
|
const approveCall = inputTokenContract.methods.approve(derivativeTokenContractAddress, MAX_INT); // TODO: need test
|
|
@@ -156,7 +156,7 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
156
156
|
for (const scheduledRequest of delegationScheduledRequests) {
|
|
157
157
|
if ((0, _utils3.reformatAddress)(scheduledRequest.delegator, 0) === (0, _utils3.reformatAddress)(address, 0)) {
|
|
158
158
|
// add network prefix
|
|
159
|
-
const isClaimable = scheduledRequest.whenExecutable - currentRound
|
|
159
|
+
const isClaimable = scheduledRequest.whenExecutable - currentRound <= 0;
|
|
160
160
|
const remainingEra = scheduledRequest.whenExecutable - currentRound;
|
|
161
161
|
const waitingTime = remainingEra * _constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
162
162
|
const claimable = Object.values(scheduledRequest.action)[0];
|
|
@@ -13,7 +13,7 @@ var _uiKeyring = require("@subwallet/ui-keyring");
|
|
|
13
13
|
class AutoEnableChainsTokens extends _Base.default {
|
|
14
14
|
async run() {
|
|
15
15
|
const accounts = _uiKeyring.keyring.getAccounts();
|
|
16
|
-
await this.state.autoEnableChains(accounts.map(_ref => {
|
|
16
|
+
await this.state.balanceService.autoEnableChains(accounts.map(_ref => {
|
|
17
17
|
let {
|
|
18
18
|
address
|
|
19
19
|
} = _ref;
|
|
@@ -15,6 +15,7 @@ var _NominatorMetadata = _interopRequireDefault(require("@subwallet/extension-ba
|
|
|
15
15
|
var _YieldPoolStore = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/YieldPoolStore"));
|
|
16
16
|
var _YieldPositionStore = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/YieldPositionStore"));
|
|
17
17
|
var _utils = require("@subwallet/extension-base/utils");
|
|
18
|
+
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
18
19
|
var _dexieExportImport = require("dexie-export-import");
|
|
19
20
|
var _util = require("@polkadot/util");
|
|
20
21
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
@@ -71,7 +72,15 @@ class DatabaseService {
|
|
|
71
72
|
|
|
72
73
|
// Balance
|
|
73
74
|
async getStoredBalance() {
|
|
74
|
-
|
|
75
|
+
const addresses = _uiKeyring.default.getPairs().map(_ref => {
|
|
76
|
+
let {
|
|
77
|
+
address
|
|
78
|
+
} = _ref;
|
|
79
|
+
return address;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Filter not exist address
|
|
83
|
+
return this.stores.balance.table.filter(obj => addresses.includes(obj.address)).toArray();
|
|
75
84
|
}
|
|
76
85
|
async updateBalanceStore(item) {
|
|
77
86
|
if (item.state === _KoniTypes.APIItemState.READY) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _defaults = require("@subwallet/extension-base/defaults");
|
|
9
|
+
var _SubscribableStore = _interopRequireDefault(require("@subwallet/extension-base/stores/SubscribableStore"));
|
|
10
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
class DetectAccountBalanceStore extends _SubscribableStore.default {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(_defaults.EXTENSION_PREFIX ? `${_defaults.EXTENSION_PREFIX}DetectBalanceCache` : null);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = DetectAccountBalanceStore;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.filterAssetsByChainAndType = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
const filterAssetsByChainAndType = (chainAssetMap, chain, assetTypes) => {
|
|
11
|
+
const result = {};
|
|
12
|
+
Object.values(chainAssetMap).forEach(assetInfo => {
|
|
13
|
+
if (assetTypes.includes(assetInfo.assetType) && assetInfo.originChain === chain) {
|
|
14
|
+
result[assetInfo.slug] = assetInfo;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
exports.filterAssetsByChainAndType = filterAssetsByChainAndType;
|
package/cjs/utils/index.js
CHANGED
|
@@ -104,6 +104,18 @@ Object.keys(_array).forEach(function (key) {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
|
+
var _asset = require("./asset");
|
|
108
|
+
Object.keys(_asset).forEach(function (key) {
|
|
109
|
+
if (key === "default" || key === "__esModule") return;
|
|
110
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
111
|
+
if (key in exports && exports[key] === _asset[key]) return;
|
|
112
|
+
Object.defineProperty(exports, key, {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function () {
|
|
115
|
+
return _asset[key];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
107
119
|
var _environment = require("./environment");
|
|
108
120
|
Object.keys(_environment).forEach(function (key) {
|
|
109
121
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
|
-
export declare function getEVMBalance(networkKey: string, addresses: string[],
|
|
2
|
+
export declare function getEVMBalance(networkKey: string, addresses: string[], web3Api: _EvmApi): Promise<string[]>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export async function getEVMBalance(networkKey, addresses,
|
|
5
|
-
const web3Api = evmApiMap[networkKey];
|
|
4
|
+
export async function getEVMBalance(networkKey, addresses, web3Api) {
|
|
6
5
|
return await Promise.all(addresses.map(async address => {
|
|
7
6
|
try {
|
|
8
7
|
return await web3Api.api.eth.getBalance(address);
|
|
@@ -11,7 +11,7 @@ interface HandleTransferBalanceResultProps {
|
|
|
11
11
|
updateState?: (promise: Partial<ExternalRequestPromise>) => void;
|
|
12
12
|
}
|
|
13
13
|
export declare const handleTransferBalanceResult: ({ callback, changeValue, networkKey, receipt, response, updateState }: HandleTransferBalanceResultProps) => void;
|
|
14
|
-
export declare function getEVMTransactionObject(chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean,
|
|
15
|
-
export declare function getERC20TransactionObject(assetAddress: string, chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean,
|
|
14
|
+
export declare function getEVMTransactionObject(chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, web3Api: _EvmApi): Promise<[TransactionConfig, string]>;
|
|
15
|
+
export declare function getERC20TransactionObject(assetAddress: string, chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApi: _EvmApi): Promise<[TransactionConfig, string]>;
|
|
16
16
|
export declare function getERC721Transaction(web3Api: _EvmApi, chain: string, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string): Promise<TransactionConfig>;
|
|
17
17
|
export {};
|
|
@@ -34,10 +34,9 @@ export const handleTransferBalanceResult = ({
|
|
|
34
34
|
});
|
|
35
35
|
callback(response);
|
|
36
36
|
};
|
|
37
|
-
export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll,
|
|
37
|
+
export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, web3Api) {
|
|
38
38
|
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
39
39
|
const networkKey = chainInfo.slug;
|
|
40
|
-
const web3Api = evmApiMap[networkKey];
|
|
41
40
|
const priority = await calculateGasFeeParams(web3Api, networkKey);
|
|
42
41
|
const transactionObject = {
|
|
43
42
|
to: to,
|
|
@@ -63,11 +62,10 @@ export async function getEVMTransactionObject(chainInfo, from, to, value, transf
|
|
|
63
62
|
}
|
|
64
63
|
return [transactionObject, transactionObject.value.toString()];
|
|
65
64
|
}
|
|
66
|
-
export async function getERC20TransactionObject(assetAddress, chainInfo, from, to, value, transferAll,
|
|
65
|
+
export async function getERC20TransactionObject(assetAddress, chainInfo, from, to, value, transferAll, evmApi) {
|
|
67
66
|
var _priority$maxFeePerGa2, _priority$maxPriority2;
|
|
68
67
|
const networkKey = chainInfo.slug;
|
|
69
|
-
const
|
|
70
|
-
const erc20Contract = getERC20Contract(networkKey, assetAddress, evmApiMap);
|
|
68
|
+
const erc20Contract = getERC20Contract(assetAddress, evmApi);
|
|
71
69
|
let freeAmount = new BigN(0);
|
|
72
70
|
let transferValue = value;
|
|
73
71
|
if (transferAll) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
2
|
import { Contract } from 'web3-eth-contract';
|
|
3
|
-
export declare const getERC20Contract: (
|
|
3
|
+
export declare const getERC20Contract: (assetAddress: string, evmApi: _EvmApi, options?: {}) => Contract;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { _ERC20_ABI } from '@subwallet/extension-base/services/chain-service/helper';
|
|
5
|
-
export const getERC20Contract = (
|
|
5
|
+
export const getERC20Contract = (assetAddress, evmApi, options = {}) => {
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
8
|
-
return new
|
|
8
|
+
return new evmApi.api.eth.Contract(_ERC20_ABI, assetAddress, options);
|
|
9
9
|
};
|
|
@@ -1036,11 +1036,11 @@ export default class KoniExtension {
|
|
|
1036
1036
|
return this.getPrice();
|
|
1037
1037
|
}
|
|
1038
1038
|
async getBalance(reset) {
|
|
1039
|
-
return this.#koniState.getBalance(reset);
|
|
1039
|
+
return this.#koniState.balanceService.getBalance(reset);
|
|
1040
1040
|
}
|
|
1041
1041
|
async subscribeBalance(id, port) {
|
|
1042
1042
|
const cb = createSubscription(id, port);
|
|
1043
|
-
const balanceSubscription = this.#koniState.
|
|
1043
|
+
const balanceSubscription = this.#koniState.balanceService.subscribeBalanceMap().subscribe({
|
|
1044
1044
|
next: rs => {
|
|
1045
1045
|
const data = {
|
|
1046
1046
|
details: rs
|
|
@@ -1565,12 +1565,13 @@ export default class KoniExtension {
|
|
|
1565
1565
|
// TODO: review this
|
|
1566
1566
|
chainType = ChainType.EVM;
|
|
1567
1567
|
const txVal = transferAll ? freeBalance.value : value || '0';
|
|
1568
|
+
const evmApi = evmApiMap[networkKey];
|
|
1568
1569
|
|
|
1569
1570
|
// Estimate with EVM API
|
|
1570
1571
|
if (_isTokenEvmSmartContract(tokenInfo) || _isLocalToken(tokenInfo)) {
|
|
1571
|
-
[transaction, transferAmount.value] = await getERC20TransactionObject(_getContractAddressOfToken(tokenInfo), chainInfo, from, to, txVal, !!transferAll,
|
|
1572
|
+
[transaction, transferAmount.value] = await getERC20TransactionObject(_getContractAddressOfToken(tokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApi);
|
|
1572
1573
|
} else {
|
|
1573
|
-
[transaction, transferAmount.value] = await getEVMTransactionObject(chainInfo, from, to, txVal, !!transferAll,
|
|
1574
|
+
[transaction, transferAmount.value] = await getEVMTransactionObject(chainInfo, from, to, txVal, !!transferAll, evmApi);
|
|
1574
1575
|
}
|
|
1575
1576
|
} else if (_isMantaZkAsset(tokenInfo)) {
|
|
1576
1577
|
// TODO
|
|
@@ -23,7 +23,7 @@ import DatabaseService from '@subwallet/extension-base/services/storage-service/
|
|
|
23
23
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
24
24
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
25
25
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
26
|
-
import {
|
|
26
|
+
import { BalanceMap, EvmFeeInfo } from '@subwallet/extension-base/types';
|
|
27
27
|
import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
|
|
28
28
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
29
29
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
@@ -38,7 +38,6 @@ export default class KoniState {
|
|
|
38
38
|
private readonly unsubscriptionMap;
|
|
39
39
|
private readonly accountRefStore;
|
|
40
40
|
private externalRequest;
|
|
41
|
-
private balanceMap;
|
|
42
41
|
private crowdloanMap;
|
|
43
42
|
private crowdloanSubject;
|
|
44
43
|
private nftSubject;
|
|
@@ -155,18 +154,8 @@ export default class KoniState {
|
|
|
155
154
|
getAccountAddress(): string | null;
|
|
156
155
|
getDecodedAddresses(address?: string): string[];
|
|
157
156
|
getAllAddresses(): string[];
|
|
158
|
-
removeInactiveChainBalances(): Promise<void>;
|
|
159
|
-
getBalance(reset?: boolean): Promise<BalanceJson>;
|
|
160
|
-
getStoredBalance(address: string): Promise<BalanceItem[]>;
|
|
161
|
-
private isFirstLoad;
|
|
162
|
-
handleResetBalance(newAddress: string, forceRefresh?: boolean): Promise<void>;
|
|
163
157
|
resetCrowdloanMap(newAddress: string): Promise<void>;
|
|
164
158
|
resetStaking(newAddress: string): void;
|
|
165
|
-
private balanceUpdateCache;
|
|
166
|
-
/** Note: items must be same tokenSlug */
|
|
167
|
-
setBalanceItem(items: BalanceItem[]): void;
|
|
168
|
-
private updateBalanceStore;
|
|
169
|
-
subscribeBalance(): BehaviorSubject<BalanceMap>;
|
|
170
159
|
getCrowdloan(reset?: boolean): CrowdloanJson;
|
|
171
160
|
getStoredCrowdloan(address: string): Promise<Record<string, import("../../../services/storage-service/databases").ICrowdloanItem>>;
|
|
172
161
|
setCrowdloanItem(networkKey: string, item: CrowdloanItem): void;
|
|
@@ -237,7 +226,7 @@ export default class KoniState {
|
|
|
237
226
|
wakeup(): Promise<void>;
|
|
238
227
|
cancelSubscription(id: string): boolean;
|
|
239
228
|
createUnsubscriptionHandle(id: string, unsubscribe: () => void): void;
|
|
240
|
-
|
|
229
|
+
get detectBalanceChainSlugMap(): Record<string, string>;
|
|
241
230
|
onAccountAdd(): void;
|
|
242
231
|
onAccountRemove(): void;
|
|
243
232
|
reloadNft(): Promise<boolean>;
|