@subwallet/extension-base 1.1.6-0 → 1.1.6-2
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/api/nft/config.js +1 -1
- package/cjs/koni/api/staking/bonding/amplitude.js +18 -17
- package/cjs/koni/api/staking/bonding/paraChain.js +11 -17
- package/cjs/koni/background/handlers/Extension.js +16 -3
- package/cjs/koni/background/handlers/Tabs.js +1 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/SubWalleEvmProvider.js +18 -7
- package/cjs/services/chain-service/constants.js +5 -3
- package/cjs/services/chain-service/handler/AbstractChainHandler.js +25 -11
- package/cjs/services/chain-service/handler/EvmApi.js +15 -5
- package/cjs/services/chain-service/handler/EvmChainHandler.js +2 -2
- package/cjs/services/chain-service/handler/SubstrateApi.js +36 -17
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +5 -5
- package/cjs/services/chain-service/index.js +12 -6
- package/cjs/services/migration-service/scripts/MigrateWalletReference.js +31 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/setting-service/constants.js +2 -1
- package/cjs/services/storage-service/db-stores/Nft.js +2 -2
- package/cjs/services/storage-service/db-stores/Staking.js +2 -2
- package/koni/api/nft/config.d.ts +1 -1
- package/koni/api/nft/config.js +1 -1
- package/koni/api/staking/bonding/amplitude.js +18 -17
- package/koni/api/staking/bonding/paraChain.js +11 -17
- package/koni/api/staking/bonding/utils.d.ts +3 -3
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +16 -3
- package/koni/background/handlers/Tabs.js +1 -5
- package/package.json +12 -6
- package/packageInfo.js +1 -1
- package/page/SubWalleEvmProvider.d.ts +2 -1
- package/page/SubWalleEvmProvider.js +18 -7
- package/services/chain-service/constants.js +5 -3
- package/services/chain-service/handler/AbstractChainHandler.d.ts +5 -5
- package/services/chain-service/handler/AbstractChainHandler.js +24 -9
- package/services/chain-service/handler/EvmApi.d.ts +4 -2
- package/services/chain-service/handler/EvmApi.js +15 -5
- package/services/chain-service/handler/EvmChainHandler.js +2 -2
- package/services/chain-service/handler/SubstrateApi.d.ts +5 -2
- package/services/chain-service/handler/SubstrateApi.js +36 -17
- package/services/chain-service/handler/SubstrateChainHandler.js +6 -6
- package/services/chain-service/handler/types.d.ts +2 -1
- package/services/chain-service/index.d.ts +1 -0
- package/services/chain-service/index.js +12 -6
- package/services/chain-service/types.d.ts +1 -0
- package/services/migration-service/scripts/MigrateWalletReference.d.ts +4 -0
- package/services/migration-service/scripts/MigrateWalletReference.js +23 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/setting-service/constants.js +2 -1
- package/services/storage-service/db-stores/Nft.js +2 -2
- package/services/storage-service/db-stores/Staking.js +2 -2
|
@@ -395,7 +395,7 @@ class ChainService {
|
|
|
395
395
|
this.dataMap.assetRefMap = latestAssetRefMap;
|
|
396
396
|
await this.initChains();
|
|
397
397
|
this.chainInfoMapSubject.next(this.getChainInfoMap());
|
|
398
|
-
this.
|
|
398
|
+
this.updateChainStateMapSubscription();
|
|
399
399
|
this.assetRegistrySubject.next(this.getAssetRegistry());
|
|
400
400
|
this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
|
|
401
401
|
await this.initApis();
|
|
@@ -423,14 +423,14 @@ class ChainService {
|
|
|
423
423
|
endpoint,
|
|
424
424
|
providerName
|
|
425
425
|
} = this.getChainCurrentProviderByKey(chainInfo.slug);
|
|
426
|
-
const onUpdateStatus =
|
|
426
|
+
const onUpdateStatus = status => {
|
|
427
427
|
const currentStatus = this.getChainStateByKey(chainInfo.slug).connectionStatus;
|
|
428
|
-
const newStatus = isConnected ? _types3._ChainConnectionStatus.CONNECTED : _types3._ChainConnectionStatus.DISCONNECTED;
|
|
429
428
|
|
|
430
429
|
// Avoid unnecessary update in case disable chain
|
|
431
|
-
if (currentStatus !==
|
|
432
|
-
|
|
433
|
-
this.
|
|
430
|
+
if (currentStatus !== status) {
|
|
431
|
+
console.log(chainInfo.name, currentStatus, status);
|
|
432
|
+
this.setChainConnectionStatus(chainInfo.slug, status);
|
|
433
|
+
this.updateChainStateMapSubscription();
|
|
434
434
|
}
|
|
435
435
|
};
|
|
436
436
|
if (chainInfo.substrateInfo !== null && chainInfo.substrateInfo !== undefined) {
|
|
@@ -515,6 +515,12 @@ class ChainService {
|
|
|
515
515
|
needUpdate && this.updateChainStateMapSubscription();
|
|
516
516
|
return needUpdate;
|
|
517
517
|
}
|
|
518
|
+
async reconnectChain(chain) {
|
|
519
|
+
var _this$getSubstrateApi, _this$getEvmApi;
|
|
520
|
+
await ((_this$getSubstrateApi = this.getSubstrateApi(chain)) === null || _this$getSubstrateApi === void 0 ? void 0 : _this$getSubstrateApi.recoverConnect());
|
|
521
|
+
await ((_this$getEvmApi = this.getEvmApi(chain)) === null || _this$getEvmApi === void 0 ? void 0 : _this$getEvmApi.recoverConnect());
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
518
524
|
disableChain(chainSlug) {
|
|
519
525
|
const chainInfo = this.getChainInfoByKey(chainSlug);
|
|
520
526
|
const chainStateMap = this.getChainStateMap();
|
|
@@ -0,0 +1,31 @@
|
|
|
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 _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
|
|
9
|
+
var _uuid = require("uuid");
|
|
10
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
class MigrateWalletReference extends _Base.default {
|
|
14
|
+
async run() {
|
|
15
|
+
try {
|
|
16
|
+
return new Promise(resolve => {
|
|
17
|
+
this.state.settingService.getSettings(currentSettings => {
|
|
18
|
+
const walletReference = (0, _uuid.v4)();
|
|
19
|
+
this.state.settingService.setSettings({
|
|
20
|
+
...currentSettings,
|
|
21
|
+
walletReference: walletReference
|
|
22
|
+
});
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = MigrateWalletReference;
|
|
@@ -15,6 +15,7 @@ var _MigrateLedgerAccount = _interopRequireDefault(require("./MigrateLedgerAccou
|
|
|
15
15
|
var _MigrateNetworkSettings = _interopRequireDefault(require("./MigrateNetworkSettings"));
|
|
16
16
|
var _MigrateSettings = _interopRequireDefault(require("./MigrateSettings"));
|
|
17
17
|
var _MigrateTransactionHistory = _interopRequireDefault(require("./MigrateTransactionHistory"));
|
|
18
|
+
var _MigrateWalletReference = _interopRequireDefault(require("./MigrateWalletReference"));
|
|
18
19
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
19
20
|
// SPDX-License-Identifier: Apache-2.0
|
|
20
21
|
|
|
@@ -30,7 +31,8 @@ var _default = {
|
|
|
30
31
|
'1.0.3-01': _MigrateAutoLock.default,
|
|
31
32
|
'1.0.3-02': _MigrateChainPatrol.default,
|
|
32
33
|
'1.0.9-01': _MigrateLedgerAccount.default,
|
|
33
|
-
'1.0.12-02': _MigrateEthProvider.default
|
|
34
|
+
'1.0.12-02': _MigrateEthProvider.default,
|
|
35
|
+
'1.1.6-01': _MigrateWalletReference.default
|
|
34
36
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
35
37
|
};
|
|
36
38
|
exports.default = _default;
|
|
@@ -35,6 +35,7 @@ const DEFAULT_SETTING = {
|
|
|
35
35
|
theme: DEFAULT_THEME,
|
|
36
36
|
camera: DEFAULT_CAMERA_ENABLE,
|
|
37
37
|
timeAutoLock: DEFAULT_AUTO_LOCK_TIME,
|
|
38
|
-
enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE
|
|
38
|
+
enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE,
|
|
39
|
+
walletReference: ''
|
|
39
40
|
};
|
|
40
41
|
exports.DEFAULT_SETTING = DEFAULT_SETTING;
|
|
@@ -14,11 +14,11 @@ class NftStore extends _BaseStoreWithAddressAndChain.default {
|
|
|
14
14
|
getNft(addresses) {
|
|
15
15
|
let chainList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
16
16
|
if (addresses.length) {
|
|
17
|
-
return this.table.where('address').anyOfIgnoreCase(addresses).and(item =>
|
|
17
|
+
return this.table.where('address').anyOfIgnoreCase(addresses).and(item => chainList && chainList.includes(item.chain)).toArray();
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// return this.table.filter((item) => !chainHashes.length || chainHashes.includes(item.chainHash)).toArray();
|
|
21
|
-
return this.table.filter(item =>
|
|
21
|
+
return this.table.filter(item => chainList && chainList.includes(item.chain)).toArray();
|
|
22
22
|
}
|
|
23
23
|
subscribeNft(addresses) {
|
|
24
24
|
let chainList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -18,9 +18,9 @@ class StakingStore extends _BaseStoreWithAddressAndChain.default {
|
|
|
18
18
|
getStakings(addresses) {
|
|
19
19
|
let chainList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
20
20
|
if (addresses.length) {
|
|
21
|
-
return this.table.where('address').anyOfIgnoreCase(addresses).and(item =>
|
|
21
|
+
return this.table.where('address').anyOfIgnoreCase(addresses).and(item => chainList && chainList.includes(item.chain) && parseFloat(item.balance) > 0).toArray();
|
|
22
22
|
}
|
|
23
|
-
return this.table.filter(item =>
|
|
23
|
+
return this.table.filter(item => chainList && chainList.includes(item.chain) && parseFloat(item.balance) > 0).toArray();
|
|
24
24
|
}
|
|
25
25
|
getStakingsByChains(chainList) {
|
|
26
26
|
return this.table.filter(item => chainList.includes(item.chain) && parseFloat(item.balance) > 0).toArray();
|
package/koni/api/nft/config.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const GATEWAY_IPFS_IO = "https://gateway.ipfs.io/ipfs/";
|
|
|
20
20
|
export declare const DWEB_LINK = "https://dweb.link/ipfs/";
|
|
21
21
|
export declare const IPFS_GATEWAY_4EVERLAND = "https://4everland.io/ipfs/";
|
|
22
22
|
export declare const IPFS_FLEEK = "https://ipfs.fleek.co/ipfs/";
|
|
23
|
-
export declare const IPFS_HARDBIN = "https://hardbin.com/ipfs";
|
|
23
|
+
export declare const IPFS_HARDBIN = "https://hardbin.com/ipfs/";
|
|
24
24
|
export declare enum SUPPORTED_NFT_NETWORKS {
|
|
25
25
|
karura = "karura",
|
|
26
26
|
acala = "acala",
|
package/koni/api/nft/config.js
CHANGED
|
@@ -24,7 +24,7 @@ export const GATEWAY_IPFS_IO = 'https://gateway.ipfs.io/ipfs/';
|
|
|
24
24
|
export const DWEB_LINK = 'https://dweb.link/ipfs/';
|
|
25
25
|
export const IPFS_GATEWAY_4EVERLAND = 'https://4everland.io/ipfs/';
|
|
26
26
|
export const IPFS_FLEEK = 'https://ipfs.fleek.co/ipfs/';
|
|
27
|
-
export const IPFS_HARDBIN = 'https://hardbin.com/ipfs';
|
|
27
|
+
export const IPFS_HARDBIN = 'https://hardbin.com/ipfs/';
|
|
28
28
|
export let SUPPORTED_NFT_NETWORKS;
|
|
29
29
|
(function (SUPPORTED_NFT_NETWORKS) {
|
|
30
30
|
SUPPORTED_NFT_NETWORKS["karura"] = "karura";
|
|
@@ -199,23 +199,24 @@ export async function getAmplitudeCollatorsInfo(chain, substrateApi) {
|
|
|
199
199
|
const delegatorReturn = parseFloat(rawDelegatorReturn.split('%')[0]);
|
|
200
200
|
const allCollators = [];
|
|
201
201
|
for (const _collator of _allCollators) {
|
|
202
|
-
const collatorInfo = _collator[1].
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
202
|
+
const collatorInfo = _collator[1].toPrimitive();
|
|
203
|
+
const bnTotalStake = new BN(collatorInfo.total);
|
|
204
|
+
const bnOwnStake = new BN(collatorInfo.stake);
|
|
205
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
206
|
+
allCollators.push({
|
|
207
|
+
address: collatorInfo.id,
|
|
208
|
+
totalStake: bnTotalStake.toString(),
|
|
209
|
+
ownStake: bnOwnStake.toString(),
|
|
210
|
+
otherStake: bnOtherStake.toString(),
|
|
211
|
+
nominatorCount: collatorInfo.delegators.length,
|
|
212
|
+
commission: 0,
|
|
213
|
+
expectedReturn: delegatorReturn,
|
|
214
|
+
blocked: false,
|
|
215
|
+
isVerified: false,
|
|
216
|
+
minBond: '0',
|
|
217
|
+
chain,
|
|
218
|
+
isCrowded: collatorInfo.delegators.length >= parseInt(maxDelegatorsPerCollator)
|
|
219
|
+
});
|
|
219
220
|
}
|
|
220
221
|
return allCollators;
|
|
221
222
|
}
|
|
@@ -26,7 +26,7 @@ export function validateParaChainUnbondingCondition(amount, nominatorMetadata, c
|
|
|
26
26
|
const bnRemainingStake = bnActiveStake.sub(new BN(amount));
|
|
27
27
|
const bnChainMinStake = new BN(chainStakingMetadata.minStake || '0');
|
|
28
28
|
const bnCollatorMinStake = new BN(targetNomination.validatorMinStake || '0');
|
|
29
|
-
const bnMinStake = bnCollatorMinStake
|
|
29
|
+
const bnMinStake = BN.max(bnCollatorMinStake, bnChainMinStake);
|
|
30
30
|
if (targetNomination.hasUnstaking) {
|
|
31
31
|
errors.push(new TransactionError(StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
|
|
32
32
|
}
|
|
@@ -83,9 +83,10 @@ export function validateParaChainBondingCondition(chainInfo, amount, selectedCol
|
|
|
83
83
|
}
|
|
84
84
|
export function subscribeParaChainStakingMetadata(chain, substrateApi, callback) {
|
|
85
85
|
return substrateApi.api.query.parachainStaking.round(_round => {
|
|
86
|
+
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$con3;
|
|
86
87
|
const roundObj = _round.toHuman();
|
|
87
88
|
const round = parseRawNumber(roundObj.current);
|
|
88
|
-
const maxDelegations = substrateApi.api.consts.parachainStaking.maxDelegationsPerDelegator.toString();
|
|
89
|
+
const maxDelegations = (_substrateApi$api$con = substrateApi.api.consts) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.parachainStaking) === null || _substrateApi$api$con2 === void 0 ? void 0 : (_substrateApi$api$con3 = _substrateApi$api$con2.maxDelegationsPerDelegator) === null || _substrateApi$api$con3 === void 0 ? void 0 : _substrateApi$api$con3.toString();
|
|
89
90
|
const unstakingDelay = substrateApi.api.consts.parachainStaking.delegationBondLessDelay.toString();
|
|
90
91
|
const unstakingPeriod = parseInt(unstakingDelay) * (_STAKING_ERA_LENGTH_MAP[chain] || _STAKING_ERA_LENGTH_MAP.default);
|
|
91
92
|
callback(chain, {
|
|
@@ -314,17 +315,21 @@ export async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
314
315
|
const _collatorAddress = collator[0].toHuman();
|
|
315
316
|
const collatorAddress = _collatorAddress[0];
|
|
316
317
|
const collatorInfo = collator[1].toPrimitive();
|
|
318
|
+
const bnTotalStake = new BN(collatorInfo.totalCounted);
|
|
319
|
+
const bnOwnStake = new BN(collatorInfo.bond);
|
|
320
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
321
|
+
const bnMinBond = new BN(collatorInfo.lowestTopDelegationAmount);
|
|
317
322
|
allCollators.push({
|
|
318
323
|
commission: 0,
|
|
319
324
|
expectedReturn: 0,
|
|
320
325
|
address: collatorAddress,
|
|
321
|
-
totalStake:
|
|
322
|
-
ownStake:
|
|
323
|
-
otherStake:
|
|
326
|
+
totalStake: bnTotalStake.toString(),
|
|
327
|
+
ownStake: bnOwnStake.toString(),
|
|
328
|
+
otherStake: bnOtherStake.toString(),
|
|
324
329
|
nominatorCount: collatorInfo.delegationCount,
|
|
325
330
|
blocked: false,
|
|
326
331
|
isVerified: false,
|
|
327
|
-
minBond:
|
|
332
|
+
minBond: bnMinBond.toString(),
|
|
328
333
|
chain,
|
|
329
334
|
isCrowded: parseInt(maxDelegationPerCollator) > 0
|
|
330
335
|
});
|
|
@@ -336,10 +341,6 @@ export async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
336
341
|
]);
|
|
337
342
|
const rawInfo = _info.toHuman();
|
|
338
343
|
const rawIdentity = _identity ? _identity.toHuman() : null;
|
|
339
|
-
const rawBond = rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.bond;
|
|
340
|
-
const bond = new BN(rawBond.replaceAll(',', ''));
|
|
341
|
-
const delegationCount = parseRawNumber(rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.delegationCount);
|
|
342
|
-
const minDelegation = parseRawNumber(rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.lowestTopDelegationAmount);
|
|
343
344
|
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
344
345
|
let isReasonable = false;
|
|
345
346
|
let identity;
|
|
@@ -351,21 +352,14 @@ export async function getParachainCollatorsInfo(chain, substrateApi) {
|
|
|
351
352
|
extraInfoMap[collator.address] = {
|
|
352
353
|
identity,
|
|
353
354
|
isVerified: isReasonable,
|
|
354
|
-
bond: bond.toString(),
|
|
355
|
-
minDelegation: minDelegation.toString(),
|
|
356
|
-
delegationCount,
|
|
357
355
|
active
|
|
358
356
|
};
|
|
359
357
|
}));
|
|
360
358
|
for (const validator of allCollators) {
|
|
361
|
-
validator.minBond = extraInfoMap[validator.address].minDelegation.toString();
|
|
362
|
-
validator.ownStake = extraInfoMap[validator.address].bond.toString();
|
|
363
359
|
validator.blocked = !extraInfoMap[validator.address].active;
|
|
364
360
|
validator.identity = extraInfoMap[validator.address].identity;
|
|
365
361
|
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
366
362
|
// @ts-ignore
|
|
367
|
-
validator.otherStake = (validator.totalStake - validator.ownStake).toString();
|
|
368
|
-
validator.nominatorCount = extraInfoMap[validator.address].delegationCount;
|
|
369
363
|
validator.commission = collatorCommission;
|
|
370
364
|
}
|
|
371
365
|
return allCollators;
|
|
@@ -38,10 +38,10 @@ export interface ParachainStakingStakeOption {
|
|
|
38
38
|
amount: number;
|
|
39
39
|
}
|
|
40
40
|
export interface ParachainStakingCandidateMetadata {
|
|
41
|
-
bond:
|
|
41
|
+
bond: string;
|
|
42
42
|
delegationCount: number;
|
|
43
|
-
totalCounted:
|
|
44
|
-
lowestTopDelegationAmount:
|
|
43
|
+
totalCounted: string;
|
|
44
|
+
lowestTopDelegationAmount: string;
|
|
45
45
|
status: any | 'Active';
|
|
46
46
|
}
|
|
47
47
|
export declare enum PalletParachainStakingRequestType {
|
|
@@ -1371,12 +1371,20 @@ export default class KoniExtension {
|
|
|
1371
1371
|
async subscribeHistory(id, port) {
|
|
1372
1372
|
const cb = createSubscription(id, port);
|
|
1373
1373
|
const historySubject = await this.#koniState.historyService.getHistorySubject();
|
|
1374
|
-
historySubject.subscribe(
|
|
1375
|
-
|
|
1374
|
+
const subscription = historySubject.subscribe(histories => {
|
|
1375
|
+
const addresses = keyring.getAccounts().map(a => a.address.toLowerCase());
|
|
1376
|
+
|
|
1377
|
+
// Re-filter
|
|
1378
|
+
cb(histories.filter(item => addresses.includes(item.address.toLowerCase())));
|
|
1379
|
+
});
|
|
1380
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
1376
1381
|
port.onDisconnect.addListener(() => {
|
|
1377
1382
|
this.cancelSubscription(id);
|
|
1378
1383
|
});
|
|
1379
|
-
|
|
1384
|
+
const addresses = keyring.getAccounts().map(a => a.address.toLowerCase());
|
|
1385
|
+
|
|
1386
|
+
// Re-filter
|
|
1387
|
+
return historySubject.getValue().filter(item => addresses.includes(item.address.toLowerCase()));
|
|
1380
1388
|
}
|
|
1381
1389
|
|
|
1382
1390
|
// Save address to contact
|
|
@@ -1673,6 +1681,9 @@ export default class KoniExtension {
|
|
|
1673
1681
|
}) {
|
|
1674
1682
|
return await this.#koniState.enableChain(chainSlug, enableTokens);
|
|
1675
1683
|
}
|
|
1684
|
+
async reconnectChain(chainSlug) {
|
|
1685
|
+
return this.#koniState.chainService.reconnectChain(chainSlug);
|
|
1686
|
+
}
|
|
1676
1687
|
async validateNetwork({
|
|
1677
1688
|
existedChainSlug,
|
|
1678
1689
|
provider
|
|
@@ -3603,6 +3614,8 @@ export default class KoniExtension {
|
|
|
3603
3614
|
return this.getSupportedSmartContractTypes();
|
|
3604
3615
|
case 'pri(chainService.enableChain)':
|
|
3605
3616
|
return await this.enableChain(request);
|
|
3617
|
+
case 'pri(chainService.reconnectChain)':
|
|
3618
|
+
return await this.reconnectChain(request);
|
|
3606
3619
|
case 'pri(chainService.disableChain)':
|
|
3607
3620
|
return await this.disableChain(request);
|
|
3608
3621
|
case 'pri(chainService.removeChain)':
|
|
@@ -843,11 +843,7 @@ export default class KoniTabs {
|
|
|
843
843
|
return true;
|
|
844
844
|
}
|
|
845
845
|
isEvmPublicRequest(type, request) {
|
|
846
|
-
|
|
847
|
-
return true;
|
|
848
|
-
} else {
|
|
849
|
-
return false;
|
|
850
|
-
}
|
|
846
|
+
return type === 'evm(request)' && ['eth_chainId', 'net_version'].includes(request === null || request === void 0 ? void 0 : request.method);
|
|
851
847
|
}
|
|
852
848
|
async addPspToken(id, url, {
|
|
853
849
|
genesisHash,
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.6-
|
|
20
|
+
"version": "1.1.6-2",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -695,6 +695,11 @@
|
|
|
695
695
|
"require": "./cjs/services/migration-service/scripts/MigrateTransactionHistory.js",
|
|
696
696
|
"default": "./services/migration-service/scripts/MigrateTransactionHistory.js"
|
|
697
697
|
},
|
|
698
|
+
"./services/migration-service/scripts/MigrateWalletReference": {
|
|
699
|
+
"types": "./services/migration-service/scripts/MigrateWalletReference.d.ts",
|
|
700
|
+
"require": "./cjs/services/migration-service/scripts/MigrateWalletReference.js",
|
|
701
|
+
"default": "./services/migration-service/scripts/MigrateWalletReference.js"
|
|
702
|
+
},
|
|
698
703
|
"./services/notification-service/NotificationService": {
|
|
699
704
|
"types": "./services/notification-service/NotificationService.d.ts",
|
|
700
705
|
"require": "./cjs/services/notification-service/NotificationService.js",
|
|
@@ -1183,11 +1188,11 @@
|
|
|
1183
1188
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1184
1189
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1185
1190
|
"@substrate/connect": "^0.7.26",
|
|
1186
|
-
"@subwallet/chain-list": "
|
|
1187
|
-
"@subwallet/extension-base": "^1.1.6-
|
|
1188
|
-
"@subwallet/extension-chains": "^1.1.6-
|
|
1189
|
-
"@subwallet/extension-dapp": "^1.1.6-
|
|
1190
|
-
"@subwallet/extension-inject": "^1.1.6-
|
|
1191
|
+
"@subwallet/chain-list": "0.2.9",
|
|
1192
|
+
"@subwallet/extension-base": "^1.1.6-2",
|
|
1193
|
+
"@subwallet/extension-chains": "^1.1.6-2",
|
|
1194
|
+
"@subwallet/extension-dapp": "^1.1.6-2",
|
|
1195
|
+
"@subwallet/extension-inject": "^1.1.6-2",
|
|
1191
1196
|
"@subwallet/keyring": "^0.0.10",
|
|
1192
1197
|
"@subwallet/ui-keyring": "^0.0.10",
|
|
1193
1198
|
"@walletconnect/sign-client": "^2.8.4",
|
|
@@ -1214,6 +1219,7 @@
|
|
|
1214
1219
|
"moment": "^2.29.4",
|
|
1215
1220
|
"protobufjs": "^7.2.4",
|
|
1216
1221
|
"rxjs": "^7.8.1",
|
|
1222
|
+
"uuid": "^9.0.0",
|
|
1217
1223
|
"web3": "^1.10.0",
|
|
1218
1224
|
"web3-core": "^1.10.0",
|
|
1219
1225
|
"web3-core-helpers": "^1.10.0",
|
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.6-
|
|
10
|
+
version: '1.1.6-2'
|
|
11
11
|
};
|
|
@@ -12,12 +12,13 @@ export declare class SubWalletEvmProvider extends SafeEventEmitter implements Ev
|
|
|
12
12
|
readonly version: string;
|
|
13
13
|
protected sendMessage: SendRequest;
|
|
14
14
|
protected _connected: boolean;
|
|
15
|
-
protected _subscribed: boolean;
|
|
16
15
|
constructor(sendMessage: SendRequest, version: string);
|
|
17
16
|
get connected(): boolean;
|
|
18
17
|
isConnected(): boolean;
|
|
19
18
|
protected subscribeExtensionEvents(): void;
|
|
20
19
|
enable(): Promise<unknown>;
|
|
20
|
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
21
|
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
21
22
|
request<T>({ method, params }: RequestArguments): Promise<T>;
|
|
22
23
|
private _sendSync;
|
|
23
24
|
send<T>(method: string, params?: T[]): Promise<JsonRpcResponse<T>>;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import SafeEventEmitter from '@metamask/safe-event-emitter';
|
|
5
|
+
let subscribeFlag = false;
|
|
5
6
|
export class SubWalletEvmProvider extends SafeEventEmitter {
|
|
6
7
|
isSubWallet = true;
|
|
7
8
|
isMetaMask = false;
|
|
8
9
|
_connected = false;
|
|
9
|
-
_subscribed = false;
|
|
10
10
|
constructor(sendMessage, version) {
|
|
11
11
|
super();
|
|
12
12
|
this.version = version;
|
|
@@ -20,7 +20,7 @@ export class SubWalletEvmProvider extends SafeEventEmitter {
|
|
|
20
20
|
return this._connected;
|
|
21
21
|
}
|
|
22
22
|
subscribeExtensionEvents() {
|
|
23
|
-
if (
|
|
23
|
+
if (subscribeFlag) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
this.sendMessage('evm(events.subscribe)', null, ({
|
|
@@ -41,18 +41,32 @@ export class SubWalletEvmProvider extends SafeEventEmitter {
|
|
|
41
41
|
console.warn('Can not handle event', type, payload);
|
|
42
42
|
}
|
|
43
43
|
}).then(done => {
|
|
44
|
-
|
|
45
|
-
}).catch(
|
|
44
|
+
subscribeFlag = true;
|
|
45
|
+
}).catch(() => {
|
|
46
|
+
subscribeFlag = false;
|
|
47
|
+
});
|
|
48
|
+
subscribeFlag = true;
|
|
46
49
|
}
|
|
47
50
|
async enable() {
|
|
48
51
|
return this.request({
|
|
49
52
|
method: 'eth_requestAccounts'
|
|
50
53
|
});
|
|
51
54
|
}
|
|
55
|
+
on(eventName, listener) {
|
|
56
|
+
this.subscribeExtensionEvents();
|
|
57
|
+
super.on(eventName, listener);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
once(eventName, listener) {
|
|
61
|
+
this.subscribeExtensionEvents();
|
|
62
|
+
super.once(eventName, listener);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
52
65
|
request({
|
|
53
66
|
method,
|
|
54
67
|
params
|
|
55
68
|
}) {
|
|
69
|
+
// Subscribe events
|
|
56
70
|
switch (method) {
|
|
57
71
|
case 'eth_requestAccounts':
|
|
58
72
|
return new Promise((resolve, reject) => {
|
|
@@ -61,9 +75,6 @@ export class SubWalletEvmProvider extends SafeEventEmitter {
|
|
|
61
75
|
origin,
|
|
62
76
|
accountAuthType: 'evm'
|
|
63
77
|
}).then(() => {
|
|
64
|
-
// Subscribe event
|
|
65
|
-
this.subscribeExtensionEvents();
|
|
66
|
-
|
|
67
78
|
// Return account list
|
|
68
79
|
this.request({
|
|
69
80
|
method: 'eth_accounts'
|
|
@@ -49,13 +49,13 @@ export const _NFT_CHAIN_GROUP = {
|
|
|
49
49
|
// Staking--------------------------------------------------------------------------------------------------------------
|
|
50
50
|
|
|
51
51
|
export const _STAKING_CHAIN_GROUP = {
|
|
52
|
-
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend'],
|
|
52
|
+
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware'],
|
|
53
53
|
para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari'],
|
|
54
54
|
astar: ['astar', 'shiden', 'shibuya'],
|
|
55
55
|
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum'],
|
|
56
56
|
// amplitude and kilt only share some common logic
|
|
57
57
|
kilt: ['kilt', 'kilt_peregrine'],
|
|
58
|
-
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph'],
|
|
58
|
+
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate'],
|
|
59
59
|
bifrost: ['bifrost', 'bifrost_testnet'],
|
|
60
60
|
aleph: ['aleph', 'alephTest'],
|
|
61
61
|
// A0 has distinct tokenomics
|
|
@@ -87,7 +87,9 @@ export const _STAKING_ERA_LENGTH_MAP = {
|
|
|
87
87
|
amplitude_test: 2,
|
|
88
88
|
pendulum: 2,
|
|
89
89
|
kilt: 2,
|
|
90
|
-
kilt_peregrine: 2
|
|
90
|
+
kilt_peregrine: 2,
|
|
91
|
+
edgeware: 6,
|
|
92
|
+
kate: 6
|
|
91
93
|
};
|
|
92
94
|
export const _PARACHAIN_INFLATION_DISTRIBUTION = {
|
|
93
95
|
moonbeam: {
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
3
3
|
import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
4
|
-
import { _ChainBaseApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
+
import { _ChainBaseApi, _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
5
|
import { BehaviorSubject } from 'rxjs';
|
|
6
6
|
export declare const FIRST_RECONNECT_TIME = 3000;
|
|
7
|
-
export declare const SHORT_RETRY_TIME =
|
|
8
|
-
export declare const LONG_RETRY_TIME = 60000;
|
|
7
|
+
export declare const SHORT_RETRY_TIME = 20000;
|
|
9
8
|
interface RetryObject {
|
|
10
9
|
retryTimes: number;
|
|
11
10
|
timeout?: NodeJS.Timer;
|
|
12
11
|
}
|
|
13
12
|
export declare abstract class AbstractChainHandler {
|
|
14
13
|
protected parent?: ChainService | undefined;
|
|
15
|
-
readonly apiStateMapSubject: BehaviorSubject<Record<string,
|
|
14
|
+
readonly apiStateMapSubject: BehaviorSubject<Record<string, _ChainConnectionStatus>>;
|
|
16
15
|
protected recoverMap: Record<string, RetryObject>;
|
|
17
16
|
protected isSleeping: boolean;
|
|
18
17
|
protected constructor(parent?: ChainService | undefined);
|
|
@@ -21,8 +20,9 @@ export declare abstract class AbstractChainHandler {
|
|
|
21
20
|
abstract recoverApi(chainSlug: string): void;
|
|
22
21
|
abstract sleep(): Promise<void>;
|
|
23
22
|
abstract wakeUp(): Promise<void>;
|
|
24
|
-
|
|
23
|
+
handleConnection(chain: string, newStatus: _ChainConnectionStatus, forceRecover?: boolean): void;
|
|
25
24
|
protected handleRecover(chain: string): void;
|
|
25
|
+
protected isRecovering(chain: string): boolean;
|
|
26
26
|
protected cancelRecover(chain: string): void;
|
|
27
27
|
cancelAllRecover(): void;
|
|
28
28
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
5
|
import { BehaviorSubject } from 'rxjs';
|
|
5
|
-
const
|
|
6
|
+
const MAX_RECOVER_RETRY = 6;
|
|
6
7
|
export const FIRST_RECONNECT_TIME = 3000;
|
|
7
|
-
export const SHORT_RETRY_TIME =
|
|
8
|
-
export const LONG_RETRY_TIME = 60000;
|
|
8
|
+
export const SHORT_RETRY_TIME = 20000;
|
|
9
|
+
// export const LONG_RETRY_TIME = 60000;
|
|
10
|
+
|
|
9
11
|
export class AbstractChainHandler {
|
|
10
12
|
apiStateMapSubject = new BehaviorSubject({});
|
|
11
13
|
// Recover retry times
|
|
@@ -15,20 +17,25 @@ export class AbstractChainHandler {
|
|
|
15
17
|
this.parent = parent;
|
|
16
18
|
this.recoverMap = {};
|
|
17
19
|
}
|
|
18
|
-
|
|
20
|
+
handleConnection(chain, newStatus, forceRecover = false) {
|
|
19
21
|
const currentMap = this.apiStateMapSubject.getValue();
|
|
20
|
-
const
|
|
22
|
+
const oldStatus = currentMap[chain];
|
|
21
23
|
|
|
22
24
|
// Update api state
|
|
23
|
-
if (
|
|
25
|
+
if (oldStatus !== newStatus) {
|
|
24
26
|
this.apiStateMapSubject.next({
|
|
25
27
|
...currentMap,
|
|
26
|
-
[chain]:
|
|
28
|
+
[chain]: newStatus
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
// Reset retry when connected is successful
|
|
33
|
+
if (newStatus === _ChainConnectionStatus.CONNECTED) {
|
|
34
|
+
this.cancelRecover(chain);
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
// Handle connection change
|
|
31
|
-
if (!
|
|
38
|
+
if ((!this.isRecovering(chain) || forceRecover) && newStatus === _ChainConnectionStatus.DISCONNECTED) {
|
|
32
39
|
this.handleRecover(chain);
|
|
33
40
|
}
|
|
34
41
|
}
|
|
@@ -48,8 +55,13 @@ export class AbstractChainHandler {
|
|
|
48
55
|
};
|
|
49
56
|
clearTimeout(retryRecord.timeout);
|
|
50
57
|
const retryTimes = retryRecord.retryTimes;
|
|
58
|
+
if (retryTimes >= MAX_RECOVER_RETRY) {
|
|
59
|
+
this.handleConnection(chain, _ChainConnectionStatus.UNSTABLE);
|
|
60
|
+
this.cancelRecover(chain); // Need manual recover
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
// Slow down recover frequency if increasing recover times
|
|
52
|
-
const retryTimeout = retryTimes === 0 ? FIRST_RECONNECT_TIME :
|
|
64
|
+
const retryTimeout = retryTimes === 0 ? FIRST_RECONNECT_TIME : SHORT_RETRY_TIME;
|
|
53
65
|
|
|
54
66
|
// Recover api after retry timeout
|
|
55
67
|
const timeout = setTimeout(() => {
|
|
@@ -68,6 +80,9 @@ export class AbstractChainHandler {
|
|
|
68
80
|
timeout
|
|
69
81
|
};
|
|
70
82
|
}
|
|
83
|
+
isRecovering(chain) {
|
|
84
|
+
return !!this.recoverMap[chain];
|
|
85
|
+
}
|
|
71
86
|
cancelRecover(chain) {
|
|
72
87
|
const retryRecord = this.recoverMap[chain];
|
|
73
88
|
if (retryRecord) {
|