@subwallet/extension-base 1.1.51-2 → 1.1.53-0

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 (71) hide show
  1. package/cjs/koni/api/tokens/evm/balance.js +1 -2
  2. package/cjs/koni/api/tokens/evm/transfer.js +3 -5
  3. package/cjs/koni/api/tokens/evm/web3.js +3 -3
  4. package/cjs/koni/background/handlers/Extension.js +5 -4
  5. package/cjs/koni/background/handlers/State.js +8 -71
  6. package/cjs/koni/background/subscription.js +3 -63
  7. package/cjs/packageInfo.js +1 -1
  8. package/cjs/services/balance-service/BalanceMapImpl.js +2 -2
  9. package/cjs/services/balance-service/helpers/index.js +27 -0
  10. package/cjs/services/balance-service/helpers/subscribe/evm.js +33 -15
  11. package/cjs/services/balance-service/helpers/subscribe/{balance.js → index.js} +46 -29
  12. package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +34 -15
  13. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +157 -72
  14. package/cjs/services/balance-service/index.js +277 -75
  15. package/cjs/services/chain-service/constants.js +2 -1
  16. package/cjs/services/chain-service/health-check/utils/asset-info.js +1 -3
  17. package/cjs/services/chain-service/index.js +1 -9
  18. package/cjs/services/chain-service/utils/patch.js +1 -1
  19. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
  20. package/cjs/services/request-service/handler/ConnectWCRequestHandler.js +0 -1
  21. package/cjs/services/storage-service/DatabaseService.js +10 -1
  22. package/cjs/services/wallet-connect-service/helpers.js +1 -1
  23. package/cjs/services/wallet-connect-service/index.js +19 -0
  24. package/cjs/utils/asset.js +19 -0
  25. package/cjs/utils/eth/parseTransaction/index.js +1 -1
  26. package/cjs/utils/index.js +12 -0
  27. package/koni/api/tokens/evm/balance.d.ts +1 -1
  28. package/koni/api/tokens/evm/balance.js +1 -2
  29. package/koni/api/tokens/evm/transfer.d.ts +2 -2
  30. package/koni/api/tokens/evm/transfer.js +3 -5
  31. package/koni/api/tokens/evm/web3.d.ts +1 -1
  32. package/koni/api/tokens/evm/web3.js +2 -2
  33. package/koni/background/handlers/Extension.js +5 -4
  34. package/koni/background/handlers/State.d.ts +1 -12
  35. package/koni/background/handlers/State.js +9 -72
  36. package/koni/background/subscription.d.ts +1 -5
  37. package/koni/background/subscription.js +1 -60
  38. package/package.json +23 -13
  39. package/packageInfo.js +1 -1
  40. package/services/balance-service/BalanceMapImpl.js +1 -1
  41. package/services/balance-service/helpers/index.d.ts +2 -0
  42. package/services/balance-service/helpers/index.js +5 -0
  43. package/services/balance-service/helpers/subscribe/evm.d.ts +3 -5
  44. package/services/balance-service/helpers/subscribe/evm.js +31 -14
  45. package/services/balance-service/helpers/subscribe/{balance.d.ts → index.d.ts} +2 -2
  46. package/services/balance-service/helpers/subscribe/{balance.js → index.js} +41 -28
  47. package/services/balance-service/helpers/subscribe/substrate/equilibrium.d.ts +3 -4
  48. package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +29 -13
  49. package/services/balance-service/helpers/subscribe/substrate/index.d.ts +2 -2
  50. package/services/balance-service/helpers/subscribe/substrate/index.js +144 -67
  51. package/services/balance-service/index.d.ts +64 -6
  52. package/services/balance-service/index.js +279 -77
  53. package/services/chain-service/constants.js +2 -1
  54. package/services/chain-service/health-check/utils/asset-info.js +1 -3
  55. package/services/chain-service/index.js +2 -10
  56. package/services/chain-service/utils/patch.js +1 -1
  57. package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
  58. package/services/request-service/handler/ConnectWCRequestHandler.js +0 -1
  59. package/services/storage-service/DatabaseService.js +7 -1
  60. package/services/wallet-connect-service/helpers.js +1 -1
  61. package/services/wallet-connect-service/index.d.ts +1 -0
  62. package/services/wallet-connect-service/index.js +19 -1
  63. package/types/{balance.d.ts → balance/index.d.ts} +16 -0
  64. package/types/index.js +1 -1
  65. package/utils/asset.d.ts +2 -0
  66. package/utils/asset.js +12 -0
  67. package/utils/eth/parseTransaction/index.js +1 -1
  68. package/utils/index.d.ts +1 -0
  69. package/utils/index.js +1 -0
  70. /package/cjs/types/{balance.js → balance/index.js} +0 -0
  71. /package/types/{balance.js → balance/index.js} +0 -0
