@subwallet/extension-base 1.1.24-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.
Files changed (81) hide show
  1. package/background/KoniTypes.d.ts +1 -25
  2. package/cjs/constants/index.js +9 -3
  3. package/cjs/koni/api/staking/bonding/index.js +1 -0
  4. package/cjs/koni/api/tokens/evm/balance.js +5 -1
  5. package/cjs/koni/api/tokens/evm/transfer.js +8 -4
  6. package/cjs/koni/background/cron.js +2 -2
  7. package/cjs/koni/background/handlers/Extension.js +5 -5
  8. package/cjs/koni/background/handlers/Mobile.js +1 -1
  9. package/cjs/koni/background/handlers/State.js +123 -44
  10. package/cjs/koni/background/subscription.js +2 -2
  11. package/cjs/packageInfo.js +1 -1
  12. package/cjs/services/balance-service/helpers/group.js +53 -0
  13. package/cjs/services/balance-service/helpers/subscribe/balance.js +111 -0
  14. package/cjs/services/balance-service/helpers/subscribe/evm.js +95 -0
  15. package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +113 -0
  16. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +324 -0
  17. package/cjs/services/balance-service/index.js +41 -16
  18. package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
  19. package/cjs/services/history-service/index.js +12 -8
  20. package/cjs/services/migration-service/scripts/MigrateProvider.js +1 -1
  21. package/cjs/services/storage-service/DatabaseService.js +7 -2
  22. package/cjs/services/storage-service/db-stores/Balance.js +9 -9
  23. package/cjs/services/subscan-service/index.js +66 -22
  24. package/cjs/services/transaction-service/index.js +4 -3
  25. package/cjs/types/balance.js +1 -0
  26. package/cjs/types/index.js +11 -0
  27. package/cjs/utils/{address.js → account.js} +32 -2
  28. package/cjs/utils/eth.js +7 -2
  29. package/cjs/utils/index.js +12 -0
  30. package/constants/index.d.ts +2 -0
  31. package/constants/index.js +2 -0
  32. package/koni/api/staking/bonding/index.js +1 -0
  33. package/koni/api/tokens/evm/balance.js +5 -1
  34. package/koni/api/tokens/evm/transfer.d.ts +1 -1
  35. package/koni/api/tokens/evm/transfer.js +8 -4
  36. package/koni/background/cron.js +3 -3
  37. package/koni/background/handlers/Extension.js +5 -5
  38. package/koni/background/handlers/Mobile.js +1 -1
  39. package/koni/background/handlers/State.d.ts +6 -4
  40. package/koni/background/handlers/State.js +111 -33
  41. package/koni/background/subscription.js +2 -2
  42. package/package.json +39 -14
  43. package/packageInfo.js +1 -1
  44. package/services/balance-service/helpers/group.d.ts +9 -0
  45. package/services/balance-service/helpers/group.js +46 -0
  46. package/services/balance-service/helpers/subscribe/balance.d.ts +4 -0
  47. package/services/balance-service/helpers/subscribe/balance.js +103 -0
  48. package/services/balance-service/helpers/subscribe/evm.d.ts +5 -0
  49. package/services/balance-service/helpers/subscribe/evm.js +87 -0
  50. package/services/balance-service/helpers/subscribe/substrate/equilibrium.d.ts +4 -0
  51. package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +105 -0
  52. package/services/balance-service/helpers/subscribe/substrate/index.d.ts +4 -0
  53. package/services/balance-service/helpers/subscribe/substrate/index.js +316 -0
  54. package/services/balance-service/index.d.ts +24 -5
  55. package/services/balance-service/index.js +40 -14
  56. package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
  57. package/services/history-service/index.js +12 -8
  58. package/services/migration-service/scripts/MigrateProvider.js +1 -1
  59. package/services/storage-service/DatabaseService.d.ts +4 -2
  60. package/services/storage-service/DatabaseService.js +7 -2
  61. package/services/storage-service/databases/index.d.ts +2 -1
  62. package/services/storage-service/db-stores/Balance.d.ts +2 -2
  63. package/services/storage-service/db-stores/Balance.js +9 -9
  64. package/services/subscan-service/index.d.ts +11 -5
  65. package/services/subscan-service/index.js +66 -26
  66. package/services/subscan-service/types.d.ts +4 -0
  67. package/services/transaction-service/index.js +5 -4
  68. package/types/balance.d.ts +40 -0
  69. package/types/balance.js +1 -0
  70. package/types/index.d.ts +1 -0
  71. package/types/index.js +1 -0
  72. package/utils/account.d.ts +15 -0
  73. package/utils/{address.js → account.js} +28 -0
  74. package/utils/eth.d.ts +1 -0
  75. package/utils/eth.js +4 -0
  76. package/utils/index.d.ts +1 -0
  77. package/utils/index.js +1 -0
  78. package/cjs/koni/api/dotsama/balance.js +0 -464
  79. package/koni/api/dotsama/balance.d.ts +0 -6
  80. package/koni/api/dotsama/balance.js +0 -451
  81. package/utils/address.d.ts +0 -5
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.BalanceService = void 0;
7
7
  var _BalanceError = require("@subwallet/extension-base/background/errors/BalanceError");
