Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Send/Send.js
Show All 16 Lines | |||||
import { isMobile, isIOS, isSafari } from 'react-device-detect'; | import { isMobile, isIOS, isSafari } from 'react-device-detect'; | ||||
import { | import { | ||||
currency, | currency, | ||||
isValidTokenPrefix, | isValidTokenPrefix, | ||||
parseAddress, | parseAddress, | ||||
toLegacy, | toLegacy, | ||||
} from '@components/Common/Ticker.js'; | } from '@components/Common/Ticker.js'; | ||||
import { Event } from '@utils/GoogleAnalytics'; | import { Event } from '@utils/GoogleAnalytics'; | ||||
import BigNumber from 'bignumber.js'; | |||||
export const BalanceHeader = styled.div` | export const BalanceHeader = styled.div` | ||||
p { | p { | ||||
color: #777; | color: #777; | ||||
width: 100%; | width: 100%; | ||||
font-size: 14px; | font-size: 14px; | ||||
margin-bottom: 0px; | margin-bottom: 0px; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | async function submit() { | ||||
); | ); | ||||
return; | return; | ||||
} | } | ||||
// Calculate the amount in BCH | // Calculate the amount in BCH | ||||
let bchValue = value; | let bchValue = value; | ||||
if (selectedCurrency === 'USD') { | if (selectedCurrency === 'USD') { | ||||
bchValue = (value / fiatPrice).toFixed(8); | bchValue = new BigNumber((value / fiatPrice).toFixed(8)).toString(); | ||||
} | } | ||||
try { | try { | ||||
const link = await sendBch( | const link = await sendBch( | ||||
BCH, | BCH, | ||||
wallet, | wallet, | ||||
slpBalancesAndUtxos.nonSlpUtxos, | slpBalancesAndUtxos.nonSlpUtxos, | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | const handleSelectedCurrencyChange = e => { | ||||
setSelectedCurrency(e); | setSelectedCurrency(e); | ||||
// Clear input field to prevent accidentally sending 1 BCH instead of 1 USD | // Clear input field to prevent accidentally sending 1 BCH instead of 1 USD | ||||
setFormData(p => ({ ...p, value: '' })); | setFormData(p => ({ ...p, value: '' })); | ||||
}; | }; | ||||
const handleBchAmountChange = e => { | const handleBchAmountChange = e => { | ||||
const { value, name } = e.target; | const { value, name } = e.target; | ||||
let error = false; | let error = false; | ||||
let bchValue = value; | |||||
let BigNumCashAmount = new BigNumber(value); | |||||
if (selectedCurrency === 'USD') { | if (selectedCurrency === 'USD') { | ||||
bchValue = (value / fiatPrice).toFixed(8); | BigNumCashAmount = new BigNumber((value / fiatPrice).toFixed(8)); | ||||
} | } | ||||
// Validate value for > 0 | // Validate value for > 0 | ||||
if (isNaN(bchValue)) { | if (isNaN(BigNumCashAmount)) { | ||||
error = 'Amount must be a number'; | error = 'Amount must be a number'; | ||||
} else if (bchValue <= 0) { | } else if (BigNumCashAmount.lte(0)) { | ||||
error = 'Amount must be greater than 0'; | error = 'Amount must be greater than 0'; | ||||
} else if (bchValue < currency.dust) { | } else if (BigNumCashAmount.lt(currency.dust)) { | ||||
error = `Send amount must be at least ${currency.dust} ${currency.ticker}`; | error = `Send amount must be at least ${currency.dust} ${currency.ticker}`; | ||||
} else if (bchValue > balances.totalBalance) { | } else if (BigNumCashAmount.gt(new BigNumber(balances.totalBalance))) { | ||||
error = `Amount cannot exceed your ${currency.ticker} balance`; | error = `Amount cannot exceed your ${currency.ticker} balance`; | ||||
} else if (!isNaN(bchValue) && bchValue.toString().includes('.')) { | } else if ( | ||||
if (bchValue.toString().split('.')[1].length > 8) { | !isNaN(BigNumCashAmount) && | ||||
BigNumCashAmount.toString().includes('.') | |||||
) { | |||||
if (BigNumCashAmount.toString().split('.')[1].length > 8) { | |||||
error = `${currency.ticker} transactions do not support more than 8 decimal places`; | error = `${currency.ticker} transactions do not support more than 8 decimal places`; | ||||
} | } | ||||
} | } | ||||
setSendBchAmountError(error); | setSendBchAmountError(error); | ||||
setFormData(p => ({ ...p, [name]: value })); | setFormData(p => ({ ...p, [name]: value })); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines |