@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
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _FundStatus, _MultiChainAsset } from '@subwallet/chain-list/types';
3
2
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
4
3
  import { AuthUrls, Resolver } from '@subwallet/extension-base/background/handlers/State';
@@ -7,7 +6,7 @@ import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chai
7
6
  import { _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
8
7
  import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
9
8
  import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
10
- import { BuyServiceInfo, BuyTokenInfo } from '@subwallet/extension-base/types';
9
+ import { BalanceJson, BuyServiceInfo, BuyTokenInfo } from '@subwallet/extension-base/types';
11
10
  import { InjectedAccount, InjectedAccountWithMeta, MetadataDefBase } from '@subwallet/extension-inject/types';
12
11
  import { KeyringPair$Json, KeyringPair$Meta } from '@subwallet/keyring/types';
13
12
  import { KeyringOptions } from '@subwallet/ui-keyring/options/types';
@@ -18,7 +17,6 @@ import Web3 from 'web3';
18
17
  import { RequestArguments, TransactionConfig } from 'web3-core';
19
18
  import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers';
20
19
  import { SignerResult } from '@polkadot/types/types/extrinsic';
21
- import { BN } from '@polkadot/util';
22
20
  import { HexString } from '@polkadot/util/types';
23
21
  import { KeypairType } from '@polkadot/util-crypto/types';
24
22
  import { TransactionWarning } from './warnings/TransactionWarning';
@@ -196,28 +194,6 @@ export interface MetadataItem {
196
194
  specVersion: string;
197
195
  hexValue: HexString;
198
196
  }
199
- export interface TokenBalanceRaw {
200
- reserved: BN;
201
- frozen: BN;
202
- free: BN;
203
- }
204
- export interface SubstrateBalance {
205
- reserved?: string;
206
- miscFrozen?: string;
207
- feeFrozen?: string;
208
- }
209
- export interface BalanceItem {
210
- tokenSlug: string;
211
- state: APIItemState;
212
- timestamp?: number;
213
- free: string;
214
- locked: string;
215
- substrateInfo?: SubstrateBalance;
216
- }
217
- export interface BalanceJson {
218
- reset?: boolean;
219
- details: Record<string, BalanceItem>;
220
- }
221
197
  export interface CrowdloanItem {
222
198
  state: APIItemState;
223
199
  paraState?: CrowdloanParaState;
@@ -25,9 +25,11 @@ var _exportNames = {
25
25
  ALL_GENESIS_HASH: true,
26
26
  IGNORE_GET_SUBSTRATE_FEATURES_LIST: true,
27
27
  IGNORE_QR_SIGNER: true,
28
- XCM_MIN_AMOUNT_RATIO: true
28
+ XCM_MIN_AMOUNT_RATIO: true,
29
+ GAS_PRICE_RATIO: true,
30
+ NETWORK_MULTI_GAS_FEE: true
29
31
  };
30
- exports.XCM_MIN_AMOUNT_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
32
+ exports.XCM_MIN_AMOUNT_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.NETWORK_MULTI_GAS_FEE = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.GAS_PRICE_RATIO = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
31
33
  var _staking = require("./staking");
32
34
  Object.keys(_staking).forEach(function (key) {
33
35
  if (key === "default" || key === "__esModule") return;
@@ -98,4 +100,8 @@ exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = IGNORE_GET_SUBSTRATE_FEATURES_LIST;
98
100
  const IGNORE_QR_SIGNER = [];
99
101
  exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
100
102
  const XCM_MIN_AMOUNT_RATIO = 1.2;
101
- exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
103
+ exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
104
+ const GAS_PRICE_RATIO = 1.05;
105
+ exports.GAS_PRICE_RATIO = GAS_PRICE_RATIO;
106
+ const NETWORK_MULTI_GAS_FEE = ['astarEvm'];
107
+ exports.NETWORK_MULTI_GAS_FEE = NETWORK_MULTI_GAS_FEE;
@@ -122,6 +122,7 @@ async function getCancelWithdrawalExtrinsic(substrateApi, chain, selectedUnstaki
122
122
  function subscribeEssentialChainStakingMetadata(substrateApiMap, chainInfoMap, callback) {
123
123
  const unsubList = [];
124
124
 
125
+ // TODO: replace with for of to improve performance
125
126
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
126
127
  Object.values(chainInfoMap).forEach(async chainInfo => {
127
128
  if (!substrateApiMap[chainInfo.slug]) {
@@ -10,6 +10,10 @@ exports.getEVMBalance = getEVMBalance;
10
10
  async function getEVMBalance(networkKey, addresses, evmApiMap) {
11
11
  const web3Api = evmApiMap[networkKey];
12
12
  return await Promise.all(addresses.map(async address => {
13
- return await web3Api.api.eth.getBalance(address);
13
+ try {
14
+ return await web3Api.api.eth.getBalance(address);
15
+ } catch (e) {
16
+ return '0';
17
+ }
14
18
  }));
15
19
  }
@@ -11,6 +11,7 @@ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
11
11
  var _web = require("@subwallet/extension-base/koni/api/tokens/evm/web3");
12
12
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
13
13
  var _helper = require("@subwallet/extension-base/services/chain-service/helper");
14
+ var _eth = require("@subwallet/extension-base/utils/eth");
14
15
  var _util = require("@polkadot/util");
15
16
  // Copyright 2019-2022 @subwallet/extension-base
16
17
  // SPDX-License-Identifier: Apache-2.0
@@ -46,7 +47,8 @@ exports.handleTransferBalanceResult = handleTransferBalanceResult;
46
47
  async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, evmApiMap) {
47
48
  const networkKey = chainInfo.slug;
48
49
  const web3Api = evmApiMap[networkKey];
49
- const gasPrice = await web3Api.api.eth.getGasPrice();
50
+ const _price = await web3Api.api.eth.getGasPrice();
51
+ const gasPrice = (0, _eth.recalculateGasPrice)(_price, chainInfo.slug);
50
52
  const transactionObject = {
51
53
  gasPrice: gasPrice,
52
54
  to: to,
@@ -80,11 +82,12 @@ async function getERC20TransactionObject(assetAddress, chainInfo, from, to, valu
80
82
  return erc20Contract.methods.transfer(to, transferValue).encodeABI();
81
83
  }
82
84
  const transferData = generateTransferData(to, transferValue);
83
- const [gasLimit, gasPrice] = await Promise.all([
85
+ const [gasLimit, _price] = await Promise.all([
84
86
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
85
87
  erc20Contract.methods.transfer(to, transferValue).estimateGas({
86
88
  from
87
89
  }), evmApi.api.eth.getGasPrice()]);
90
+ const gasPrice = (0, _eth.recalculateGasPrice)(_price, chainInfo.slug);
88
91
  const transactionObject = {
89
92
  gasPrice: gasPrice,
90
93
  gas: gasLimit,
@@ -98,14 +101,15 @@ async function getERC20TransactionObject(assetAddress, chainInfo, from, to, valu
98
101
  }
99
102
  return [transactionObject, transferValue];
100
103
  }
101
- async function getERC721Transaction(web3Api, contractAddress, senderAddress, recipientAddress, tokenId) {
104
+ async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId) {
102
105
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
103
106
  const contract = new web3Api.api.eth.Contract(_helper._ERC721_ABI, contractAddress);
104
- const [gasLimit, gasPrice] = await Promise.all([
107
+ const [gasLimit, _price] = await Promise.all([
105
108
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
106
109
  contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).estimateGas({
107
110
  from: senderAddress
108
111
  }), web3Api.api.eth.getGasPrice()]);
112
+ const gasPrice = (0, _eth.recalculateGasPrice)(_price, chain);
109
113
  return {
110
114
  from: senderAddress,
111
115
  gasPrice,
@@ -115,8 +115,8 @@ class KoniCron {
115
115
  if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
116
116
  this.resetNft(currentAccountInfo.address);
117
117
  this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), _constants.CRON_REFRESH_NFT_INTERVAL);
118
- this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_INTERVAL);
119
- this.addCron('refreshPoolingSta kingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
118
+ // this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
119
+ this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
120
120
  this.addCron('syncMantaPay', this.syncMantaPay, _constants.CRON_SYNC_MANTA_PAY);
121
121
  } else {
122
122
  this.setStakingRewardReady();
@@ -33,7 +33,6 @@ var _constants4 = require("@subwallet/extension-base/services/setting-service/co
33
33
  var _constants5 = require("@subwallet/extension-base/services/wallet-connect-service/constants");
34
34
  var _helpers2 = require("@subwallet/extension-base/services/wallet-connect-service/helpers");
35
35
  var _utils2 = require("@subwallet/extension-base/utils");
36
- var _address2 = require("@subwallet/extension-base/utils/address");
37
36
  var _eth = require("@subwallet/extension-base/utils/eth");
38
37
  var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTransaction");
39
38
  var _number = require("@subwallet/extension-base/utils/number");
@@ -546,7 +545,7 @@ class KoniExtension {
546
545
  subscribeAddresses(id, port) {
547
546
  const _cb = (0, _subscriptions.createSubscription)(id, port);
548
547
  const subscription = this.#koniState.keyringService.addressesSubject.subscribe(subjectInfo => {
549
- const addresses = (0, _address2.convertSubjectInfoToAddresses)(subjectInfo);
548
+ const addresses = (0, _utils2.convertSubjectInfoToAddresses)(subjectInfo);
550
549
  _cb({
551
550
  addresses: addresses
552
551
  });
@@ -557,7 +556,7 @@ class KoniExtension {
557
556
  });
558
557
  const subjectInfo = this.#koniState.keyringService.addresses;
559
558
  return {
560
- addresses: (0, _address2.convertSubjectInfoToAddresses)(subjectInfo)
559
+ addresses: (0, _utils2.convertSubjectInfoToAddresses)(subjectInfo)
561
560
  };
562
561
  }
563
562
  saveRecentAccount(_ref22) {
@@ -1779,7 +1778,7 @@ class KoniExtension {
1779
1778
  } = inputData;
1780
1779
  const contractAddress = params.contractAddress;
1781
1780
  const tokenId = params.tokenId;
1782
- const transaction = await (0, _transfer3.getERC721Transaction)(this.#koniState.getEvmApi(networkKey), contractAddress, senderAddress, recipientAddress, tokenId);
1781
+ const transaction = await (0, _transfer3.getERC721Transaction)(this.#koniState.getEvmApi(networkKey), networkKey, contractAddress, senderAddress, recipientAddress, tokenId);
1783
1782
 
1784
1783
  // this.addContact(recipientAddress);
1785
1784
 
@@ -1930,7 +1929,8 @@ class KoniExtension {
1930
1929
  // null address
1931
1930
  from: address
1932
1931
  };
1933
- const gasPrice = await web3.api.eth.getGasPrice();
1932
+ const _price = await web3.api.eth.getGasPrice();
1933
+ const gasPrice = (0, _eth.recalculateGasPrice)(_price, networkKey);
1934
1934
  const gasLimit = await web3.api.eth.estimateGas(transaction);
1935
1935
  estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
1936
1936
  } else {
@@ -119,7 +119,7 @@ class Mobile {
119
119
  if (storage) {
120
120
  const storageData = JSON.parse(storage);
121
121
  for (const key in storageData) {
122
- localStorage.setItem(key, JSON.stringify(storageData[key]));
122
+ localStorage.setItem(key, storageData[key]);
123
123
  }
124
124
  }
125
125
  if (indexedDB) {
@@ -11,6 +11,7 @@ var _subscriptions = require("@subwallet/extension-base/background/handlers/subs
11
11
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
12
12
  var _constants = require("@subwallet/extension-base/constants");
13
13
  var _balanceService = require("@subwallet/extension-base/services/balance-service");
14
+ var _group = require("@subwallet/extension-base/services/balance-service/helpers/group");
14
15
  var _types = require("@subwallet/extension-base/services/base/types");
15
16
  var _buyService = _interopRequireDefault(require("@subwallet/extension-base/services/buy-service"));
16
17
  var _campaignService = _interopRequireDefault(require("@subwallet/extension-base/services/campaign-service"));
@@ -32,6 +33,7 @@ var _transactionService = _interopRequireDefault(require("@subwallet/extension-b
32
33
  var _walletConnectService = _interopRequireDefault(require("@subwallet/extension-base/services/wallet-connect-service"));
33
34
  var _AccountRef = _interopRequireDefault(require("@subwallet/extension-base/stores/AccountRef"));
34
35
  var _utils2 = require("@subwallet/extension-base/utils");
36
+ var _eth = require("@subwallet/extension-base/utils/eth");
35
37
  var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
36
38
  var _promise = require("@subwallet/extension-base/utils/promise");
37
39
  var _decode = require("@subwallet/keyring/pair/decode");
@@ -97,7 +99,7 @@ class KoniState {
97
99
  this.settingService = new _SettingService.default();
98
100
  this.requestService = new _requestService.default(this.chainService, this.settingService, this.keyringService);
99
101
  this.priceService = new _priceService.PriceService(this.dbService, this.eventService, this.chainService);
100
- this.balanceService = new _balanceService.BalanceService(this.chainService);
102
+ this.balanceService = new _balanceService.BalanceService(this);
101
103
  this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService, this.subscanService);
102
104
  this.transactionService = new _transactionService.default(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
103
105
  this.walletConnectService = new _walletConnectService.default(this, this.requestService);
@@ -195,16 +197,23 @@ class KoniState {
195
197
  generateDefaultBalanceMap() {
196
198
  const balanceMap = {};
197
199
  const activeChains = this.chainService.getActiveChainInfoMap();
198
- Object.values(activeChains).forEach(chainInfo => {
199
- const chainAssetMap = this.chainService.getFungibleTokensByChain(chainInfo.slug);
200
- Object.keys(chainAssetMap).forEach(assetSlug => {
201
- balanceMap[assetSlug] = {
202
- tokenSlug: assetSlug,
203
- free: '',
204
- locked: '',
205
- state: _KoniTypes.APIItemState.PENDING
206
- };
200
+ const isAllAccount = (0, _utils2.isAccountAll)(this.keyringService.currentAccount.address);
201
+ const addresses = isAllAccount ? Object.keys(this.keyringService.accounts) : [this.keyringService.currentAccount.address];
202
+ addresses.forEach(address => {
203
+ const temp = {};
204
+ Object.values(activeChains).forEach(chainInfo => {
205
+ const chainAssetMap = this.chainService.getFungibleTokensByChain(chainInfo.slug);
206
+ Object.keys(chainAssetMap).forEach(assetSlug => {
207
+ temp[assetSlug] = {
208
+ address,
209
+ tokenSlug: assetSlug,
210
+ free: '',
211
+ locked: '',
212
+ state: _KoniTypes.APIItemState.PENDING
213
+ };
214
+ });
207
215
  });
216
+ balanceMap[address] = temp;
208
217
  });
209
218
  return balanceMap;
210
219
  }
@@ -681,14 +690,18 @@ class KoniState {
681
690
  removeInactiveChainBalances(balanceMap) {
682
691
  const activeBalanceMap = {};
683
692
  Object.entries(balanceMap).forEach(_ref5 => {
684
- let [tokenSlug, balanceItem] = _ref5;
685
- const tokenInfo = this.chainService.getAssetBySlug(tokenSlug);
686
- if (tokenInfo) {
687
- const chainInfo = this.chainService.getChainInfoByKey(tokenInfo.originChain);
688
- if (chainInfo && this.getChainStateByKey(chainInfo.slug).active) {
689
- activeBalanceMap[tokenSlug] = balanceItem;
693
+ let [address, balances] = _ref5;
694
+ activeBalanceMap[address] = {};
695
+ Object.entries(balances).forEach(_ref6 => {
696
+ let [tokenSlug, item] = _ref6;
697
+ const tokenInfo = this.chainService.getAssetBySlug(tokenSlug);
698
+ if (tokenInfo) {
699
+ const chainInfo = this.chainService.getChainInfoByKey(tokenInfo.originChain);
700
+ if (chainInfo && this.getChainStateByKey(chainInfo.slug).active) {
701
+ activeBalanceMap[address][tokenSlug] = item;
702
+ }
690
703
  }
691
- }
704
+ });
692
705
  });
693
706
  return activeBalanceMap;
694
707
  }
@@ -700,7 +713,7 @@ class KoniState {
700
713
  };
701
714
  }
702
715
  async getStoredBalance(address) {
703
- const items = await this.dbService.stores.balance.getBalanceMapByAddress(address);
716
+ const items = await this.dbService.stores.balance.getBalanceMapByAddresses(address);
704
717
  return items || {};
705
718
  }
706
719
  async handleSwitchAccount(newAddress) {
@@ -710,6 +723,31 @@ class KoniState {
710
723
  const defaultData = this.generateDefaultBalanceMap();
711
724
  let storedData = await this.getStoredBalance(newAddress);
712
725
  storedData = this.removeInactiveChainBalances(storedData);
726
+ const result = {};
727
+ for (const [address, balanceInfo] of Object.entries(defaultData)) {
728
+ result[address] = {
729
+ ...balanceInfo
730
+ };
731
+ }
732
+ for (const [address, balanceInfo] of Object.entries(storedData)) {
733
+ if (!result[address]) {
734
+ result[address] = {
735
+ ...balanceInfo
736
+ };
737
+ } else {
738
+ const temp = {
739
+ ...result[address]
740
+ };
741
+ for (const [slug, item] of Object.entries(balanceInfo)) {
742
+ temp[slug] = {
743
+ ...item
744
+ };
745
+ }
746
+ result[address] = {
747
+ ...temp
748
+ };
749
+ }
750
+ }
713
751
  this.balanceMap = {
714
752
  ...defaultData,
715
753
  ...storedData
@@ -737,19 +775,59 @@ class KoniState {
737
775
  });
738
776
  });
739
777
  }
740
- setBalanceItem(tokenSlug, item) {
741
- this.balanceMap[tokenSlug] = {
742
- timestamp: +new Date(),
743
- ...item
744
- };
745
- this.updateBalanceStore(item);
746
- this.lazyNext('setBalanceItem', () => {
747
- this.publishBalance();
748
- });
778
+
779
+ /** Note: items must be same tokenSlug */
780
+ setBalanceItem(items) {
781
+ if (items.length) {
782
+ const tokens = [];
783
+ const updates = [];
784
+ for (const item of items) {
785
+ const address = item.address;
786
+ const tokenSlug = item.tokenSlug;
787
+ if (!tokens.includes(tokenSlug)) {
788
+ tokens.push(tokenSlug);
789
+ }
790
+ if (!this.balanceMap[address]) {
791
+ this.balanceMap[address] = {};
792
+ }
793
+ const data = {
794
+ timestamp: +new Date(),
795
+ ...item
796
+ };
797
+ this.balanceMap[address][tokenSlug] = data;
798
+ updates.push(data);
799
+ }
800
+ const isAllAccount = (0, _utils2.isAccountAll)(this.keyringService.currentAccount.address);
801
+ if (isAllAccount) {
802
+ const address = _constants.ALL_ACCOUNT_KEY;
803
+ for (const token of tokens) {
804
+ const items = [];
805
+ for (const [_adr, balanceInfo] of Object.entries(this.balanceMap)) {
806
+ if (!(0, _utils2.isSameAddress)(_adr, address)) {
807
+ const item = balanceInfo[token];
808
+ item && items.push(item);
809
+ }
810
+ }
811
+ const _balance = (0, _group.groupBalance)(items, address, token);
812
+ const balance = {
813
+ timestamp: +new Date(),
814
+ ..._balance
815
+ };
816
+ if (!this.balanceMap[address]) {
817
+ this.balanceMap[address] = {};
818
+ }
819
+ this.balanceMap[address][token] = balance;
820
+ updates.push(balance);
821
+ }
822
+ }
823
+ this.updateBalanceStore(updates);
824
+ this.lazyNext('setBalanceItem', () => {
825
+ this.publishBalance();
826
+ });
827
+ }
749
828
  }
750
- updateBalanceStore(item) {
751
- const currentAccountInfo = this.keyringService.currentAccount;
752
- this.dbService.updateBalanceStore(currentAccountInfo.address, item).catch(e => this.logger.warn(e));
829
+ updateBalanceStore(items) {
830
+ this.dbService.updateBulkBalanceStore(items).catch(e => this.logger.warn(e));
753
831
  }
754
832
  subscribeBalance() {
755
833
  return this.balanceSubject;
@@ -1030,8 +1108,8 @@ class KoniState {
1030
1108
  if (!genesisHash) {
1031
1109
  return [undefined, undefined];
1032
1110
  }
1033
- const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref6 => {
1034
- let [networkKey, chainInfo] = _ref6;
1111
+ const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref7 => {
1112
+ let [networkKey, chainInfo] = _ref7;
1035
1113
  return (0, _utils._getSubstrateGenesisHash)(chainInfo) === genesisHash;
1036
1114
  });
1037
1115
  if (rs) {
@@ -1048,9 +1126,9 @@ class KoniState {
1048
1126
  if (!chainId) {
1049
1127
  return [undefined, undefined];
1050
1128
  }
1051
- const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref7 => {
1129
+ const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref8 => {
1052
1130
  var _chainInfo$evmInfo;
1053
- let [networkKey, chainInfo] = _ref7;
1131
+ let [networkKey, chainInfo] = _ref8;
1054
1132
  return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) === chainId;
1055
1133
  });
1056
1134
  if (rs) {
@@ -1066,11 +1144,11 @@ class KoniState {
1066
1144
  }
1067
1145
  return Object.values(_constants2._PREDEFINED_SINGLE_MODES).find(item => item.networkKeys.includes(networkKey));
1068
1146
  }
1069
- accountExportPrivateKey(_ref8) {
1147
+ accountExportPrivateKey(_ref9) {
1070
1148
  let {
1071
1149
  address,
1072
1150
  password
1073
- } = _ref8;
1151
+ } = _ref9;
1074
1152
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1075
1153
  const exportedJson = _uiKeyring.keyring.backupAccount(_uiKeyring.keyring.getPair(address), password);
1076
1154
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
@@ -1080,11 +1158,11 @@ class KoniState {
1080
1158
  publicKey: (0, _util.u8aToHex)(decoded.publicKey)
1081
1159
  };
1082
1160
  }
1083
- checkPublicAndSecretKey(_ref9) {
1161
+ checkPublicAndSecretKey(_ref10) {
1084
1162
  let {
1085
1163
  publicKey,
1086
1164
  secretKey
1087
- } = _ref9;
1165
+ } = _ref10;
1088
1166
  try {
1089
1167
  const _secret = (0, _util.hexStripPrefix)(secretKey);
1090
1168
  if (_secret.length === 64) {
@@ -1202,11 +1280,11 @@ class KoniState {
1202
1280
  return this.requestService.addConfirmation(id, url, 'evmSignatureRequest', signPayload, {
1203
1281
  requiredPassword: false,
1204
1282
  address
1205
- }).then(_ref10 => {
1283
+ }).then(_ref11 => {
1206
1284
  let {
1207
1285
  isApproved,
1208
1286
  payload
1209
- } = _ref10;
1287
+ } = _ref11;
1210
1288
  if (isApproved) {
1211
1289
  if (payload) {
1212
1290
  return payload;
@@ -1253,7 +1331,8 @@ class KoniState {
1253
1331
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1254
1332
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1255
1333
  }
1256
- const gasPrice = await web3.eth.getGasPrice();
1334
+ const _price = await web3.eth.getGasPrice();
1335
+ const gasPrice = (0, _eth.recalculateGasPrice)(_price, networkKey);
1257
1336
  transaction.gasPrice = gasPrice;
1258
1337
  const estimateGas = new _util.BN(gasPrice.toString()).mul(new _util.BN(transaction.gas)).toString();
1259
1338
 
@@ -1490,7 +1569,7 @@ class KoniState {
1490
1569
  const chainMap = this.chainService.getChainInfoMap();
1491
1570
  const balanceDataList = await Promise.all(promiseList);
1492
1571
  balanceDataList.forEach(balanceData => {
1493
- balanceData && balanceData.forEach(_ref11 => {
1572
+ balanceData && balanceData.forEach(_ref12 => {
1494
1573
  var _currentAssetSettings;
1495
1574
  let {
1496
1575
  balance,
@@ -1499,7 +1578,7 @@ class KoniState {
1499
1578
  locked,
1500
1579
  network,
1501
1580
  symbol
1502
- } = _ref11;
1581
+ } = _ref12;
1503
1582
  const chain = _subscanChainMap.SUBSCAN_BALANCE_CHAIN_MAP_REVERSE[network];
1504
1583
  const chainInfo = chain ? chainMap[chain] : null;
1505
1584
  const balanceIsEmpty = (!balance || balance === '0') && (!locked || locked === '0') && (!bonded || bonded === '0');
@@ -1688,7 +1767,7 @@ class KoniState {
1688
1767
  };
1689
1768
  balanceItem.free = ((_zkBalances$i = zkBalances[i]) === null || _zkBalances$i === void 0 ? void 0 : _zkBalances$i.toString()) || '0';
1690
1769
  balanceItem.state = _KoniTypes.APIItemState.READY;
1691
- this.setBalanceItem(balanceItem.tokenSlug, balanceItem);
1770
+ this.setBalanceItem([balanceItem]);
1692
1771
  }
1693
1772
  }).catch(console.warn);
1694
1773
  }
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.KoniSubscription = void 0;
7
- var _balance = require("@subwallet/extension-base/koni/api/dotsama/balance");
8
7
  var _crowdloan = require("@subwallet/extension-base/koni/api/dotsama/crowdloan");
9
8
  var _staking = require("@subwallet/extension-base/koni/api/staking");
10
9
  var _bonding = require("@subwallet/extension-base/koni/api/staking/bonding");
11
10
  var _paraChain = require("@subwallet/extension-base/koni/api/staking/paraChain");
12
11
  var _handlers = require("@subwallet/extension-base/koni/background/handlers");
12
+ var _balance = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/balance");
13
13
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
14
14
  var _types = require("@subwallet/extension-base/services/event-service/types");
15
15
  var _utils2 = require("@subwallet/extension-base/utils");
@@ -153,7 +153,7 @@ class KoniSubscription {
153
153
  }
154
154
  });
155
155
  const unsub = (0, _balance.subscribeBalance)(addresses, filteredChainInfoMap, substrateApiMap, evmApiMap, result => {
156
- this.state.setBalanceItem(result.tokenSlug, result);
156
+ this.state.setBalanceItem(result);
157
157
  });
158
158
  const unsub2 = this.state.subscribeMantaPayBalance();
159
159
  if (onlyRunOnFirstTime) {
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.1.24-0'
16
+ version: '1.1.24-1'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.groupBalance = void 0;
8
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
+ var _utils = require("@subwallet/extension-base/utils");
10
+ var _bn = _interopRequireDefault(require("bn.js"));
11
+ // Copyright 2019-2022 @subwallet/extension-base
12
+ // SPDX-License-Identifier: Apache-2.0
13
+
14
+ /**
15
+ * Group the balance of {token} from {items} into {address}
16
+ * @param {BalanceItem[]} items - List balance want to group
17
+ * @param {string} address - Address will be grouped to
18
+ * @param {string} token - Slug of token will be group balance
19
+ * @return {BalanceItem} - Grouped balance information of token
20
+ */
21
+ const groupBalance = (items, address, token) => {
22
+ const states = items.map(item => item.state);
23
+ const result = {
24
+ address,
25
+ tokenSlug: token,
26
+ free: (0, _utils.sumBN)(items.map(item => new _bn.default(item.free))).toString(),
27
+ locked: (0, _utils.sumBN)(items.map(item => new _bn.default(item.locked))).toString(),
28
+ state: states.every(item => item === _KoniTypes.APIItemState.NOT_SUPPORT) ? _KoniTypes.APIItemState.NOT_SUPPORT : states.some(item => item === _KoniTypes.APIItemState.READY) ? _KoniTypes.APIItemState.READY : _KoniTypes.APIItemState.PENDING
29
+ };
30
+ for (const item of items) {
31
+ if (item.substrateInfo) {
32
+ if (!result.substrateInfo) {
33
+ result.substrateInfo = {
34
+ ...item.substrateInfo
35
+ };
36
+ } else {
37
+ const old = {
38
+ ...result.substrateInfo
39
+ };
40
+ const _new = {
41
+ ...item.substrateInfo
42
+ };
43
+ result.substrateInfo = {
44
+ reserved: new _bn.default(old.reserved || '0').add(new _bn.default(_new.reserved || '0')).toString(),
45
+ feeFrozen: new _bn.default(old.feeFrozen || '0').add(new _bn.default(_new.feeFrozen || '0')).toString(),
46
+ miscFrozen: new _bn.default(old.miscFrozen || '0').add(new _bn.default(_new.miscFrozen || '0')).toString()
47
+ };
48
+ }
49
+ }
50
+ }
51
+ return result;
52
+ };
53
+ exports.groupBalance = groupBalance;