@subwallet/extension-base 1.0.5-2 → 1.0.6-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 (54) hide show
  1. package/background/KoniTypes.d.ts +7 -1
  2. package/cjs/constants/index.js +1 -1
  3. package/cjs/koni/api/staking/bonding/relayChain.js +2 -7
  4. package/cjs/koni/api/staking/bonding/utils.js +9 -0
  5. package/cjs/koni/api/staking/index.js +6 -3
  6. package/cjs/koni/api/staking/relayChain.js +16 -14
  7. package/cjs/koni/background/handlers/Extension.js +60 -46
  8. package/cjs/koni/background/handlers/State.js +16 -0
  9. package/cjs/koni/background/handlers/Tabs.js +47 -28
  10. package/cjs/packageInfo.js +1 -1
  11. package/cjs/services/chain-service/constants.js +3 -3
  12. package/cjs/services/chain-service/index.js +5 -0
  13. package/cjs/services/chain-service/utils.js +15 -10
  14. package/cjs/services/history-service/subsquid-multi-chain-history.js +2 -2
  15. package/cjs/services/request-service/index.js +3 -0
  16. package/cjs/services/setting-service/SettingService.js +14 -0
  17. package/cjs/services/storage-service/DatabaseService.js +1 -1
  18. package/cjs/services/storage-service/db-stores/Nft.js +3 -3
  19. package/cjs/services/transaction-service/index.js +11 -5
  20. package/cjs/services/transaction-service/utils.js +3 -0
  21. package/cjs/stores/PassPhishingStore.js +18 -0
  22. package/constants/index.d.ts +1 -1
  23. package/constants/index.js +1 -1
  24. package/koni/api/staking/bonding/relayChain.js +3 -8
  25. package/koni/api/staking/bonding/utils.d.ts +1 -0
  26. package/koni/api/staking/bonding/utils.js +8 -0
  27. package/koni/api/staking/index.js +6 -4
  28. package/koni/api/staking/relayChain.js +16 -14
  29. package/koni/background/handlers/Extension.d.ts +1 -0
  30. package/koni/background/handlers/Extension.js +61 -48
  31. package/koni/background/handlers/State.d.ts +1 -0
  32. package/koni/background/handlers/State.js +16 -0
  33. package/koni/background/handlers/Tabs.d.ts +2 -0
  34. package/koni/background/handlers/Tabs.js +47 -28
  35. package/package.json +11 -6
  36. package/packageInfo.js +1 -1
  37. package/services/chain-service/constants.js +3 -3
  38. package/services/chain-service/index.js +5 -0
  39. package/services/chain-service/utils.d.ts +1 -0
  40. package/services/chain-service/utils.js +14 -10
  41. package/services/history-service/subsquid-multi-chain-history.js +2 -2
  42. package/services/request-service/handler/AuthRequestHandler.d.ts +1 -1
  43. package/services/request-service/index.d.ts +1 -0
  44. package/services/request-service/index.js +3 -0
  45. package/services/setting-service/SettingService.d.ts +5 -1
  46. package/services/setting-service/SettingService.js +14 -0
  47. package/services/storage-service/DatabaseService.js +1 -1
  48. package/services/storage-service/db-stores/Nft.d.ts +1 -1
  49. package/services/storage-service/db-stores/Nft.js +3 -3
  50. package/services/transaction-service/index.js +11 -5
  51. package/services/transaction-service/types.d.ts +3 -3
  52. package/services/transaction-service/utils.js +3 -0
  53. package/stores/PassPhishingStore.d.ts +5 -0
  54. package/stores/PassPhishingStore.js +10 -0
@@ -129,7 +129,7 @@ class TransactionService {
129
129
  } else {
130
130
  var _pair$meta;
131
131
  if ((_pair$meta = pair.meta) !== null && _pair$meta !== void 0 && _pair$meta.isReadOnly) {
132
- validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR, 'This is read-only account'));
132
+ validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR, 'This is watch-only account'));
133
133
  }
134
134
  }
135
135
 
