Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix hex to BN conversion #8734

Merged
merged 2 commits into from
Feb 27, 2024
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
5 changes: 1 addition & 4 deletions app/components/UI/TransactionElement/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
balanceToFiatNumber,
weiToFiatNumber,
addCurrencySymbol,
toBN,
BNToHex,
limitToMaximumDecimalPlaces,
} from '../../../util/number';
Expand All @@ -34,7 +33,6 @@ import { isSwapsNativeAsset } from '../Swaps/utils';
import { toLowerCaseEquals } from '../../../util/general';
import Engine from '../../../core/Engine';
import { isEIP1559Transaction } from '@metamask/transaction-controller';
import { convertHexToDecimal } from '@metamask/controller-utils';

const { getSwapsContractAddress } = swapsUtils;

Expand Down Expand Up @@ -282,8 +280,7 @@ export function decodeIncomingTransfer(args) {
selectedAddress,
} = args;

const decimalAmount = convertHexToDecimal(value);
const amount = toBN(decimalAmount);
const amount = hexToBN(value);
const token = { symbol, decimals, address: contractAddress };

const renderTokenAmount = token
Expand Down
57 changes: 56 additions & 1 deletion app/components/UI/TransactionElement/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('decodeIncomingTransfer', () => {
transaction: {
to: '0x77648f1407986479fb1fa5cc3597084b5dbdb057',
from: '0x1440ec793ae50fa046b95bfeca5af475b6003f9e',
value: '0x52daf0',
value: '52daf0',
},
transferInformation: {
symbol: 'USDT',
Expand Down Expand Up @@ -54,4 +54,59 @@ describe('decodeIncomingTransfer', () => {
summarySecondaryTotalAmount: undefined,
});
});

it('should decode an incoming transfer with big number with 10 digits', () => {
// Arrange
const args = {
tx: {
transaction: {
to: '0x77648f1407986479fb1fa5cc3597084b5dbdb057',
from: '0x1440ec793ae50fa046b95bfeca5af475b6003f9e',
value: '3B9ACA00', // 1000000000 in decimal
},
transferInformation: {
symbol: 'USDT',
decimals: 6,
contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
},
transactionHash:
'0x942d7843454266b81bf631022aa5f3f944691731b62d67c4e80c4bb5740058bb',
},
currentCurrency: 'usd',
contractExchangeRates: {},
totalGas: '0x64',
actionKey: 'key',
primaryCurrency: 'ETH',
selectedAddress: '0x77648f1407986479fb1fa5cc3597084b5dbdb057',
ticker: 'ETH',
};

// Act
const [transactionElement, transactionDetails] =
decodeIncomingTransfer(args);

// Assert
expect(transactionElement).toEqual({
actionKey: 'key',
renderFrom: '0x1440ec793aE50fA046B95bFeCa5aF475b6003f9e',
renderTo: '0x77648F1407986479fb1fA5Cc3597084B5dbDB057',
value: '1000 USDT',
fiatValue: undefined,
isIncomingTransfer: true,
transactionType: 'transaction_received_token',
});
expect(transactionDetails).toEqual({
renderTotalGas: '< 0.00001 ETH',
renderValue: '1000 USDT',
renderFrom: '0x1440ec793aE50fA046B95bFeCa5aF475b6003f9e',
renderTo: '0x77648F1407986479fb1fA5Cc3597084B5dbDB057',
transactionHash:
'0x942d7843454266b81bf631022aa5f3f944691731b62d67c4e80c4bb5740058bb',
transactionType: 'transaction_received_token',
summaryAmount: '1000 USDT',
summaryFee: '< 0.00001 ETH',
summaryTotalAmount: '1000 USDT / < 0.00001 ETH',
summarySecondaryTotalAmount: undefined,
});
});
});
Loading