@subwallet/extension-base 1.0.4-1 → 1.0.5-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 +12 -1
- package/background/KoniTypes.js +1 -0
- package/background/errors/TransactionError.js +4 -0
- package/background/handlers/State.d.ts +1 -1
- package/background/handlers/State.js +2 -8
- package/background/handlers/subscriptions.js +0 -1
- package/background/types.d.ts +2 -2
- package/cjs/background/KoniTypes.js +1 -0
- package/cjs/background/errors/TransactionError.js +4 -0
- package/cjs/background/handlers/State.js +1 -7
- package/cjs/background/handlers/subscriptions.js +0 -1
- package/cjs/constants/index.js +6 -6
- package/cjs/koni/api/coingecko.js +1 -4
- package/cjs/koni/api/dotsama/balance.js +7 -5
- package/cjs/koni/api/dotsama/crowdloan.js +0 -4
- package/cjs/koni/api/dotsama/transfer.js +0 -4
- package/cjs/koni/api/nft/acala_nft/index.js +1 -1
- package/cjs/koni/api/nft/bit.country/index.js +1 -1
- package/cjs/koni/api/nft/evm_nft/index.js +2 -3
- package/cjs/koni/api/nft/index.js +1 -2
- package/cjs/koni/api/nft/karura_nft/index.js +1 -1
- package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
- package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
- package/cjs/koni/api/nft/transfer.js +5 -5
- package/cjs/koni/api/nft/unique_nft/index.js +1 -1
- package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
- package/cjs/koni/api/staking/bonding/astar.js +28 -12
- package/cjs/koni/api/staking/bonding/utils.js +4 -0
- package/cjs/koni/api/staking/relayChain.js +0 -1
- package/cjs/koni/api/staking/subsquidStaking.js +0 -2
- package/cjs/koni/api/tokens/wasm/index.js +0 -1
- package/cjs/koni/api/tokens/wasm/utils.js +0 -1
- package/cjs/koni/api/xcm/index.js +0 -1
- package/cjs/koni/background/cron.js +0 -45
- package/cjs/koni/background/handlers/Extension.js +163 -133
- package/cjs/koni/background/handlers/State.js +18 -3
- package/cjs/koni/background/handlers/Tabs.js +34 -2
- package/cjs/koni/background/handlers/index.js +3 -2
- package/cjs/koni/background/subscription.js +0 -26
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +2 -9
- package/cjs/services/chain-service/handler/light-client/index.js +9 -6
- package/cjs/services/chain-service/index.js +0 -2
- package/cjs/services/chain-service/utils.js +3 -0
- package/cjs/services/history-service/helpers/recoverHistoryStatus.js +108 -0
- package/cjs/services/history-service/index.js +60 -5
- package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
- package/cjs/services/history-service/testChainMap.js +724 -0
- package/cjs/services/keyring-service/index.js +0 -2
- package/cjs/services/migration-service/index.js +0 -3
- package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
- package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
- package/cjs/services/migration-service/scripts/index.js +5 -1
- package/cjs/services/price-service/coingecko.js +1 -1
- package/cjs/services/price-service/index.js +0 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +1 -1
- package/cjs/services/setting-service/constants.js +8 -2
- package/cjs/services/storage-service/DatabaseService.js +2 -44
- package/cjs/services/transaction-service/constants.js +11 -0
- package/cjs/services/transaction-service/index.js +28 -9
- package/cjs/services/transaction-service/utils.js +25 -14
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/koni/api/coingecko.js +1 -4
- package/koni/api/dotsama/balance.js +7 -5
- package/koni/api/dotsama/crowdloan.js +0 -4
- package/koni/api/dotsama/transfer.js +0 -4
- package/koni/api/nft/acala_nft/index.js +1 -1
- package/koni/api/nft/bit.country/index.js +1 -1
- package/koni/api/nft/evm_nft/index.js +2 -3
- package/koni/api/nft/index.js +1 -2
- package/koni/api/nft/karura_nft/index.js +1 -1
- package/koni/api/nft/quartz_nft/index.js +1 -1
- package/koni/api/nft/rmrk_nft/index.js +2 -3
- package/koni/api/nft/statemine_nft/index.js +1 -1
- package/koni/api/nft/transfer.js +5 -5
- package/koni/api/nft/unique_nft/index.js +1 -1
- package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
- package/koni/api/nft/wasm_nft/index.js +1 -2
- package/koni/api/staking/bonding/astar.d.ts +2 -1
- package/koni/api/staking/bonding/astar.js +27 -12
- package/koni/api/staking/bonding/utils.js +4 -0
- package/koni/api/staking/relayChain.js +0 -1
- package/koni/api/staking/subsquidStaking.js +0 -2
- package/koni/api/tokens/wasm/index.js +0 -1
- package/koni/api/tokens/wasm/utils.js +0 -1
- package/koni/api/xcm/index.js +0 -1
- package/koni/background/cron.js +0 -45
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +78 -50
- package/koni/background/handlers/State.d.ts +3 -1
- package/koni/background/handlers/State.js +18 -3
- package/koni/background/handlers/Tabs.d.ts +1 -0
- package/koni/background/handlers/Tabs.js +32 -1
- package/koni/background/handlers/index.js +3 -2
- package/koni/background/subscription.d.ts +0 -1
- package/koni/background/subscription.js +0 -26
- package/package.json +55 -34
- package/packageInfo.js +1 -1
- package/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +2 -9
- package/services/chain-service/handler/light-client/index.js +8 -6
- package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
- package/services/chain-service/index.js +0 -2
- package/services/chain-service/utils.js +3 -0
- package/services/history-service/helpers/recoverHistoryStatus.d.ts +11 -0
- package/services/history-service/helpers/recoverHistoryStatus.js +98 -0
- package/services/history-service/index.d.ts +6 -0
- package/services/history-service/index.js +61 -6
- package/services/history-service/subsquid-multi-chain-history.js +3 -2
- package/services/history-service/testChainMap.d.ts +3 -0
- package/services/history-service/testChainMap.js +716 -0
- package/services/keyring-service/index.js +0 -2
- package/services/migration-service/index.js +0 -3
- package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
- package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
- package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
- package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
- package/services/migration-service/scripts/index.js +5 -1
- package/services/price-service/coingecko.js +1 -1
- package/services/price-service/index.js +0 -3
- package/services/request-service/handler/AuthRequestHandler.js +1 -1
- package/services/setting-service/constants.d.ts +4 -2
- package/services/setting-service/constants.js +5 -1
- package/services/storage-service/DatabaseService.js +2 -44
- package/services/transaction-service/constants.d.ts +1 -0
- package/services/transaction-service/constants.js +4 -0
- package/services/transaction-service/index.d.ts +1 -0
- package/services/transaction-service/index.js +29 -10
- package/services/transaction-service/utils.d.ts +1 -1
- package/services/transaction-service/utils.js +24 -13
|
@@ -208,7 +208,6 @@ class KoniState {
|
|
|
208
208
|
this.onReady();
|
|
209
209
|
this.onAccountAdd();
|
|
210
210
|
this.onAccountRemove();
|
|
211
|
-
this.logger.log('Done init state');
|
|
212
211
|
}
|
|
213
212
|
startSubscription() {
|
|
214
213
|
this.dbService.subscribeChainStakingMetadata([], data => {
|
|
@@ -224,7 +223,6 @@ class KoniState {
|
|
|
224
223
|
this.historyService.start().catch(console.error);
|
|
225
224
|
this.priceService.start().catch(console.error);
|
|
226
225
|
this.ready = true;
|
|
227
|
-
this.logger.log('State is ready');
|
|
228
226
|
}
|
|
229
227
|
isReady() {
|
|
230
228
|
return this.ready;
|
|
@@ -623,7 +621,24 @@ class KoniState {
|
|
|
623
621
|
...settings,
|
|
624
622
|
camera: value
|
|
625
623
|
};
|
|
626
|
-
|
|
624
|
+
this.settingService.setSettings(newSettings);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
setAutoLockTime(value) {
|
|
628
|
+
this.settingService.getSettings(settings => {
|
|
629
|
+
const newSettings = {
|
|
630
|
+
...settings,
|
|
631
|
+
timeAutoLock: value
|
|
632
|
+
};
|
|
633
|
+
this.settingService.setSettings(newSettings);
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
setEnableChainPatrol(value) {
|
|
637
|
+
this.settingService.getSettings(settings => {
|
|
638
|
+
const newSettings = {
|
|
639
|
+
...settings,
|
|
640
|
+
enableChainPatrol: value
|
|
641
|
+
};
|
|
627
642
|
this.settingService.setSettings(newSettings);
|
|
628
643
|
});
|
|
629
644
|
}
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.default = void 0;
|
|
7
|
+
exports.default = exports.chainPatrolCheckUrl = void 0;
|
|
8
8
|
var _types = require("@subwallet/chain-list/types");
|
|
9
9
|
var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
|
|
10
10
|
var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
|
|
@@ -15,6 +15,7 @@ var _RequestExtrinsicSign = _interopRequireDefault(require("@subwallet/extension
|
|
|
15
15
|
var _constants = require("@subwallet/extension-base/constants");
|
|
16
16
|
var _defaults = require("@subwallet/extension-base/defaults");
|
|
17
17
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
18
|
+
var _constants2 = require("@subwallet/extension-base/services/setting-service/constants");
|
|
18
19
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
19
20
|
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
20
21
|
var _web = _interopRequireDefault(require("web3"));
|
|
@@ -94,11 +95,36 @@ function transformAccountsV2(accounts) {
|
|
|
94
95
|
};
|
|
95
96
|
});
|
|
96
97
|
}
|
|
98
|
+
// check if a URL is blocked
|
|
99
|
+
const chainPatrolCheckUrl = async url => {
|
|
100
|
+
const response = await fetch('https://app.chainpatrol.io/api/v2/asset/check', {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/json',
|
|
104
|
+
'X-API-KEY': 'e5e88cd0-7994-4667-9071-bab849c2ba71'
|
|
105
|
+
},
|
|
106
|
+
body: JSON.stringify({
|
|
107
|
+
type: 'URL',
|
|
108
|
+
content: url
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
const data = await response.json();
|
|
112
|
+
return data.status === 'BLOCKED';
|
|
113
|
+
};
|
|
114
|
+
exports.chainPatrolCheckUrl = chainPatrolCheckUrl;
|
|
97
115
|
class KoniTabs {
|
|
98
116
|
#koniState;
|
|
99
117
|
evmEventEmitterMap = {};
|
|
118
|
+
#chainPatrolService = _constants2.DEFAULT_CHAIN_PATROL_ENABLE;
|
|
100
119
|
constructor(koniState) {
|
|
101
120
|
this.#koniState = koniState;
|
|
121
|
+
const updateChainPatrolService = rs => {
|
|
122
|
+
this.#chainPatrolService = rs.enableChainPatrol;
|
|
123
|
+
};
|
|
124
|
+
this.#koniState.settingService.getSettings(updateChainPatrolService);
|
|
125
|
+
this.#koniState.settingService.getSubject().subscribe({
|
|
126
|
+
next: updateChainPatrolService
|
|
127
|
+
});
|
|
102
128
|
}
|
|
103
129
|
|
|
104
130
|
/// Clone from Polkadot.js
|
|
@@ -197,6 +223,13 @@ class KoniTabs {
|
|
|
197
223
|
this.redirectPhishingLanding(url);
|
|
198
224
|
return true;
|
|
199
225
|
}
|
|
226
|
+
if (this.#chainPatrolService) {
|
|
227
|
+
const isInChainPatrolDenyList = await chainPatrolCheckUrl(url);
|
|
228
|
+
if (isInChainPatrolDenyList) {
|
|
229
|
+
this.redirectPhishingLanding(url);
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
200
233
|
return false;
|
|
201
234
|
}
|
|
202
235
|
|
|
@@ -698,7 +731,6 @@ class KoniTabs {
|
|
|
698
731
|
const {
|
|
699
732
|
method
|
|
700
733
|
} = request;
|
|
701
|
-
console.log('method: ' + method);
|
|
702
734
|
try {
|
|
703
735
|
switch (method) {
|
|
704
736
|
case 'eth_chainId':
|
|
@@ -60,11 +60,12 @@ function handlers(_ref, port) {
|
|
|
60
60
|
const sender = port.sender;
|
|
61
61
|
const from = isExtension ? 'extension' : sender.tab && sender.tab.url || sender.url || '<unknown>';
|
|
62
62
|
const source = `${from}: ${id}: ${message}`;
|
|
63
|
-
|
|
63
|
+
|
|
64
|
+
// console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
|
|
64
65
|
|
|
65
66
|
const promise = isMobile ? mobile.handle(id, message, request, port) : isExtension ? extension.handle(id, message, request, port) : tabs.handle(id, message, request, from, port);
|
|
66
67
|
promise.then(response => {
|
|
67
|
-
console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
|
|
68
|
+
// console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
|
|
68
69
|
|
|
69
70
|
// between the start and the end of the promise, the user may have closed
|
|
70
71
|
// the tab, in which case port will be undefined
|
|
@@ -32,7 +32,6 @@ class KoniSubscription {
|
|
|
32
32
|
this.dbService = dbService;
|
|
33
33
|
this.state = state;
|
|
34
34
|
this.logger = (0, _util.logger)('Subscription');
|
|
35
|
-
this.init();
|
|
36
35
|
}
|
|
37
36
|
getSubscriptionMap() {
|
|
38
37
|
return this.subscriptionMap;
|
|
@@ -61,7 +60,6 @@ class KoniSubscription {
|
|
|
61
60
|
}
|
|
62
61
|
start() {
|
|
63
62
|
var _this$state$keyringSe;
|
|
64
|
-
this.logger.log('Starting subscription');
|
|
65
63
|
const currentAddress = (_this$state$keyringSe = this.state.keyringService.currentAccount) === null || _this$state$keyringSe === void 0 ? void 0 : _this$state$keyringSe.address;
|
|
66
64
|
if (currentAddress) {
|
|
67
65
|
this.subscribeBalancesAndCrowdloans(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
@@ -74,7 +72,6 @@ class KoniSubscription {
|
|
|
74
72
|
if (!needReload) {
|
|
75
73
|
return;
|
|
76
74
|
}
|
|
77
|
-
this.logger.log('ServiceInfo updated, restarting...');
|
|
78
75
|
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
79
76
|
if (!address) {
|
|
80
77
|
return;
|
|
@@ -85,34 +82,12 @@ class KoniSubscription {
|
|
|
85
82
|
this.state.eventService.onLazy(this.eventHandler);
|
|
86
83
|
}
|
|
87
84
|
stop() {
|
|
88
|
-
this.logger.log('Stopping subscription');
|
|
89
85
|
if (this.eventHandler) {
|
|
90
86
|
this.state.eventService.offLazy(this.eventHandler);
|
|
91
87
|
this.eventHandler = undefined;
|
|
92
88
|
}
|
|
93
89
|
this.stopAllSubscription();
|
|
94
90
|
}
|
|
95
|
-
init() {
|
|
96
|
-
this.state.getAuthorize(value => {
|
|
97
|
-
const authString = localStorage.getItem('authUrls') || '{}';
|
|
98
|
-
const previousAuth = JSON.parse(authString);
|
|
99
|
-
if (previousAuth && Object.keys(previousAuth).length) {
|
|
100
|
-
Object.keys(previousAuth).forEach(url => {
|
|
101
|
-
if (previousAuth[url].isAllowed) {
|
|
102
|
-
previousAuth[url].isAllowedMap = this.state.getAddressList(true);
|
|
103
|
-
} else {
|
|
104
|
-
previousAuth[url].isAllowedMap = this.state.getAddressList();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
const migrateValue = {
|
|
109
|
-
...previousAuth,
|
|
110
|
-
...value
|
|
111
|
-
};
|
|
112
|
-
this.state.setAuthorize(migrateValue);
|
|
113
|
-
localStorage.setItem('authUrls', '{}');
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
91
|
subscribeBalancesAndCrowdloans(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
|
|
117
92
|
this.state.handleSwitchAccount(address).then(() => {
|
|
118
93
|
const addresses = this.state.getDecodedAddresses(address);
|
|
@@ -270,7 +245,6 @@ class KoniSubscription {
|
|
|
270
245
|
if (dataFromApi[chainInfo.slug]) {
|
|
271
246
|
this.state.updateChainStakingMetadata(dataFromApi[chainInfo.slug]);
|
|
272
247
|
} else {
|
|
273
|
-
console.warn('Not found staking data from api', chainInfo.slug);
|
|
274
248
|
const chainStakingMetadata = await (0, _bonding.getChainStakingMetadata)(chainInfo, substrateApiMap[chainInfo.slug]);
|
|
275
249
|
this.state.updateChainStakingMetadata(chainStakingMetadata);
|
|
276
250
|
}
|
package/cjs/packageInfo.js
CHANGED
|
@@ -37,7 +37,6 @@ class SubstrateChainHandler {
|
|
|
37
37
|
resumeAllApis() {
|
|
38
38
|
return Promise.all(Object.values(this.getSubstrateApiMap()).map(async substrateApi => {
|
|
39
39
|
if (!substrateApi.api.isConnected && substrateApi.api.connect) {
|
|
40
|
-
this.logger.log(`[Substrate] Resuming network [${substrateApi.specName}]`);
|
|
41
40
|
await substrateApi.api.connect();
|
|
42
41
|
}
|
|
43
42
|
}));
|
|
@@ -46,7 +45,6 @@ class SubstrateChainHandler {
|
|
|
46
45
|
return Promise.all(Object.values(this.getSubstrateApiMap()).map(async substrateApi => {
|
|
47
46
|
if (substrateApi.api.isConnected) {
|
|
48
47
|
var _substrateApi$api, _substrateApi$api2;
|
|
49
|
-
this.logger.log(`[Substrate] Stopping network [${substrateApi.chainSlug}]`);
|
|
50
48
|
((_substrateApi$api = substrateApi.api) === null || _substrateApi$api === void 0 ? void 0 : _substrateApi$api.disconnect) && (await ((_substrateApi$api2 = substrateApi.api) === null || _substrateApi$api2 === void 0 ? void 0 : _substrateApi$api2.disconnect()));
|
|
51
49
|
}
|
|
52
50
|
}));
|
|
@@ -104,7 +102,6 @@ class SubstrateChainHandler {
|
|
|
104
102
|
gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
|
|
105
103
|
})]);
|
|
106
104
|
if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
|
|
107
|
-
this.logger.error('Error response while validating WASM contract');
|
|
108
105
|
return {
|
|
109
106
|
name: '',
|
|
110
107
|
decimals: -1,
|
|
@@ -131,7 +128,6 @@ class SubstrateChainHandler {
|
|
|
131
128
|
}); // read-only operation so no gas limit
|
|
132
129
|
|
|
133
130
|
if (!collectionIdResp.result.isOk || !collectionIdResp.output) {
|
|
134
|
-
this.logger.error('Error response while validating WASM contract');
|
|
135
131
|
return {
|
|
136
132
|
name: '',
|
|
137
133
|
decimals: -1,
|
|
@@ -156,7 +152,7 @@ class SubstrateChainHandler {
|
|
|
156
152
|
contractError
|
|
157
153
|
};
|
|
158
154
|
} catch (e) {
|
|
159
|
-
this.logger.error(
|
|
155
|
+
this.logger.error(e);
|
|
160
156
|
return {
|
|
161
157
|
name: '',
|
|
162
158
|
decimals: -1,
|
|
@@ -222,7 +218,6 @@ class SubstrateChainHandler {
|
|
|
222
218
|
defaultFormatBalance: undefined,
|
|
223
219
|
recoverConnect: () => {
|
|
224
220
|
substrateApi.apiRetry = 0;
|
|
225
|
-
this.logger.log('Recover connect to ', apiUrl);
|
|
226
221
|
provider.connect().then(this.logger.log).catch(this.logger.error);
|
|
227
222
|
},
|
|
228
223
|
get isReady() {
|
|
@@ -244,7 +239,6 @@ class SubstrateChainHandler {
|
|
|
244
239
|
}
|
|
245
240
|
};
|
|
246
241
|
api.on('connected', () => {
|
|
247
|
-
this.logger.log('Substrate API connected to ', apiUrl);
|
|
248
242
|
substrateApi.apiRetry = 0;
|
|
249
243
|
if (substrateApi.isApiReadyOnce) {
|
|
250
244
|
substrateApi.isApiReady = true;
|
|
@@ -262,7 +256,6 @@ class SubstrateChainHandler {
|
|
|
262
256
|
}
|
|
263
257
|
});
|
|
264
258
|
api.on('ready', () => {
|
|
265
|
-
this.logger.log('Substrate API ready with', apiUrl);
|
|
266
259
|
this.loadOnReady(registry, api).then(rs => {
|
|
267
260
|
(0, _util.objectSpread)(substrateApi, rs);
|
|
268
261
|
}).catch(error => {
|
|
@@ -314,7 +307,7 @@ class SubstrateChainHandler {
|
|
|
314
307
|
const tokenSymbol = properties.tokenSymbol.unwrapOr([_util.formatBalance.getDefaults().unit, ...DEFAULT_AUX]);
|
|
315
308
|
const tokenDecimals = properties.tokenDecimals.unwrapOr([DEFAULT_DECIMALS]);
|
|
316
309
|
const isDevelopment = systemChainType.isDevelopment || systemChainType.isLocal || (0, _util.isTestChain)(systemChain);
|
|
317
|
-
this.logger.log(`
|
|
310
|
+
this.logger.log(`Connected to ${systemChain} (${systemChainType.toString()}), ${(0, _util.stringify)(properties)}`);
|
|
318
311
|
|
|
319
312
|
// explicitly override the ss58Format as specified
|
|
320
313
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -5,15 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getSubstrateConnectProvider = getSubstrateConnectProvider;
|
|
7
7
|
exports.relayChainSpecs = exports.paraChainSpecs = void 0;
|
|
8
|
+
var Sc = _interopRequireWildcard(require("@substrate/connect"));
|
|
8
9
|
var _rpcProvider = require("@polkadot/rpc-provider");
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
9
12
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
10
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
14
|
|
|
12
15
|
const relayChainSpecs = {
|
|
13
|
-
kusama:
|
|
14
|
-
polkadot:
|
|
15
|
-
rococo:
|
|
16
|
-
westend:
|
|
16
|
+
kusama: Sc.WellKnownChain.ksmcc3,
|
|
17
|
+
polkadot: Sc.WellKnownChain.polkadot,
|
|
18
|
+
rococo: Sc.WellKnownChain.rococo_v2_2,
|
|
19
|
+
westend: Sc.WellKnownChain.westend2
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
// Direct get spec data from @polkadot/react-api repository
|
|
@@ -106,14 +109,14 @@ class ProviderPlaceholder {
|
|
|
106
109
|
function getSubstrateConnectProvider(specLink) {
|
|
107
110
|
const [relayName, paraName] = specLink.split('/');
|
|
108
111
|
const relaySpec = relayChainSpecs[relayName];
|
|
109
|
-
const relayProvider = new _rpcProvider.ScProvider(relaySpec);
|
|
112
|
+
const relayProvider = new _rpcProvider.ScProvider(Sc, relaySpec);
|
|
110
113
|
if (!paraName) {
|
|
111
114
|
return relayProvider;
|
|
112
115
|
}
|
|
113
116
|
const paraChainData = paraChainSpecs[specLink];
|
|
114
117
|
let scProvider;
|
|
115
118
|
const scPromise = fetch(paraChainData).then(rs => rs.text()).then(spec => {
|
|
116
|
-
scProvider = new _rpcProvider.ScProvider(
|
|
119
|
+
scProvider = new _rpcProvider.ScProvider(Sc, spec);
|
|
117
120
|
return scProvider;
|
|
118
121
|
}).catch(console.error);
|
|
119
122
|
return new ProviderPlaceholder(scPromise);
|
|
@@ -367,7 +367,6 @@ class ChainService {
|
|
|
367
367
|
this.assetRegistrySubject.next(this.getAssetRegistry());
|
|
368
368
|
this.initApis();
|
|
369
369
|
await this.initAssetSettings();
|
|
370
|
-
this.logger.log('Initiated chains, assets and APIs');
|
|
371
370
|
}
|
|
372
371
|
initApis() {
|
|
373
372
|
// TODO: this might be async
|
|
@@ -1156,7 +1155,6 @@ class ChainService {
|
|
|
1156
1155
|
});
|
|
1157
1156
|
await Promise.all(promiseList);
|
|
1158
1157
|
if (update) {
|
|
1159
|
-
console.log('Update chain connection state');
|
|
1160
1158
|
this.chainStateMapSubject.next(chainStateMap);
|
|
1161
1159
|
}
|
|
1162
1160
|
}
|
|
@@ -352,6 +352,9 @@ function _getAssetDecimals(assetInfo) {
|
|
|
352
352
|
}
|
|
353
353
|
function _getBlockExplorerFromChain(chainInfo) {
|
|
354
354
|
let blockExplorer;
|
|
355
|
+
if (!chainInfo) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
355
358
|
if (_isPureEvmChain(chainInfo)) {
|
|
356
359
|
var _chainInfo$evmInfo4;
|
|
357
360
|
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo4 = chainInfo.evmInfo) === null || _chainInfo$evmInfo4 === void 0 ? void 0 : _chainInfo$evmInfo4.blockExplorer;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.historyRecover = exports.HistoryRecoverStatus = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
let HistoryRecoverStatus;
|
|
10
|
+
exports.HistoryRecoverStatus = HistoryRecoverStatus;
|
|
11
|
+
(function (HistoryRecoverStatus) {
|
|
12
|
+
HistoryRecoverStatus["SUCCESS"] = "SUCCESS";
|
|
13
|
+
HistoryRecoverStatus["FAILED"] = "FAILED";
|
|
14
|
+
HistoryRecoverStatus["API_INACTIVE"] = "API_INACTIVE";
|
|
15
|
+
HistoryRecoverStatus["LACK_INFO"] = "LACK_INFO";
|
|
16
|
+
HistoryRecoverStatus["FAIL_DETECT"] = "FAIL_DETECT";
|
|
17
|
+
HistoryRecoverStatus["UNKNOWN"] = "UNKNOWN";
|
|
18
|
+
})(HistoryRecoverStatus || (exports.HistoryRecoverStatus = HistoryRecoverStatus = {}));
|
|
19
|
+
const substrateRecover = async (history, chainService) => {
|
|
20
|
+
const {
|
|
21
|
+
blockHash,
|
|
22
|
+
chain,
|
|
23
|
+
extrinsicHash
|
|
24
|
+
} = history;
|
|
25
|
+
try {
|
|
26
|
+
const substrateApi = chainService.getSubstrateApi(chain);
|
|
27
|
+
if (substrateApi) {
|
|
28
|
+
const _api = await substrateApi.isReady;
|
|
29
|
+
const api = _api.api;
|
|
30
|
+
if (!blockHash) {
|
|
31
|
+
console.log(`Fail to find extrinsic ${extrinsicHash} on ${chain}: No block hash`);
|
|
32
|
+
return HistoryRecoverStatus.LACK_INFO;
|
|
33
|
+
}
|
|
34
|
+
const block = await api.rpc.chain.getBlock(blockHash);
|
|
35
|
+
const allEvents = await api.query.system.events.at(blockHash);
|
|
36
|
+
const extrinsics = block.block.extrinsics;
|
|
37
|
+
let index;
|
|
38
|
+
extrinsics.forEach((extrinsic, _idx) => {
|
|
39
|
+
if (extrinsicHash === extrinsic.hash.toHex()) {
|
|
40
|
+
index = _idx;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
if (index === undefined) {
|
|
44
|
+
console.log(`Fail to find extrinsic ${extrinsicHash} on ${chain}`);
|
|
45
|
+
return HistoryRecoverStatus.FAIL_DETECT;
|
|
46
|
+
}
|
|
47
|
+
const events = allEvents.filter(_ref => {
|
|
48
|
+
let {
|
|
49
|
+
phase
|
|
50
|
+
} = _ref;
|
|
51
|
+
return phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index);
|
|
52
|
+
});
|
|
53
|
+
for (const {
|
|
54
|
+
event
|
|
55
|
+
} of events) {
|
|
56
|
+
if (api.events.system.ExtrinsicSuccess.is(event)) {
|
|
57
|
+
return HistoryRecoverStatus.SUCCESS;
|
|
58
|
+
} else if (api.events.system.ExtrinsicFailed.is(event)) {
|
|
59
|
+
return HistoryRecoverStatus.FAILED;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return HistoryRecoverStatus.FAIL_DETECT;
|
|
63
|
+
} else {
|
|
64
|
+
console.error(`Fail to update history ${chain}-${extrinsicHash}: Api not active`);
|
|
65
|
+
return HistoryRecoverStatus.API_INACTIVE;
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error(`Fail to update history ${chain}-${extrinsicHash}:`, e.message);
|
|
69
|
+
return HistoryRecoverStatus.UNKNOWN;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const evmRecover = async (history, chainService) => {
|
|
73
|
+
const {
|
|
74
|
+
chain,
|
|
75
|
+
extrinsicHash
|
|
76
|
+
} = history;
|
|
77
|
+
try {
|
|
78
|
+
const evmApi = chainService.getEvmApi(chain);
|
|
79
|
+
if (evmApi) {
|
|
80
|
+
const _api = await evmApi.isReady;
|
|
81
|
+
const api = _api.api;
|
|
82
|
+
const block = await api.eth.getTransactionReceipt(extrinsicHash);
|
|
83
|
+
return block.status ? HistoryRecoverStatus.SUCCESS : HistoryRecoverStatus.FAILED;
|
|
84
|
+
} else {
|
|
85
|
+
console.error(`Fail to update history ${chain}-${extrinsicHash}: Api not active`);
|
|
86
|
+
return HistoryRecoverStatus.API_INACTIVE;
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.error(`Fail to update history ${chain}-${extrinsicHash}:`, e.message);
|
|
90
|
+
return HistoryRecoverStatus.UNKNOWN;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// undefined: Cannot check status
|
|
95
|
+
// true: Transaction success
|
|
96
|
+
// false: Transaction failed
|
|
97
|
+
const historyRecover = async (history, chainService) => {
|
|
98
|
+
const {
|
|
99
|
+
chainType
|
|
100
|
+
} = history;
|
|
101
|
+
if (chainType) {
|
|
102
|
+
const checkFunction = chainType === 'substrate' ? substrateRecover : evmRecover;
|
|
103
|
+
return await checkFunction(history, chainService);
|
|
104
|
+
} else {
|
|
105
|
+
return HistoryRecoverStatus.LACK_INFO;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
exports.historyRecover = historyRecover;
|
|
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.HistoryService = void 0;
|
|
7
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
7
8
|
var _constants = require("@subwallet/extension-base/constants");
|
|
8
9
|
var _types = require("@subwallet/extension-base/services/base/types");
|
|
10
|
+
var _recoverHistoryStatus = require("@subwallet/extension-base/services/history-service/helpers/recoverHistoryStatus");
|
|
9
11
|
var _promise = require("@subwallet/extension-base/utils/promise");
|
|
10
12
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
11
13
|
var _rxjs = require("rxjs");
|
|
@@ -15,6 +17,7 @@ var _subsquidMultiChainHistory = require("./subsquid-multi-chain-history");
|
|
|
15
17
|
|
|
16
18
|
class HistoryService {
|
|
17
19
|
historySubject = new _rxjs.BehaviorSubject([]);
|
|
20
|
+
#processingHistories = {};
|
|
18
21
|
constructor(dbService, chainService, eventService, keyringService) {
|
|
19
22
|
this.dbService = dbService;
|
|
20
23
|
this.chainService = chainService;
|
|
@@ -24,6 +27,7 @@ class HistoryService {
|
|
|
24
27
|
}
|
|
25
28
|
fetchPromise = null;
|
|
26
29
|
interval = undefined;
|
|
30
|
+
recoverInterval = undefined;
|
|
27
31
|
async fetchAndLoadHistories(addresses) {
|
|
28
32
|
if (!addresses || addresses.length === 0) {
|
|
29
33
|
return [];
|
|
@@ -95,9 +99,6 @@ class HistoryService {
|
|
|
95
99
|
});
|
|
96
100
|
const updateRecords = historyItems.filter(item => {
|
|
97
101
|
const key = `${item.chain}-${item.extrinsicHash}`;
|
|
98
|
-
|
|
99
|
-
// !excludeKeys.includes(key) && console.log('Cancel update', key);
|
|
100
|
-
|
|
101
102
|
return item.origin === 'app' || !excludeKeys.includes(key);
|
|
102
103
|
});
|
|
103
104
|
await this.dbService.upsertHistory(updateRecords);
|
|
@@ -126,12 +127,56 @@ class HistoryService {
|
|
|
126
127
|
this.fetchPromise = null;
|
|
127
128
|
return Promise.resolve();
|
|
128
129
|
}
|
|
130
|
+
async startRecoverHistories() {
|
|
131
|
+
await this.recoverHistories();
|
|
132
|
+
this.recoverInterval = setInterval(() => {
|
|
133
|
+
this.recoverHistories().catch(console.error);
|
|
134
|
+
}, _constants.CRON_RECOVER_HISTORY_INTERVAL);
|
|
135
|
+
}
|
|
136
|
+
stopRecoverHistories() {
|
|
137
|
+
clearInterval(this.recoverInterval);
|
|
138
|
+
return Promise.resolve();
|
|
139
|
+
}
|
|
140
|
+
async recoverHistories() {
|
|
141
|
+
const list = [];
|
|
142
|
+
for (const processingHistory of Object.values(this.#processingHistories)) {
|
|
143
|
+
const chainState = this.chainService.getChainStateByKey(processingHistory.chain);
|
|
144
|
+
if (chainState.active) {
|
|
145
|
+
list.push(processingHistory);
|
|
146
|
+
}
|
|
147
|
+
if (list.length >= 10) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const promises = list.map(history => (0, _recoverHistoryStatus.historyRecover)(history, this.chainService));
|
|
152
|
+
const result = await Promise.all(promises);
|
|
153
|
+
result.forEach((status, index) => {
|
|
154
|
+
const extrinsicHash = list[index].extrinsicHash;
|
|
155
|
+
switch (status) {
|
|
156
|
+
case _recoverHistoryStatus.HistoryRecoverStatus.API_INACTIVE:
|
|
157
|
+
break;
|
|
158
|
+
case _recoverHistoryStatus.HistoryRecoverStatus.FAILED:
|
|
159
|
+
case _recoverHistoryStatus.HistoryRecoverStatus.SUCCESS:
|
|
160
|
+
this.updateHistoryByExtrinsicHash(extrinsicHash, {
|
|
161
|
+
status: status === _recoverHistoryStatus.HistoryRecoverStatus.SUCCESS ? _KoniTypes.ExtrinsicStatus.SUCCESS : _KoniTypes.ExtrinsicStatus.FAIL
|
|
162
|
+
}).catch(console.error);
|
|
163
|
+
delete this.#processingHistories[extrinsicHash];
|
|
164
|
+
break;
|
|
165
|
+
default:
|
|
166
|
+
delete this.#processingHistories[extrinsicHash];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
if (!Object.keys(this.#processingHistories).length) {
|
|
170
|
+
await this.stopRecoverHistories();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
129
173
|
startPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
130
174
|
async init() {
|
|
131
175
|
this.status = _types.ServiceStatus.INITIALIZING;
|
|
132
176
|
await this.loadData();
|
|
133
177
|
Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
|
|
134
178
|
this.getHistories().catch(console.log);
|
|
179
|
+
this.getProcessingHistory().catch(console.log);
|
|
135
180
|
this.eventService.on('account.add', () => {
|
|
136
181
|
(async () => {
|
|
137
182
|
await this.stopCron();
|
|
@@ -144,12 +189,22 @@ class HistoryService {
|
|
|
144
189
|
}).catch(console.error);
|
|
145
190
|
this.status = _types.ServiceStatus.INITIALIZED;
|
|
146
191
|
}
|
|
192
|
+
async getProcessingHistory() {
|
|
193
|
+
const histories = await this.dbService.getHistories();
|
|
194
|
+
this.#processingHistories = {};
|
|
195
|
+
histories.filter(history => {
|
|
196
|
+
return history.status === 'processing';
|
|
197
|
+
}).forEach(history => {
|
|
198
|
+
this.#processingHistories[history.extrinsicHash] = history;
|
|
199
|
+
});
|
|
200
|
+
this.startRecoverHistories().catch(console.error);
|
|
201
|
+
}
|
|
147
202
|
async start() {
|
|
148
203
|
try {
|
|
149
|
-
console.debug('Start history service');
|
|
150
204
|
this.startPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
151
205
|
this.status = _types.ServiceStatus.STARTING;
|
|
152
206
|
await this.startCron();
|
|
207
|
+
await this.startRecoverHistories();
|
|
153
208
|
this.status = _types.ServiceStatus.STARTED;
|
|
154
209
|
this.startPromiseHandler.resolve();
|
|
155
210
|
} catch (e) {
|
|
@@ -161,12 +216,12 @@ class HistoryService {
|
|
|
161
216
|
}
|
|
162
217
|
stopPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
163
218
|
async stop() {
|
|
164
|
-
console.debug('Stop history service');
|
|
165
219
|
try {
|
|
166
220
|
this.stopPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
167
221
|
this.status = _types.ServiceStatus.STOPPING;
|
|
168
222
|
await this.persistData();
|
|
169
223
|
await this.stopCron();
|
|
224
|
+
await this.stopRecoverHistories();
|
|
170
225
|
this.stopPromiseHandler.resolve();
|
|
171
226
|
this.status = _types.ServiceStatus.STOPPED;
|
|
172
227
|
} catch (e) {
|
|
@@ -120,7 +120,7 @@ function parseSubsquidTransactionData(address, type, historyItem, chainInfo, arg
|
|
|
120
120
|
const parsedArgs = args;
|
|
121
121
|
const transaction = data.call.data.args.transaction.value;
|
|
122
122
|
to = autoFormatAddress(parsedArgs.to);
|
|
123
|
-
from = autoFormatAddress(parsedArgs.from);
|
|
123
|
+
from = autoFormatAddress(parsedArgs.from || address);
|
|
124
124
|
extrinsicHash = parsedArgs.transactionHash || extrinsic.hash;
|
|
125
125
|
amount = transaction.value || '0';
|
|
126
126
|
fee = (parseInt(transaction.gasPrice) * parseInt(transaction.gasLimit)).toString();
|
|
@@ -255,7 +255,8 @@ async function fetchMultiChainHistories(addresses, chainMap) {
|
|
|
255
255
|
const usedAddresses = relatedAddresses.filter(a => lowerAddresses.includes(a.toLowerCase()));
|
|
256
256
|
const chainInfo = chainMap[chainId];
|
|
257
257
|
if (chainInfo === undefined) {
|
|
258
|
-
console.warn(`Not found chain info for chain id: ${chainId}`);
|
|
258
|
+
console.warn(`Not found chain info for chain id: ${chainId}`); // TODO: resolve conflicting chainId
|
|
259
|
+
|
|
259
260
|
return;
|
|
260
261
|
}
|
|
261
262
|
usedAddresses.forEach(address => {
|