@toruslabs/ethereum-controllers 5.5.1 → 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.
@@ -1564,7 +1564,6 @@ async function determineTransactionType(txParams, provider) {
1564
1564
 
1565
1565
 
1566
1566
 
1567
-
1568
1567
  function getEtherScanHashLink(txHash, chainId) {
1569
1568
  if (!SUPPORTED_NETWORKS[chainId]) return "";
1570
1569
  return `${SUPPORTED_NETWORKS[chainId].blockExplorerUrl}/tx/${txHash}`;
@@ -1718,13 +1717,24 @@ const addEtherscanTransactions = async (txn, lowerCaseSelectedAddress, provider,
1718
1717
  }));
1719
1718
  const finalTxs = transactionPromises.reduce((accumulator, x) => {
1720
1719
  var _SUPPORTED_NETWORKS$c3, _SUPPORTED_NETWORKS$c4;
1721
- const totalAmountString = x.value ? (0,external_ethers_namespaceObject.formatEther)(x.value) : "";
1720
+ let totalAmountString = x.value ? new (external_bignumber_js_default())(x.value).div(new (external_bignumber_js_default())(10).pow(new (external_bignumber_js_default())(x.tokenDecimal || 18))).toString() : "";
1721
+ let type = CONTRACT_TYPE_ETH;
1722
+ if (x.contractAddress !== "") {
1723
+ if (x.tokenID) {
1724
+ type = x.tokenValue ? CONTRACT_TYPE_ERC1155 : CONTRACT_TYPE_ERC721;
1725
+ } else {
1726
+ type = CONTRACT_TYPE_ERC20;
1727
+ }
1728
+ }
1729
+ if (type === CONTRACT_TYPE_ERC1155) {
1730
+ totalAmountString = x.tokenValue;
1731
+ }
1722
1732
  const etherscanTransaction = {
1723
1733
  etherscanLink: getEtherScanHashLink(x.hash, chainId),
1724
- type: x.type || ((_SUPPORTED_NETWORKS$c3 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c3 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c3.ticker) || CONTRACT_TYPE_ETH,
1734
+ type,
1725
1735
  type_image_link: x.type_image_link || "n/a",
1726
- type_name: x.type_name || "n/a",
1727
- symbol: (_SUPPORTED_NETWORKS$c4 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c4 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c4.ticker,
1736
+ type_name: x.tokenName || ((_SUPPORTED_NETWORKS$c3 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c3 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c3.ticker) || "n/a",
1737
+ symbol: x.tokenSymbol || ((_SUPPORTED_NETWORKS$c4 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c4 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c4.ticker),
1728
1738
  token_id: x.tokenID || "",
1729
1739
  total_amount: totalAmountString,
1730
1740
  created_at: new Date(Number(x.timeStamp) * 1000),
@@ -1736,8 +1746,8 @@ const addEtherscanTransactions = async (txn, lowerCaseSelectedAddress, provider,
1736
1746
  input: x.input,
1737
1747
  contract_address: x.contractAddress,
1738
1748
  transaction_category: x.transaction_category,
1739
- gas: x.gas,
1740
- gasPrice: x.gasPrice,
1749
+ gas: `0x${new (external_bignumber_js_default())(x.gasUsed || 0, 10).toString(16)}`,
1750
+ gasPrice: `0x${new (external_bignumber_js_default())(x.gasPrice || 0, 10).toString(16)}`,
1741
1751
  chain_id: chainId,
1742
1752
  currency_amount: "",
1743
1753
  nonce: x.nonce,
@@ -2561,7 +2571,6 @@ const eth_sig_util_namespaceObject = require("@metamask/eth-sig-util");
2561
2571
 
2562
2572
 
2563
2573
 
2564
-
2565
2574
  class KeyringController extends base_controllers_namespaceObject.BaseKeyringController {
2566
2575
  constructor(_ref) {
2567
2576
  let {
@@ -2589,17 +2598,15 @@ class KeyringController extends base_controllers_namespaceObject.BaseKeyringCont
2589
2598
  return this.state.wallets.map(w => w.publicKey);
2590
2599
  }
2591
2600
  importAccount(accountPrivateKey) {
2592
- const hexPrivateKey = (0,util_namespaceObject.addHexPrefix)(accountPrivateKey);
2593
- const signingKey = new external_ethers_namespaceObject.SigningKey(hexPrivateKey);
2594
- const wallet = new external_ethers_namespaceObject.Wallet(signingKey.privateKey);
2595
- const {
2596
- address
2597
- } = wallet;
2601
+ const hexPrivateKey = accountPrivateKey.padStart(64, "0");
2602
+ const bufferPrivKey = Buffer.from(hexPrivateKey, "hex");
2603
+ const publicKey = (0,util_namespaceObject.bytesToHex)((0,util_namespaceObject.privateToPublic)(bufferPrivKey));
2604
+ const address = (0,util_namespaceObject.bytesToHex)((0,util_namespaceObject.privateToAddress)(bufferPrivKey));
2598
2605
  const existingWallet = this.state.wallets.find(w => w.address === address);
2599
2606
  if (existingWallet) return existingWallet.address;
2600
2607
  this.update({
2601
2608
  wallets: [...this.state.wallets, {
2602
- publicKey: signingKey.publicKey,
2609
+ publicKey,
2603
2610
  privateKey: accountPrivateKey,
2604
2611
  address
2605
2612
  }]
@@ -4540,7 +4547,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4540
4547
  calledFromEmbed,
4541
4548
  userInfo,
4542
4549
  rehydrate,
4543
- locale = "en-US",
4550
+ locale = "en",
4544
4551
  type,
4545
4552
  signatures,
4546
4553
  web3AuthClientId,
@@ -4644,7 +4651,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
4644
4651
  async patchNewTx(tx, address) {
4645
4652
  var _this$getAddressState2;
4646
4653
  const formattedTx = formatPastTx(tx);
4647
- const storePastTx = (_this$getAddressState2 = this.getAddressState(address)) === null || _this$getAddressState2 === void 0 ? void 0 : _this$getAddressState2.formattedPastTransactions;
4654
+ const storePastTx = ((_this$getAddressState2 = this.getAddressState(address)) === null || _this$getAddressState2 === void 0 ? void 0 : _this$getAddressState2.formattedPastTransactions) || [];
4648
4655
  const duplicateIndex = storePastTx.findIndex(x => x.transaction_hash === tx.transaction_hash && x.chainId === tx.chain_id);
4649
4656
  if (tx.status === base_controllers_namespaceObject.TransactionStatus.submitted || tx.status === base_controllers_namespaceObject.TransactionStatus.confirmed) {
4650
4657
  if (duplicateIndex === -1) {