Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Send/Send.js
Show First 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | |||||
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 | ||||
const ContextValue = React.useContext(WalletContext); | const ContextValue = React.useContext(WalletContext); | ||||
const location = useLocation(); | const location = useLocation(); | ||||
const { BCH, wallet, fiatPrice, apiError, cashtabSettings, chronik } = | const { | ||||
ContextValue; | BCH, | ||||
wallet, | |||||
fiatPrice, | |||||
apiError, | |||||
cashtabSettings, | |||||
chronik, | |||||
Backendless, | |||||
} = ContextValue; | |||||
const walletState = getWalletState(wallet); | const walletState = getWalletState(wallet); | ||||
const { balances, slpBalancesAndUtxos } = walletState; | const { balances, slpBalancesAndUtxos } = walletState; | ||||
// Modal settings | // Modal settings | ||||
const [showConfirmMsgToSign, setShowConfirmMsgToSign] = useState(false); | const [showConfirmMsgToSign, setShowConfirmMsgToSign] = useState(false); | ||||
const [msgToSign, setMsgToSign] = useState(''); | const [msgToSign, setMsgToSign] = useState(''); | ||||
const [signMessageIsValid, setSignMessageIsValid] = useState(null); | const [signMessageIsValid, setSignMessageIsValid] = useState(null); | ||||
const [isOneToManyXECSend, setIsOneToManyXECSend] = useState(false); | const [isOneToManyXECSend, setIsOneToManyXECSend] = useState(false); | ||||
const [opReturnMsg, setOpReturnMsg] = useState(false); | const [opReturnMsg, setOpReturnMsg] = useState(false); | ||||
▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | async function send() { | ||||
return; | return; | ||||
} | } | ||||
// Event("Category", "Action", "Label") | // Event("Category", "Action", "Label") | ||||
// Track number of BCHA send transactions and whether users | // Track number of BCHA send transactions and whether users | ||||
// are sending BCHA or USD | // are sending BCHA or USD | ||||
Event('Send.js', 'Send', selectedCurrency); | Event('Send.js', 'Send', selectedCurrency); | ||||
let aliasFlag = false; | |||||
passLoadingStatus(true); | passLoadingStatus(true); | ||||
const { address, value } = formData; | const { address, value } = formData; | ||||
let cleanAddress; | |||||
if (formData.address.slice(-4).toLowerCase() === '.xec') { | |||||
cleanAddress = formData.address; | |||||
aliasFlag = true; | |||||
} else { | |||||
// Get the param-free address | // Get the param-free address | ||||
let cleanAddress = address.split('?')[0]; | cleanAddress = address.split('?')[0]; | ||||
// Ensure address has bitcoincash: prefix and checksum | // Ensure address has bitcoincash: prefix and checksum | ||||
cleanAddress = toLegacyCash(cleanAddress); | cleanAddress = toLegacyCash(cleanAddress); | ||||
} | |||||
// Calculate the amount in BCH | // Calculate the amount in BCH | ||||
let bchValue = value; | let bchValue = value; | ||||
if (selectedCurrency !== 'XEC') { | if (selectedCurrency !== 'XEC') { | ||||
bchValue = fiatToCrypto(value, fiatPrice); | bchValue = fiatToCrypto(value, fiatPrice); | ||||
} | } | ||||
// encrypted message limit truncation | // encrypted message limit truncation | ||||
Show All 15 Lines | async function send() { | ||||
slpBalancesAndUtxos.nonSlpUtxos, | slpBalancesAndUtxos.nonSlpUtxos, | ||||
currency.defaultFee, | currency.defaultFee, | ||||
optionalOpReturnMsg, | optionalOpReturnMsg, | ||||
false, // sendToMany boolean flag | false, // sendToMany boolean flag | ||||
null, // address array not applicable for one to many tx | null, // address array not applicable for one to many tx | ||||
cleanAddress, | cleanAddress, | ||||
bchValue, | bchValue, | ||||
isEncryptedOptionalOpReturnMsg, | isEncryptedOptionalOpReturnMsg, | ||||
null, // airdropFlag | |||||
null, // airdropTokenId | |||||
Backendless, | |||||
aliasFlag, // alias flag | |||||
); | ); | ||||
sendXecNotification(link); | sendXecNotification(link); | ||||
clearInputForms(); | clearInputForms(); | ||||
} catch (e) { | } catch (e) { | ||||
handleSendXecError(e, isOneToManyXECSend); | handleSendXecError(e, isOneToManyXECSend); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
const handleAddressChange = e => { | const handleAddressChange = e => { | ||||
const { value, name } = e.target; | const { value, name } = e.target; | ||||
let error = false; | let error = false; | ||||
let addressString = value; | let addressString = value; | ||||
let isValid; | |||||
// parse address for parameters | // parse address for parameters | ||||
const addressInfo = parseAddressForParams(addressString); | const addressInfo = parseAddressForParams(addressString); | ||||
// if the input ends in '.xec' then skip standard validation | |||||
if (addressString.slice(-4).toLowerCase() === '.xec') { | |||||
isValid = true; | |||||
} else { | |||||
// validate address | // validate address | ||||
const isValid = isValidXecAddress(addressInfo.address); | isValid = isValidXecAddress(addressInfo.address); | ||||
} | |||||
/* | /* | ||||
Model | Model | ||||
addressInfo = | addressInfo = | ||||
{ | { | ||||
address: '', | address: '', | ||||
queryString: '', | queryString: '', | ||||
▲ Show 20 Lines • Show All 870 Lines • Show Last 20 Lines |