@subwallet/extension-base 1.1.25-1 → 1.1.27-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 (76) hide show
  1. package/background/KoniTypes.d.ts +3 -3
  2. package/background/handlers/State.js +3 -2
  3. package/cjs/background/handlers/State.js +3 -2
  4. package/cjs/constants/staking.js +4 -2
  5. package/cjs/koni/api/dotsama/transfer.js +2 -2
  6. package/cjs/koni/api/nft/config.js +2 -1
  7. package/cjs/koni/api/staking/bonding/astar.js +15 -24
  8. package/cjs/koni/api/staking/bonding/relayChain.js +48 -25
  9. package/cjs/koni/api/xcm/xTokens.js +1 -1
  10. package/cjs/koni/background/handlers/Extension.js +15 -8
  11. package/cjs/koni/background/handlers/Mobile.js +81 -5
  12. package/cjs/koni/background/handlers/State.js +54 -118
  13. package/cjs/koni/background/handlers/index.js +1 -1
  14. package/cjs/koni/background/subscription.js +34 -11
  15. package/cjs/packageInfo.js +1 -1
  16. package/cjs/services/balance-service/BalanceMapImpl.js +111 -0
  17. package/cjs/services/campaign-service/index.js +2 -0
  18. package/cjs/services/chain-service/constants.js +20 -3
  19. package/cjs/services/event-service/index.js +7 -7
  20. package/cjs/services/event-service/types.js +1 -1
  21. package/cjs/services/history-service/index.js +1 -0
  22. package/cjs/services/keyring-service/index.js +10 -6
  23. package/cjs/services/migration-service/scripts/index.js +3 -1
  24. package/cjs/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js +16 -0
  25. package/cjs/services/migration-service/scripts/tokens/MigrateToken.js +33 -0
  26. package/cjs/services/setting-service/SettingService.js +2 -1
  27. package/cjs/services/setting-service/i18n/i18n.js +2 -1
  28. package/cjs/services/storage-service/DatabaseService.js +8 -19
  29. package/cjs/services/storage-service/db-stores/Balance.js +4 -13
  30. package/cjs/services/wallet-connect-service/index.js +6 -3
  31. package/cjs/storage/index.js +59 -0
  32. package/cjs/utils/array.js +27 -1
  33. package/constants/staking.d.ts +1 -0
  34. package/constants/staking.js +2 -1
  35. package/koni/api/dotsama/transfer.js +2 -2
  36. package/koni/api/nft/config.js +2 -1
  37. package/koni/api/staking/bonding/astar.js +15 -24
  38. package/koni/api/staking/bonding/relayChain.js +40 -17
  39. package/koni/api/xcm/xTokens.js +1 -1
  40. package/koni/background/handlers/Extension.js +15 -8
  41. package/koni/background/handlers/Mobile.d.ts +6 -0
  42. package/koni/background/handlers/Mobile.js +75 -3
  43. package/koni/background/handlers/State.d.ts +10 -9
  44. package/koni/background/handlers/State.js +43 -105
  45. package/koni/background/handlers/index.js +1 -1
  46. package/koni/background/subscription.d.ts +4 -1
  47. package/koni/background/subscription.js +34 -11
  48. package/package.json +40 -20
  49. package/packageInfo.js +1 -1
  50. package/services/balance-service/BalanceMapImpl.d.ts +17 -0
  51. package/services/balance-service/BalanceMapImpl.js +101 -0
  52. package/services/campaign-service/index.d.ts +1 -0
  53. package/services/campaign-service/index.js +2 -0
  54. package/services/chain-service/constants.d.ts +1 -0
  55. package/services/chain-service/constants.js +18 -2
  56. package/services/event-service/index.d.ts +1 -4
  57. package/services/event-service/index.js +8 -7
  58. package/services/event-service/types.js +1 -1
  59. package/services/history-service/index.js +1 -0
  60. package/services/keyring-service/index.js +10 -6
  61. package/services/migration-service/scripts/index.js +3 -1
  62. package/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.d.ts +5 -0
  63. package/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js +8 -0
  64. package/services/migration-service/scripts/tokens/MigrateToken.d.ts +9 -0
  65. package/services/migration-service/scripts/tokens/MigrateToken.js +26 -0
  66. package/services/setting-service/SettingService.js +2 -1
  67. package/services/setting-service/i18n/i18n.js +2 -1
  68. package/services/storage-service/DatabaseService.d.ts +3 -1
  69. package/services/storage-service/DatabaseService.js +7 -19
  70. package/services/storage-service/db-stores/Balance.d.ts +3 -2
  71. package/services/storage-service/db-stores/Balance.js +4 -13
  72. package/services/wallet-connect-service/index.js +5 -3
  73. package/storage/index.d.ts +14 -0
  74. package/storage/index.js +52 -0
  75. package/utils/array.d.ts +1 -0
  76. package/utils/array.js +26 -1
