@subwallet/extension-base 1.1.24-0 → 1.1.24-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.
Files changed (99) hide show
  1. package/background/KoniTypes.d.ts +2 -25
  2. package/cjs/constants/index.js +9 -3
  3. package/cjs/koni/api/staking/bonding/amplitude.js +6 -4
  4. package/cjs/koni/api/staking/bonding/astar.js +4 -0
  5. package/cjs/koni/api/staking/bonding/index.js +5 -0
  6. package/cjs/koni/api/staking/bonding/paraChain.js +9 -20
  7. package/cjs/koni/api/staking/bonding/relayChain.js +41 -23
  8. package/cjs/koni/api/staking/bonding/utils.js +67 -16
  9. package/cjs/koni/api/tokens/evm/balance.js +5 -1
  10. package/cjs/koni/api/tokens/evm/transfer.js +8 -4
  11. package/cjs/koni/background/cron.js +2 -2
  12. package/cjs/koni/background/handlers/Extension.js +5 -5
  13. package/cjs/koni/background/handlers/Mobile.js +1 -1
  14. package/cjs/koni/background/handlers/State.js +123 -44
  15. package/cjs/koni/background/subscription.js +2 -2
  16. package/cjs/packageInfo.js +1 -1
  17. package/cjs/services/balance-service/helpers/group.js +53 -0
  18. package/cjs/services/balance-service/helpers/subscribe/balance.js +111 -0
  19. package/cjs/services/balance-service/helpers/subscribe/evm.js +95 -0
  20. package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +113 -0
  21. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +324 -0
  22. package/cjs/services/balance-service/index.js +41 -16
  23. package/cjs/services/chain-service/constants.js +4 -3
  24. package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
  25. package/cjs/services/history-service/index.js +12 -8
  26. package/cjs/services/migration-service/scripts/MigrateProvider.js +1 -1
  27. package/cjs/services/storage-service/DatabaseService.js +7 -2
  28. package/cjs/services/storage-service/db-stores/Balance.js +9 -9
  29. package/cjs/services/subscan-service/index.js +66 -22
  30. package/cjs/services/transaction-service/index.js +4 -3
  31. package/cjs/types/balance.js +1 -0
  32. package/cjs/types/index.js +11 -0
  33. package/cjs/utils/{address.js → account.js} +32 -2
  34. package/cjs/utils/eth.js +7 -2
  35. package/cjs/utils/index.js +12 -0
  36. package/constants/index.d.ts +2 -0
  37. package/constants/index.js +2 -0
  38. package/koni/api/staking/bonding/amplitude.d.ts +3 -0
  39. package/koni/api/staking/bonding/amplitude.js +6 -4
  40. package/koni/api/staking/bonding/astar.d.ts +3 -0
  41. package/koni/api/staking/bonding/astar.js +4 -0
  42. package/koni/api/staking/bonding/index.d.ts +3 -0
  43. package/koni/api/staking/bonding/index.js +5 -0
  44. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  45. package/koni/api/staking/bonding/paraChain.js +9 -20
  46. package/koni/api/staking/bonding/relayChain.d.ts +3 -0
  47. package/koni/api/staking/bonding/relayChain.js +41 -24
  48. package/koni/api/staking/bonding/utils.d.ts +15 -2
  49. package/koni/api/staking/bonding/utils.js +69 -18
  50. package/koni/api/tokens/evm/balance.js +5 -1
  51. package/koni/api/tokens/evm/transfer.d.ts +1 -1
  52. package/koni/api/tokens/evm/transfer.js +8 -4
  53. package/koni/background/cron.js +3 -3
  54. package/koni/background/handlers/Extension.js +5 -5
  55. package/koni/background/handlers/Mobile.js +1 -1
  56. package/koni/background/handlers/State.d.ts +6 -4
  57. package/koni/background/handlers/State.js +111 -33
  58. package/koni/background/subscription.js +2 -2
  59. package/package.json +40 -15
  60. package/packageInfo.js +1 -1
  61. package/services/balance-service/helpers/group.d.ts +9 -0
  62. package/services/balance-service/helpers/group.js +46 -0
  63. package/services/balance-service/helpers/subscribe/balance.d.ts +4 -0
  64. package/services/balance-service/helpers/subscribe/balance.js +103 -0
  65. package/services/balance-service/helpers/subscribe/evm.d.ts +5 -0
  66. package/services/balance-service/helpers/subscribe/evm.js +87 -0
  67. package/services/balance-service/helpers/subscribe/substrate/equilibrium.d.ts +4 -0
  68. package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +105 -0
  69. package/services/balance-service/helpers/subscribe/substrate/index.d.ts +4 -0
  70. package/services/balance-service/helpers/subscribe/substrate/index.js +316 -0
  71. package/services/balance-service/index.d.ts +24 -5
  72. package/services/balance-service/index.js +40 -14
  73. package/services/chain-service/constants.js +4 -3
  74. package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
  75. package/services/history-service/index.js +12 -8
  76. package/services/migration-service/scripts/MigrateProvider.js +1 -1
  77. package/services/storage-service/DatabaseService.d.ts +4 -2
  78. package/services/storage-service/DatabaseService.js +7 -2
  79. package/services/storage-service/databases/index.d.ts +2 -1
  80. package/services/storage-service/db-stores/Balance.d.ts +2 -2
  81. package/services/storage-service/db-stores/Balance.js +9 -9
  82. package/services/subscan-service/index.d.ts +11 -5
  83. package/services/subscan-service/index.js +66 -26
  84. package/services/subscan-service/types.d.ts +4 -0
  85. package/services/transaction-service/index.js +5 -4
  86. package/types/balance.d.ts +40 -0
  87. package/types/balance.js +1 -0
  88. package/types/index.d.ts +1 -0
  89. package/types/index.js +1 -0
  90. package/utils/account.d.ts +15 -0
  91. package/utils/{address.js → account.js} +28 -0
  92. package/utils/eth.d.ts +1 -0
  93. package/utils/eth.js +4 -0
  94. package/utils/index.d.ts +1 -0
  95. package/utils/index.js +1 -0
  96. package/cjs/koni/api/dotsama/balance.js +0 -464
  97. package/koni/api/dotsama/balance.d.ts +0 -6
  98. package/koni/api/dotsama/balance.js +0 -451
  99. package/utils/address.d.ts +0 -5
