@subwallet/extension-base 1.0.4-0 → 1.0.5-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/background/KoniTypes.d.ts +37 -16
  2. package/background/KoniTypes.js +2 -0
  3. package/background/errors/TransactionError.js +4 -0
  4. package/background/handlers/State.d.ts +1 -1
  5. package/background/handlers/State.js +2 -8
  6. package/background/handlers/subscriptions.js +0 -1
  7. package/background/types.d.ts +2 -2
  8. package/cjs/background/KoniTypes.js +2 -0
  9. package/cjs/background/errors/TransactionError.js +4 -0
  10. package/cjs/background/handlers/State.js +1 -7
  11. package/cjs/background/handlers/subscriptions.js +0 -1
  12. package/cjs/constants/index.js +6 -6
  13. package/cjs/koni/api/coingecko.js +1 -4
  14. package/cjs/koni/api/dotsama/balance.js +7 -5
  15. package/cjs/koni/api/dotsama/crowdloan.js +0 -4
  16. package/cjs/koni/api/dotsama/transfer.js +0 -4
  17. package/cjs/koni/api/nft/acala_nft/index.js +1 -1
  18. package/cjs/koni/api/nft/bit.country/index.js +1 -1
  19. package/cjs/koni/api/nft/evm_nft/index.js +2 -3
  20. package/cjs/koni/api/nft/index.js +1 -2
  21. package/cjs/koni/api/nft/karura_nft/index.js +1 -1
  22. package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
  23. package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
  24. package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
  25. package/cjs/koni/api/nft/transfer.js +5 -5
  26. package/cjs/koni/api/nft/unique_nft/index.js +1 -1
  27. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  28. package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
  29. package/cjs/koni/api/staking/bonding/amplitude.js +9 -2
  30. package/cjs/koni/api/staking/bonding/astar.js +37 -13
  31. package/cjs/koni/api/staking/bonding/paraChain.js +10 -2
  32. package/cjs/koni/api/staking/bonding/relayChain.js +21 -4
  33. package/cjs/koni/api/staking/bonding/utils.js +4 -0
  34. package/cjs/koni/api/staking/relayChain.js +0 -1
  35. package/cjs/koni/api/staking/subsquidStaking.js +0 -2
  36. package/cjs/koni/api/tokens/wasm/index.js +0 -1
  37. package/cjs/koni/api/tokens/wasm/utils.js +0 -1
  38. package/cjs/koni/api/xcm/index.js +0 -1
  39. package/cjs/koni/background/cron.js +0 -45
  40. package/cjs/koni/background/handlers/Extension.js +204 -132
  41. package/cjs/koni/background/handlers/State.js +30 -3
  42. package/cjs/koni/background/handlers/Tabs.js +34 -2
  43. package/cjs/koni/background/handlers/index.js +3 -2
  44. package/cjs/koni/background/subscription.js +0 -26
  45. package/cjs/packageInfo.js +1 -1
  46. package/cjs/services/chain-service/constants.js +1 -1
  47. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  48. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -10
  49. package/cjs/services/chain-service/handler/light-client/index.js +9 -6
  50. package/cjs/services/chain-service/index.js +75 -28
  51. package/cjs/services/chain-service/utils.js +3 -0
  52. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +108 -0
  53. package/cjs/services/history-service/index.js +60 -5
  54. package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
  55. package/cjs/services/history-service/testChainMap.js +724 -0
  56. package/cjs/services/keyring-service/index.js +9 -2
  57. package/cjs/services/migration-service/index.js +7 -7
  58. package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +39 -0
  59. package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
  60. package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
  61. package/cjs/services/migration-service/scripts/index.js +7 -1
  62. package/cjs/services/price-service/coingecko.js +1 -1
  63. package/cjs/services/price-service/index.js +0 -4
  64. package/cjs/services/request-service/handler/AuthRequestHandler.js +8 -1
  65. package/cjs/services/request-service/handler/EvmRequestHandler.js +21 -0
  66. package/cjs/services/request-service/handler/MetadataRequestHandler.js +6 -0
  67. package/cjs/services/request-service/handler/SubstrateRequestHandler.js +6 -0
  68. package/cjs/services/request-service/index.js +6 -0
  69. package/cjs/services/setting-service/SettingService.js +4 -9
  70. package/cjs/services/setting-service/constants.js +18 -2
  71. package/cjs/services/storage-service/DatabaseService.js +16 -44
  72. package/cjs/services/storage-service/databases/index.js +1 -1
  73. package/cjs/services/storage-service/db-stores/BaseStore.js +3 -0
  74. package/cjs/services/transaction-service/constants.js +11 -0
  75. package/cjs/services/transaction-service/index.js +31 -9
  76. package/cjs/services/transaction-service/utils.js +25 -14
  77. package/constants/index.d.ts +1 -1
  78. package/constants/index.js +1 -1
  79. package/koni/api/coingecko.js +1 -4
  80. package/koni/api/dotsama/balance.js +7 -5
  81. package/koni/api/dotsama/crowdloan.js +0 -4
  82. package/koni/api/dotsama/transfer.js +0 -4
  83. package/koni/api/nft/acala_nft/index.js +1 -1
  84. package/koni/api/nft/bit.country/index.js +1 -1
  85. package/koni/api/nft/evm_nft/index.js +2 -3
  86. package/koni/api/nft/index.js +1 -2
  87. package/koni/api/nft/karura_nft/index.js +1 -1
  88. package/koni/api/nft/quartz_nft/index.js +1 -1
  89. package/koni/api/nft/rmrk_nft/index.js +2 -3
  90. package/koni/api/nft/statemine_nft/index.js +1 -1
  91. package/koni/api/nft/transfer.js +5 -5
  92. package/koni/api/nft/unique_nft/index.js +1 -1
  93. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  94. package/koni/api/nft/wasm_nft/index.js +1 -2
  95. package/koni/api/staking/bonding/amplitude.js +9 -2
  96. package/koni/api/staking/bonding/astar.d.ts +2 -1
  97. package/koni/api/staking/bonding/astar.js +36 -13
  98. package/koni/api/staking/bonding/paraChain.js +10 -2
  99. package/koni/api/staking/bonding/relayChain.js +21 -4
  100. package/koni/api/staking/bonding/utils.js +4 -0
  101. package/koni/api/staking/relayChain.js +0 -1
  102. package/koni/api/staking/subsquidStaking.js +0 -2
  103. package/koni/api/tokens/wasm/index.js +0 -1
  104. package/koni/api/tokens/wasm/utils.js +0 -1
  105. package/koni/api/xcm/index.js +0 -1
  106. package/koni/background/cron.js +0 -45
  107. package/koni/background/handlers/Extension.d.ts +3 -0
  108. package/koni/background/handlers/Extension.js +120 -51
  109. package/koni/background/handlers/State.d.ts +4 -1
  110. package/koni/background/handlers/State.js +30 -3
  111. package/koni/background/handlers/Tabs.d.ts +1 -0
  112. package/koni/background/handlers/Tabs.js +32 -1
  113. package/koni/background/handlers/index.js +3 -2
  114. package/koni/background/subscription.d.ts +0 -1
  115. package/koni/background/subscription.js +0 -26
  116. package/package.json +65 -39
  117. package/packageInfo.js +1 -1
  118. package/services/chain-service/constants.js +1 -1
  119. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  120. package/services/chain-service/handler/SubstrateChainHandler.js +3 -10
  121. package/services/chain-service/handler/light-client/index.js +8 -6
  122. package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
  123. package/services/chain-service/index.d.ts +2 -1
  124. package/services/chain-service/index.js +75 -28
  125. package/services/chain-service/utils.js +3 -0
  126. package/services/history-service/helpers/recoverHistoryStatus.d.ts +11 -0
  127. package/services/history-service/helpers/recoverHistoryStatus.js +98 -0
  128. package/services/history-service/index.d.ts +6 -0
  129. package/services/history-service/index.js +61 -6
  130. package/services/history-service/subsquid-multi-chain-history.js +3 -2
  131. package/services/history-service/testChainMap.d.ts +3 -0
  132. package/services/history-service/testChainMap.js +716 -0
  133. package/services/keyring-service/index.d.ts +1 -0
  134. package/services/keyring-service/index.js +9 -2
  135. package/services/migration-service/index.js +7 -7
  136. package/services/migration-service/scripts/MigrateAuthUrls.d.ts +4 -0
  137. package/services/migration-service/scripts/MigrateAuthUrls.js +31 -0
  138. package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
  139. package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
  140. package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
  141. package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
  142. package/services/migration-service/scripts/index.js +7 -1
  143. package/services/price-service/coingecko.js +1 -1
  144. package/services/price-service/index.js +0 -4
  145. package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
  146. package/services/request-service/handler/AuthRequestHandler.js +8 -1
  147. package/services/request-service/handler/EvmRequestHandler.d.ts +1 -0
  148. package/services/request-service/handler/EvmRequestHandler.js +21 -0
  149. package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -0
  150. package/services/request-service/handler/MetadataRequestHandler.js +6 -0
  151. package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
  152. package/services/request-service/handler/SubstrateRequestHandler.js +6 -0
  153. package/services/request-service/index.d.ts +1 -0
  154. package/services/request-service/index.js +6 -0
  155. package/services/setting-service/SettingService.d.ts +1 -0
  156. package/services/setting-service/SettingService.js +5 -10
  157. package/services/setting-service/constants.d.ts +4 -1
  158. package/services/setting-service/constants.js +14 -1
  159. package/services/storage-service/DatabaseService.d.ts +1 -0
  160. package/services/storage-service/DatabaseService.js +16 -44
  161. package/services/storage-service/databases/index.js +1 -1
  162. package/services/storage-service/db-stores/BaseStore.d.ts +1 -0
  163. package/services/storage-service/db-stores/BaseStore.js +3 -0
  164. package/services/transaction-service/constants.d.ts +1 -0
  165. package/services/transaction-service/constants.js +4 -0
  166. package/services/transaction-service/index.d.ts +2 -0
  167. package/services/transaction-service/index.js +32 -10
  168. package/services/transaction-service/utils.d.ts +1 -1
  169. package/services/transaction-service/utils.js +24 -13
