@subwallet/extension-base 1.0.1 → 1.0.2-1
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 +10 -3
- package/background/KoniTypes.js +6 -0
- package/cjs/background/KoniTypes.js +8 -1
- package/cjs/constants/index.js +6 -3
- package/cjs/koni/api/dotsama/balance.js +11 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +6 -2
- package/cjs/koni/api/staking/bonding/astar.js +40 -243
- package/cjs/koni/api/staking/bonding/index.js +4 -4
- package/cjs/koni/api/staking/bonding/paraChain.js +16 -10
- package/cjs/koni/api/staking/bonding/relayChain.js +62 -7
- package/cjs/koni/api/staking/bonding/utils.js +29 -3
- package/cjs/koni/api/xcm/index.js +0 -111
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/xTokens.js +2 -4
- package/cjs/koni/background/cron.js +61 -62
- package/cjs/koni/background/handlers/Extension.js +143 -149
- package/cjs/koni/background/handlers/State.js +129 -91
- package/cjs/koni/background/handlers/Tabs.js +40 -38
- package/cjs/koni/background/subscription.js +48 -43
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +5 -0
- package/cjs/services/chain-service/constants.js +1 -11
- package/cjs/services/chain-service/index.js +39 -5
- package/cjs/services/chain-service/utils.js +4 -0
- package/cjs/services/event-service/index.js +71 -0
- package/cjs/services/event-service/types.js +1 -0
- package/cjs/services/history-service/index.js +36 -17
- package/cjs/services/history-service/subsquid-multi-chain-history.js +7 -2
- package/cjs/services/keyring-service/index.js +101 -0
- package/cjs/services/migration-service/index.js +13 -10
- package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
- package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
- package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
- package/cjs/services/migration-service/scripts/index.js +13 -4
- package/cjs/services/price-service/coingecko.js +16 -3
- package/cjs/services/price-service/index.js +15 -17
- package/cjs/services/request-service/constants.js +8 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +39 -12
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/cjs/services/storage-service/db-stores/Nft.js +4 -1
- package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
- package/cjs/services/subscan-service/index.js +107 -0
- package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
- package/cjs/services/subscan-service/types.js +1 -0
- package/cjs/services/transaction-service/index.js +45 -10
- package/cjs/services/transaction-service/utils.js +4 -6
- package/cjs/utils/address.js +9 -1
- package/cjs/utils/index.js +24 -13
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/koni/api/dotsama/balance.js +11 -0
- package/koni/api/staking/bonding/amplitude.d.ts +1 -1
- package/koni/api/staking/bonding/amplitude.js +8 -4
- package/koni/api/staking/bonding/astar.d.ts +2 -11
- package/koni/api/staking/bonding/astar.js +35 -229
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +4 -4
- package/koni/api/staking/bonding/paraChain.d.ts +1 -1
- package/koni/api/staking/bonding/paraChain.js +17 -11
- package/koni/api/staking/bonding/relayChain.d.ts +1 -1
- package/koni/api/staking/bonding/relayChain.js +63 -8
- package/koni/api/staking/bonding/utils.d.ts +13 -1
- package/koni/api/staking/bonding/utils.js +27 -3
- package/koni/api/xcm/index.js +1 -112
- package/koni/api/xcm/polkadotXcm.js +1 -1
- package/koni/api/xcm/xTokens.js +3 -5
- package/koni/background/cron.js +60 -60
- package/koni/background/handlers/Extension.js +71 -76
- package/koni/background/handlers/State.d.ts +16 -14
- package/koni/background/handlers/State.js +126 -91
- package/koni/background/handlers/Tabs.js +22 -19
- package/koni/background/subscription.d.ts +1 -1
- package/koni/background/subscription.js +49 -44
- package/package.json +56 -16
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -0
- package/page/index.js +4 -0
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +0 -9
- package/services/chain-service/index.d.ts +6 -4
- package/services/chain-service/index.js +39 -7
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +3 -0
- package/services/event-service/index.d.ts +22 -0
- package/services/event-service/index.js +59 -0
- package/services/event-service/types.d.ts +32 -0
- package/services/event-service/types.js +1 -0
- package/services/history-service/index.d.ts +5 -3
- package/services/history-service/index.js +36 -17
- package/services/history-service/subsquid-multi-chain-history.js +7 -2
- package/services/keyring-service/index.d.ts +19 -0
- package/services/keyring-service/index.js +93 -0
- package/services/migration-service/index.js +11 -9
- package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
- package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
- package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
- package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
- package/services/migration-service/scripts/MigrateSettings.js +23 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
- package/services/migration-service/scripts/index.d.ts +1 -0
- package/services/migration-service/scripts/index.js +10 -3
- package/services/price-service/coingecko.js +16 -3
- package/services/price-service/index.d.ts +5 -3
- package/services/price-service/index.js +15 -17
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +6 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
- package/services/request-service/handler/AuthRequestHandler.js +40 -13
- package/services/request-service/index.d.ts +7 -1
- package/services/request-service/index.js +3 -0
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +4 -1
- package/services/storage-service/db-stores/Transaction.js +10 -7
- package/services/subscan-service/index.d.ts +20 -0
- package/services/subscan-service/index.js +99 -0
- package/services/subscan-service/subscan-chain-map.d.ts +5 -0
- package/services/subscan-service/subscan-chain-map.js +63 -0
- package/services/subscan-service/types.d.ts +27 -0
- package/services/subscan-service/types.js +1 -0
- package/services/transaction-service/event-parser/index.d.ts +2 -2
- package/services/transaction-service/index.d.ts +4 -2
- package/services/transaction-service/index.js +45 -10
- package/services/transaction-service/utils.js +5 -6
- package/utils/address.d.ts +1 -0
- package/utils/address.js +9 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.js +21 -12
- package/cjs/background/errors/EvmRpcError.js +0 -21
- package/cjs/background/errors/SubWalletProviderError.js +0 -17
- package/cjs/constants/ethereum.js +0 -19
- package/cjs/errors/SubWalletProviderError.js +0 -17
- package/cjs/koni/api/xcm/astar.js +0 -160
- package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
- package/cjs/koni/api/xcm/statemintXcm.js +0 -197
- package/cjs/koni/api/xcm/substrateXcm.js +0 -213
- package/cjs/koni/migration/Base.js +0 -20
- package/cjs/koni/migration/index.js +0 -45
- package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
- package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
- package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
- package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
- package/cjs/koni/migration/scripts/index.js +0 -22
- package/cjs/koni/page/index.js +0 -16
- package/cjs/services/asset-service/index.js +0 -91
- package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
- package/cjs/stores/Balance.js +0 -18
- package/cjs/stores/Crowdloan.js +0 -18
- package/cjs/stores/CustomEvmToken.js +0 -18
- package/cjs/stores/NetworkMap.js +0 -18
- package/cjs/stores/Nft.js +0 -18
- package/cjs/stores/NftCollection.js +0 -18
- package/cjs/stores/Price.js +0 -18
- package/cjs/stores/Staking.js +0 -18
- package/cjs/stores/StakingReward.js +0 -18
- package/cjs/utils/eth/parseTransactionData.js +0 -284
- package/koni/page/index.d.ts +0 -2
- package/koni/page/index.js +0 -9
- /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
|
@@ -15,15 +15,18 @@ var _balanceService = require("@subwallet/extension-base/services/balance-servic
|
|
|
15
15
|
var _chainService = require("@subwallet/extension-base/services/chain-service");
|
|
16
16
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
17
17
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
18
|
+
var _eventService = require("@subwallet/extension-base/services/event-service");
|
|
18
19
|
var _historyService = require("@subwallet/extension-base/services/history-service");
|
|
20
|
+
var _keyringService = require("@subwallet/extension-base/services/keyring-service");
|
|
19
21
|
var _migrationService = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service"));
|
|
20
22
|
var _NotificationService = _interopRequireDefault(require("@subwallet/extension-base/services/notification-service/NotificationService"));
|
|
21
23
|
var _priceService = require("@subwallet/extension-base/services/price-service");
|
|
22
24
|
var _requestService = _interopRequireDefault(require("@subwallet/extension-base/services/request-service"));
|
|
23
25
|
var _SettingService = _interopRequireDefault(require("@subwallet/extension-base/services/setting-service/SettingService"));
|
|
24
26
|
var _DatabaseService = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/DatabaseService"));
|
|
27
|
+
var _subscanService = require("@subwallet/extension-base/services/subscan-service");
|
|
28
|
+
var _subscanChainMap = require("@subwallet/extension-base/services/subscan-service/subscan-chain-map");
|
|
25
29
|
var _transactionService = _interopRequireDefault(require("@subwallet/extension-base/services/transaction-service"));
|
|
26
|
-
var _stores = require("@subwallet/extension-base/stores");
|
|
27
30
|
var _AccountRef = _interopRequireDefault(require("@subwallet/extension-base/stores/AccountRef"));
|
|
28
31
|
var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
29
32
|
var _decode = require("@subwallet/keyring/pair/decode");
|
|
@@ -62,15 +65,8 @@ const generateDefaultCrowdloanMap = () => {
|
|
|
62
65
|
class KoniState {
|
|
63
66
|
injectedProviders = new Map();
|
|
64
67
|
unsubscriptionMap = {};
|
|
65
|
-
currentAccountStore = new _stores.CurrentAccountStore();
|
|
66
68
|
accountRefStore = new _AccountRef.default();
|
|
67
|
-
keyringStateSubject = new _rxjs.Subject();
|
|
68
69
|
externalRequest = {};
|
|
69
|
-
keyringState = {
|
|
70
|
-
isReady: false,
|
|
71
|
-
isLocked: true,
|
|
72
|
-
hasMasterPassword: false
|
|
73
|
-
};
|
|
74
70
|
serviceInfoSubject = new _rxjs.Subject();
|
|
75
71
|
balanceMap = {};
|
|
76
72
|
balanceSubject = new _rxjs.Subject();
|
|
@@ -88,19 +84,21 @@ class KoniState {
|
|
|
88
84
|
};
|
|
89
85
|
lazyMap = {};
|
|
90
86
|
ready = false;
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
87
|
constructor() {
|
|
93
88
|
let providers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
94
89
|
this.providers = providers;
|
|
95
90
|
this.dbService = new _DatabaseService.default();
|
|
91
|
+
this.eventService = new _eventService.EventService();
|
|
92
|
+
this.subscanService = new _subscanService.SubscanService();
|
|
93
|
+
this.keyringService = new _keyringService.KeyringService(this.eventService);
|
|
96
94
|
this.notificationService = new _NotificationService.default();
|
|
97
|
-
this.chainService = new _chainService.ChainService(this.dbService);
|
|
95
|
+
this.chainService = new _chainService.ChainService(this.dbService, this.eventService);
|
|
98
96
|
this.settingService = new _SettingService.default();
|
|
99
97
|
this.requestService = new _requestService.default(this.chainService, this.settingService);
|
|
100
|
-
this.priceService = new _priceService.PriceService(this.
|
|
98
|
+
this.priceService = new _priceService.PriceService(this.dbService, this.eventService, this.chainService);
|
|
101
99
|
this.balanceService = new _balanceService.BalanceService(this.chainService);
|
|
102
|
-
this.historyService = new _historyService.HistoryService(this.dbService, this.chainService);
|
|
103
|
-
this.transactionService = new _transactionService.default(this.chainService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
|
|
100
|
+
this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService);
|
|
101
|
+
this.transactionService = new _transactionService.default(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
|
|
104
102
|
this.migrationService = new _migrationService.default(this);
|
|
105
103
|
this.subscription = new _subscription.KoniSubscription(this, this.dbService);
|
|
106
104
|
this.cron = new _cron.KoniCron(this, this.subscription, this.dbService);
|
|
@@ -208,8 +206,10 @@ class KoniState {
|
|
|
208
206
|
await this.chainService.init();
|
|
209
207
|
await this.migrationService.run();
|
|
210
208
|
this.startSubscription();
|
|
211
|
-
this.
|
|
209
|
+
this.eventService.emit('chain.ready', true);
|
|
212
210
|
this.onReady();
|
|
211
|
+
this.onAccountAdd();
|
|
212
|
+
this.onAccountRemove();
|
|
213
213
|
this.logger.log('Done init state');
|
|
214
214
|
}
|
|
215
215
|
startSubscription() {
|
|
@@ -229,15 +229,10 @@ class KoniState {
|
|
|
229
229
|
isReady() {
|
|
230
230
|
return this.ready;
|
|
231
231
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return this.keyringStateSubject;
|
|
237
|
-
}
|
|
238
|
-
setKeyringState(data, callback) {
|
|
239
|
-
this.keyringStateSubject.next(data);
|
|
240
|
-
this.keyringState = data;
|
|
232
|
+
updateKeyringState() {
|
|
233
|
+
let isReady = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
234
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
235
|
+
this.keyringService.updateKeyringState(isReady);
|
|
241
236
|
callback && callback();
|
|
242
237
|
}
|
|
243
238
|
lazyNext = (key, callback) => {
|
|
@@ -296,7 +291,7 @@ class KoniState {
|
|
|
296
291
|
return this.dbService.getNominatorMetadata();
|
|
297
292
|
}
|
|
298
293
|
async getStaking() {
|
|
299
|
-
const addresses =
|
|
294
|
+
const addresses = this.getDecodedAddresses();
|
|
300
295
|
const stakings = await this.dbService.getStakings(addresses, this.activeChainSlugs);
|
|
301
296
|
return {
|
|
302
297
|
ready: true,
|
|
@@ -355,12 +350,12 @@ class KoniState {
|
|
|
355
350
|
subscribeNftCollection() {
|
|
356
351
|
return this.dbService.stores.nftCollection.subscribeNftCollection(this.activeChainSlugs);
|
|
357
352
|
}
|
|
358
|
-
|
|
353
|
+
resetNft(newAddress) {
|
|
359
354
|
this.getNft().then(data => this.nftSubject.next(data || {
|
|
360
355
|
nftList: [],
|
|
361
356
|
total: 0
|
|
362
357
|
})).catch(e => this.logger.warn(e));
|
|
363
|
-
const addresses =
|
|
358
|
+
const addresses = this.getDecodedAddresses(newAddress);
|
|
364
359
|
this.dbService.subscribeNft(addresses, this.activeChainSlugs, nfts => {
|
|
365
360
|
this.nftSubject.next({
|
|
366
361
|
nftList: nfts,
|
|
@@ -379,7 +374,7 @@ class KoniState {
|
|
|
379
374
|
return this.dbService.deleteNftCollection(chain, collectionId);
|
|
380
375
|
}
|
|
381
376
|
async getNft() {
|
|
382
|
-
const addresses =
|
|
377
|
+
const addresses = this.getDecodedAddresses();
|
|
383
378
|
if (!addresses.length) {
|
|
384
379
|
return;
|
|
385
380
|
}
|
|
@@ -453,9 +448,6 @@ class KoniState {
|
|
|
453
448
|
subscribeStakingReward() {
|
|
454
449
|
return this.stakingRewardSubject;
|
|
455
450
|
}
|
|
456
|
-
getCurrentAccount(update) {
|
|
457
|
-
this.currentAccountStore.get('CurrentAccountInfo', update);
|
|
458
|
-
}
|
|
459
451
|
setCurrentAccount(data, callback) {
|
|
460
452
|
const {
|
|
461
453
|
address,
|
|
@@ -465,7 +457,7 @@ class KoniState {
|
|
|
465
457
|
...data
|
|
466
458
|
};
|
|
467
459
|
if (address === _constants.ALL_ACCOUNT_KEY) {
|
|
468
|
-
const pairs = _uiKeyring.keyring.
|
|
460
|
+
const pairs = _uiKeyring.keyring.getAccounts();
|
|
469
461
|
const pair = pairs[0];
|
|
470
462
|
const pairGenesisHash = pair.meta.genesisHash;
|
|
471
463
|
if (pairs.length > 1 || !pair) {
|
|
@@ -476,10 +468,8 @@ class KoniState {
|
|
|
476
468
|
result.allGenesisHash = pairGenesisHash || undefined;
|
|
477
469
|
}
|
|
478
470
|
}
|
|
479
|
-
this.
|
|
480
|
-
|
|
481
|
-
callback && callback();
|
|
482
|
-
});
|
|
471
|
+
this.keyringService.setCurrentAccount(result);
|
|
472
|
+
callback && callback();
|
|
483
473
|
}
|
|
484
474
|
setAccountTie(address, genesisHash) {
|
|
485
475
|
if (address !== _constants.ALL_ACCOUNT_KEY) {
|
|
@@ -490,12 +480,11 @@ class KoniState {
|
|
|
490
480
|
genesisHash
|
|
491
481
|
});
|
|
492
482
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
});
|
|
483
|
+
const accountInfo = this.keyringService.currentAccount;
|
|
484
|
+
if (address === accountInfo.address) {
|
|
485
|
+
accountInfo.currentGenesisHash = genesisHash || _constants.ALL_GENESIS_HASH;
|
|
486
|
+
this.setCurrentAccount(accountInfo);
|
|
487
|
+
}
|
|
499
488
|
return true;
|
|
500
489
|
}
|
|
501
490
|
async switchEvmNetworkByUrl(shortenUrl, networkKey) {
|
|
@@ -518,9 +507,7 @@ class KoniState {
|
|
|
518
507
|
const {
|
|
519
508
|
address,
|
|
520
509
|
currentGenesisHash
|
|
521
|
-
} =
|
|
522
|
-
this.getCurrentAccount(resolve);
|
|
523
|
-
});
|
|
510
|
+
} = this.keyringService.currentAccount;
|
|
524
511
|
return this.requestService.addConfirmation(id, url, 'switchNetworkRequest', {
|
|
525
512
|
networkKey,
|
|
526
513
|
address: changeAddress
|
|
@@ -638,35 +625,28 @@ class KoniState {
|
|
|
638
625
|
subscribeSettingsSubject() {
|
|
639
626
|
return this.settingService.getSubject();
|
|
640
627
|
}
|
|
641
|
-
subscribeCurrentAccount() {
|
|
642
|
-
return this.currentAccountStore.getSubject();
|
|
643
|
-
}
|
|
644
628
|
getAccountAddress() {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
resolve(null);
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
});
|
|
629
|
+
const address = this.keyringService.currentAccount.address;
|
|
630
|
+
if (address === '') {
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
return address;
|
|
654
634
|
}
|
|
655
|
-
|
|
635
|
+
getDecodedAddresses(address) {
|
|
656
636
|
let checkingAddress = address;
|
|
657
637
|
if (!address) {
|
|
658
|
-
checkingAddress =
|
|
638
|
+
checkingAddress = this.getAccountAddress();
|
|
659
639
|
}
|
|
660
640
|
if (!checkingAddress) {
|
|
661
641
|
return [];
|
|
662
642
|
}
|
|
663
643
|
if (checkingAddress === _constants.ALL_ACCOUNT_KEY) {
|
|
664
|
-
return
|
|
644
|
+
return this.getAllAddresses();
|
|
665
645
|
}
|
|
666
646
|
return [checkingAddress];
|
|
667
647
|
}
|
|
668
648
|
getAllAddresses() {
|
|
669
|
-
return
|
|
649
|
+
return _uiKeyring.keyring.getAccounts().map(account => account.address);
|
|
670
650
|
}
|
|
671
651
|
removeInactiveChainBalances(balanceMap) {
|
|
672
652
|
const activeBalanceMap = {};
|
|
@@ -715,11 +695,11 @@ class KoniState {
|
|
|
715
695
|
};
|
|
716
696
|
this.publishCrowdloan(true);
|
|
717
697
|
}
|
|
718
|
-
|
|
698
|
+
resetStaking(newAddress) {
|
|
719
699
|
this.getStaking().then(data => {
|
|
720
700
|
this.stakingSubject.next(data);
|
|
721
701
|
}).catch(e => this.logger.warn(e));
|
|
722
|
-
const addresses =
|
|
702
|
+
const addresses = this.getDecodedAddresses(newAddress);
|
|
723
703
|
this.dbService.subscribeStaking(addresses, this.activeChainSlugs, stakings => {
|
|
724
704
|
this.stakingSubject.next({
|
|
725
705
|
ready: true,
|
|
@@ -738,9 +718,8 @@ class KoniState {
|
|
|
738
718
|
});
|
|
739
719
|
}
|
|
740
720
|
updateBalanceStore(item) {
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
});
|
|
721
|
+
const currentAccountInfo = this.keyringService.currentAccount;
|
|
722
|
+
this.dbService.updateBalanceStore(currentAccountInfo.address, item).catch(e => this.logger.warn(e));
|
|
744
723
|
}
|
|
745
724
|
subscribeBalance() {
|
|
746
725
|
return this.balanceSubject;
|
|
@@ -769,9 +748,8 @@ class KoniState {
|
|
|
769
748
|
});
|
|
770
749
|
}
|
|
771
750
|
updateCrowdloanStore(networkKey, item) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
});
|
|
751
|
+
const currentAccountInfo = this.keyringService.currentAccount;
|
|
752
|
+
this.dbService.updateCrowdloanStore(networkKey, currentAccountInfo.address, item).catch(e => this.logger.warn(e));
|
|
775
753
|
}
|
|
776
754
|
subscribeCrowdloan() {
|
|
777
755
|
return this.crowdloanSubject;
|
|
@@ -836,12 +814,11 @@ class KoniState {
|
|
|
836
814
|
await this.chainService.updateAssetSetting(tokenSlug, {
|
|
837
815
|
visible: true
|
|
838
816
|
});
|
|
817
|
+
this.eventService.emit('asset.update', tokenSlug);
|
|
839
818
|
}
|
|
840
|
-
this.updateServiceInfo();
|
|
841
819
|
}
|
|
842
820
|
deleteCustomAssets(targetTokens) {
|
|
843
821
|
this.chainService.deleteCustomAssets(targetTokens);
|
|
844
|
-
this.updateServiceInfo();
|
|
845
822
|
}
|
|
846
823
|
async validateCustomChain(provider, existedChainSlug) {
|
|
847
824
|
return await this.chainService.validateCustomChain(provider, existedChainSlug);
|
|
@@ -865,13 +842,10 @@ class KoniState {
|
|
|
865
842
|
visible: true
|
|
866
843
|
});
|
|
867
844
|
}
|
|
868
|
-
this.updateServiceInfo();
|
|
869
845
|
return true;
|
|
870
846
|
}
|
|
871
847
|
removeCustomChain(networkKey) {
|
|
872
|
-
|
|
873
|
-
this.updateServiceInfo();
|
|
874
|
-
return result;
|
|
848
|
+
return this.chainService.removeCustomChain(networkKey);
|
|
875
849
|
}
|
|
876
850
|
|
|
877
851
|
// TODO: avoids turning off chains related to ledger account
|
|
@@ -897,18 +871,14 @@ class KoniState {
|
|
|
897
871
|
async disableChain(chainSlug) {
|
|
898
872
|
// const defaultChains = this.getDefaultNetworkKeys();
|
|
899
873
|
await this.chainService.updateAssetSettingByChain(chainSlug, false);
|
|
900
|
-
|
|
901
|
-
this.updateServiceInfo();
|
|
902
|
-
return result;
|
|
874
|
+
return this.chainService.disableChain(chainSlug);
|
|
903
875
|
}
|
|
904
876
|
async enableChain(chainSlug) {
|
|
905
877
|
let enableTokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
906
878
|
if (enableTokens) {
|
|
907
879
|
await this.chainService.updateAssetSettingByChain(chainSlug, true);
|
|
908
880
|
}
|
|
909
|
-
|
|
910
|
-
this.updateServiceInfo();
|
|
911
|
-
return result;
|
|
881
|
+
return this.chainService.enableChain(chainSlug);
|
|
912
882
|
}
|
|
913
883
|
resetDefaultChains() {
|
|
914
884
|
const defaultChains = this.getDefaultNetworkKeys();
|
|
@@ -949,17 +919,14 @@ class KoniState {
|
|
|
949
919
|
subscribeServiceInfo() {
|
|
950
920
|
return this.serviceInfoSubject;
|
|
951
921
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
this.
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
chainStateMap: this.chainService.getChainStateMap()
|
|
961
|
-
});
|
|
962
|
-
});
|
|
922
|
+
getServiceInfo() {
|
|
923
|
+
return {
|
|
924
|
+
chainInfoMap: this.chainService.getChainInfoMap(),
|
|
925
|
+
chainApiMap: this.getApiMap(),
|
|
926
|
+
currentAccountInfo: this.keyringService.currentAccount,
|
|
927
|
+
assetRegistry: this.chainService.getAssetRegistry(),
|
|
928
|
+
chainStateMap: this.chainService.getChainStateMap()
|
|
929
|
+
};
|
|
963
930
|
}
|
|
964
931
|
getExternalRequestMap() {
|
|
965
932
|
return this.externalRequest;
|
|
@@ -1401,5 +1368,76 @@ class KoniState {
|
|
|
1401
1368
|
createUnsubscriptionHandle(id, unsubscribe) {
|
|
1402
1369
|
this.unsubscriptionMap[id] = unsubscribe;
|
|
1403
1370
|
}
|
|
1371
|
+
async autoEnableChains(addresses) {
|
|
1372
|
+
const assetMap = this.chainService.getAssetRegistry();
|
|
1373
|
+
const promiseList = addresses.map(address => {
|
|
1374
|
+
return this.subscanService.getMultiChainBalance(address).catch(e => {
|
|
1375
|
+
console.error(e);
|
|
1376
|
+
return null;
|
|
1377
|
+
});
|
|
1378
|
+
});
|
|
1379
|
+
const needEnableChains = [];
|
|
1380
|
+
const needActiveTokens = [];
|
|
1381
|
+
const currentAssetSettings = await this.chainService.getAssetSettings();
|
|
1382
|
+
const chainMap = this.chainService.getChainInfoMap();
|
|
1383
|
+
const balanceDataList = await Promise.all(promiseList);
|
|
1384
|
+
balanceDataList.forEach(balanceData => {
|
|
1385
|
+
balanceData && balanceData.forEach(_ref14 => {
|
|
1386
|
+
var _currentAssetSettings;
|
|
1387
|
+
let {
|
|
1388
|
+
balance,
|
|
1389
|
+
bonded,
|
|
1390
|
+
category,
|
|
1391
|
+
locked,
|
|
1392
|
+
network,
|
|
1393
|
+
symbol
|
|
1394
|
+
} = _ref14;
|
|
1395
|
+
const chain = _subscanChainMap.SUBSCAN_CHAIN_MAP_REVERSE[network];
|
|
1396
|
+
const chainInfo = chain ? chainMap[chain] : null;
|
|
1397
|
+
const balanceIsEmpty = (!balance || balance === '0') && !locked && locked === '0' && (!bonded || bonded === '0');
|
|
1398
|
+
|
|
1399
|
+
// Cancel if chain is not supported or is testnet or balance is 0
|
|
1400
|
+
if (!chainInfo || chainInfo.isTestnet || balanceIsEmpty) {
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
const tokenKey = `${chain}-${category === 'native' ? 'NATIVE' : 'LOCAL'}-${symbol.toUpperCase()}`;
|
|
1404
|
+
if (assetMap[tokenKey] && !((_currentAssetSettings = currentAssetSettings[tokenKey]) !== null && _currentAssetSettings !== void 0 && _currentAssetSettings.visible)) {
|
|
1405
|
+
needEnableChains.push(chain);
|
|
1406
|
+
needActiveTokens.push(tokenKey);
|
|
1407
|
+
currentAssetSettings[tokenKey] = {
|
|
1408
|
+
visible: true
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
});
|
|
1413
|
+
if (needActiveTokens.length) {
|
|
1414
|
+
this.chainService.enableChains(needEnableChains);
|
|
1415
|
+
this.chainService.setAssetSettings({
|
|
1416
|
+
...currentAssetSettings
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
onAccountAdd() {
|
|
1421
|
+
this.eventService.on('account.add', address => {
|
|
1422
|
+
this.autoEnableChains([address]).catch(this.logger.error);
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
onAccountRemove() {
|
|
1426
|
+
this.eventService.on('account.remove', address => {
|
|
1427
|
+
// Some separate service like historyService will listen to this event and remove inside that service
|
|
1428
|
+
|
|
1429
|
+
const stores = this.dbService.stores;
|
|
1430
|
+
|
|
1431
|
+
// Remove Balance
|
|
1432
|
+
stores.balance.removeAllByAddress(address).catch(console.error);
|
|
1433
|
+
stores.balance.removeAllByAddress(_constants.ALL_ACCOUNT_KEY).catch(console.error);
|
|
1434
|
+
|
|
1435
|
+
// Remove NFT
|
|
1436
|
+
stores.nft.deleteNftByAddress([address]).catch(console.error);
|
|
1437
|
+
|
|
1438
|
+
// Remove Staking Data
|
|
1439
|
+
stores.staking.removeAllByAddress(address).catch(console.error);
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1404
1442
|
}
|
|
1405
1443
|
exports.default = KoniState;
|
|
@@ -256,32 +256,34 @@ class KoniTabs {
|
|
|
256
256
|
const allAccounts = _accounts.accounts.subject.getValue();
|
|
257
257
|
const accountList = transformAccountsV2(allAccounts, false, authInfo, 'evm').map(a => a.address);
|
|
258
258
|
let accounts = [];
|
|
259
|
-
this.#koniState.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
accounts = [address];
|
|
267
|
-
}
|
|
268
|
-
resolve(accounts);
|
|
269
|
-
});
|
|
259
|
+
const address = this.#koniState.keyringService.currentAccount.address;
|
|
260
|
+
if (address === _constants.ALL_ACCOUNT_KEY || !accountList.includes(address) || getAll) {
|
|
261
|
+
accounts = accountList;
|
|
262
|
+
} else if (address && accountList.includes(address)) {
|
|
263
|
+
accounts = [address];
|
|
264
|
+
}
|
|
265
|
+
resolve(accounts);
|
|
270
266
|
}).catch(console.error);
|
|
271
267
|
});
|
|
272
268
|
}
|
|
273
269
|
async getEvmState(url) {
|
|
274
|
-
let
|
|
270
|
+
let currentChain;
|
|
271
|
+
let autoActiveChain = false;
|
|
275
272
|
if (url) {
|
|
276
273
|
const authInfo = await this.getAuthInfo(url);
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
});
|
|
274
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.currentEvmNetworkKey) {
|
|
275
|
+
currentChain = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentEvmNetworkKey;
|
|
276
|
+
}
|
|
277
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
278
|
+
autoActiveChain = true;
|
|
279
|
+
}
|
|
284
280
|
}
|
|
281
|
+
const currentEvmNetwork = this.#koniState.requestService.getDAppChainInfo({
|
|
282
|
+
autoActive: autoActiveChain,
|
|
283
|
+
accessType: 'evm',
|
|
284
|
+
defaultChain: currentChain,
|
|
285
|
+
url
|
|
286
|
+
});
|
|
285
287
|
if (currentEvmNetwork) {
|
|
286
288
|
const {
|
|
287
289
|
evmInfo,
|
|
@@ -327,10 +329,10 @@ class KoniTabs {
|
|
|
327
329
|
date: new Date().getTime()
|
|
328
330
|
}];
|
|
329
331
|
}
|
|
330
|
-
async switchEvmChain(id, url,
|
|
332
|
+
async switchEvmChain(id, url, _ref12) {
|
|
331
333
|
let {
|
|
332
334
|
params
|
|
333
|
-
} =
|
|
335
|
+
} = _ref12;
|
|
334
336
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
335
337
|
const chainId = params[0].chainId;
|
|
336
338
|
const evmState = await this.getEvmState(url);
|
|
@@ -345,11 +347,11 @@ class KoniTabs {
|
|
|
345
347
|
}
|
|
346
348
|
return null;
|
|
347
349
|
}
|
|
348
|
-
async addEvmToken(id, url,
|
|
350
|
+
async addEvmToken(id, url, _ref13) {
|
|
349
351
|
var _input$type, _input$options, _input$options2;
|
|
350
352
|
let {
|
|
351
353
|
params
|
|
352
|
-
} =
|
|
354
|
+
} = _ref13;
|
|
353
355
|
const input = params;
|
|
354
356
|
const _tokenType = (input === null || input === void 0 ? void 0 : (_input$type = input.type) === null || _input$type === void 0 ? void 0 : _input$type.toLowerCase()) || '';
|
|
355
357
|
if (_tokenType !== 'erc20' && _tokenType !== 'erc721') {
|
|
@@ -384,10 +386,10 @@ class KoniTabs {
|
|
|
384
386
|
};
|
|
385
387
|
return await this.#koniState.addTokenConfirm(id, url, tokenInfo);
|
|
386
388
|
}
|
|
387
|
-
async addEvmChain(id, url,
|
|
389
|
+
async addEvmChain(id, url, _ref14) {
|
|
388
390
|
let {
|
|
389
391
|
params
|
|
390
|
-
} =
|
|
392
|
+
} = _ref14;
|
|
391
393
|
const input = params;
|
|
392
394
|
if (input && input.length > 0) {
|
|
393
395
|
const {
|
|
@@ -481,7 +483,7 @@ class KoniTabs {
|
|
|
481
483
|
currentAccountList = newAccountList;
|
|
482
484
|
}
|
|
483
485
|
};
|
|
484
|
-
const accountListSubscription = this.#koniState.
|
|
486
|
+
const accountListSubscription = this.#koniState.keyringService.currentAccountSubject.subscribe(() => {
|
|
485
487
|
onCurrentAccountChanged().catch(console.error);
|
|
486
488
|
});
|
|
487
489
|
|
|
@@ -531,11 +533,11 @@ class KoniTabs {
|
|
|
531
533
|
const networkCheckInterval = setInterval(networkCheck, _constants.CRON_GET_API_MAP_STATUS);
|
|
532
534
|
const provider = await this.getEvmProvider(url);
|
|
533
535
|
const eventMap = {};
|
|
534
|
-
eventMap.data =
|
|
536
|
+
eventMap.data = _ref15 => {
|
|
535
537
|
let {
|
|
536
538
|
method,
|
|
537
539
|
params
|
|
538
|
-
} =
|
|
540
|
+
} = _ref15;
|
|
539
541
|
emitEvent('message', {
|
|
540
542
|
type: method,
|
|
541
543
|
data: params
|
|
@@ -544,8 +546,8 @@ class KoniTabs {
|
|
|
544
546
|
eventMap.error = rs => {
|
|
545
547
|
emitEvent('error', rs);
|
|
546
548
|
};
|
|
547
|
-
Object.entries(eventMap).forEach(
|
|
548
|
-
let [event, callback] =
|
|
549
|
+
Object.entries(eventMap).forEach(_ref16 => {
|
|
550
|
+
let [event, callback] = _ref16;
|
|
549
551
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
550
552
|
(provider === null || provider === void 0 ? void 0 : provider.on) && (provider === null || provider === void 0 ? void 0 : provider.on(event, callback));
|
|
551
553
|
});
|
|
@@ -559,8 +561,8 @@ class KoniTabs {
|
|
|
559
561
|
if (this.evmEventEmitterMap[url][id]) {
|
|
560
562
|
delete this.evmEventEmitterMap[url][id];
|
|
561
563
|
}
|
|
562
|
-
Object.entries(eventMap).forEach(
|
|
563
|
-
let [event, callback] =
|
|
564
|
+
Object.entries(eventMap).forEach(_ref17 => {
|
|
565
|
+
let [event, callback] = _ref17;
|
|
564
566
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
565
567
|
(provider === null || provider === void 0 ? void 0 : provider.removeListener) && (provider === null || provider === void 0 ? void 0 : provider.removeListener(event, callback));
|
|
566
568
|
});
|
|
@@ -595,11 +597,11 @@ class KoniTabs {
|
|
|
595
597
|
}
|
|
596
598
|
return provider;
|
|
597
599
|
}
|
|
598
|
-
async performWeb3Method(id, url,
|
|
600
|
+
async performWeb3Method(id, url, _ref18, callback) {
|
|
599
601
|
let {
|
|
600
602
|
method,
|
|
601
603
|
params
|
|
602
|
-
} =
|
|
604
|
+
} = _ref18;
|
|
603
605
|
const provider = await this.getEvmProvider(url);
|
|
604
606
|
this.checkAndHandleProviderStatus(provider);
|
|
605
607
|
return new Promise((resolve, reject) => {
|
|
@@ -624,11 +626,11 @@ class KoniTabs {
|
|
|
624
626
|
const allowedAccounts = await this.getEvmCurrentAccount(url, true);
|
|
625
627
|
return !!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase());
|
|
626
628
|
}
|
|
627
|
-
async evmSign(id, url,
|
|
629
|
+
async evmSign(id, url, _ref19) {
|
|
628
630
|
let {
|
|
629
631
|
method,
|
|
630
632
|
params
|
|
631
|
-
} =
|
|
633
|
+
} = _ref19;
|
|
632
634
|
const allowedAccounts = await this.getEvmCurrentAccount(url, true);
|
|
633
635
|
const signResult = await this.#koniState.evmSign(id, url, method, params, allowedAccounts);
|
|
634
636
|
if (signResult) {
|
|
@@ -637,10 +639,10 @@ class KoniTabs {
|
|
|
637
639
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Have something wrong to sign message');
|
|
638
640
|
}
|
|
639
641
|
}
|
|
640
|
-
async evmSendTransaction(id, url,
|
|
642
|
+
async evmSendTransaction(id, url, _ref20) {
|
|
641
643
|
let {
|
|
642
644
|
params
|
|
643
|
-
} =
|
|
645
|
+
} = _ref20;
|
|
644
646
|
const transactionParams = params[0];
|
|
645
647
|
const canUseAccount = transactionParams.from && this.canUseAccount(transactionParams.from, url);
|
|
646
648
|
const evmState = await this.getEvmState(url);
|