Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/apps/the-exchange/components/ExchangeAction/ExchangeAction.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useEtherspotSwaps } from '@etherspot/transaction-kit';
import { CircularProgress } from '@mui/material';
import { ethers } from 'ethers';
import { BigNumber } from 'ethers';
import { useEffect, useState } from 'react';
import { formatEther } from 'viem';

// services
import {
Expand Down Expand Up @@ -90,6 +91,10 @@ const ExchangeAction = () => {
if ('receiveAmount' in bestOffer.offer) {
// eslint-disable-next-line no-plusplus
for (let i = 0; i < bestOffer.offer.transactions.length; ++i) {
const { value } = bestOffer.offer.transactions[i];
const bigIntValue = BigNumber.from(value).toBigInt();
const integerValue = formatEther(bigIntValue);
Comment on lines +94 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Check for mismatch in transaction value representation.
Using formatEther(bigIntValue) produces a decimal string (e.g. "0.5" for half an ETH), whereas most lower-level transaction methods expect a value designated in WEI. Ensure addToBatch and subsequent transaction logic will properly interpret the returned string. If it expects a WEI amount, consider passing the raw wei value instead (e.g., a BigInt or a hex string).


addToBatch({
title: getTransactionTitle(
i,
Expand All @@ -101,7 +106,7 @@ const ExchangeAction = () => {
'',
chainId: chainNameToChainIdTokensData(swapToken?.blockchain) || 0,
to: bestOffer.offer.transactions[i].to,
value: bestOffer.offer.transactions[i].value,
value: integerValue,
data: bestOffer.offer.transactions[i].data,
});
}
Expand All @@ -117,6 +122,9 @@ const ExchangeAction = () => {
if (stepTransactions) {
// eslint-disable-next-line no-plusplus
for (let i = 0; i < stepTransactions.length; ++i) {
const { value } = stepTransactions[i];
const bigIntValue = BigNumber.from(value).toBigInt();
const integerValue = formatEther(bigIntValue);
addToBatch({
title: getTransactionTitle(
i,
Expand All @@ -128,7 +136,7 @@ const ExchangeAction = () => {
'',
chainId: chainNameToChainIdTokensData(swapToken?.blockchain) || 0,
to: stepTransactions[i].to || '',
value: ethers.BigNumber.from(stepTransactions[i].value),
value: integerValue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reconfirm the final transaction value format.
As with previous segments, value: integerValue is a decimal string from formatEther, which could introduce confusion or errors if the receiving function or contract requires a raw WEI value.

data: stepTransactions[i].data?.toString() ?? '',
});
}
Expand Down
46 changes: 35 additions & 11 deletions src/services/tokensData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,42 @@ export const loadTokensData = (): Token[] => {
if (tokensData.length === 0) {
tokensData = (tokens as TokenDataType).data.flatMap((item) =>
item.blockchains
.map((blockchain, index) => ({
id: item.id,
name: item.name,
symbol: item.symbol,
logo: item.logo,
blockchain,
contract: item.contracts[index],
decimals: item.decimals[index],
}))
.filter((token) => allowedBlockchains.includes(token.blockchain))
.map((blockchain, index) => {
let { name } = item;
let { symbol } = item;
const contract = item.contracts[index];

if (name === 'XDAI' && symbol === 'XDAI') {
name = 'Wrapped XDAI';
symbol = 'WXDAI';
}

if (
name === 'Ethereum' &&
symbol === 'ETH' &&
contract !== '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
) {
name = 'Wrapped Ether';
symbol = 'WETH';
}

return contract !== '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
? {
id: item.id,
name,
symbol,
logo: item.logo,
blockchain,
contract,
decimals: item.decimals[index],
}
: null;
})
.filter(
(token): token is Token =>
token !== null && allowedBlockchains.includes(token.blockchain)
)
);

// Add native/gas tokens
CompatibleChains.forEach((chain) => {
const nativeAsset = getNativeAssetForChainId(chain.chainId);
Expand Down