@@ -34,7 +34,7 @@ export function validatePoolBondingCondition(chainInfo, amount, selectedPool, ad
34
34
  if (nominatorMetadata) {
35
35
  const bnCurrentActiveStake = new BN(nominatorMetadata.activeStake);
36
36
  bnTotalStake = bnTotalStake.add(bnCurrentActiveStake);
37
- if (!bnCurrentActiveStake.gt(BN_ZERO)) {
37
+ if (nominatorMetadata.unstakings.length > 0) {
38
38
  errors.push(new TransactionError(StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
39
39
  }
40
40
  }
@@ -47,7 +47,7 @@ export function validateRelayBondingCondition(chainInfo, amount, selectedValidat
47
47
  const errors = [];
48
48
  let bnTotalStake = new BN(amount);
49
49
  const bnMinStake = new BN(chainStakingMetadata.minStake);
50
- if (!nominatorMetadata) {
50
+ if (!nominatorMetadata || nominatorMetadata.status === StakingStatus.NOT_STAKING) {
51
51
  if (!bnTotalStake.gte(bnMinStake)) {
52
52
  errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
53
53
  }
@@ -145,7 +145,15 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
145
145
  const currentEra = _currentEra.toString();
146
146
  const bonded = _bonded.toHuman();
147
147
  if (!ledger) {
148
- return;
148
+ return {
149
+ chain,
150
+ type: StakingType.NOMINATED,
151
+ status: StakingStatus.NOT_STAKING,
152
+ address: address,
153
+ activeStake: '0',
154
+ nominations: [],
155
+ unstakings: []
156
+ };
149
157
  }
150
158
  const activeStake = ledger.active.toString();
151
159
  const nominationList = [];
@@ -225,7 +233,16 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
225
233
  const poolMemberInfo = _poolMemberInfo.toPrimitive();
226
234
  const currentEra = _currentEra.toString();
227
235
  if (!poolMemberInfo) {
228
- return;
236
+ return {
237
+ chain: chainInfo.slug,
238
+ type: StakingType.POOLED,
239
+ address,
240
+ status: StakingStatus.NOT_STAKING,
241
+ activeStake: '0',
242
+ nominations: [],
243
+ // can only join 1 pool at a time
244
+ unstakings: []
245
+ };
229
246
  }
230
247
  let stakingStatus = StakingStatus.NOT_EARNING;
231
248
  const _poolMetadata = await chainApi.api.query.nominationPools.metadata(poolMemberInfo.poolId);
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { getAstarWithdrawable } from '@subwallet/extension-base/koni/api/staking/bonding/astar';
5
6
  import { _KNOWN_CHAIN_INFLATION_PARAMS, _STAKING_CHAIN_GROUP, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
6
7
  import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
7
8
  import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
@@ -211,6 +212,9 @@ export function isActionFromValidator(stakingType, chain) {
211
212
  export function getWithdrawalInfo(nominatorMetadata) {
212
213
  const unstakings = nominatorMetadata.unstakings;
213
214
  let result;
215
+ if (_STAKING_CHAIN_GROUP.astar.includes(nominatorMetadata.chain)) {
216
+ return getAstarWithdrawable(nominatorMetadata);
217
+ }
214
218
  for (const unstaking of unstakings) {
215
219
  if (unstaking.status === UnstakingStatus.CLAIMABLE) {
216
220
  result = unstaking; // only get the first withdrawal
@@ -154,7 +154,6 @@ export async function getNominationPoolReward(addresses, chainInfoMap, substrate
154
154
  }));
155
155
  }));
156
156
  } catch (e) {
157
- console.error('Error fetching unclaimed reward for nomination pool', e);
158
157
  return rewardList;
159
158
  }
160
159
  return rewardList;
@@ -76,7 +76,6 @@ const getSubsquidStaking = async (accounts, chain, chainInfoMap) => {
76
76
  }));
77
77
  return result;
78
78
  } catch (e) {
79
- console.error(`error getting ${chain} staking reward from subsquid`, e);
80
79
  return [];
81
80
  }
82
81
  };
@@ -94,7 +93,6 @@ export const getAllSubsquidStaking = async (accounts, chainInfoMap) => {
94
93
  rewardList = rewardList.concat(rewardItems);
95
94
  }));