@@ -168,8 +168,8 @@ class TransactionService {
168
168
  const transactionId = (0, _helpers.getTransactionId)(transaction.chainType, transaction.chain, isInternal);
169
169
  return {
170
170
  ...transaction,
171
- createdAt: new Date(),
172
- updatedAt: new Date(),
171
+ createdAt: new Date().getTime(),
172
+ updatedAt: new Date().getTime(),
173
173
  errors: transaction.errors || [],
174
174
  warnings: transaction.warnings || [],
175
175
  url: transaction.url || _constants2.EXTENSION_REQUEST_URL,
@@ -210,6 +210,9 @@ class TransactionService {
210
210
  const stopByErrors = validatedTransaction.errors.length > 0;
211
211
  const stopByWarnings = validatedTransaction.warnings.length > 0 && !validatedTransaction.ignoreWarnings;
212
212
  if (stopByErrors || stopByWarnings) {
213
+ // @ts-ignore
214
+ 'transaction' in validatedTransaction && delete validatedTransaction.transaction;
215
+ 'additionalValidator' in validatedTransaction && delete validatedTransaction.additionalValidator;
213
216
  return validatedTransaction;
214
217
  }
215
218
  validatedTransaction.warnings = [];
@@ -227,6 +230,10 @@ class TransactionService {
227
230
  }
228
231
  });
229
232
  });
233
+
234
+ // @ts-ignore
235
+ 'transaction' in validatedTransaction && delete validatedTransaction.transaction;
236
+ 'additionalValidator' in validatedTransaction && delete validatedTransaction.additionalValidator;
230
237
  return validatedTransaction;
231
238
  }
