Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Send/Send.js
Show All 22 Lines | |||||
import { Event } from '@utils/GoogleAnalytics'; | import { Event } from '@utils/GoogleAnalytics'; | ||||
import { fiatToCrypto, shouldRejectAmountInput } from '@utils/validation'; | import { fiatToCrypto, shouldRejectAmountInput } from '@utils/validation'; | ||||
import { formatBalance } from '@utils/cashMethods'; | import { formatBalance } from '@utils/cashMethods'; | ||||
import { | import { | ||||
BalanceHeader, | BalanceHeader, | ||||
BalanceHeaderFiat, | BalanceHeaderFiat, | ||||
ZeroBalanceHeader, | ZeroBalanceHeader, | ||||
ConvertAmount, | ConvertAmount, | ||||
AlertMsg, | |||||
} from '@components/Common/Atoms'; | } from '@components/Common/Atoms'; | ||||
// 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, filledAddress, callbackTxId }) => { | const SendBCH = ({ jestBCH, filledAddress, callbackTxId }) => { | ||||
// 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 | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | const handleAddressChange = e => { | ||||
const { address, isValid, queryString, amount } = addressInfo; | const { address, isValid, queryString, amount } = addressInfo; | ||||
// If query string, | // If query string, | ||||
// Show an alert that only amount and currency.ticker are supported | // Show an alert that only amount and currency.ticker are supported | ||||
setQueryStringText(queryString); | setQueryStringText(queryString); | ||||
// Is this valid address? | // Is this valid address? | ||||
if (!isValid) { | if (!isValid) { | ||||
error = 'Address is not a valid cash address'; | error = `Invalid ${currency.ticker} address`; | ||||
// If valid address but token format | // If valid address but token format | ||||
if (isValidTokenPrefix(address)) { | if (isValidTokenPrefix(address)) { | ||||
error = `Token addresses are not supported for ${currency.ticker} sends`; | error = `Token addresses are not supported for ${currency.ticker} sends`; | ||||
} | } | ||||
} | } | ||||
setSendBchAddressError(error); | setSendBchAddressError(error); | ||||
// Set amount if it's in the query string | // Set amount if it's in the query string | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | if (fiatPrice !== null && !isNaN(formData.value)) { | ||||
)} USD`; | )} USD`; | ||||
} else { | } else { | ||||
fiatPriceString = `${ | fiatPriceString = `${ | ||||
formData.value ? fiatToCrypto(formData.value, fiatPrice) : '0' | formData.value ? fiatToCrypto(formData.value, fiatPrice) : '0' | ||||
} ${currency.ticker}`; | } ${currency.ticker}`; | ||||
} | } | ||||
} | } | ||||
const priceApiError = fiatPrice === null && selectedCurrency === 'USD'; | |||||
return ( | return ( | ||||
<> | <> | ||||
<Modal | <Modal | ||||
title="Confirm Send" | title="Confirm Send" | ||||
visible={isModalVisible} | visible={isModalVisible} | ||||
onOk={handleOk} | onOk={handleOk} | ||||
onCancel={handleCancel} | onCancel={handleCancel} | ||||
> | > | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | return ( | ||||
}} | }} | ||||
selectProps={{ | selectProps={{ | ||||
value: selectedCurrency, | value: selectedCurrency, | ||||
disabled: queryStringText !== null, | disabled: queryStringText !== null, | ||||
onChange: e => | onChange: e => | ||||
handleSelectedCurrencyChange(e), | handleSelectedCurrencyChange(e), | ||||
}} | }} | ||||
></SendBchInput> | ></SendBchInput> | ||||
<ConvertAmount>= {fiatPriceString}</ConvertAmount> | {priceApiError && ( | ||||
<AlertMsg> | |||||
Error fetching fiat price. Setting send by | |||||
USD disabled | |||||
</AlertMsg> | |||||
)} | |||||
<ConvertAmount> | |||||
{fiatPriceString !== '' && '='}{' '} | |||||
{fiatPriceString} | |||||
</ConvertAmount> | |||||
<div | <div | ||||
style={{ | style={{ | ||||
paddingTop: '12px', | paddingTop: '12px', | ||||
}} | }} | ||||
> | > | ||||
{!balances.totalBalance || | {!balances.totalBalance || | ||||
apiError || | apiError || | ||||
sendBchAmountError || | sendBchAmountError || | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |