@subwallet/extension-base 1.1.25-0 → 1.1.26-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/background/KoniTypes.d.ts +2 -2
  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/relayChain.js +48 -25
  8. package/cjs/koni/api/xcm/xTokens.js +1 -1
  9. package/cjs/koni/background/handlers/Extension.js +11 -8
  10. package/cjs/koni/background/handlers/Mobile.js +81 -5
  11. package/cjs/koni/background/handlers/State.js +45 -117
  12. package/cjs/koni/background/subscription.js +2 -2
  13. package/cjs/packageInfo.js +1 -1
  14. package/cjs/services/balance-service/BalanceMapImpl.js +114 -0
  15. package/cjs/services/campaign-service/index.js +2 -0
  16. package/cjs/services/chain-service/constants.js +24 -3
  17. package/cjs/services/event-service/index.js +7 -7
  18. package/cjs/services/event-service/types.js +1 -1
  19. package/cjs/services/history-service/index.js +1 -0
  20. package/cjs/services/keyring-service/index.js +10 -6
  21. package/cjs/services/migration-service/scripts/index.js +3 -1
  22. package/cjs/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js +16 -0
  23. package/cjs/services/migration-service/scripts/tokens/MigrateToken.js +33 -0
  24. package/cjs/services/setting-service/SettingService.js +2 -1
  25. package/cjs/services/setting-service/i18n/i18n.js +2 -1
  26. package/cjs/services/storage-service/DatabaseService.js +8 -19
  27. package/cjs/services/storage-service/db-stores/Balance.js +4 -13
  28. package/cjs/services/wallet-connect-service/index.js +6 -3
  29. package/cjs/storage/index.js +59 -0
  30. package/cjs/utils/array.js +27 -1
  31. package/constants/staking.d.ts +1 -0
  32. package/constants/staking.js +2 -1
  33. package/koni/api/dotsama/transfer.js +2 -2
  34. package/koni/api/nft/config.js +2 -1
  35. package/koni/api/staking/bonding/relayChain.js +40 -17
  36. package/koni/api/xcm/xTokens.js +1 -1
  37. package/koni/background/handlers/Extension.js +11 -8
  38. package/koni/background/handlers/Mobile.d.ts +6 -0
  39. package/koni/background/handlers/Mobile.js +75 -3
  40. package/koni/background/handlers/State.d.ts +7 -8
  41. package/koni/background/handlers/State.js +34 -104
  42. package/koni/background/subscription.js +2 -2
  43. package/package.json +40 -20
  44. package/packageInfo.js +1 -1
  45. package/services/balance-service/BalanceMapImpl.d.ts +17 -0
  46. package/services/balance-service/BalanceMapImpl.js +104 -0
  47. package/services/campaign-service/index.d.ts +1 -0
  48. package/services/campaign-service/index.js +2 -0
  49. package/services/chain-service/constants.d.ts +1 -0
  50. package/services/chain-service/constants.js +22 -2
  51. package/services/event-service/index.d.ts +1 -4
  52. package/services/event-service/index.js +8 -7
  53. package/services/event-service/types.js +1 -1
  54. package/services/history-service/index.js +1 -0
  55. package/services/keyring-service/index.js +10 -6
  56. package/services/migration-service/scripts/index.js +3 -1
  57. package/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.d.ts +5 -0
  58. package/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js +8 -0
  59. package/services/migration-service/scripts/tokens/MigrateToken.d.ts +9 -0
  60. package/services/migration-service/scripts/tokens/MigrateToken.js +26 -0
  61. package/services/setting-service/SettingService.js +2 -1
  62. package/services/setting-service/i18n/i18n.js +2 -1
  63. package/services/storage-service/DatabaseService.d.ts +3 -1
  64. package/services/storage-service/DatabaseService.js +7 -19
  65. package/services/storage-service/db-stores/Balance.d.ts +3 -2
  66. package/services/storage-service/db-stores/Balance.js +4 -13
  67. package/services/wallet-connect-service/index.js +5 -3
  68. package/storage/index.d.ts +14 -0
  69. package/storage/index.js +52 -0
  70. package/utils/array.d.ts +1 -0
  71. package/utils/array.js +26 -1
