Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Wallet/Wallet.js
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | export const ExternalLink = styled.a` | ||||
@media (max-width: 768px) { | @media (max-width: 768px) { | ||||
padding: 10px 0; | padding: 10px 0; | ||||
font-size: 14px; | font-size: 14px; | ||||
} | } | ||||
`; | `; | ||||
const WalletInfo = () => { | const WalletInfo = () => { | ||||
const ContextValue = React.useContext(WalletContext); | const ContextValue = React.useContext(WalletContext); | ||||
const { | const { wallet, fiatPrice, apiError } = ContextValue; | ||||
wallet, | let balances; | ||||
fiatPrice, | let parsedTxHistory; | ||||
balances, | let tokens; | ||||
tokens, | // use parameters from wallet.state object and not legacy separate parameters, if they are in state | ||||
parsedTxHistory, | // handle edge case of user with old wallet who has not opened latest Cashtab version yet | ||||
apiError, | |||||
} = ContextValue; | // If the wallet object from ContextValue has a `state key`, then check which keys are in the wallet object | ||||
// Else set it as blank | |||||
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') && | |||||
paramsInWalletState.includes('parsedTxHistory') && | |||||
paramsInWalletState.includes('tokens') | |||||
) { | |||||
balances = wallet.state.balances; | |||||
parsedTxHistory = wallet.state.parsedTxHistory; | |||||
tokens = wallet.state.tokens; | |||||
} 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; | |||||
parsedTxHistory = ContextValue.parsedTxHistory; | |||||
tokens = ContextValue.tokens; | |||||
} | |||||
const [address, setAddress] = React.useState('cashAddress'); | const [address, setAddress] = React.useState('cashAddress'); | ||||
const [activeTab, setActiveTab] = React.useState('txHistory'); | const [activeTab, setActiveTab] = React.useState('txHistory'); | ||||
const hasHistory = parsedTxHistory && parsedTxHistory.length > 0; | const hasHistory = parsedTxHistory && parsedTxHistory.length > 0; | ||||
const handleChangeAddress = () => { | const handleChangeAddress = () => { | ||||
setAddress(address === 'cashAddress' ? 'slpAddress' : 'cashAddress'); | setAddress(address === 'cashAddress' ? 'slpAddress' : 'cashAddress'); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |