Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Send/SendToken.js
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | |||||
const SendToken = ({ tokenId, jestBCH, passLoadingStatus }) => { | const SendToken = ({ tokenId, jestBCH, passLoadingStatus }) => { | ||||
const { BCH, wallet, apiError, cashtabSettings, chronik } = | const { BCH, wallet, apiError, cashtabSettings, chronik } = | ||||
React.useContext(WalletContext); | React.useContext(WalletContext); | ||||
const walletState = getWalletState(wallet); | const walletState = getWalletState(wallet); | ||||
const { tokens } = walletState; | const { tokens } = walletState; | ||||
const token = tokens.find(token => token.tokenId === tokenId); | const token = tokens.find(token => token.tokenId === tokenId); | ||||
const previousToken = usePrevious(token); | const previousWalletState = usePrevious(walletState); | ||||
const [tokenStats, setTokenStats] = useState(null); | const [tokenStats, setTokenStats] = useState(null); | ||||
const [queryStringText, setQueryStringText] = useState(null); | const [queryStringText, setQueryStringText] = useState(null); | ||||
const [sendTokenAddressError, setSendTokenAddressError] = useState(false); | const [sendTokenAddressError, setSendTokenAddressError] = useState(false); | ||||
const [sendTokenAmountError, setSendTokenAmountError] = useState(false); | const [sendTokenAmountError, setSendTokenAmountError] = useState(false); | ||||
const [eTokenBurnAmount, setETokenBurnAmount] = useState(new BigNumber(1)); | const [eTokenBurnAmount, setETokenBurnAmount] = useState(new BigNumber(1)); | ||||
const [showConfirmBurnEtoken, setShowConfirmBurnEtoken] = useState(false); | const [showConfirmBurnEtoken, setShowConfirmBurnEtoken] = useState(false); | ||||
const [burnTokenAmountError, setBurnTokenAmountError] = useState(false); | const [burnTokenAmountError, setBurnTokenAmountError] = useState(false); | ||||
▲ Show 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | const handleBurnConfirmationInput = e => { | ||||
setConfirmationOfEtokenToBeBurnt(value); | setConfirmationOfEtokenToBeBurnt(value); | ||||
}; | }; | ||||
const handleBurnAmountInput = () => { | const handleBurnAmountInput = () => { | ||||
if (!burnTokenAmountError) { | if (!burnTokenAmountError) { | ||||
setShowConfirmBurnEtoken(true); | setShowConfirmBurnEtoken(true); | ||||
} | } | ||||
}; | }; | ||||
useEffect(() => { | useEffect(() => { | ||||
/* | // Unlock UI after user sends an eToken tx to their own wallet | ||||
If the balance has changed, unlock the UI | |||||
Note that the 'token' dependency changes every time the wallet state is set | |||||
This useEffect loop can't use token.balance as the dependency as this is | |||||
occasionally undefined, which the screen UI also makes use of | |||||
*/ | |||||
if ( | if ( | ||||
token && | walletState && | ||||
token.balance && | walletState.balances && | ||||
previousToken && | walletState.balances.totalBalanceInSatoshis && | ||||
previousToken.balance && | previousWalletState && | ||||
token.balance.toString() !== previousToken.balance.toString() | previousWalletState.balances && | ||||
previousWalletState.balances.totalBalanceInSatoshis && | |||||
walletState.balances.totalBalanceInSatoshis !== | |||||
previousWalletState.balances.totalBalanceInSatoshis | |||||
) { | ) { | ||||
passLoadingStatus(false); | passLoadingStatus(false); | ||||
} | } | ||||
// In the case of a tx that burns all of a token, also lose the loader | }, [walletState]); | ||||
if (!token && previousToken) { | |||||
passLoadingStatus(false); | |||||
} | |||||
}, [token]); | |||||
return ( | return ( | ||||
<> | <> | ||||
<Modal | <Modal | ||||
title="Confirm Send" | title="Confirm Send" | ||||
open={isModalVisible} | open={isModalVisible} | ||||
onOk={handleOk} | onOk={handleOk} | ||||
onCancel={handleCancel} | onCancel={handleCancel} | ||||
▲ Show 20 Lines • Show All 347 Lines • Show Last 20 Lines |