@@ -1,7 +1,31 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { state } from '@subwallet/extension-base/koni/background/handlers/index';
5
+ import { SWStorage } from '@subwallet/extension-base/storage';
6
+ import { listMerge } from '@subwallet/extension-base/utils';
4
7
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
8
+ export function isLocalStorageReset() {
9
+ var _window;
10
+ if ((_window = window) !== null && _window !== void 0 && _window.localStorage) {
11
+ return !window.localStorage.getItem('keyring:subwallet');
12
+ } else {
13
+ return false;
14
+ }
15
+ }
16
+ export async function isIndexedDBReset() {
17
+ try {
18
+ return (await state.dbService.stores.migration.table.count()) < 1;
19
+ } catch (e) {
20
+ return true;
21
+ }
22
+ }
23
+
24
+ // Detect problems on the web-runner
25
+ export async function isWebRunnerDataReset() {
26
+ return isLocalStorageReset() || (await isIndexedDBReset());
27
+ }
28
+ const swStorage = SWStorage.instance;
5
29
  const DEFAULT_SERVICE_MAP = {
6
30
  subscription: {
7
31
  chainRegistry: true,
@@ -22,8 +46,17 @@ export default class Mobile {
22
46
  // @ts-ignore
23
47
 
24
48
  restoreHandler = createPromiseHandler();
49
+ lastRestoreData = {};
25
50
  constructor(state) {
26
51
  this.state = state;
52
+ if (!isLocalStorageReset()) {
53
+ this.lastRestoreData.storage = swStorage.copy();
54
+ }
55
+ (async () => {
56
+ if (!(await isIndexedDBReset())) {
57
+ this.lastRestoreData.indexedDB = await state.dbService.getExportJson();
58
+ }
59
+ })().catch(console.error);
27
60
  }
28
61
  ping() {
29
62
  return 'mobile:ping';
@@ -94,10 +127,46 @@ export default class Mobile {
94
127
  restartSubscriptionServices(services) {
95
128
  console.log('restartSubscriptionServices');
96
129
  }
97
- async mobileBackup() {
130
+ async _getLocalStorageExportData() {
131
+ return Promise.resolve(JSON.stringify(swStorage.copy()));
132
+ }
133
+ async _getDexieExportData() {
98
134
  const indexedDB = await this.state.dbService.exportDB();
135
+ if ((await isIndexedDBReset()) && this.lastRestoreData.indexedDB) {
136
+ // Merge with latest restore DexieData
137
+ const exportData = await this.state.dbService.getExportJson();
138
+ const exportTables = exportData === null || exportData === void 0 ? void 0 : exportData.data.data;
139
+ const existedData = this.lastRestoreData.indexedDB;
140
+ const existedTableMap = Object.fromEntries(existedData.data.data.map(table => [table.tableName, table]));
141
+ if ((exportTables === null || exportTables === void 0 ? void 0 : exportTables.length) > 0) {
142
+ exportTables.forEach(({
143
+ inbound,
144
+ rows,
145
+ tableName
146
+ }) => {
147
+ const latestTable = existedTableMap[tableName];
148
+
149
+ // chain & asset & campaign
150
+ if (tableName === 'chain' || tableName === 'asset' || tableName === 'campaign') {
151
+ latestTable.rows = listMerge('slug', latestTable.rows, rows);
152
+
153
+ // Todo: Campaign still doesn't work
154
+ } else if (tableName === 'migrations') {
155
+ latestTable.rows = listMerge('key', latestTable.rows, rows);
156
+ } else if (tableName === 'transactions') {
157
+ latestTable.rows = listMerge(['chain', 'address', 'extrinsicHash'], latestTable.rows, rows);
158
+ }
159
+ });
160
+ }
161
+ return JSON.stringify(existedData);
162
+ }
163
+ return indexedDB;
164
+ }
165
+ async mobileBackup() {
166
+ const storage = await this._getLocalStorageExportData();
167
+ const indexedDB = await this._getDexieExportData();
99
168
  return {
100
- storage: JSON.stringify(localStorage),
169
+ storage,
101
170
  indexedDB
102
171
  };
103
172
  }
@@ -108,10 +177,13 @@ export default class Mobile {
108
177
  if (storage) {
109
178
  const storageData = JSON.parse(storage);
110
179
  for (const key in storageData) {
111
- localStorage.setItem(key, storageData[key]);
180
+ swStorage.setItem(key, storageData[key]);
112
181
  }
113
182
  }
114
183
  if (indexedDB) {
184
+ // Backup the last restore data to memory
185
+ this.lastRestoreData.indexedDB = JSON.parse(indexedDB);
186
+ // Backup the last restore data to memory
115
187
  await this.state.dbService.importDB(indexedDB);
116
188
  }
117
189
  this.restoreHandler.resolve();
@@ -36,7 +36,6 @@ export default class KoniState {
36
36
  private readonly accountRefStore;
37
37
  private externalRequest;
38
38
  private balanceMap;
39
- private balanceSubject;
40
39
  private crowdloanMap;
41
40
  private crowdloanSubject;
42
41
  private nftSubject;
@@ -84,7 +83,7 @@ export default class KoniState {
84
83
  saveMetadata(meta: MetadataDef): void;
85
84
  sign(url: string, request: RequestSign, account: AccountJson): Promise<ResponseSigning>;
86
85
  get authSubjectV2(): BehaviorSubject<import("@subwallet/extension-base/background/types").AuthorizeRequest[]>;
87
- generateDefaultBalanceMap(): BalanceMap;
86
+ generateDefaultBalanceMap(_addresses?: string[]): BalanceMap;
88
87
  private afterChainServiceInit;
89
88
  init(): Promise<void>;
90
89
  initMantaPay(password: string): Promise<void>;
@@ -150,17 +149,18 @@ export default class KoniState {
150
149
  getAccountAddress(): string | null;
151
150
  getDecodedAddresses(address?: string): string[];
152
151
  getAllAddresses(): string[];
153
- private removeInactiveChainBalances;
154
- getBalance(reset?: boolean): BalanceJson;
155
- getStoredBalance(address: string): Promise<BalanceMap>;
152
+ removeInactiveChainBalances(): Promise<void>;
153
+ getBalance(reset?: boolean): Promise<BalanceJson>;
154
+ getStoredBalance(address: string): Promise<BalanceItem[]>;
155
+ private isFirstLoad;
156
156
  handleSwitchAccount(newAddress: string): Promise<void>;
157
- resetBalanceMap(newAddress: string): Promise<void>;
158
157
  resetCrowdloanMap(newAddress: string): Promise<void>;
159
158
  resetStaking(newAddress: string): void;
159
+ private balanceUpdateCache;
160
160
  /** Note: items must be same tokenSlug */
161
161
  setBalanceItem(items: BalanceItem[]): void;
162
162
  private updateBalanceStore;
163
- subscribeBalance(): Subject<BalanceJson>;
163
+ subscribeBalance(): BehaviorSubject<BalanceMap>;
164
164
  getCrowdloan(reset?: boolean): CrowdloanJson;
165
165
  getStoredCrowdloan(address: string): Promise<Record<string, import("../../../services/storage-service/databases").ICrowdloanItem>>;
166
166
  setCrowdloanItem(networkKey: string, item: CrowdloanItem): void;
@@ -210,7 +210,6 @@ export default class KoniState {
210
210
  cleanExternalRequest(): void;
211
211
  pauseAllNetworks(code?: number, reason?: string): Promise<void>;
212
212
  resumeAllNetworks(): Promise<void>;
213
- private publishBalance;
214
213
  private publishCrowdloan;
215
214
  findNetworkKeyByGenesisHash(genesisHash?: string | null): [string | undefined, _ChainInfo | undefined];
216
215
  findChainIdGenesisHash(genesisHash?: string | null): number | undefined;
@@ -7,7 +7,7 @@ import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/ba
7
7
  import { APIItemState, BasicTxErrorType, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
8
8
  import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
9
9
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
10
- import { groupBalance } from '@subwallet/extension-base/services/balance-service/helpers/group';
10
+ import { BalanceMapImpl } from '@subwallet/extension-base/services/balance-service/BalanceMapImpl';
11
11
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
12
12
  import BuyService from '@subwallet/extension-base/services/buy-service';
13
13
  import CampaignService from '@subwallet/extension-base/services/campaign-service';
@@ -28,7 +28,7 @@ import { SUBSCAN_API_CHAIN_MAP, SUBSCAN_BALANCE_CHAIN_MAP_REVERSE } from '@subwa
28
28
  import TransactionService from '@subwallet/extension-base/services/transaction-service';
29
29
  import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
30
30
  import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
31
- import { isAccountAll, isSameAddress, stripUrl, TARGET_ENV } from '@subwallet/extension-base/utils';
31
+ import { addLazy, isAccountAll, stripUrl, TARGET_ENV } from '@subwallet/extension-base/utils';
32
32
  import { recalculateGasPrice } from '@subwallet/extension-base/utils/eth';
33
33
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
34
34
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
@@ -61,8 +61,7 @@ export default class KoniState {
61
61
  unsubscriptionMap = {};
62
62
  accountRefStore = new AccountRefStore();
63
63
  externalRequest = {};
64
- balanceMap = {};
65
- balanceSubject = new Subject();
64
+ balanceMap = new BalanceMapImpl();
66
65
  crowdloanMap = generateDefaultCrowdloanMap();
67
66
  crowdloanSubject = new Subject();
68
67
  nftSubject = new Subject();
@@ -186,11 +185,11 @@ export default class KoniState {
186
185
  get authSubjectV2() {
187
186
  return this.requestService.authSubjectV2;
188
187
  }
189
- generateDefaultBalanceMap() {
188
+ generateDefaultBalanceMap(_addresses) {
190
189
  const balanceMap = {};
191
190
  const activeChains = this.chainService.getActiveChainInfoMap();
192
191
  const isAllAccount = isAccountAll(this.keyringService.currentAccount.address);
193
- const addresses = isAllAccount ? Object.keys(this.keyringService.accounts) : [this.keyringService.currentAccount.address];
192
+ const addresses = _addresses || (isAllAccount ? Object.keys(this.keyringService.accounts) : [this.keyringService.currentAccount.address]);
194
193
  addresses.forEach(address => {
195
194
  const temp = {};
196
195
  Object.values(activeChains).forEach(chainInfo => {
@@ -217,6 +216,7 @@ export default class KoniState {
217
216
  await this.chainService.init();
218
217
  this.afterChainServiceInit();
219
218
  await this.migrationService.run();
219
+ this.campaignService.init();
220
220
  this.eventService.emit('chain.ready', true);
221
221
  this.onReady();
222
222
  this.onAccountAdd();
@@ -673,70 +673,29 @@ export default class KoniState {
673
673
  getAllAddresses() {
674
674
  return keyring.getAccounts().map(account => account.address);
675
675
  }
676
- removeInactiveChainBalances(balanceMap) {
677
- const activeBalanceMap = {};
678
- Object.entries(balanceMap).forEach(([address, balances]) => {
679
- activeBalanceMap[address] = {};
680
- Object.entries(balances).forEach(([tokenSlug, item]) => {
681
- const tokenInfo = this.chainService.getAssetBySlug(tokenSlug);
682
- if (tokenInfo) {
683
- const chainInfo = this.chainService.getChainInfoByKey(tokenInfo.originChain);
684
- if (chainInfo && this.getChainStateByKey(chainInfo.slug).active) {
685
- activeBalanceMap[address][tokenSlug] = item;
686
- }
687
- }
688
- });
676
+ async removeInactiveChainBalances() {
677
+ const assetSettings = await this.chainService.getAssetSettings();
678
+ this.balanceMap.removeBalanceItemByFilter(item => {
679
+ return !assetSettings[item.tokenSlug];
689
680
  });
690
- return activeBalanceMap;
691
681
  }
692
- getBalance(reset) {
693
- const activeData = this.removeInactiveChainBalances(this.balanceMap);
682
+ async getBalance(reset) {
683
+ await this.removeInactiveChainBalances();
694
684
  return {
695
- details: activeData,
685
+ details: this.balanceMap.map,
696
686
  reset
697
687
  };
698
688
  }
699
689
  async getStoredBalance(address) {
700
- const items = await this.dbService.stores.balance.getBalanceMapByAddresses(address);
701
- return items || {};
690
+ return await this.dbService.stores.balance.getBalanceMapByAddresses(address);
702
691
  }
692
+ isFirstLoad = true;
703
693
  async handleSwitchAccount(newAddress) {
704
- await Promise.all([this.resetBalanceMap(newAddress), this.resetCrowdloanMap(newAddress)]);
705
- }
706
- async resetBalanceMap(newAddress) {
707
- const defaultData = this.generateDefaultBalanceMap();
708
- let storedData = await this.getStoredBalance(newAddress);
709
- storedData = this.removeInactiveChainBalances(storedData);
710
- const result = {};
711
- for (const [address, balanceInfo] of Object.entries(defaultData)) {
712
- result[address] = {
713
- ...balanceInfo
714
- };
715
- }
716
- for (const [address, balanceInfo] of Object.entries(storedData)) {
717
- if (!result[address]) {
718
- result[address] = {
719
- ...balanceInfo
720
- };
721
- } else {
722
- const temp = {
723
- ...result[address]
724
- };
725
- for (const [slug, item] of Object.entries(balanceInfo)) {
726
- temp[slug] = {
727
- ...item
728
- };
729
- }
730
- result[address] = {
731
- ...temp
732
- };
733
- }
694
+ if (this.isFirstLoad) {
695
+ const backupBalanceData = await this.dbService.getStoredBalance();
696
+ this.balanceMap.updateBalanceItems(backupBalanceData, isAccountAll(newAddress));
734
697
  }
735
- this.balanceMap = {
736
- ...defaultData,
737
- ...storedData
738
- };
739
- this.publishBalance(true);
698
+ await Promise.all([this.resetCrowdloanMap(newAddress), this.removeInactiveChainBalances()]);
740
699
  }
741
700
  async resetCrowdloanMap(newAddress) {
742
701
  const defaultData = generateDefaultCrowdloanMap();
@@ -759,62 +718,35 @@ export default class KoniState {
759
718
  });
760
719
  });
761
720
  }
721
+ balanceUpdateCache = [];
762
722
 
763
723
  /** Note: items must be same tokenSlug */
764
724
  setBalanceItem(items) {
765
725
  if (items.length) {
766
- const tokens = [];
767
- const updates = [];
726
+ const nowTime = new Date().getTime();
768
727
  for (const item of items) {
769
- const address = item.address;
770
- const tokenSlug = item.tokenSlug;
771
- if (!tokens.includes(tokenSlug)) {
772
- tokens.push(tokenSlug);
773
- }
774
- if (!this.balanceMap[address]) {
775
- this.balanceMap[address] = {};
776
- }
777
- const data = {
778
- timestamp: +new Date(),
728
+ const balance = {
729
+ timestamp: nowTime,
779
730
  ...item
780
731
  };
781
- this.balanceMap[address][tokenSlug] = data;
782
- updates.push(data);
732
+ this.balanceUpdateCache.push(balance);
783
733
  }
784
- const isAllAccount = isAccountAll(this.keyringService.currentAccount.address);
785
- if (isAllAccount) {
786
- const address = ALL_ACCOUNT_KEY;
787
- for (const token of tokens) {
788
- const items = [];
789
- for (const [_adr, balanceInfo] of Object.entries(this.balanceMap)) {
790
- if (!isSameAddress(_adr, address)) {
791
- const item = balanceInfo[token];
792
- item && items.push(item);
793
- }
794
- }
795
- const _balance = groupBalance(items, address, token);
796
- const balance = {
797
- timestamp: +new Date(),
798
- ..._balance
799
- };
800
- if (!this.balanceMap[address]) {
801
- this.balanceMap[address] = {};
802
- }
803
- this.balanceMap[address][token] = balance;
804
- updates.push(balance);
734
+ addLazy('updateBalanceStore', () => {
735
+ const isAllAccount = isAccountAll(this.keyringService.currentAccount.address);
736
+ this.balanceMap.updateBalanceItems(this.balanceUpdateCache, isAllAccount);
737
+ if (isAllAccount) {
738
+ this.balanceUpdateCache = [...this.balanceUpdateCache, ...Object.values(this.balanceMap.map[ALL_ACCOUNT_KEY])];
805
739
  }
806
- }
807
- this.updateBalanceStore(updates);
808
- this.lazyNext('setBalanceItem', () => {
809
- this.publishBalance();
810
- });
740
+ this.updateBalanceStore(this.balanceUpdateCache);
741
+ this.balanceUpdateCache = [];
742
+ }, 300, 1800);
811
743
  }
812
744
  }
813
745
  updateBalanceStore(items) {
814
746
  this.dbService.updateBulkBalanceStore(items).catch(e => this.logger.warn(e));
815
747
  }
816
748
  subscribeBalance() {
817
- return this.balanceSubject;
749
+ return this.balanceMap.mapSubject;
818
750
  }
819
751
  getCrowdloan(reset) {
820
752
  return {
@@ -1064,9 +996,6 @@ export default class KoniState {
1064
996
  async resumeAllNetworks() {
1065
997
  return this.chainService.resumeAllChainApis();
1066
998
  }
1067
- publishBalance(reset) {
1068
- this.balanceSubject.next(this.getBalance(reset));
1069
- }
1070
999
  publishCrowdloan(reset) {
1071
1000
  this.crowdloanSubject.next(this.getCrowdloan(reset));
1072
1001
  }
@@ -1593,6 +1522,7 @@ export default class KoniState {
1593
1522
  // Remove Balance
1594
1523
  stores.balance.removeAllByAddress(address).catch(console.error);
1595
1524
  stores.balance.removeAllByAddress(ALL_ACCOUNT_KEY).catch(console.error);
1525
+ this.balanceMap.removeBalanceItems([address, ALL_ACCOUNT_KEY]);
1596
1526
 
1597
1527
  // Remove NFT
1598
1528
  stores.nft.deleteNftByAddress([address]).catch(console.error);
@@ -50,7 +50,7 @@ export class KoniSubscription {
50
50
  }
51
51
  async start() {
52
52
  var _this$state$keyringSe;
53
- await Promise.all([this.state.eventService.waitKeyringReady, this.state.eventService.waitAssetReady]);
53
+ await Promise.all([this.state.eventService.waitCryptoReady, this.state.eventService.waitKeyringReady, this.state.eventService.waitAssetReady]);
54
54
  const currentAddress = (_this$state$keyringSe = this.state.keyringService.currentAccount) === null || _this$state$keyringSe === void 0 ? void 0 : _this$state$keyringSe.address;
55
55
  if (currentAddress) {
56
56
  this.subscribeBalancesAndCrowdloans(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
@@ -70,7 +70,7 @@ export class KoniSubscription {
70
70
  this.subscribeBalancesAndCrowdloans(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
71
71
  this.subscribeStakingOnChain(address, serviceInfo.chainApiMap.substrate);
72
72
  };
73
- this.state.eventService.onLazy(this.eventHandler);
73
+ this.state.eventService.onLazy(this.eventHandler.bind(this));
74
74
  }
75
75
  async stop() {
76
76
  if (this.eventHandler) {
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.1.25-0",
20
+ "version": "1.1.26-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -510,6 +510,11 @@
510
510
  "require": "./cjs/services/balance-service/index.js",
511
511
  "default": "./services/balance-service/index.js"
512
512
  },
513
+ "./services/balance-service/BalanceMapImpl": {
514
+ "types": "./services/balance-service/BalanceMapImpl.d.ts",
515
+ "require": "./cjs/services/balance-service/BalanceMapImpl.js",
516
+ "default": "./services/balance-service/BalanceMapImpl.js"
517
+ },
513
518
  "./services/balance-service/helpers/group": {
514
519
  "types": "./services/balance-service/helpers/group.d.ts",
515
520
  "require": "./cjs/services/balance-service/helpers/group.js",
@@ -838,6 +843,16 @@
838
843
  "require": "./cjs/services/migration-service/scripts/providers/MigrateProvidersV1M1P24.js",
839
844
  "default": "./services/migration-service/scripts/providers/MigrateProvidersV1M1P24.js"
840
845
  },
846
+ "./services/migration-service/scripts/tokens/MigratePolygonUSDCProvider": {
847
+ "types": "./services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.d.ts",
848
+ "require": "./cjs/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js",
849
+ "default": "./services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js"
850
+ },
851
+ "./services/migration-service/scripts/tokens/MigrateToken": {
852
+ "types": "./services/migration-service/scripts/tokens/MigrateToken.d.ts",
853
+ "require": "./cjs/services/migration-service/scripts/tokens/MigrateToken.js",
854
+ "default": "./services/migration-service/scripts/tokens/MigrateToken.js"
855
+ },
841
856
  "./services/notification-service/NotificationService": {
842
857
  "types": "./services/notification-service/NotificationService.d.ts",
843
858
  "require": "./cjs/services/notification-service/NotificationService.js",
@@ -1153,6 +1168,11 @@
1153
1168
  "require": "./cjs/signers/web3/QrSigner.js",
1154
1169
  "default": "./signers/web3/QrSigner.js"
1155
1170
  },
1171
+ "./storage": {
1172
+ "types": "./storage/index.d.ts",
1173
+ "require": "./cjs/storage/index.js",
1174
+ "default": "./storage/index.js"
1175
+ },
1156
1176
  "./stores": {
1157
1177
  "types": "./stores/index.d.ts",
1158
1178
  "require": "./cjs/stores/index.js",
@@ -1346,34 +1366,34 @@
1346
1366
  "@metamask/safe-event-emitter": "^2.0.0",
1347
1367
  "@metaverse-network-sdk/type-definitions": "^0.0.1-13",
1348
1368
  "@oak-foundation/types": "^0.0.23",
1349
- "@polkadot/api": "^10.9.1",
1350
- "@polkadot/api-contract": "^10.9.1",
1351
- "@polkadot/api-derive": "^10.9.1",
1352
- "@polkadot/apps-config": "^0.132.1",
1353
- "@polkadot/hw-ledger": "^12.3.2",
1354
- "@polkadot/networks": "^12.3.2",
1355
- "@polkadot/phishing": "^0.21.5",
1356
- "@polkadot/rpc-provider": "^10.9.1",
1357
- "@polkadot/types": "^10.9.1",
1358
- "@polkadot/types-augment": "^10.9.1",
1359
- "@polkadot/ui-settings": "^3.5.1",
1360
- "@polkadot/util": "^12.3.2",
1361
- "@polkadot/util-crypto": "^12.3.2",
1369
+ "@polkadot/api": "^10.11.1",
1370
+ "@polkadot/api-contract": "^10.11.1",
1371
+ "@polkadot/api-derive": "^10.11.1",
1372
+ "@polkadot/apps-config": "^0.133.1",
1373
+ "@polkadot/hw-ledger": "^12.6.1",
1374
+ "@polkadot/networks": "^12.6.1",
1375
+ "@polkadot/phishing": "^0.22.1",
1376
+ "@polkadot/rpc-provider": "^10.11.1",
1377
+ "@polkadot/types": "^10.11.1",
1378
+ "@polkadot/types-augment": "^10.11.1",
1379
+ "@polkadot/ui-settings": "^3.6.4",
1380
+ "@polkadot/util": "^12.6.1",
1381
+ "@polkadot/util-crypto": "^12.6.1",
1362
1382
  "@reduxjs/toolkit": "^1.9.1",
1363
1383
  "@sora-substrate/type-definitions": "^1.17.7",
1364
1384
  "@substrate/connect": "^0.7.26",
1365
- "@subwallet/chain-list": "0.2.28",
1366
- "@subwallet/extension-base": "^1.1.25-0",
1367
- "@subwallet/extension-chains": "^1.1.25-0",
1368
- "@subwallet/extension-dapp": "^1.1.25-0",
1369
- "@subwallet/extension-inject": "^1.1.25-0",
1385
+ "@subwallet/chain-list": "^0.2.30",
1386
+ "@subwallet/extension-base": "^1.1.26-0",
1387
+ "@subwallet/extension-chains": "^1.1.26-0",
1388
+ "@subwallet/extension-dapp": "^1.1.26-0",
1389
+ "@subwallet/extension-inject": "^1.1.26-0",
1370
1390
  "@subwallet/keyring": "^0.1.1",
1371
1391
  "@subwallet/ui-keyring": "^0.1.1",
1372
1392
  "@walletconnect/sign-client": "^2.8.4",
1373
1393
  "@walletconnect/types": "^2.8.4",
1374
1394
  "@walletconnect/utils": "^2.8.4",
1375
1395
  "avail-js-sdk": "^0.0.10",
1376
- "axios": "^1.2.1",
1396
+ "axios": "^1.6.2",
1377
1397
  "bignumber.js": "^9.1.1",
1378
1398
  "bn.js": "^5.2.1",
1379
1399
  "bowser": "^2.11.0",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.1.25-0'
10
+ version: '1.1.26-0'
11
11
  };
@@ -0,0 +1,17 @@
1
+ import { BalanceInfo, BalanceItem, BalanceMap } from '@subwallet/extension-base/types';
2
+ import { BehaviorSubject } from 'rxjs';
3
+ export declare class BalanceMapImpl {
4
+ private _map;
5
+ private _mapSubject;
6
+ constructor(_map?: BalanceMap);
7
+ get map(): BalanceMap;
8
+ get mapSubject(): BehaviorSubject<BalanceMap>;
9
+ setData(map: BalanceMap): void;
10
+ setAddressData(address: string, data: BalanceInfo): void;
11
+ triggerChange(computeAll?: boolean): void;
12
+ updateBalanceItem(balanceItem: BalanceItem, trigger?: boolean): void;
13
+ updateBalanceItems(balanceItems: BalanceItem[], computeAll?: boolean): void;
14
+ removeBalanceItemByFilter(filter: (balanceItem: BalanceItem) => boolean): void;
15
+ computeAllAccountBalance(): void;
16
+ removeBalanceItems(addresses?: string[], tokenSlugs?: string[]): void;
17
+ }
@@ -0,0 +1,104 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
+ import { groupBalance } from '@subwallet/extension-base/services/balance-service/helpers/group';
6
+ import { isAccountAll } from '@subwallet/extension-base/utils';
7
+ import { BehaviorSubject } from 'rxjs';
8
+ export class BalanceMapImpl {
9
+ constructor(_map = {}) {
10
+ this._map = _map;
11
+ this._mapSubject = new BehaviorSubject(_map);
12
+ }
13
+ get map() {
14
+ return this._mapSubject.getValue();
15
+ }
16
+ get mapSubject() {
17
+ return this._mapSubject;
18
+ }
19
+ setData(map) {
20
+ this._map = map;
21
+ this.triggerChange();
22
+ }
23
+ setAddressData(address, data) {
24
+ this._map[address] = data;
25
+ this.triggerChange();
26
+ }
27
+ triggerChange(computeAll) {
28
+ if (computeAll) {
29
+ this.computeAllAccountBalance();
30
+ }
31
+ this._mapSubject.next(this._map);
32
+ }
33
+ updateBalanceItem(balanceItem, trigger = false) {
34
+ const {
35
+ address,
36
+ tokenSlug
37
+ } = balanceItem;
38
+ if (!address.startsWith('5') && !address.startsWith('0x')) {
39
+ console.log('check address', address);
40
+ }
41
+ if (!this._map[address]) {
42
+ this._map[address] = {};
43
+ }
44
+ this._map[address][tokenSlug] = balanceItem;
45
+ trigger && this.triggerChange();
46
+ }
47
+ updateBalanceItems(balanceItems, computeAll) {
48
+ balanceItems.forEach(balanceItem => {
49
+ this.updateBalanceItem(balanceItem);
50
+ });
51
+ this.triggerChange(computeAll);
52
+ }
53
+ removeBalanceItemByFilter(filter) {
54
+ Object.keys(this._map).forEach(address => {
55
+ Object.keys(this._map[address]).forEach(tokenSlug => {
56
+ if (filter(this._map[address][tokenSlug])) {
57
+ delete this._map[address][tokenSlug];
58
+ }
59
+ });
60
+ });
61
+ this.triggerChange();
62
+ }
63
+ computeAllAccountBalance() {
64
+ const allAccountBalanceInfo = {};
65
+ const allAccountBalance = {};
66
+ Object.keys(this._map).filter(a => !isAccountAll(a)).forEach(address => {
67
+ Object.keys(this._map[address]).forEach(tokenSlug => {
68
+ if (!allAccountBalance[tokenSlug]) {
69
+ allAccountBalance[tokenSlug] = [];
70
+ }
71
+ allAccountBalance[tokenSlug].push(this._map[address][tokenSlug]);
72
+ });
73
+ });
74
+ Object.entries(allAccountBalance).forEach(([tokenSlug, balanceItems]) => {
75
+ allAccountBalanceInfo[tokenSlug] = groupBalance(balanceItems, ALL_ACCOUNT_KEY, tokenSlug);
76
+ });
77
+ this._map[ALL_ACCOUNT_KEY] = allAccountBalanceInfo;
78
+ }
79
+
80
+ // Remove balance items buy address or tokenSlug
81
+ removeBalanceItems(addresses, tokenSlugs) {
82
+ // If addresses is empty, remove all
83
+ if (addresses && tokenSlugs) {
84
+ addresses.forEach(address => {
85
+ tokenSlugs.forEach(tokenSlug => {
86
+ this._map[address] && this._map[address][tokenSlug] && delete this._map[address][tokenSlug];
87
+ });
88
+ });
89
+ } else if (addresses && !tokenSlugs) {
90
+ addresses.forEach(address => {
91
+ this._map[address] && delete this._map[address];
92
+ });
93
+ } else if (!addresses && tokenSlugs) {
94
+ Object.keys(this._map).forEach(address => {
95
+ tokenSlugs.forEach(tokenSlug => {
96
+ this._map[address][tokenSlug] && delete this._map[address][tokenSlug];
97
+ });
98
+ });
99
+ } else {
100
+ this._map = {};
101
+ }
102
+ this.triggerChange();
103
+ }
104
+ }
@@ -3,6 +3,7 @@ import KoniState from '@subwallet/extension-base/koni/background/handlers/State'
3
3
  export default class CampaignService {
4
4
  #private;
5
5
  constructor(state: KoniState);
6
+ init(): void;
6
7
  private fetchCampaign;
7
8
  private runCampaign;
8
9
  getProcessingCampaign(): Promise<CampaignData[]>;
@@ -9,6 +9,8 @@ export default class CampaignService {
9
9
  #state;
10
10
  constructor(state) {
11
11
  this.#state = state;
12
+ }
13
+ init() {
12
14
  this.fetchCampaign().catch(e => {
13
15
  console.error('Error on fetch campaigns', e);
14
16
  });
@@ -45,6 +45,7 @@ export declare const _STAKING_CHAIN_GROUP: {
45
45
  ternoa: string[];
46
46
  };
47
47
  export declare const _STAKING_ERA_LENGTH_MAP: Record<string, number>;
48
+ export declare const _EXPECTED_BLOCK_TIME: Record<string, number>;
48
49
  export declare const _PARACHAIN_INFLATION_DISTRIBUTION: Record<string, Record<string, number>>;
49
50
  export interface _SubstrateInflationParams {
50
51
  auctionAdjust: number;