@@ -11,7 +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
+ var _BalanceMapImpl = require("@subwallet/extension-base/services/balance-service/BalanceMapImpl");
15
15
  var _types = require("@subwallet/extension-base/services/base/types");
16
16
  var _buyService = _interopRequireDefault(require("@subwallet/extension-base/services/buy-service"));
17
17
  var _campaignService = _interopRequireDefault(require("@subwallet/extension-base/services/campaign-service"));
@@ -67,8 +67,7 @@ class KoniState {
67
67
  unsubscriptionMap = {};
68
68
  accountRefStore = new _AccountRef.default();
69
69
  externalRequest = {};
70
- balanceMap = {};
71
- balanceSubject = new _rxjs.Subject();
70
+ balanceMap = new _BalanceMapImpl.BalanceMapImpl();
72
71
  crowdloanMap = generateDefaultCrowdloanMap();
73
72
  crowdloanSubject = new _rxjs.Subject();
74
73
  nftSubject = new _rxjs.Subject();
@@ -194,11 +193,11 @@ class KoniState {
194
193
  get authSubjectV2() {
195
194
  return this.requestService.authSubjectV2;
196
195
  }
197
- generateDefaultBalanceMap() {
196
+ generateDefaultBalanceMap(_addresses) {
198
197
  const balanceMap = {};
199
198
  const activeChains = this.chainService.getActiveChainInfoMap();
200
199
  const isAllAccount = (0, _utils2.isAccountAll)(this.keyringService.currentAccount.address);
201
- const addresses = isAllAccount ? Object.keys(this.keyringService.accounts) : [this.keyringService.currentAccount.address];
200
+ const addresses = _addresses || (isAllAccount ? Object.keys(this.keyringService.accounts) : [this.keyringService.currentAccount.address]);
202
201
  addresses.forEach(address => {
203
202
  const temp = {};
204
203
  Object.values(activeChains).forEach(chainInfo => {
@@ -225,6 +224,7 @@ class KoniState {
225
224
  await this.chainService.init();
226
225
  this.afterChainServiceInit();
227
226
  await this.migrationService.run();
227
+ this.campaignService.init();
228
228
  this.eventService.emit('chain.ready', true);
229
229
  this.onReady();
230
230
  this.onAccountAdd();
@@ -687,72 +687,29 @@ class KoniState {
687
687
  getAllAddresses() {
688
688
  return _uiKeyring.keyring.getAccounts().map(account => account.address);
689
689
  }
690
- removeInactiveChainBalances(balanceMap) {
691
- const activeBalanceMap = {};
692
- Object.entries(balanceMap).forEach(_ref5 => {
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
- }
703
- }
704
- });
690
+ async removeInactiveChainBalances() {
691
+ const assetSettings = await this.chainService.getAssetSettings();
692
+ this.balanceMap.removeBalanceItemByFilter(item => {
693
+ return !assetSettings[item.tokenSlug];
705
694
  });
706
- return activeBalanceMap;
707
695
  }
708
- getBalance(reset) {
709
- const activeData = this.removeInactiveChainBalances(this.balanceMap);
696
+ async getBalance(reset) {
697
+ await this.removeInactiveChainBalances();
710
698
  return {
711
- details: activeData,
699
+ details: this.balanceMap.map,
712
700
  reset
713
701
  };
714
702
  }
715
703
  async getStoredBalance(address) {
716
- const items = await this.dbService.stores.balance.getBalanceMapByAddresses(address);
717
- return items || {};
704
+ return await this.dbService.stores.balance.getBalanceMapByAddresses(address);
718
705
  }
719
- async handleSwitchAccount(newAddress) {
720
- await Promise.all([this.resetBalanceMap(newAddress), this.resetCrowdloanMap(newAddress)]);
721
- }
722
- async resetBalanceMap(newAddress) {
723
- const defaultData = this.generateDefaultBalanceMap();
724
- let storedData = await this.getStoredBalance(newAddress);
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
- }
706
+ isFirstLoad = true;
707
+ async handleResetBalance(newAddress, forceRefresh) {
708
+ if (this.isFirstLoad || forceRefresh) {
709
+ const backupBalanceData = await this.dbService.getStoredBalance();
710
+ this.balanceMap.updateBalanceItems(backupBalanceData, (0, _utils2.isAccountAll)(newAddress));
750
711
  }
751
- this.balanceMap = {
752
- ...defaultData,
753
- ...storedData
754
- };
755
- this.publishBalance(true);
712
+ await Promise.all([this.removeInactiveChainBalances()]);
756
713
  }
757
714
  async resetCrowdloanMap(newAddress) {
758
715
  const defaultData = generateDefaultCrowdloanMap();
@@ -775,62 +732,35 @@ class KoniState {
775
732
  });
776
733
  });
777
734
  }
735
+ balanceUpdateCache = [];
778
736
 
779
737
  /** Note: items must be same tokenSlug */
780
738
  setBalanceItem(items) {
781
739
  if (items.length) {
782
- const tokens = [];
783
- const updates = [];
740
+ const nowTime = new Date().getTime();
784
741
  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(),
742
+ const balance = {
743
+ timestamp: nowTime,
795
744
  ...item
796
745
  };
797
- this.balanceMap[address][tokenSlug] = data;
798
- updates.push(data);
746
+ this.balanceUpdateCache.push(balance);
799
747
  }
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);
748
+ (0, _utils2.addLazy)('updateBalanceStore', () => {
749
+ const isAllAccount = (0, _utils2.isAccountAll)(this.keyringService.currentAccount.address);
750
+ this.balanceMap.updateBalanceItems(this.balanceUpdateCache, isAllAccount);
751
+ if (isAllAccount) {
752
+ this.balanceUpdateCache = [...this.balanceUpdateCache, ...Object.values(this.balanceMap.map[_constants.ALL_ACCOUNT_KEY])];
821
753
  }
822
- }
823
- this.updateBalanceStore(updates);
824
- this.lazyNext('setBalanceItem', () => {
825
- this.publishBalance();
826
- });
754
+ this.updateBalanceStore(this.balanceUpdateCache);
755
+ this.balanceUpdateCache = [];
756
+ }, 300, 1800);
827
757
  }
828
758
  }
829
759
  updateBalanceStore(items) {
830
760
  this.dbService.updateBulkBalanceStore(items).catch(e => this.logger.warn(e));
831
761
  }
832
762
  subscribeBalance() {
833
- return this.balanceSubject;
763
+ return this.balanceMap.mapSubject;
834
764
  }
835
765
  getCrowdloan(reset) {
836
766
  return {
@@ -1081,9 +1011,6 @@ class KoniState {
1081
1011
  async resumeAllNetworks() {
1082
1012
  return this.chainService.resumeAllChainApis();
1083
1013
  }
1084
- publishBalance(reset) {
1085
- this.balanceSubject.next(this.getBalance(reset));
1086
- }
1087
1014
  publishCrowdloan(reset) {
1088
1015
  this.crowdloanSubject.next(this.getCrowdloan(reset));
1089
1016
  }
@@ -1108,8 +1035,8 @@ class KoniState {
1108
1035
  if (!genesisHash) {
1109
1036
  return [undefined, undefined];
1110
1037
  }
1111
- const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref7 => {
1112
- let [networkKey, chainInfo] = _ref7;
1038
+ const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref5 => {
1039
+ let [networkKey, chainInfo] = _ref5;
1113
1040
  return (0, _utils._getSubstrateGenesisHash)(chainInfo) === genesisHash;
1114
1041
  });
1115
1042
  if (rs) {
@@ -1126,9 +1053,9 @@ class KoniState {
1126
1053
  if (!chainId) {
1127
1054
  return [undefined, undefined];
1128
1055
  }
1129
- const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref8 => {
1056
+ const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref6 => {
1130
1057
  var _chainInfo$evmInfo;
1131
- let [networkKey, chainInfo] = _ref8;
1058
+ let [networkKey, chainInfo] = _ref6;
1132
1059
  return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) === chainId;
1133
1060
  });
1134
1061
  if (rs) {
@@ -1144,11 +1071,11 @@ class KoniState {
1144
1071
  }
1145
1072
  return Object.values(_constants2._PREDEFINED_SINGLE_MODES).find(item => item.networkKeys.includes(networkKey));
1146
1073
  }
1147
- accountExportPrivateKey(_ref9) {
1074
+ accountExportPrivateKey(_ref7) {
1148
1075
  let {
1149
1076
  address,
1150
1077
  password
1151
- } = _ref9;
1078
+ } = _ref7;
1152
1079
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1153
1080
  const exportedJson = _uiKeyring.keyring.backupAccount(_uiKeyring.keyring.getPair(address), password);
1154
1081
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
@@ -1158,11 +1085,11 @@ class KoniState {
1158
1085
  publicKey: (0, _util.u8aToHex)(decoded.publicKey)
1159
1086
  };
1160
1087
  }
1161
- checkPublicAndSecretKey(_ref10) {
1088
+ checkPublicAndSecretKey(_ref8) {
1162
1089
  let {
1163
1090
  publicKey,
1164
1091
  secretKey
1165
- } = _ref10;
1092
+ } = _ref8;
1166
1093
  try {
1167
1094
  const _secret = (0, _util.hexStripPrefix)(secretKey);
1168
1095
  if (_secret.length === 64) {
@@ -1280,11 +1207,11 @@ class KoniState {
1280
1207
  return this.requestService.addConfirmation(id, url, 'evmSignatureRequest', signPayload, {
1281
1208
  requiredPassword: false,
1282
1209
  address
1283
- }).then(_ref11 => {
1210
+ }).then(_ref9 => {
1284
1211
  let {
1285
1212
  isApproved,
1286
1213
  payload
1287
- } = _ref11;
1214
+ } = _ref9;
1288
1215
  if (isApproved) {
1289
1216
  if (payload) {
1290
1217
  return payload;
@@ -1569,7 +1496,7 @@ class KoniState {
1569
1496
  const chainMap = this.chainService.getChainInfoMap();
1570
1497
  const balanceDataList = await Promise.all(promiseList);
1571
1498
  balanceDataList.forEach(balanceData => {
1572
- balanceData && balanceData.forEach(_ref12 => {
1499
+ balanceData && balanceData.forEach(_ref10 => {
1573
1500
  var _currentAssetSettings;
1574
1501
  let {
1575
1502
  balance,
@@ -1578,7 +1505,7 @@ class KoniState {
1578
1505
  locked,
1579
1506
  network,
1580
1507
  symbol
1581
- } = _ref12;
1508
+ } = _ref10;
1582
1509
  const chain = _subscanChainMap.SUBSCAN_BALANCE_CHAIN_MAP_REVERSE[network];
1583
1510
  const chainInfo = chain ? chainMap[chain] : null;
1584
1511
  const balanceIsEmpty = (!balance || balance === '0') && (!locked || locked === '0') && (!bonded || bonded === '0');
@@ -1619,6 +1546,7 @@ class KoniState {
1619
1546
  // Remove Balance
1620
1547
  stores.balance.removeAllByAddress(address).catch(console.error);
1621
1548
  stores.balance.removeAllByAddress(_constants.ALL_ACCOUNT_KEY).catch(console.error);
1549
+ this.balanceMap.removeBalanceItems([address, _constants.ALL_ACCOUNT_KEY]);
1622
1550
 
1623
1551
  // Remove NFT
1624
1552
  stores.nft.deleteNftByAddress([address]).catch(console.error);
@@ -1636,6 +1564,14 @@ class KoniState {
1636
1564
  await this.subscription.reloadStaking();
1637
1565
  return true;
1638
1566
  }
1567
+ async reloadBalance() {
1568
+ await this.subscription.reloadBalance();
1569
+ return true;
1570
+ }
1571
+ async reloadCrowdloan() {
1572
+ await this.subscription.reloadCrowdloan();
1573
+ return true;
1574
+ }
1639
1575
  async approvePassPhishingPage(_url) {
1640
1576
  return new Promise(resolve => {
1641
1577
  this.settingService.getPassPhishingList(value => {
@@ -58,7 +58,7 @@ function handlers(_ref, port) {
58
58
  const isMobile = port.name === _defaults.PORT_MOBILE;
59
59
  const isExtension = port.name === extensionPortName;
60
60
  const sender = port.sender;
61
- const from = isExtension ? 'extension' : sender.tab && sender.tab.url || sender.url || '<unknown>';
61
+ const from = isExtension ? 'extension' : sender.url || sender.tab && sender.tab.url || '<unknown>';
62
62
  const source = `${from}: ${id}: ${message}`;
63
63
 
64
64
  // console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
@@ -56,10 +56,11 @@ class KoniSubscription {
56
56
  }
57
57
  async start() {
58
58
  var _this$state$keyringSe;
59
- await Promise.all([this.state.eventService.waitKeyringReady, this.state.eventService.waitAssetReady]);
59
+ await Promise.all([this.state.eventService.waitCryptoReady, this.state.eventService.waitKeyringReady, this.state.eventService.waitAssetReady]);
60
60
  const currentAddress = (_this$state$keyringSe = this.state.keyringService.currentAccount) === null || _this$state$keyringSe === void 0 ? void 0 : _this$state$keyringSe.address;
61
61
  if (currentAddress) {
62
- this.subscribeBalancesAndCrowdloans(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
62
+ this.subscribeBalances(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
63
+ this.subscribeCrowdloans(currentAddress, this.state.getSubstrateApiMap());
63
64
  this.subscribeStakingOnChain(currentAddress, this.state.getSubstrateApiMap());
64
65
  }
65
66
  this.eventHandler = (events, eventTypes) => {
@@ -73,10 +74,11 @@ class KoniSubscription {
73
74
  if (!address) {
74
75
  return;
75
76
  }
76
- this.subscribeBalancesAndCrowdloans(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
77
+ this.subscribeBalances(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
78
+ this.subscribeCrowdloans(address, serviceInfo.chainApiMap.substrate);
77
79
  this.subscribeStakingOnChain(address, serviceInfo.chainApiMap.substrate);
78
80
  };
79
- this.state.eventService.onLazy(this.eventHandler);
81
+ this.state.eventService.onLazy(this.eventHandler.bind(this));
80
82
  }
81
83
  async stop() {
82
84
  if (this.eventHandler) {
@@ -86,16 +88,24 @@ class KoniSubscription {
86
88
  this.stopAllSubscription();
87
89
  return Promise.resolve();
88
90
  }
89
- subscribeBalancesAndCrowdloans(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
90
- this.state.handleSwitchAccount(address).then(() => {
91
- const addresses = this.state.getDecodedAddresses(address);
92
- if (!addresses.length) {
93
- return;
94
- }
91
+ subscribeBalances(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
92
+ const addresses = this.state.getDecodedAddresses(address);
93
+ if (!addresses.length) {
94
+ return;
95
+ }
96
+ this.state.handleResetBalance(address).then(() => {
95
97
  this.updateSubscription('balance', this.initBalanceSubscription(addresses, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime));
96
- this.updateSubscription('crowdloan', this.initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime));
97
98
  }).catch(err => this.logger.warn(err));
98
99
  }
100
+ subscribeCrowdloans(address, substrateApiMap, onlyRunOnFirstTime) {
101
+ const addresses = this.state.getDecodedAddresses(address);
102
+ if (!addresses.length) {
103
+ return;
104
+ }
105
+ this.state.resetCrowdloanMap(address).then(() => {
106
+ this.updateSubscription('crowdloan', this.initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime));
107
+ }).catch(console.error);
108
+ }
99
109
  subscribeStakingOnChain(address, substrateApiMap, onlyRunOnFirstTime) {
100
110
  this.state.resetStaking(address);
101
111
  const addresses = this.state.getDecodedAddresses(address);
@@ -255,5 +265,18 @@ class KoniSubscription {
255
265
  this.subscribeStakingOnChain(currentAddress, this.state.getSubstrateApiMap());
256
266
  await (0, _utils2.waitTimeout)(1800);
257
267
  }
268
+ async reloadBalance() {
269
+ var _this$state$keyringSe3;
270
+ const currentAddress = (_this$state$keyringSe3 = this.state.keyringService.currentAccount) === null || _this$state$keyringSe3 === void 0 ? void 0 : _this$state$keyringSe3.address;
271
+ this.subscribeBalances(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
272
+ await (0, _utils2.waitTimeout)(1800);
273
+ }
274
+ async reloadCrowdloan() {
275
+ var _this$state$keyringSe4;
276
+ const currentAddress = (_this$state$keyringSe4 = this.state.keyringService.currentAccount) === null || _this$state$keyringSe4 === void 0 ? void 0 : _this$state$keyringSe4.address;
277
+ await this.state.handleResetBalance(currentAddress, true);
278
+ this.subscribeCrowdloans(currentAddress, this.state.getSubstrateApiMap());
279
+ await (0, _utils2.waitTimeout)(1800);
280
+ }
258
281
  }
259
282
  exports.KoniSubscription = KoniSubscription;
@@ -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.25-1'
16
+ version: '1.1.27-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BalanceMapImpl = void 0;
7
+ var _constants = require("@subwallet/extension-base/constants");
8
+ var _group = require("@subwallet/extension-base/services/balance-service/helpers/group");
9
+ var _utils = require("@subwallet/extension-base/utils");
10
+ var _rxjs = require("rxjs");
11
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
12
+ // SPDX-License-Identifier: Apache-2.0
13
+
14
+ class BalanceMapImpl {
15
+ constructor() {
16
+ let _map = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17
+ this._map = _map;
18
+ this._mapSubject = new _rxjs.BehaviorSubject(_map);
19
+ }
20
+ get map() {
21
+ return this._mapSubject.getValue();
22
+ }
23
+ get mapSubject() {
24
+ return this._mapSubject;
25
+ }
26
+ setData(map) {
27
+ this._map = map;
28
+ this.triggerChange();
29
+ }
30
+ setAddressData(address, data) {
31
+ this._map[address] = data;
32
+ this.triggerChange();
33
+ }
34
+ triggerChange(computeAll) {
35
+ if (computeAll) {
36
+ this.computeAllAccountBalance();
37
+ }
38
+ this._mapSubject.next(this._map);
39
+ }
40
+ updateBalanceItem(balanceItem) {
41
+ let trigger = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
42
+ const {
43
+ address,
44
+ tokenSlug
45
+ } = balanceItem;
46
+ if (!this._map[address]) {
47
+ this._map[address] = {};
48
+ }
49
+ this._map[address][tokenSlug] = balanceItem;
50
+ trigger && this.triggerChange();
51
+ }
52
+ updateBalanceItems(balanceItems, computeAll) {
53
+ balanceItems.forEach(balanceItem => {
54
+ this.updateBalanceItem(balanceItem);
55
+ });
56
+ this.triggerChange(computeAll);
57
+ }
58
+ removeBalanceItemByFilter(filter) {
59
+ Object.keys(this._map).forEach(address => {
60
+ Object.keys(this._map[address]).forEach(tokenSlug => {
61
+ if (filter(this._map[address][tokenSlug])) {
62
+ delete this._map[address][tokenSlug];
63
+ }
64
+ });
65
+ });
66
+ this.triggerChange();
67
+ }
68
+ computeAllAccountBalance() {
69
+ const allAccountBalanceInfo = {};
70
+ const allAccountBalance = {};
71
+ Object.keys(this._map).filter(a => !(0, _utils.isAccountAll)(a)).forEach(address => {
72
+ Object.keys(this._map[address]).forEach(tokenSlug => {
73
+ if (!allAccountBalance[tokenSlug]) {
74
+ allAccountBalance[tokenSlug] = [];
75
+ }
76
+ allAccountBalance[tokenSlug].push(this._map[address][tokenSlug]);
77
+ });
78
+ });
79
+ Object.entries(allAccountBalance).forEach(_ref => {
80
+ let [tokenSlug, balanceItems] = _ref;
81
+ allAccountBalanceInfo[tokenSlug] = (0, _group.groupBalance)(balanceItems, _constants.ALL_ACCOUNT_KEY, tokenSlug);
82
+ });
83
+ this._map[_constants.ALL_ACCOUNT_KEY] = allAccountBalanceInfo;
84
+ }
85
+
86
+ // Remove balance items buy address or tokenSlug
87
+ removeBalanceItems(addresses, tokenSlugs) {
88
+ // If addresses is empty, remove all
89
+ if (addresses && tokenSlugs) {
90
+ addresses.forEach(address => {
91
+ tokenSlugs.forEach(tokenSlug => {
92
+ this._map[address] && this._map[address][tokenSlug] && delete this._map[address][tokenSlug];
93
+ });
94
+ });
95
+ } else if (addresses && !tokenSlugs) {
96
+ addresses.forEach(address => {
97
+ this._map[address] && delete this._map[address];
98
+ });
99
+ } else if (!addresses && tokenSlugs) {
100
+ Object.keys(this._map).forEach(address => {
101
+ tokenSlugs.forEach(tokenSlug => {
102
+ this._map[address][tokenSlug] && delete this._map[address][tokenSlug];
103
+ });
104
+ });
105
+ } else {
106
+ this._map = {};
107
+ }
108
+ this.triggerChange();
109
+ }
110
+ }
111
+ exports.BalanceMapImpl = BalanceMapImpl;
@@ -15,6 +15,8 @@ class CampaignService {
15
15
  #state;
16
16
  constructor(state) {
17
17
  this.#state = state;
18
+ }
19
+ init() {
18
20
  this.fetchCampaign().catch(e => {
19
21
  console.error('Error on fetch campaigns', e);
20
22
  });
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports._ZK_ASSET_PREFIX = exports._XCM_TYPE = exports._XCM_CHAIN_GROUP = exports._TRANSFER_NOT_SUPPORTED_CHAINS = exports._TRANSFER_CHAIN_GROUP = exports._SUBSTRATE_DEFAULT_INFLATION_PARAMS = exports._STAKING_ERA_LENGTH_MAP = exports._STAKING_CHAIN_GROUP = exports._PURE_EVM_CHAINS = exports._PREDEFINED_SINGLE_MODES = exports._PARACHAIN_INFLATION_DISTRIBUTION = exports._NFT_CHAIN_GROUP = exports._MULTI_CHAIN_ASSET_SRC = exports._MANTA_ZK_CHAIN_GROUP = exports._KNOWN_CHAIN_INFLATION_PARAMS = exports._DEFAULT_MANTA_ZK_CHAIN = exports._DEFAULT_ACTIVE_CHAINS = exports._CHAIN_LOGO_MAP_SRC = exports._CHAIN_INFO_SRC = exports._CHAIN_ASSET_SRC = exports._BALANCE_TOKEN_GROUP = exports._BALANCE_PARSING_CHAIN_GROUP = exports._BALANCE_CHAIN_GROUP = exports._ASSET_REF_SRC = exports._ASSET_LOGO_MAP_SRC = exports._API_OPTIONS_CHAIN_GROUP = exports.EVM_REFORMAT_DECIMALS = exports.EVM_PASS_CONNECT_STATUS = exports.API_MAX_RETRY = exports.API_CONNECT_TIMEOUT = exports.API_AUTO_CONNECT_MS = void 0;
6
+ exports._ZK_ASSET_PREFIX = exports._XCM_TYPE = exports._XCM_CHAIN_GROUP = exports._TRANSFER_NOT_SUPPORTED_CHAINS = exports._TRANSFER_CHAIN_GROUP = exports._SUBSTRATE_DEFAULT_INFLATION_PARAMS = exports._STAKING_ERA_LENGTH_MAP = exports._STAKING_CHAIN_GROUP = exports._PURE_EVM_CHAINS = exports._PREDEFINED_SINGLE_MODES = exports._PARACHAIN_INFLATION_DISTRIBUTION = exports._NFT_CHAIN_GROUP = exports._MULTI_CHAIN_ASSET_SRC = exports._MANTA_ZK_CHAIN_GROUP = exports._KNOWN_CHAIN_INFLATION_PARAMS = exports._EXPECTED_BLOCK_TIME = exports._DEFAULT_MANTA_ZK_CHAIN = exports._DEFAULT_ACTIVE_CHAINS = exports._CHAIN_LOGO_MAP_SRC = exports._CHAIN_INFO_SRC = exports._CHAIN_ASSET_SRC = exports._BALANCE_TOKEN_GROUP = exports._BALANCE_PARSING_CHAIN_GROUP = exports._BALANCE_CHAIN_GROUP = exports._ASSET_REF_SRC = exports._ASSET_LOGO_MAP_SRC = exports._API_OPTIONS_CHAIN_GROUP = exports.EVM_REFORMAT_DECIMALS = exports.EVM_PASS_CONNECT_STATUS = exports.API_MAX_RETRY = exports.API_CONNECT_TIMEOUT = exports.API_AUTO_CONNECT_MS = void 0;
7
7
  var _chainList = require("@subwallet/chain-list");
8
8
  var _types = require("@subwallet/chain-list/types");
9
9
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
@@ -113,6 +113,23 @@ const _STAKING_ERA_LENGTH_MAP = {
113
113
  goldberg_testnet: 24
114
114
  };
115
115
  exports._STAKING_ERA_LENGTH_MAP = _STAKING_ERA_LENGTH_MAP;
116
+ const _EXPECTED_BLOCK_TIME = {
117
+ // in seconds
118
+ alephTest: 1,
119
+ aleph: 1,
120
+ polkadot: 6,
121
+ kusama: 6,
122
+ polkadex: 12,
123
+ ternoa: 6,
124
+ ternoa_alphanet: 6,
125
+ westend: 6,
126
+ kate: 20,
127
+ edgeware: 6,
128
+ creditcoin: 12,
129
+ vara_network: 3,
130
+ goldberg_testnet: 20
131
+ };
132
+ exports._EXPECTED_BLOCK_TIME = _EXPECTED_BLOCK_TIME;
116
133
  const _PARACHAIN_INFLATION_DISTRIBUTION = {
117
134
  moonbeam: {
118
135
  // https://docs.moonbeam.network/learn/features/staking/#annual-inflation
@@ -210,7 +227,7 @@ const _TRANSFER_NOT_SUPPORTED_CHAINS = ['subspace_gemini_3a', 'kulupu', 'joystre
210
227
  exports._TRANSFER_NOT_SUPPORTED_CHAINS = _TRANSFER_NOT_SUPPORTED_CHAINS;
211
228
  const _TRANSFER_CHAIN_GROUP = {
212
229
  acala: ['karura', 'acala', 'acala_testnet'],
213
- kintsugi: ['kintsugi', 'kintsugi_test', 'interlay', 'hydradx_main', 'mangatax_para'],
230
+ kintsugi: ['kintsugi', 'kintsugi_test', 'interlay', 'mangatax_para'],
214
231
  genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
215
232
  crab: ['crab', 'pangolin'],
216
233
  bitcountry: ['pioneer', 'bitcountry', 'bifrost', 'bifrost_dot'],
@@ -218,7 +235,7 @@ const _TRANSFER_CHAIN_GROUP = {
218
235
  riochain: ['riochain'],
219
236
  sora_substrate: ['sora_substrate'],
220
237
  avail: ['kate', 'goldberg_testnet'],
221
- pendulum: ['pendulum', 'amplitude', 'amplitude_test'],
238
+ pendulum: ['pendulum', 'amplitude', 'amplitude_test', 'hydradx_main'],
222
239
  centrifuge: ['centrifuge']
223
240
  };
224
241
  exports._TRANSFER_CHAIN_GROUP = _TRANSFER_CHAIN_GROUP;
@@ -11,15 +11,14 @@ var _eventemitter = _interopRequireDefault(require("eventemitter3"));
11
11
 
12
12
  // Stateless service handle runtime event on background
13
13
 
14
+ const DEFAULT_LAZY_TIME = 300;
15
+ const LONG_LAZY_TIME = 900;
16
+ const LONG_LAZY_EVENTS = ['account.add', 'chain.add'];
14
17
  class EventService extends _eventemitter.default {
15
18
  pendingEvents = [];
16
19
  lazyEmitter = new _eventemitter.default();
17
20
  constructor() {
18
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
19
- lazyTime: 300
20
- };
21
21
  super();
22
- this.lazyTime = options.lazyTime;
23
22
  this.timeoutId = null;
24
23
  this.waitCryptoReady = this.generateWaitPromise('crypto.ready');
25
24
  this.waitDatabaseReady = this.generateWaitPromise('database.ready');
@@ -39,13 +38,14 @@ class EventService extends _eventemitter.default {
39
38
  });
40
39
  });
41
40
  }
42
- setLazyTimeout() {
41
+ setLazyTimeout(eventType) {
43
42
  if (this.timeoutId) {
44
43
  clearTimeout(this.timeoutId);
45
44
  }
45
+ const timeout = LONG_LAZY_EVENTS.includes(eventType) ? LONG_LAZY_TIME : DEFAULT_LAZY_TIME;
46
46
  this.timeoutId = setTimeout(() => {
47
47
  this.emitLazy();
48
- }, this.lazyTime);
48
+ }, timeout);
49
49
  }
50
50
  emitLazy() {
51
51
  try {
@@ -74,7 +74,7 @@ class EventService extends _eventemitter.default {
74
74
  type: eventType,
75
75
  data: args
76
76
  });
77
- this.setLazyTimeout();
77
+ this.setLazyTimeout(eventType);
78
78
  return super.emit(eventType, ...args);
79
79
  }
80
80
  }
@@ -7,7 +7,7 @@ exports.COMMON_RELOAD_EVENTS = void 0;
7
7
  // Copyright 2019-2022 @subwallet/extension-base
8
8
  // SPDX-License-Identifier: Apache-2.0
9
9
 
10
- const COMMON_RELOAD_EVENTS = ['account.updateCurrent', 'asset.updateState', 'account.add', 'chain.updateState', 'account.remove', 'chain.add', 'mantaPay.initSync',
10
+ const COMMON_RELOAD_EVENTS = ['account.updateCurrent', 'account.add', 'account.remove', 'asset.updateState', 'chain.updateState', 'chain.add', 'mantaPay.initSync',
11
11
  // TODO: re-check this
12
12
  'mantaPay.enable'];
13
13
  exports.COMMON_RELOAD_EVENTS = COMMON_RELOAD_EVENTS;
@@ -247,6 +247,7 @@ class HistoryService {
247
247
  startPromiseHandler = (0, _promise.createPromiseHandler)();
248
248
  async init() {
249
249
  this.status = _types.ServiceStatus.INITIALIZING;
250
+ await this.eventService.waitCryptoReady;
250
251
  await this.loadData();
251
252
  Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
252
253
  this.getHistories().catch(console.log);