96
95
  } catch (e) {
97
- console.error('Error fetching staking reward from SubSquid', e);
98
96
  return rewardList;
99
97
  }
100
98
  return rewardList;
@@ -23,7 +23,6 @@ export async function getPSP34TransferExtrinsic(networkKey, substrateApi, sender
23
23
  gasLimit
24
24
  }, recipientAddress, onChainOption, {});
25
25
  } catch (e) {
26
- console.error('Error getting WASM NFT transfer extrinsic', e);
27
26
  return null;
28
27
  }
29
28
  }
@@ -9,7 +9,6 @@ const toContractAbiMessage = (contractPromise, message) => {
9
9
  if (!value) {
10
10
  const messages = contractPromise === null || contractPromise === void 0 ? void 0 : contractPromise.abi.messages.map(m => m.method).join(', ');
11
11
  const error = `"${message}" not found in metadata.spec.messages: [${messages}]`;
12
- console.error(error);
13
12
  return {
14
13
  ok: false,
15
14
  error
@@ -25,6 +25,5 @@ export const createXcmExtrinsic = async ({
25
25
  } else {
26
26
  extrinsic = getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
27
27
  }
28
- console.log('XCM extrinsic: ', extrinsic.toHex());
29
28
  return extrinsic;
30
29
  };
@@ -93,7 +93,6 @@ export class KoniCron {
93
93
  if (!commonReload && !chainUpdated && !stakingSubmitted) {
94
94
  return;
95
95
  }
96
- this.logger.log('ServiceInfo updated, Cron restarting...', eventTypes);
97
96
  const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
98
97
  if (!address) {
99
98
  return;
@@ -133,7 +132,6 @@ export class KoniCron {
133
132
  if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
134
133
  return;
135
134
  }
136
- this.logger.log('Starting cron jobs');
137
135
  if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
138
136
  this.resetNft(currentAccountInfo.address);
139
137
  this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
@@ -162,48 +160,12 @@ export class KoniCron {
162
160
  this.serviceSubscription.unsubscribe();
163
161
  this.serviceSubscription = undefined;
164
162
  }
165
- this.logger.log('Stopping cron jobs');
166
163
  this.removeAllCrons();
167
164
  this.status = 'stopped';
168
165
  };
169
166
  updateApiMapStatus = () => {
170
167
  this.state.chainService.updateApiMapStatus().catch(console.error);
171
- // const apiMap = this.state.getApiMap();
172
- // const networkMap = this.state.getChainStateMap();
173
- //
174
- // for (const [key, substrateApi] of Object.entries(apiMap.substrate)) {
175
- // let status: _ChainConnectionStatus = _ChainConnectionStatus.CONNECTING;
176
- //
177
- // if (substrateApi.isApiConnected) {
178
- // status = _ChainConnectionStatus.CONNECTED;
179
- // }
180
- //
181
- // if (!networkMap[key].connectionStatus) {
182
- // this.state.updateChainConnectionStatus(key, status);
183
- // } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== status) {
184
- // this.state.updateChainConnectionStatus(key, status);
185
- // }
186
- // }
187
- //
188
- // for (const [key, evmApi] of Object.entries(apiMap.evm)) {
189
- // evmApi.api.eth.net.isListening()
190
- // .then(() => {
191
- // if (!networkMap[key].connectionStatus) {
192
- // this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTED);
193
- // } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _ChainConnectionStatus.CONNECTED) {
194
- // this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTED);
195
- // }
196
- // })
197
- // .catch(() => {
198
- // if (!networkMap[key].connectionStatus) {
199
- // this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTING);
200
- // } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _ChainConnectionStatus.CONNECTING) {
201
- // this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTING);
202
- // }
203
- // });
204
- // }
205
168
  };
206
-
207
169
  recoverApiMap = () => {
208
170
  var _this$subscriptions;
209
171
  const apiMap = this.state.getApiMap();
@@ -224,7 +186,6 @@ export class KoniCron {
224
186
  };
225
187
  refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
226
188
  return () => {
227
- console.debug('Refresh NFT state');
228
189
  this.subscriptions.subscribeNft(address, apiMap.substrate, apiMap.evm, smartContractNfts, chainInfoMap);
229
190
  };
230
191
  };
@@ -236,13 +197,11 @@ export class KoniCron {
236
197
  };
237
198
  refreshStakingReward = address => {
238
199
  return () => {
239
- console.debug('Refresh staking reward state');
240
200
  this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
241
201
  };
242
202
  };
243
203
  refreshStakingRewardFastInterval = address => {
244
204
  return () => {
245
- console.debug('Refresh staking reward data with fast interval');
246
205
  this.subscriptions.subscribeStakingRewardFastInterval(address).catch(this.logger.error);
247
206
  };
248
207
  };
@@ -254,20 +213,17 @@ export class KoniCron {
254
213
  };
255
214
  updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
256
215
  return () => {
257
- console.debug('Fetching chain staking metadata');
258
216
  this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
259
217
  };
260
218
  };
261
219
  updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
262
220
  return () => {
263
- console.debug('Fetching nominator data for', address);
264
221
  this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
265
222
  };
266
223
  };
267
224
  async reloadNft() {
268
225
  const address = this.state.keyringService.currentAccount.address;
269
226
  const serviceInfo = this.state.getServiceInfo();
270
- console.debug('Hard refresh NFT for', address);
271
227
  this.resetNft(address);
272
228
  this.removeCron('refreshNft');
273
229
  this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
@@ -276,7 +232,6 @@ export class KoniCron {
276
232
  }
277
233
  async reloadStaking() {
278
234
  const address = this.state.keyringService.currentAccount.address;
279
- console.debug('Hard refresh staking meta for', address);
280
235
  this.resetStakingReward();
281
236
  this.removeCron('refreshStakingReward');
282
237
  this.removeCron('refreshPoolingStakingReward');
@@ -73,7 +73,9 @@ export default class KoniExtension {
73
73
  private saveTheme;
74
74
  private setCamera;
75
75
  private saveBrowserConfirmationType;
76
+ private setAutoLockTime;
76
77
  private subscribeSettings;
78
+ private setEnableChainPatrol;
77
79
  private subscribeAuthUrls;
78
80
  private _saveCurrentAccountAddress;
79
81
  private updateCurrentAccountAddress;
@@ -169,6 +171,7 @@ export default class KoniExtension {
169
171
  private keyringUnlock;
170
172
  private keyringLock;
171
173
  private keyringExportMnemonic;
174
+ private resetWallet;
172
175
  private signingApprovePasswordV2;
173
176
  private derivationCreateMultiple;
174
177
  private derivationCreateV3;
@@ -7,7 +7,7 @@ import { isJsonPayload, SEED_DEFAULT_LENGTH, SEED_LENGTHS } from '@subwallet/ext
7
7
  import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
8
8
  import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
9
9
  import { AccountExternalErrorCode, BasicTxErrorType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, StakingType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
10
- import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, DEFAULT_TIME_AUTO_LOCK } from '@subwallet/extension-base/constants';
10
+ import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH } from '@subwallet/extension-base/constants';
11
11
  import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
12
12
  import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
13
13
  import { checkReferenceCount, checkSupportTransfer, createTransferExtrinsic } from '@subwallet/extension-base/koni/api/dotsama/transfer';
@@ -20,6 +20,7 @@ import { getPSP34TransferExtrinsic } from '@subwallet/extension-base/koni/api/to
20
20
  import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
21
21
  import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isNativeToken, _isTokenEvmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
22
22
  import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
23
+ import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
23
24
  import { reformatAddress } from '@subwallet/extension-base/utils';
24
25
  import { convertSubjectInfoToAddresses } from '@subwallet/extension-base/utils/address';
25
26
  import { createTransactionFromRLP, signatureToHex } from '@subwallet/extension-base/utils/eth';
@@ -55,8 +56,20 @@ const ACCOUNT_ALL_JSON = {
55
56
  export default class KoniExtension {
56
57
  #lockTimeOut = undefined;
57
58
  #koniState;
59
+ #timeAutoLock = DEFAULT_AUTO_LOCK_TIME;
58
60
  constructor(state) {
59
61
  this.#koniState = state;
62
+ const updateTimeAutoLock = rs => {
63
+ this.#timeAutoLock = rs.timeAutoLock;
64
+ clearTimeout(this.#lockTimeOut);
65
+ this.#lockTimeOut = setTimeout(() => {
66
+ this.keyringLock();
67
+ }, this.#timeAutoLock * 60 * 1000);
68
+ };
69
+ this.#koniState.settingService.getSettings(updateTimeAutoLock);
70
+ this.#koniState.settingService.getSubject().subscribe({
71
+ next: updateTimeAutoLock
72
+ });
60
73
  }
61
74
 
62
75
  /// Clone from PolkadotJs
@@ -326,7 +339,6 @@ export default class KoniExtension {
326
339
  windowOpen(path) {
327
340
  const url = `${chrome.extension.getURL('index.html')}#${path}`;
328
341
  if (!ALLOWED_PATH.includes(path)) {
329
- console.error('Not allowed to open the url:', url);
330
342
  return false;
331
343
  }
332
344
  withErrorLog(() => chrome.tabs.create({
@@ -712,7 +724,6 @@ export default class KoniExtension {
712
724
  assert(value, 'The source is not known');
713
725
  if (this.isAddressValidWithAuthType(address, value[url].accountAuthType)) {
714
726
  value[url].isAllowedMap[address] = connectValue;
715
- console.log('Devbu: ', value);
716
727
  this.#koniState.setAuthorize(value, () => {
717
728
  callBack && callBack(value);
718
729
  });
@@ -725,7 +736,6 @@ export default class KoniExtension {
725
736
  this.#koniState.getAuthorize(value => {
726
737
  assert(value, 'The source is not known');
727
738
  value[id].isAllowed = connectValue;
728
- console.log('Devbu: ', value);
729
739
  this.#koniState.setAuthorize(value);
730
740
  });
731
741
  }
@@ -733,7 +743,6 @@ export default class KoniExtension {
733
743
  this.#koniState.getAuthorize(value => {
734
744
  assert(value, 'The source is not known');
735
745
  value[id].isAllowedMap = values;
736
- console.log('Devbu: ', value);
737
746
  this.#koniState.setAuthorize(value);
738
747
  });
739
748
  }
@@ -762,22 +771,18 @@ export default class KoniExtension {
762
771
  });
763
772
  });
764
773
  }
765
- toggleBalancesVisibility(id, port) {
766
- const cb = createSubscription(id, port);
767
- this.#koniState.getSettings(value => {
768
- const updateValue = {
769
- ...value,
770
- isShowBalance: !value.isShowBalance
771
- };
772
- this.#koniState.setSettings(updateValue, () => {
773
- // eslint-disable-next-line node/no-callback-literal
774
- cb(updateValue);
774
+ async toggleBalancesVisibility() {
775
+ return new Promise(resolve => {
776
+ this.#koniState.getSettings(value => {
777
+ const updateValue = {
778
+ ...value,
779
+ isShowBalance: !value.isShowBalance
780
+ };
781
+ this.#koniState.setSettings(updateValue, () => {
782
+ resolve(!value.isShowBalance);
783
+ });
775
784
  });
776
785
  });