8
8
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
- var _balance = require("@subwallet/extension-base/koni/api/dotsama/balance");
10
- var _handlers = require("@subwallet/extension-base/koni/background/handlers");
9
+ var _group = require("@subwallet/extension-base/services/balance-service/helpers/group");
10
+ var _evm = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/evm");
11
+ var _substrate = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/substrate");
11
12
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
12
13
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
13
14
  var _utils2 = require("@subwallet/extension-base/utils");
@@ -15,10 +16,17 @@ var _i18next = require("i18next");
15
16
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
16
17
  // SPDX-License-Identifier: Apache-2.0
17
18
 
19
+ /**
20
+ * Balance service
21
+ * @class
22
+ */
18
23
  class BalanceService {
19
- constructor(chainService) {
20
- this.chainService = chainService;
21
-
24
+ /**
25
+ * @constructor
26
+ * @param {KoniState} state - The state of extension.
27
+ */
28
+ constructor(state) {
29
+ this.state = state;
22
30
  // Todo: Load data from db to balanceSubject
23
31
  // Todo: Start subscribe balance and data
24
32
  // Todo: Listen change and apply to balanceSubject
@@ -29,9 +37,10 @@ class BalanceService {
29
37
  // Todo: Move everything of fetching balance to this service
30
38
  }
31
39
 
40
+ /* Subscribe token free balance on chain */
32
41
  async subscribeTokenFreeBalance(address, chain, tokenSlug, callback) {
33
- const chainInfo = this.chainService.getChainInfoByKey(chain);
34
- const chainState = this.chainService.getChainStateByKey(chain);
42
+ const chainInfo = this.state.chainService.getChainInfoByKey(chain);
43
+ const chainState = this.state.chainService.getChainStateByKey(chain);
35
44
  if (!chainInfo || !chainState || !chainState.active) {
36
45
  return Promise.reject(new _BalanceError.BalanceError(_KoniTypes.BalanceErrorType.NETWORK_ERROR, (0, _i18next.t)('{{chain}} is inactive. Please enable network', {
37
46
  replace: {
@@ -40,7 +49,7 @@ class BalanceService {
40
49
  })));
41
50
  }
42
51
  const tSlug = tokenSlug || (0, _utils._getChainNativeTokenSlug)(chainInfo);
43
- const tokenInfo = this.chainService.getAssetBySlug(tSlug);
52
+ const tokenInfo = this.state.chainService.getAssetBySlug(tSlug);
44
53
  if (!tokenInfo) {
45
54
  return Promise.reject(new _BalanceError.BalanceError(_KoniTypes.BalanceErrorType.TOKEN_ERROR, (0, _i18next.t)('Transfer is currently not available for this token: {{tSlug}}', {
46
55
  replace: {
@@ -75,35 +84,51 @@ class BalanceService {
75
84
  }, 9999);
76
85
  });
77
86
  }
87
+
88
+ /**
89
+ * @public
90
+ * @async
91
+ * @function getTokenFreeBalance
92
+ * @desc Fetch free balance on chain
93
+ * @param {string} address - Address
94
+ * @param {string} chain - Slug of chain
95
+ * @param {string} [tokenSlug] - Slug of token
96
+ * @return {Promise<AmountData>} - Free token balance of address on chain
97
+ */
78
98
  async getTokenFreeBalance(address, chain, tokenSlug) {
79
99
  const [, balance] = await this.subscribeTokenFreeBalance(address, chain, tokenSlug);
80
100
  return balance;
81
101
  }
82
- subscribeBalance(addresses, chains, callback) {
102
+ subscribeBalance(addresses, chains, _callback) {
83
103
  const [substrateAddresses, evmAddresses] = (0, _utils2.categoryAddresses)(addresses);
84
- const chainInfoMap = this.chainService.getChainInfoMap();
85
- const chainStateMap = this.chainService.getChainStateMap();
86
- const substrateApiMap = this.chainService.getSubstrateApiMap();
87
- const evmApiMap = this.chainService.getEvmApiMap();
104
+ const chainInfoMap = this.state.chainService.getChainInfoMap();
105
+ const chainStateMap = this.state.chainService.getChainStateMap();
106
+ const substrateApiMap = this.state.chainService.getSubstrateApiMap();
107
+ const evmApiMap = this.state.chainService.getEvmApiMap();
88
108
 
89
109
  // Get data from chain or all chains
90
110
  const chainList = chains || Object.keys(chainInfoMap);
91
111
  // Filter active chain only
92
112
  const useChainInfos = chainList.filter(c => chainStateMap[c] && chainStateMap[c].active).map(c => chainInfoMap[c]);
113
+ const callback = items => {
114
+ if (items.length) {
115
+ _callback((0, _group.groupBalance)(items, 'GROUPED', items[0].tokenSlug));
116
+ }
117
+ };
93
118
 
94
119
  // Looping over each chain
95
120
  const unsubList = useChainInfos.map(async chainInfo => {
96
121
  const chainSlug = chainInfo.slug;
97
122
  const useAddresses = (0, _utils._isChainEvmCompatible)(chainInfo) ? evmAddresses : substrateAddresses;
98
123
  if ((0, _utils._isPureEvmChain)(chainInfo)) {
99
- const nativeTokenInfo = _handlers.state.getNativeTokenInfo(chainSlug);
100
- return (0, _balance.subscribeEVMBalance)(chainSlug, useAddresses, evmApiMap, callback, nativeTokenInfo);
124
+ const nativeTokenInfo = this.state.getNativeTokenInfo(chainSlug);
125
+ return (0, _evm.subscribeEVMBalance)(chainSlug, useAddresses, evmApiMap, callback, nativeTokenInfo);
101
126
  }
102
127
  if (!useAddresses || useAddresses.length === 0 || _constants._PURE_EVM_CHAINS.indexOf(chainSlug) > -1) {
103
128
  return undefined;
104
129
  }
105
130
  const networkAPI = await substrateApiMap[chainSlug].isReady;
106
- return (0, _balance.subscribeSubstrateBalance)(useAddresses, chainInfo, chainSlug, networkAPI, evmApiMap, callback);
131
+ return (0, _substrate.subscribeSubstrateBalance)(useAddresses, chainInfo, chainSlug, networkAPI, evmApiMap, callback);
107
132
  });
108
133
  return () => {
109
134
  unsubList.forEach(subProm => {
@@ -20,6 +20,12 @@ function paramJsonParse(item) {
20
20
  return [];
21
21
  }
22
22
  }
23
+ function autoAddPublicKeyPrefix(publicKey) {
24
+ if (!publicKey.startsWith('0x')) {
25
+ return `0x${publicKey}`;
26
+ }
27
+ return publicKey;
28
+ }
23
29
  function balanceTransferParserFunction(item) {
24
30
  const params = paramJsonParse(item);
25
31
  params.forEach(p => {
@@ -27,7 +33,7 @@ function balanceTransferParserFunction(item) {
27
33
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
28
34
  const toPublicKey = p.value.id || p.value.Id;
29
35
  if (toPublicKey) {
30
- item.to = (0, _utilCrypto.encodeAddress)(toPublicKey, 42);
36
+ item.to = (0, _utilCrypto.encodeAddress)(autoAddPublicKeyPrefix(toPublicKey), 42);
31
37
  }
32
38
  } else if (p.name === 'value') {
33
39
  if (item.amount) {
@@ -83,7 +83,7 @@ class HistoryService {
83
83
  const excludeExtrinsicParserKeys = ['balances.transfer_all'];
84
84
 
85
85
  // Note: fetchAllPossibleExtrinsicItems and fetchAllPossibleTransferItems-receive can run parallelly
86
- // Hover, fetchAllPossibleTransferItems-sent must run after fetchAllPossibleExtrinsicItems,
86
+ // However, fetchAllPossibleTransferItems-sent must run after fetchAllPossibleExtrinsicItems,
87
87
  // to avoid "duplicate Extrinsic Hash between items" problem
88
88
 
89
89
  this.subscanService.fetchAllPossibleExtrinsicItems(chain, address, extrinsicItems => {
@@ -104,11 +104,12 @@ class HistoryService {
104
104
  excludeTransferExtrinsicHash.push(x.extrinsic_hash);
105
105
  }
106
106
  });
107
- this.subscanService.fetchAllPossibleTransferItems(chain, address, 'sent', transferItems => {
107
+ this.subscanService.fetchAllPossibleTransferItems(chain, address, 'sent').then(rsMap => {
108
108
  const result = [];
109
- transferItems.forEach(t => {
110
- if (!excludeTransferExtrinsicHash.includes(t.hash)) {
111
- result.push((0, _subscanHistory.parseSubscanTransferData)(address, t, chainInfo));
109
+ Object.keys(rsMap).forEach(hash => {
110
+ // only push item that does not have same hash with another item
111
+ if (!excludeTransferExtrinsicHash.includes(hash) && rsMap[hash].length === 1) {
112
+ result.push((0, _subscanHistory.parseSubscanTransferData)(address, rsMap[hash][0], chainInfo));
112
113
  }
113
114
  });
114
115
  this.addHistoryItems(result).catch(e => {
@@ -120,10 +121,13 @@ class HistoryService {
120
121
  }).catch(e => {
121
122
  console.log('fetchAllPossibleExtrinsicItems error', e);
122
123
  });
123
- this.subscanService.fetchAllPossibleTransferItems(chain, address, 'received', transferItems => {
124
+ this.subscanService.fetchAllPossibleTransferItems(chain, address, 'received').then(rsMap => {
124
125
  const result = [];
125
- transferItems.forEach(t => {
126
- result.push((0, _subscanHistory.parseSubscanTransferData)(address, t, chainInfo));
126
+ Object.keys(rsMap).forEach(hash => {
127
+ // only push item that does not have same hash with another item
128
+ if (rsMap[hash].length === 1) {
129
+ result.push((0, _subscanHistory.parseSubscanTransferData)(address, rsMap[hash][0], chainInfo));
130
+ }
127
131
  });
128
132
  this.addHistoryItems(result).catch(e => {
129
133
  console.log('addHistoryItems in fetchAllPossibleTransferItems-receive error', e);
@@ -14,7 +14,7 @@ class MigrateProvider extends _Base.default {
14
14
  const state = this.state;
15
15
  const chainState = state.getChainStateByKey(this.slug);
16
16
  const chainInfo = state.getChainInfo(this.slug);
17
- if (chainState.active && chainState.currentProvider === this.oldProvider) {
17
+ if (chainState && chainState.active && chainState.currentProvider === this.oldProvider) {
18
18
  await state.upsertChainInfo({
19
19
  mode: 'update',
20
20
  chainEditInfo: {
@@ -65,14 +65,19 @@ class DatabaseService {
65
65
  async getStoredBalance() {
66
66
  return this.stores.balance.table.toArray();
67
67
  }
68
- async updateBalanceStore(address, item) {
68
+ async updateBalanceStore(item) {
69
69
  if (item.state === _KoniTypes.APIItemState.READY) {
70
70
  return this.stores.balance.upsert({
71
- address,
72
71
  ...item
73
72
  });
74
73
  }
75
74
  }
75
+ async updateBulkBalanceStore(items) {
76
+ const filtered = items.filter(item => item.state !== _KoniTypes.APIItemState.PENDING);
77
+ if (filtered.length) {
78
+ return this.stores.balance.bulkUpsert(filtered);
79
+ }
80
+ }
76
81
  async removeFromBalanceStore(assets) {
77
82
  return this.stores.balance.removeBySlugs(assets);
78
83
  }
@@ -10,17 +10,17 @@ var _BaseStoreWithAddress = _interopRequireDefault(require("../db-stores/BaseSto
10
10
  // SPDX-License-Identifier: Apache-2.0
11
11
 
12
12
  class BalanceStore extends _BaseStoreWithAddress.default {
13
- async getBalanceMapByAddress(address) {
14
- const data = await this.table.where('address').equals(address).toArray();
13
+ async getBalanceMapByAddresses(addresses) {
14
+ const data = await this.table.where('address').anyOf(addresses).toArray();
15
15
  const balanceMap = {};
16
16
  data.forEach(storedBalance => {
17
- balanceMap[storedBalance.tokenSlug] = {
18
- tokenSlug: storedBalance.tokenSlug,
19
- state: storedBalance.state,
20
- free: storedBalance.free,
21
- locked: storedBalance.locked,
22
- substrateInfo: storedBalance.substrateInfo,
23
- timestamp: storedBalance.timestamp
17
+ const address = storedBalance.address;
18
+ const slug = storedBalance.tokenSlug;
19
+ if (!balanceMap[address]) {
20
+ balanceMap[address] = {};
21
+ }
22
+ balanceMap[address][slug] = {
23
+ ...storedBalance
24
24
  };
25
25
  });
26
26
  return balanceMap;
@@ -129,11 +129,19 @@ class SubscanService {
129
129
  }
130
130
  getExtrinsicsList(chain, address) {
131
131
  let page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
132
+ let blockRange = arguments.length > 3 ? arguments[3] : undefined;
133
+ const _blockRange = (() => {
134
+ if (!blockRange || !blockRange.to) {
135
+ return null;
136
+ }
137
+ return `${blockRange.from || 0}-${blockRange.to}`;
138
+ })();
132
139
  return this.addRequest(async () => {
133
140
  const rs = await this.postRequest(this.getApiUrl(chain, 'api/scan/extrinsics'), {
134
141
  page,
135
142
  row: QUERY_ROW,
136
- address
143
+ address,
144
+ block_range: _blockRange
137
145
  });
138
146
  if (rs.status !== 200) {
139
147
  throw new _SWError.SWError('SubscanService.getExtrinsicsList', await rs.text());
@@ -143,22 +151,38 @@ class SubscanService {
143
151
  });
144
152
  }
145
153
  async fetchAllPossibleExtrinsicItems(chain, address, cbAfterEachRequest) {
146
- let count = 0;
154
+ let limit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
155
+ page: 10,
156
+ record: 1000
157
+ };
158
+ let maxCount = 0;
159
+ let currentCount = 0;
160
+ const blockRange = {
161
+ from: null,
162
+ to: null
163
+ };
147
164
  const resultMap = {};
148
165
  const _getExtrinsicItems = async page => {
149
- const res = await this.getExtrinsicsList(chain, address, page);
166
+ const res = await this.getExtrinsicsList(chain, address, page, blockRange);
150
167
  if (!res || !res.count || !res.extrinsics || !res.extrinsics.length) {
151
168
  return;
152
169
  }
153
- if (res.count > count) {
154
- count = res.count;
170
+ if (res.count > maxCount) {
171
+ maxCount = res.count;
155
172
  }
156
173
  cbAfterEachRequest === null || cbAfterEachRequest === void 0 ? void 0 : cbAfterEachRequest(res.extrinsics);
157
174
  res.extrinsics.forEach(item => {
158
175
  resultMap[item.extrinsic_hash] = item;
159
176
  });
160
- if (Object.values(resultMap).length < count) {
177
+ currentCount += res.extrinsics.length;
178
+ if (page > limit.page || currentCount > limit.record) {
179
+ return;
180
+ }
181
+ if (currentCount < maxCount) {
161
182
  await (0, _utils.wait)(100);
183
+ if (page === 0) {
184
+ blockRange.to = res.extrinsics[0].block_num;
185
+ }
162
186
  await _getExtrinsicItems(++page);
163
187
  }
164
188
  };
@@ -168,16 +192,16 @@ class SubscanService {
168
192
  getTransfersList(chain, address) {
169
193
  let page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
170
194
  let direction = arguments.length > 3 ? arguments[3] : undefined;
171
- const requestBody = {
172
- page,
173
- row: QUERY_ROW,
174
- address
175
- };
176
- if (direction) {
177
- requestBody.direction = direction;
178
- }
195
+ let blockRange = arguments.length > 4 ? arguments[4] : undefined;
179
196
  return this.addRequest(async () => {
180
- const rs = await this.postRequest(this.getApiUrl(chain, 'api/v2/scan/transfers'), requestBody);
197
+ const rs = await this.postRequest(this.getApiUrl(chain, 'api/v2/scan/transfers'), {
198
+ page,
199
+ row: QUERY_ROW,
200
+ address,
201
+ direction: direction || null,
202
+ from_block: (blockRange === null || blockRange === void 0 ? void 0 : blockRange.from) || null,
203
+ to_block: (blockRange === null || blockRange === void 0 ? void 0 : blockRange.to) || null
204
+ });
181
205
  if (rs.status !== 200) {
182
206
  throw new _SWError.SWError('SubscanService.getTransfersList', await rs.text());
183
207
  }
@@ -186,27 +210,47 @@ class SubscanService {
186
210
  });
187
211
  }
188
212
  async fetchAllPossibleTransferItems(chain, address, direction, cbAfterEachRequest) {
189
- let count = 0;
213
+ let limit = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
214
+ page: 10,
215
+ record: 1000
216
+ };
217
+ let maxCount = 0;
218
+ let currentCount = 0;
219
+ const blockRange = {
220
+ from: null,
221
+ to: null
222
+ };
190
223
  const resultMap = {};
191
224
  const _getTransferItems = async page => {
192
- const res = await this.getTransfersList(chain, address, page, direction);
225
+ const res = await this.getTransfersList(chain, address, page, direction, blockRange);
193
226
  if (!res || !res.count || !res.transfers || !res.transfers.length) {
194
227
  return;
195
228
  }
196
- if (res.count > count) {
197
- count = res.count;
229
+ if (res.count > maxCount) {
230
+ maxCount = res.count;
198
231
  }
199
232
  cbAfterEachRequest === null || cbAfterEachRequest === void 0 ? void 0 : cbAfterEachRequest(res.transfers);
200
233
  res.transfers.forEach(item => {
201
- resultMap[item.hash] = item;
234
+ if (!resultMap[item.hash]) {
235
+ resultMap[item.hash] = [item];
236
+ } else {
237
+ resultMap[item.hash].push(item);
238
+ }
202
239
  });
203
- if (Object.values(resultMap).length < count) {
240
+ currentCount += res.transfers.length;
241
+ if (page > limit.page || currentCount > limit.record) {
242
+ return;
243
+ }
244
+ if (currentCount < maxCount) {
204
245
  await (0, _utils.wait)(100);
246
+ if (page === 0) {
247
+ blockRange.to = res.transfers[0].block_num;
248
+ }
205
249
  await _getTransferItems(++page);
206
250
  }
207
251
  };
208
252
  await _getTransferItems(0);
209
- return Object.values(resultMap);
253
+ return resultMap;
210
254
  }
211
255
  }
212
256
  exports.SubscanService = SubscanService;
@@ -121,7 +121,8 @@ class TransactionService {
121
121
  if (!web3) {
122
122
  validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
123
123
  } else {
124
- const gasPrice = await web3.api.eth.getGasPrice();
124
+ const _price = await web3.api.eth.getGasPrice();
125
+ const gasPrice = (0, _eth.recalculateGasPrice)(_price, chainInfo.slug);
125
126
  const gasLimit = await web3.api.eth.estimateGas(transaction);
126
127
  estimateFee.value = (gasLimit * parseInt(gasPrice)).toString();
127
128
  }
@@ -932,8 +933,8 @@ class TransactionService {
932
933
  }).forEach(_ref11 => {
933
934
  let {
934
935
  event: {
935
- method,
936
- data: [error]
936
+ data: [error],
937
+ method
937
938
  }
938
939
  } = _ref11;
939
940
  if (method === 'ExtrinsicFailed') {
@@ -0,0 +1 @@
1
+ "use strict";
@@ -3,6 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _balance = require("./balance");
7
+ Object.keys(_balance).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _balance[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _balance[key];
14
+ }
15
+ });
16
+ });
6
17
  var _buy = require("./buy");
7
18
  Object.keys(_buy).forEach(function (key) {
8
19
  if (key === "default" || key === "__esModule") return;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.convertSubjectInfoToAddresses = void 0;
7
+ exports.getAccountJsonByAddress = exports.convertSubjectInfoToAddresses = void 0;
7
8
  exports.quickFormatAddressToCompare = quickFormatAddressToCompare;
8
9
  exports.simpleAddress = void 0;
9
10
  var _index = require("@subwallet/extension-base/utils/index");
11
+ var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
10
12
  var _utilCrypto = require("@polkadot/util-crypto");
11
13
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
12
14
  // SPDX-License-Identifier: Apache-2.0
@@ -31,4 +33,32 @@ const convertSubjectInfoToAddresses = subjectInfo => {
31
33
  ...info.json.meta
32
34
  }));
33
35
  };
34
- exports.convertSubjectInfoToAddresses = convertSubjectInfoToAddresses;
36
+
37
+ /**
38
+ * @function getAccountJsonByAddress
39
+ * @desc Get account info by address
40
+ * <p>
41
+ * Note: Use on the background only
42
+ * </p>
43
+ * @param {string} address - Address
44
+ * @returns {AccountJson|null} - Account info or null if not found
45
+ */
46
+ exports.convertSubjectInfoToAddresses = convertSubjectInfoToAddresses;
47
+ const getAccountJsonByAddress = address => {
48
+ try {
49
+ const pair = _uiKeyring.default.getPair(address);
50
+ if (pair) {
51
+ return {
52
+ address: pair.address,
53
+ type: pair.type,
54
+ ...pair.meta
55
+ };
56
+ } else {
57
+ return null;
58
+ }
59
+ } catch (e) {
60
+ console.warn(e);
61
+ return null;
62
+ }
63
+ };
64
+ exports.getAccountJsonByAddress = getAccountJsonByAddress;
package/cjs/utils/eth.js CHANGED
@@ -4,7 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.signatureToHex = exports.createTransactionFromRLP = exports.anyNumberToBN = exports.Transaction = void 0;
7
+ exports.signatureToHex = exports.recalculateGasPrice = exports.createTransactionFromRLP = exports.anyNumberToBN = exports.Transaction = void 0;
8
+ var _constants = require("@subwallet/extension-base/constants");
8
9
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
9
10
  var _ethers = require("ethers");
10
11
  var _util = require("@polkadot/util");
@@ -69,4 +70,8 @@ const signatureToHex = sig => {
69
70
  const hexV = (0, _util.hexStripPrefix)((0, _util.numberToHex)(v));
70
71
  return hexR + hexS + hexV;
71
72
  };
72
- exports.signatureToHex = signatureToHex;
73
+ exports.signatureToHex = signatureToHex;
74
+ const recalculateGasPrice = (_price, chain) => {
75
+ return _constants.NETWORK_MULTI_GAS_FEE.includes(chain) ? new _bignumber.default(_price).multipliedBy(_constants.GAS_PRICE_RATIO).toFixed(0) : _price;
76
+ };
77
+ exports.recalculateGasPrice = recalculateGasPrice;
@@ -78,6 +78,18 @@ var _i18next = require("i18next");
78
78
  var _util = require("@polkadot/util");
79
79
  var _utilCrypto = require("@polkadot/util-crypto");
80
80
  var _canDerive = require("./canDerive");
81
+ var _account = require("./account");
82
+ Object.keys(_account).forEach(function (key) {
83
+ if (key === "default" || key === "__esModule") return;
84
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
85
+ if (key in exports && exports[key] === _account[key]) return;
86
+ Object.defineProperty(exports, key, {
87
+ enumerable: true,
88
+ get: function () {
89
+ return _account[key];
90
+ }
91
+ });
92
+ });
81
93
  var _array = require("./array");
82
94
  Object.keys(_array).forEach(function (key) {
83
95
  if (key === "default" || key === "__esModule") return;
@@ -20,5 +20,7 @@ export declare const ALL_GENESIS_HASH: null;
20
20
  export declare const IGNORE_GET_SUBSTRATE_FEATURES_LIST: string[];
21
21
  export declare const IGNORE_QR_SIGNER: string[];
22
22
  export declare const XCM_MIN_AMOUNT_RATIO = 1.2;
23
+ export declare const GAS_PRICE_RATIO = 1.05;
24
+ export declare const NETWORK_MULTI_GAS_FEE: string[];
23
25
  export * from './staking';
24
26
  export * from './storage';
@@ -23,5 +23,7 @@ export const ALL_GENESIS_HASH = null;
23
23
  export const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
24
24
  export const IGNORE_QR_SIGNER = [];
25
25
  export const XCM_MIN_AMOUNT_RATIO = 1.2;
26
+ export const GAS_PRICE_RATIO = 1.05;
27
+ export const NETWORK_MULTI_GAS_FEE = ['astarEvm'];
26
28
  export * from "./staking.js";
27
29
  export * from "./storage.js";
@@ -104,6 +104,7 @@ export async function getCancelWithdrawalExtrinsic(substrateApi, chain, selected
104
104
  export function subscribeEssentialChainStakingMetadata(substrateApiMap, chainInfoMap, callback) {
105
105
  const unsubList = [];
106
106
 
107
+ // TODO: replace with for of to improve performance
107
108
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
108
109
  Object.values(chainInfoMap).forEach(async chainInfo => {
109
110
  if (!substrateApiMap[chainInfo.slug]) {
@@ -4,6 +4,10 @@
4
4
  export async function getEVMBalance(networkKey, addresses, evmApiMap) {
5
5
  const web3Api = evmApiMap[networkKey];
6
6
  return await Promise.all(addresses.map(async address => {
7
- return await web3Api.api.eth.getBalance(address);
7
+ try {
8
+ return await web3Api.api.eth.getBalance(address);
9
+ } catch (e) {
10
+ return '0';
11
+ }
8
12
  }));
9
13
  }
@@ -13,5 +13,5 @@ interface HandleTransferBalanceResultProps {
13
13
  export declare const handleTransferBalanceResult: ({ callback, changeValue, networkKey, receipt, response, updateState }: HandleTransferBalanceResultProps) => void;
14
14
  export declare function getEVMTransactionObject(chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
15
15
  export declare function getERC20TransactionObject(assetAddress: string, chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
16
- export declare function getERC721Transaction(web3Api: _EvmApi, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string): Promise<TransactionConfig>;
16
+ export declare function getERC721Transaction(web3Api: _EvmApi, chain: string, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string): Promise<TransactionConfig>;
17
17
  export {};
@@ -5,6 +5,7 @@ import { ExternalRequestPromiseStatus } from '@subwallet/extension-base/backgrou
5
5
  import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/web3';
6
6
  import { _BALANCE_PARSING_CHAIN_GROUP, EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-service/constants';
7
7
  import { _ERC721_ABI } from '@subwallet/extension-base/services/chain-service/helper';
8
+ import { recalculateGasPrice } from '@subwallet/extension-base/utils/eth';
8
9
  import { BN, hexToBn } from '@polkadot/util';
9
10
  export const handleTransferBalanceResult = ({
10
11
  callback,
@@ -35,7 +36,8 @@ export const handleTransferBalanceResult = ({
35
36
  export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, evmApiMap) {
36
37
  const networkKey = chainInfo.slug;
37
38
  const web3Api = evmApiMap[networkKey];
38
- const gasPrice = await web3Api.api.eth.getGasPrice();
39
+ const _price = await web3Api.api.eth.getGasPrice();
40
+ const gasPrice = recalculateGasPrice(_price, chainInfo.slug);
39
41
  const transactionObject = {
40
42
  gasPrice: gasPrice,
41
43
  to: to,
@@ -69,11 +71,12 @@ export async function getERC20TransactionObject(assetAddress, chainInfo, from, t
69
71
  return erc20Contract.methods.transfer(to, transferValue).encodeABI();
70
72
  }
71
73
  const transferData = generateTransferData(to, transferValue);
72
- const [gasLimit, gasPrice] = await Promise.all([
74
+ const [gasLimit, _price] = await Promise.all([
73
75
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
74
76
  erc20Contract.methods.transfer(to, transferValue).estimateGas({
75
77
  from
76
78
  }), evmApi.api.eth.getGasPrice()]);
79
+ const gasPrice = recalculateGasPrice(_price, chainInfo.slug);
77
80
  const transactionObject = {
78
81
  gasPrice: gasPrice,
79
82
  gas: gasLimit,
@@ -87,14 +90,15 @@ export async function getERC20TransactionObject(assetAddress, chainInfo, from, t
87
90
  }
88
91
  return [transactionObject, transferValue];
89
92
  }
90
- export async function getERC721Transaction(web3Api, contractAddress, senderAddress, recipientAddress, tokenId) {
93
+ export async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId) {
91
94
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
92
95
  const contract = new web3Api.api.eth.Contract(_ERC721_ABI, contractAddress);
93
- const [gasLimit, gasPrice] = await Promise.all([
96
+ const [gasLimit, _price] = await Promise.all([
94
97
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
95
98
  contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).estimateGas({
96
99
  from: senderAddress
97
100
  }), web3Api.api.eth.getGasPrice()]);
101
+ const gasPrice = recalculateGasPrice(_price, chain);
98
102
  return {
99
103
  from: senderAddress,
100
104
  gasPrice,
@@ -1,7 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
4
+ import { CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
5
5
  import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  import { waitTimeout } from '@subwallet/extension-base/utils';
7
7
  import { Subject } from 'rxjs';
@@ -104,8 +104,8 @@ export class KoniCron {
104
104
  if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
105
105
  this.resetNft(currentAccountInfo.address);
106
106
  this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
107
- this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
108
- this.addCron('refreshPoolingSta kingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
107
+ // this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
108
+ this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
109
109
  this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
110
110
  } else {
111
111
  this.setStakingRewardReady();