@subwallet/extension-base 1.0.4-1 → 1.0.5-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +14 -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 +164 -134
- 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 +227 -0
- package/cjs/services/history-service/index.js +68 -6
- 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/notification-service/NotificationService.js +1 -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 +3 -45
- package/cjs/services/transaction-service/constants.js +11 -0
- package/cjs/services/transaction-service/index.js +60 -20
- package/cjs/services/transaction-service/utils.js +25 -14
- package/cjs/utils/index.js +3 -0
- 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 +79 -51
- 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 +17 -0
- package/services/history-service/helpers/recoverHistoryStatus.js +214 -0
- package/services/history-service/index.d.ts +6 -0
- package/services/history-service/index.js +69 -7
- 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/notification-service/NotificationService.js +1 -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.d.ts +1 -1
- package/services/storage-service/DatabaseService.js +3 -45
- 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 +61 -21
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.d.ts +1 -1
- package/services/transaction-service/utils.js +24 -13
- package/utils/index.js +3 -0
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ExtrinsicStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { CRON_RECOVER_HISTORY_INTERVAL, CRON_REFRESH_HISTORY_INTERVAL } from '@subwallet/extension-base/constants';
|
|
5
6
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
7
|
+
import { historyRecover, HistoryRecoverStatus } from '@subwallet/extension-base/services/history-service/helpers/recoverHistoryStatus';
|
|
6
8
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
7
9
|
import { keyring } from '@subwallet/ui-keyring';
|
|
8
10
|
import { BehaviorSubject } from 'rxjs';
|
|
9
11
|
import { fetchMultiChainHistories } from "./subsquid-multi-chain-history.js";
|
|
10
12
|
export class HistoryService {
|
|
11
13
|
historySubject = new BehaviorSubject([]);
|
|
14
|
+
#needRecoveryHistories = {};
|
|
12
15
|
constructor(dbService, chainService, eventService, keyringService) {
|
|
13
16
|
this.dbService = dbService;
|
|
14
17
|
this.chainService = chainService;
|
|
@@ -18,6 +21,7 @@ export class HistoryService {
|
|
|
18
21
|
}
|
|
19
22
|
fetchPromise = null;
|
|
20
23
|
interval = undefined;
|
|
24
|
+
recoverInterval = undefined;
|
|
21
25
|
async fetchAndLoadHistories(addresses) {
|
|
22
26
|
if (!addresses || addresses.length === 0) {
|
|
23
27
|
return [];
|
|
@@ -69,7 +73,7 @@ export class HistoryService {
|
|
|
69
73
|
await this.addHistoryItems(updatedRecords);
|
|
70
74
|
}
|
|
71
75
|
async updateHistoryByExtrinsicHash(extrinsicHash, updateData) {
|
|
72
|
-
await this.dbService.
|
|
76
|
+
await this.dbService.updateHistoryByExtrinsicHash(extrinsicHash, updateData);
|
|
73
77
|
this.historySubject.next(await this.dbService.getHistories());
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -88,9 +92,6 @@ export class HistoryService {
|
|
|
88
92
|
});
|
|
89
93
|
const updateRecords = historyItems.filter(item => {
|
|
90
94
|
const key = `${item.chain}-${item.extrinsicHash}`;
|
|
91
|
-
|
|
92
|
-
// !excludeKeys.includes(key) && console.log('Cancel update', key);
|
|
93
|
-
|
|
94
95
|
return item.origin === 'app' || !excludeKeys.includes(key);
|
|
95
96
|
});
|
|
96
97
|
await this.dbService.upsertHistory(updateRecords);
|
|
@@ -119,12 +120,60 @@ export class HistoryService {
|
|
|
119
120
|
this.fetchPromise = null;
|
|
120
121
|
return Promise.resolve();
|
|
121
122
|
}
|
|
123
|
+
async startRecoverHistories() {
|
|
124
|
+
await this.recoverHistories();
|
|
125
|
+
this.recoverInterval = setInterval(() => {
|
|
126
|
+
this.recoverHistories().catch(console.error);
|
|
127
|
+
}, CRON_RECOVER_HISTORY_INTERVAL);
|
|
128
|
+
}
|
|
129
|
+
stopRecoverHistories() {
|
|
130
|
+
clearInterval(this.recoverInterval);
|
|
131
|
+
return Promise.resolve();
|
|
132
|
+
}
|
|
133
|
+
async recoverHistories() {
|
|
134
|
+
const list = [];
|
|
135
|
+
for (const processingHistory of Object.values(this.#needRecoveryHistories)) {
|
|
136
|
+
const chainState = this.chainService.getChainStateByKey(processingHistory.chain);
|
|
137
|
+
if (chainState.active) {
|
|
138
|
+
list.push(processingHistory);
|
|
139
|
+
}
|
|
140
|
+
if (list.length >= 10) {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const promises = list.map(history => historyRecover(history, this.chainService));
|
|
145
|
+
const results = await Promise.all(promises);
|
|
146
|
+
results.forEach((recoverResult, index) => {
|
|
147
|
+
const currentExtrinsicHash = list[index].extrinsicHash;
|
|
148
|
+
const updateData = {
|
|
149
|
+
...recoverResult,
|
|
150
|
+
status: ExtrinsicStatus.UNKNOWN
|
|
151
|
+
};
|
|
152
|
+
switch (recoverResult.status) {
|
|
153
|
+
case HistoryRecoverStatus.API_INACTIVE:
|
|
154
|
+
break;
|
|
155
|
+
case HistoryRecoverStatus.FAILED:
|
|
156
|
+
case HistoryRecoverStatus.SUCCESS:
|
|
157
|
+
updateData.status = recoverResult.status === HistoryRecoverStatus.SUCCESS ? ExtrinsicStatus.SUCCESS : ExtrinsicStatus.FAIL;
|
|
158
|
+
this.updateHistoryByExtrinsicHash(currentExtrinsicHash, updateData).catch(console.error);
|
|
159
|
+
delete this.#needRecoveryHistories[currentExtrinsicHash];
|
|
160
|
+
break;
|
|
161
|
+
default:
|
|
162
|
+
this.updateHistoryByExtrinsicHash(currentExtrinsicHash, updateData).catch(console.error);
|
|
163
|
+
delete this.#needRecoveryHistories[currentExtrinsicHash];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
if (!Object.keys(this.#needRecoveryHistories).length) {
|
|
167
|
+
await this.stopRecoverHistories();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
122
170
|
startPromiseHandler = createPromiseHandler();
|
|
123
171
|
async init() {
|
|
124
172
|
this.status = ServiceStatus.INITIALIZING;
|
|
125
173
|
await this.loadData();
|
|
126
174
|
Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
|
|
127
175
|
this.getHistories().catch(console.log);
|
|
176
|
+
this.recoverProcessingHistory().catch(console.error);
|
|
128
177
|
this.eventService.on('account.add', () => {
|
|
129
178
|
(async () => {
|
|
130
179
|
await this.stopCron();
|
|
@@ -137,9 +186,22 @@ export class HistoryService {
|
|
|
137
186
|
}).catch(console.error);
|
|
138
187
|
this.status = ServiceStatus.INITIALIZED;
|
|
139
188
|
}
|
|
189
|
+
async recoverProcessingHistory() {
|
|
190
|
+
const histories = await this.dbService.getHistories();
|
|
191
|
+
this.#needRecoveryHistories = {};
|
|
192
|
+
histories.filter(history => {
|
|
193
|
+
return [ExtrinsicStatus.PROCESSING, ExtrinsicStatus.SUBMITTING].includes(history.status);
|
|
194
|
+
}).forEach(history => {
|
|
195
|
+
this.#needRecoveryHistories[history.extrinsicHash] = history;
|
|
196
|
+
});
|
|
197
|
+
const recoverNumber = Object.keys(this.#needRecoveryHistories).length;
|
|
198
|
+
if (recoverNumber > 0) {
|
|
199
|
+
console.log(`Recover ${recoverNumber} processing history`);
|
|
200
|
+
}
|
|
201
|
+
this.startRecoverHistories().catch(console.error);
|
|
202
|
+
}
|
|
140
203
|
async start() {
|
|
141
204
|
try {
|
|
142
|
-
console.debug('Start history service');
|
|
143
205
|
this.startPromiseHandler = createPromiseHandler();
|
|
144
206
|
this.status = ServiceStatus.STARTING;
|
|
145
207
|
await this.startCron();
|
|
@@ -154,12 +216,12 @@ export class HistoryService {
|
|
|
154
216
|
}
|
|
155
217
|
stopPromiseHandler = createPromiseHandler();
|
|
156
218
|
async stop() {
|
|
157
|
-
console.debug('Stop history service');
|
|
158
219
|
try {
|
|
159
220
|
this.stopPromiseHandler = createPromiseHandler();
|
|
160
221
|
this.status = ServiceStatus.STOPPING;
|
|
161
222
|
await this.persistData();
|
|
162
223
|
await this.stopCron();
|
|
224
|
+
await this.stopRecoverHistories();
|
|
163
225
|
this.stopPromiseHandler.resolve();
|
|
164
226
|
this.status = ServiceStatus.STOPPED;
|
|
165
227
|
} catch (e) {
|
|
@@ -110,7 +110,7 @@ export function parseSubsquidTransactionData(address, type, historyItem, chainIn
|
|
|
110
110
|
const parsedArgs = args;
|
|
111
111
|
const transaction = data.call.data.args.transaction.value;
|
|
112
112
|
to = autoFormatAddress(parsedArgs.to);
|
|
113
|
-
from = autoFormatAddress(parsedArgs.from);
|
|
113
|
+
from = autoFormatAddress(parsedArgs.from || address);
|
|
114
114
|
extrinsicHash = parsedArgs.transactionHash || extrinsic.hash;
|
|
115
115
|
amount = transaction.value || '0';
|
|
116
116
|
fee = (parseInt(transaction.gasPrice) * parseInt(transaction.gasLimit)).toString();
|
|
@@ -244,7 +244,8 @@ export async function fetchMultiChainHistories(addresses, chainMap, maxPage = 25
|
|
|
244
244
|
const usedAddresses = relatedAddresses.filter(a => lowerAddresses.includes(a.toLowerCase()));
|
|
245
245
|
const chainInfo = chainMap[chainId];
|
|
246
246
|
if (chainInfo === undefined) {
|
|
247
|
-
console.warn(`Not found chain info for chain id: ${chainId}`);
|
|
247
|
+
console.warn(`Not found chain info for chain id: ${chainId}`); // TODO: resolve conflicting chainId
|
|
248
|
+
|
|
248
249
|
return;
|
|
249
250
|
}
|
|
250
251
|
usedAddresses.forEach(address => {
|