@subwallet/extension-base 1.2.11-0 → 1.2.12-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.
@@ -951,6 +951,7 @@ export interface EvmSendTransactionParams {
951
951
  maxFeePerGas?: string | number;
952
952
  gasPrice?: string | number;
953
953
  data?: string;
954
+ gas?: string | number;
954
955
  }
955
956
  export interface SwitchNetworkRequest {
956
957
  networkKey: string;
@@ -3015,7 +3015,6 @@ class KoniExtension {
3015
3015
  payload
3016
3016
  } = request;
3017
3017
  let registry;
3018
- let isEvm = false;
3019
3018
  if (isJsonPayload(payload)) {
3020
3019
  const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
3021
3020
  let metadata;
@@ -3069,9 +3068,6 @@ class KoniExtension {
3069
3068
  registry = this.#koniState.getSubstrateApi(chainInfo.slug).api.registry;
3070
3069
  }
3071
3070
  }
3072
- if (chainInfo) {
3073
- isEvm = (0, _utils3._isChainEvmCompatible)(chainInfo);
3074
- }
3075
3071
  } else {
3076
3072
  // for non-payload, just create a registry to use
3077
3073
  registry = new _types3.TypeRegistry();
@@ -3080,7 +3076,7 @@ class KoniExtension {
3080
3076
  resolve({
3081
3077
  id,
3082
3078
  // In case evm chain, must be cut 2 character after 0x
3083
- signature: isEvm ? `0x${result.signature.slice(4)}` : result.signature
3079
+ signature: result.signature
3084
3080
  });
3085
3081
  if (this.#alwaysLock) {
3086
3082
  this.keyringLock();
@@ -1225,35 +1225,38 @@ class KoniState {
1225
1225
  from: transactionParams.from,
1226
1226
  to: transactionParams.to,
1227
1227
  value: autoFormatNumber(transactionParams.value),
1228
- gasPrice: autoFormatNumber(transactionParams.gasPrice),
1228
+ gas: autoFormatNumber(transactionParams.gas),
1229
+ gasPrice: autoFormatNumber(transactionParams.gasPrice || transactionParams.gasLimit),
1229
1230
  maxPriorityFeePerGas: autoFormatNumber(transactionParams.maxPriorityFeePerGas),
1230
1231
  maxFeePerGas: autoFormatNumber(transactionParams.maxFeePerGas),
1231
1232
  data: transactionParams.data
1232
1233
  };
1233
- const getTransactionGas = async () => {
1234
+ if (!transactionParams.gas) {
1235
+ const getTransactionGas = async () => {
1236
+ try {
1237
+ transaction.gas = await web3.eth.estimateGas({
1238
+ ...transaction
1239
+ });
1240
+ } catch (e) {
1241
+ // @ts-ignore
1242
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1243
+ throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1244
+ }
1245
+ };
1246
+
1247
+ // Calculate transaction data
1234
1248
  try {
1235
- transaction.gas = await web3.eth.estimateGas({
1236
- ...transaction
1237
- });
1249
+ await Promise.race([getTransactionGas(), (0, _utils3.wait)(3000).then(async () => {
1250
+ if (!transaction.gas) {
1251
+ await this.chainService.initSingleApi(networkKey);
1252
+ await getTransactionGas();
1253
+ }
1254
+ })]);
1238
1255
  } catch (e) {
1239
1256
  // @ts-ignore
1240
1257
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1241
1258
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1242
1259
  }
1243
- };
1244
-
1245
- // Calculate transaction data
1246
- try {
1247
- await Promise.race([getTransactionGas(), (0, _utils3.wait)(3000).then(async () => {
1248
- if (!transaction.gas) {
1249
- await this.chainService.initSingleApi(networkKey);
1250
- await getTransactionGas();
1251
- }
1252
- })]);
1253
- } catch (e) {
1254
- // @ts-ignore
1255
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1256
- throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1257
1260
  }
1258
1261
  if (!transaction.gas) {
1259
1262
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS);
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.2.11-0'
16
+ version: '1.2.12-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -37,24 +37,22 @@ async function getSnowBridgeEvmTransfer(tokenInfo, originChainInfo, destinationC
37
37
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
38
38
  const transferEncodedCall = transferCall.encodeABI();
39
39
  const [priority, sendTokenFee] = await Promise.all([(0, _utils3.calculateGasFeeParams)(evmApi, evmApi.chainSlug), getSendFeeToken(snowBridgeContract, tokenContract, destinationChainParaId, destinationFee)]);
40
- let gasLimit;
41
- try {
42
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
43
- gasLimit = await transferCall.estimateGas({
44
- from: sender
45
- });
46
- } catch (e) {
47
- gasLimit = 200000; // todo: handle this better
48
- }
49
-
50
- return {
40
+ const transactionConfig = {
51
41
  from: sender,
52
42
  to: snowBridgeContractAddress,
53
43
  value: sendTokenFee,
54
44
  data: transferEncodedCall,
55
- gas: gasLimit,
56
45
  gasPrice: priority.gasPrice,
57
46
  maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
58
47
  maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
59
48
  };
49
+ let gasLimit;
50
+ try {
51
+ gasLimit = await evmApi.api.eth.estimateGas(transactionConfig);
52
+ } catch (e) {
53
+ gasLimit = 200000; // todo: handle this better
54
+ }
55
+
56
+ transactionConfig.gas = gasLimit;
57
+ return transactionConfig;
60
58
  }
@@ -22,12 +22,13 @@ var _logger = require("@polkadot/util/logger");
22
22
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
23
23
  // SPDX-License-Identifier: Apache-2.0
24
24
 
25
- const filterChainInfoMap = data => {
25
+ const filterChainInfoMap = (data, ignoredChains) => {
26
26
  return Object.fromEntries(Object.entries(data).filter(_ref => {
27
- let [, info] = _ref;
28
- return !info.bitcoinInfo;
27
+ let [slug, info] = _ref;
28
+ return !info.bitcoinInfo && !ignoredChains.includes(slug);
29
29
  }));
30
30
  };
31
+ const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest'];
31
32
  const filterAssetInfoMap = (chainInfo, assets) => {
32
33
  return Object.fromEntries(Object.entries(assets).filter(_ref2 => {
33
34
  let [, info] = _ref2;
@@ -857,7 +858,7 @@ class ChainService {
857
858
  }
858
859
  async initChains() {
859
860
  const storedChainSettings = await this.dbService.getAllChainStore();
860
- const defaultChainInfoMap = filterChainInfoMap(_chainList.ChainInfoMap);
861
+ const defaultChainInfoMap = filterChainInfoMap(_chainList.ChainInfoMap, ignoredList);
861
862
  const storedChainSettingMap = {};
862
863
  storedChainSettings.forEach(chainStoredSetting => {
863
864
  storedChainSettingMap[chainStoredSetting.slug] = chainStoredSetting;
@@ -98,7 +98,7 @@ class InterlayLendingPoolHandler extends _base.default {
98
98
  for (let i = 0; i < balances.length; i++) {
99
99
  const balanceItem = balances[i];
100
100
  const address = useAddresses[i];
101
- const bnActiveBalance = balanceItem.free || _util.BN_ZERO;
101
+ const bnActiveBalance = balanceItem.reserved || _util.BN_ZERO;
102
102
  const bnTotalBalance = bnActiveBalance.mul(new _util.BN(exchangeRate)).div(decimals);
103
103
  const result = {
104
104
  ...this.baseInfo,
@@ -10,7 +10,7 @@ exports.getShortMetadata = exports.getMetadataHash = exports._isRuntimeUpdated =
10
10
  const LEDGER_API_URL = 'https://ledger-api.subwallet.app';
11
11
  const createUrl = path => `${LEDGER_API_URL}/${path}`;
12
12
  const _isRuntimeUpdated = signedExtensions => {
13
- return signedExtensions.includes('CheckMetadataHash');
13
+ return signedExtensions ? signedExtensions.includes('CheckMetadataHash') : false;
14
14
  };
15
15
  exports._isRuntimeUpdated = _isRuntimeUpdated;
16
16
  const getMetadataHash = async chain => {
@@ -2932,7 +2932,6 @@ export default class KoniExtension {
2932
2932
  payload
2933
2933
  } = request;
2934
2934
  let registry;
2935
- let isEvm = false;
2936
2935
  if (isJsonPayload(payload)) {
2937
2936
  const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
2938
2937
  let metadata;
@@ -2986,9 +2985,6 @@ export default class KoniExtension {
2986
2985
  registry = this.#koniState.getSubstrateApi(chainInfo.slug).api.registry;
2987
2986
  }
2988
2987
  }
2989
- if (chainInfo) {
2990
- isEvm = _isChainEvmCompatible(chainInfo);
2991
- }
2992
2988
  } else {
2993
2989
  // for non-payload, just create a registry to use
2994
2990
  registry = new TypeRegistry();
@@ -2997,7 +2993,7 @@ export default class KoniExtension {
2997
2993
  resolve({
2998
2994
  id,
2999
2995
  // In case evm chain, must be cut 2 character after 0x
3000
- signature: isEvm ? `0x${result.signature.slice(4)}` : result.signature
2996
+ signature: result.signature
3001
2997
  });
3002
2998
  if (this.#alwaysLock) {
3003
2999
  this.keyringLock();
@@ -1202,35 +1202,38 @@ export default class KoniState {
1202
1202
  from: transactionParams.from,
1203
1203
  to: transactionParams.to,
1204
1204
  value: autoFormatNumber(transactionParams.value),
1205
- gasPrice: autoFormatNumber(transactionParams.gasPrice),
1205
+ gas: autoFormatNumber(transactionParams.gas),
1206
+ gasPrice: autoFormatNumber(transactionParams.gasPrice || transactionParams.gasLimit),
1206
1207
  maxPriorityFeePerGas: autoFormatNumber(transactionParams.maxPriorityFeePerGas),
1207
1208
  maxFeePerGas: autoFormatNumber(transactionParams.maxFeePerGas),
1208
1209
  data: transactionParams.data
1209
1210
  };
1210
- const getTransactionGas = async () => {
1211
+ if (!transactionParams.gas) {
1212
+ const getTransactionGas = async () => {
1213
+ try {
1214
+ transaction.gas = await web3.eth.estimateGas({
1215
+ ...transaction
1216
+ });
1217
+ } catch (e) {
1218
+ // @ts-ignore
1219
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1220
+ throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1221
+ }
1222
+ };
1223
+
1224
+ // Calculate transaction data
1211
1225
  try {
1212
- transaction.gas = await web3.eth.estimateGas({
1213
- ...transaction
1214
- });
1226
+ await Promise.race([getTransactionGas(), wait(3000).then(async () => {
1227
+ if (!transaction.gas) {
1228
+ await this.chainService.initSingleApi(networkKey);
1229
+ await getTransactionGas();
1230
+ }
1231
+ })]);
1215
1232
  } catch (e) {
1216
1233
  // @ts-ignore
1217
1234
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1218
1235
  throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1219
1236
  }
1220
- };
1221
-
1222
- // Calculate transaction data
1223
- try {
1224
- await Promise.race([getTransactionGas(), wait(3000).then(async () => {
1225
- if (!transaction.gas) {
1226
- await this.chainService.initSingleApi(networkKey);
1227
- await getTransactionGas();
1228
- }
1229
- })]);
1230
- } catch (e) {
1231
- // @ts-ignore
1232
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1233
- throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1234
1237
  }
1235
1238
  if (!transaction.gas) {
1236
1239
  throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS);
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.2.11-0",
20
+ "version": "1.2.12-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -1948,11 +1948,11 @@
1948
1948
  "@reduxjs/toolkit": "^1.9.1",
1949
1949
  "@sora-substrate/type-definitions": "^1.17.7",
1950
1950
  "@substrate/connect": "^0.8.9",
1951
- "@subwallet/chain-list": "0.2.70",
1952
- "@subwallet/extension-base": "^1.2.11-0",
1953
- "@subwallet/extension-chains": "^1.2.11-0",
1954
- "@subwallet/extension-dapp": "^1.2.11-0",
1955
- "@subwallet/extension-inject": "^1.2.11-0",
1951
+ "@subwallet/chain-list": "0.2.71",
1952
+ "@subwallet/extension-base": "^1.2.12-0",
1953
+ "@subwallet/extension-chains": "^1.2.12-0",
1954
+ "@subwallet/extension-dapp": "^1.2.12-0",
1955
+ "@subwallet/extension-inject": "^1.2.12-0",
1956
1956
  "@subwallet/keyring": "^0.1.5",
1957
1957
  "@subwallet/ui-keyring": "^0.1.5",
1958
1958
  "@walletconnect/keyvaluestorage": "^1.1.1",
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.2.11-0'
10
+ version: '1.2.12-0'
11
11
  };
@@ -31,24 +31,22 @@ export async function getSnowBridgeEvmTransfer(tokenInfo, originChainInfo, desti
31
31
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
32
32
  const transferEncodedCall = transferCall.encodeABI();
33
33
  const [priority, sendTokenFee] = await Promise.all([calculateGasFeeParams(evmApi, evmApi.chainSlug), getSendFeeToken(snowBridgeContract, tokenContract, destinationChainParaId, destinationFee)]);
34
- let gasLimit;
35
- try {
36
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
37
- gasLimit = await transferCall.estimateGas({
38
- from: sender
39
- });
40
- } catch (e) {
41
- gasLimit = 200000; // todo: handle this better
42
- }
43
-
44
- return {
34
+ const transactionConfig = {
45
35
  from: sender,
46
36
  to: snowBridgeContractAddress,
47
37
  value: sendTokenFee,
48
38
  data: transferEncodedCall,
49
- gas: gasLimit,
50
39
  gasPrice: priority.gasPrice,
51
40
  maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
52
41
  maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
53
42
  };
43
+ let gasLimit;
44
+ try {
45
+ gasLimit = await evmApi.api.eth.estimateGas(transactionConfig);
46
+ } catch (e) {
47
+ gasLimit = 200000; // todo: handle this better
48
+ }
49
+
50
+ transactionConfig.gas = gasLimit;
51
+ return transactionConfig;
54
52
  }
@@ -15,9 +15,10 @@ import { addLazy, fetchStaticData, filterAssetsByChainAndType, MODULE_SUPPORT }
15
15
  import { BehaviorSubject, Subject } from 'rxjs';
16
16
  import Web3 from 'web3';
17
17
  import { logger as createLogger } from '@polkadot/util/logger';
18
- const filterChainInfoMap = data => {
19
- return Object.fromEntries(Object.entries(data).filter(([, info]) => !info.bitcoinInfo));
18
+ const filterChainInfoMap = (data, ignoredChains) => {
19
+ return Object.fromEntries(Object.entries(data).filter(([slug, info]) => !info.bitcoinInfo && !ignoredChains.includes(slug)));
20
20
  };
21
+ const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest'];
21
22
  const filterAssetInfoMap = (chainInfo, assets) => {
22
23
  return Object.fromEntries(Object.entries(assets).filter(([, info]) => chainInfo[info.originChain]));
23
24
  };
@@ -829,7 +830,7 @@ export class ChainService {
829
830
  }
830
831
  async initChains() {
831
832
  const storedChainSettings = await this.dbService.getAllChainStore();
832
- const defaultChainInfoMap = filterChainInfoMap(ChainInfoMap);
833
+ const defaultChainInfoMap = filterChainInfoMap(ChainInfoMap, ignoredList);
833
834
  const storedChainSettingMap = {};
834
835
  storedChainSettings.forEach(chainStoredSetting => {
835
836
  storedChainSettingMap[chainStoredSetting.slug] = chainStoredSetting;
@@ -91,7 +91,7 @@ export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
91
91
  for (let i = 0; i < balances.length; i++) {
92
92
  const balanceItem = balances[i];
93
93
  const address = useAddresses[i];
94
- const bnActiveBalance = balanceItem.free || BN_ZERO;
94
+ const bnActiveBalance = balanceItem.reserved || BN_ZERO;
95
95
  const bnTotalBalance = bnActiveBalance.mul(new BN(exchangeRate)).div(decimals);
96
96
  const result = {
97
97
  ...this.baseInfo,
@@ -1,3 +1,3 @@
1
- export declare const _isRuntimeUpdated: (signedExtensions: string[]) => boolean;
1
+ export declare const _isRuntimeUpdated: (signedExtensions?: string[]) => boolean;
2
2
  export declare const getMetadataHash: (chain: string) => Promise<string>;
3
3
  export declare const getShortMetadata: (chain: string, blob: string) => Promise<string>;
package/utils/metadata.js CHANGED
@@ -4,7 +4,7 @@
4
4
  const LEDGER_API_URL = 'https://ledger-api.subwallet.app';
5
5
  const createUrl = path => `${LEDGER_API_URL}/${path}`;
6
6
  export const _isRuntimeUpdated = signedExtensions => {
7
- return signedExtensions.includes('CheckMetadataHash');
7
+ return signedExtensions ? signedExtensions.includes('CheckMetadataHash') : false;
8
8
  };
9
9
  export const getMetadataHash = async chain => {
10
10
  const data = {