@subwallet/extension-base 1.0.1 → 1.0.2-1b

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 (220) hide show
  1. package/background/KoniTypes.d.ts +25 -36
  2. package/background/KoniTypes.js +12 -7
  3. package/background/errors/TransactionError.js +21 -1
  4. package/cjs/background/KoniTypes.js +14 -8
  5. package/cjs/background/errors/TransactionError.js +20 -0
  6. package/cjs/constants/index.js +13 -28
  7. package/cjs/koni/api/dotsama/balance.js +60 -224
  8. package/cjs/koni/api/dotsama/transfer.js +30 -29
  9. package/cjs/koni/api/nft/acala_nft/index.js +4 -1
  10. package/cjs/koni/api/nft/bit.country/index.js +4 -1
  11. package/cjs/koni/api/nft/evm_nft/index.js +7 -3
  12. package/cjs/koni/api/nft/index.js +3 -6
  13. package/cjs/koni/api/nft/karura_nft/index.js +4 -1
  14. package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
  15. package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
  16. package/cjs/koni/api/nft/unique_nft/index.js +6 -1
  17. package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
  18. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  19. package/cjs/koni/api/staking/bonding/amplitude.js +18 -10
  20. package/cjs/koni/api/staking/bonding/astar.js +37 -238
  21. package/cjs/koni/api/staking/bonding/index.js +26 -14
  22. package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
  23. package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
  24. package/cjs/koni/api/staking/bonding/utils.js +55 -10
  25. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  26. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  27. package/cjs/koni/api/xcm/index.js +0 -111
  28. package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +3 -5
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +179 -77
  33. package/cjs/koni/background/handlers/Extension.js +231 -195
  34. package/cjs/koni/background/handlers/State.js +147 -111
  35. package/cjs/koni/background/handlers/Tabs.js +48 -39
  36. package/cjs/koni/background/subscription.js +64 -56
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/page/index.js +5 -0
  39. package/cjs/services/chain-service/constants.js +1 -11
  40. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  41. package/cjs/services/chain-service/handler/light-client/index.js +2 -0
  42. package/cjs/services/chain-service/index.js +39 -6
  43. package/cjs/services/chain-service/utils.js +4 -0
  44. package/cjs/services/event-service/index.js +75 -0
  45. package/cjs/services/event-service/types.js +11 -0
  46. package/cjs/services/history-service/index.js +46 -21
  47. package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
  48. package/cjs/services/keyring-service/index.js +101 -0
  49. package/cjs/services/migration-service/index.js +13 -10
  50. package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
  51. package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
  52. package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
  53. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
  54. package/cjs/services/migration-service/scripts/index.js +13 -4
  55. package/cjs/services/price-service/coingecko.js +15 -3
  56. package/cjs/services/price-service/index.js +15 -18
  57. package/cjs/services/request-service/constants.js +8 -2
  58. package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
  59. package/cjs/services/request-service/index.js +3 -0
  60. package/cjs/services/storage-service/DatabaseService.js +53 -34
  61. package/cjs/services/storage-service/databases/index.js +1 -1
  62. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  63. package/cjs/services/storage-service/db-stores/Nft.js +8 -18
  64. package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
  65. package/cjs/services/subscan-service/index.js +107 -0
  66. package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
  67. package/cjs/services/subscan-service/types.js +1 -0
  68. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  69. package/cjs/services/transaction-service/index.js +66 -22
  70. package/cjs/services/transaction-service/utils.js +4 -6
  71. package/cjs/utils/address.js +9 -1
  72. package/cjs/utils/index.js +30 -26
  73. package/constants/index.d.ts +8 -13
  74. package/constants/index.js +8 -13
  75. package/koni/api/dotsama/balance.d.ts +0 -1
  76. package/koni/api/dotsama/balance.js +33 -197
  77. package/koni/api/dotsama/transfer.js +5 -4
  78. package/koni/api/nft/acala_nft/index.js +3 -1
  79. package/koni/api/nft/bit.country/index.js +3 -1
  80. package/koni/api/nft/evm_nft/index.js +6 -3
  81. package/koni/api/nft/index.d.ts +1 -2
  82. package/koni/api/nft/index.js +3 -6
  83. package/koni/api/nft/karura_nft/index.js +3 -1
  84. package/koni/api/nft/nft.d.ts +1 -0
  85. package/koni/api/nft/rmrk_nft/index.js +8 -1
  86. package/koni/api/nft/statemine_nft/index.js +3 -1
  87. package/koni/api/nft/unique_nft/index.js +5 -1
  88. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  89. package/koni/api/nft/wasm_nft/index.js +167 -109
  90. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  91. package/koni/api/nft/wasm_nft/utils.js +7 -5
  92. package/koni/api/staking/bonding/amplitude.d.ts +1 -2
  93. package/koni/api/staking/bonding/amplitude.js +22 -13
  94. package/koni/api/staking/bonding/astar.d.ts +2 -11
  95. package/koni/api/staking/bonding/astar.js +39 -231
  96. package/koni/api/staking/bonding/index.d.ts +5 -2
  97. package/koni/api/staking/bonding/index.js +27 -17
  98. package/koni/api/staking/bonding/paraChain.d.ts +4 -1
  99. package/koni/api/staking/bonding/paraChain.js +101 -14
  100. package/koni/api/staking/bonding/relayChain.d.ts +6 -2
  101. package/koni/api/staking/bonding/relayChain.js +172 -17
  102. package/koni/api/staking/bonding/utils.d.ts +15 -2
  103. package/koni/api/staking/bonding/utils.js +53 -11
  104. package/koni/api/tokens/wasm/index.js +5 -4
  105. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  106. package/koni/api/tokens/wasm/utils.js +54 -0
  107. package/koni/api/xcm/index.js +1 -112
  108. package/koni/api/xcm/polkadotXcm.js +3 -3
  109. package/koni/api/xcm/utils.d.ts +5 -6
  110. package/koni/api/xcm/utils.js +15 -10
  111. package/koni/api/xcm/xTokens.js +5 -7
  112. package/koni/api/xcm/xcmPallet.js +10 -9
  113. package/koni/background/cron.d.ts +6 -1
  114. package/koni/background/cron.js +179 -76
  115. package/koni/background/handlers/Extension.d.ts +2 -2
  116. package/koni/background/handlers/Extension.js +161 -125
  117. package/koni/background/handlers/State.d.ts +21 -20
  118. package/koni/background/handlers/State.js +144 -111
  119. package/koni/background/handlers/Tabs.js +30 -20
  120. package/koni/background/subscription.d.ts +1 -1
  121. package/koni/background/subscription.js +64 -58
  122. package/package.json +63 -18
  123. package/packageInfo.js +1 -1
  124. package/page/index.d.ts +2 -0
  125. package/page/index.js +4 -0
  126. package/services/chain-service/constants.d.ts +0 -1
  127. package/services/chain-service/constants.js +0 -9
  128. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  129. package/services/chain-service/handler/light-client/index.d.ts +17 -1
  130. package/services/chain-service/handler/light-client/index.js +1 -1
  131. package/services/chain-service/helper/psp22_abi.json +1041 -881
  132. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  133. package/services/chain-service/index.d.ts +6 -4
  134. package/services/chain-service/index.js +40 -9
  135. package/services/chain-service/utils.d.ts +1 -0
  136. package/services/chain-service/utils.js +3 -0
  137. package/services/event-service/index.d.ts +22 -0
  138. package/services/event-service/index.js +63 -0
  139. package/services/event-service/types.d.ts +28 -0
  140. package/services/event-service/types.js +4 -0
  141. package/services/history-service/index.d.ts +5 -3
  142. package/services/history-service/index.js +46 -21
  143. package/services/history-service/subsquid-multi-chain-history.js +22 -13
  144. package/services/keyring-service/index.d.ts +19 -0
  145. package/services/keyring-service/index.js +93 -0
  146. package/services/migration-service/index.js +11 -9
  147. package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
  148. package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
  149. package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
  150. package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
  151. package/services/migration-service/scripts/MigrateSettings.js +23 -0
  152. package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
  153. package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
  154. package/services/migration-service/scripts/index.d.ts +1 -0
  155. package/services/migration-service/scripts/index.js +10 -3
  156. package/services/price-service/coingecko.js +15 -3
  157. package/services/price-service/index.d.ts +5 -3
  158. package/services/price-service/index.js +15 -18
  159. package/services/request-service/constants.d.ts +1 -0
  160. package/services/request-service/constants.js +6 -1
  161. package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
  162. package/services/request-service/handler/AuthRequestHandler.js +44 -13
  163. package/services/request-service/index.d.ts +7 -1
  164. package/services/request-service/index.js +3 -0
  165. package/services/storage-service/DatabaseService.d.ts +1 -0
  166. package/services/storage-service/DatabaseService.js +53 -34
  167. package/services/storage-service/databases/index.js +1 -1
  168. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
  169. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  170. package/services/storage-service/db-stores/Nft.d.ts +3 -3
  171. package/services/storage-service/db-stores/Nft.js +8 -17
  172. package/services/storage-service/db-stores/Transaction.js +10 -7
  173. package/services/subscan-service/index.d.ts +20 -0
  174. package/services/subscan-service/index.js +99 -0
  175. package/services/subscan-service/subscan-chain-map.d.ts +5 -0
  176. package/services/subscan-service/subscan-chain-map.js +63 -0
  177. package/services/subscan-service/types.d.ts +27 -0
  178. package/services/subscan-service/types.js +1 -0
  179. package/services/transaction-service/event-parser/index.d.ts +2 -2
  180. package/services/transaction-service/event-parser/index.js +21 -49
  181. package/services/transaction-service/index.d.ts +4 -2
  182. package/services/transaction-service/index.js +66 -22
  183. package/services/transaction-service/utils.js +5 -6
  184. package/utils/address.d.ts +1 -0
  185. package/utils/address.js +9 -2
  186. package/utils/index.d.ts +2 -1
  187. package/utils/index.js +26 -23
  188. package/cjs/background/errors/EvmRpcError.js +0 -21
  189. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  190. package/cjs/constants/ethereum.js +0 -19
  191. package/cjs/errors/SubWalletProviderError.js +0 -17
  192. package/cjs/koni/api/xcm/astar.js +0 -160
  193. package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
  194. package/cjs/koni/api/xcm/statemintXcm.js +0 -197
  195. package/cjs/koni/api/xcm/substrateXcm.js +0 -213
  196. package/cjs/koni/migration/Base.js +0 -20
  197. package/cjs/koni/migration/index.js +0 -45
  198. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
  199. package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
  200. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
  201. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
  202. package/cjs/koni/migration/scripts/index.js +0 -22
  203. package/cjs/koni/page/index.js +0 -16
  204. package/cjs/services/asset-service/index.js +0 -91
  205. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
  206. package/cjs/stores/Balance.js +0 -18
  207. package/cjs/stores/Crowdloan.js +0 -18
  208. package/cjs/stores/CustomEvmToken.js +0 -18
  209. package/cjs/stores/NetworkMap.js +0 -18
  210. package/cjs/stores/Nft.js +0 -18
  211. package/cjs/stores/NftCollection.js +0 -18
  212. package/cjs/stores/Price.js +0 -18
  213. package/cjs/stores/Staking.js +0 -18
  214. package/cjs/stores/StakingReward.js +0 -18
  215. package/cjs/utils/eth/parseTransactionData.js +0 -284
  216. package/koni/page/index.d.ts +0 -2
  217. package/koni/page/index.js +0 -9
  218. /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
  219. /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
  220. /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
