@toruslabs/ethereum-controllers 5.5.2 → 5.5.3

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.
@@ -2,7 +2,7 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
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, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, TX_EVENTS, BaseTransactionStateManager, transactionMatchesNetwork as transactionMatchesNetwork$1 } from '@toruslabs/base-controllers';
4
4
  import { Mutex } from 'async-mutex';
5
- import { BrowserProvider, toQuantity, Contract, Interface, formatEther, isHexString as isHexString$1, JsonRpcProvider, keccak256 } from 'ethers';
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';
@@ -1495,13 +1495,24 @@ const addEtherscanTransactions = async (txn, lowerCaseSelectedAddress, provider,
1495
1495
  }));
1496
1496
  const finalTxs = transactionPromises.reduce((accumulator, x) => {
1497
1497
  var _SUPPORTED_NETWORKS$c3, _SUPPORTED_NETWORKS$c4;
1498
- const totalAmountString = x.value ? formatEther(x.value) : "";
1498
+ let totalAmountString = x.value ? new BigNumber(x.value).div(new BigNumber(10).pow(new BigNumber(x.tokenDecimal || 18))).toString() : "";
1499
+ let type = CONTRACT_TYPE_ETH;
1500
+ if (x.contractAddress !== "") {
1501
+ if (x.tokenID) {
1502
+ type = x.tokenValue ? CONTRACT_TYPE_ERC1155 : CONTRACT_TYPE_ERC721;
1503
+ } else {
1504
+ type = CONTRACT_TYPE_ERC20;
1505
+ }
1506
+ }
1507
+ if (type === CONTRACT_TYPE_ERC1155) {
1508
+ totalAmountString = x.tokenValue;
1509
+ }
1499
1510
  const etherscanTransaction = {
1500
1511
  etherscanLink: getEtherScanHashLink(x.hash, chainId),
1501
- type: x.type || ((_SUPPORTED_NETWORKS$c3 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c3 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c3.ticker) || CONTRACT_TYPE_ETH,
1512
+ type,
1502
1513
  type_image_link: x.type_image_link || "n/a",
1503
- type_name: x.type_name || "n/a",
1504
- symbol: (_SUPPORTED_NETWORKS$c4 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c4 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c4.ticker,
1514
+ type_name: x.tokenName || ((_SUPPORTED_NETWORKS$c3 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c3 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c3.ticker) || "n/a",
1515
+ symbol: x.tokenSymbol || ((_SUPPORTED_NETWORKS$c4 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c4 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c4.ticker),
1505
1516
  token_id: x.tokenID || "",
1506
1517
  total_amount: totalAmountString,
1507
1518
  created_at: new Date(Number(x.timeStamp) * 1000),
@@ -1513,8 +1524,8 @@ const addEtherscanTransactions = async (txn, lowerCaseSelectedAddress, provider,
1513
1524
  input: x.input,
1514
1525
  contract_address: x.contractAddress,
1515
1526
  transaction_category: x.transaction_category,
1516
- gas: x.gas,
1517
- gasPrice: x.gasPrice,
1527
+ gas: `0x${new BigNumber(x.gasUsed || 0, 10).toString(16)}`,
1528
+ gasPrice: `0x${new BigNumber(x.gasPrice || 0, 10).toString(16)}`,
1518
1529
  chain_id: chainId,
1519
1530
  currency_amount: "",
1520
1531
  nonce: x.nonce,
@@ -4135,7 +4146,7 @@ class PreferencesController extends BasePreferencesController {
4135
4146
  calledFromEmbed,
4136
4147
  userInfo,
4137
4148
  rehydrate,
4138
- locale = "en-US",
4149
+ locale = "en",
4139
4150
  type,
4140
4151
  signatures,
4141
4152
  web3AuthClientId,
@@ -4239,7 +4250,7 @@ class PreferencesController extends BasePreferencesController {
4239
4250
  async patchNewTx(tx, address) {
4240
4251
  var _this$getAddressState2;
4241
4252
  const formattedTx = formatPastTx(tx);
4242
- const storePastTx = (_this$getAddressState2 = this.getAddressState(address)) === null || _this$getAddressState2 === void 0 ? void 0 : _this$getAddressState2.formattedPastTransactions;
4253
+ const storePastTx = ((_this$getAddressState2 = this.getAddressState(address)) === null || _this$getAddressState2 === void 0 ? void 0 : _this$getAddressState2.formattedPastTransactions) || [];
4243
4254
  const duplicateIndex = storePastTx.findIndex(x => x.transaction_hash === tx.transaction_hash && x.chainId === tx.chain_id);
4244
4255
  if (tx.status === TransactionStatus.submitted || tx.status === TransactionStatus.confirmed) {
4245
4256
  if (duplicateIndex === -1) {