777
- port.onDisconnect.addListener(() => {
778
- this.cancelSubscription(id);
779
- });
780
- return true;
781
786
  }
782
787
  saveAccountAllLogo(data, id, port) {
783
788
  const cb = createSubscription(id, port);
@@ -818,6 +823,12 @@ export default class KoniExtension {
818
823
  });
819
824
  return true;
820
825
  }
826
+ setAutoLockTime({
827
+ autoLockTime
828
+ }) {
829
+ this.#koniState.setAutoLockTime(autoLockTime);
830
+ return true;
831
+ }
821
832
  async subscribeSettings(id, port) {
822
833
  const cb = createSubscription(id, port);
823
834
  const balancesVisibilitySubscription = this.#koniState.subscribeSettingsSubject().subscribe({
@@ -831,6 +842,12 @@ export default class KoniExtension {
831
842
  });
832
843
  return await this.getSettings();
833
844
  }
845
+ setEnableChainPatrol({
846
+ enable
847
+ }) {
848
+ this.#koniState.setEnableChainPatrol(enable);
849
+ return true;
850
+ }
834
851
  async subscribeAuthUrls(id, port) {
835
852
  const cb = createSubscription(id, port);
836
853
  const authorizeUrlSubscription = this.#koniState.subscribeAuthorizeUrlSubject().subscribe({
@@ -894,11 +911,11 @@ export default class KoniExtension {
894
911
  }
895
912
  async updateAssetSetting(params) {
896
913
  try {
897
- await this.#koniState.chainService.updateAssetSetting(params.tokenSlug, params.assetSetting);
914
+ await this.#koniState.chainService.updateAssetSetting(params.tokenSlug, params.assetSetting, params.autoEnableNativeToken);
898
915
  this.#koniState.eventService.emit('asset.updateState', params.tokenSlug);
899
916
  return true;
900
917
  } catch (e) {
901
- console.error('Error updating asset setting', e);
918
+ console.error(e);
902
919
  return false;
903
920
  }
904
921
  }
@@ -1522,7 +1539,7 @@ export default class KoniExtension {
1522
1539
  try {
1523
1540
  return this.#koniState.refreshSubstrateApi(networkKey);
1524
1541
  } catch (e) {
1525
- console.error('error recovering substrate api', e);
1542
+ console.error(e);
1526
1543
  return false;
1527
1544
  }
1528
1545
  }
@@ -1531,7 +1548,7 @@ export default class KoniExtension {
1531
1548
  await this.#koniState.upsertCustomToken(data);
1532
1549
  return true;
1533
1550
  } catch (e) {
1534
- console.error('Error insert/update custom token', e);
1551
+ console.error(e);
1535
1552
  return false;
1536
1553
  }
1537
1554
  }