@@ -7,10 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.BalanceService = void 0;
8
8
  var _BalanceError = require("@subwallet/extension-base/background/errors/BalanceError");
9
9
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
10
- var _group = require("@subwallet/extension-base/services/balance-service/helpers/group");
11
- var _evm = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/evm");
12
- var _substrate = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/substrate");
13
- var _constants = require("@subwallet/extension-base/services/chain-service/constants");
10
+ var _constants = require("@subwallet/extension-base/constants");
11
+ var _types = require("@subwallet/extension-base/services/base/types");
14
12
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
15
13
  var _DetectAccountBalance = _interopRequireDefault(require("@subwallet/extension-base/stores/DetectAccountBalance"));
16
14
  var _utils2 = require("@subwallet/extension-base/utils");
@@ -18,6 +16,8 @@ var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
18
16
  var _i18next = require("i18next");
19
17
  var _rxjs = require("rxjs");
20
18
  var _util = require("@polkadot/util");
19
+ var _BalanceMapImpl = require("./BalanceMapImpl");
20
+ var _helpers = require("./helpers");
21
21
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
22
22
  // SPDX-License-Identifier: Apache-2.0
23
23
 
@@ -26,56 +26,127 @@ var _util = require("@polkadot/util");
26
26
  * @class
27
27
  */
