@subwallet/extension-base 1.0.2-2 → 1.0.2-3
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 +46 -38
- package/background/KoniTypes.js +8 -8
- package/background/errors/TransactionError.js +25 -1
- package/background/types.d.ts +10 -5
- package/cjs/background/KoniTypes.js +8 -8
- package/cjs/background/errors/TransactionError.js +24 -0
- package/cjs/constants/index.js +8 -26
- package/cjs/koni/api/dotsama/balance.js +49 -224
- package/cjs/koni/api/dotsama/transfer.js +34 -39
- package/cjs/koni/api/nft/acala_nft/index.js +7 -7
- package/cjs/koni/api/nft/bit.country/index.js +7 -6
- package/cjs/koni/api/nft/evm_nft/index.js +8 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +7 -6
- package/cjs/koni/api/nft/rmrk_nft/index.js +11 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +7 -6
- package/cjs/koni/api/nft/unique_nft/index.js +5 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +170 -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 +122 -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 +171 -61
- package/cjs/koni/background/handlers/Extension.js +382 -207
- package/cjs/koni/background/handlers/State.js +41 -33
- package/cjs/koni/background/handlers/Tabs.js +50 -17
- package/cjs/koni/background/subscription.js +32 -29
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/index.js +59 -45
- 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 +19 -13
- package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
- package/cjs/services/keyring-service/index.js +11 -13
- 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 +13 -7
- package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
- package/cjs/services/request-service/index.js +14 -5
- package/cjs/services/storage-service/DatabaseService.js +56 -34
- package/cjs/services/storage-service/db-stores/Nft.js +7 -15
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +26 -15
- package/cjs/utils/address.js +10 -1
- package/cjs/utils/index.js +9 -15
- 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 +11 -16
- package/koni/api/nft/acala_nft/index.js +7 -7
- package/koni/api/nft/bit.country/index.js +7 -6
- package/koni/api/nft/evm_nft/index.js +7 -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 +7 -6
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +11 -1
- package/koni/api/nft/statemine_nft/index.js +7 -6
- 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 +168 -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 +121 -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 +172 -62
- package/koni/background/handlers/Extension.d.ts +8 -3
- package/koni/background/handlers/Extension.js +297 -126
- package/koni/background/handlers/State.d.ts +5 -6
- package/koni/background/handlers/State.js +43 -33
- package/koni/background/handlers/Tabs.js +50 -17
- package/koni/background/subscription.js +31 -30
- package/package.json +18 -13
- package/packageInfo.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
- 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.d.ts +3 -2
- package/services/chain-service/index.js +53 -40
- package/services/chain-service/types.d.ts +1 -0
- 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 +4 -2
- package/services/history-service/index.js +19 -13
- package/services/history-service/subsquid-multi-chain-history.js +16 -12
- package/services/keyring-service/index.d.ts +4 -2
- package/services/keyring-service/index.js +11 -13
- package/services/price-service/coingecko.js +0 -1
- package/services/price-service/index.js +2 -3
- package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
- package/services/request-service/handler/AuthRequestHandler.js +13 -7
- package/services/request-service/handler/EvmRequestHandler.js +8 -12
- package/services/request-service/index.d.ts +3 -1
- package/services/request-service/index.js +14 -5
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +56 -34
- package/services/storage-service/db-stores/Nft.d.ts +2 -2
- package/services/storage-service/db-stores/Nft.js +7 -14
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.js +26 -15
- package/utils/address.d.ts +3 -0
- package/utils/address.js +8 -1
- package/utils/index.d.ts +2 -2
- package/utils/index.js +7 -13
|
@@ -67,16 +67,7 @@ export default class EvmRequestHandler {
|
|
|
67
67
|
});
|
|
68
68
|
this.confirmationsQueueSubject.next(confirmations);
|
|
69
69
|
if (!isInternal) {
|
|
70
|
-
|
|
71
|
-
const popupList = this.#requestService.popup;
|
|
72
|
-
if (this.#requestService.popup.length > 0) {
|
|
73
|
-
// eslint-disable-next-line no-void
|
|
74
|
-
void chrome.windows.update(popupList[0], {
|
|
75
|
-
focused: true
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
this.#requestService.popupOpen();
|
|
79
|
-
}
|
|
70
|
+
this.#requestService.popupOpen();
|
|
80
71
|
}
|
|
81
72
|
this.#requestService.updateIconV2();
|
|
82
73
|
return promise;
|
|
@@ -127,7 +118,8 @@ export default class EvmRequestHandler {
|
|
|
127
118
|
data: toBuffer(config.data)
|
|
128
119
|
};
|
|
129
120
|
const common = Common.custom({
|
|
130
|
-
chainId: config.chainId
|
|
121
|
+
chainId: config.chainId,
|
|
122
|
+
defaultHardfork: 'petersburg'
|
|
131
123
|
});
|
|
132
124
|
|
|
133
125
|
// @ts-ignore
|
|
@@ -140,11 +132,15 @@ export default class EvmRequestHandler {
|
|
|
140
132
|
const {
|
|
141
133
|
estimateGas,
|
|
142
134
|
from,
|
|
143
|
-
|
|
135
|
+
gas,
|
|
136
|
+
gasPrice,
|
|
137
|
+
value
|
|
144
138
|
} = transaction;
|
|
145
139
|
const pair = keyring.getPair(from);
|
|
146
140
|
const params = {
|
|
147
141
|
...transaction,
|
|
142
|
+
gas: anyNumberToBN(gas).toNumber(),
|
|
143
|
+
value: anyNumberToBN(value).toNumber(),
|
|
148
144
|
gasPrice: anyNumberToBN(gasPrice).toNumber(),
|
|
149
145
|
gasLimit: anyNumberToBN(estimateGas).toNumber()
|
|
150
146
|
// nonce: await web3.eth.getTransactionCount(from) // Todo: fill this value from transaction service
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AuthRequestV2, ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationType, RequestConfirmationComplete } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { AccountAuthType, AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestSign, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
|
|
3
3
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
|
+
import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
|
|
4
5
|
import { AuthUrls, MetaRequest } from '@subwallet/extension-base/services/request-service/types';
|
|
5
6
|
import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
|
|
6
7
|
import { MetadataDef } from '@subwallet/extension-inject/types';
|
|
@@ -8,8 +9,9 @@ import { BehaviorSubject, Subject } from 'rxjs';
|
|
|
8
9
|
import { SignerPayloadJSON } from '@polkadot/types/types/extrinsic';
|
|
9
10
|
export default class RequestService {
|
|
10
11
|
#private;
|
|
12
|
+
private keyringService;
|
|
11
13
|
readonly settingService: SettingService;
|
|
12
|
-
constructor(chainService: ChainService, settingService: SettingService);
|
|
14
|
+
constructor(chainService: ChainService, settingService: SettingService, keyringService: KeyringService);
|
|
13
15
|
get numAllRequests(): number;
|
|
14
16
|
updateIconV2(shouldClose?: boolean): void;
|
|
15
17
|
getAddressList(value?: boolean): Record<string, boolean>;
|
|
@@ -6,7 +6,6 @@ import EvmRequestHandler from '@subwallet/extension-base/services/request-servic
|
|
|
6
6
|
import MetadataRequestHandler from '@subwallet/extension-base/services/request-service/handler/MetadataRequestHandler';
|
|
7
7
|
import PopupHandler from '@subwallet/extension-base/services/request-service/handler/PopupHandler';
|
|
8
8
|
import SubstrateRequestHandler from '@subwallet/extension-base/services/request-service/handler/SubstrateRequestHandler';
|
|
9
|
-
import { accounts } from '@subwallet/ui-keyring/observable/accounts';
|
|
10
9
|
export default class RequestService {
|
|
11
10
|
// Common
|
|
12
11
|
#chainService;
|
|
@@ -17,12 +16,13 @@ export default class RequestService {
|
|
|
17
16
|
#evmRequestHandler;
|
|
18
17
|
|
|
19
18
|
// Common
|
|
20
|
-
constructor(chainService, settingService) {
|
|
19
|
+
constructor(chainService, settingService, keyringService) {
|
|
20
|
+
this.keyringService = keyringService;
|
|
21
21
|
this.#chainService = chainService;
|
|
22
22
|
this.settingService = settingService;
|
|
23
23
|
this.#popupHandler = new PopupHandler(this);
|
|
24
24
|
this.#metadataRequestHandler = new MetadataRequestHandler(this);
|
|
25
|
-
this.#authRequestHandler = new AuthRequestHandler(this, this.#chainService);
|
|
25
|
+
this.#authRequestHandler = new AuthRequestHandler(this, this.#chainService, this.keyringService);
|
|
26
26
|
this.#substrateRequestHandler = new SubstrateRequestHandler(this);
|
|
27
27
|
this.#evmRequestHandler = new EvmRequestHandler(this);
|
|
28
28
|
|
|
@@ -36,7 +36,7 @@ export default class RequestService {
|
|
|
36
36
|
this.#popupHandler.updateIconV2(shouldClose);
|
|
37
37
|
}
|
|
38
38
|
getAddressList(value = false) {
|
|
39
|
-
const addressList = Object.keys(
|
|
39
|
+
const addressList = Object.keys(this.keyringService.accounts);
|
|
40
40
|
return addressList.reduce((addressList, v) => ({
|
|
41
41
|
...addressList,
|
|
42
42
|
[v]: value
|
|
@@ -51,7 +51,16 @@ export default class RequestService {
|
|
|
51
51
|
this.#popupHandler.popupClose();
|
|
52
52
|
}
|
|
53
53
|
popupOpen() {
|
|
54
|
-
|
|
54
|
+
// Not open new popup and use existed
|
|
55
|
+
const popupList = this.#popupHandler.popup;
|
|
56
|
+
if (popupList && popupList.length > 0) {
|
|
57
|
+
var _chrome$windows$updat;
|
|
58
|
+
(_chrome$windows$updat = chrome.windows.update(popupList[0], {
|
|
59
|
+
focused: true
|
|
60
|
+
})) === null || _chrome$windows$updat === void 0 ? void 0 : _chrome$windows$updat.catch(console.error);
|
|
61
|
+
} else {
|
|
62
|
+
this.#popupHandler.popupOpen();
|
|
63
|
+
}
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
// Metadata
|
|
@@ -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, collectionIds: string[], nftIds: string[], ownNothing?: boolean): 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');
|
|
123
|
-
|
|
125
|
+
// this.logger.log('Updating transaction histories');
|
|
126
|
+
const cleanedHistory = histories.filter(x => x && x.address && x.chain && x.extrinsicHash);
|
|
127
|
+
return this.stores.transaction.bulkUpsert(cleanedHistory);
|
|
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,22 @@ export default class DatabaseService {
|
|
|
144
149
|
});
|
|
145
150
|
return this.nftSubscription;
|
|
146
151
|
}
|
|
152
|
+
async cleanUpNft(chain, owner, collectionIds, nftIds, ownNothing) {
|
|
153
|
+
if (ownNothing) {
|
|
154
|
+
return this.stores.nft.deleteNftsByChainAndOwner(chain, reformatAddress(owner, 42));
|
|
155
|
+
}
|
|
156
|
+
const result = await this.stores.nft.cleanUpNfts(chain, reformatAddress(owner, 42), collectionIds, nftIds);
|
|
157
|
+
result > 0 && console.debug(`Cleaned up ${result} NFTs on chain ${chain} for owner ${reformatAddress(owner, 42)}`, collectionIds, nftIds);
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
147
160
|
async getNft(addresses, chainHashes) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return
|
|
161
|
+
// this.logger.log('Get NFTs: ', nfts);
|
|
162
|
+
|
|
163
|
+
return this.stores.nft.getNft(addresses, chainHashes);
|
|
151
164
|
}
|
|
152
165
|
async addNft(address, nft) {
|
|
153
|
-
this.logger.log(`Updating NFT for [${nft.chain}]`);
|
|
166
|
+
// this.logger.log(`Updating NFT for [${nft.chain}]`);
|
|
167
|
+
|
|
154
168
|
return this.stores.nft.upsert({
|
|
155
169
|
...nft,
|
|
156
170
|
address
|
|
@@ -160,47 +174,54 @@ export default class DatabaseService {
|
|
|
160
174
|
return this.stores.nft.deleteNftItem(chain, addresses, nftItem);
|
|
161
175
|
}
|
|
162
176
|
removeNfts(chain, address, collectionId, nftIds) {
|
|
163
|
-
this.logger.log(`Remove NFTs [${nftIds.join(', ')}]`);
|
|
177
|
+
// this.logger.log(`Remove NFTs [${nftIds.join(', ')}]`);
|
|
178
|
+
|
|
164
179
|
return this.stores.nft.removeNfts(chain, address, collectionId, nftIds);
|
|
165
180
|
}
|
|
166
181
|
|
|
167
182
|
// Chain
|
|
168
183
|
async updateChainStore(item) {
|
|
169
|
-
this.logger.log(`Updating storageInfo for chain [${item.slug}]`);
|
|
184
|
+
// this.logger.log(`Updating storageInfo for chain [${item.slug}]`);
|
|
185
|
+
|
|
170
186
|
return this.stores.chain.upsert(item);
|
|
171
187
|
}
|
|
172
188
|
async bulkUpdateChainStore(data) {
|
|
173
|
-
this.logger.log('Bulk updating ChainStore');
|
|
189
|
+
// this.logger.log('Bulk updating ChainStore');
|
|
190
|
+
|
|
174
191
|
return this.stores.chain.bulkUpsert(data);
|
|
175
192
|
}
|
|
176
193
|
async removeFromChainStore(chains) {
|
|
177
|
-
this.logger.log('Bulk removing ChainStore');
|
|
194
|
+
// this.logger.log('Bulk removing ChainStore');
|
|
195
|
+
|
|
178
196
|
return this.stores.chain.removeChains(chains);
|
|
179
197
|
}
|
|
180
198
|
async getAllChainStore() {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return
|
|
199
|
+
// this.logger.log('Get all chains: ', allChains);
|
|
200
|
+
|
|
201
|
+
return this.stores.chain.getAll();
|
|
184
202
|
}
|
|
185
203
|
|
|
186
204
|
// Asset
|
|
187
205
|
async updateAssetStore(item) {
|
|
188
|
-
this.logger.log(`Updating storageInfo for chainAsset [${item.originChain}]`);
|
|
206
|
+
// this.logger.log(`Updating storageInfo for chainAsset [${item.originChain}]`);
|
|
207
|
+
|
|
189
208
|
return this.stores.asset.upsert(item);
|
|
190
209
|
}
|
|
191
210
|
async getAllAssetStore() {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return
|
|
211
|
+
// this.logger.log('Get all stored assets: ', allAssets);
|
|
212
|
+
|
|
213
|
+
return this.stores.asset.getAll();
|
|
195
214
|
}
|
|
196
215
|
async removeFromAssetStore(items) {
|
|
197
|
-
this.logger.log('Bulk removing AssetStore');
|
|
216
|
+
// this.logger.log('Bulk removing AssetStore');
|
|
217
|
+
|
|
198
218
|
return this.stores.asset.removeAssets(items);
|
|
199
219
|
}
|
|
200
220
|
|
|
201
221
|
// Staking
|
|
202
222
|
async updateChainStakingMetadata(item) {
|
|
203
|
-
this.logger.log('Update ChainStakingMetadata: ', item.chain);
|
|
223
|
+
// this.logger.log('Update ChainStakingMetadata: ', item.chain);
|
|
224
|
+
|
|
204
225
|
return this.stores.chainStakingMetadata.upsert(item);
|
|
205
226
|
}
|
|
206
227
|
async getChainStakingMetadata() {
|
|
@@ -210,7 +231,8 @@ export default class DatabaseService {
|
|
|
210
231
|
return this.stores.chainStakingMetadata.getByChainAndType(chain, type);
|
|
211
232
|
}
|
|
212
233
|
async updateNominatorMetadata(item) {
|
|
213
|
-
this.logger.log('Update NominatorMetadata: ', item.address, item.chain);
|
|
234
|
+
// this.logger.log('Update NominatorMetadata: ', item.address, item.chain);
|
|
235
|
+
|
|
214
236
|
return this.stores.nominatorMetadata.upsert(item);
|
|
215
237
|
}
|
|
216
238
|
async getNominatorMetadata() {
|
|
@@ -4,8 +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
|
-
|
|
8
|
-
|
|
7
|
+
cleanUpNfts(chain: string, address: string, collectionIds: string[], nftIds: string[]): import("dexie").PromiseExtended<number>;
|
|
8
|
+
deleteNftsByChainAndOwner(chain: string, address: string): import("dexie").PromiseExtended<number>;
|
|
9
9
|
deleteNftByAddress(addresses: string[]): import("dexie").PromiseExtended<number>;
|
|
10
10
|
deleteNftItem(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
|
|
11
11
|
deleteNftsByCollection(chain: string, collectionId: string): import("dexie").PromiseExtended<number>;
|
|
@@ -15,24 +15,17 @@ export default class NftStore extends BaseStoreWithAddressAndChain {
|
|
|
15
15
|
subscribeNft(addresses, chainList = []) {
|
|
16
16
|
return liveQuery(() => this.getNft(addresses, chainList));
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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();
|
|
18
|
+
cleanUpNfts(chain, address, collectionIds, nftIds) {
|
|
19
|
+
return this.table.where({
|
|
20
|
+
address,
|
|
21
|
+
chain
|
|
22
|
+
}).and(nft => !collectionIds.includes(nft.collectionId) || collectionIds.includes(nft.collectionId) && !nftIds.includes(nft.id)).delete();
|
|
30
23
|
}
|
|
31
|
-
|
|
24
|
+
deleteNftsByChainAndOwner(chain, address) {
|
|
32
25
|
return this.table.where({
|
|
33
26
|
address,
|
|
34
27
|
chain
|
|
35
|
-
}).
|
|
28
|
+
}).delete();
|
|
36
29
|
}
|
|
37
30
|
deleteNftByAddress(addresses) {
|
|
38
31
|
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
|
};
|
|
@@ -180,7 +180,6 @@ export default class TransactionService {
|
|
|
180
180
|
this.transactionSubject.next({
|
|
181
181
|
...transactions
|
|
182
182
|
});
|
|
183
|
-
console.log(transaction);
|
|
184
183
|
|
|
185
184
|
// Send transaction
|
|
186
185
|
return await this.sendTransaction(transaction);
|
|
@@ -427,11 +426,11 @@ export default class TransactionService {
|
|
|
427
426
|
}
|
|
428
427
|
try {
|
|
429
428
|
// Return one more history record if transaction send to account in the wallets
|
|
430
|
-
const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && keyring.
|
|
429
|
+
const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && keyring.getPair(historyItem.to);
|
|
431
430
|
if (toAccount) {
|
|
432
431
|
return [historyItem, {
|
|
433
432
|
...historyItem,
|
|
434
|
-
address:
|
|
433
|
+
address: toAccount.address,
|
|
435
434
|
direction: TransactionDirection.RECEIVED
|
|
436
435
|
}];
|
|
437
436
|
}
|
|
@@ -456,18 +455,27 @@ export default class TransactionService {
|
|
|
456
455
|
handlePostProcessing(id) {
|
|
457
456
|
// must be done after success/failure to make sure the transaction is finalized
|
|
458
457
|
const transaction = this.getTransaction(id);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
458
|
+
if (transaction.extrinsicType === ExtrinsicType.SEND_NFT) {
|
|
459
|
+
const inputData = parseTransactionData(transaction.data);
|
|
460
|
+
try {
|
|
461
|
+
const sender = keyring.getPair(inputData.senderAddress);
|
|
462
|
+
sender && this.databaseService.handleNftTransfer(transaction.chain, [sender.address, ALL_ACCOUNT_KEY], inputData.nftItem).then(() => {
|
|
463
|
+
this.eventService.emit('transaction.transferNft', undefined);
|
|
464
|
+
}).catch(console.error);
|
|
465
|
+
} catch (e) {
|
|
466
|
+
console.error(e);
|
|
467
|
+
}
|
|
468
|
+
try {
|
|
469
|
+
const recipient = keyring.getPair(inputData.recipientAddress);
|
|
470
|
+
recipient && this.databaseService.addNft(recipient.address, {
|
|
471
|
+
...inputData.nftItem,
|
|
472
|
+
owner: recipient.address
|
|
473
|
+
}).catch(console.error);
|
|
474
|
+
} catch (e) {
|
|
475
|
+
console.error(e);
|
|
476
|
+
}
|
|
477
|
+
} else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) {
|
|
478
|
+
this.eventService.emit('transaction.submitStaking', transaction.chain);
|
|
471
479
|
}
|
|
472
480
|
}
|
|
473
481
|
onSuccess({
|
|
@@ -576,6 +584,9 @@ export default class TransactionService {
|
|
|
576
584
|
payload.isToContract = isToContract;
|
|
577
585
|
payload.parseData = isToContract ? payload.data ? (await parseContractInput(payload.data || '', payload.to || '', chainInfo)).result : '' : payload.data || '';
|
|
578
586
|
}
|
|
587
|
+
if ('data' in payload && payload.data === undefined) {
|
|
588
|
+
delete payload.data;
|
|
589
|
+
}
|
|
579
590
|
|
|
580
591
|
// Set unique nonce to avoid transaction errors
|
|
581
592
|
if (!payload.nonce) {
|
package/utils/address.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { AddressJson } from '@subwallet/extension-base/background/types';
|
|
2
|
+
import { SubjectInfo } from '@subwallet/ui-keyring/observable/types';
|
|
1
3
|
export declare const simpleAddress: (address: string) => string;
|
|
2
4
|
export declare function quickFormatAddressToCompare(address?: string): string | undefined;
|
|
5
|
+
export declare const convertSubjectInfoToAddresses: (subjectInfo: SubjectInfo) => AddressJson[];
|
package/utils/address.js
CHANGED
|
@@ -14,4 +14,11 @@ export function quickFormatAddressToCompare(address) {
|
|
|
14
14
|
return address;
|
|
15
15
|
}
|
|
16
16
|
return reformatAddress(address, 42).toLowerCase();
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
|
+
export const convertSubjectInfoToAddresses = subjectInfo => {
|
|
19
|
+
return Object.values(subjectInfo).map(info => ({
|
|
20
|
+
address: info.json.address,
|
|
21
|
+
type: info.type,
|
|
22
|
+
...info.json.meta
|
|
23
|
+
}));
|
|
24
|
+
};
|
package/utils/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const isDef: (x: any) => boolean;
|
|
|
8
8
|
export declare const nonEmptyArr: (x: any) => boolean;
|
|
9
9
|
export declare const isEmptyArray: (x: any) => boolean;
|
|
10
10
|
export declare function isAccountAll(address?: string): boolean;
|
|
11
|
-
export declare function reformatAddress(address: string, networkPrefix
|
|
11
|
+
export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean): string;
|
|
12
12
|
export declare function filterAddressByNetworkKey(addresses: string[], networkKey: string, isEthereum?: boolean): string[];
|
|
13
13
|
export declare function categoryAddresses(addresses: string[]): string[][];
|
|
14
14
|
export declare function categoryNetworks(networks: NetworkJson[]): string[][];
|
|
@@ -34,6 +34,6 @@ export declare function mergeNetworkProviders(customNetwork: NetworkJson, predef
|
|
|
34
34
|
};
|
|
35
35
|
export declare const filterAndSortingAccountByAuthType: (accounts: AccountJson[], accountAuthType: AccountAuthType, sorting?: boolean) => AccountJson[];
|
|
36
36
|
export declare function parseRawNumber(value: string): number;
|
|
37
|
-
export declare function parseNumberToDisplay(amount: BN, decimals: number | undefined): string;
|
|
38
37
|
export declare function isSameAddress(address1: string, address2: string): boolean;
|
|
39
38
|
export declare function getDomainFromUrl(url: string): string;
|
|
39
|
+
export declare function waitTimeout(ms: number): Promise<void>;
|
package/utils/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { CrowdloanParaState } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
6
|
-
import BigNumber from 'bignumber.js';
|
|
7
6
|
import { BN, hexToU8a, isHex } from '@polkadot/util';
|
|
8
7
|
import { decodeAddress, encodeAddress, ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
|
|
9
8
|
export { canDerive } from "./canDerive.js";
|
|
@@ -14,7 +13,7 @@ export const isEmptyArray = x => !Array.isArray(x) || Array.isArray(x) && x.leng
|
|
|
14
13
|
export function isAccountAll(address) {
|
|
15
14
|
return address === ALL_ACCOUNT_KEY;
|
|
16
15
|
}
|
|
17
|
-
export function reformatAddress(address, networkPrefix, isEthereum = false) {
|
|
16
|
+
export function reformatAddress(address, networkPrefix = 42, isEthereum = false) {
|
|
18
17
|
try {
|
|
19
18
|
if (isEthereumAddress(address)) {
|
|
20
19
|
return address;
|
|
@@ -264,21 +263,16 @@ export const filterAndSortingAccountByAuthType = (accounts, accountAuthType, sor
|
|
|
264
263
|
export function parseRawNumber(value) {
|
|
265
264
|
return parseFloat(value.replaceAll(',', ''));
|
|
266
265
|
}
|
|
267
|
-
export function parseNumberToDisplay(amount, decimals) {
|
|
268
|
-
if (!decimals) {
|
|
269
|
-
return '0';
|
|
270
|
-
}
|
|
271
|
-
const parsedAmount = parseRawNumber(amount.toString());
|
|
272
|
-
const bigN = new BigNumber(parsedAmount / 10 ** decimals);
|
|
273
|
-
const roundedString = bigN.toFixed(9);
|
|
274
|
-
const formattedString = parseFloat(roundedString); // remove excess zeros at the end
|
|
275
|
-
|
|
276
|
-
return formattedString.toString();
|
|
277
|
-
}
|
|
278
266
|
export function isSameAddress(address1, address2) {
|
|
267
|
+
if (isEthereumAddress(address1)) {
|
|
268
|
+
return address1.toLowerCase() === address2.toLowerCase();
|
|
269
|
+
}
|
|
279
270
|
return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
|
|
280
271
|
}
|
|
281
272
|
|
|
282
273
|
export function getDomainFromUrl(url) {
|
|
283
274
|
return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
|
|
275
|
+
}
|
|
276
|
+
export async function waitTimeout(ms) {
|
|
277
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
284
278
|
}
|