@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
|
@@ -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
|
+
#needRecoveryHistories = {};
|
|
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 [];
|
|
@@ -76,7 +80,7 @@ class HistoryService {
|
|
|
76
80
|
await this.addHistoryItems(updatedRecords);
|
|
77
81
|
}
|
|
78
82
|
async updateHistoryByExtrinsicHash(extrinsicHash, updateData) {
|
|
79
|
-
await this.dbService.
|
|
83
|
+
await this.dbService.updateHistoryByExtrinsicHash(extrinsicHash, updateData);
|
|
80
84
|
this.historySubject.next(await this.dbService.getHistories());
|
|
81
85
|
}
|
|
82
86
|
|
|
@@ -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,60 @@ 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.#needRecoveryHistories)) {
|
|
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 results = await Promise.all(promises);
|
|
153
|
+
results.forEach((recoverResult, index) => {
|
|
154
|
+
const currentExtrinsicHash = list[index].extrinsicHash;
|
|
155
|
+
const updateData = {
|
|
156
|
+
...recoverResult,
|
|
157
|
+
status: _KoniTypes.ExtrinsicStatus.UNKNOWN
|
|
158
|
+
};
|
|
159
|
+
switch (recoverResult.status) {
|
|
160
|
+
case _recoverHistoryStatus.HistoryRecoverStatus.API_INACTIVE:
|
|
161
|
+
break;
|
|
162
|
+
case _recoverHistoryStatus.HistoryRecoverStatus.FAILED:
|
|
163
|
+
case _recoverHistoryStatus.HistoryRecoverStatus.SUCCESS:
|
|
164
|
+
updateData.status = recoverResult.status === _recoverHistoryStatus.HistoryRecoverStatus.SUCCESS ? _KoniTypes.ExtrinsicStatus.SUCCESS : _KoniTypes.ExtrinsicStatus.FAIL;
|
|
165
|
+
this.updateHistoryByExtrinsicHash(currentExtrinsicHash, updateData).catch(console.error);
|
|
166
|
+
delete this.#needRecoveryHistories[currentExtrinsicHash];
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
this.updateHistoryByExtrinsicHash(currentExtrinsicHash, updateData).catch(console.error);
|
|
170
|
+
delete this.#needRecoveryHistories[currentExtrinsicHash];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
if (!Object.keys(this.#needRecoveryHistories).length) {
|
|
174
|
+
await this.stopRecoverHistories();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
129
177
|
startPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
130
178
|
async init() {
|
|
131
179
|
this.status = _types.ServiceStatus.INITIALIZING;
|
|
132
180
|
await this.loadData();
|
|
133
181
|
Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
|
|
134
182
|
this.getHistories().catch(console.log);
|
|
183
|
+
this.recoverProcessingHistory().catch(console.error);
|
|
135
184
|
this.eventService.on('account.add', () => {
|
|
136
185
|
(async () => {
|
|
137
186
|
await this.stopCron();
|
|
@@ -144,9 +193,22 @@ class HistoryService {
|
|
|
144
193
|
}).catch(console.error);
|
|
145
194
|
this.status = _types.ServiceStatus.INITIALIZED;
|
|
146
195
|
}
|
|
196
|
+
async recoverProcessingHistory() {
|
|
197
|
+
const histories = await this.dbService.getHistories();
|
|
198
|
+
this.#needRecoveryHistories = {};
|
|
199
|
+
histories.filter(history => {
|
|
200
|
+
return [_KoniTypes.ExtrinsicStatus.PROCESSING, _KoniTypes.ExtrinsicStatus.SUBMITTING].includes(history.status);
|
|
201
|
+
}).forEach(history => {
|
|
202
|
+
this.#needRecoveryHistories[history.extrinsicHash] = history;
|
|
203
|
+
});
|
|
204
|
+
const recoverNumber = Object.keys(this.#needRecoveryHistories).length;
|
|
205
|
+
if (recoverNumber > 0) {
|
|
206
|
+
console.log(`Recover ${recoverNumber} processing history`);
|
|
207
|
+
}
|
|
208
|
+
this.startRecoverHistories().catch(console.error);
|
|
209
|
+
}
|
|
147
210
|
async start() {
|
|
148
211
|
try {
|
|
149
|
-
console.debug('Start history service');
|
|
150
212
|
this.startPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
151
213
|
this.status = _types.ServiceStatus.STARTING;
|
|
152
214
|
await this.startCron();
|
|
@@ -161,12 +223,12 @@ class HistoryService {
|
|
|
161
223
|
}
|
|
162
224
|
stopPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
163
225
|
async stop() {
|
|
164
|
-
console.debug('Stop history service');
|
|
165
226
|
try {
|
|
166
227
|
this.stopPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
167
228
|
this.status = _types.ServiceStatus.STOPPING;
|
|
168
229
|
await this.persistData();
|
|
169
230
|
await this.stopCron();
|
|
231
|
+
await this.stopRecoverHistories();
|
|
170
232
|
this.stopPromiseHandler.resolve();
|
|
171
233
|
this.status = _types.ServiceStatus.STOPPED;
|
|
172
234
|
} 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 => {
|