@subwallet/extension-base 1.0.2-1 → 1.0.2-1b
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 +16 -34
- package/background/KoniTypes.js +6 -7
- package/background/errors/TransactionError.js +21 -1
- package/cjs/background/KoniTypes.js +6 -7
- package/cjs/background/errors/TransactionError.js +20 -0
- package/cjs/constants/index.js +8 -26
- package/cjs/koni/api/dotsama/balance.js +49 -224
- package/cjs/koni/api/dotsama/transfer.js +30 -29
- package/cjs/koni/api/nft/acala_nft/index.js +4 -1
- package/cjs/koni/api/nft/bit.country/index.js +4 -1
- package/cjs/koni/api/nft/evm_nft/index.js +7 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +4 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
- package/cjs/koni/api/nft/unique_nft/index.js +6 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
- package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
- package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
- package/cjs/koni/api/staking/bonding/astar.js +15 -13
- package/cjs/koni/api/staking/bonding/index.js +22 -10
- package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +119 -16
- package/cjs/koni/api/staking/bonding/utils.js +27 -8
- package/cjs/koni/api/tokens/wasm/index.js +5 -4
- package/cjs/koni/api/tokens/wasm/utils.js +63 -0
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +150 -47
- package/cjs/koni/background/handlers/Extension.js +106 -64
- package/cjs/koni/background/handlers/State.js +19 -21
- package/cjs/koni/background/handlers/Tabs.js +8 -1
- package/cjs/koni/background/subscription.js +32 -29
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/handler/light-client/index.js +2 -0
- package/cjs/services/chain-service/index.js +6 -7
- package/cjs/services/event-service/index.js +5 -1
- package/cjs/services/event-service/types.js +11 -1
- package/cjs/services/history-service/index.js +16 -10
- package/cjs/services/history-service/subsquid-multi-chain-history.js +12 -9
- package/cjs/services/price-service/coingecko.js +0 -1
- package/cjs/services/price-service/index.js +2 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +6 -2
- package/cjs/services/storage-service/DatabaseService.js +52 -33
- package/cjs/services/storage-service/db-stores/Nft.js +4 -17
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +23 -14
- package/cjs/utils/index.js +7 -14
- package/constants/index.d.ts +7 -13
- package/constants/index.js +7 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +22 -197
- package/koni/api/dotsama/transfer.js +5 -4
- package/koni/api/nft/acala_nft/index.js +3 -1
- package/koni/api/nft/bit.country/index.js +3 -1
- package/koni/api/nft/evm_nft/index.js +6 -3
- package/koni/api/nft/index.d.ts +1 -2
- package/koni/api/nft/index.js +3 -6
- package/koni/api/nft/karura_nft/index.js +3 -1
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +8 -1
- package/koni/api/nft/statemine_nft/index.js +3 -1
- package/koni/api/nft/unique_nft/index.js +5 -1
- package/koni/api/nft/wasm_nft/index.d.ts +0 -2
- package/koni/api/nft/wasm_nft/index.js +167 -109
- package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
- package/koni/api/nft/wasm_nft/utils.js +7 -5
- package/koni/api/staking/bonding/amplitude.d.ts +0 -1
- package/koni/api/staking/bonding/amplitude.js +15 -10
- package/koni/api/staking/bonding/astar.js +8 -6
- package/koni/api/staking/bonding/index.d.ts +4 -1
- package/koni/api/staking/bonding/index.js +23 -13
- package/koni/api/staking/bonding/paraChain.d.ts +3 -0
- package/koni/api/staking/bonding/paraChain.js +86 -5
- package/koni/api/staking/bonding/relayChain.d.ts +5 -1
- package/koni/api/staking/bonding/relayChain.js +118 -18
- package/koni/api/staking/bonding/utils.d.ts +3 -2
- package/koni/api/staking/bonding/utils.js +27 -9
- package/koni/api/tokens/wasm/index.js +5 -4
- package/koni/api/tokens/wasm/utils.d.ts +6 -0
- package/koni/api/tokens/wasm/utils.js +54 -0
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +151 -48
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +108 -67
- package/koni/background/handlers/State.d.ts +5 -6
- package/koni/background/handlers/State.js +19 -21
- package/koni/background/handlers/Tabs.js +8 -1
- package/koni/background/subscription.js +31 -30
- package/package.json +9 -4
- package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
- package/services/chain-service/handler/light-client/index.d.ts +17 -1
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +1041 -881
- package/services/chain-service/helper/psp34_abi.json +2963 -1807
- package/services/chain-service/index.js +6 -7
- package/services/event-service/index.js +5 -1
- package/services/event-service/types.d.ts +5 -9
- package/services/event-service/types.js +4 -1
- package/services/history-service/index.d.ts +1 -1
- package/services/history-service/index.js +16 -10
- package/services/history-service/subsquid-multi-chain-history.js +15 -11
- package/services/price-service/coingecko.js +0 -1
- package/services/price-service/index.js +2 -3
- package/services/request-service/handler/AuthRequestHandler.js +6 -2
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +52 -33
- package/services/storage-service/db-stores/Nft.d.ts +1 -2
- package/services/storage-service/db-stores/Nft.js +4 -16
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.js +23 -14
- package/utils/index.d.ts +1 -1
- package/utils/index.js +6 -12
|
@@ -277,7 +277,7 @@ export class ChainService {
|
|
|
277
277
|
this.dbService.removeFromChainStore([slug]).catch(console.error);
|
|
278
278
|
this.updateChainSubscription();
|
|
279
279
|
this.lockChainInfoMap = false;
|
|
280
|
-
this.eventService.emit('chain.
|
|
280
|
+
this.eventService.emit('chain.updateState', slug);
|
|
281
281
|
return true;
|
|
282
282
|
}
|
|
283
283
|
resetChainInfoMap(excludedChains) {
|
|
@@ -343,7 +343,7 @@ export class ChainService {
|
|
|
343
343
|
this.dbService.removeFromAssetStore(targetAssets).catch(e => this.logger.error(e));
|
|
344
344
|
this.assetRegistrySubject.next(assetRegistry);
|
|
345
345
|
targetAssets.forEach(assetSlug => {
|
|
346
|
-
this.eventService.emit('asset.
|
|
346
|
+
this.eventService.emit('asset.updateState', assetSlug);
|
|
347
347
|
});
|
|
348
348
|
}
|
|
349
349
|
|
|
@@ -414,7 +414,7 @@ export class ChainService {
|
|
|
414
414
|
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
415
415
|
}).catch(console.error);
|
|
416
416
|
this.lockChainInfoMap = false;
|
|
417
|
-
this.eventService.emit('chain.
|
|
417
|
+
this.eventService.emit('chain.updateState', chainSlug);
|
|
418
418
|
return true;
|
|
419
419
|
}
|
|
420
420
|
enableChain(chainSlug) {
|
|
@@ -449,7 +449,7 @@ export class ChainService {
|
|
|
449
449
|
}).catch(console.error);
|
|
450
450
|
this.updateChainStateMapSubscription();
|
|
451
451
|
this.lockChainInfoMap = false;
|
|
452
|
-
this.eventService.emit('chain.
|
|
452
|
+
this.eventService.emit('chain.updateState', chainSlug);
|
|
453
453
|
return true;
|
|
454
454
|
}
|
|
455
455
|
checkExistedPredefinedChain(genesisHash, evmChainId) {
|
|
@@ -672,7 +672,7 @@ export class ChainService {
|
|
|
672
672
|
active: targetChainState.active,
|
|
673
673
|
currentProvider: targetChainState.currentProvider
|
|
674
674
|
}).then(() => {
|
|
675
|
-
this.eventService.emit('chain.
|
|
675
|
+
this.eventService.emit('chain.updateState', chainSlug);
|
|
676
676
|
}).catch(e => this.logger.error(e));
|
|
677
677
|
}
|
|
678
678
|
insertChain(params) {
|
|
@@ -1105,7 +1105,6 @@ export class ChainService {
|
|
|
1105
1105
|
this.setAssetSettings(assetSettings, false);
|
|
1106
1106
|
}
|
|
1107
1107
|
this.eventService.emit('asset.ready', true);
|
|
1108
|
-
console.log('Done init asset settings');
|
|
1109
1108
|
}
|
|
1110
1109
|
setAssetSettings(assetSettings, emitEvent = true) {
|
|
1111
1110
|
const updateAssets = [];
|
|
@@ -1119,7 +1118,7 @@ export class ChainService {
|
|
|
1119
1118
|
}
|
|
1120
1119
|
this.assetSettingSubject.next(assetSettings);
|
|
1121
1120
|
updateAssets.forEach(slug => {
|
|
1122
|
-
this.eventService.emit(
|
|
1121
|
+
this.eventService.emit('asset.updateState', slug);
|
|
1123
1122
|
});
|
|
1124
1123
|
this.store.set('AssetSetting', assetSettings);
|
|
1125
1124
|
}
|
|
@@ -34,7 +34,11 @@ export class EventService extends EventEmitter {
|
|
|
34
34
|
}, this.lazyTime);
|
|
35
35
|
}
|
|
36
36
|
emitLazy() {
|
|
37
|
-
|
|
37
|
+
try {
|
|
38
|
+
this.lazyEmitter.emit('lazy', this.pendingEvents, this.pendingEvents.map(e => e.type));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error('Get error in some listener of lazy event', e);
|
|
41
|
+
}
|
|
38
42
|
this.pendingEvents = [];
|
|
39
43
|
this.timeoutId = null;
|
|
40
44
|
}
|
|
@@ -9,20 +9,16 @@ export interface EventRegistry {
|
|
|
9
9
|
'account.remove': [string];
|
|
10
10
|
'chain.ready': [boolean];
|
|
11
11
|
'chain.add': [string];
|
|
12
|
-
'chain.
|
|
13
|
-
'chain.disable': [string];
|
|
14
|
-
'chain.enable': [string];
|
|
15
|
-
'chain.remove': [string];
|
|
12
|
+
'chain.updateState': [string];
|
|
16
13
|
'asset.ready': [boolean];
|
|
17
|
-
'asset.
|
|
18
|
-
'asset.update': [string];
|
|
19
|
-
'asset.enable': [string];
|
|
20
|
-
'asset.disable': [string];
|
|
21
|
-
'asset.remove': [string];
|
|
14
|
+
'asset.updateState': [string];
|
|
22
15
|
'transaction.done': [SWTransaction];
|
|
23
16
|
'transaction.failed': [SWTransaction | undefined];
|
|
17
|
+
'transaction.submitStaking': [string];
|
|
18
|
+
'transaction.transferNft': [SWTransaction | undefined];
|
|
24
19
|
}
|
|
25
20
|
export declare type EventType = keyof EventRegistry;
|
|
21
|
+
export declare const COMMON_RELOAD_EVENTS: EventType[];
|
|
26
22
|
export interface EventItem<T extends EventType> {
|
|
27
23
|
type: T;
|
|
28
24
|
data: EventRegistry[T];
|
|
@@ -17,8 +17,8 @@ export declare class HistoryService {
|
|
|
17
17
|
refreshHistoryInterval(): void;
|
|
18
18
|
getHistories(): Promise<TransactionHistoryItem<import("@subwallet/extension-base/background/KoniTypes").ExtrinsicType.TRANSFER_BALANCE>[]>;
|
|
19
19
|
getHistorySubject(): Promise<BehaviorSubject<TransactionHistoryItem<import("@subwallet/extension-base/background/KoniTypes").ExtrinsicType.TRANSFER_BALANCE>[]>>;
|
|
20
|
-
insertHistories(historyItems: TransactionHistoryItem[]): Promise<void>;
|
|
21
20
|
updateHistories(chain: string, extrinsicHash: string, updateData: Partial<TransactionHistoryItem>): Promise<void>;
|
|
21
|
+
insertHistories(historyItems: TransactionHistoryItem[]): Promise<void>;
|
|
22
22
|
addHistoryItems(historyItems: TransactionHistoryItem[]): Promise<void>;
|
|
23
23
|
removeHistoryByAddress(address: string): Promise<void>;
|
|
24
24
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { CRON_REFRESH_HISTORY_INTERVAL } from '@subwallet/extension-base/constants';
|
|
5
|
-
import { quickFormatAddressToCompare } from '@subwallet/extension-base/utils/address';
|
|
6
5
|
import { keyring } from '@subwallet/ui-keyring';
|
|
7
6
|
import { accounts } from '@subwallet/ui-keyring/observable/accounts';
|
|
8
7
|
import { BehaviorSubject } from 'rxjs';
|
|
@@ -50,7 +49,7 @@ export class HistoryService {
|
|
|
50
49
|
record.fromName = accountMap[(_record$from = record.from) === null || _record$from === void 0 ? void 0 : _record$from.toLowerCase()];
|
|
51
50
|
record.toName = accountMap[(_record$to = record.to) === null || _record$to === void 0 ? void 0 : _record$to.toLowerCase()];
|
|
52
51
|
});
|
|
53
|
-
this.
|
|
52
|
+
await this.addHistoryItems(historyRecords);
|
|
54
53
|
return historyRecords;
|
|
55
54
|
}
|
|
56
55
|
async fetchHistories(addresses) {
|
|
@@ -75,8 +74,8 @@ export class HistoryService {
|
|
|
75
74
|
const addressList = keyring.getAccounts().map(a => a.address);
|
|
76
75
|
const currentHistories = this.historySubject.value;
|
|
77
76
|
if (!this.fetchPromise || currentHistories.length === 0) {
|
|
78
|
-
|
|
79
|
-
this.historySubject.next(
|
|
77
|
+
await this.fetchHistories(addressList);
|
|
78
|
+
this.historySubject.next(await this.dbService.getHistories());
|
|
80
79
|
}
|
|
81
80
|
return this.historySubject.getValue();
|
|
82
81
|
}
|
|
@@ -84,10 +83,6 @@ export class HistoryService {
|
|
|
84
83
|
await this.getHistories();
|
|
85
84
|
return this.historySubject;
|
|
86
85
|
}
|
|
87
|
-
async insertHistories(historyItems) {
|
|
88
|
-
await this.dbService.upsertHistory(historyItems);
|
|
89
|
-
this.historySubject.next(await this.dbService.getHistories());
|
|
90
|
-
}
|
|
91
86
|
async updateHistories(chain, extrinsicHash, updateData) {
|
|
92
87
|
const existedRecords = await this.dbService.getHistories({
|
|
93
88
|
chain,
|
|
@@ -101,14 +96,25 @@ export class HistoryService {
|
|
|
101
96
|
});
|
|
102
97
|
await this.addHistoryItems(updatedRecords);
|
|
103
98
|
}
|
|
99
|
+
|
|
100
|
+
// Insert history without check override origin 'app'
|
|
101
|
+
async insertHistories(historyItems) {
|
|
102
|
+
await this.dbService.upsertHistory(historyItems);
|
|
103
|
+
this.historySubject.next(await this.dbService.getHistories());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Insert history with check override origin 'app'
|
|
104
107
|
async addHistoryItems(historyItems) {
|
|
105
108
|
// Prevent override record with original is 'app'
|
|
106
109
|
const appRecords = this.historySubject.value.filter(item => item.origin === 'app');
|
|
107
110
|
const excludeKeys = appRecords.map(item => {
|
|
108
|
-
return `${item.chain}-${
|
|
111
|
+
return `${item.chain}-${item.extrinsicHash}`;
|
|
109
112
|
});
|
|
110
113
|
const updateRecords = historyItems.filter(item => {
|
|
111
|
-
const key = `${item.chain}-${
|
|
114
|
+
const key = `${item.chain}-${item.extrinsicHash}`;
|
|
115
|
+
|
|
116
|
+
// !excludeKeys.includes(key) && console.log('Cancel update', key);
|
|
117
|
+
|
|
112
118
|
return item.origin === 'app' || !excludeKeys.includes(key);
|
|
113
119
|
});
|
|
114
120
|
await this.dbService.upsertHistory(updateRecords);
|
|
@@ -57,11 +57,15 @@ function autoFormatAddress(address) {
|
|
|
57
57
|
return '';
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
function generateSignature({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
function generateSignature(input) {
|
|
61
|
+
if (!input) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
const {
|
|
65
|
+
r,
|
|
66
|
+
s,
|
|
67
|
+
v
|
|
68
|
+
} = input;
|
|
65
69
|
const rHex = r.startsWith('0x') ? r.slice(2) : r;
|
|
66
70
|
const sHex = s.startsWith('0x') ? s.slice(2) : s;
|
|
67
71
|
const vHex = parseInt(v).toString(16);
|
|
@@ -243,14 +247,14 @@ export async function fetchMultiChainHistories(addresses, chainMap, maxPage = 25
|
|
|
243
247
|
console.warn(`Not found chain info for chain id: ${chainId}`);
|
|
244
248
|
return;
|
|
245
249
|
}
|
|
246
|
-
|
|
247
|
-
|
|
250
|
+
usedAddresses.forEach(address => {
|
|
251
|
+
try {
|
|
248
252
|
const transactionData = parseSubsquidTransactionData(address, name, historyItem, chainInfo, parseData(args), parseData(_data));
|
|
249
253
|
histories.push(transactionData);
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
+
} catch (e) {
|
|
255
|
+
console.warn('Parse transaction data failed', address, e);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
254
258
|
});
|
|
255
259
|
return histories;
|
|
256
260
|
}
|
|
@@ -16,7 +16,6 @@ export const getTokenPrice = async (priceIds, currency = 'usd') => {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
if (useBackupApi || ((_res = res) === null || _res === void 0 ? void 0 : _res.status) !== 200) {
|
|
19
|
-
console.log('Use backup api for price');
|
|
20
19
|
useBackupApi = true;
|
|
21
20
|
res = await axios.get(`https://chain-data.subwallet.app/api/price/get?ids=${idStr}`);
|
|
22
21
|
}
|
|
@@ -31,8 +31,8 @@ export class PriceService {
|
|
|
31
31
|
};
|
|
32
32
|
this.eventService.waitAssetReady.then(() => {
|
|
33
33
|
this.refreshPriceData();
|
|
34
|
-
this.eventService.on('asset.
|
|
35
|
-
this.eventService.on('asset.
|
|
34
|
+
this.eventService.on('asset.updateState', eventHandler);
|
|
35
|
+
this.eventService.on('asset.updateState', eventHandler);
|
|
36
36
|
}).catch(console.error);
|
|
37
37
|
}
|
|
38
38
|
async getPrice() {
|
|
@@ -62,7 +62,6 @@ export class PriceService {
|
|
|
62
62
|
ready: true
|
|
63
63
|
});
|
|
64
64
|
this.dbService.updatePriceStore(rs).catch(console.error);
|
|
65
|
-
console.log('Get Token Price From CoinGecko');
|
|
66
65
|
}).catch(console.error);
|
|
67
66
|
this.refreshTimeout = setTimeout(this.refreshPriceData.bind(this), CRON_REFRESH_PRICE_INTERVAL);
|
|
68
67
|
}
|
|
@@ -84,11 +84,11 @@ export default class AuthRequestHandler {
|
|
|
84
84
|
const chainInfoMaps = this.#chainService.getChainInfoMap();
|
|
85
85
|
const chainStateMap = this.#chainService.getChainStateMap();
|
|
86
86
|
let defaultChain = options.defaultChain;
|
|
87
|
-
|
|
87
|
+
let needEnableChains = [];
|
|
88
88
|
if (options.url) {
|
|
89
89
|
const domain = getDomainFromUrl(options.url);
|
|
90
90
|
const predefinedSupportChains = PREDEFINED_CHAIN_DAPP_CHAIN_MAP[domain];
|
|
91
|
-
if (predefinedSupportChains) {
|
|
91
|
+
if (!defaultChain && predefinedSupportChains) {
|
|
92
92
|
defaultChain = predefinedSupportChains[0];
|
|
93
93
|
options.autoActive && needEnableChains.push(...predefinedSupportChains);
|
|
94
94
|
}
|
|
@@ -106,6 +106,10 @@ export default class AuthRequestHandler {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
needEnableChains = needEnableChains.filter(slug => {
|
|
110
|
+
var _chainStateMap$slug;
|
|
111
|
+
return !((_chainStateMap$slug = chainStateMap[slug]) !== null && _chainStateMap$slug !== void 0 && _chainStateMap$slug.active);
|
|
112
|
+
});
|
|
109
113
|
needEnableChains.length > 0 && this.#chainService.enableChains(needEnableChains);
|
|
110
114
|
return chainInfo;
|
|
111
115
|
}
|
|
@@ -45,6 +45,7 @@ export default class DatabaseService {
|
|
|
45
45
|
deleteNftCollection(chain: string, collectionId: string): Promise<void>;
|
|
46
46
|
getAllNftCollection(chainHashes?: string[]): import("dexie").PromiseExtended<NftCollection[]>;
|
|
47
47
|
subscribeNft(addresses: string[], chainHashes?: string[], callback?: (nfts: INft[]) => void): Subscription;
|
|
48
|
+
cleanUpNft(chain: string, owner: string, collectionId: string, nftIds: string[]): Promise<number>;
|
|
48
49
|
getNft(addresses: string[], chainHashes?: string[]): Promise<INft[]>;
|
|
49
50
|
addNft(address: string, nft: NftItem): Promise<unknown>;
|
|
50
51
|
handleNftTransfer(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
|
|
@@ -6,6 +6,7 @@ import KoniDatabase from '@subwallet/extension-base/services/storage-service/dat
|
|
|
6
6
|
import { AssetStore, BalanceStore, ChainStore, CrowdloanStore, MigrationStore, NftCollectionStore, NftStore, PriceStore, StakingStore, TransactionStore } from '@subwallet/extension-base/services/storage-service/db-stores';
|
|
7
7
|
import ChainStakingMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata';
|
|
8
8
|
import NominatorMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata';
|
|
9
|
+
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
9
10
|
import { logger as createLogger } from '@polkadot/util';
|
|
10
11
|
export default class DatabaseService {
|
|
11
12
|
// TODO: might remove this
|
|
@@ -47,7 +48,8 @@ export default class DatabaseService {
|
|
|
47
48
|
}
|
|
48
49
|
async updateBalanceStore(address, item) {
|
|
49
50
|
if (item.state === APIItemState.READY) {
|
|
50
|
-
this.logger.log(`Updating balance for [${item.tokenSlug}]`);
|
|
51
|
+
// this.logger.log(`Updating balance for [${item.tokenSlug}]`);
|
|
52
|
+
|
|
51
53
|
return this.stores.balance.upsert({
|
|
52
54
|
address,
|
|
53
55
|
...item
|
|
@@ -62,14 +64,16 @@ export default class DatabaseService {
|
|
|
62
64
|
// Crowdloan
|
|
63
65
|
async updateCrowdloanStore(chain, address, item) {
|
|
64
66
|
if (item.state === APIItemState.READY && item.contribute !== '0') {
|
|
65
|
-
this.logger.log(`Updating crowdloan for [${chain}]`);
|
|
67
|
+
// this.logger.log(`Updating crowdloan for [${chain}]`);
|
|
68
|
+
|
|
66
69
|
return this.stores.crowdloan.upsert({
|
|
67
70
|
chain,
|
|
68
71
|
address,
|
|
69
72
|
...item
|
|
70
73
|
});
|
|
71
74
|
} else {
|
|
72
|
-
this.logger.debug(`Removing crowdloan for [${chain}]`);
|
|
75
|
+
// this.logger.debug(`Removing crowdloan for [${chain}]`);
|
|
76
|
+
|
|
73
77
|
return this.stores.crowdloan.deleteByChainAndAddress(chain, address);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
@@ -77,22 +81,23 @@ export default class DatabaseService {
|
|
|
77
81
|
// Staking
|
|
78
82
|
async updateStaking(chain, address, item) {
|
|
79
83
|
if (item.state === APIItemState.READY) {
|
|
80
|
-
this.logger.log(`Updating staking for [${chain}]`);
|
|
84
|
+
// this.logger.log(`Updating staking for [${chain}]`);
|
|
85
|
+
|
|
81
86
|
return this.stores.staking.upsert(item);
|
|
82
87
|
}
|
|
83
88
|
}
|
|
84
89
|
async getStakings(addresses, chains) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
90
|
+
// this.logger.log('Get Stakings: ', stakings);
|
|
91
|
+
|
|
92
|
+
return this.stores.staking.getStakings(addresses, chains);
|
|
88
93
|
}
|
|
89
94
|
async getStakingsByChains(chains) {
|
|
90
95
|
return this.stores.staking.getStakingsByChains(chains);
|
|
91
96
|
}
|
|
92
97
|
async getPooledStakings(addresses, chainHashes) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
98
|
+
// this.logger.log('Get Pooled Stakings: ', stakings);
|
|
99
|
+
|
|
100
|
+
return this.stores.staking.getPooledStakings(addresses, chainHashes);
|
|
96
101
|
}
|
|
97
102
|
subscribeStaking(addresses, chainList, callback) {
|
|
98
103
|
this.stakingSubscription && this.stakingSubscription.unsubscribe();
|
|
@@ -114,18 +119,18 @@ export default class DatabaseService {
|
|
|
114
119
|
|
|
115
120
|
// Transaction histories
|
|
116
121
|
async getHistories(query) {
|
|
117
|
-
|
|
118
|
-
this.logger.log('Get histories: ', histories);
|
|
119
|
-
return histories;
|
|
122
|
+
return this.stores.transaction.queryHistory(query);
|
|
120
123
|
}
|
|
121
124
|
async upsertHistory(histories) {
|
|
122
|
-
this.logger.log('Updating transaction histories');
|
|
125
|
+
// this.logger.log('Updating transaction histories');
|
|
126
|
+
|
|
123
127
|
return this.stores.transaction.bulkUpsert(histories);
|
|
124
128
|
}
|
|
125
129
|
|
|
126
130
|
// NFT Collection
|
|
127
131
|
async addNftCollection(collection) {
|
|
128
|
-
this.logger.log(`Updating NFT collection for [${collection.chain}]`);
|
|
132
|
+
// this.logger.log(`Updating NFT collection for [${collection.chain}]`);
|
|
133
|
+
|
|
129
134
|
return this.stores.nftCollection.upsert(collection);
|
|
130
135
|
}
|
|
131
136
|
async deleteNftCollection(chain, collectionId) {
|
|
@@ -144,13 +149,19 @@ export default class DatabaseService {
|
|
|
144
149
|
});
|
|
145
150
|
return this.nftSubscription;
|
|
146
151
|
}
|
|
152
|
+
async cleanUpNft(chain, owner, collectionId, nftIds) {
|
|
153
|
+
const result = await this.stores.nft.cleanUpNfts(chain, reformatAddress(owner, 42), collectionId, nftIds);
|
|
154
|
+
result > 0 && console.debug(`Clean up ${result} NFTs from collection ${collectionId} on chain ${chain} for owner ${owner}`);
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
147
157
|
async getNft(addresses, chainHashes) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return
|
|
158
|
+
// this.logger.log('Get NFTs: ', nfts);
|
|
159
|
+
|
|
160
|
+
return this.stores.nft.getNft(addresses, chainHashes);
|
|
151
161
|
}
|
|
152
162
|
async addNft(address, nft) {
|
|
153
|
-
this.logger.log(`Updating NFT for [${nft.chain}]`);
|
|
163
|
+
// this.logger.log(`Updating NFT for [${nft.chain}]`);
|
|
164
|
+
|
|
154
165
|
return this.stores.nft.upsert({
|
|
155
166
|
...nft,
|
|
156
167
|
address
|
|
@@ -160,47 +171,54 @@ export default class DatabaseService {
|
|
|
160
171
|
return this.stores.nft.deleteNftItem(chain, addresses, nftItem);
|
|
161
172
|
}
|
|
162
173
|
removeNfts(chain, address, collectionId, nftIds) {
|
|
163
|
-
this.logger.log(`Remove NFTs [${nftIds.join(', ')}]`);
|
|
174
|
+
// this.logger.log(`Remove NFTs [${nftIds.join(', ')}]`);
|
|
175
|
+
|
|
164
176
|
return this.stores.nft.removeNfts(chain, address, collectionId, nftIds);
|
|
165
177
|
}
|
|
166
178
|
|
|
167
179
|
// Chain
|
|
168
180
|
async updateChainStore(item) {
|
|
169
|
-
this.logger.log(`Updating storageInfo for chain [${item.slug}]`);
|
|
181
|
+
// this.logger.log(`Updating storageInfo for chain [${item.slug}]`);
|
|
182
|
+
|
|
170
183
|
return this.stores.chain.upsert(item);
|
|
171
184
|
}
|
|
172
185
|
async bulkUpdateChainStore(data) {
|
|
173
|
-
this.logger.log('Bulk updating ChainStore');
|
|
186
|
+
// this.logger.log('Bulk updating ChainStore');
|
|
187
|
+
|
|
174
188
|
return this.stores.chain.bulkUpsert(data);
|
|
175
189
|
}
|
|
176
190
|
async removeFromChainStore(chains) {
|
|
177
|
-
this.logger.log('Bulk removing ChainStore');
|
|
191
|
+
// this.logger.log('Bulk removing ChainStore');
|
|
192
|
+
|
|
178
193
|
return this.stores.chain.removeChains(chains);
|
|
179
194
|
}
|
|
180
195
|
async getAllChainStore() {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return
|
|
196
|
+
// this.logger.log('Get all chains: ', allChains);
|
|
197
|
+
|
|
198
|
+
return this.stores.chain.getAll();
|
|
184
199
|
}
|
|
185
200
|
|
|
186
201
|
// Asset
|
|
187
202
|
async updateAssetStore(item) {
|
|
188
|
-
this.logger.log(`Updating storageInfo for chainAsset [${item.originChain}]`);
|
|
203
|
+
// this.logger.log(`Updating storageInfo for chainAsset [${item.originChain}]`);
|
|
204
|
+
|
|
189
205
|
return this.stores.asset.upsert(item);
|
|
190
206
|
}
|
|
191
207
|
async getAllAssetStore() {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return
|
|
208
|
+
// this.logger.log('Get all stored assets: ', allAssets);
|
|
209
|
+
|
|
210
|
+
return this.stores.asset.getAll();
|
|
195
211
|
}
|
|
196
212
|
async removeFromAssetStore(items) {
|
|
197
|
-
this.logger.log('Bulk removing AssetStore');
|
|
213
|
+
// this.logger.log('Bulk removing AssetStore');
|
|
214
|
+
|
|
198
215
|
return this.stores.asset.removeAssets(items);
|
|
199
216
|
}
|
|
200
217
|
|
|
201
218
|
// Staking
|
|
202
219
|
async updateChainStakingMetadata(item) {
|
|
203
|
-
this.logger.log('Update ChainStakingMetadata: ', item.chain);
|
|
220
|
+
// this.logger.log('Update ChainStakingMetadata: ', item.chain);
|
|
221
|
+
|
|
204
222
|
return this.stores.chainStakingMetadata.upsert(item);
|
|
205
223
|
}
|
|
206
224
|
async getChainStakingMetadata() {
|
|
@@ -210,7 +228,8 @@ export default class DatabaseService {
|
|
|
210
228
|
return this.stores.chainStakingMetadata.getByChainAndType(chain, type);
|
|
211
229
|
}
|
|
212
230
|
async updateNominatorMetadata(item) {
|
|
213
|
-
this.logger.log('Update NominatorMetadata: ', item.address, item.chain);
|
|
231
|
+
// this.logger.log('Update NominatorMetadata: ', item.address, item.chain);
|
|
232
|
+
|
|
214
233
|
return this.stores.nominatorMetadata.upsert(item);
|
|
215
234
|
}
|
|
216
235
|
async getNominatorMetadata() {
|
|
@@ -4,8 +4,7 @@ import { INft } from '../databases';
|
|
|
4
4
|
export default class NftStore extends BaseStoreWithAddressAndChain<INft> {
|
|
5
5
|
getNft(addresses: string[], chainList?: string[]): import("dexie").PromiseExtended<INft[]>;
|
|
6
6
|
subscribeNft(addresses: string[], chainList?: string[]): import("dexie").Observable<INft[]>;
|
|
7
|
-
|
|
8
|
-
deleteNftsFromRemovedCollection(chain: string, address: string, collectionIds: string[]): import("dexie").Collection<INft, unknown>;
|
|
7
|
+
cleanUpNfts(chain: string, address: string, collectionId: string, nftIds: string[]): import("dexie").PromiseExtended<number>;
|
|
9
8
|
deleteNftByAddress(addresses: string[]): import("dexie").PromiseExtended<number>;
|
|
10
9
|
deleteNftItem(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
|
|
11
10
|
deleteNftsByCollection(chain: string, collectionId: string): import("dexie").PromiseExtended<number>;
|
|
@@ -15,24 +15,12 @@ export default class NftStore extends BaseStoreWithAddressAndChain {
|
|
|
15
15
|
subscribeNft(addresses, chainList = []) {
|
|
16
16
|
return liveQuery(() => this.getNft(addresses, chainList));
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
const conditions = {
|
|
20
|
-
chainHash,
|
|
21
|
-
address
|
|
22
|
-
};
|
|
23
|
-
if (!collection && nftIds && nftIds.length) {
|
|
24
|
-
return this.logger.warn('Missing collection id');
|
|
25
|
-
}
|
|
26
|
-
if (collection) {
|
|
27
|
-
conditions.collectionId = collection;
|
|
28
|
-
}
|
|
29
|
-
return this.table.where(conditions).and(item => !nftIds.some(nft => nft === item.id)).delete();
|
|
30
|
-
}
|
|
31
|
-
deleteNftsFromRemovedCollection(chain, address, collectionIds) {
|
|
18
|
+
cleanUpNfts(chain, address, collectionId, nftIds) {
|
|
32
19
|
return this.table.where({
|
|
33
20
|
address,
|
|
34
|
-
chain
|
|
35
|
-
|
|
21
|
+
chain,
|
|
22
|
+
collectionId
|
|
23
|
+
}).and(nft => !nftIds.includes(nft.id)).delete();
|
|
36
24
|
}
|
|
37
25
|
deleteNftByAddress(addresses) {
|
|
38
26
|
return this.table.where('address').anyOfIgnoreCase(addresses).delete();
|
|
@@ -1,45 +1,30 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { _getAssetDecimals, _getChainNativeTokenBasicInfo
|
|
4
|
+
import { _getAssetDecimals, _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
5
|
export function parseXcmEventLogs(historyItem, eventLogs, chain, sendingTokenInfo, chainInfo) {
|
|
6
|
-
let isFeeUseMainTokenSymbol = true;
|
|
7
6
|
for (let index = 0; index < eventLogs.length; index++) {
|
|
8
7
|
const record = eventLogs[index];
|
|
9
|
-
if (['karura', 'acala', 'acala_testnet'].includes(chain) && sendingTokenInfo && !_isNativeToken(sendingTokenInfo)) {
|
|
10
|
-
if (record.event.section === 'currencies' && record.event.method.toLowerCase() === 'transferred') {
|
|
11
|
-
if (index === 0) {
|
|
12
|
-
var _record$event$data$;
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
14
|
-
historyItem.fee = {
|
|
15
|
-
value: ((_record$event$data$ = record.event.data[3]) === null || _record$event$data$ === void 0 ? void 0 : _record$event$data$.toString()) || '0',
|
|
16
|
-
symbol: sendingTokenInfo.symbol,
|
|
17
|
-
decimals: _getAssetDecimals(sendingTokenInfo)
|
|
18
|
-
};
|
|
19
|
-
isFeeUseMainTokenSymbol = false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
8
|
const {
|
|
24
9
|
decimals: nativeDecimals,
|
|
25
10
|
symbol: nativeSymbol
|
|
26
11
|
} = _getChainNativeTokenBasicInfo(chainInfo);
|
|
27
|
-
if (
|
|
28
|
-
var _record$event$data
|
|
29
|
-
if ((_record$event$data$
|
|
30
|
-
var _record$event$data$
|
|
12
|
+
if (record.event.section === 'balances' && record.event.method.toLowerCase() === 'withdraw') {
|
|
13
|
+
var _record$event$data$;
|
|
14
|
+
if ((_record$event$data$ = record.event.data[1]) !== null && _record$event$data$ !== void 0 && _record$event$data$.toString()) {
|
|
15
|
+
var _record$event$data$2;
|
|
31
16
|
historyItem.fee = {
|
|
32
|
-
value: (_record$event$data$
|
|
17
|
+
value: (_record$event$data$2 = record.event.data[1]) === null || _record$event$data$2 === void 0 ? void 0 : _record$event$data$2.toString(),
|
|
33
18
|
symbol: nativeSymbol,
|
|
34
19
|
decimals: nativeDecimals
|
|
35
20
|
};
|
|
36
21
|
}
|
|
37
|
-
} else if (
|
|
38
|
-
var _record$event$data$
|
|
39
|
-
if ((_record$event$data$
|
|
40
|
-
var _record$event$data$
|
|
22
|
+
} else if (record.event.section === 'tokens' && record.event.method.toLowerCase() === 'withdrawn') {
|
|
23
|
+
var _record$event$data$3;
|
|
24
|
+
if (!historyItem.fee && (_record$event$data$3 = record.event.data[2]) !== null && _record$event$data$3 !== void 0 && _record$event$data$3.toString()) {
|
|
25
|
+
var _record$event$data$4;
|
|
41
26
|
historyItem.fee = {
|
|
42
|
-
value: (_record$event$data$
|
|
27
|
+
value: (_record$event$data$4 = record.event.data[2]) === null || _record$event$data$4 === void 0 ? void 0 : _record$event$data$4.toString(),
|
|
43
28
|
symbol: nativeSymbol,
|
|
44
29
|
decimals: nativeDecimals
|
|
45
30
|
};
|
|
@@ -48,28 +33,15 @@ export function parseXcmEventLogs(historyItem, eventLogs, chain, sendingTokenInf
|
|
|
48
33
|
}
|
|
49
34
|
}
|
|
50
35
|
export function parseTransferEventLogs(historyItem, eventLogs, chain, sendingTokenInfo, chainInfo) {
|
|
51
|
-
let isFeeUseMainTokenSymbol = true;
|
|
52
36
|
for (let index = 0; index < eventLogs.length; index++) {
|
|
53
37
|
const record = eventLogs[index];
|
|
54
|
-
if (['
|
|
55
|
-
if (record.event.section === 'currencies' && record.event.method.toLowerCase() === 'transferred') {
|
|
56
|
-
if (index === 0) {
|
|
57
|
-
var _record$event$data$6;
|
|
58
|
-
historyItem.fee = {
|
|
59
|
-
value: ((_record$event$data$6 = record.event.data[3]) === null || _record$event$data$6 === void 0 ? void 0 : _record$event$data$6.toString()) || '0',
|
|
60
|
-
symbol: sendingTokenInfo.symbol,
|
|
61
|
-
decimals: _getAssetDecimals(sendingTokenInfo)
|
|
62
|
-
};
|
|
63
|
-
isFeeUseMainTokenSymbol = false;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} else if (['genshiro_testnet', 'genshiro', 'equilibrium_parachain'].includes(chain) && sendingTokenInfo) {
|
|
38
|
+
if (['genshiro_testnet', 'genshiro', 'equilibrium_parachain'].includes(chain) && sendingTokenInfo) {
|
|
67
39
|
if (record.event.section === 'transactionPayment' && record.event.method.toLowerCase() === 'transactionfeepaid') {
|
|
68
|
-
var _record$event$data$
|
|
69
|
-
if ((_record$event$data$
|
|
70
|
-
var _record$event$data$
|
|
40
|
+
var _record$event$data$5;
|
|
41
|
+
if ((_record$event$data$5 = record.event.data[1]) !== null && _record$event$data$5 !== void 0 && _record$event$data$5.toString()) {
|
|
42
|
+
var _record$event$data$6;
|
|
71
43
|
historyItem.fee = {
|
|
72
|
-
value: ((_record$event$data$
|
|
44
|
+
value: ((_record$event$data$6 = record.event.data[1]) === null || _record$event$data$6 === void 0 ? void 0 : _record$event$data$6.toString()) || '0',
|
|
73
45
|
symbol: sendingTokenInfo.symbol,
|
|
74
46
|
decimals: _getAssetDecimals(sendingTokenInfo)
|
|
75
47
|
};
|
|
@@ -80,13 +52,13 @@ export function parseTransferEventLogs(historyItem, eventLogs, chain, sendingTok
|
|
|
80
52
|
decimals: nativeDecimals,
|
|
81
53
|
symbol: nativeSymbol
|
|
82
54
|
} = _getChainNativeTokenBasicInfo(chainInfo);
|
|
83
|
-
if (
|
|
84
|
-
var _record$event$data$
|
|
85
|
-
if ((_record$event$data$
|
|
86
|
-
var _record$event$data$
|
|
55
|
+
if (record.event.section === 'balances' && record.event.method.toLowerCase() === 'withdraw') {
|
|
56
|
+
var _record$event$data$7;
|
|
57
|
+
if ((_record$event$data$7 = record.event.data[1]) !== null && _record$event$data$7 !== void 0 && _record$event$data$7.toString()) {
|
|
58
|
+
var _record$event$data$8;
|
|
87
59
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
88
60
|
historyItem.fee = {
|
|
89
|
-
value: ((_record$event$data$
|
|
61
|
+
value: ((_record$event$data$8 = record.event.data[1]) === null || _record$event$data$8 === void 0 ? void 0 : _record$event$data$8.toString()) || '0',
|
|
90
62
|
symbol: nativeSymbol,
|
|
91
63
|
decimals: nativeDecimals
|
|
92
64
|
};
|