@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.
@@ -436,5 +436,8 @@ export interface EtherscanTransaction {
436
436
  type_image_link: string;
437
437
  chainId: string;
438
438
  tokenSymbol: string;
439
+ tokenName: string;
439
440
  tokenID: string;
441
+ tokenValue: string;
442
+ tokenDecimal: string;
440
443
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toruslabs/ethereum-controllers",
3
- "version": "5.5.2",
3
+ "version": "5.5.3",
4
4
  "homepage": "https://github.com/torusresearch/controllers#readme",
5
5
  "license": "ISC",
6
6
  "main": "dist/ethereumControllers.cjs.js",
@@ -24,7 +24,7 @@
24
24
  "@ethereumjs/util": "^9.0.2",
25
25
  "@metamask/eth-sig-util": "^7.0.1",
26
26
  "@metamask/rpc-errors": "^6.1.0",
27
- "@toruslabs/base-controllers": "^5.5.1",
27
+ "@toruslabs/base-controllers": "^5.5.3",
28
28
  "@toruslabs/http-helpers": "^6.0.0",
29
29
  "@toruslabs/openlogin-jrpc": "^7.0.0",
30
30
  "async-mutex": "^0.4.1",
@@ -64,7 +64,7 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "ba6a8e2124bfe47b5d75a27cda6492a46e09d59d",
67
+ "gitHead": "f7e579647725a5daef02b33153dadfbdd94c86a6",
68
68
  "devDependencies": {
69
69
  "@nomicfoundation/hardhat-toolbox": "^4.0.0",
70
70
  "hardhat": "^2.19.5"
@@ -96,7 +96,7 @@ export default class PreferencesController
96
96
  }
97
97
 
98
98
  public async initPreferences(params: InitPreferencesParams): Promise<void> {
99
- const { address, jwtToken, calledFromEmbed, userInfo, rehydrate, locale = "en-US", type, signatures, web3AuthClientId, web3AuthNetwork } = params;
99
+ const { address, jwtToken, calledFromEmbed, userInfo, rehydrate, locale = "en", type, signatures, web3AuthClientId, web3AuthNetwork } = params;
100
100
  await super.init({ address, userInfo, idToken: jwtToken, type, metadata: { email: userInfo.email, signatures, network: web3AuthNetwork } });
101
101
  const { aggregateVerifier, verifier, verifierId } = userInfo || {};
102
102
  const userExists = await this.sync(address);
@@ -185,7 +185,7 @@ export default class PreferencesController
185
185
 
186
186
  public async patchNewTx(tx: TransactionPayload, address: string): Promise<void> {
187
187
  const formattedTx = formatPastTx(tx);
188
- const storePastTx = this.getAddressState(address)?.formattedPastTransactions;
188
+ const storePastTx = this.getAddressState(address)?.formattedPastTransactions || [];
189
189
  const duplicateIndex = storePastTx.findIndex((x) => x.transaction_hash === tx.transaction_hash && x.chainId === tx.chain_id);
190
190
  if (tx.status === TransactionStatus.submitted || tx.status === TransactionStatus.confirmed) {
191
191
  if (duplicateIndex === -1) {
@@ -9,7 +9,6 @@ import {
9
9
  } from "@toruslabs/base-controllers";
10
10
  import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
11
11
  import BigNumber from "bignumber.js";
12
- import { formatEther } from "ethers";
13
12
  import log from "loglevel";
14
13
 
15
14
  import { determineTransactionType } from "../Transaction/TransactionUtils";
@@ -198,14 +197,26 @@ export const addEtherscanTransactions = async (
198
197
  );
199
198
 
200
199
  const finalTxs = transactionPromises.reduce((accumulator, x) => {
201
- const totalAmountString = x.value ? formatEther(x.value) : "";
200
+ let totalAmountString = x.value ? new BigNumber(x.value).div(new BigNumber(10).pow(new BigNumber(x.tokenDecimal || 18))).toString() : "";
201
+ let type = CONTRACT_TYPE_ETH;
202
+ if (x.contractAddress !== "") {
203
+ if (x.tokenID) {
204
+ type = x.tokenValue ? CONTRACT_TYPE_ERC1155 : CONTRACT_TYPE_ERC721;
205
+ } else {
206
+ type = CONTRACT_TYPE_ERC20;
207
+ }
208
+ }
209
+
210
+ if (type === CONTRACT_TYPE_ERC1155) {
211
+ totalAmountString = x.tokenValue;
212
+ }
202
213
 
203
214
  const etherscanTransaction: TransactionPayload = {
204
215
  etherscanLink: getEtherScanHashLink(x.hash, chainId),
205
- type: x.type || SUPPORTED_NETWORKS[chainId]?.ticker || CONTRACT_TYPE_ETH,
216
+ type,
206
217
  type_image_link: x.type_image_link || "n/a",
207
- type_name: x.type_name || "n/a",
208
- symbol: SUPPORTED_NETWORKS[chainId]?.ticker,
218
+ type_name: x.tokenName || SUPPORTED_NETWORKS[chainId]?.ticker || "n/a",
219
+ symbol: x.tokenSymbol || SUPPORTED_NETWORKS[chainId]?.ticker,
209
220
  token_id: x.tokenID || "",
210
221
  total_amount: totalAmountString,
211
222
  created_at: new Date(Number(x.timeStamp) * 1000),
@@ -217,8 +228,8 @@ export const addEtherscanTransactions = async (
217
228
  input: x.input,
218
229
  contract_address: x.contractAddress,
219
230
  transaction_category: x.transaction_category,
220
- gas: x.gas,
221
- gasPrice: x.gasPrice,
231
+ gas: `0x${new BigNumber(x.gasUsed || 0, 10).toString(16)}`,
232
+ gasPrice: `0x${new BigNumber(x.gasPrice || 0, 10).toString(16)}`,
222
233
  chain_id: chainId,
223
234
  currency_amount: "",
224
235
  nonce: x.nonce,
@@ -512,5 +512,8 @@ export interface EtherscanTransaction {
512
512
  type_image_link: string;
513
513
  chainId: string;
514
514
  tokenSymbol: string;
515
+ tokenName: string;
515
516
  tokenID: string;
517
+ tokenValue: string;
518
+ tokenDecimal: string;
516
519
  }