Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Send/Send.js
Show All 23 Lines | |||||
import { fiatToCrypto, shouldRejectAmountInput } from '@utils/validation'; | import { fiatToCrypto, shouldRejectAmountInput } from '@utils/validation'; | ||||
import { BalanceHeader } from '@components/Common/BalanceHeader'; | import { BalanceHeader } from '@components/Common/BalanceHeader'; | ||||
import { BalanceHeaderFiat } from '@components/Common/BalanceHeaderFiat'; | import { BalanceHeaderFiat } from '@components/Common/BalanceHeaderFiat'; | ||||
import { | import { | ||||
ZeroBalanceHeader, | ZeroBalanceHeader, | ||||
ConvertAmount, | ConvertAmount, | ||||
AlertMsg, | AlertMsg, | ||||
} from '@components/Common/Atoms'; | } from '@components/Common/Atoms'; | ||||
import { getWalletState } from '@utils/cashMethods'; | |||||
// 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 | ||||
const ContextValue = React.useContext(WalletContext); | const ContextValue = React.useContext(WalletContext); | ||||
const { | const { wallet, fiatPrice, apiError, cashtabSettings } = ContextValue; | ||||
wallet, | const walletState = getWalletState(wallet); | ||||
fiatPrice, | const { balances, slpBalancesAndUtxos } = walletState; | ||||
slpBalancesAndUtxos, | |||||
apiError, | |||||
cashtabSettings, | |||||
} = ContextValue; | |||||
let balances; | |||||
const paramsInWalletState = wallet.state ? Object.keys(wallet.state) : []; | |||||
// If wallet.state includes balances and parsedTxHistory params, use these | |||||
// These are saved in indexedDb in the latest version of the app, hence accessible more quickly | |||||
if (paramsInWalletState.includes('balances')) { | |||||
balances = wallet.state.balances; | |||||
} else { | |||||
// If balances and parsedTxHistory are not in the wallet.state object, load them from Context | |||||
// This is how the app used to work | |||||
balances = ContextValue.balances; | |||||
} | |||||
// Get device window width | // Get device window width | ||||
// If this is less than 769, the page will open with QR scanner open | // If this is less than 769, the page will open with QR scanner open | ||||
const { width } = useWindowDimensions(); | const { width } = useWindowDimensions(); | ||||
// Load with QR code open if device is mobile and NOT iOS + anything but safari | // Load with QR code open if device is mobile and NOT iOS + anything but safari | ||||
const scannerSupported = width < 769 && isMobile && !(isIOS && !isSafari); | const scannerSupported = width < 769 && isMobile && !(isIOS && !isSafari); | ||||
const [formData, setFormData] = useState({ | const [formData, setFormData] = useState({ | ||||
▲ Show 20 Lines • Show All 493 Lines • Show Last 20 Lines |