@subwallet/extension-base 1.1.38-1 → 1.1.39-beta.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/background/types.d.ts +1 -0
- package/cjs/koni/api/dotsama/balance.js +464 -0
- package/cjs/koni/api/nft/unique_network_nft/index.js +4 -0
- package/cjs/koni/background/handlers/Extension.js +64 -13
- package/cjs/koni/background/handlers/State.js +6 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/balance.js +1 -1
- package/cjs/services/chain-service/health-check/constants/index.js +36 -0
- package/cjs/services/chain-service/health-check/utils/asset-info.js +282 -0
- package/cjs/services/chain-service/health-check/utils/chain-info.js +36 -0
- package/cjs/services/chain-service/health-check/utils/index.js +38 -0
- package/cjs/services/chain-service/health-check/utils/provider.js +186 -0
- package/cjs/services/chain-service/index.js +61 -51
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +42 -26
- package/cjs/services/earning-service/service.js +9 -2
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
- package/cjs/services/storage-service/index.js +241 -0
- package/cjs/services/transaction-service/index.js +6 -4
- package/cjs/types.js +1 -0
- package/cjs/utils/address.js +34 -0
- package/cjs/utils/eth/mergeTransactionAndSignature.js +8 -3
- package/cjs/utils/index.js +6 -5
- package/cjs/utils/keyring.js +57 -0
- package/cjs/utils/staticData/index.js +5 -5
- package/koni/api/nft/unique_network_nft/index.d.ts +1 -0
- package/koni/api/nft/unique_network_nft/index.js +5 -1
- package/koni/api/staking/bonding/utils.d.ts +0 -1
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +64 -13
- package/koni/background/handlers/State.js +2 -1
- package/package.json +42 -17
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/balance.js +1 -1
- package/services/chain-service/health-check/constants/index.d.ts +4 -0
- package/services/chain-service/health-check/constants/index.js +26 -0
- package/services/chain-service/health-check/utils/asset-info.d.ts +14 -0
- package/services/chain-service/health-check/utils/asset-info.js +269 -0
- package/services/chain-service/health-check/utils/chain-info.d.ts +8 -0
- package/services/chain-service/health-check/utils/chain-info.js +28 -0
- package/services/chain-service/health-check/utils/index.d.ts +3 -0
- package/services/chain-service/health-check/utils/index.js +6 -0
- package/services/chain-service/health-check/utils/provider.d.ts +25 -0
- package/services/chain-service/health-check/utils/provider.js +172 -0
- package/services/chain-service/index.d.ts +7 -3
- package/services/chain-service/index.js +52 -43
- package/services/chain-service/types.d.ts +4 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +0 -1
- package/services/earning-service/handlers/native-staking/relay-chain.js +42 -26
- package/services/earning-service/handlers/special.d.ts +0 -1
- package/services/earning-service/service.js +10 -3
- package/services/transaction-service/index.js +6 -4
- package/types/balance.d.ts +0 -1
- package/types/yield/info/pallet.d.ts +4 -1
- package/utils/eth/mergeTransactionAndSignature.js +8 -3
- package/utils/index.d.ts +1 -2
- package/utils/index.js +6 -5
- package/utils/staticData/buyServiceInfos.json +0 -1
- package/utils/staticData/buyTokenConfigs.json +0 -15
- package/utils/staticData/chains.json +192 -89
- package/utils/staticData/crowdloanFunds.json +433 -58
- package/utils/staticData/index.d.ts +1 -2
- package/utils/staticData/index.js +4 -3
- package/utils/staticData/marketingCampaigns.json +1 -298
- package/utils/staticData/termAndCondition.json +1 -1
|
@@ -31,6 +31,7 @@ export class ChainService {
|
|
|
31
31
|
// TODO: consider BehaviorSubject
|
|
32
32
|
chainInfoMapSubject = new Subject();
|
|
33
33
|
chainStateMapSubject = new Subject();
|
|
34
|
+
chainStatusMapSubject = new BehaviorSubject({});
|
|
34
35
|
assetRegistrySubject = new Subject();
|
|
35
36
|
multiChainAssetMapSubject = new Subject();
|
|
36
37
|
xcmRefMapSubject = new Subject();
|
|
@@ -104,6 +105,9 @@ export class ChainService {
|
|
|
104
105
|
subscribeChainStateMap() {
|
|
105
106
|
return this.chainStateMapSubject;
|
|
106
107
|
}
|
|
108
|
+
subscribeChainStatusMap() {
|
|
109
|
+
return this.chainStatusMapSubject;
|
|
110
|
+
}
|
|
107
111
|
getAssetRegistry() {
|
|
108
112
|
return this.dataMap.assetRegistry;
|
|
109
113
|
}
|
|
@@ -181,6 +185,12 @@ export class ChainService {
|
|
|
181
185
|
getChainStateByKey(key) {
|
|
182
186
|
return this.dataMap.chainStateMap[key];
|
|
183
187
|
}
|
|
188
|
+
getChainStatusMap() {
|
|
189
|
+
return this.chainStatusMapSubject.getValue();
|
|
190
|
+
}
|
|
191
|
+
getChainStatusByKey(key) {
|
|
192
|
+
return this.getChainStatusMap()[key];
|
|
193
|
+
}
|
|
184
194
|
getActiveChains() {
|
|
185
195
|
return Object.entries(this.dataMap.chainStateMap).filter(([, chainState]) => _isChainEnabled(chainState)).map(([key]) => key);
|
|
186
196
|
}
|
|
@@ -339,9 +349,31 @@ export class ChainService {
|
|
|
339
349
|
this.lockChainInfoMap = false;
|
|
340
350
|
return true;
|
|
341
351
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
352
|
+
connectionStatusQueueMap = {};
|
|
353
|
+
updateChainConnectionStatus(slug, connectionStatus) {
|
|
354
|
+
this.connectionStatusQueueMap[slug] = connectionStatus;
|
|
355
|
+
addLazy('updateChainConnectionStatus', () => {
|
|
356
|
+
const chainStatusMap = this.getChainStatusMap();
|
|
357
|
+
let update = false;
|
|
358
|
+
Object.entries(this.connectionStatusQueueMap).forEach(([slug, status]) => {
|
|
359
|
+
if (chainStatusMap[slug]) {
|
|
360
|
+
if (chainStatusMap[slug].connectionStatus !== status) {
|
|
361
|
+
chainStatusMap[slug].connectionStatus = status;
|
|
362
|
+
chainStatusMap[slug].lastUpdated = Date.now();
|
|
363
|
+
update = true;
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
chainStatusMap[slug] = {
|
|
367
|
+
slug,
|
|
368
|
+
connectionStatus: status,
|
|
369
|
+
lastUpdated: Date.now()
|
|
370
|
+
};
|
|
371
|
+
update = true;
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
this.connectionStatusQueueMap = {};
|
|
375
|
+
update && this.chainStatusMapSubject.next(chainStatusMap);
|
|
376
|
+
});
|
|
345
377
|
}
|
|
346
378
|
upsertCustomToken(token) {
|
|
347
379
|
if (token.slug.length === 0) {
|
|
@@ -513,13 +545,8 @@ export class ChainService {
|
|
|
513
545
|
providerName
|
|
514
546
|
} = this.getChainCurrentProviderByKey(chainInfo.slug);
|
|
515
547
|
const onUpdateStatus = status => {
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
// Avoid unnecessary update in case disable chain
|
|
519
|
-
if (currentStatus !== status) {
|
|
520
|
-
this.setChainConnectionStatus(chainInfo.slug, status);
|
|
521
|
-
this.updateChainStateMapSubscription();
|
|
522
|
-
}
|
|
548
|
+
const slug = chainInfo.slug;
|
|
549
|
+
this.updateChainConnectionStatus(slug, status);
|
|
523
550
|
};
|
|
524
551
|
if (chainInfo.substrateInfo !== null && chainInfo.substrateInfo !== undefined) {
|
|
525
552
|
if (_MANTA_ZK_CHAIN_GROUP.includes(chainInfo.slug) && MODULE_SUPPORT.MANTA_ZK && this.mantaChainHandler) {
|
|
@@ -618,7 +645,7 @@ export class ChainService {
|
|
|
618
645
|
this.lockChainInfoMap = true;
|
|
619
646
|
chainStateMap[chainSlug].active = false;
|
|
620
647
|
// Set disconnect state for inactive chain
|
|
621
|
-
|
|
648
|
+
this.updateChainConnectionStatus(chainSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
622
649
|
this.destroyApiForChain(chainInfo);
|
|
623
650
|
this.dbService.updateChainStore({
|
|
624
651
|
...chainInfo,
|
|
@@ -711,9 +738,9 @@ export class ChainService {
|
|
|
711
738
|
this.dataMap.chainStateMap[chainInfo.slug] = {
|
|
712
739
|
currentProvider: providerKey,
|
|
713
740
|
slug: chainInfo.slug,
|
|
714
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
715
741
|
active: _DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
|
|
716
742
|
};
|
|
743
|
+
this.updateChainConnectionStatus(chainInfo.slug, _ChainConnectionStatus.DISCONNECTED);
|
|
717
744
|
|
|
718
745
|
// create data for storage
|
|
719
746
|
newStorageData.push({
|
|
@@ -764,9 +791,9 @@ export class ChainService {
|
|
|
764
791
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
765
792
|
currentProvider: selectedProvider,
|
|
766
793
|
slug: storedSlug,
|
|
767
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
768
794
|
active: canActive && storedChainInfo.active
|
|
769
795
|
};
|
|
796
|
+
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
770
797
|
newStorageData.push({
|
|
771
798
|
...mergedChainInfoMap[storedSlug],
|
|
772
799
|
active: canActive && storedChainInfo.active,
|
|
@@ -786,9 +813,9 @@ export class ChainService {
|
|
|
786
813
|
this.dataMap.chainStateMap[duplicatedDefaultSlug] = {
|
|
787
814
|
currentProvider: storedChainInfo.currentProvider,
|
|
788
815
|
slug: duplicatedDefaultSlug,
|
|
789
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
790
816
|
active: storedChainInfo.active
|
|
791
817
|
};
|
|
818
|
+
this.updateChainConnectionStatus(duplicatedDefaultSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
792
819
|
newStorageData.push({
|
|
793
820
|
...mergedChainInfoMap[duplicatedDefaultSlug],
|
|
794
821
|
active: storedChainInfo.active,
|
|
@@ -813,9 +840,9 @@ export class ChainService {
|
|
|
813
840
|
currentProvider: storedChainInfo.currentProvider,
|
|
814
841
|
// TODO: review
|
|
815
842
|
slug: storedSlug,
|
|
816
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
817
843
|
active: storedChainInfo.active
|
|
818
844
|
};
|
|
845
|
+
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
819
846
|
newStorageData.push({
|
|
820
847
|
...mergedChainInfoMap[storedSlug],
|
|
821
848
|
active: storedChainInfo.active,
|
|
@@ -833,9 +860,9 @@ export class ChainService {
|
|
|
833
860
|
this.dataMap.chainStateMap[slug] = {
|
|
834
861
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
835
862
|
slug,
|
|
836
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
837
863
|
active: _DEFAULT_ACTIVE_CHAINS.includes(slug)
|
|
838
864
|
};
|
|
865
|
+
this.updateChainConnectionStatus(slug, _ChainConnectionStatus.DISCONNECTED);
|
|
839
866
|
newStorageData.push({
|
|
840
867
|
...mergedChainInfoMap[slug],
|
|
841
868
|
active: _DEFAULT_ACTIVE_CHAINS.includes(slug),
|
|
@@ -910,9 +937,7 @@ export class ChainService {
|
|
|
910
937
|
}
|
|
911
938
|
}
|
|
912
939
|
updateChainStateMapSubscription() {
|
|
913
|
-
|
|
914
|
-
this.chainStateMapSubject.next(this.getChainStateMap());
|
|
915
|
-
}, 300, 900);
|
|
940
|
+
this.chainStateMapSubject.next(this.getChainStateMap());
|
|
916
941
|
}
|
|
917
942
|
updateChainInfoMapSubscription() {
|
|
918
943
|
this.chainInfoMapSubject.next(this.getChainInfoMap());
|
|
@@ -1021,10 +1046,17 @@ export class ChainService {
|
|
|
1021
1046
|
const chainStateMap = this.getChainStateMap();
|
|
1022
1047
|
chainStateMap[newChainSlug] = {
|
|
1023
1048
|
active: true,
|
|
1024
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
1025
1049
|
currentProvider: params.chainEditInfo.currentProvider,
|
|
1026
1050
|
slug: newChainSlug
|
|
1027
1051
|
};
|
|
1052
|
+
|
|
1053
|
+
// const chainStatusMap = this.getChainStatusMap();
|
|
1054
|
+
// const chainStatusMap[newChainSlug] = {
|
|
1055
|
+
// slug: newChainSlug,
|
|
1056
|
+
// connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
1057
|
+
// lastUpdated: Date.now()
|
|
1058
|
+
// };
|
|
1059
|
+
|
|
1028
1060
|
await this.initApiForChain(chainInfo);
|
|
1029
1061
|
|
|
1030
1062
|
// create a record in assetRegistry for native token and update store/subscription
|
|
@@ -1309,29 +1341,6 @@ export class ChainService {
|
|
|
1309
1341
|
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp()]);
|
|
1310
1342
|
this.checkLatestData();
|
|
1311
1343
|
}
|
|
1312
|
-
checkAndUpdateStatusMapForChain(chainSlug) {
|
|
1313
|
-
const substrateApiMap = this.getSubstrateApiMap();
|
|
1314
|
-
const evmApiMap = this.getEvmApiMap();
|
|
1315
|
-
const chainState = this.getChainStateByKey(chainSlug);
|
|
1316
|
-
let update = false;
|
|
1317
|
-
function updateState(current, status) {
|
|
1318
|
-
if (current.connectionStatus !== status) {
|
|
1319
|
-
current.connectionStatus = status;
|
|
1320
|
-
update = true;
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
if (chainState.active) {
|
|
1324
|
-
const api = substrateApiMap[chainSlug] || evmApiMap[chainSlug];
|
|
1325
|
-
if (api) {
|
|
1326
|
-
updateState(chainState, api.isApiConnected ? _ChainConnectionStatus.CONNECTED : _ChainConnectionStatus.DISCONNECTED);
|
|
1327
|
-
}
|
|
1328
|
-
} else {
|
|
1329
|
-
updateState(chainState, _ChainConnectionStatus.DISCONNECTED);
|
|
1330
|
-
}
|
|
1331
|
-
if (update) {
|
|
1332
|
-
this.dataMap.chainStateMap[chainSlug] = chainState;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
1344
|
async initAssetSettings() {
|
|
1336
1345
|
const assetSettings = await this.getAssetSettings();
|
|
1337
1346
|
const activeChainSlugs = this.getActiveChainSlugs();
|
|
@@ -22,7 +22,11 @@ export interface _ChainState {
|
|
|
22
22
|
slug: string;
|
|
23
23
|
active: boolean;
|
|
24
24
|
currentProvider: string;
|
|
25
|
+
}
|
|
26
|
+
export interface _ChainApiStatus {
|
|
27
|
+
slug: string;
|
|
25
28
|
connectionStatus: _ChainConnectionStatus;
|
|
29
|
+
lastUpdated: number;
|
|
26
30
|
}
|
|
27
31
|
export interface _SubstrateDefaultFormatBalance {
|
|
28
32
|
decimals?: number[] | number;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
3
2
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
4
3
|
import { ExtrinsicType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
@@ -280,7 +280,21 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
280
280
|
const currentEra = _era.toString();
|
|
281
281
|
const allValidators = [];
|
|
282
282
|
const validatorInfoList = [];
|
|
283
|
-
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), chainApi.api.query.staking.minNominatorBond(), ((_chainApi$api$query$s = chainApi.api.query.stakingRewards) === null || _chainApi$api$query$s === void 0 ? void 0 : _chainApi$api$query$s.data) && chainApi.api.query.stakingRewards.data()]);
|
|
283
|
+
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards, _validators] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), chainApi.api.query.staking.minNominatorBond(), ((_chainApi$api$query$s = chainApi.api.query.stakingRewards) === null || _chainApi$api$query$s === void 0 ? void 0 : _chainApi$api$query$s.data) && chainApi.api.query.stakingRewards.data(), chainApi.api.query.staking.validators.entries()]);
|
|
284
|
+
|
|
285
|
+
// filter blocked validators
|
|
286
|
+
const validators = _validators;
|
|
287
|
+
const blockValidatorList = [];
|
|
288
|
+
for (const validator of validators) {
|
|
289
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
290
|
+
const validatorAddress = validator[0].toHuman()[0];
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
292
|
+
const validatorPrefs = validator[1].toHuman();
|
|
293
|
+
const isBlocked = validatorPrefs.blocked;
|
|
294
|
+
if (isBlocked) {
|
|
295
|
+
blockValidatorList.push(validatorAddress);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
284
298
|
const stakingRewards = _stakingRewards === null || _stakingRewards === void 0 ? void 0 : _stakingRewards.toPrimitive();
|
|
285
299
|
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
286
300
|
const maxNominatorRewarded = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
@@ -296,32 +310,34 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
296
310
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
297
311
|
const rawValidatorStat = item[1].toHuman();
|
|
298
312
|
const validatorAddress = rawValidatorInfo[1];
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
313
|
+
if (!blockValidatorList.includes(validatorAddress)) {
|
|
314
|
+
const rawTotalStake = rawValidatorStat.total;
|
|
315
|
+
const rawOwnStake = rawValidatorStat.own;
|
|
316
|
+
const bnTotalStake = new BN(rawTotalStake.replaceAll(',', ''));
|
|
317
|
+
const bnOwnStake = new BN(rawOwnStake.replaceAll(',', ''));
|
|
318
|
+
const otherStake = bnTotalStake.sub(bnOwnStake);
|
|
319
|
+
totalStakeMap[validatorAddress] = bnTotalStake;
|
|
320
|
+
let nominatorCount = 0;
|
|
321
|
+
if ('others' in rawValidatorStat) {
|
|
322
|
+
const others = rawValidatorStat.others;
|
|
323
|
+
nominatorCount = others.length;
|
|
324
|
+
}
|
|
325
|
+
allValidators.push(validatorAddress);
|
|
326
|
+
validatorInfoList.push({
|
|
327
|
+
address: validatorAddress,
|
|
328
|
+
totalStake: bnTotalStake.toString(),
|
|
329
|
+
ownStake: bnOwnStake.toString(),
|
|
330
|
+
otherStake: otherStake.toString(),
|
|
331
|
+
nominatorCount,
|
|
332
|
+
// to be added later
|
|
333
|
+
commission: 0,
|
|
334
|
+
expectedReturn: 0,
|
|
335
|
+
blocked: false,
|
|
336
|
+
isVerified: false,
|
|
337
|
+
minBond,
|
|
338
|
+
isCrowded: unlimitedNominatorRewarded ? false : nominatorCount > parseInt(maxNominatorRewarded)
|
|
339
|
+
});
|
|
309
340
|
}
|
|
310
|
-
allValidators.push(validatorAddress);
|
|
311
|
-
validatorInfoList.push({
|
|
312
|
-
address: validatorAddress,
|
|
313
|
-
totalStake: bnTotalStake.toString(),
|
|
314
|
-
ownStake: bnOwnStake.toString(),
|
|
315
|
-
otherStake: otherStake.toString(),
|
|
316
|
-
nominatorCount,
|
|
317
|
-
// to be added later
|
|
318
|
-
commission: 0,
|
|
319
|
-
expectedReturn: 0,
|
|
320
|
-
blocked: false,
|
|
321
|
-
isVerified: false,
|
|
322
|
-
minBond,
|
|
323
|
-
isCrowded: unlimitedNominatorRewarded ? false : nominatorCount > parseInt(maxNominatorRewarded)
|
|
324
|
-
});
|
|
325
341
|
}
|
|
326
342
|
const extraInfoMap = {};
|
|
327
343
|
await Promise.all(allValidators.map(async address => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
2
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
3
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
@@ -5,7 +5,7 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
5
5
|
import { BasicTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
8
|
-
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
+
import { _isChainEnabled, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
10
10
|
import BaseLiquidStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/liquid-staking/base';
|
|
11
11
|
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
@@ -127,13 +127,20 @@ export default class EarningService {
|
|
|
127
127
|
this.eventService.onLazy((events, eventTypes) => {
|
|
128
128
|
(async () => {
|
|
129
129
|
const removedAddresses = [];
|
|
130
|
+
const removeChains = [];
|
|
130
131
|
events.forEach(event => {
|
|
131
132
|
if (event.type === 'account.remove') {
|
|
132
133
|
removedAddresses.push(event.data[0]);
|
|
133
134
|
}
|
|
135
|
+
if (event.type === 'chain.updateState') {
|
|
136
|
+
const chainState = this.state.getChainStateByKey(event.data[0]);
|
|
137
|
+
if (chainState && !_isChainEnabled(chainState)) {
|
|
138
|
+
removeChains.push(event.data[0]);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
134
141
|
});
|
|
135
|
-
if (
|
|
136
|
-
await this.removeYieldPositions(
|
|
142
|
+
if (removeChains.length || removedAddresses.length) {
|
|
143
|
+
await this.removeYieldPositions(removeChains, removedAddresses);
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
// Account changed or chain changed (active or inactive)
|
|
@@ -339,13 +339,14 @@ export default class TransactionService {
|
|
|
339
339
|
transactionToHistories(id, startBlock, nonce, eventLogs) {
|
|
340
340
|
const transaction = this.getTransaction(id);
|
|
341
341
|
const extrinsicType = transaction.extrinsicType;
|
|
342
|
+
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
342
343
|
const formattedTransactionAddress = reformatAddress(transaction.address);
|
|
343
344
|
const historyItem = {
|
|
344
345
|
origin: 'app',
|
|
345
346
|
chain: transaction.chain,
|
|
346
347
|
direction: TransactionDirection.SEND,
|
|
347
348
|
type: transaction.extrinsicType,
|
|
348
|
-
from:
|
|
349
|
+
from: transaction.address,
|
|
349
350
|
to: '',
|
|
350
351
|
chainType: transaction.chainType,
|
|
351
352
|
address: formattedTransactionAddress,
|
|
@@ -361,7 +362,6 @@ export default class TransactionService {
|
|
|
361
362
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
362
363
|
startBlock: startBlock || 0
|
|
363
364
|
};
|
|
364
|
-
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
365
365
|
const nativeAsset = _getChainNativeTokenBasicInfo(chainInfo);
|
|
366
366
|
const baseNativeAmount = {
|
|
367
367
|
value: '0',
|
|
@@ -861,7 +861,8 @@ export default class TransactionService {
|
|
|
861
861
|
to: transaction.to !== undefined ? transaction.to : '',
|
|
862
862
|
value: addHexPrefix(anyNumberToBN(transaction.value).toString(16)),
|
|
863
863
|
data: transaction.data,
|
|
864
|
-
chainId: _getEvmChainId(chainInfo)
|
|
864
|
+
chainId: _getEvmChainId(chainInfo),
|
|
865
|
+
type: 2
|
|
865
866
|
};
|
|
866
867
|
} else {
|
|
867
868
|
var _transaction$nonce2;
|
|
@@ -872,7 +873,8 @@ export default class TransactionService {
|
|
|
872
873
|
to: transaction.to !== undefined ? transaction.to : '',
|
|
873
874
|
value: addHexPrefix(anyNumberToBN(transaction.value).toString(16)),
|
|
874
875
|
data: transaction.data,
|
|
875
|
-
chainId: _getEvmChainId(chainInfo)
|
|
876
|
+
chainId: _getEvmChainId(chainInfo),
|
|
877
|
+
type: 0
|
|
876
878
|
};
|
|
877
879
|
}
|
|
878
880
|
return ethers.Transaction.from(txObject).unsignedSerialized;
|
package/types/balance.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { BN } from '@polkadot/util';
|
|
3
2
|
export interface PalletNominationPoolsPoolMember {
|
|
4
3
|
poolId: number;
|
|
@@ -122,6 +121,10 @@ export interface PalletStakingNominations {
|
|
|
122
121
|
submittedIn: number;
|
|
123
122
|
suppressed: boolean;
|
|
124
123
|
}
|
|
124
|
+
export interface PalletStakingValidatorPrefs {
|
|
125
|
+
commission: string;
|
|
126
|
+
blocked: boolean;
|
|
127
|
+
}
|
|
125
128
|
export interface UnlockingChunk {
|
|
126
129
|
value: number;
|
|
127
130
|
era: number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { BN_ZERO } from '@subwallet/extension-base/utils';
|
|
5
|
+
import { anyNumberToBN } from '@subwallet/extension-base/utils/eth';
|
|
4
6
|
import { addHexPrefix } from 'ethereumjs-util';
|
|
5
7
|
import { ethers } from 'ethers';
|
|
6
8
|
export const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
@@ -11,7 +13,8 @@ export const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
|
11
13
|
v: parseInt(`0x${_signature.substring(128)}`)
|
|
12
14
|
};
|
|
13
15
|
let transaction;
|
|
14
|
-
|
|
16
|
+
const max = anyNumberToBN(tx.maxFeePerGas);
|
|
17
|
+
if (max.gt(BN_ZERO)) {
|
|
15
18
|
transaction = {
|
|
16
19
|
nonce: tx.nonce,
|
|
17
20
|
maxFeePerGas: addHexPrefix(tx.maxFeePerGas.toString(16)),
|
|
@@ -21,7 +24,8 @@ export const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
|
21
24
|
value: addHexPrefix(tx.value.toString(16)),
|
|
22
25
|
data: tx.data,
|
|
23
26
|
chainId: tx.chainId,
|
|
24
|
-
signature: signature
|
|
27
|
+
signature: signature,
|
|
28
|
+
type: 2
|
|
25
29
|
};
|
|
26
30
|
} else {
|
|
27
31
|
transaction = {
|
|
@@ -32,7 +36,8 @@ export const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
|
32
36
|
value: addHexPrefix(tx.value.toString(16)),
|
|
33
37
|
data: tx.data,
|
|
34
38
|
chainId: tx.chainId,
|
|
35
|
-
signature: signature
|
|
39
|
+
signature: signature,
|
|
40
|
+
type: 0
|
|
36
41
|
};
|
|
37
42
|
}
|
|
38
43
|
return ethers.Transaction.from(transaction).serialized;
|
package/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { CrowdloanParaState, NetworkJson } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
2
|
import { AccountAuthType, AccountJson } from '@subwallet/extension-base/background/types';
|
|
4
3
|
import { BN } from '@polkadot/util';
|
|
@@ -38,7 +37,7 @@ export declare function isSameAddress(address1: string, address2: string): boole
|
|
|
38
37
|
export declare function getDomainFromUrl(url: string): string;
|
|
39
38
|
export declare function waitTimeout(ms: number): Promise<void>;
|
|
40
39
|
export declare const stripUrl: (url: string) => string;
|
|
41
|
-
export declare const baseParseIPFSUrl: (input: string) => string | undefined;
|
|
40
|
+
export declare const baseParseIPFSUrl: (input: string, customDomain?: string) => string | undefined;
|
|
42
41
|
export declare const swParseIPFSUrl: (input: string) => string | undefined;
|
|
43
42
|
export declare function wait(milliseconds: number): Promise<void>;
|
|
44
43
|
export * from './account';
|
package/utils/index.js
CHANGED
|
@@ -286,7 +286,8 @@ export const stripUrl = url => {
|
|
|
286
286
|
const parts = url.split('/');
|
|
287
287
|
return parts[2];
|
|
288
288
|
};
|
|
289
|
-
export const baseParseIPFSUrl = input => {
|
|
289
|
+
export const baseParseIPFSUrl = (input, customDomain) => {
|
|
290
|
+
const selectedDomain = customDomain || getRandomIpfsGateway();
|
|
290
291
|
if (!input || input.length === 0) {
|
|
291
292
|
return undefined;
|
|
292
293
|
}
|
|
@@ -297,17 +298,17 @@ export const baseParseIPFSUrl = input => {
|
|
|
297
298
|
return input;
|
|
298
299
|
}
|
|
299
300
|
if (input.startsWith('/ipfs/')) {
|
|
300
|
-
return
|
|
301
|
+
return selectedDomain + input.split('/ipfs/')[1];
|
|
301
302
|
}
|
|
302
303
|
if (!input.includes('ipfs://') && !input.includes('ipfs://ipfs/')) {
|
|
303
304
|
// just the IPFS hash
|
|
304
|
-
return
|
|
305
|
+
return selectedDomain + input;
|
|
305
306
|
}
|
|
306
307
|
if (input.includes('ipfs://') && !input.includes('ipfs://ipfs/')) {
|
|
307
308
|
// starts with ipfs://
|
|
308
|
-
return
|
|
309
|
+
return selectedDomain + input.split('ipfs://')[1];
|
|
309
310
|
}
|
|
310
|
-
return
|
|
311
|
+
return selectedDomain + input.split('ipfs://ipfs/')[1]; // starts with ipfs://ipfs/
|
|
311
312
|
};
|
|
312
313
|
|
|
313
314
|
export const swParseIPFSUrl = input => {
|
|
@@ -679,20 +679,5 @@
|
|
|
679
679
|
"slug": "arbitrum_one-ERC20-USDC-0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
680
680
|
"symbol": "USDC",
|
|
681
681
|
"support": "ETHEREUM"
|
|
682
|
-
},
|
|
683
|
-
{
|
|
684
|
-
"serviceInfo": {
|
|
685
|
-
"transak": {
|
|
686
|
-
"network": "polygon",
|
|
687
|
-
"symbol": "USDC",
|
|
688
|
-
"isSuspended": false
|
|
689
|
-
}
|
|
690
|
-
},
|
|
691
|
-
"network": "polygon",
|
|
692
|
-
"slug": "polygon-ERC20-USDC-0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
693
|
-
"symbol": "USDC",
|
|
694
|
-
"support": "ETHEREUM"
|
|
695
682
|
}
|
|
696
683
|
]
|
|
697
|
-
|
|
698
|
-
|