@@ -1593,26 +1610,39 @@ export default class KoniExtension {
1593
1610
  estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0';
1594
1611
  } catch (e) {
1595
1612
  estimatedFee = '0';
1596
- console.warn('Error estimating fee', e);
1613
+ console.warn(e);
1597
1614
  }
1598
1615
  }
1599
1616
  } else {
1600
- const [mockTx] = await createTransferExtrinsic({
1601
- from: address,
1602
- networkKey,
1603
- substrateApi,
1604
- to: address,
1605
- tokenInfo,
1606
- transferAll: true,
1607
- value: '0'
1608
- });
1609
- try {
1610
- var _paymentInfo$partialF2;
1611
- const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
1612
- estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
1613
- } catch (e) {
1614
- estimatedFee = '0';
1615
- console.warn('Error estimating fee', e);
1617
+ const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
1618
+ if (_isChainEvmCompatible(chainInfo)) {
1619
+ const web3 = this.#koniState.chainService.getEvmApi(networkKey);
1620
+ const transaction = {
1621
+ value: 1,
1622
+ to: address,
1623
+ from: address
1624
+ };
1625
+ const gasPrice = await web3.api.eth.getGasPrice();
1626
+ const gasLimit = await web3.api.eth.estimateGas(transaction);
1627
+ estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
1628
+ } else {
1629
+ const [mockTx] = await createTransferExtrinsic({
1630
+ from: address,
1631
+ networkKey,
1632
+ substrateApi,
1633
+ to: address,
1634
+ tokenInfo,
1635
+ transferAll: true,
1636
+ value: '0'
1637
+ });
1638
+ try {
1639
+ var _paymentInfo$partialF2;
1640
+ const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
1641
+ estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
1642
+ } catch (e) {
1643
+ estimatedFee = '0';
1644
+ console.warn('Error estimating fee', e);
1645
+ }
1616
1646
  }
1617
1647
  }
1618
1648
  maxTransferable = maxTransferable.sub(new BN(estimatedFee));
@@ -2147,7 +2177,6 @@ export default class KoniExtension {
2147
2177
  }
2148
2178
  async getNominationPoolOptions(chain) {
2149
2179
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2150
- console.log('chain', chain);
2151
2180
  return await getNominationPoolsInfo(chain, substrateApi);
2152
2181
  }
2153
2182
  async submitBonding(inputData) {
@@ -2169,7 +2198,6 @@ export default class KoniExtension {
2169
2198
  }
2170
2199
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2171
2200
  const extrinsic = await getBondingExtrinsic(chainInfo, amount, selectedValidators, substrateApi, address, nominatorMetadata);
2172
- console.log('Bonding extrinsic: ', chain, extrinsic.toHex());
2173
2201
  return await this.#koniState.transactionService.handleTransaction({
2174
2202
  address,
2175
2203
  chain: chain,
@@ -2198,7 +2226,6 @@ export default class KoniExtension {
2198
2226
  }
2199
2227
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2200
2228
  const extrinsic = await getUnbondingExtrinsic(nominatorMetadata, amount, chain, substrateApi, validatorAddress);
2201
- console.log('Unbonding extrinsic: ', extrinsic.toHex());
2202
2229
  return await this.#koniState.transactionService.handleTransaction({
2203
2230
  address: nominatorMetadata.address,
2204
2231
  chain: chain,
@@ -2219,7 +2246,6 @@ export default class KoniExtension {
2219
2246
  }
2220
2247
  const dotSamaApi = this.#koniState.getSubstrateApi(chain);
2221
2248
  const extrinsic = await getWithdrawalExtrinsic(dotSamaApi, chain, nominatorMetadata, validatorAddress);
2222
- console.log('Stake withdrawal extrinsic: ', extrinsic.toHex());
2223
2249
  return await this.#koniState.transactionService.handleTransaction({
2224
2250
  address: nominatorMetadata.address,
2225
2251
  chain: chain,
@@ -2241,7 +2267,6 @@ export default class KoniExtension {
2241
2267
  }
2242
2268
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2243
2269
  const extrinsic = await getClaimRewardExtrinsic(substrateApi, chain, address, stakingType, bondReward);
2244
- console.log('Staking claim reward extrinsic: ', extrinsic.toHex());
2245
2270
  return await this.#koniState.transactionService.handleTransaction({
2246
2271
  address,
2247
2272
  chain: chain,
@@ -2262,7 +2287,6 @@ export default class KoniExtension {
2262
2287
  }
2263
2288
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2264
2289
  const extrinsic = await getCancelWithdrawalExtrinsic(substrateApi, chain, selectedUnstaking);
2265
- console.log('Cancel stake withdrawal extrinsic', extrinsic.toHex());
2266
2290
  return await this.#koniState.transactionService.handleTransaction({
2267
2291
  address,
2268
2292
  chain,
@@ -2291,7 +2315,6 @@ export default class KoniExtension {
2291
2315
  }
2292
2316
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2293
2317
  const extrinsic = await getPoolingBondingExtrinsic(substrateApi, amount, selectedPool.id, nominatorMetadata);
2294
- console.log('Join nomination pool extrinsic', extrinsic.toHex());
2295
2318
  return await this.#koniState.transactionService.handleTransaction({
2296
2319
  address,
2297
2320
  chain,
@@ -2317,7 +2340,6 @@ export default class KoniExtension {
2317
2340
  }
2318
2341
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2319
2342
  const extrinsic = await getPoolingUnbondingExtrinsic(substrateApi, amount, nominatorMetadata);
2320
- console.log('Nomination pool unbond extrinsic', extrinsic.toHex());
2321
2343
  return await this.#koniState.transactionService.handleTransaction({
2322
2344
  address: nominatorMetadata.address,
2323
2345
  chain,
@@ -2386,6 +2408,11 @@ export default class KoniExtension {
2386
2408
  chainType: ChainType.SUBSTRATE
2387
2409
  });
2388
2410
  }