@@ -1,5 +1,5 @@
1
1
  import { _ChainAsset } from '@subwallet/chain-list/types';
2
- import { BalanceItem, ChainStakingMetadata, CrowdloanItem, MantaPayConfig, NftCollection, NftItem, NominatorMetadata, PriceJson, StakingItem, StakingType, TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
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(address: string, item: BalanceItem): Promise<unknown>;
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>;
@@ -58,14 +58,19 @@ export default class DatabaseService {
58
58
  async getStoredBalance() {
59
59
  return this.stores.balance.table.toArray();
60
60
  }
61
- async updateBalanceStore(address, item) {
61
+ async updateBalanceStore(item) {
62
62
  if (item.state === APIItemState.READY) {
63
63
  return this.stores.balance.upsert({
64
- address,
65
64
  ...item
66
65
  });
67
66
  }
68
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
+ }
69
74
  async removeFromBalanceStore(assets) {
70
75
  return this.stores.balance.removeBySlugs(assets);
71
76
  }
@@ -1,5 +1,6 @@
1
1
  import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
- import { BalanceItem, CampaignData, ChainStakingMetadata, CrowdloanItem, MetadataItem, NftCollection, NftItem, NominatorMetadata, PriceJson, StakingItem, TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
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 { BalanceItem } from '@subwallet/extension-base/background/KoniTypes';
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
- getBalanceMapByAddress(address: string): Promise<Record<string, BalanceItem>>;
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 getBalanceMapByAddress(address) {
7
- const data = await this.table.where('address').equals(address).toArray();
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
- balanceMap[storedBalance.tokenSlug] = {
11
- tokenSlug: storedBalance.tokenSlug,
12
- state: storedBalance.state,
13
- free: storedBalance.free,
14
- locked: storedBalance.locked,
15
- substrateInfo: storedBalance.substrateInfo,
16
- timestamp: storedBalance.timestamp
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): Promise<ExtrinsicItem[]>;
26
- getTransfersList(chain: string, address: string, page?: number, direction?: 'sent' | 'received'): Promise<TransfersListResponse>;
27
- fetchAllPossibleTransferItems(chain: string, address: string, direction?: 'sent' | 'received', cbAfterEachRequest?: (items: TransferItem[]) => void): Promise<TransferItem[]>;
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
- let count = 0;
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 > count) {
145
- count = res.count;
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
- if (Object.values(resultMap).length < count) {
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'), requestBody);
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
- let count = 0;
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 > count) {
186
- count = res.count;
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] = item;
219
+ if (!resultMap[item.hash]) {
220
+ resultMap[item.hash] = [item];
221
+ } else {
222
+ resultMap[item.hash].push(item);
223
+ }
191
224
  });
192
- if (Object.values(resultMap).length < count) {
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 Object.values(resultMap);
238
+ return resultMap;
199
239
  }
200
240
  }
@@ -171,3 +171,7 @@ export interface TransfersListResponse {
171
171
  count: number;
172
172
  transfers: null | TransferItem[];
173
173
  }
174
+ export declare type RequestBlockRange = {
175
+ from: number | null;
176
+ to: number | null;
177
+ };
@@ -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 gasPrice = await web3.api.eth.getGasPrice();
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
- method,
916
- data: [error]
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
+ }
@@ -0,0 +1 @@
1
+ export {};
package/types/index.d.ts CHANGED
@@ -7,4 +7,5 @@ export interface Message extends MessageEvent {
7
7
  subscription?: string;
8
8
  };
9
9
  }
10
+ export * from './balance';
10
11
  export * from './buy';
package/types/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright 2019-2022 @polkadot/extension authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ export * from "./balance.js";
4
5
  export * from "./buy.js";
5
6
  export {};
@@ -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';
package/utils/index.js CHANGED
@@ -294,6 +294,7 @@ export function wait(milliseconds) {
294
294
  }, milliseconds);
295
295
  });
296
296
  }
297
+ export * from "./account.js";
297
298
  export * from "./array.js";
298
299
  export * from "./environment.js";
299
300
  export * from "./lazy.js";