@subwallet/extension-base 1.1.23-0 → 1.1.24-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +12 -26
- package/cjs/constants/index.js +9 -3
- package/cjs/koni/api/staking/bonding/index.js +1 -0
- package/cjs/koni/api/tokens/evm/balance.js +5 -1
- package/cjs/koni/api/tokens/evm/transfer.js +8 -4
- package/cjs/koni/background/cron.js +2 -2
- package/cjs/koni/background/handlers/Extension.js +14 -5
- package/cjs/koni/background/handlers/Mobile.js +32 -0
- package/cjs/koni/background/handlers/State.js +126 -45
- package/cjs/koni/background/subscription.js +2 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/group.js +53 -0
- package/cjs/services/balance-service/helpers/subscribe/balance.js +111 -0
- package/cjs/services/balance-service/helpers/subscribe/evm.js +95 -0
- package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +113 -0
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +324 -0
- package/cjs/services/balance-service/index.js +41 -16
- package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
- package/cjs/services/history-service/index.js +12 -8
- package/cjs/services/migration-service/scripts/MigrateProvider.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +47 -2
- package/cjs/services/storage-service/db-stores/Balance.js +9 -9
- package/cjs/services/subscan-service/index.js +66 -22
- package/cjs/services/transaction-service/index.js +4 -3
- package/cjs/types/balance.js +1 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/{address.js → account.js} +32 -2
- package/cjs/utils/eth.js +7 -2
- package/cjs/utils/index.js +12 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +2 -0
- package/koni/api/staking/bonding/index.js +1 -0
- package/koni/api/tokens/evm/balance.js +5 -1
- package/koni/api/tokens/evm/transfer.d.ts +1 -1
- package/koni/api/tokens/evm/transfer.js +8 -4
- package/koni/background/cron.js +3 -3
- package/koni/background/handlers/Extension.js +14 -5
- package/koni/background/handlers/Mobile.d.ts +5 -1
- package/koni/background/handlers/Mobile.js +31 -0
- package/koni/background/handlers/State.d.ts +6 -4
- package/koni/background/handlers/State.js +114 -34
- package/koni/background/subscription.js +2 -2
- package/package.json +40 -14
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/group.d.ts +9 -0
- package/services/balance-service/helpers/group.js +46 -0
- package/services/balance-service/helpers/subscribe/balance.d.ts +4 -0
- package/services/balance-service/helpers/subscribe/balance.js +103 -0
- package/services/balance-service/helpers/subscribe/evm.d.ts +5 -0
- package/services/balance-service/helpers/subscribe/evm.js +87 -0
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.d.ts +4 -0
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +105 -0
- package/services/balance-service/helpers/subscribe/substrate/index.d.ts +4 -0
- package/services/balance-service/helpers/subscribe/substrate/index.js +316 -0
- package/services/balance-service/index.d.ts +24 -5
- package/services/balance-service/index.js +40 -14
- package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
- package/services/history-service/index.js +12 -8
- package/services/migration-service/scripts/MigrateProvider.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +7 -2
- package/services/storage-service/DatabaseService.js +47 -2
- package/services/storage-service/databases/index.d.ts +2 -1
- package/services/storage-service/db-stores/Balance.d.ts +2 -2
- package/services/storage-service/db-stores/Balance.js +9 -9
- package/services/subscan-service/index.d.ts +11 -5
- package/services/subscan-service/index.js +66 -26
- package/services/subscan-service/types.d.ts +4 -0
- package/services/transaction-service/index.js +5 -4
- package/types/balance.d.ts +40 -0
- package/types/balance.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/account.d.ts +15 -0
- package/utils/{address.js → account.js} +28 -0
- package/utils/eth.d.ts +1 -0
- package/utils/eth.js +4 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/cjs/koni/api/dotsama/balance.js +0 -464
- package/koni/api/dotsama/balance.d.ts +0 -6
- package/koni/api/dotsama/balance.js +0 -451
- package/utils/address.d.ts +0 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
|
-
import {
|
|
2
|
+
import { ChainStakingMetadata, CrowdloanItem, MantaPayConfig, NftCollection, NftItem, NominatorMetadata, PriceJson, StakingItem, StakingType, TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
4
4
|
import { IBalance, ICampaign, IChain, INft } from '@subwallet/extension-base/services/storage-service/databases';
|
|
5
5
|
import { AssetStore, BalanceStore, ChainStore, CrowdloanStore, MetadataStore, MigrationStore, NftCollectionStore, NftStore, PriceStore, StakingStore, TransactionStore } from '@subwallet/extension-base/services/storage-service/db-stores';
|
|
@@ -8,6 +8,7 @@ import ChainStakingMetadataStore from '@subwallet/extension-base/services/storag
|
|
|
8
8
|
import MantaPayStore from '@subwallet/extension-base/services/storage-service/db-stores/MantaPay';
|
|
9
9
|
import NominatorMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata';
|
|
10
10
|
import { HistoryQuery } from '@subwallet/extension-base/services/storage-service/db-stores/Transaction';
|
|
11
|
+
import { BalanceItem } from '@subwallet/extension-base/types';
|
|
11
12
|
import { Subscription } from 'dexie';
|
|
12
13
|
export default class DatabaseService {
|
|
13
14
|
private eventService;
|
|
@@ -36,7 +37,8 @@ export default class DatabaseService {
|
|
|
36
37
|
updatePriceStore(priceData: PriceJson): Promise<void>;
|
|
37
38
|
getPriceStore(): Promise<PriceJson | undefined>;
|
|
38
39
|
getStoredBalance(): Promise<IBalance[]>;
|
|
39
|
-
updateBalanceStore(
|
|
40
|
+
updateBalanceStore(item: BalanceItem): Promise<unknown>;
|
|
41
|
+
updateBulkBalanceStore(items: BalanceItem[]): Promise<unknown>;
|
|
40
42
|
removeFromBalanceStore(assets: string[]): Promise<number>;
|
|
41
43
|
updateCrowdloanStore(chain: string, address: string, item: CrowdloanItem): Promise<unknown>;
|
|
42
44
|
updateStaking(chain: string, address: string, item: StakingItem): Promise<unknown>;
|
|
@@ -83,4 +85,7 @@ export default class DatabaseService {
|
|
|
83
85
|
getProcessingCampaign(): Promise<import("@subwallet/extension-base/background/KoniTypes").CampaignData[]>;
|
|
84
86
|
getCampaign(slug: string): Promise<import("@subwallet/extension-base/background/KoniTypes").CampaignData | undefined>;
|
|
85
87
|
upsertCampaign(campaign: ICampaign): import("dexie").PromiseExtended<unknown>;
|
|
88
|
+
exportDB(): Promise<string>;
|
|
89
|
+
importDB(data: string): Promise<boolean>;
|
|
90
|
+
checkImportMetadata(data: string): Promise<import("dexie-export-import").DexieExportJsonMeta | null>;
|
|
86
91
|
}
|
|
@@ -9,7 +9,9 @@ import ChainStakingMetadataStore from '@subwallet/extension-base/services/storag
|
|
|
9
9
|
import MantaPayStore from '@subwallet/extension-base/services/storage-service/db-stores/MantaPay';
|
|
10
10
|
import NominatorMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata';
|
|
11
11
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
12
|
+
import { exportDB, peakImportFile } from 'dexie-export-import';
|
|
12
13
|
import { logger as createLogger } from '@polkadot/util';
|
|
14
|
+
const EXPORT_EXCLUDE_TABLES = ['metadata'];
|
|
13
15
|
export default class DatabaseService {
|
|
14
16
|
// TODO: might remove this
|
|
15
17
|
|
|
@@ -56,14 +58,19 @@ export default class DatabaseService {
|
|
|
56
58
|
async getStoredBalance() {
|
|
57
59
|
return this.stores.balance.table.toArray();
|
|
58
60
|
}
|
|
59
|
-
async updateBalanceStore(
|
|
61
|
+
async updateBalanceStore(item) {
|
|
60
62
|
if (item.state === APIItemState.READY) {
|
|
61
63
|
return this.stores.balance.upsert({
|
|
62
|
-
address,
|
|
63
64
|
...item
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
}
|
|
68
|
+
async updateBulkBalanceStore(items) {
|
|
69
|
+
const filtered = items.filter(item => item.state !== APIItemState.PENDING);
|
|
70
|
+
if (filtered.length) {
|
|
71
|
+
return this.stores.balance.bulkUpsert(filtered);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
67
74
|
async removeFromBalanceStore(assets) {
|
|
68
75
|
return this.stores.balance.removeBySlugs(assets);
|
|
69
76
|
}
|
|
@@ -279,4 +286,42 @@ export default class DatabaseService {
|
|
|
279
286
|
upsertCampaign(campaign) {
|
|
280
287
|
return this.stores.campaign.upsertCampaign(campaign);
|
|
281
288
|
}
|
|
289
|
+
async exportDB() {
|
|
290
|
+
const blob = await exportDB(this._db, {
|
|
291
|
+
filter: (table, value, key) => {
|
|
292
|
+
if (EXPORT_EXCLUDE_TABLES.indexOf(table) >= 0) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
return await blob.text();
|
|
299
|
+
}
|
|
300
|
+
async importDB(data) {
|
|
301
|
+
try {
|
|
302
|
+
const blob = new Blob([data], {
|
|
303
|
+
type: 'application/json'
|
|
304
|
+
});
|
|
305
|
+
await this._db.import(blob, {
|
|
306
|
+
overwriteValues: true,
|
|
307
|
+
acceptMissingTables: true,
|
|
308
|
+
acceptVersionDiff: true
|
|
309
|
+
});
|
|
310
|
+
return true;
|
|
311
|
+
} catch (e) {
|
|
312
|
+
this.logger.error(e);
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async checkImportMetadata(data) {
|
|
317
|
+
try {
|
|
318
|
+
const blob = new Blob([data], {
|
|
319
|
+
type: 'application/json'
|
|
320
|
+
});
|
|
321
|
+
return await peakImportFile(blob);
|
|
322
|
+
} catch (e) {
|
|
323
|
+
this.logger.error(e);
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
282
327
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import {
|
|
2
|
+
import { CampaignData, ChainStakingMetadata, CrowdloanItem, MetadataItem, NftCollection, NftItem, NominatorMetadata, PriceJson, StakingItem, TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
import { BalanceItem } from '@subwallet/extension-base/types';
|
|
3
4
|
import Dexie, { Table } from 'dexie';
|
|
4
5
|
export interface DefaultChainDoc {
|
|
5
6
|
chain: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BalanceMap } from '@subwallet/extension-base/types';
|
|
2
2
|
import { IBalance } from '../databases';
|
|
3
3
|
import BaseStoreWithAddress from '../db-stores/BaseStoreWithAddress';
|
|
4
4
|
export default class BalanceStore extends BaseStoreWithAddress<IBalance> {
|
|
5
|
-
|
|
5
|
+
getBalanceMapByAddresses(addresses: string): Promise<BalanceMap>;
|
|
6
6
|
removeBySlugs(tokenSlugs: string[]): Promise<number>;
|
|
7
7
|
}
|
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
import BaseStoreWithAddress from "./BaseStoreWithAddress.js";
|
|
5
5
|
export default class BalanceStore extends BaseStoreWithAddress {
|
|
6
|
-
async
|
|
7
|
-
const data = await this.table.where('address').
|
|
6
|
+
async getBalanceMapByAddresses(addresses) {
|
|
7
|
+
const data = await this.table.where('address').anyOf(addresses).toArray();
|
|
8
8
|
const balanceMap = {};
|
|
9
9
|
data.forEach(storedBalance => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const address = storedBalance.address;
|
|
11
|
+
const slug = storedBalance.tokenSlug;
|
|
12
|
+
if (!balanceMap[address]) {
|
|
13
|
+
balanceMap[address] = {};
|
|
14
|
+
}
|
|
15
|
+
balanceMap[address][slug] = {
|
|
16
|
+
...storedBalance
|
|
17
17
|
};
|
|
18
18
|
});
|
|
19
19
|
return balanceMap;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CrowdloanContributionsResponse, ExtrinsicItem, ExtrinsicsListResponse, IMultiChainBalance, TransferItem, TransfersListResponse } from '@subwallet/extension-base/services/subscan-service/types';
|
|
1
|
+
import { CrowdloanContributionsResponse, ExtrinsicItem, ExtrinsicsListResponse, IMultiChainBalance, RequestBlockRange, TransferItem, TransfersListResponse } from '@subwallet/extension-base/services/subscan-service/types';
|
|
2
2
|
export declare class SubscanService {
|
|
3
3
|
private subscanChainMap;
|
|
4
4
|
private limitRate;
|
|
@@ -21,8 +21,14 @@ export declare class SubscanService {
|
|
|
21
21
|
setSubscanChainMap(subscanChainMap: Record<string, string>): void;
|
|
22
22
|
getMultiChainBalance(address: string): Promise<IMultiChainBalance[]>;
|
|
23
23
|
getCrowdloanContributions(relayChain: string, address: string, page?: number): Promise<CrowdloanContributionsResponse>;
|
|
24
|
-
getExtrinsicsList(chain: string, address: string, page?: number): Promise<ExtrinsicsListResponse>;
|
|
25
|
-
fetchAllPossibleExtrinsicItems(chain: string, address: string, cbAfterEachRequest?: (items: ExtrinsicItem[]) => void
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
getExtrinsicsList(chain: string, address: string, page?: number, blockRange?: RequestBlockRange): Promise<ExtrinsicsListResponse>;
|
|
25
|
+
fetchAllPossibleExtrinsicItems(chain: string, address: string, cbAfterEachRequest?: (items: ExtrinsicItem[]) => void, limit?: {
|
|
26
|
+
page: number;
|
|
27
|
+
record: number;
|
|
28
|
+
}): Promise<ExtrinsicItem[]>;
|
|
29
|
+
getTransfersList(chain: string, address: string, page?: number, direction?: 'sent' | 'received', blockRange?: RequestBlockRange): Promise<TransfersListResponse>;
|
|
30
|
+
fetchAllPossibleTransferItems(chain: string, address: string, direction?: 'sent' | 'received', cbAfterEachRequest?: (items: TransferItem[]) => void, limit?: {
|
|
31
|
+
page: number;
|
|
32
|
+
record: number;
|
|
33
|
+
}): Promise<Record<string, TransferItem[]>>;
|
|
28
34
|
}
|
|
@@ -119,12 +119,19 @@ export class SubscanService {
|
|
|
119
119
|
return jsonData.data;
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
getExtrinsicsList(chain, address, page = 0) {
|
|
122
|
+
getExtrinsicsList(chain, address, page = 0, blockRange) {
|
|
123
|
+
const _blockRange = (() => {
|
|
124
|
+
if (!blockRange || !blockRange.to) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return `${blockRange.from || 0}-${blockRange.to}`;
|
|
128
|
+
})();
|
|
123
129
|
return this.addRequest(async () => {
|
|
124
130
|
const rs = await this.postRequest(this.getApiUrl(chain, 'api/scan/extrinsics'), {
|
|
125
131
|
page,
|
|
126
132
|
row: QUERY_ROW,
|
|
127
|
-
address
|
|
133
|
+
address,
|
|
134
|
+
block_range: _blockRange
|
|
128
135
|
});
|
|
129
136
|
if (rs.status !== 200) {
|
|
130
137
|
throw new SWError('SubscanService.getExtrinsicsList', await rs.text());
|
|
@@ -133,40 +140,54 @@ export class SubscanService {
|
|
|
133
140
|
return jsonData.data;
|
|
134
141
|
});
|
|
135
142
|
}
|
|
136
|
-
async fetchAllPossibleExtrinsicItems(chain, address, cbAfterEachRequest
|
|
137
|
-
|
|
143
|
+
async fetchAllPossibleExtrinsicItems(chain, address, cbAfterEachRequest, limit = {
|
|
144
|
+
page: 10,
|
|
145
|
+
record: 1000
|
|
146
|
+
}) {
|
|
147
|
+
let maxCount = 0;
|
|
148
|
+
let currentCount = 0;
|
|
149
|
+
const blockRange = {
|
|
150
|
+
from: null,
|
|
151
|
+
to: null
|
|
152
|
+
};
|
|
138
153
|
const resultMap = {};
|
|
139
154
|
const _getExtrinsicItems = async page => {
|
|
140
|
-
const res = await this.getExtrinsicsList(chain, address, page);
|
|
155
|
+
const res = await this.getExtrinsicsList(chain, address, page, blockRange);
|
|
141
156
|
if (!res || !res.count || !res.extrinsics || !res.extrinsics.length) {
|
|
142
157
|
return;
|
|
143
158
|
}
|
|
144
|
-
if (res.count >
|
|
145
|
-
|
|
159
|
+
if (res.count > maxCount) {
|
|
160
|
+
maxCount = res.count;
|
|
146
161
|
}
|
|
147
162
|
cbAfterEachRequest === null || cbAfterEachRequest === void 0 ? void 0 : cbAfterEachRequest(res.extrinsics);
|
|
148
163
|
res.extrinsics.forEach(item => {
|
|
149
164
|
resultMap[item.extrinsic_hash] = item;
|
|
150
165
|
});
|
|
151
|
-
|
|
166
|
+
currentCount += res.extrinsics.length;
|
|
167
|
+
if (page > limit.page || currentCount > limit.record) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (currentCount < maxCount) {
|
|
152
171
|
await wait(100);
|
|
172
|
+
if (page === 0) {
|
|
173
|
+
blockRange.to = res.extrinsics[0].block_num;
|
|
174
|
+
}
|
|
153
175
|
await _getExtrinsicItems(++page);
|
|
154
176
|
}
|
|
155
177
|
};
|
|
156
178
|
await _getExtrinsicItems(0);
|
|
157
179
|
return Object.values(resultMap);
|
|
158
180
|
}
|
|
159
|
-
getTransfersList(chain, address, page = 0, direction) {
|
|
160
|
-
const requestBody = {
|
|
161
|
-
page,
|
|
162
|
-
row: QUERY_ROW,
|
|
163
|
-
address
|
|
164
|
-
};
|
|
165
|
-
if (direction) {
|
|
166
|
-
requestBody.direction = direction;
|
|
167
|
-
}
|
|
181
|
+
getTransfersList(chain, address, page = 0, direction, blockRange) {
|
|
168
182
|
return this.addRequest(async () => {
|
|
169
|
-
const rs = await this.postRequest(this.getApiUrl(chain, 'api/v2/scan/transfers'),
|
|
183
|
+
const rs = await this.postRequest(this.getApiUrl(chain, 'api/v2/scan/transfers'), {
|
|
184
|
+
page,
|
|
185
|
+
row: QUERY_ROW,
|
|
186
|
+
address,
|
|
187
|
+
direction: direction || null,
|
|
188
|
+
from_block: (blockRange === null || blockRange === void 0 ? void 0 : blockRange.from) || null,
|
|
189
|
+
to_block: (blockRange === null || blockRange === void 0 ? void 0 : blockRange.to) || null
|
|
190
|
+
});
|
|
170
191
|
if (rs.status !== 200) {
|
|
171
192
|
throw new SWError('SubscanService.getTransfersList', await rs.text());
|
|
172
193
|
}
|
|
@@ -174,27 +195,46 @@ export class SubscanService {
|
|
|
174
195
|
return jsonData.data;
|
|
175
196
|
});
|
|
176
197
|
}
|
|
177
|
-
async fetchAllPossibleTransferItems(chain, address, direction, cbAfterEachRequest
|
|
178
|
-
|
|
198
|
+
async fetchAllPossibleTransferItems(chain, address, direction, cbAfterEachRequest, limit = {
|
|
199
|
+
page: 10,
|
|
200
|
+
record: 1000
|
|
201
|
+
}) {
|
|
202
|
+
let maxCount = 0;
|
|
203
|
+
let currentCount = 0;
|
|
204
|
+
const blockRange = {
|
|
205
|
+
from: null,
|
|
206
|
+
to: null
|
|
207
|
+
};
|
|
179
208
|
const resultMap = {};
|
|
180
209
|
const _getTransferItems = async page => {
|
|
181
|
-
const res = await this.getTransfersList(chain, address, page, direction);
|
|
210
|
+
const res = await this.getTransfersList(chain, address, page, direction, blockRange);
|
|
182
211
|
if (!res || !res.count || !res.transfers || !res.transfers.length) {
|
|
183
212
|
return;
|
|
184
213
|
}
|
|
185
|
-
if (res.count >
|
|
186
|
-
|
|
214
|
+
if (res.count > maxCount) {
|
|
215
|
+
maxCount = res.count;
|
|
187
216
|
}
|
|
188
217
|
cbAfterEachRequest === null || cbAfterEachRequest === void 0 ? void 0 : cbAfterEachRequest(res.transfers);
|
|
189
218
|
res.transfers.forEach(item => {
|
|
190
|
-
resultMap[item.hash]
|
|
219
|
+
if (!resultMap[item.hash]) {
|
|
220
|
+
resultMap[item.hash] = [item];
|
|
221
|
+
} else {
|
|
222
|
+
resultMap[item.hash].push(item);
|
|
223
|
+
}
|
|
191
224
|
});
|
|
192
|
-
|
|
225
|
+
currentCount += res.transfers.length;
|
|
226
|
+
if (page > limit.page || currentCount > limit.record) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (currentCount < maxCount) {
|
|
193
230
|
await wait(100);
|
|
231
|
+
if (page === 0) {
|
|
232
|
+
blockRange.to = res.transfers[0].block_num;
|
|
233
|
+
}
|
|
194
234
|
await _getTransferItems(++page);
|
|
195
235
|
}
|
|
196
236
|
};
|
|
197
237
|
await _getTransferItems(0);
|
|
198
|
-
return
|
|
238
|
+
return resultMap;
|
|
199
239
|
}
|
|
200
240
|
}
|
|
@@ -14,7 +14,7 @@ import { parseTransferEventLogs, parseXcmEventLogs } from '@subwallet/extension-
|
|
|
14
14
|
import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
15
15
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
16
16
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
17
|
-
import { anyNumberToBN } from '@subwallet/extension-base/utils/eth';
|
|
17
|
+
import { anyNumberToBN, recalculateGasPrice } from '@subwallet/extension-base/utils/eth';
|
|
18
18
|
import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
|
|
19
19
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
20
20
|
import keyring from '@subwallet/ui-keyring';
|
|
@@ -114,7 +114,8 @@ export default class TransactionService {
|
|
|
114
114
|
if (!web3) {
|
|
115
115
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
116
116
|
} else {
|
|
117
|
-
const
|
|
117
|
+
const _price = await web3.api.eth.getGasPrice();
|
|
118
|
+
const gasPrice = recalculateGasPrice(_price, chainInfo.slug);
|
|
118
119
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
119
120
|
estimateFee.value = (gasLimit * parseInt(gasPrice)).toString();
|
|
120
121
|
}
|
|
@@ -912,8 +913,8 @@ export default class TransactionService {
|
|
|
912
913
|
}
|
|
913
914
|
}) => section === 'system').forEach(({
|
|
914
915
|
event: {
|
|
915
|
-
|
|
916
|
-
|
|
916
|
+
data: [error],
|
|
917
|
+
method
|
|
917
918
|
}
|
|
918
919
|
}) => {
|
|
919
920
|
if (method === 'ExtrinsicFailed') {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
import { BN } from '@polkadot/util';
|
|
4
|
+
export interface TokenBalanceRaw {
|
|
5
|
+
reserved: BN;
|
|
6
|
+
frozen: BN;
|
|
7
|
+
free: BN;
|
|
8
|
+
}
|
|
9
|
+
export interface SubstrateBalance {
|
|
10
|
+
reserved?: string;
|
|
11
|
+
miscFrozen?: string;
|
|
12
|
+
feeFrozen?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Balance info of a token on an address
|
|
16
|
+
* @property {string} address - Address
|
|
17
|
+
* @property {string} tokenSlug - Slug of token
|
|
18
|
+
* @property {APIItemState} state - State of information
|
|
19
|
+
* @property {number} [timestamp] - Time to get information
|
|
20
|
+
* @property {string} free - Free balance
|
|
21
|
+
* @property {string} locked - Locked balance
|
|
22
|
+
* @property {SubstrateBalance} [substrateInfo] - Substrate info of balance
|
|
23
|
+
*/
|
|
24
|
+
export interface BalanceItem {
|
|
25
|
+
address: string;
|
|
26
|
+
tokenSlug: string;
|
|
27
|
+
state: APIItemState;
|
|
28
|
+
timestamp?: number;
|
|
29
|
+
free: string;
|
|
30
|
+
locked: string;
|
|
31
|
+
substrateInfo?: SubstrateBalance;
|
|
32
|
+
}
|
|
33
|
+
/** Balance info of all tokens on an address */
|
|
34
|
+
export declare type BalanceInfo = Record<string, BalanceItem>;
|
|
35
|
+
/** Balance info of all addresses */
|
|
36
|
+
export declare type BalanceMap = Record<string, BalanceInfo>;
|
|
37
|
+
export interface BalanceJson {
|
|
38
|
+
reset?: boolean;
|
|
39
|
+
details: BalanceMap;
|
|
40
|
+
}
|
package/types/balance.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/index.d.ts
CHANGED
package/types/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AccountJson, AddressJson } from '@subwallet/extension-base/background/types';
|
|
2
|
+
import { SubjectInfo } from '@subwallet/ui-keyring/observable/types';
|
|
3
|
+
export declare const simpleAddress: (address: string) => string;
|
|
4
|
+
export declare function quickFormatAddressToCompare(address?: string): string | undefined;
|
|
5
|
+
export declare const convertSubjectInfoToAddresses: (subjectInfo: SubjectInfo) => AddressJson[];
|
|
6
|
+
/**
|
|
7
|
+
* @function getAccountJsonByAddress
|
|
8
|
+
* @desc Get account info by address
|
|
9
|
+
* <p>
|
|
10
|
+
* Note: Use on the background only
|
|
11
|
+
* </p>
|
|
12
|
+
* @param {string} address - Address
|
|
13
|
+
* @returns {AccountJson|null} - Account info or null if not found
|
|
14
|
+
*/
|
|
15
|
+
export declare const getAccountJsonByAddress: (address: string) => AccountJson | null;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { reformatAddress } from '@subwallet/extension-base/utils/index';
|
|
5
|
+
import keyring from '@subwallet/ui-keyring';
|
|
5
6
|
import { decodeAddress, encodeAddress, isAddress, isEthereumAddress } from '@polkadot/util-crypto';
|
|
6
7
|
export const simpleAddress = address => {
|
|
7
8
|
if (isEthereumAddress(address)) {
|
|
@@ -21,4 +22,31 @@ export const convertSubjectInfoToAddresses = subjectInfo => {
|
|
|
21
22
|
type: info.type,
|
|
22
23
|
...info.json.meta
|
|
23
24
|
}));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @function getAccountJsonByAddress
|
|
29
|
+
* @desc Get account info by address
|
|
30
|
+
* <p>
|
|
31
|
+
* Note: Use on the background only
|
|
32
|
+
* </p>
|
|
33
|
+
* @param {string} address - Address
|
|
34
|
+
* @returns {AccountJson|null} - Account info or null if not found
|
|
35
|
+
*/
|
|
36
|
+
export const getAccountJsonByAddress = address => {
|
|
37
|
+
try {
|
|
38
|
+
const pair = keyring.getPair(address);
|
|
39
|
+
if (pair) {
|
|
40
|
+
return {
|
|
41
|
+
address: pair.address,
|
|
42
|
+
type: pair.type,
|
|
43
|
+
...pair.meta
|
|
44
|
+
};
|
|
45
|
+
} else {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.warn(e);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
24
52
|
};
|
package/utils/eth.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export declare class Transaction {
|
|
|
15
15
|
export declare const anyNumberToBN: (value?: string | number | BNEther) => BigN;
|
|
16
16
|
export declare const createTransactionFromRLP: (rlp: string) => Transaction | null;
|
|
17
17
|
export declare const signatureToHex: (sig: SignedTransaction) => string;
|
|
18
|
+
export declare const recalculateGasPrice: (_price: string, chain: string) => string;
|
package/utils/eth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { GAS_PRICE_RATIO, NETWORK_MULTI_GAS_FEE } from '@subwallet/extension-base/constants';
|
|
4
5
|
import BigN from 'bignumber.js';
|
|
5
6
|
import { ethers } from 'ethers';
|
|
6
7
|
import { hexStripPrefix, numberToHex } from '@polkadot/util';
|
|
@@ -58,4 +59,7 @@ export const signatureToHex = sig => {
|
|
|
58
59
|
const hexS = s.length % 2 === 1 ? `0${s}` : s;
|
|
59
60
|
const hexV = hexStripPrefix(numberToHex(v));
|
|
60
61
|
return hexR + hexS + hexV;
|
|
62
|
+
};
|
|
63
|
+
export const recalculateGasPrice = (_price, chain) => {
|
|
64
|
+
return NETWORK_MULTI_GAS_FEE.includes(chain) ? new BigN(_price).multipliedBy(GAS_PRICE_RATIO).toFixed(0) : _price;
|
|
61
65
|
};
|
package/utils/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export declare function getDomainFromUrl(url: string): string;
|
|
|
40
40
|
export declare function waitTimeout(ms: number): Promise<void>;
|
|
41
41
|
export declare const stripUrl: (url: string) => string;
|
|
42
42
|
export declare function wait(milliseconds: number): Promise<void>;
|
|
43
|
+
export * from './account';
|
|
43
44
|
export * from './array';
|
|
44
45
|
export * from './environment';
|
|
45
46
|
export * from './lazy';
|