28
28
  class BalanceService {
29
+ balanceUpdateCache = [];
30
+ startPromiseHandler = (0, _utils2.createPromiseHandler)();
31
+ stopPromiseHandler = (0, _utils2.createPromiseHandler)();
32
+ status = _types.ServiceStatus.NOT_INITIALIZED;
33
+ isReload = false;
29
34
  detectAccountBalanceStore = new _DetectAccountBalance.default();
30
35
  balanceDetectSubject = new _rxjs.BehaviorSubject({});
31
36
  intervalTime = 3 * 60 * 1000;
32
37
  cacheTime = 15 * 60 * 1000;
38
+
33
39
  /**
34
40
  * @constructor
35
41
  * @param {KoniState} state - The state of extension.
36
42
  */
37
43
  constructor(state) {
38
44
  this.state = state;
39
- // Todo: Load data from db to balanceSubject
40
- // Todo: Start subscribe balance and data
41
- // Todo: Listen change and apply to balanceSubject
42
- // Todo: Active/Chain
43
- // Todo: Add/remove account
44
- // Todo: Add new account
45
- // Todo: Optimize get balance for single account and chain with cache
46
- // Todo: Move everything of fetching balance to this service
47
-
48
- this.startHandler = (0, _utils2.createPromiseHandler)();
49
- const updateBalanceDetectCache = value => {
50
- this.startHandler.resolve();
51
- this.balanceDetectSubject.next(value || {});
52
- };
53
- this.getBalanceDetectCache(updateBalanceDetectCache);
54
- this.detectAccountBalanceStore.getSubject().subscribe({
55
- next: updateBalanceDetectCache
56
- });
57
- this.startDetectBalance().catch(console.error);
45
+ this.balanceMap = new _BalanceMapImpl.BalanceMapImpl();
58
46
  }
59
- async startDetectBalance() {
60
- const scanBalance = () => {
61
- const addresses = _uiKeyring.default.getPairs().map(account => account.address);
62
- const cache = this.balanceDetectSubject.value;
63
- const now = Date.now();
64
- const needDetectAddresses = [];
65
- for (const address of addresses) {
66
- if (!cache[address] || now - cache[address] > this.cacheTime) {
67
- needDetectAddresses.push(address);
68
- }
47
+
48
+ /** Init service */
49
+ async init() {
50
+ this.status = _types.ServiceStatus.INITIALIZING;
51
+ await this.state.eventService.waitChainReady;
52
+ await this.state.eventService.waitAccountReady;
53
+
54
+ // Load data from db to balanceSubject
55
+ await this.loadData();
56
+ this.status = _types.ServiceStatus.INITIALIZED;
57
+
58
+ // Start service
59
+ await this.start();
60
+
61
+ // Handle events
62
+ this.state.eventService.onLazy(this.handleEvents.bind(this));
63
+ }
64
+
65
+ /** Restore balance map */
66
+ async loadData() {
67
+ const backupBalanceData = await this.state.dbService.getStoredBalance();
68
+ this.balanceMap.updateBalanceItems(backupBalanceData, true);
69
+ }
70
+
71
+ /** Start service */
72
+ async start() {
73
+ if (this.status === _types.ServiceStatus.STOPPING) {
74
+ await this.waitForStopped();
75
+ }
76
+ if (this.status === _types.ServiceStatus.STARTED || this.status === _types.ServiceStatus.STARTING) {
77
+ return await this.waitForStarted();
78
+ }
79
+ this.status = _types.ServiceStatus.STARTING;
80
+ await this.startScanBalance();
81
+
82
+ // Run subscribe balance
83
+ await this.runSubscribeBalances();
84
+
85
+ // Update status
86
+ this.stopPromiseHandler = (0, _utils2.createPromiseHandler)();
87
+ this.status = _types.ServiceStatus.STARTED;
88
+ this.startPromiseHandler.resolve();
89
+ }
90
+
91
+ /** Stop service */
92
+ async stop() {
93
+ if (this.status === _types.ServiceStatus.STARTING) {
94
+ await this.waitForStarted();
95
+ }
96
+ if (this.status === _types.ServiceStatus.STOPPED || this.status === _types.ServiceStatus.STOPPING) {
97
+ return await this.waitForStopped();
98
+ }
99
+ this.runUnsubscribeBalances();
100
+ this.stopScanBalance();
101
+
102
+ // Update status
103
+ this.startPromiseHandler = (0, _utils2.createPromiseHandler)();
104
+ this.status = _types.ServiceStatus.STOPPING;
105
+ this.stopPromiseHandler.resolve();
106
+ }
107
+
108
+ /** Wait service start */
109
+ waitForStarted() {
110
+ return this.startPromiseHandler.promise;
111
+ }
112
+
113
+ /** Wait service stop */
114
+ waitForStopped() {
115
+ return this.stopPromiseHandler.promise;
116
+ }
117
+
118
+ /**
119
+ * Handle when data change
120
+ * */
121
+ handleEvents(events, eventTypes) {
122
+ const removedAddresses = [];
123
+ let needReload = false;
124
+ let lazyTime = 2000;
125
+
126
+ // Account changed or chain changed (active or inactive)
127
+ if (eventTypes.includes('account.updateCurrent') || eventTypes.includes('account.add') || eventTypes.includes('chain.updateState') || eventTypes.includes('asset.updateState')) {
128
+ needReload = true;
129
+ if (eventTypes.includes('account.updateCurrent')) {
130
+ lazyTime = 1000;
69
131
  }
70
- if (needDetectAddresses.length) {
71
- this.autoEnableChains(needDetectAddresses).finally(_util.noop);
132
+ }
133
+ events.forEach(event => {
134
+ if (event.type === 'account.remove') {
135
+ removedAddresses.push(event.data[0]);
136
+ lazyTime = 1000;
72
137
  }
73
- };
74
- await this.state.eventService.waitAccountReady;
75
- await this.state.eventService.waitChainReady;
76
- await this.startHandler.promise;
77
- scanBalance();
78
- setInterval(scanBalance, this.intervalTime);
138
+ });
139
+ if (removedAddresses.length > 0) {
140
+ this.balanceMap.removeBalanceItems([...removedAddresses, _constants.ALL_ACCOUNT_KEY]); // Add all account key to recalculate all account balances
141
+ needReload = true;
142
+ }
143
+ if (needReload) {
144
+ (0, _utils2.addLazy)('reloadBalanceByEvents', () => {
145
+ if (!this.isReload) {
146
+ this.runSubscribeBalances().catch(console.error);
147
+ }
148
+ }, lazyTime, undefined, true);
149
+ }
79
150
  }
80
151
  getBalanceDetectCache(update) {
81
152
  this.detectAccountBalanceStore.get('DetectBalanceCache', value => {
@@ -94,7 +165,7 @@ class BalanceService {
94
165
  });
95
166
  }
96
167
 
97
- /* Subscribe token free balance on chain */
168
+ /** Subscribe token free balance of a address on chain */
98
169
  async subscribeTokenFreeBalance(address, chain, tokenSlug, callback) {
99
170
  const chainInfo = this.state.chainService.getChainInfoByKey(chain);
100
171
  const chainState = this.state.chainService.getChainStateByKey(chain);
@@ -116,7 +187,12 @@ class BalanceService {
116
187
  }
117
188
  return new Promise((resolve, reject) => {
118
189
  let hasError = true;
119
- const unsub = this.subscribeBalance([address], [chain], rs => {
190
+ const assetMap = this.state.chainService.getAssetRegistry();
191
+ const chainInfoMap = this.state.chainService.getChainInfoMap();
192
+ const evmApiMap = this.state.chainService.getEvmApiMap();
193
+ const substrateApiMap = this.state.chainService.getSubstrateApiMap();
194
+ const unsub = (0, _helpers.subscribeBalance)([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
195
+ const rs = result[0];
120
196
  if (rs.tokenSlug === tSlug) {
121
197
  hasError = false;
122
198
  const balance = {
@@ -156,45 +232,131 @@ class BalanceService {
156
232
  const [, balance] = await this.subscribeTokenFreeBalance(address, chain, tokenSlug);
157
233
  return balance;
158
234
  }
159
- subscribeBalance(addresses, chains, _callback) {
160
- const [substrateAddresses, evmAddresses] = (0, _utils2.categoryAddresses)(addresses);
161
- const chainInfoMap = this.state.chainService.getChainInfoMap();
162
- const chainStateMap = this.state.chainService.getChainStateMap();
163
- const substrateApiMap = this.state.chainService.getSubstrateApiMap();
164
- const evmApiMap = this.state.chainService.getEvmApiMap();
165
235
 
166
- // Get data from chain or all chains
167
- const chainList = chains || Object.keys(chainInfoMap);
168
- // Filter active chain only
169
- const useChainInfos = chainList.filter(c => chainStateMap[c] && chainStateMap[c].active).map(c => chainInfoMap[c]);
170
- const callback = items => {
171
- if (items.length) {
172
- _callback((0, _group.groupBalance)(items, 'GROUPED', items[0].tokenSlug));
173
- }
236
+ /** Remove balance from the subject object by addresses */
237
+ removeBalanceByAddresses(addresses) {
238
+ this.balanceMap.removeBalanceItems([...addresses, _constants.ALL_ACCOUNT_KEY]);
239
+ }
240
+
241
+ /** Remove inactive asset from the balance map */
242
+ async removeInactiveChainBalances() {
243
+ const assetSettings = await this.state.chainService.getAssetSettings();
244
+ this.balanceMap.removeBalanceItemByFilter(item => {
245
+ return !assetSettings[item.tokenSlug];
246
+ });
247
+ }
248
+ async getBalance(reset) {
249
+ await this.removeInactiveChainBalances();
250
+ return {
251
+ details: this.balanceMap.map,
252
+ reset
174
253
  };
254
+ }
175
255
 
176
- // Looping over each chain
177
- const unsubList = useChainInfos.map(async chainInfo => {
178
- const chainSlug = chainInfo.slug;
179
- const useAddresses = (0, _utils._isChainEvmCompatible)(chainInfo) ? evmAddresses : substrateAddresses;
180
- if ((0, _utils._isPureEvmChain)(chainInfo)) {
181
- const nativeTokenInfo = this.state.getNativeTokenInfo(chainSlug);
182
- return (0, _evm.subscribeEVMBalance)(chainSlug, useAddresses, evmApiMap, callback, nativeTokenInfo);
183
- }
184
- if (!useAddresses || useAddresses.length === 0 || _constants._PURE_EVM_CHAINS.indexOf(chainSlug) > -1) {
185
- return undefined;
256
+ /** Get stored balance from db */
257
+ async getStoredBalance(address) {
258
+ return await this.state.dbService.stores.balance.getBalanceMapByAddresses(address);
259
+ }
260
+ async handleResetBalance(forceRefresh) {
261
+ if (forceRefresh) {
262
+ this.balanceMap.setData({});
263
+ await this.state.dbService.stores.balance.clear();
264
+ } else {
265
+ await Promise.all([this.removeInactiveChainBalances()]);
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Update value for balance map
271
+ * Note: items must be same tokenSlug */
272
+ setBalanceItem(items) {
273
+ if (items.length) {
274
+ const nowTime = new Date().getTime();
275
+ for (const item of items) {
276
+ const balance = {
277
+ timestamp: nowTime,
278
+ ...item
279
+ };
280
+ this.balanceUpdateCache.push(balance);
186
281
  }
187
- const networkAPI = await substrateApiMap[chainSlug].isReady;
188
- return (0, _substrate.subscribeSubstrateBalance)(useAddresses, chainInfo, chainSlug, networkAPI, evmApiMap, callback);
282
+ (0, _utils2.addLazy)('updateBalanceStore', () => {
283
+ const isAllAccount = (0, _utils2.isAccountAll)(this.state.keyringService.currentAccount.address);
284
+ this.balanceMap.updateBalanceItems(this.balanceUpdateCache, isAllAccount);
285
+ if (isAllAccount) {
286
+ this.balanceUpdateCache = [...this.balanceUpdateCache, ...Object.values(this.balanceMap.map[_constants.ALL_ACCOUNT_KEY])];
287
+ }
288
+ this.updateBalanceStore(this.balanceUpdateCache);
289
+ this.balanceUpdateCache = [];
290
+ }, 300, 1800);
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Store balance map to db
296
+ * */
297
+ updateBalanceStore(items) {
298
+ this.state.dbService.updateBulkBalanceStore(items).catch(console.warn);
299
+ }
300
+
301
+ /**
302
+ * Subscribe balance map with subject object
303
+ * */
304
+ subscribeBalanceMap() {
305
+ return this.balanceMap.mapSubject;
306
+ }
307
+
308
+ /** Subscribe area */
309
+
310
+ /** Subscribe balance subscription */
311
+ async runSubscribeBalances() {
312
+ await Promise.all([this.state.eventService.waitKeyringReady, this.state.eventService.waitChainReady]);
313
+ this.runUnsubscribeBalances();
314
+ const addresses = this.state.getDecodedAddresses();
315
+ if (!addresses.length) {
316
+ return;
317
+ }
318
+
319
+ // Reset balance before subscribe
320
+ await this.handleResetBalance();
321
+ let cancel = false;
322
+ const assetMap = this.state.chainService.getAssetRegistry();
323
+ const chainInfoMap = this.state.chainService.getChainInfoMap();
324
+ const evmApiMap = this.state.chainService.getEvmApiMap();
325
+ const substrateApiMap = this.state.chainService.getSubstrateApiMap();
326
+ const activeChainSlugs = Object.keys(this.state.getActiveChainInfoMap());
327
+ const assetState = this.state.chainService.subscribeAssetSettings().value;
328
+ const assets = Object.values(assetMap).filter(asset => {
329
+ var _assetState$asset$slu;
330
+ return activeChainSlugs.includes(asset.originChain) && ((_assetState$asset$slu = assetState[asset.slug]) === null || _assetState$asset$slu === void 0 ? void 0 : _assetState$asset$slu.visible);
331
+ }).map(asset => asset.slug);
332
+ const unsub = (0, _helpers.subscribeBalance)(addresses, activeChainSlugs, assets, assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
333
+ !cancel && this.setBalanceItem(result);
189
334
  });
190
- return () => {
191
- unsubList.forEach(subProm => {
192
- subProm.then(unsub => {
193
- unsub && unsub();
194
- }).catch(console.error);
195
- });
335
+ const unsub2 = this.state.subscribeMantaPayBalance();
336
+ this._unsubscribeBalance = () => {
337
+ cancel = true;
338
+ unsub && unsub();
339
+ unsub2 && unsub2();
196
340
  };
197
341
  }
342
+
343
+ /** Unsubscribe balance subscription */
344
+ runUnsubscribeBalances() {
345
+ this._unsubscribeBalance && this._unsubscribeBalance();
346
+ this._unsubscribeBalance = undefined;
347
+ }
348
+
349
+ /** Reload balance subscription */
350
+ async reloadBalance() {
351
+ this.isReload = true;
352
+ await this.handleResetBalance(true);
353
+ await this.runSubscribeBalances();
354
+ await (0, _utils2.waitTimeout)(1800);
355
+ this.isReload = false;
356
+ }
357
+
358
+ /** Subscribe area */
359
+
198
360
  async autoEnableChains(addresses) {
199
361
  this.setBalanceDetectCache(addresses);
200
362
  const assetMap = this.state.chainService.getAssetRegistry();
@@ -263,5 +425,45 @@ class BalanceService {
263
425
  });
264
426
  }
265
427
  }
428
+ async startScanBalance() {
429
+ var _this$startBalanceDet2;
430
+ await Promise.all([this.state.eventService.waitAccountReady, this.state.eventService.waitChainReady]);
431
+ this.stopScanBalance();
432
+ this.startBalanceDetectCache = (0, _utils2.createPromiseHandler)();
433
+ const updateBalanceDetectCache = value => {
434
+ var _this$startBalanceDet;
435
+ (_this$startBalanceDet = this.startBalanceDetectCache) === null || _this$startBalanceDet === void 0 ? void 0 : _this$startBalanceDet.resolve();
436
+ this.balanceDetectSubject.next(value || {});
437
+ };
438
+ this.getBalanceDetectCache(updateBalanceDetectCache);
439
+ const subscription = this.detectAccountBalanceStore.getSubject().subscribe({
440
+ next: updateBalanceDetectCache
441
+ });
442
+ this._unsubscribeBalanceDetectCache = subscription.unsubscribe;
443
+ const scanBalance = () => {
444
+ const addresses = _uiKeyring.default.getPairs().map(account => account.address);
445
+ const cache = this.balanceDetectSubject.value;
446
+ const now = Date.now();
447
+ const needDetectAddresses = [];
448
+ for (const address of addresses) {
449
+ if (!cache[address] || now - cache[address] > this.cacheTime) {
450
+ needDetectAddresses.push(address);
451
+ }
452
+ }
453
+ if (needDetectAddresses.length) {
454
+ this.autoEnableChains(needDetectAddresses).finally(_util.noop);
455
+ }
456
+ };
457
+ await ((_this$startBalanceDet2 = this.startBalanceDetectCache) === null || _this$startBalanceDet2 === void 0 ? void 0 : _this$startBalanceDet2.promise);
458
+ scanBalance();
459
+ this._intervalScan = setInterval(scanBalance, this.intervalTime);
460
+ }
461
+ stopScanBalance() {
462
+ this._intervalScan && clearInterval(this._intervalScan);
463
+ this._unsubscribeBalanceDetectCache && this._unsubscribeBalanceDetectCache();
464
+ this._intervalScan = undefined;
465
+ this._unsubscribeBalanceDetectCache = undefined;
466
+ this.startBalanceDetectCache = undefined;
467
+ }
266
468
  }
267
469
  exports.BalanceService = BalanceService;
@@ -263,7 +263,8 @@ exports._DEFAULT_ACTIVE_CHAINS = _DEFAULT_ACTIVE_CHAINS;
263
263
  const EVM_PASS_CONNECT_STATUS = {
264
264
  arbitrum_one: ['*'],
265
265
  okxTest: ['*'],
266
- astarZkEvm: ['*']
266
+ astarZkEvm: ['*'],
267
+ xlayer: ['*']
267
268
  };
268
269
  exports.EVM_PASS_CONNECT_STATUS = EVM_PASS_CONNECT_STATUS;
269
270
  const EVM_REFORMAT_DECIMALS = {
@@ -227,9 +227,7 @@ const getEvmNativeInfo = async api => {
227
227
  exports.getEvmNativeInfo = getEvmNativeInfo;
228
228
  const getErc20AssetInfo = async (asset, api) => {
229
229
  const contractAddress = (0, _utils2._getContractAddressOfToken)(asset);
230
- const tokenContract = (0, _web.getERC20Contract)('chain', contractAddress, {
231
- chain: api
232
- });
230
+ const tokenContract = (0, _web.getERC20Contract)(contractAddress, api);
233
231
  const [_decimals, _symbol, _name] = await Promise.all([
234
232
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
235
233
  tokenContract.methods.decimals().call(),
@@ -286,13 +286,7 @@ class ChainService {
286
286
  return destinationTokenInfo;
287
287
  }
288
288
  getAssetByChainAndType(chainSlug, assetTypes) {
289
- const result = {};
290
- Object.values(this.getAssetRegistry()).forEach(assetInfo => {
291
- if (assetTypes.includes(assetInfo.assetType) && assetInfo.originChain === chainSlug) {
292
- result[assetInfo.slug] = assetInfo;
293
- }
294
- });
295
- return result;
289
+ return (0, _utils2.filterAssetsByChainAndType)(this.getAssetRegistry(), chainSlug, assetTypes);
296
290
  }
297
291
  getSmartContractNfts() {
298
292
  const result = [];
@@ -578,8 +572,6 @@ class ChainService {
578
572
  const chainState = chainStateMap[originChain];
579
573
  if (!assetState) {
580
574
  // If this asset not has asset setting, this token is not enabled before (not turned off before)
581
- // @ts-ignore
582
- // TODO: Merge issue detect balance to define manualTurnOff props
583
575
  if (!chainState || !chainState.manualTurnOff) {
584
576
  await this.updateAssetSetting(assetSlug, {
585
577
  visible: true
@@ -12,7 +12,7 @@ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
12
12
  const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
13
13
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
14
14
  const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
15
- const ChainListVersion = '0.2.53';
15
+ const ChainListVersion = '0.2.54';
16
16
  async function fetchPatchData(slug) {
17
17
  try {
18
18
  const fetchPromise = (0, _crossFetch.default)(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
@@ -201,7 +201,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
201
201
  const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
202
202
  const inputTokenSlug = this.inputAsset;
203
203
  const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
204
- const inputTokenContract = (0, _web.getERC20Contract)(this.chain, (0, _utils._getContractAddressOfToken)(inputTokenInfo), this.state.getEvmApiMap());
204
+ const inputTokenContract = (0, _web.getERC20Contract)((0, _utils._getContractAddressOfToken)(inputTokenInfo), evmApi);
205
205
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
206
206
  const allowanceCall = inputTokenContract.methods.allowance(params.address, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo));
207
207
  const [allowance, gasPrice] = await Promise.all([
@@ -266,7 +266,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
266
266
  const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
267
267
  const derivativeTokenContractAddress = (0, _utils._getContractAddressOfToken)(derivativeTokenInfo);
268
268
  const evmApi = this.evmApi;
269
- const inputTokenContract = (0, _web.getERC20Contract)(this.chain, (0, _utils._getContractAddressOfToken)(inputTokenInfo), this.state.getEvmApiMap());
269
+ const inputTokenContract = (0, _web.getERC20Contract)((0, _utils._getContractAddressOfToken)(inputTokenInfo), evmApi);
270
270
 
271
271
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
272
272
  const approveCall = inputTokenContract.methods.approve(derivativeTokenContractAddress, MAX_INT); // TODO: need test
@@ -59,7 +59,6 @@ class ConnectWCRequestHandler {
59
59
  ...request
60
60
  };
61
61
  this.updateIconConnectWC();
62
- this.#requestService.popupOpen();
63
62
  }
64
63
  resetWallet() {
65
64
  for (const request of Object.values(this.#connectWCRequests)) {
@@ -15,6 +15,7 @@ var _NominatorMetadata = _interopRequireDefault(require("@subwallet/extension-ba
15
15
  var _YieldPoolStore = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/YieldPoolStore"));
16
16
  var _YieldPositionStore = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/YieldPositionStore"));
17
17
  var _utils = require("@subwallet/extension-base/utils");
18
+ var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
18
19
  var _dexieExportImport = require("dexie-export-import");
19
20
  var _util = require("@polkadot/util");
20
21
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
@@ -71,7 +72,15 @@ class DatabaseService {
71
72
 
72
73
  // Balance
73
74
  async getStoredBalance() {
74
- return this.stores.balance.table.toArray();
75
+ const addresses = _uiKeyring.default.getPairs().map(_ref => {
76
+ let {
77
+ address
78
+ } = _ref;
79
+ return address;
80
+ });
81
+
82
+ // Filter not exist address
83
+ return this.stores.balance.table.filter(obj => addresses.includes(obj.address)).toArray();
75
84
  }
76
85
  async updateBalanceStore(item) {
77
86
  if (item.state === _KoniTypes.APIItemState.READY) {
@@ -18,7 +18,7 @@ exports.getWCId = getWCId;
18
18
  const convertConnectRequest = request => {
19
19
  return {
20
20
  id: getWCId(request.id),
21
- isInternal: false,
21
+ isInternal: true,
22
22
  request: request,
23
23
  url: request.params.proposer.metadata.url
24
24
  };
@@ -21,6 +21,8 @@ var _types = require("./types");
21
21
  // SPDX-License-Identifier: Apache-2.0
22
22
 
23
23
  const storage = _storage.SWStorage.instance;
24
+ const methodDOTRequire = [_types.POLKADOT_SIGNING_METHODS.POLKADOT_SIGN_MESSAGE, _types.POLKADOT_SIGNING_METHODS.POLKADOT_SIGN_TRANSACTION];
25
+ const methodEVMRequire = [_types.EIP155_SIGNING_METHODS.PERSONAL_SIGN, _types.EIP155_SIGNING_METHODS.ETH_SIGN, _types.EIP155_SIGNING_METHODS.ETH_SEND_TRANSACTION];
24
26
  var _requestService = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("requestService");
25
27
  var _polkadotRequestHandler = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("polkadotRequestHandler");
26
28
  var _eip155RequestHandler = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("eip155RequestHandler");
@@ -125,6 +127,13 @@ class WalletConnectService {
125
127
  async approveSession(result) {
126
128
  var _classPrivateFieldLoo4;
127
129
  (0, _classPrivateFieldLooseBase2.default)(this, _checkClient)[_checkClient]();
130
+ Object.entries(result.namespaces).forEach(_ref => {
131
+ let [namespace, {
132
+ methods
133
+ }] = _ref;
134
+ methods = [...methods, ...this.findMethodsMissing(_constants.WALLET_CONNECT_EIP155_NAMESPACE === namespace ? methodEVMRequire : methodDOTRequire, methods)];
135
+ result.namespaces[namespace].methods = methods;
136
+ });
128
137
  await ((_classPrivateFieldLoo4 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo4 === void 0 ? void 0 : _classPrivateFieldLoo4.approve(result));
129
138
  (0, _classPrivateFieldLooseBase2.default)(this, _updateSessions)[_updateSessions]();
130
139
  }
@@ -193,6 +202,16 @@ class WalletConnectService {
193
202
  }));
194
203
  (0, _classPrivateFieldLooseBase2.default)(this, _updateSessions)[_updateSessions]();
195
204
  }
205
+ findMethodsMissing(methodRequire, methods) {
206
+ const methodMap = methods.reduce((obj, m) => ({
207
+ ...obj,
208
+ [m]: m
209
+ }), {});
210
+ return methodEVMRequire.reduce((methods, m) => {
211
+ !methodMap[m] && methods.push(m);
212
+ return methods;
213
+ }, []);
214
+ }
196
215
  }
197
216
  exports.default = WalletConnectService;
198
217
  function _get_haveData() {
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.filterAssetsByChainAndType = void 0;
7
+ // Copyright 2019-2022 @subwallet/extension-base
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ const filterAssetsByChainAndType = (chainAssetMap, chain, assetTypes) => {
11
+ const result = {};
12
+ Object.values(chainAssetMap).forEach(assetInfo => {
13
+ if (assetTypes.includes(assetInfo.assetType) && assetInfo.originChain === chain) {
14
+ result[assetInfo.slug] = assetInfo;
15
+ }
16
+ });
17
+ return result;
18
+ };
19
+ exports.filterAssetsByChainAndType = filterAssetsByChainAndType;
@@ -93,8 +93,8 @@ const parseResult = (type, input, name) => {
93
93
  };
94
94
  } else {
95
95
  return {
96
- type: types,
97
96
  name: genName(name),
97
+ type: types,
98
98
  value: genInput(input)
99
99
  };
100
100
  }
@@ -104,6 +104,18 @@ Object.keys(_array).forEach(function (key) {
104
104
  }
105
105
  });
106
106
  });
107
+ var _asset = require("./asset");
108
+ Object.keys(_asset).forEach(function (key) {
109
+ if (key === "default" || key === "__esModule") return;
110
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
111
+ if (key in exports && exports[key] === _asset[key]) return;
112
+ Object.defineProperty(exports, key, {
113
+ enumerable: true,
114
+ get: function () {
115
+ return _asset[key];
116
+ }
117
+ });
118
+ });
107
119
  var _environment = require("./environment");
108
120
  Object.keys(_environment).forEach(function (key) {
109
121
  if (key === "default" || key === "__esModule") return;
@@ -1,2 +1,2 @@
1
1
  import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
2
- export declare function getEVMBalance(networkKey: string, addresses: string[], evmApiMap: Record<string, _EvmApi>): Promise<string[]>;
2
+ export declare function getEVMBalance(networkKey: string, addresses: string[], web3Api: _EvmApi): Promise<string[]>;
@@ -1,8 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- export async function getEVMBalance(networkKey, addresses, evmApiMap) {
5
- const web3Api = evmApiMap[networkKey];
4
+ export async function getEVMBalance(networkKey, addresses, web3Api) {
6
5
  return await Promise.all(addresses.map(async address => {
7
6
  try {
8
7
  return await web3Api.api.eth.getBalance(address);
@@ -11,7 +11,7 @@ interface HandleTransferBalanceResultProps {
11
11
  updateState?: (promise: Partial<ExternalRequestPromise>) => void;
12
12
  }
13
13
  export declare const handleTransferBalanceResult: ({ callback, changeValue, networkKey, receipt, response, updateState }: HandleTransferBalanceResultProps) => void;
14
- export declare function getEVMTransactionObject(chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
15
- export declare function getERC20TransactionObject(assetAddress: string, chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
14
+ export declare function getEVMTransactionObject(chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, web3Api: _EvmApi): Promise<[TransactionConfig, string]>;
15
+ export declare function getERC20TransactionObject(assetAddress: string, chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApi: _EvmApi): Promise<[TransactionConfig, string]>;
16
16
  export declare function getERC721Transaction(web3Api: _EvmApi, chain: string, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string): Promise<TransactionConfig>;
17
17
  export {};