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) { | ||||
// calculate conversion to fiatPrice | |||||
fiatPriceString = `${(fiatPrice * Number(formData.value)).toFixed( | |||||
2, | |||||
)}`; | |||||
// formats to fiat locale style | |||||
fiatPriceString = formatFiatBalance(Number(fiatPriceString)); | |||||
// insert symbol and currency before/after the locale formatted fiat balance | |||||
fiatPriceString = `${ | fiatPriceString = `${ | ||||
cashtabSettings | cashtabSettings | ||||
? `${ | ? `${ | ||||
currency.fiatCurrencies[cashtabSettings.fiatCurrency] | currency.fiatCurrencies[cashtabSettings.fiatCurrency] | ||||
.symbol | .symbol | ||||
} ` | } ` | ||||
: '$ ' | : '$ ' | ||||
} ${(fiatPrice * Number(formData.value)).toFixed(2)} ${ | } ${fiatPriceString} ${ | ||||
cashtabSettings && cashtabSettings.fiatCurrency | cashtabSettings && cashtabSettings.fiatCurrency | ||||
? cashtabSettings.fiatCurrency.toUpperCase() | ? cashtabSettings.fiatCurrency.toUpperCase() | ||||
: 'USD' | : 'USD' | ||||
}`; | }`; | ||||
} 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 |