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