@subwallet/extension-base 1.0.4-0 → 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 +37 -16
- package/background/KoniTypes.js +2 -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 +2 -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/amplitude.js +9 -2
- package/cjs/koni/api/staking/bonding/astar.js +37 -13
- package/cjs/koni/api/staking/bonding/paraChain.js +10 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +21 -4
- 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 +204 -132
- package/cjs/koni/background/handlers/State.js +30 -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/constants.js +1 -1
- package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -10
- package/cjs/services/chain-service/handler/light-client/index.js +9 -6
- package/cjs/services/chain-service/index.js +75 -28
- 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 +9 -2
- package/cjs/services/migration-service/index.js +7 -7
- package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +39 -0
- 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 +7 -1
- package/cjs/services/price-service/coingecko.js +1 -1
- package/cjs/services/price-service/index.js +0 -4
- package/cjs/services/request-service/handler/AuthRequestHandler.js +8 -1
- package/cjs/services/request-service/handler/EvmRequestHandler.js +21 -0
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +6 -0
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +6 -0
- package/cjs/services/request-service/index.js +6 -0
- package/cjs/services/setting-service/SettingService.js +4 -9
- package/cjs/services/setting-service/constants.js +18 -2
- package/cjs/services/storage-service/DatabaseService.js +16 -44
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStore.js +3 -0
- package/cjs/services/transaction-service/constants.js +11 -0
- package/cjs/services/transaction-service/index.js +31 -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/amplitude.js +9 -2
- package/koni/api/staking/bonding/astar.d.ts +2 -1
- package/koni/api/staking/bonding/astar.js +36 -13
- package/koni/api/staking/bonding/paraChain.js +10 -2
- package/koni/api/staking/bonding/relayChain.js +21 -4
- 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 +3 -0
- package/koni/background/handlers/Extension.js +120 -51
- package/koni/background/handlers/State.d.ts +4 -1
- package/koni/background/handlers/State.js +30 -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 +65 -39
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +3 -10
- 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.d.ts +2 -1
- package/services/chain-service/index.js +75 -28
- 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.d.ts +1 -0
- package/services/keyring-service/index.js +9 -2
- package/services/migration-service/index.js +7 -7
- package/services/migration-service/scripts/MigrateAuthUrls.d.ts +4 -0
- package/services/migration-service/scripts/MigrateAuthUrls.js +31 -0
- 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 +7 -1
- package/services/price-service/coingecko.js +1 -1
- package/services/price-service/index.js +0 -4
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
- package/services/request-service/handler/AuthRequestHandler.js +8 -1
- package/services/request-service/handler/EvmRequestHandler.d.ts +1 -0
- package/services/request-service/handler/EvmRequestHandler.js +21 -0
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -0
- package/services/request-service/handler/MetadataRequestHandler.js +6 -0
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
- package/services/request-service/handler/SubstrateRequestHandler.js +6 -0
- package/services/request-service/index.d.ts +1 -0
- package/services/request-service/index.js +6 -0
- package/services/setting-service/SettingService.d.ts +1 -0
- package/services/setting-service/SettingService.js +5 -10
- package/services/setting-service/constants.d.ts +4 -1
- package/services/setting-service/constants.js +14 -1
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +16 -44
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStore.d.ts +1 -0
- package/services/storage-service/db-stores/BaseStore.js +3 -0
- package/services/transaction-service/constants.d.ts +1 -0
- package/services/transaction-service/constants.js +4 -0
- package/services/transaction-service/index.d.ts +2 -0
- package/services/transaction-service/index.js +32 -10
- package/services/transaction-service/utils.d.ts +1 -1
- package/services/transaction-service/utils.js +24 -13
|
@@ -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 => {
|