Skip to content

Commit

Permalink
fix: Transaction Details view shows inaccurate balance on Mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Jan 18, 2024
1 parent c681f89 commit ce9c2d2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/components/UI/TransactionElement/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function getCollectibleTransfer(args) {
return [transactionElement, transactionDetails];
}

function decodeIncomingTransfer(args) {
export function decodeIncomingTransfer(args) {
const {
tx: {
transaction: { to, from, value },
Expand All @@ -281,7 +281,8 @@ function decodeIncomingTransfer(args) {
selectedAddress,
} = args;

const amount = toBN(value);
const decimalAmount = parseInt(value, 16).toString();
const amount = toBN(decimalAmount);
const token = { symbol, decimals, address: contractAddress };

const renderTokenAmount = token
Expand All @@ -299,6 +300,7 @@ function decodeIncomingTransfer(args) {
exchangeRate,
currentCurrency,
);

renderTokenFiatNumber = balanceToFiatNumber(
fromTokenMinimalUnit(amount, token.decimals) || 0,
conversionRate,
Expand Down
57 changes: 57 additions & 0 deletions app/components/UI/TransactionElement/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { decodeIncomingTransfer } from './utils';
describe('decodeIncomingTransfer', () => {
it('should decode an incoming transfer', () => {
// Arrange
const args = {
tx: {
transaction: {
to: '0x77648f1407986479fb1fa5cc3597084b5dbdb057',
from: '0x1440ec793ae50fa046b95bfeca5af475b6003f9e',
value: '0x52daf0',
},
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: '5.43 USDT',
fiatValue: undefined,
isIncomingTransfer: true,
transactionType: 'transaction_received_token',
});
expect(transactionDetails).toEqual({
renderTotalGas: '< 0.00001 ETH',
renderValue: '5.43 USDT',
renderFrom: '0x1440ec793aE50fA046B95bFeCa5aF475b6003f9e',
renderTo: '0x77648F1407986479fb1fA5Cc3597084B5dbDB057',
transactionHash:
'0x942d7843454266b81bf631022aa5f3f944691731b62d67c4e80c4bb5740058bb',
transactionType: 'transaction_received_token',
summaryAmount: '5.43 USDT',
summaryFee: '< 0.00001 ETH',
summaryTotalAmount: '5.43 USDT / < 0.00001 ETH',
summarySecondaryTotalAmount: undefined,
});
});
});

0 comments on commit ce9c2d2

Please sign in to comment.