@toruslabs/ethereum-controllers 5.7.0 → 5.8.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.
@@ -4624,7 +4624,6 @@ class NftsController extends base_controllers_namespaceObject.BaseController {
4624
4624
 
4625
4625
 
4626
4626
 
4627
-
4628
4627
  class PreferencesController extends base_controllers_namespaceObject.BasePreferencesController {
4629
4628
  constructor(_ref) {
4630
4629
  let {
@@ -4770,13 +4769,13 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4770
4769
  }
4771
4770
  return false;
4772
4771
  } catch (error) {
4772
+ if (base_controllers_namespaceObject.isUnauthorizedError) {
4773
+ throw error;
4774
+ }
4773
4775
  external_loglevel_default().error(error);
4774
4776
  return false;
4775
4777
  } finally {
4776
- Promise.all([this.getWalletOrders(address).catch(error => {
4777
- external_loglevel_default().error("unable to fetch wallet orders", error);
4778
- })]).then(data => {
4779
- const [walletTx] = data;
4778
+ this.getWalletOrders(address).then(walletTx => {
4780
4779
  // eslint-disable-next-line promise/always-return
4781
4780
  if (walletTx && walletTx.length > 0) {
4782
4781
  this.updateState({
@@ -4855,9 +4854,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4855
4854
  }
4856
4855
  async fetchEtherscanTx(parameters) {
4857
4856
  try {
4858
- const url = new URL(`${this.config.api}/etherscan`);
4859
- url.searchParams.append("chainId", parameters.chainId);
4860
- const response = await (0,http_helpers_namespaceObject.get)(url.href, this.headers(parameters.selectedAddress));
4857
+ const response = await this.wsApiClient.authGet(`etherscan?chainId=${parameters.chainId}`, this.authCredentials(parameters.selectedAddress));
4861
4858
  external_loglevel_default().info("Etherscan Response API", response);
4862
4859
  return response.success ? response.data : [];
4863
4860
  } catch (error) {
@@ -4867,20 +4864,12 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4867
4864
  }
4868
4865
  async getEtherScanTokens(address, chainId) {
4869
4866
  const selectedAddress = address;
4870
- const apiUrl = new URL(this.config.api);
4871
- apiUrl.pathname = `/tokens`;
4872
- apiUrl.searchParams.append("chainId", chainId);
4873
- apiUrl.searchParams.append("address", selectedAddress);
4874
- const result = await (0,http_helpers_namespaceObject.get)(apiUrl.href, this.headers(this.state.selectedAddress));
4867
+ const result = await this.wsApiClient.authGet(`tokens?chainId=${chainId}&address=${selectedAddress}`, this.authCredentials());
4875
4868
  return result.data;
4876
4869
  }
4877
4870
  async getSimpleHashNfts(address, chainId) {
4878
4871
  const selectedAddress = address;
4879
- const apiUrl = new URL(this.config.api);
4880
- apiUrl.pathname = `/nfts`;
4881
- apiUrl.searchParams.append("chainId", chainId);
4882
- apiUrl.searchParams.append("address", selectedAddress);
4883
- const result = await (0,http_helpers_namespaceObject.get)(apiUrl.href, this.headers(this.state.selectedAddress));
4872
+ const result = await this.wsApiClient.authGet(`nfts?chainId=${chainId}&address=${selectedAddress}`, this.authCredentials());
4884
4873
  return result.data;
4885
4874
  }
4886
4875
  getCustomTokens(address) {
@@ -4932,8 +4921,6 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4932
4921
  network
4933
4922
  } = _ref2;
4934
4923
  try {
4935
- const apiUrl = new URL(this.config.api);
4936
- apiUrl.pathname = `/customnetwork`;
4937
4924
  const {
4938
4925
  selectedAddress
4939
4926
  } = this.state;
@@ -4947,7 +4934,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4947
4934
  logo: network.logo,
4948
4935
  symbol_name: network.tickerName
4949
4936
  };
4950
- const res = await (0,http_helpers_namespaceObject.post)(apiUrl.href, payload, this.headers(selectedAddress), {
4937
+ const res = await this.wsApiClient.authPost("customnetwork", payload, this.authCredentials(selectedAddress), {
4951
4938
  useAPIKey: true
4952
4939
  });
4953
4940
  await this.sync(selectedAddress);
@@ -4962,9 +4949,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4962
4949
  const {
4963
4950
  selectedAddress
4964
4951
  } = this.state;
4965
- const apiUrl = new URL(this.config.api);
4966
- apiUrl.pathname = `/customnetwork/${id}`;
4967
- await (0,http_helpers_namespaceObject.remove)(apiUrl.href, {}, this.headers(selectedAddress), {
4952
+ await this.wsApiClient.authRemove(`customnetwork/${id}`, {}, this.authCredentials(selectedAddress), {
4968
4953
  useAPIKey: true
4969
4954
  });
4970
4955
  await this.sync(selectedAddress);
@@ -4983,8 +4968,6 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4983
4968
  const {
4984
4969
  selectedAddress
4985
4970
  } = this.state;
4986
- const apiUrl = new URL(this.config.api);
4987
- apiUrl.pathname = `/customnetwork/${id}`;
4988
4971
  const payload = {
4989
4972
  network_name: network.displayName,
4990
4973
  rpc_url: network.rpcTarget,
@@ -4993,7 +4976,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4993
4976
  block_explorer_url: network.blockExplorerUrl || undefined,
4994
4977
  is_testnet: network.isTestnet || false
4995
4978
  };
4996
- await (0,http_helpers_namespaceObject.patch)(apiUrl.href, payload, this.headers(selectedAddress), {
4979
+ await this.wsApiClient.authPatch(`customnetwork/${id}`, payload, this.authCredentials(selectedAddress), {
4997
4980
  useAPIKey: true
4998
4981
  });
4999
4982
  await this.sync(selectedAddress);
@@ -1,13 +1,13 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
- import { CHAIN_NAMESPACES, BaseController, randomId, TransactionStatus, TRANSACTION_TYPES, formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, BaseBlockTracker, timeout, BaseCurrencyController, BaseKeyringController, PROVIDER_JRPC_METHODS, createFetchMiddleware, createInflightCacheMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, TX_EVENTS, BaseTransactionStateManager, transactionMatchesNetwork as transactionMatchesNetwork$1 } from '@toruslabs/base-controllers';
3
+ import { CHAIN_NAMESPACES, BaseController, randomId, TransactionStatus, TRANSACTION_TYPES, formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, BaseBlockTracker, timeout, BaseCurrencyController, BaseKeyringController, PROVIDER_JRPC_METHODS, createFetchMiddleware, createInflightCacheMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, isUnauthorizedError, TX_EVENTS, BaseTransactionStateManager, transactionMatchesNetwork as transactionMatchesNetwork$1 } from '@toruslabs/base-controllers';
4
4
  import { Mutex } from 'async-mutex';
5
5
  import { BrowserProvider, toQuantity, Contract, Interface, isHexString as isHexString$1, JsonRpcProvider, keccak256 } from 'ethers';
6
6
  import log from 'loglevel';
7
7
  import { isHexString, addHexPrefix, isValidAddress, toChecksumAddress, stripHexPrefix, bytesToHex, privateToPublic, privateToAddress, ecsign, bigIntToBytes } from '@ethereumjs/util';
8
8
  import BigNumber from 'bignumber.js';
9
9
  import { rpcErrors, providerErrors } from '@metamask/rpc-errors';
10
- import { get, post, remove, patch } from '@toruslabs/http-helpers';
10
+ import { get } from '@toruslabs/http-helpers';
11
11
  import { cloneDeep, merge, omitBy, mapValues, keyBy, sortBy, pickBy } from 'lodash';
12
12
  import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
13
13
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
@@ -4365,13 +4365,13 @@ class PreferencesController extends BasePreferencesController {
4365
4365
  }
4366
4366
  return false;
4367
4367
  } catch (error) {
4368
+ if (isUnauthorizedError) {
4369
+ throw error;
4370
+ }
4368
4371
  log.error(error);
4369
4372
  return false;
4370
4373
  } finally {
4371
- Promise.all([this.getWalletOrders(address).catch(error => {
4372
- log.error("unable to fetch wallet orders", error);
4373
- })]).then(data => {
4374
- const [walletTx] = data;
4374
+ this.getWalletOrders(address).then(walletTx => {
4375
4375
  // eslint-disable-next-line promise/always-return
4376
4376
  if (walletTx && walletTx.length > 0) {
4377
4377
  this.updateState({
@@ -4450,9 +4450,7 @@ class PreferencesController extends BasePreferencesController {
4450
4450
  }
4451
4451
  async fetchEtherscanTx(parameters) {
4452
4452
  try {
4453
- const url = new URL(`${this.config.api}/etherscan`);
4454
- url.searchParams.append("chainId", parameters.chainId);
4455
- const response = await get(url.href, this.headers(parameters.selectedAddress));
4453
+ const response = await this.wsApiClient.authGet(`etherscan?chainId=${parameters.chainId}`, this.authCredentials(parameters.selectedAddress));
4456
4454
  log.info("Etherscan Response API", response);
4457
4455
  return response.success ? response.data : [];
4458
4456
  } catch (error) {
@@ -4462,20 +4460,12 @@ class PreferencesController extends BasePreferencesController {
4462
4460
  }
4463
4461
  async getEtherScanTokens(address, chainId) {
4464
4462
  const selectedAddress = address;
4465
- const apiUrl = new URL(this.config.api);
4466
- apiUrl.pathname = `/tokens`;
4467
- apiUrl.searchParams.append("chainId", chainId);
4468
- apiUrl.searchParams.append("address", selectedAddress);
4469
- const result = await get(apiUrl.href, this.headers(this.state.selectedAddress));
4463
+ const result = await this.wsApiClient.authGet(`tokens?chainId=${chainId}&address=${selectedAddress}`, this.authCredentials());
4470
4464
  return result.data;
4471
4465
  }
4472
4466
  async getSimpleHashNfts(address, chainId) {
4473
4467
  const selectedAddress = address;
4474
- const apiUrl = new URL(this.config.api);
4475
- apiUrl.pathname = `/nfts`;
4476
- apiUrl.searchParams.append("chainId", chainId);
4477
- apiUrl.searchParams.append("address", selectedAddress);
4478
- const result = await get(apiUrl.href, this.headers(this.state.selectedAddress));
4468
+ const result = await this.wsApiClient.authGet(`nfts?chainId=${chainId}&address=${selectedAddress}`, this.authCredentials());
4479
4469
  return result.data;
4480
4470
  }
4481
4471
  getCustomTokens(address) {
@@ -4527,8 +4517,6 @@ class PreferencesController extends BasePreferencesController {
4527
4517
  network
4528
4518
  } = _ref2;
4529
4519
  try {
4530
- const apiUrl = new URL(this.config.api);
4531
- apiUrl.pathname = `/customnetwork`;
4532
4520
  const {
4533
4521
  selectedAddress
4534
4522
  } = this.state;
@@ -4542,7 +4530,7 @@ class PreferencesController extends BasePreferencesController {
4542
4530
  logo: network.logo,
4543
4531
  symbol_name: network.tickerName
4544
4532
  };
4545
- const res = await post(apiUrl.href, payload, this.headers(selectedAddress), {
4533
+ const res = await this.wsApiClient.authPost("customnetwork", payload, this.authCredentials(selectedAddress), {
4546
4534
  useAPIKey: true
4547
4535
  });
4548
4536
  await this.sync(selectedAddress);
@@ -4557,9 +4545,7 @@ class PreferencesController extends BasePreferencesController {
4557
4545
  const {
4558
4546
  selectedAddress
4559
4547
  } = this.state;
4560
- const apiUrl = new URL(this.config.api);
4561
- apiUrl.pathname = `/customnetwork/${id}`;
4562
- await remove(apiUrl.href, {}, this.headers(selectedAddress), {
4548
+ await this.wsApiClient.authRemove(`customnetwork/${id}`, {}, this.authCredentials(selectedAddress), {
4563
4549
  useAPIKey: true
4564
4550
  });
4565
4551
  await this.sync(selectedAddress);
@@ -4578,8 +4564,6 @@ class PreferencesController extends BasePreferencesController {
4578
4564
  const {
4579
4565
  selectedAddress
4580
4566
  } = this.state;
4581
- const apiUrl = new URL(this.config.api);
4582
- apiUrl.pathname = `/customnetwork/${id}`;
4583
4567
  const payload = {
4584
4568
  network_name: network.displayName,
4585
4569
  rpc_url: network.rpcTarget,
@@ -4588,7 +4572,7 @@ class PreferencesController extends BasePreferencesController {
4588
4572
  block_explorer_url: network.blockExplorerUrl || undefined,
4589
4573
  is_testnet: network.isTestnet || false
4590
4574
  };
4591
- await patch(apiUrl.href, payload, this.headers(selectedAddress), {
4575
+ await this.wsApiClient.authPatch(`customnetwork/${id}`, payload, this.authCredentials(selectedAddress), {
4592
4576
  useAPIKey: true
4593
4577
  });
4594
4578
  await this.sync(selectedAddress);