232
239
  async sendTransaction(transaction) {
@@ -293,7 +300,7 @@ class TransactionService {
293
300
  status: transaction.status,
294
301
  transactionId: transaction.id,
295
302
  extrinsicHash: transaction.extrinsicHash,
296
- time: transaction.createdAt.getTime(),
303
+ time: transaction.createdAt,
297
304
  fee: transaction.estimateFee,
298
305
  blockNumber: 0,
299
306
  // Will be added in next step
@@ -302,7 +309,6 @@ class TransactionService {
302
309
  nonce: nonce || 0,
303
310
  startBlock: startBlock || 0
304
311
  };
305
- console.log('historyItem', historyItem);
306
312
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
307
313
  const nativeAsset = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
308
314
  const baseNativeAmount = {
@@ -27,6 +27,9 @@ function getBlockExplorerTxRoute(chainInfo) {
27
27
  if ((0, _utils._isPureEvmChain)(chainInfo)) {
28
28
  return 'tx';
29
29
  }
30
+ if (['aventus'].includes(chainInfo.slug)) {
31
+ return 'transaction';
32
+ }
30
33
  return 'extrinsic';
31
34
  }
32
35
  function getExplorerLink(chainInfo, value, type) {
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _defaults = require("@subwallet/extension-base/defaults");
9
+ var _SubscribableStore = _interopRequireDefault(require("@subwallet/extension-base/stores/SubscribableStore"));
10
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class PassPhishingStore extends _SubscribableStore.default {
14
+ constructor() {
15
+ super(_defaults.EXTENSION_PREFIX ? `${_defaults.EXTENSION_PREFIX}subwallet-pass-phishing-list` : null);
16
+ }
17
+ }
18
+ exports.default = PassPhishingStore;
@@ -6,7 +6,7 @@ export declare const ASTAR_REFRESH_BALANCE_INTERVAL = 60000;
6
6
  export declare const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
7
7
  export declare const CRON_REFRESH_NFT_INTERVAL = 7200000;
8
8
  export declare const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
9
- export declare const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 300000;
9
+ export declare const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 45000;
10
10
  export declare const CRON_REFRESH_HISTORY_INTERVAL = 900000;
11
11
  export declare const CRON_GET_API_MAP_STATUS = 10000;
12
12
  export declare const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
@@ -9,7 +9,7 @@ export const ASTAR_REFRESH_BALANCE_INTERVAL = 60000;
9
9
  export const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
10
10
  export const CRON_REFRESH_NFT_INTERVAL = 7200000;
11
11
  export const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
12
- export const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 300000;
12
+ export const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 45000;
13
13
  export const CRON_REFRESH_HISTORY_INTERVAL = 900000;
14
14
  export const CRON_GET_API_MAP_STATUS = 10000;
15
15
  export const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
@@ -5,7 +5,7 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
5
5
  import { StakingStatus, StakingTxErrorType, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
6
6
  import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculateInflation, calculateValidatorStakedReturn, getCommission, parseIdentity, parsePoolStashAddress, transformPoolName } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
7
7
  import { _STAKING_CHAIN_GROUP, _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
8
- import { _getChainNativeTokenBasicInfo, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
8
+ import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
9
9
  import { reformatAddress } from '@subwallet/extension-base/utils';
10
10
  import { BN, BN_ZERO } from '@polkadot/util';
11
11
  import { isEthereumAddress } from '@polkadot/util-crypto';
@@ -13,7 +13,7 @@ export function validateRelayUnbondingCondition(amount, chainStakingMetadata, no
13
13
  const errors = [];
14
14
  const bnActiveStake = new BN(nominatorMetadata.activeStake);
15
15
  const bnRemainingStake = bnActiveStake.sub(new BN(amount));
16
- const minStake = new BN(chainStakingMetadata.minPoolBonding || '0');
16
+ const minStake = new BN(chainStakingMetadata.minJoinNominationPool || '0');
17
17
  if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
18
18
  errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE));
19
19
  }
@@ -27,7 +27,7 @@ export function validatePoolBondingCondition(chainInfo, amount, selectedPool, ad
27
27
  // amount >= min stake
28
28
  const errors = [];
29
29
  let bnTotalStake = new BN(amount);
30
- const bnMinStake = new BN(chainStakingMetadata.minPoolBonding || '0');
30
+ const bnMinStake = new BN(chainStakingMetadata.minJoinNominationPool || '0');
31
31
  if (selectedPool.state !== 'Open') {
32
32
  errors.push(new TransactionError(StakingTxErrorType.INACTIVE_NOMINATION_POOL));
33
33
  }
@@ -69,9 +69,6 @@ export function validateRelayBondingCondition(chainInfo, amount, selectedValidat
69
69
  export async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
70
70
  var _chainApi$api$query$a, _chainApi$api$query, _chainApi$api$query$s, _chainApi$api$query2, _chainApi$api$query2$, _chainApi$api$query3, _chainApi$api$query3$;
71
71
  const chain = chainInfo.slug;
72
- const {
73
- decimals
74
- } = _getChainNativeTokenBasicInfo(chainInfo);
75
72
  const chainApi = await substrateApi.isReady;
76
73
  const _era = await chainApi.api.query.staking.currentEra();
77
74
  const currentEra = _era.toString();
@@ -115,8 +112,6 @@ export async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
115
112
  // in %, annually
116
113
  inflation,
117
114
  minStake: minStake.toString(),
118
- minPoolBonding: (10 ** decimals).toString(),
119
- // default is 1
120
115
  maxValidatorPerNominator: parseInt(maxNominations),
121
116
  maxWithdrawalRequestPerValidator: parseInt(maxUnlockingChunks),
122
117
  allowCancelUnstaking: true,
@@ -153,3 +153,4 @@ export declare function getStakingAvailableActionsByNominator(nominatorMetadata:
153
153
  export declare function isActionFromValidator(stakingType: StakingType, chain: string): boolean;
154
154
  export declare function getWithdrawalInfo(nominatorMetadata: NominatorMetadata): UnstakingInfo | undefined;
155
155
  export declare function getStakingStatusByNominations(bnTotalActiveStake: BN, nominationList: NominationInfo[]): StakingStatus;
156
+ export declare function getValidatorLabel(chain: string): "dApp" | "Validator" | "Collator";
@@ -241,4 +241,12 @@ export function getStakingStatusByNominations(bnTotalActiveStake, nominationList
241
241
  }
242
242
  }
243
243
  return stakingStatus;
244
+ }
245
+ export function getValidatorLabel(chain) {
246
+ if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
247
+ return 'dApp';
248
+ } else if (_STAKING_CHAIN_GROUP.relay.includes(chain)) {
249
+ return 'Validator';
250
+ }
251
+ return 'Collator';
244
252
  }
@@ -5,7 +5,7 @@ import { getAmplitudeStakingOnChain, getAstarStakingOnChain, getParaStakingOnCha
5
5
  import { getNominationPoolReward, getRelayPoolingOnChain, getRelayStakingOnChain } from '@subwallet/extension-base/koni/api/staking/relayChain';
6
6
  import { getAllSubsquidStaking } from '@subwallet/extension-base/koni/api/staking/subsquidStaking';
7
7
  import { _PURE_EVM_CHAINS, _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
8
- import { _isChainEvmCompatible, _isChainSupportSubstrateStaking } from '@subwallet/extension-base/services/chain-service/utils';
8
+ import { _isChainEvmCompatible, _isChainSupportSubstrateStaking, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
9
9
  import { categoryAddresses } from '@subwallet/extension-base/utils';
10
10
  export function stakingOnChainApi(addresses, substrateApiMap, callback, chainInfoMap) {
11
11
  const filteredApiMap = [];
@@ -57,11 +57,13 @@ export async function getNominationStakingRewardData(addresses, chainInfoMap) {
57
57
  }
58
58
  export async function getPoolingStakingRewardData(addresses, networkMap, dotSamaApiMap) {
59
59
  const activeNetworks = [];
60
- Object.keys(networkMap).forEach(key => {
61
- activeNetworks.push(key);
60
+ Object.entries(networkMap).forEach(([key, chainInfo]) => {
61
+ if (_isChainSupportSubstrateStaking(chainInfo) && _isSubstrateRelayChain(chainInfo)) {
62
+ activeNetworks.push(key);
63
+ }
62
64
  });
63
65
  if (activeNetworks.length === 0) {
64
66
  return [];
65
67
  }
66
- return await getNominationPoolReward(addresses, networkMap, dotSamaApiMap);
68
+ return getNominationPoolReward(addresses, networkMap, dotSamaApiMap);
67
69
  }
@@ -138,20 +138,22 @@ export async function getNominationPoolReward(addresses, chainInfoMap, substrate
138
138
  try {
139
139
  await Promise.all(targetNetworks.map(async networkKey => {
140
140
  const substrateApi = await substrateApiMap[networkKey].isReady;
141
- await Promise.all(validAddresses.map(async address => {
142
- var _substrateApi$api$cal, _substrateApi$api$cal2;
143
- const _unclaimedReward = await ((_substrateApi$api$cal = substrateApi.api.call) === null || _substrateApi$api$cal === void 0 ? void 0 : (_substrateApi$api$cal2 = _substrateApi$api$cal.nominationPoolsApi) === null || _substrateApi$api$cal2 === void 0 ? void 0 : _substrateApi$api$cal2.pendingRewards(address));
144
- if (_unclaimedReward) {
145
- rewardList.push({
146
- address: address,
147
- chain: networkKey,
148
- unclaimedReward: _unclaimedReward.toString(),
149
- name: chainInfoMap[networkKey].name,
150
- state: APIItemState.READY,
151
- type: StakingType.POOLED
152
- });
153
- }
154
- }));
141
+ if (substrateApi.api.call.nominationPoolsApi) {
142
+ await Promise.all(validAddresses.map(async address => {
143
+ var _substrateApi$api$cal, _substrateApi$api$cal2;
144
+ const _unclaimedReward = await ((_substrateApi$api$cal = substrateApi.api.call) === null || _substrateApi$api$cal === void 0 ? void 0 : (_substrateApi$api$cal2 = _substrateApi$api$cal.nominationPoolsApi) === null || _substrateApi$api$cal2 === void 0 ? void 0 : _substrateApi$api$cal2.pendingRewards(address));
145
+ if (_unclaimedReward) {
146
+ rewardList.push({
147
+ address: address,
148
+ chain: networkKey,
149
+ unclaimedReward: _unclaimedReward.toString(),
150
+ name: chainInfoMap[networkKey].name,
151
+ state: APIItemState.READY,
152
+ type: StakingType.POOLED
153
+ });
154
+ }
155
+ }));
156
+ }
155
157
  }));
156
158
  } catch (e) {
157
159
  return rewardList;
@@ -188,5 +188,6 @@ export default class KoniExtension {
188
188
  private subscribeNotifications;
189
189
  private reloadCron;
190
190
  private getLogoMap;
191
+ private passPhishingPage;
191
192
  handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
192
193
  }
@@ -18,7 +18,7 @@ import { getPoolingBondingExtrinsic, getPoolingUnbondingExtrinsic, validatePoolB
18
18
  import { getERC20TransactionObject, getERC721Transaction, getEVMTransactionObject } from '@subwallet/extension-base/koni/api/tokens/evm/transfer';
19
19
  import { getPSP34TransferExtrinsic } from '@subwallet/extension-base/koni/api/tokens/wasm';
20
20
  import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
21
- import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isNativeToken, _isTokenEvmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
21
+ import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isNativeToken, _isTokenEvmSmartContract, _isTokenTransferredByEvm } from '@subwallet/extension-base/services/chain-service/utils';
22
22
  import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
23
23
  import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
24
24
  import { reformatAddress } from '@subwallet/extension-base/utils';
@@ -31,7 +31,7 @@ import BigN from 'bignumber.js';
31
31
  import { Transaction } from 'ethereumjs-tx';
32
32
  import { TypeRegistry } from '@polkadot/types';
33
33
  import { assert, BN, BN_ZERO, hexStripPrefix, hexToU8a, isAscii, isHex, u8aToHex, u8aToString } from '@polkadot/util';
34
- import { base64Decode, decodeAddress, isAddress, isEthereumAddress, jsonDecrypt, keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
34
+ import { addressToEvm, base64Decode, decodeAddress, isAddress, isEthereumAddress, jsonDecrypt, keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
35
35
  const ETH_DERIVE_DEFAULT = '/m/44\'/60\'/0\'/0/0';
36
36
  function getSuri(seed, type) {
37
37
  return type === 'ethereum' ? `${seed}${ETH_DERIVE_DEFAULT}` : seed;
@@ -1398,7 +1398,8 @@ export default class KoniExtension {
1398
1398
 
1399
1399
  // Get native token amount
1400
1400
  const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
1401
- if (isEthereumAddress(from) && isEthereumAddress(to)) {
1401
+ if (isEthereumAddress(from) && isEthereumAddress(to) && _isTokenTransferredByEvm(tokenInfo)) {
1402
+ // TODO: review this
1402
1403
  chainType = ChainType.EVM;
1403
1404
  const txVal = transferAll ? freeBalance.value : value || '0';
1404
1405
 
@@ -1589,61 +1590,60 @@ export default class KoniExtension {
1589
1590
  const substrateApi = this.#koniState.chainService.getSubstrateApi(networkKey);
1590
1591
  let estimatedFee;
1591
1592
  let maxTransferable = new BN(freeBalance.value);
1592
- if (isXcmTransfer) {
1593
- const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
1594
- const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, tokenInfo.slug);
1595
- if (!destinationTokenInfo) {
1596
- estimatedFee = '0';
1597
- } else {
1598
- maxTransferable = maxTransferable.sub(new BN(tokenInfo.minAmount || '0'));
1599
- const mockTx = await createXcmExtrinsic({
1600
- chainInfoMap,
1601
- destinationTokenInfo,
1602
- originTokenInfo: tokenInfo,
1603
- recipient: address,
1604
- sendingValue: '0',
1605
- substrateApi
1606
- });
1607
- try {
1593
+ try {
1594
+ if (isXcmTransfer) {
1595
+ const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
1596
+ const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, tokenInfo.slug);
1597
+ if (!destinationTokenInfo) {
1598
+ estimatedFee = '0';
1599
+ } else {
1608
1600
  var _paymentInfo$partialF;
1601
+ maxTransferable = maxTransferable.sub(new BN(tokenInfo.minAmount || '0'));
1602
+ const desChainInfo = chainInfoMap[destChain];
1603
+ const orgChainInfo = chainInfoMap[networkKey];
1604
+ const recipient = !isEthereumAddress(address) && _isChainEvmCompatible(desChainInfo) && !_isChainEvmCompatible(orgChainInfo) ? u8aToHex(addressToEvm(address)) : address;
1605
+ const mockTx = await createXcmExtrinsic({
1606
+ chainInfoMap,
1607
+ destinationTokenInfo,
1608
+ originTokenInfo: tokenInfo,
1609
+ recipient: recipient,
1610
+ sendingValue: '0',
1611
+ substrateApi
1612
+ });
1609
1613
  const paymentInfo = await mockTx.paymentInfo(address);
1610
1614
  estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0';
1611
- } catch (e) {
1612
- estimatedFee = '0';
1613
- console.warn(e);
1614
1615
  }
1615
- }
1616
- } else {
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
1616
  } 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 {
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: 0,
1622
+ to: '0x0000000000000000000000000000000000000000',
1623
+ // null address
1624
+ from: address
1625
+ };
1626
+ const gasPrice = await web3.api.eth.getGasPrice();
1627
+ const gasLimit = await web3.api.eth.estimateGas(transaction);
1628
+ estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
1629
+ } else {
1639
1630
  var _paymentInfo$partialF2;
1631
+ const [mockTx] = await createTransferExtrinsic({
1632
+ from: address,
1633
+ networkKey,
1634
+ substrateApi,
1635
+ to: address,
1636
+ tokenInfo,
1637
+ transferAll: true,
1638
+ value: '0'
1639
+ });
1640
1640
  const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
1641
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
1642
  }
1646
1643
  }
1644
+ } catch (e) {
1645
+ estimatedFee = '0';
1646
+ console.warn('Error estimating fee', e);
1647
1647
  }
1648
1648
  maxTransferable = maxTransferable.sub(new BN(estimatedFee));
1649
1649
  return {
@@ -2837,6 +2837,7 @@ export default class KoniExtension {
2837
2837
  function convertRs(rs) {
2838
2838
  return Object.fromEntries(Object.entries(rs).map(([key, value]) => {
2839
2839
  const {
2840
+ additionalValidator,
2840
2841
  transaction,
2841
2842
  ...transactionResult
2842
2843
  } = value;
@@ -2883,6 +2884,14 @@ export default class KoniExtension {
2883
2884
  };
2884
2885
  }
2885
2886
 
2887
+ // Phishing detect
2888
+
2889
+ async passPhishingPage({
2890
+ url
2891
+ }) {
2892
+ return await this.#koniState.approvePassPhishingPage(url);
2893
+ }
2894
+
2886
2895
  // --------------------------------------------------------------
2887
2896
  // eslint-disable-next-line @typescript-eslint/require-await
2888
2897
  async handle(id, type, request, port) {
@@ -3208,6 +3217,10 @@ export default class KoniExtension {
3208
3217
  case 'pri(authorize.subscribe)':
3209
3218
  return await this.subscribeAuthUrls(id, port);
3210
3219
 
3220
+ // Phishing page
3221
+ case 'pri(phishing.pass)':
3222
+ return await this.passPhishingPage(request);
3223
+
3211
3224
  /// Keyring state
3212
3225
  case 'pri(keyring.subscribe)':
3213
3226
  return this.keyringStateSubscribe(id, port);
@@ -223,6 +223,7 @@ export default class KoniState {
223
223
  onAccountRemove(): void;
224
224
  reloadNft(): Promise<boolean>;
225
225
  reloadStaking(): Promise<boolean>;
226
+ approvePassPhishingPage(_url: string): Promise<boolean>;
226
227
  resetWallet(resetAll: boolean): Promise<void>;
227
228
  }
228
229
  export {};
@@ -1441,6 +1441,22 @@ export default class KoniState {
1441
1441
  async reloadStaking() {
1442
1442
  return await this.cron.reloadStaking();
1443
1443
  }
1444
+ async approvePassPhishingPage(_url) {
1445
+ return new Promise(resolve => {
1446
+ this.settingService.getPassPhishingList(value => {
1447
+ const result = {
1448
+ ...value
1449
+ };
1450
+ const url = this.requestService.stripUrl(_url);
1451
+ result[url] = {
1452
+ pass: true
1453
+ };
1454
+ this.settingService.setPassPhishing(result, () => {
1455
+ resolve(true);
1456
+ });
1457
+ });
1458
+ });
1459
+ }
1444
1460
  async resetWallet(resetAll) {
1445
1461
  this.keyringService.resetWallet(resetAll);
1446
1462
  this.requestService.resetWallet();
@@ -20,6 +20,8 @@ export default class KoniTabs {
20
20
  private rpcSubscribeConnected;
21
21
  private rpcUnsubscribe;
22
22
  private redirectPhishingLanding;
23
+ private checkPassList;
24
+ protected checkPhishing(url: string): Promise<boolean>;
23
25
  protected redirectIfPhishing(url: string): Promise<boolean>;
24
26
  private cancelSubscription;
25
27
  private createUnsubscriptionHandle;
@@ -84,6 +84,7 @@ export default class KoniTabs {
84
84
  #koniState;
85
85
  evmEventEmitterMap = {};
86
86
  #chainPatrolService = DEFAULT_CHAIN_PATROL_ENABLE;
87
+ #passPhishing = {};
87
88
  constructor(koniState) {
88
89
  this.#koniState = koniState;
89
90
  const updateChainPatrolService = rs => {
@@ -93,6 +94,13 @@ export default class KoniTabs {
93
94
  this.#koniState.settingService.getSubject().subscribe({
94
95
  next: updateChainPatrolService
95
96
  });
97
+ const updatePassPhishing = rs => {
98
+ this.#passPhishing = rs;
99
+ };
100
+ this.#koniState.settingService.getPassPhishingList(updatePassPhishing);
101
+ this.#koniState.settingService.passPhishingSubject().subscribe({
102
+ next: updatePassPhishing
103
+ });
96
104
  }
97
105
 
98
106
  /// Clone from Polkadot.js
@@ -179,21 +187,31 @@ export default class KoniTabs {
179
187
  })));
180
188
  });
181
189
  }
182
- async redirectIfPhishing(url) {
190
+ checkPassList(_url) {
191
+ const url = stripUrl(_url);
192
+ const result = this.#passPhishing[url];
193
+ return result ? !result.pass : true;
194
+ }
195
+ async checkPhishing(url) {
183
196
  const isInDenyList = await checkIfDenied(url);
184
197
  if (isInDenyList) {
185
- this.redirectPhishingLanding(url);
186
- return true;
198
+ return this.checkPassList(url);
187
199
  }
188
200
  if (this.#chainPatrolService) {
189
201
  const isInChainPatrolDenyList = await chainPatrolCheckUrl(url);
190
202
  if (isInChainPatrolDenyList) {
191
- this.redirectPhishingLanding(url);
192
- return true;
203
+ return this.checkPassList(url);
193
204
  }
194
205
  }
195
206
  return false;
196
207
  }
208
+ async redirectIfPhishing(url) {
209
+ const result = await this.checkPhishing(url);
210
+ if (result) {
211
+ this.redirectPhishingLanding(url);
212
+ }
213
+ return result;
214
+ }
197
215
 
198
216
  ///
199
217
 
@@ -401,35 +419,36 @@ export default class KoniTabs {
401
419
  const chainIdNum = parseInt(chainId, 16);
402
420
  const [existedNetworkSlug, existedChainInfo] = this.#koniState.findNetworkKeyByChainId(chainIdNum);
403
421
  if (existedNetworkSlug && existedChainInfo && existedChainInfo !== null && existedChainInfo !== void 0 && existedChainInfo.evmInfo) {
404
- const evmInfo = existedChainInfo.evmInfo;
405
- const substrateInfo = existedChainInfo.substrateInfo;
406
- const chainState = this.#koniState.getChainStateByKey(existedNetworkSlug);
407
- await this.#koniState.addNetworkConfirm(id, url, {
408
- mode: 'update',
409
- chainSpec: {
410
- evmChainId: evmInfo.evmChainId,
411
- decimals: evmInfo.decimals,
412
- existentialDeposit: evmInfo.existentialDeposit,
413
- genesisHash: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.genesisHash) || '',
414
- paraId: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.paraId) || null,
415
- addressPrefix: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.addressPrefix) || 0
416
- },
417
- chainEditInfo: {
418
- blockExplorer: blockExplorerUrls === null || blockExplorerUrls === void 0 ? void 0 : blockExplorerUrls[0],
419
- slug: existedNetworkSlug,
420
- currentProvider: chainState.currentProvider,
421
- providers: existedChainInfo.providers,
422
- symbol: evmInfo.symbol,
423
- chainType: 'EVM',
424
- name: existedChainInfo.name
425
- }
426
- });
427
422
  return await this.switchEvmChain(id, url, {
428
423
  method: 'wallet_switchEthereumChain',
429
424
  params: [{
430
425
  chainId
431
426
  }]
432
427
  });
428
+ // const evmInfo = existedChainInfo.evmInfo;
429
+ // const substrateInfo = existedChainInfo.substrateInfo;
430
+ // const chainState = this.#koniState.getChainStateByKey(existedNetworkSlug);
431
+ //
432
+ // return await this.#koniState.addNetworkConfirm(id, url, {
433
+ // mode: 'update',
434
+ // chainSpec: {
435
+ // evmChainId: evmInfo.evmChainId,
436
+ // decimals: evmInfo.decimals,
437
+ // existentialDeposit: evmInfo.existentialDeposit,
438
+ // genesisHash: substrateInfo?.genesisHash || '',
439
+ // paraId: substrateInfo?.paraId || null,
440
+ // addressPrefix: substrateInfo?.addressPrefix || 0
441
+ // },
442
+ // chainEditInfo: {
443
+ // blockExplorer: blockExplorerUrls?.[0],
444
+ // slug: existedNetworkSlug,
445
+ // currentProvider: chainState.currentProvider,
446
+ // providers: existedChainInfo.providers,
447
+ // symbol: evmInfo.symbol,
448
+ // chainType: 'EVM',
449
+ // name: existedChainInfo.name
450
+ // }
451
+ // });
433
452
  } else if (rpcUrls && chainName) {
434
453
  const filteredUrls = rpcUrls.filter(targetString => {
435
454
  let url;
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.0.5-2",
20
+ "version": "1.0.6-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -1555,6 +1555,11 @@
1555
1555
  "require": "./cjs/stores/Metadata.js",
1556
1556
  "default": "./stores/Metadata.js"
1557
1557
  },
1558
+ "./stores/PassPhishingStore": {
1559
+ "types": "./stores/PassPhishingStore.d.ts",
1560
+ "require": "./cjs/stores/PassPhishingStore.js",
1561
+ "default": "./stores/PassPhishingStore.js"
1562
+ },
1558
1563
  "./stores/Settings": {
1559
1564
  "types": "./stores/Settings.d.ts",
1560
1565
  "require": "./cjs/stores/Settings.js",
@@ -1692,11 +1697,11 @@
1692
1697
  "@sora-substrate/type-definitions": "^1.17.7",
1693
1698
  "@subsocial/types": "^0.6.8",
1694
1699
  "@substrate/connect": "^0.7.26",
1695
- "@subwallet/chain-list": "^0.1.2",
1696
- "@subwallet/extension-base": "^1.0.5-2",
1697
- "@subwallet/extension-chains": "^1.0.5-2",
1698
- "@subwallet/extension-dapp": "^1.0.5-2",
1699
- "@subwallet/extension-inject": "^1.0.5-2",
1700
+ "@subwallet/chain-list": "^0.1.7",
1701
+ "@subwallet/extension-base": "^1.0.6-0",
1702
+ "@subwallet/extension-chains": "^1.0.6-0",
1703
+ "@subwallet/extension-dapp": "^1.0.6-0",
1704
+ "@subwallet/extension-inject": "^1.0.6-0",
1700
1705
  "@subwallet/keyring": "^0.0.9",
1701
1706
  "@subwallet/ui-keyring": "^0.0.9",
1702
1707
  "@unique-nft/types": "^0.6.0-4",
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.0.5-2'
10
+ version: '1.0.6-0'
11
11
  };
@@ -26,7 +26,7 @@ export const _BALANCE_CHAIN_GROUP = {
26
26
  genshiro: ['genshiro_testnet', 'genshiro'],
27
27
  equilibrium_parachain: ['equilibrium_parachain'],
28
28
  bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry'],
29
- statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain'],
29
+ statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2'],
30
30
  kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'] // perhaps there are some runtime updates
31
31
  };
32
32
 
@@ -55,7 +55,7 @@ export const _STAKING_CHAIN_GROUP = {
55
55
  kilt: ['kilt', 'kilt_peregrine'],
56
56
  nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph'],
57
57
  bifrost: ['bifrost', 'bifrost_testnet'],
58
- aleph: ['aleph, alephTest'] // A0 has distinct tokenomics
58
+ aleph: ['aleph', 'alephTest'] // A0 has distinct tokenomics
59
59
  };
60
60
 
61
61
  export const _STAKING_ERA_LENGTH_MAP = {
@@ -179,7 +179,7 @@ export const _TRANSFER_CHAIN_GROUP = {
179
179
  genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
180
180
  crab: ['crab', 'pangolin'],
181
181
  bitcountry: ['pioneer', 'bitcountry'],
182
- statemine: ['statemint', 'statemine']
182
+ statemine: ['statemint', 'statemine', 'darwinia2']
183
183
  };
184
184
  export const _BALANCE_PARSING_CHAIN_GROUP = {
185
185
  bobabeam: ['bobabeam', 'bobabase']