2411
+
2412
+ /// Keyring state
2413
+
2414
+ // Subscribe keyring state
2415
+
2389
2416
  keyringStateSubscribe(id, port) {
2390
2417
  const cb = createSubscription(id, port);
2391
2418
  const keyringStateSubject = this.#koniState.keyringService.keyringStateSubject;
@@ -2396,6 +2423,9 @@ export default class KoniExtension {
2396
2423
  });
2397
2424
  return this.#koniState.keyringService.keyringState;
2398
2425
  }
2426
+
2427
+ // Change master password
2428
+
2399
2429
  keyringChangeMasterPassword({
2400
2430
  createNew,
2401
2431
  newPassword,
@@ -2431,6 +2461,9 @@ export default class KoniExtension {
2431
2461
  errors: []
2432
2462
  };
2433
2463
  }
2464
+
2465
+ // Migrate password
2466
+
2434
2467
  keyringMigrateMasterPassword({
2435
2468
  address,
2436
2469
  password
@@ -2449,6 +2482,9 @@ export default class KoniExtension {
2449
2482
  errors: []
2450
2483
  };
2451
2484
  }
2485
+
2486
+ // Unlock wallet
2487
+
2452
2488
  keyringUnlock({
2453
2489
  password
2454
2490
  }) {
@@ -2466,11 +2502,17 @@ export default class KoniExtension {
2466
2502
  errors: []
2467
2503
  };
2468
2504
  }
2505
+
2506
+ // Lock wallet
2507
+
2469
2508
  keyringLock() {
2470
2509
  keyring.lockAll();
2471
2510
  this.#koniState.updateKeyringState();
2472
2511
  clearTimeout(this.#lockTimeOut);
2473
2512
  }
2513
+
2514
+ // Export mnemonic
2515
+
2474
2516
  keyringExportMnemonic({
2475
2517
  address,
2476
2518
  password
@@ -2482,6 +2524,25 @@ export default class KoniExtension {
2482
2524
  };
2483
2525
  }
2484
2526
 
2527
+ // Reset wallet
2528
+
2529
+ async resetWallet({
2530
+ resetAll
2531
+ }) {
2532
+ try {
2533
+ await this.#koniState.resetWallet(resetAll);
2534
+ return {
2535
+ errors: [],
2536
+ status: true
2537
+ };
2538
+ } catch (e) {
2539
+ return {
2540
+ errors: [e.message],
2541
+ status: false
2542
+ };
2543
+ }
2544
+ }
2545
+
2485
2546
  /// Signing external request
2486
2547
  signingApprovePasswordV2({
2487
2548
  id
@@ -2584,7 +2645,7 @@ export default class KoniExtension {
2584
2645
  this._addAddressToAuthList(address, isAllowed);
2585
2646
  result.push(childPair);
2586
2647
  } catch (e) {
2587
- console.log(`Fail to derive from ${parentAddress} with path ${item.suri}`, e);
2648
+ console.log(e);
2588
2649
  }
2589
2650
  }
2590
2651
  if (result.length === 1) {
@@ -2828,7 +2889,7 @@ export default class KoniExtension {
2828
2889
  clearTimeout(this.#lockTimeOut);
2829
2890
  this.#lockTimeOut = setTimeout(() => {
2830
2891
  this.keyringLock();
2831
- }, DEFAULT_TIME_AUTO_LOCK);
2892
+ }, this.#timeAutoLock * 60 * 1000);
2832
2893
  switch (type) {
2833
2894
  /// Clone from PolkadotJs
2834
2895
  case 'pri(accounts.create.external)':
@@ -2908,7 +2969,9 @@ export default class KoniExtension {
2908
2969
  case 'pri(authorize.toggle)':
2909
2970
  return this.toggleAuthorization2(request);
2910
2971
  case 'pri(settings.changeBalancesVisibility)':
2911
- return this.toggleBalancesVisibility(id, port);
2972
+ return await this.toggleBalancesVisibility();
2973
+
2974
+ // Settings
2912
2975
  case 'pri(settings.subscribe)':
2913
2976
  return await this.subscribeSettings(id, port);
2914
2977
  case 'pri(settings.saveAccountAllLogo)':
@@ -2919,6 +2982,10 @@ export default class KoniExtension {
2919
2982
  return this.saveTheme(request, id, port);
2920
2983
  case 'pri(settings.saveBrowserConfirmationType)':
2921
2984
  return this.saveBrowserConfirmationType(request, id, port);
2985
+ case 'pri(settings.saveAutoLockTime)':
2986
+ return this.setAutoLockTime(request);
2987
+ case 'pri(settings.saveEnableChainPatrol)':
2988
+ return this.setEnableChainPatrol(request);
2922
2989
  case 'pri(price.getPrice)':
2923
2990
  return await this.getPrice();
2924
2991
  case 'pri(price.getSubscription)':
@@ -3154,6 +3221,8 @@ export default class KoniExtension {
3154
3221
  return this.keyringLock();
3155
3222
  case 'pri(keyring.export.mnemonic)':
3156
3223
  return this.keyringExportMnemonic(request);
3224
+ case 'pri(keyring.reset)':
3225
+ return await this.resetWallet(request);
3157
3226
 
3158
3227
  /// Signing external
3159
3228
  case 'pri(signing.approve.passwordV2)':