Hello Stackoverflow Community,
I was hoping you could help me with the following logic. I would like to return from a custom-built hook the last item the user selected in a onClick function.
const useActiveWeb3React = (): Web3ReactContextInterface<Web3Provider> => {
const { chainId, account, ...web3React } = useWeb3React()
const { solanaAccount, solanaChainId } = useSolanaWeb3React()
const activeChain = "if the user's last selected chain is Solana" ? solanaChainId : chainId
const activeAccount = activeChain === ChainId.SOLANA ? solanaAccount : account
return { chainId: activeChain, account: activeAccount, ...web3React }
}
OnClick handler that would send a network change request to either MetaMask or Phantom Wallet when user selects one of the chains.
const handleSelection = (network: ChainId) => {
onDismiss()
onNetworkSelect(network)
}
What I would like to accomplish is that if the user selected in the app ChainId.SOLANA
I would like to update activeChain
variable in the useActiveWeb3React
hook so that the whole app also knows user now wants to be on Solana. And then if the user switches back to Ethereum
I want to update the activeChain
to reflect the users last selection. Also I would like to stay at that chain if user refreshes the app.
I have access to redux store in the app.
How would you do it?
Thanks for suggestions!