@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,6 +15,7 @@ var _handlers = require("@subwallet/extension-base/koni/background/handlers");
|
|
|
15
15
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
16
16
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
17
17
|
var _util = require("@polkadot/util");
|
|
18
|
+
var _utilCrypto = require("@polkadot/util-crypto");
|
|
18
19
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
19
20
|
// SPDX-License-Identifier: Apache-2.0
|
|
20
21
|
|
|
@@ -56,19 +57,22 @@ class KoniSubscription {
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
start() {
|
|
60
|
+
var _this$state$keyringSe;
|
|
59
61
|
this.logger.log('Starting subscription');
|
|
60
|
-
this.state.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
!this.serviceSubscription && (this.serviceSubscription = this.state.subscribeServiceInfo().subscribe({
|
|
70
|
-
next: serviceInfo => {
|
|
62
|
+
const currentAddress = (_this$state$keyringSe = this.state.keyringService.currentAccount) === null || _this$state$keyringSe === void 0 ? void 0 : _this$state$keyringSe.address;
|
|
63
|
+
if (currentAddress) {
|
|
64
|
+
this.subscribeBalancesAndCrowdloans(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
65
|
+
this.subscribeStakingOnChain(currentAddress, this.state.getSubstrateApiMap());
|
|
66
|
+
}
|
|
67
|
+
if (!this.eventHandler) {
|
|
68
|
+
const reloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'chain.update', 'chain.enable', 'asset.update', 'asset.enable', 'transaction.done', 'transaction.failed'];
|
|
69
|
+
this.eventHandler = (events, eventTypes) => {
|
|
71
70
|
var _serviceInfo$currentA;
|
|
71
|
+
const serviceInfo = this.state.getServiceInfo();
|
|
72
|
+
const needReload = eventTypes.some(eT => reloadEvents.includes(eT));
|
|
73
|
+
if (!needReload) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
72
76
|
this.logger.log('ServiceInfo updated, restarting...');
|
|
73
77
|
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
74
78
|
if (!address) {
|
|
@@ -76,14 +80,14 @@ class KoniSubscription {
|
|
|
76
80
|
}
|
|
77
81
|
this.subscribeBalancesAndCrowdloans(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
|
|
78
82
|
this.subscribeStakingOnChain(address, serviceInfo.chainApiMap.substrate);
|
|
79
|
-
}
|
|
80
|
-
|
|
83
|
+
};
|
|
84
|
+
this.state.eventService.onLazy(this.eventHandler);
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
87
|
stop() {
|
|
83
88
|
this.logger.log('Stopping subscription');
|
|
84
|
-
if (this.
|
|
85
|
-
this.
|
|
86
|
-
this.serviceSubscription = undefined;
|
|
89
|
+
if (this.eventHandler) {
|
|
90
|
+
this.state.eventService.offLazy(this.eventHandler);
|
|
87
91
|
}
|
|
88
92
|
this.stopAllSubscription();
|
|
89
93
|
}
|
|
@@ -110,24 +114,21 @@ class KoniSubscription {
|
|
|
110
114
|
}
|
|
111
115
|
subscribeBalancesAndCrowdloans(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
|
|
112
116
|
this.state.switchAccount(address).then(() => {
|
|
113
|
-
this.state.getDecodedAddresses(address)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}).catch(this.logger.error);
|
|
117
|
+
const addresses = this.state.getDecodedAddresses(address);
|
|
118
|
+
if (!addresses.length) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.updateSubscription('balance', this.initBalanceSubscription(addresses, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime));
|
|
122
|
+
this.updateSubscription('crowdloan', this.initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime));
|
|
120
123
|
}).catch(err => this.logger.warn(err));
|
|
121
124
|
}
|
|
122
125
|
subscribeStakingOnChain(address, substrateApiMap, onlyRunOnFirstTime) {
|
|
123
|
-
this.state.resetStaking(address)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}).catch(this.logger.error);
|
|
130
|
-
}).catch(err => this.logger.warn(err));
|
|
126
|
+
this.state.resetStaking(address);
|
|
127
|
+
const addresses = this.state.getDecodedAddresses(address);
|
|
128
|
+
if (!addresses.length) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.updateSubscription('stakingOnChain', this.initStakingOnChainSubscription(addresses, substrateApiMap, onlyRunOnFirstTime));
|
|
131
132
|
}
|
|
132
133
|
initStakingOnChainSubscription(addresses, substrateApiMap, onlyRunOnFirstTime) {
|
|
133
134
|
const unsub = (0, _staking.stakingOnChainApi)(addresses, substrateApiMap, (networkKey, rs) => {
|
|
@@ -143,9 +144,9 @@ class KoniSubscription {
|
|
|
143
144
|
}
|
|
144
145
|
initBalanceSubscription(addresses, chainInfoMap, chainStateMap, substrateApiMap, evmApiMap, onlyRunOnFirstTime) {
|
|
145
146
|
const filteredChainInfoMap = {};
|
|
146
|
-
Object.values(
|
|
147
|
-
if (
|
|
148
|
-
filteredChainInfoMap[
|
|
147
|
+
Object.values(chainStateMap).forEach(chainState => {
|
|
148
|
+
if (chainState.active) {
|
|
149
|
+
filteredChainInfoMap[chainState.slug] = chainInfoMap[chainState.slug];
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
152
|
const unsub = (0, _balance.subscribeBalance)(addresses, filteredChainInfoMap, substrateApiMap, evmApiMap, result => {
|
|
@@ -172,12 +173,11 @@ class KoniSubscription {
|
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
175
|
subscribeNft(address, substrateApiMap, evmApiMap, smartContractNfts, chainInfoMap) {
|
|
175
|
-
this.state.getDecodedAddresses(address)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}).catch(this.logger.error);
|
|
176
|
+
const addresses = this.state.getDecodedAddresses(address);
|
|
177
|
+
if (!addresses.length) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.initNftSubscription(addresses, substrateApiMap, evmApiMap, smartContractNfts, chainInfoMap);
|
|
181
181
|
}
|
|
182
182
|
initNftSubscription(addresses, substrateApiMap, evmApiMap, smartContractNfts, chainInfoMap) {
|
|
183
183
|
var _this = this;
|
|
@@ -194,7 +194,7 @@ class KoniSubscription {
|
|
|
194
194
|
}).catch(this.logger.log);
|
|
195
195
|
}
|
|
196
196
|
async subscribeStakingReward(address) {
|
|
197
|
-
const addresses =
|
|
197
|
+
const addresses = this.state.getDecodedAddresses(address);
|
|
198
198
|
if (!addresses.length) {
|
|
199
199
|
return;
|
|
200
200
|
}
|
|
@@ -212,7 +212,7 @@ class KoniSubscription {
|
|
|
212
212
|
this.logger.log('Set staking reward state done', result);
|
|
213
213
|
}
|
|
214
214
|
async subscribeStakingRewardFastInterval(address) {
|
|
215
|
-
const addresses =
|
|
215
|
+
const addresses = this.state.getDecodedAddresses(address);
|
|
216
216
|
if (!addresses.length) {
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
@@ -262,8 +262,13 @@ class KoniSubscription {
|
|
|
262
262
|
if (currentAddress === _constants.ALL_ACCOUNT_KEY) {
|
|
263
263
|
addresses = await this.state.getStakingOwnersByChains(Object.keys(filteredChainInfoMap));
|
|
264
264
|
}
|
|
265
|
-
|
|
265
|
+
const validAddresses = addresses.filter(address => !(0, _utilCrypto.isEthereumAddress)(address));
|
|
266
|
+
await Promise.all(validAddresses.map(async address => {
|
|
267
|
+
const isEvmAddress = (0, _utilCrypto.isEthereumAddress)(address);
|
|
266
268
|
await Promise.all(Object.values(filteredChainInfoMap).map(async chainInfo => {
|
|
269
|
+
if (isEvmAddress && !(0, _utils._isChainEvmCompatible)(chainInfo)) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
267
272
|
if ((0, _utils._isSubstrateRelayChain)(chainInfo) && _constants2._STAKING_CHAIN_GROUP.nominationPool.includes(chainInfo.slug)) {
|
|
268
273
|
const poolMemberMetadata = await (0, _relayChain.getRelayChainPoolMemberMetadata)(chainInfo, address, substrateApiMap[chainInfo.slug]);
|
|
269
274
|
if (poolMemberMetadata) {
|
package/cjs/packageInfo.js
CHANGED
package/cjs/page/index.js
CHANGED
|
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.enable = enable;
|
|
8
8
|
exports.handleResponse = handleResponse;
|
|
9
|
+
exports.initEvmProvider = initEvmProvider;
|
|
9
10
|
exports.sendMessage = sendMessage;
|
|
10
11
|
var _ProviderError = require("@subwallet/extension-base/background/errors/ProviderError");
|
|
11
12
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
13
|
+
var _SubWalleEvmProvider = require("@subwallet/extension-base/page/SubWalleEvmProvider");
|
|
12
14
|
var _defaults = require("../defaults");
|
|
13
15
|
var _getId = require("../utils/getId");
|
|
14
16
|
var _Injected = _interopRequireDefault(require("./Injected"));
|
|
@@ -62,4 +64,7 @@ function handleResponse(data) {
|
|
|
62
64
|
} else {
|
|
63
65
|
handler.resolve(data.response);
|
|
64
66
|
}
|
|
67
|
+
}
|
|
68
|
+
function initEvmProvider(version) {
|
|
69
|
+
return new _SubWalleEvmProvider.SubWalletEvmProvider(sendMessage, version);
|
|
65
70
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports._XCM_TYPE = exports.
|
|
6
|
+
exports._XCM_TYPE = exports._XCM_CHAIN_GROUP = exports._TRANSFER_NOT_SUPPORTED_CHAINS = exports._TRANSFER_CHAIN_GROUP = exports._SUBSTRATE_DEFAULT_INFLATION_PARAMS = exports._STAKING_ERA_LENGTH_MAP = exports._STAKING_CHAIN_GROUP = exports._PURE_EVM_CHAINS = exports._PREDEFINED_SINGLE_MODES = exports._PARACHAIN_INFLATION_DISTRIBUTION = exports._NFT_CHAIN_GROUP = exports._KNOWN_CHAIN_INFLATION_PARAMS = exports._DEFAULT_ACTIVE_CHAINS = exports._BALANCE_TOKEN_GROUP = exports._BALANCE_PARSING_CHAIN_GROUP = exports._BALANCE_CHAIN_GROUP = exports._API_OPTIONS_CHAIN_GROUP = exports.API_MAX_RETRY = exports.API_AUTO_CONNECT_MS = void 0;
|
|
7
7
|
var _chainList = require("@subwallet/chain-list");
|
|
8
8
|
var _types = require("@subwallet/chain-list/types");
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
@@ -207,18 +207,8 @@ const _XCM_CHAIN_GROUP = {
|
|
|
207
207
|
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint'],
|
|
208
208
|
xcmPallet: ['polkadot', 'kusama']
|
|
209
209
|
// default is xTokens pallet
|
|
210
|
-
// moonbeam: ['moonbeam', 'moonriver', 'moonbase'],
|
|
211
|
-
// astar: ['astar', 'shiden'],
|
|
212
|
-
// statemine: ['statemint', 'statemine'],
|
|
213
|
-
// bifrost: ['bifrost'],
|
|
214
|
-
// genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
|
|
215
|
-
// kintsugi: ['kintsugi', 'kintsugi_test', 'interlay'],
|
|
216
|
-
// acala: ['karura', 'acala', 'acala_testnet'],
|
|
217
|
-
// astarEvm: ['astarEvm', 'shidenEvm']
|
|
218
210
|
};
|
|
219
211
|
exports._XCM_CHAIN_GROUP = _XCM_CHAIN_GROUP;
|
|
220
|
-
const _XCM_CHAIN_USE_LIMITED_WEIGHT = ['acala', 'karura', 'statemint'];
|
|
221
|
-
exports._XCM_CHAIN_USE_LIMITED_WEIGHT = _XCM_CHAIN_USE_LIMITED_WEIGHT;
|
|
222
212
|
const _XCM_TYPE = {
|
|
223
213
|
RP: `${_types._SubstrateChainType.RELAYCHAIN}-${_types._SubstrateChainType.PARACHAIN}`,
|
|
224
214
|
// DMP
|
|
@@ -28,8 +28,6 @@ class ChainService {
|
|
|
28
28
|
assetRegistry: {},
|
|
29
29
|
assetRefMap: {}
|
|
30
30
|
};
|
|
31
|
-
// to save chain, token settings from user
|
|
32
|
-
|
|
33
31
|
lockChainInfoMap = false; // prevent unwanted changes (edit, enable, disable) to chainInfoMap
|
|
34
32
|
|
|
35
33
|
// TODO: consider BehaviorSubject
|
|
@@ -42,8 +40,9 @@ class ChainService {
|
|
|
42
40
|
// Todo: Update to new store indexed DB
|
|
43
41
|
store = new _AssetSetting.default();
|
|
44
42
|
assetSettingSubject = new _rxjs.BehaviorSubject({});
|
|
45
|
-
constructor(dbService) {
|
|
43
|
+
constructor(dbService, eventService) {
|
|
46
44
|
this.dbService = dbService;
|
|
45
|
+
this.eventService = eventService;
|
|
47
46
|
this.substrateChainHandler = new _SubstrateChainHandler.SubstrateChainHandler();
|
|
48
47
|
this.evmChainHandler = new _EvmChainHandler.EvmChainHandler();
|
|
49
48
|
this.chainInfoMapSubject.next(this.dataMap.chainInfoMap);
|
|
@@ -217,9 +216,13 @@ class ChainService {
|
|
|
217
216
|
return this.getAssetRegistry()[slug];
|
|
218
217
|
}
|
|
219
218
|
getFungibleTokensByChain(chainSlug) {
|
|
219
|
+
let checkActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
220
220
|
const result = {};
|
|
221
|
+
const assetSettings = this.assetSettingSubject.value;
|
|
221
222
|
Object.values(this.getAssetRegistry()).forEach(chainAsset => {
|
|
222
|
-
|
|
223
|
+
var _assetSettings$chainA;
|
|
224
|
+
const _filterActive = !checkActive || ((_assetSettings$chainA = assetSettings[chainAsset.slug]) === null || _assetSettings$chainA === void 0 ? void 0 : _assetSettings$chainA.visible);
|
|
225
|
+
if (chainAsset.originChain === chainSlug && (0, _utils._isAssetFungibleToken)(chainAsset) && _filterActive) {
|
|
223
226
|
result[chainAsset.slug] = chainAsset;
|
|
224
227
|
}
|
|
225
228
|
});
|
|
@@ -283,6 +286,7 @@ class ChainService {
|
|
|
283
286
|
this.dbService.removeFromChainStore([slug]).catch(console.error);
|
|
284
287
|
this.updateChainSubscription();
|
|
285
288
|
this.lockChainInfoMap = false;
|
|
289
|
+
this.eventService.emit('chain.remove', slug);
|
|
286
290
|
return true;
|
|
287
291
|
}
|
|
288
292
|
resetChainInfoMap(excludedChains) {
|
|
@@ -316,6 +320,10 @@ class ChainService {
|
|
|
316
320
|
token.slug = `${_types3._CUSTOM_PREFIX}${defaultSlug}`;
|
|
317
321
|
}
|
|
318
322
|
}
|
|
323
|
+
if (token.originChain && (0, _utils._isAssetFungibleToken)(token)) {
|
|
324
|
+
var _this$getChainInfoByK;
|
|
325
|
+
token.hasValue = !((_this$getChainInfoByK = this.getChainInfoByKey(token.originChain)) !== null && _this$getChainInfoByK !== void 0 && _this$getChainInfoByK.isTestnet);
|
|
326
|
+
}
|
|
319
327
|
const assetRegistry = this.getAssetRegistry();
|
|
320
328
|
assetRegistry[token.slug] = token;
|
|
321
329
|
this.dbService.updateAssetStore(token).catch(e => this.logger.error(e));
|
|
@@ -343,6 +351,9 @@ class ChainService {
|
|
|
343
351
|
this.dbService.removeFromBalanceStore(targetAssets).catch(e => this.logger.error(e));
|
|
344
352
|
this.dbService.removeFromAssetStore(targetAssets).catch(e => this.logger.error(e));
|
|
345
353
|
this.assetRegistrySubject.next(assetRegistry);
|
|
354
|
+
targetAssets.forEach(assetSlug => {
|
|
355
|
+
this.eventService.emit('asset.remove', assetSlug);
|
|
356
|
+
});
|
|
346
357
|
}
|
|
347
358
|
|
|
348
359
|
// Business logic
|
|
@@ -415,6 +426,7 @@ class ChainService {
|
|
|
415
426
|
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
416
427
|
}).catch(console.error);
|
|
417
428
|
this.lockChainInfoMap = false;
|
|
429
|
+
this.eventService.emit('chain.enable', chainSlug);
|
|
418
430
|
return true;
|
|
419
431
|
}
|
|
420
432
|
enableChain(chainSlug) {
|
|
@@ -449,6 +461,7 @@ class ChainService {
|
|
|
449
461
|
}).catch(console.error);
|
|
450
462
|
this.updateChainStateMapSubscription();
|
|
451
463
|
this.lockChainInfoMap = false;
|
|
464
|
+
this.eventService.emit('chain.disable', chainSlug);
|
|
452
465
|
return true;
|
|
453
466
|
}
|
|
454
467
|
checkExistedPredefinedChain(genesisHash, evmChainId) {
|
|
@@ -671,6 +684,8 @@ class ChainService {
|
|
|
671
684
|
...targetChainInfo,
|
|
672
685
|
active: targetChainState.active,
|
|
673
686
|
currentProvider: targetChainState.currentProvider
|
|
687
|
+
}).then(() => {
|
|
688
|
+
this.eventService.emit('chain.update', chainSlug);
|
|
674
689
|
}).catch(e => this.logger.error(e));
|
|
675
690
|
}
|
|
676
691
|
insertChain(params) {
|
|
@@ -755,6 +770,8 @@ class ChainService {
|
|
|
755
770
|
active: true,
|
|
756
771
|
currentProvider: params.chainEditInfo.currentProvider,
|
|
757
772
|
...chainInfo
|
|
773
|
+
}).then(() => {
|
|
774
|
+
this.eventService.emit('chain.add', newChainSlug);
|
|
758
775
|
}).catch(e => this.logger.error(e));
|
|
759
776
|
return nativeTokenSlug;
|
|
760
777
|
}
|
|
@@ -1100,12 +1117,26 @@ class ChainService {
|
|
|
1100
1117
|
};
|
|
1101
1118
|
}
|
|
1102
1119
|
});
|
|
1103
|
-
this.setAssetSettings(assetSettings);
|
|
1120
|
+
this.setAssetSettings(assetSettings, false);
|
|
1104
1121
|
}
|
|
1122
|
+
this.eventService.emit('asset.ready', true);
|
|
1105
1123
|
console.log('Done init asset settings');
|
|
1106
1124
|
}
|
|
1107
1125
|
setAssetSettings(assetSettings) {
|
|
1126
|
+
let emitEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1127
|
+
const updateAssets = [];
|
|
1128
|
+
if (emitEvent) {
|
|
1129
|
+
Object.keys(assetSettings).forEach(slug => {
|
|
1130
|
+
var _this$assetSettingSub;
|
|
1131
|
+
if (((_this$assetSettingSub = this.assetSettingSubject.value[slug]) === null || _this$assetSettingSub === void 0 ? void 0 : _this$assetSettingSub.visible) !== assetSettings[slug].visible) {
|
|
1132
|
+
updateAssets.push(slug);
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1108
1136
|
this.assetSettingSubject.next(assetSettings);
|
|
1137
|
+
updateAssets.forEach(slug => {
|
|
1138
|
+
this.eventService.emit(assetSettings[slug].visible ? 'asset.enable' : 'asset.disable', slug);
|
|
1139
|
+
});
|
|
1109
1140
|
this.store.set('AssetSetting', assetSettings);
|
|
1110
1141
|
}
|
|
1111
1142
|
async getStoreAssetSettings() {
|
|
@@ -1122,6 +1153,7 @@ class ChainService {
|
|
|
1122
1153
|
}
|
|
1123
1154
|
async updateAssetSetting(assetSlug, assetSetting) {
|
|
1124
1155
|
const currentAssetSettings = await this.getAssetSettings();
|
|
1156
|
+
let needUpdateSubject;
|
|
1125
1157
|
|
|
1126
1158
|
// Update settings
|
|
1127
1159
|
currentAssetSettings[assetSlug] = assetSetting;
|
|
@@ -1133,8 +1165,10 @@ class ChainService {
|
|
|
1133
1165
|
// if chain not enabled, then automatically enable
|
|
1134
1166
|
if (chainState && !chainState.active) {
|
|
1135
1167
|
this.enableChain(chainState.slug);
|
|
1168
|
+
needUpdateSubject = true;
|
|
1136
1169
|
}
|
|
1137
1170
|
}
|
|
1171
|
+
return needUpdateSubject;
|
|
1138
1172
|
}
|
|
1139
1173
|
async updateAssetSettingByChain(chainSlug, visible) {
|
|
1140
1174
|
const storedAssetSettings = await this.getAssetSettings();
|
|
@@ -50,6 +50,7 @@ exports._isCustomChain = _isCustomChain;
|
|
|
50
50
|
exports._isCustomProvider = _isCustomProvider;
|
|
51
51
|
exports._isEqualContractAddress = _isEqualContractAddress;
|
|
52
52
|
exports._isEqualSmartContractAsset = _isEqualSmartContractAsset;
|
|
53
|
+
exports._isLocalToken = _isLocalToken;
|
|
53
54
|
exports._isNativeToken = _isNativeToken;
|
|
54
55
|
exports._isNativeTokenBySlug = _isNativeTokenBySlug;
|
|
55
56
|
exports._isPureEvmChain = _isPureEvmChain;
|
|
@@ -272,6 +273,9 @@ function _getChainNativeTokenSlug(chainInfo) {
|
|
|
272
273
|
}
|
|
273
274
|
return `${chainInfo.slug}-${_types._AssetType.NATIVE}-${_getChainNativeTokenBasicInfo(chainInfo).symbol}`;
|
|
274
275
|
}
|
|
276
|
+
function _isLocalToken(tokenInfo) {
|
|
277
|
+
return tokenInfo.assetType === _types._AssetType.LOCAL;
|
|
278
|
+
}
|
|
275
279
|
function _isTokenEvmSmartContract(tokenInfo) {
|
|
276
280
|
return [_types._AssetType.ERC721, _types._AssetType.ERC20].includes(tokenInfo.assetType);
|
|
277
281
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.EventService = void 0;
|
|
8
|
+
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
// Stateless service handle runtime event on background
|
|
13
|
+
|
|
14
|
+
class EventService extends _eventemitter.default {
|
|
15
|
+
pendingEvents = [];
|
|
16
|
+
lazyEmitter = new _eventemitter.default();
|
|
17
|
+
constructor() {
|
|
18
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
19
|
+
lazyTime: 300
|
|
20
|
+
};
|
|
21
|
+
super();
|
|
22
|
+
this.lazyTime = options.lazyTime;
|
|
23
|
+
this.timeoutId = null;
|
|
24
|
+
this.waitKeyringReady = this.generateWaitPromise('keyring.ready');
|
|
25
|
+
this.waitAccountReady = this.generateWaitPromise('account.ready');
|
|
26
|
+
this.waitChainReady = this.generateWaitPromise('chain.ready');
|
|
27
|
+
this.waitAssetReady = this.generateWaitPromise('asset.ready');
|
|
28
|
+
}
|
|
29
|
+
generateWaitPromise(eventType) {
|
|
30
|
+
return new Promise(resolve => {
|
|
31
|
+
this.once(eventType, isReady => {
|
|
32
|
+
resolve(isReady);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
setLazyTimeout() {
|
|
37
|
+
if (this.timeoutId) {
|
|
38
|
+
clearTimeout(this.timeoutId);
|
|
39
|
+
}
|
|
40
|
+
this.timeoutId = setTimeout(() => {
|
|
41
|
+
this.emitLazy();
|
|
42
|
+
}, this.lazyTime);
|
|
43
|
+
}
|
|
44
|
+
emitLazy() {
|
|
45
|
+
this.lazyEmitter.emit('lazy', this.pendingEvents, this.pendingEvents.map(e => e.type));
|
|
46
|
+
this.pendingEvents = [];
|
|
47
|
+
this.timeoutId = null;
|
|
48
|
+
}
|
|
49
|
+
onLazy(callback) {
|
|
50
|
+
this.lazyEmitter.on('lazy', callback);
|
|
51
|
+
}
|
|
52
|
+
offLazy(callback) {
|
|
53
|
+
this.lazyEmitter.off('lazy', callback);
|
|
54
|
+
}
|
|
55
|
+
onceLazy(callback) {
|
|
56
|
+
this.lazyEmitter.once('lazy', callback);
|
|
57
|
+
}
|
|
58
|
+
emit(eventType) {
|
|
59
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
60
|
+
args[_key - 1] = arguments[_key];
|
|
61
|
+
}
|
|
62
|
+
console.debug('Emit event: ', eventType, ...args);
|
|
63
|
+
this.pendingEvents.push({
|
|
64
|
+
type: eventType,
|
|
65
|
+
data: args
|
|
66
|
+
});
|
|
67
|
+
this.setLazyTimeout();
|
|
68
|
+
return super.emit(eventType, ...args);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.EventService = EventService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.HistoryService = void 0;
|
|
7
7
|
var _constants = require("@subwallet/extension-base/constants");
|
|
8
|
+
var _address = require("@subwallet/extension-base/utils/address");
|
|
9
|
+
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
8
10
|
var _accounts = require("@subwallet/ui-keyring/observable/accounts");
|
|
9
11
|
var _rxjs = require("rxjs");
|
|
10
12
|
var _subsquidMultiChainHistory = require("./subsquid-multi-chain-history");
|
|
@@ -13,20 +15,25 @@ var _subsquidMultiChainHistory = require("./subsquid-multi-chain-history");
|
|
|
13
15
|
|
|
14
16
|
class HistoryService {
|
|
15
17
|
historySubject = new _rxjs.BehaviorSubject([]);
|
|
16
|
-
constructor(dbService, chainService) {
|
|
18
|
+
constructor(dbService, chainService, eventService) {
|
|
17
19
|
this.dbService = dbService;
|
|
18
20
|
this.chainService = chainService;
|
|
19
|
-
|
|
21
|
+
this.eventService = eventService;
|
|
20
22
|
// Load history from database
|
|
21
23
|
this.dbService.getHistories().then(histories => {
|
|
22
24
|
this.historySubject.next(histories);
|
|
23
25
|
}).catch(console.error);
|
|
24
26
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
// Wait for keyring and chain ready and start
|
|
28
|
+
Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
|
|
29
|
+
this.getHistories().catch(console.log);
|
|
30
|
+
this.eventService.on('account.add', () => {
|
|
31
|
+
this.refreshHistoryInterval();
|
|
32
|
+
});
|
|
33
|
+
this.eventService.on('account.remove', address => {
|
|
34
|
+
this.removeHistoryByAddress(address).catch(console.error);
|
|
35
|
+
});
|
|
36
|
+
}).catch(console.error);
|
|
30
37
|
}
|
|
31
38
|
fetchPromise = null;
|
|
32
39
|
nextFetch = undefined;
|
|
@@ -50,8 +57,8 @@ class HistoryService {
|
|
|
50
57
|
record.fromName = accountMap[(_record$from = record.from) === null || _record$from === void 0 ? void 0 : _record$from.toLowerCase()];
|
|
51
58
|
record.toName = accountMap[(_record$to = record.to) === null || _record$to === void 0 ? void 0 : _record$to.toLowerCase()];
|
|
52
59
|
});
|
|
53
|
-
|
|
54
|
-
return
|
|
60
|
+
this.dbService.upsertHistory(historyRecords).catch(console.error);
|
|
61
|
+
return historyRecords;
|
|
55
62
|
}
|
|
56
63
|
async fetchHistories(addresses) {
|
|
57
64
|
if (!this.fetchPromise) {
|
|
@@ -67,11 +74,14 @@ class HistoryService {
|
|
|
67
74
|
clearTimeout(this.nextFetch);
|
|
68
75
|
this.invalidCache();
|
|
69
76
|
this.getHistories().catch(console.error);
|
|
70
|
-
this.nextFetch = setTimeout(
|
|
77
|
+
this.nextFetch = setTimeout(() => {
|
|
78
|
+
this.refreshHistoryInterval();
|
|
79
|
+
}, _constants.CRON_REFRESH_HISTORY_INTERVAL);
|
|
71
80
|
}
|
|
72
81
|
async getHistories() {
|
|
73
|
-
const addressList =
|
|
74
|
-
|
|
82
|
+
const addressList = _uiKeyring.keyring.getAccounts().map(a => a.address);
|
|
83
|
+
const currentHistories = this.historySubject.value;
|
|
84
|
+
if (!this.fetchPromise || currentHistories.length === 0) {
|
|
75
85
|
const historyRecords = await this.fetchHistories(addressList);
|
|
76
86
|
this.historySubject.next(historyRecords);
|
|
77
87
|
}
|
|
@@ -81,11 +91,11 @@ class HistoryService {
|
|
|
81
91
|
await this.getHistories();
|
|
82
92
|
return this.historySubject;
|
|
83
93
|
}
|
|
84
|
-
async
|
|
85
|
-
await this.dbService.upsertHistory(
|
|
94
|
+
async insertHistories(historyItems) {
|
|
95
|
+
await this.dbService.upsertHistory(historyItems);
|
|
86
96
|
this.historySubject.next(await this.dbService.getHistories());
|
|
87
97
|
}
|
|
88
|
-
async
|
|
98
|
+
async updateHistories(chain, extrinsicHash, updateData) {
|
|
89
99
|
const existedRecords = await this.dbService.getHistories({
|
|
90
100
|
chain,
|
|
91
101
|
extrinsicHash
|
|
@@ -93,13 +103,22 @@ class HistoryService {
|
|
|
93
103
|
const updatedRecords = existedRecords.map(r => {
|
|
94
104
|
return {
|
|
95
105
|
...r,
|
|
96
|
-
...
|
|
106
|
+
...updateData
|
|
97
107
|
};
|
|
98
108
|
});
|
|
99
109
|
await this.addHistoryItems(updatedRecords);
|
|
100
110
|
}
|
|
101
111
|
async addHistoryItems(historyItems) {
|
|
102
|
-
|
|
112
|
+
// Prevent override record with original is 'app'
|
|
113
|
+
const appRecords = this.historySubject.value.filter(item => item.origin === 'app');
|
|
114
|
+
const excludeKeys = appRecords.map(item => {
|
|
115
|
+
return `${item.chain}-${(0, _address.quickFormatAddressToCompare)(item.address) || ''}-${item.extrinsicHash}`;
|
|
116
|
+
});
|
|
117
|
+
const updateRecords = historyItems.filter(item => {
|
|
118
|
+
const key = `${item.chain}-${(0, _address.quickFormatAddressToCompare)(item.address) || ''}-${item.extrinsicHash}`;
|
|
119
|
+
return item.origin === 'app' || !excludeKeys.includes(key);
|
|
120
|
+
});
|
|
121
|
+
await this.dbService.upsertHistory(updateRecords);
|
|
103
122
|
this.historySubject.next(await this.dbService.getHistories());
|
|
104
123
|
}
|
|
105
124
|
async removeHistoryByAddress(address) {
|
|
@@ -119,10 +119,15 @@ function parseSubsquidTransactionData(address, type, historyItem, chainInfo, arg
|
|
|
119
119
|
to = autoFormatAddress(parsedArgs.to);
|
|
120
120
|
from = autoFormatAddress(parsedArgs.from);
|
|
121
121
|
extrinsicHash = parsedArgs.transactionHash;
|
|
122
|
-
amount = transaction.value;
|
|
122
|
+
amount = transaction.value || '0';
|
|
123
123
|
fee = (parseInt(transaction.gasPrice) * parseInt(transaction.gasLimit)).toString();
|
|
124
124
|
signature = generateSignature(transaction.signature);
|
|
125
125
|
success = extrinsic.success;
|
|
126
|
+
|
|
127
|
+
// Special fix for moonbeam
|
|
128
|
+
if ((historyItem.chainId === 'moonbeam' || historyItem.chainId === 'moonriver') && typeof amount === 'object') {
|
|
129
|
+
amount = amount[0];
|
|
130
|
+
}
|
|
126
131
|
break;
|
|
127
132
|
}
|
|
128
133
|
|
|
@@ -167,7 +172,7 @@ function parseSubsquidTransactionData(address, type, historyItem, chainInfo, arg
|
|
|
167
172
|
}
|
|
168
173
|
return {
|
|
169
174
|
address,
|
|
170
|
-
origin:
|
|
175
|
+
origin: 'subsquid',
|
|
171
176
|
time: toTimestamp(historyItem.timestamp),
|
|
172
177
|
chainType,
|
|
173
178
|
from,
|