Skip to content

Commit

Permalink
make all TransactionSummaryScreenProps consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoncalves committed Feb 20, 2024
1 parent 1957414 commit c316522
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
28 changes: 16 additions & 12 deletions src/screens/activity/ActivityRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ export const ActivityBasicRow = ({
const usdBalance = roundBalance(price, 2)

const txSummary: TransactionSummaryScreenProps = useMemo(() => {
const feeUsd = roundBalance(Number(fee.usdValue), 2)
const totalUsd = Number(price) + Number(fee.usdValue)
const tokenUsd = usdBalance.toFixed(2)
const feeUsd = Number(fee.usdValue).toFixed(2)
const totalUsd = (Number(tokenUsd) + Number(feeUsd)).toFixed(2)
const isAmountSmall = !usdBalance && !!price

const totalToken =
symbol === fee.symbol
? Number(value) + Number(fee.tokenValue)
: Number(value)

return {
transaction: {
Expand All @@ -92,21 +99,18 @@ export const ActivityBasicRow = ({
balance: value,
},
usdValue: {
symbol: usdBalance || !price ? '$' : '<',
symbol: isAmountSmall ? '<' : '$',
symbolType: 'usd',
balance: price ? usdBalance.toFixed(2) || '0.01' : '0.00',
balance: isAmountSmall ? '0.01' : tokenUsd,
},
totalToken:
symbol === fee.symbol
? Number(value) + Number(fee.tokenValue)
: Number(value),
totalUsd: roundBalance(totalUsd, 2).toFixed(2),
status,
fee: {
tokenValue: fee.tokenValue,
symbol: fee.symbol || symbol,
usdValue: feeUsd.toFixed(2),
tokenValue: fee.tokenValue,
usdValue: feeUsd,
},
totalToken,
totalUsd: totalUsd,
status,
amIReceiver,
from,
to,
Expand Down
24 changes: 10 additions & 14 deletions src/ux/requestsModal/ReviewBitcoinTransactionContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ export const ReviewBitcoinTransactionContainer = ({
convertTokenToUSD(Number(amount), tokenPrices.BTC.price).toFixed(2)

// usd values
const amountToPayUsd = convertToUSD(amountToPay)
const amountUsd = convertToUSD(amountToPay)
const feeUsd = convertToUSD(miningFee)
const isAmountSmall = !Number(amountToPayUsd) && !!Number(amountToPay)
const totalSent = Number(amountToPay) + Number(miningFee)
const totalUsd = (Number(amountUsd) + Number(feeUsd)).toFixed(2)
const isAmountSmall = !Number(amountUsd) && !!Number(amountToPay)

const totalBtc = Number(amountToPay) + Number(miningFee)

return {
transaction: {
Expand All @@ -96,24 +98,18 @@ export const ReviewBitcoinTransactionContainer = ({
symbol: TokenSymbol.BTC,
},
usdValue: {
balance: isAmountSmall ? '0.01' : amountToPayUsd,
symbolType: 'usd',
symbol: isAmountSmall ? '<' : '$',
symbolType: 'usd',
balance: isAmountSmall ? '0.01' : amountUsd,
},
fee: {
symbol: TokenSymbol.BTC,
tokenValue: miningFee,
usdValue: feeUsd,
symbol: TokenSymbol.BTC,
},
totalToken: totalBtc,
totalUsd,
time: 'approx 1 min',
total: {
tokenValue: amountToPay,
usdValue: formatTokenValues(Number(amountToPayUsd) + Number(feeUsd)),
},
totalToken: totalSent,
totalUsd: Number(
formatTokenValues(Number(amountToPayUsd) + Number(feeUsd)),
),
to: addressToPay,
},
buttons: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber } from 'ethers'
import { BigNumber, BigNumberish } from 'ethers'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Alert, StyleSheet, View } from 'react-native'
Expand Down Expand Up @@ -203,16 +203,18 @@ export const ReviewTransactionContainer = ({
Alert.alert(t('transaction_summary_insufficient_funds'))
}

// get usd values
const tokenUsd = convertTokenToUSD(Number(value), tokenQuote)
const feeUsd = convertTokenToUSD(Number(feeValue), feeQuote)
// usd values
const convertToUSD = (amount: string | BigNumberish, quote: number) =>
convertTokenToUSD(Number(amount), quote).toFixed(2)

const tokenUsd = convertToUSD(value, tokenQuote)
const feeUsd = convertToUSD(feeValue, feeQuote)
const totalUsd = (Number(tokenUsd) + Number(feeUsd)).toFixed(2)
const isAmountSmall = !Number(tokenUsd) && !!Number(value)

const totalToken =
symbol === feeSymbol ? Number(value) + Number(feeValue) : Number(value)

const totalUsd = (Number(tokenUsd) + Number(feeUsd)).toFixed(2)

return {
transaction: {
tokenValue: {
Expand All @@ -226,9 +228,9 @@ export const ReviewTransactionContainer = ({
balance: isAmountSmall ? '0.01' : tokenUsd,
},
fee: {
tokenValue: rbtcFeeValue ?? feeValue,
usdValue: formatTokenValues(feeUsd),
symbol: feeSymbol,
tokenValue: rbtcFeeValue ?? feeValue,
usdValue: feeUsd,
},
totalToken,
totalUsd,
Expand Down

0 comments on commit c316522

Please sign in to comment.