@@ -1,11 +1,13 @@
1
1
  /// <reference types="chrome" />
2
2
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
3
- import { AddTokenRequestExternal, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, BrowserConfirmationType, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, KeyringState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, ThemeNames, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
3
+ import { AddTokenRequestExternal, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, BrowserConfirmationType, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, ThemeNames, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
4
4
  import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
5
5
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
6
6
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
7
7
  import { _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest } from '@subwallet/extension-base/services/chain-service/types';
8
+ import { EventService } from '@subwallet/extension-base/services/event-service';
8
9
  import { HistoryService } from '@subwallet/extension-base/services/history-service';
10
+ import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
9
11
  import MigrationService from '@subwallet/extension-base/services/migration-service';
10
12
  import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
11
13
  import { PriceService } from '@subwallet/extension-base/services/price-service';
@@ -13,6 +15,7 @@ import RequestService from '@subwallet/extension-base/services/request-service';
13
15
  import { AuthUrls, MetaRequest, SignRequest } from '@subwallet/extension-base/services/request-service/types';
14
16
  import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
15
17
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
18
+ import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
16
19
  import TransactionService from '@subwallet/extension-base/services/transaction-service';
17
20
  import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
18
21
  import SimpleKeyring from 'eth-simple-keyring';
@@ -26,12 +29,8 @@ export default class KoniState {
26
29
  private injectedProviders;
27
30
  private readonly providers;
28
31
  private readonly unsubscriptionMap;
29
- private readonly currentAccountStore;
30
32
  private readonly accountRefStore;
31
- private readonly keyringStateSubject;
32
33
  private externalRequest;
33
- private keyringState;
34
- private serviceInfoSubject;
35
34
  private balanceMap;
36
35
  private balanceSubject;
37
36
  private crowdloanMap;
@@ -44,6 +43,8 @@ export default class KoniState {
44
43
  private stakingRewardState;
45
44
  private lazyMap;
46
45
  readonly notificationService: NotificationService;
46
+ readonly eventService: EventService;
47
+ readonly keyringService: KeyringService;
47
48
  readonly chainService: ChainService;
48
49
  readonly dbService: DatabaseService;
49
50
  private cron;
@@ -57,6 +58,7 @@ export default class KoniState {
57
58
  readonly priceService: PriceService;
58
59
  readonly balanceService: BalanceService;
59
60
  readonly migrationService: MigrationService;
61
+ readonly subscanService: SubscanService;
60
62
  constructor(providers?: Providers);
61
63
  get knownMetadata(): MetadataDef[];
62
64
  injectMetadata(url: string, request: MetadataDef): Promise<boolean>;
@@ -76,9 +78,7 @@ export default class KoniState {
76
78
  private startSubscription;
77
79
  onReady(): void;
78
80
  isReady(): boolean;
79
- getKeyringState(): KeyringState;
80
- subscribeKeyringState(): Subject<KeyringState>;
81
- setKeyringState(data: KeyringState, callback?: () => void): void;
81
+ updateKeyringState(isReady?: boolean, callback?: () => void): void;
82
82
  private lazyNext;
83
83
  getAuthRequestV2(id: string): AuthRequestV2;
84
84
  setAuthorize(data: AuthUrls, callback?: () => void): void;
@@ -106,10 +106,10 @@ export default class KoniState {
106
106
  setNftCollection(network: string, data: NftCollection, callback?: (data: NftCollection) => void): void;
107
107
  getNftCollection(): import("dexie").PromiseExtended<NftCollection[]>;
108
108
  subscribeNftCollection(): import("dexie").Observable<NftCollection[]>;
109
- resetNft(newAddress: string): Promise<void>;
109
+ resetNft(newAddress: string): void;
110
110
  updateNftData(network: string, nftData: NftItem, address: string, callback?: (nftData: NftItem) => void): void;
111
- removeNfts(chain: string, address: string, collectionId: string, nftIds: string[]): import("dexie").PromiseExtended<number>;
112
111
  deleteNftCollection(chain: string, collectionId: string): Promise<void>;
112
+ cleanUpNfts(chain: string, owner: string, collectionId: string, nftIds: string[]): void;
113
113
  getNft(): Promise<NftJson | undefined>;
114
114
  subscribeNft(): Subject<NftJson>;
115
115
  resetStakingReward(): void;
@@ -120,7 +120,6 @@ export default class KoniState {
120
120
  removeAccountRef(address: string, callback: () => void): void;
121
121
  getStakingReward(update: (value: StakingRewardJson) => void): void;
122
122
  subscribeStakingReward(): Subject<StakingRewardJson>;
123
- getCurrentAccount(update: (value: CurrentAccountInfo) => void): void;
124
123
  setCurrentAccount(data: CurrentAccountInfo, callback?: () => void): void;
125
124
  setAccountTie(address: string, genesisHash: string | null): boolean;
126
125
  switchEvmNetworkByUrl(shortenUrl: string, networkKey: string): Promise<void>;
@@ -135,17 +134,16 @@ export default class KoniState {
135
134
  setBrowserConfirmationType(browserConfirmationType: BrowserConfirmationType, callback?: (settingData: UiSettings) => void): void;
136
135
  setCamera(value: boolean): void;
137
136
  subscribeSettingsSubject(): Subject<RequestSettingsType>;
138
- subscribeCurrentAccount(): Subject<CurrentAccountInfo>;
139
- getAccountAddress(): Promise<string | null | undefined>;
140
- getDecodedAddresses(address?: string): Promise<string[]>;
137
+ getAccountAddress(): string | null;
138
+ getDecodedAddresses(address?: string): string[];
141
139
  getAllAddresses(): string[];
142
140
  private removeInactiveChainBalances;
143
141
  getBalance(reset?: boolean): BalanceJson;
144
142
  getStoredBalance(address: string): Promise<Record<string, BalanceItem>>;
145
- switchAccount(newAddress: string): Promise<void>;
143
+ handleSwitchAccount(newAddress: string): Promise<void>;
146
144
  resetBalanceMap(newAddress: string): Promise<void>;
147
145
  resetCrowdloanMap(newAddress: string): Promise<void>;
148
- resetStaking(newAddress: string): Promise<void>;
146
+ resetStaking(newAddress: string): void;
149
147
  setBalanceItem(tokenSlug: string, item: BalanceItem): void;
150
148
  private updateBalanceStore;
151
149
  subscribeBalance(): Subject<BalanceJson>;
@@ -154,7 +152,6 @@ export default class KoniState {
154
152
  setCrowdloanItem(networkKey: string, item: CrowdloanItem): void;
155
153
  private updateCrowdloanStore;
156
154
  subscribeCrowdloan(): Subject<CrowdloanJson>;
157
- getAllPriceIds(): string[];
158
155
  getSmartContractNfts(): _ChainAsset[];
159
156
  getChainInfoMap(): Record<string, _ChainInfo>;
160
157
  getChainStateMap(): Record<string, _ChainState>;
@@ -183,7 +180,6 @@ export default class KoniState {
183
180
  disableChain(chainSlug: string): Promise<boolean>;
184
181
  enableChain(chainSlug: string, enableTokens?: boolean): Promise<boolean>;
185
182
  resetDefaultChains(): boolean;
186
- updateNetworkStatus(networkKey: string, status: _ChainConnectionStatus): void;
187
183
  getSubstrateApiMap(): Record<string, import("@subwallet/extension-base/services/chain-service/types")._SubstrateApi>;
188
184
  getSubstrateApi(networkKey: string): import("@subwallet/extension-base/services/chain-service/types")._SubstrateApi;
189
185
  getEvmApiMap(): Record<string, import("@subwallet/extension-base/services/chain-service/types")._EvmApi>;
@@ -191,8 +187,7 @@ export default class KoniState {
191
187
  getApiMap(): ApiMap;
192
188
  refreshSubstrateApi(key: string): boolean;
193
189
  refreshWeb3Api(key: string): void;
194
- subscribeServiceInfo(): Subject<ServiceInfo>;
195
- updateServiceInfo(): void;
190
+ getServiceInfo(): ServiceInfo;
196
191
  getExternalRequestMap(): Record<string, ExternalRequestPromise>;
197
192
  setExternalRequestMap(id: string, value: ExternalRequestPromise): void;
198
193
  getExternalRequest(id: string): ExternalRequestPromise;
@@ -220,5 +215,11 @@ export default class KoniState {
220
215
  wakeup(): Promise<void>;
221
216
  cancelSubscription(id: string): boolean;
222
217
  createUnsubscriptionHandle(id: string, unsubscribe: () => void): void;
218
+ updateChainConnectionStatus(chain: string, status: _ChainConnectionStatus): void;
219
+ autoEnableChains(addresses: string[]): Promise<void>;
220
+ onAccountAdd(): void;
221
+ onAccountRemove(): void;
222
+ reloadNft(): Promise<boolean>;
223
+ reloadStaking(): Promise<boolean>;
223
224
  }
224
225
  export {};
@@ -11,15 +11,18 @@ import { BalanceService } from '@subwallet/extension-base/services/balance-servi
11
11
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
12
12
  import { _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
13
13
  import { _getEvmChainId, _getSubstrateGenesisHash, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _isSubstrateParachain, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
14
+ import { EventService } from '@subwallet/extension-base/services/event-service';
14
15
  import { HistoryService } from '@subwallet/extension-base/services/history-service';
16
+ import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
15
17
  import MigrationService from '@subwallet/extension-base/services/migration-service';
16
18
  import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
17
19
  import { PriceService } from '@subwallet/extension-base/services/price-service';
18
20
  import RequestService from '@subwallet/extension-base/services/request-service';
19
21
  import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
20
22
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
23
+ import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
24
+ import { SUBSCAN_CHAIN_MAP_REVERSE } from '@subwallet/extension-base/services/subscan-service/subscan-chain-map';
21
25
  import TransactionService from '@subwallet/extension-base/services/transaction-service';
22
- import { CurrentAccountStore } from '@subwallet/extension-base/stores';
23
26
  import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
24
27
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
25
28
  import { decodePair } from '@subwallet/keyring/pair/decode';
@@ -54,16 +57,8 @@ const generateDefaultCrowdloanMap = () => {
54
57
  export default class KoniState {
55
58
  injectedProviders = new Map();
56
59
  unsubscriptionMap = {};
57
- currentAccountStore = new CurrentAccountStore();
58
60
  accountRefStore = new AccountRefStore();
59
- keyringStateSubject = new Subject();
60
61
  externalRequest = {};
61
- keyringState = {
62
- isReady: false,
63
- isLocked: true,
64
- hasMasterPassword: false
65
- };
66
- serviceInfoSubject = new Subject();
67
62
  balanceMap = {};
68
63
  balanceSubject = new Subject();
69
64
  crowdloanMap = generateDefaultCrowdloanMap();
@@ -80,18 +75,20 @@ export default class KoniState {
80
75
  };
81
76
  lazyMap = {};
82
77
  ready = false;
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
78
  constructor(providers = {}) {
85
79
  this.providers = providers;
86
80
  this.dbService = new DatabaseService();
81
+ this.eventService = new EventService();
82
+ this.subscanService = new SubscanService();
83
+ this.keyringService = new KeyringService(this.eventService);
87
84
  this.notificationService = new NotificationService();
88
- this.chainService = new ChainService(this.dbService);
85
+ this.chainService = new ChainService(this.dbService, this.eventService);
89
86
  this.settingService = new SettingService();
90
87
  this.requestService = new RequestService(this.chainService, this.settingService);
91
- this.priceService = new PriceService(this.serviceInfoSubject, this.dbService, this.chainService);
88
+ this.priceService = new PriceService(this.dbService, this.eventService, this.chainService);
92
89
  this.balanceService = new BalanceService(this.chainService);
93
- this.historyService = new HistoryService(this.dbService, this.chainService);
94
- this.transactionService = new TransactionService(this.chainService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
90
+ this.historyService = new HistoryService(this.dbService, this.chainService, this.eventService);
91
+ this.transactionService = new TransactionService(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
95
92
  this.migrationService = new MigrationService(this);
96
93
  this.subscription = new KoniSubscription(this, this.dbService);
97
94
  this.cron = new KoniCron(this, this.subscription, this.dbService);
@@ -198,8 +195,10 @@ export default class KoniState {
198
195
  await this.chainService.init();
199
196
  await this.migrationService.run();
200
197
  this.startSubscription();
201
- this.updateServiceInfo();
198
+ this.eventService.emit('chain.ready', true);
202
199
  this.onReady();
200
+ this.onAccountAdd();
201
+ this.onAccountRemove();
203
202
  this.logger.log('Done init state');
204
203
  }
205
204
  startSubscription() {
@@ -219,15 +218,8 @@ export default class KoniState {
219
218
  isReady() {
220
219
  return this.ready;
221
220
  }
222
- getKeyringState() {
223
- return this.keyringState;
224
- }
225
- subscribeKeyringState() {
226
- return this.keyringStateSubject;
227
- }
228
- setKeyringState(data, callback) {
229
- this.keyringStateSubject.next(data);
230
- this.keyringState = data;
221
+ updateKeyringState(isReady = true, callback) {
222
+ this.keyringService.updateKeyringState(isReady);
231
223
  callback && callback();
232
224
  }
233
225
  lazyNext = (key, callback) => {
@@ -285,7 +277,7 @@ export default class KoniState {
285
277
  return this.dbService.getNominatorMetadata();
286
278
  }
287
279
  async getStaking() {
288
- const addresses = await this.getDecodedAddresses();
280
+ const addresses = this.getDecodedAddresses();
289
281
  const stakings = await this.dbService.getStakings(addresses, this.activeChainSlugs);
290
282
  return {
291
283
  ready: true,
@@ -303,7 +295,7 @@ export default class KoniState {
303
295
  return addresses;
304
296
  }
305
297
  async getPooledStakingRecordsByAddress(addresses) {
306
- return await this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
298
+ return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
307
299
  }
308
300
 
309
301
  // TODO: delete later
@@ -344,12 +336,12 @@ export default class KoniState {
344
336
  subscribeNftCollection() {
345
337
  return this.dbService.stores.nftCollection.subscribeNftCollection(this.activeChainSlugs);
346
338
  }
347
- async resetNft(newAddress) {
339
+ resetNft(newAddress) {
348
340
  this.getNft().then(data => this.nftSubject.next(data || {
349
341
  nftList: [],
350
342
  total: 0
351
343
  })).catch(e => this.logger.warn(e));
352
- const addresses = await this.getDecodedAddresses(newAddress);
344
+ const addresses = this.getDecodedAddresses(newAddress);
353
345
  this.dbService.subscribeNft(addresses, this.activeChainSlugs, nfts => {
354
346
  this.nftSubject.next({
355
347
  nftList: nfts,
@@ -361,14 +353,14 @@ export default class KoniState {
361
353
  this.dbService.addNft(address, nftData).catch(e => this.logger.warn(e));
362
354
  callback && callback(nftData);
363
355
  }
364
- removeNfts(chain, address, collectionId, nftIds) {
365
- return this.dbService.removeNfts(chain, address, collectionId, nftIds);
366
- }
367
356
  deleteNftCollection(chain, collectionId) {
368
357
  return this.dbService.deleteNftCollection(chain, collectionId);
369
358
  }
359
+ cleanUpNfts(chain, owner, collectionId, nftIds) {
360
+ this.dbService.cleanUpNft(chain, owner, collectionId, nftIds).catch(e => this.logger.warn(e));
361
+ }
370
362
  async getNft() {
371
- const addresses = await this.getDecodedAddresses();
363
+ const addresses = this.getDecodedAddresses();
372
364
  if (!addresses.length) {
373
365
  return;
374
366
  }
@@ -442,9 +434,6 @@ export default class KoniState {
442
434
  subscribeStakingReward() {
443
435
  return this.stakingRewardSubject;
444
436
  }
445
- getCurrentAccount(update) {
446
- this.currentAccountStore.get('CurrentAccountInfo', update);
447
- }
448
437
  setCurrentAccount(data, callback) {
449
438
  const {
450
439
  address,
@@ -454,9 +443,9 @@ export default class KoniState {
454
443
  ...data
455
444
  };
456
445
  if (address === ALL_ACCOUNT_KEY) {
457
- const pairs = keyring.getPairs();
446
+ const pairs = keyring.getAccounts();
458
447
  const pair = pairs[0];
459
- const pairGenesisHash = pair.meta.genesisHash;
448
+ const pairGenesisHash = (pair === null || pair === void 0 ? void 0 : pair.meta.genesisHash) || '';
460
449
  if (pairs.length > 1 || !pair) {
461
450
  result.allGenesisHash = currentGenesisHash || undefined;
462
451
  } else {
@@ -465,10 +454,8 @@ export default class KoniState {
465
454
  result.allGenesisHash = pairGenesisHash || undefined;
466
455
  }
467
456
  }
468
- this.currentAccountStore.set('CurrentAccountInfo', result, () => {
469
- this.updateServiceInfo();
470
- callback && callback();
471
- });
457
+ this.keyringService.setCurrentAccount(result);
458
+ callback && callback();
472
459
  }
473
460
  setAccountTie(address, genesisHash) {
474
461
  if (address !== ALL_ACCOUNT_KEY) {
@@ -479,12 +466,11 @@ export default class KoniState {
479
466
  genesisHash
480
467
  });
481
468
  }
482
- this.getCurrentAccount(accountInfo => {
483
- if (address === accountInfo.address) {
484
- accountInfo.currentGenesisHash = genesisHash || ALL_GENESIS_HASH;
485
- this.setCurrentAccount(accountInfo);
486
- }
487
- });
469
+ const accountInfo = this.keyringService.currentAccount;
470
+ if (address === accountInfo.address) {
471
+ accountInfo.currentGenesisHash = genesisHash || ALL_GENESIS_HASH;
472
+ this.setCurrentAccount(accountInfo);
473
+ }
488
474
  return true;
489
475
  }
490
476
  async switchEvmNetworkByUrl(shortenUrl, networkKey) {
@@ -507,9 +493,7 @@ export default class KoniState {
507
493
  const {
508
494
  address,
509
495
  currentGenesisHash
510
- } = await new Promise(resolve => {
511
- this.getCurrentAccount(resolve);
512
- });
496
+ } = this.keyringService.currentAccount;
513
497
  return this.requestService.addConfirmation(id, url, 'switchNetworkRequest', {
514
498
  networkKey,
515
499
  address: changeAddress
@@ -624,35 +608,28 @@ export default class KoniState {
624
608
  subscribeSettingsSubject() {
625
609
  return this.settingService.getSubject();
626
610
  }
627
- subscribeCurrentAccount() {
628
- return this.currentAccountStore.getSubject();
629
- }
630
611
  getAccountAddress() {
631
- return new Promise((resolve, reject) => {
632
- this.getCurrentAccount(account => {
633
- if (account) {
634
- resolve(account.address);
635
- } else {
636
- resolve(null);
637
- }
638
- });
639
- });
612
+ const address = this.keyringService.currentAccount.address;
613
+ if (address === '') {
614
+ return null;
615
+ }
616
+ return address;
640
617
  }
641
- async getDecodedAddresses(address) {
618
+ getDecodedAddresses(address) {
642
619
  let checkingAddress = address;
643
620
  if (!address) {
644
- checkingAddress = await this.getAccountAddress();
621
+ checkingAddress = this.getAccountAddress();
645
622
  }
646
623
  if (!checkingAddress) {
647
624
  return [];
648
625
  }
649
626
  if (checkingAddress === ALL_ACCOUNT_KEY) {
650
- return Object.keys(accounts.subject.value);
627
+ return this.getAllAddresses();
651
628
  }
652
629
  return [checkingAddress];
653
630
  }
654
631
  getAllAddresses() {
655
- return Object.keys(accounts.subject.value);
632
+ return keyring.getAccounts().map(account => account.address);
656
633
  }
657
634
  removeInactiveChainBalances(balanceMap) {
658
635
  const activeBalanceMap = {};
@@ -678,7 +655,7 @@ export default class KoniState {
678
655
  const items = await this.dbService.stores.balance.getBalanceMapByAddress(address);
679
656
  return items || {};
680
657
  }
681
- async switchAccount(newAddress) {
658
+ async handleSwitchAccount(newAddress) {
682
659
  await Promise.all([this.resetBalanceMap(newAddress), this.resetCrowdloanMap(newAddress)]);
683
660
  }
684
661
  async resetBalanceMap(newAddress) {
@@ -700,11 +677,11 @@ export default class KoniState {
700
677
  };
701
678
  this.publishCrowdloan(true);
702
679
  }
703
- async resetStaking(newAddress) {
680
+ resetStaking(newAddress) {
704
681
  this.getStaking().then(data => {
705
682
  this.stakingSubject.next(data);
706
683
  }).catch(e => this.logger.warn(e));
707
- const addresses = await this.getDecodedAddresses(newAddress);
684
+ const addresses = this.getDecodedAddresses(newAddress);
708
685
  this.dbService.subscribeStaking(addresses, this.activeChainSlugs, stakings => {
709
686
  this.stakingSubject.next({
710
687
  ready: true,
@@ -723,9 +700,8 @@ export default class KoniState {
723
700
  });
724
701
  }
725
702
  updateBalanceStore(item) {
726
- this.getCurrentAccount(currentAccountInfo => {
727
- this.dbService.updateBalanceStore(currentAccountInfo.address, item).catch(e => this.logger.warn(e));
728
- });
703
+ const currentAccountInfo = this.keyringService.currentAccount;
704
+ this.dbService.updateBalanceStore(currentAccountInfo.address, item).catch(e => this.logger.warn(e));
729
705
  }
730
706
  subscribeBalance() {
731
707
  return this.balanceSubject;
@@ -754,16 +730,12 @@ export default class KoniState {
754
730
  });
755
731
  }
756
732
  updateCrowdloanStore(networkKey, item) {
757
- this.getCurrentAccount(currentAccountInfo => {
758
- this.dbService.updateCrowdloanStore(networkKey, currentAccountInfo.address, item).catch(e => this.logger.warn(e));
759
- });
733
+ const currentAccountInfo = this.keyringService.currentAccount;
734
+ this.dbService.updateCrowdloanStore(networkKey, currentAccountInfo.address, item).catch(e => this.logger.warn(e));
760
735
  }
761
736
  subscribeCrowdloan() {
762
737
  return this.crowdloanSubject;
763
738
  }
764
- getAllPriceIds() {
765
- return this.chainService.getAllPriceIds();
766
- }
767
739
  getSmartContractNfts() {
768
740
  return this.chainService.getSmartContractNfts();
769
741
  }
@@ -821,12 +793,13 @@ export default class KoniState {
821
793
  await this.chainService.updateAssetSetting(tokenSlug, {
822
794
  visible: true
823
795
  });
796
+ this.eventService.emit('asset.updateState', tokenSlug);
797
+ } else {
798
+ this.eventService.emit('asset.updateState', tokenSlug);
824
799
  }
825
- this.updateServiceInfo();
826
800
  }
827
801
  deleteCustomAssets(targetTokens) {
828
802
  this.chainService.deleteCustomAssets(targetTokens);
829
- this.updateServiceInfo();
830
803
  }
831
804
  async validateCustomChain(provider, existedChainSlug) {
832
805
  return await this.chainService.validateCustomChain(provider, existedChainSlug);
@@ -849,14 +822,12 @@ export default class KoniState {
849
822
  await this.chainService.updateAssetSetting(newNativeTokenSlug, {
850
823
  visible: true
851
824
  });
825
+ this.eventService.emit('asset.updateState', newNativeTokenSlug);
852
826
  }
853
- this.updateServiceInfo();
854
827
  return true;
855
828
  }
856
829
  removeCustomChain(networkKey) {
857
- const result = this.chainService.removeCustomChain(networkKey);
858
- this.updateServiceInfo();
859
- return result;
830
+ return this.chainService.removeCustomChain(networkKey);
860
831
  }
861
832
 
862
833
  // TODO: avoids turning off chains related to ledger account
@@ -882,29 +853,18 @@ export default class KoniState {
882
853
  async disableChain(chainSlug) {
883
854
  // const defaultChains = this.getDefaultNetworkKeys();
884
855
  await this.chainService.updateAssetSettingByChain(chainSlug, false);
885
- const result = this.chainService.disableChain(chainSlug);
886
- this.updateServiceInfo();
887
- return result;
856
+ return this.chainService.disableChain(chainSlug);
888
857
  }
889
858
  async enableChain(chainSlug, enableTokens = true) {
890
859
  if (enableTokens) {
891
860
  await this.chainService.updateAssetSettingByChain(chainSlug, true);
892
861
  }
893
- const result = this.chainService.enableChain(chainSlug);
894
- this.updateServiceInfo();
895
- return result;
862
+ return this.chainService.enableChain(chainSlug);
896
863
  }
897
864
  resetDefaultChains() {
898
865
  const defaultChains = this.getDefaultNetworkKeys();
899
866
  return this.chainService.resetChainInfoMap(defaultChains);
900
867
  }
901
- updateNetworkStatus(networkKey, status) {
902
- const chainState = this.chainService.getChainStateByKey(networkKey);
903
- if (chainState.connectionStatus === status) {
904
- return;
905
- }
906
- this.chainService.setChainConnectionStatus(networkKey, status);
907
- }
908
868
  getSubstrateApiMap() {
909
869
  return this.chainService.getSubstrateApiMap();
910
870
  }
@@ -930,20 +890,14 @@ export default class KoniState {
930
890
  refreshWeb3Api(key) {
931
891
  this.chainService.refreshEvmApi(key);
932
892
  }
933
- subscribeServiceInfo() {
934
- return this.serviceInfoSubject;
935
- }
936
- updateServiceInfo() {
937
- this.logger.log('<---Update serviceInfo--->');
938
- this.getCurrentAccount(value => {
939
- this.serviceInfoSubject.next({
940
- chainInfoMap: this.chainService.getChainInfoMap(),
941
- chainApiMap: this.getApiMap(),
942
- currentAccountInfo: value,
943
- assetRegistry: this.chainService.getAssetRegistry(),
944
- chainStateMap: this.chainService.getChainStateMap()
945
- });
946
- });
893
+ getServiceInfo() {
894
+ return {
895
+ chainInfoMap: this.chainService.getChainInfoMap(),
896
+ chainApiMap: this.getApiMap(),
897
+ currentAccountInfo: this.keyringService.currentAccount,
898
+ assetRegistry: this.chainService.getAssetRegistry(),
899
+ chainStateMap: this.chainService.getChainStateMap()
900
+ };
947
901
  }
948
902
  getExternalRequestMap() {
949
903
  return this.externalRequest;
@@ -1374,4 +1328,83 @@ export default class KoniState {
1374
1328
  createUnsubscriptionHandle(id, unsubscribe) {
1375
1329
  this.unsubscriptionMap[id] = unsubscribe;
1376
1330
  }
1331
+ updateChainConnectionStatus(chain, status) {
1332
+ this.chainService.setChainConnectionStatus(chain, status);
1333
+ }
1334
+ async autoEnableChains(addresses) {
1335
+ const assetMap = this.chainService.getAssetRegistry();
1336
+ const promiseList = addresses.map(address => {
1337
+ return this.subscanService.getMultiChainBalance(address).catch(e => {
1338
+ console.error(e);
1339
+ return null;
1340
+ });
1341
+ });
1342
+ const needEnableChains = [];
1343
+ const needActiveTokens = [];
1344
+ const currentAssetSettings = await this.chainService.getAssetSettings();
1345
+ const chainMap = this.chainService.getChainInfoMap();
1346
+ const balanceDataList = await Promise.all(promiseList);
1347
+ balanceDataList.forEach(balanceData => {
1348
+ balanceData && balanceData.forEach(({
1349
+ balance,
1350
+ bonded,
1351
+ category,
1352
+ locked,
1353
+ network,
1354
+ symbol
1355
+ }) => {
1356
+ var _currentAssetSettings;
1357
+ const chain = SUBSCAN_CHAIN_MAP_REVERSE[network];
1358
+ const chainInfo = chain ? chainMap[chain] : null;
1359
+ const balanceIsEmpty = (!balance || balance === '0') && !locked && locked === '0' && (!bonded || bonded === '0');
1360
+
1361
+ // Cancel if chain is not supported or is testnet or balance is 0
1362
+ if (!chainInfo || chainInfo.isTestnet || balanceIsEmpty) {
1363
+ return;
1364
+ }
1365
+ const tokenKey = `${chain}-${category === 'native' ? 'NATIVE' : 'LOCAL'}-${symbol.toUpperCase()}`;
1366
+ if (assetMap[tokenKey] && !((_currentAssetSettings = currentAssetSettings[tokenKey]) !== null && _currentAssetSettings !== void 0 && _currentAssetSettings.visible)) {
1367
+ needEnableChains.push(chain);
1368
+ needActiveTokens.push(tokenKey);
1369
+ currentAssetSettings[tokenKey] = {
1370
+ visible: true
1371
+ };
1372
+ }
1373
+ });
1374
+ });
1375
+ if (needActiveTokens.length) {
1376
+ this.chainService.enableChains(needEnableChains);
1377
+ this.chainService.setAssetSettings({
1378
+ ...currentAssetSettings
1379
+ });
1380
+ }
1381
+ }
1382
+ onAccountAdd() {
1383
+ this.eventService.on('account.add', address => {
1384
+ this.autoEnableChains([address]).catch(this.logger.error);
1385
+ });
1386
+ }
1387
+ onAccountRemove() {
1388
+ this.eventService.on('account.remove', address => {
1389
+ // Some separate service like historyService will listen to this event and remove inside that service
1390
+
1391
+ const stores = this.dbService.stores;
1392
+
1393
+ // Remove Balance
1394
+ stores.balance.removeAllByAddress(address).catch(console.error);
1395
+ stores.balance.removeAllByAddress(ALL_ACCOUNT_KEY).catch(console.error);
1396
+
1397
+ // Remove NFT
1398
+ stores.nft.deleteNftByAddress([address]).catch(console.error);
1399
+
1400
+ // Remove Staking Data
1401
+ stores.staking.removeAllByAddress(address).catch(console.error);
1402
+ });
1403
+ }
1404
+ async reloadNft() {
1405
+ return await this.cron.reloadNft();
1406
+ }
1407
+ async reloadStaking() {
1408
+ return await this.cron.reloadStaking();
1409
+ }
1377
1410
  }