Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Send/Send.js
Show All 26 Lines | |||||
import { | import { | ||||
ZeroBalanceHeader, | ZeroBalanceHeader, | ||||
ConvertAmount, | ConvertAmount, | ||||
AlertMsg, | AlertMsg, | ||||
} from '@components/Common/Atoms'; | } from '@components/Common/Atoms'; | ||||
import { getWalletState } from '@utils/cashMethods'; | import { getWalletState } from '@utils/cashMethods'; | ||||
import { CashReceivedNotificationIcon } from '@components/Common/CustomIcons'; | import { CashReceivedNotificationIcon } from '@components/Common/CustomIcons'; | ||||
import ApiError from '@components/Common/ApiError'; | import ApiError from '@components/Common/ApiError'; | ||||
import { formatFiatBalance } from '@utils/validation'; | |||||
// Note jestBCH is only used for unit tests; BCHJS must be mocked for jest | // Note jestBCH is only used for unit tests; BCHJS must be mocked for jest | ||||
const SendBCH = ({ jestBCH, passLoadingStatus }) => { | const SendBCH = ({ jestBCH, passLoadingStatus }) => { | ||||
// use balance parameters from wallet.state object and not legacy balances parameter from walletState, if user has migrated wallet | // use balance parameters from wallet.state object and not legacy balances parameter from walletState, if user has migrated wallet | ||||
// this handles edge case of user with old wallet who has not opened latest Cashtab version yet | // this handles edge case of user with old wallet who has not opened latest Cashtab version yet | ||||
// If the wallet object from ContextValue has a `state key`, then check which keys are in the wallet object | // If the wallet object from ContextValue has a `state key`, then check which keys are in the wallet object | ||||
// Else set it as blank | // Else set it as blank | ||||
▲ Show 20 Lines • Show All 311 Lines • ▼ Show 20 Lines | const onMax = async () => { | ||||
'Unable to calculate the max value due to network errors', | 'Unable to calculate the max value due to network errors', | ||||
); | ); | ||||
} | } | ||||
}; | }; | ||||
// Display price in USD below input field for send amount, if it can be calculated | // Display price in USD below input field for send amount, if it can be calculated | ||||
let fiatPriceString = ''; | let fiatPriceString = ''; | ||||
if (fiatPrice !== null && !isNaN(formData.value)) { | if (fiatPrice !== null && !isNaN(formData.value)) { | ||||
if (selectedCurrency === currency.ticker) { | if (selectedCurrency === currency.ticker) { | ||||
fiatPriceString = `${ | // calculate conversion to fiatPrice | ||||
bytesofman: This code block (inside this `if() {}` statement) needs to handle the case where… | |||||
cashtabSettings | fiatPriceString = `${(fiatPrice * Number(formData.value)).toFixed( | ||||
? `${ | 2, | ||||
currency.fiatCurrencies[cashtabSettings.fiatCurrency] | )}`; | ||||
.symbol | |||||
} ` | // formats to fiat locale style | ||||
: '$ ' | fiatPriceString = formatFiatBalance(Number(fiatPriceString)); | ||||
} ${(fiatPrice * Number(formData.value)).toFixed(2)} ${ | |||||
cashtabSettings && cashtabSettings.fiatCurrency | // insert symbol and currency before/after the locale formatted fiat balance | ||||
? cashtabSettings.fiatCurrency.toUpperCase() | fiatPriceString = | ||||
: 'USD' | currency.fiatCurrencies[cashtabSettings?.fiatCurrency]?.symbol + | ||||
}`; | ' ' + | ||||
fiatPriceString + | |||||
' ' + | |||||
cashtabSettings?.fiatCurrency.toUpperCase(); | |||||
} else { | } else { | ||||
fiatPriceString = `${ | fiatPriceString = `${ | ||||
formData.value ? fiatToCrypto(formData.value, fiatPrice) : '0' | formData.value | ||||
? formatFiatBalance( | |||||
Number(fiatToCrypto(formData.value, fiatPrice)), | |||||
) | |||||
: formatFiatBalance(0) | |||||
} ${currency.ticker}`; | } ${currency.ticker}`; | ||||
} | } | ||||
} | } | ||||
const priceApiError = fiatPrice === null && selectedCurrency !== 'XEC'; | const priceApiError = fiatPrice === null && selectedCurrency !== 'XEC'; | ||||
return ( | return ( | ||||
<> | <> | ||||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |
This code block (inside this if() {} statement) needs to handle the case where cashtabSettings is false, similar to the code block it is replacing.
If cashtabSettings is false, assume currency is USD.
It's an edge case for wallets that haven't been loaded since this feature was pushed, but no reason not to preserve it.