Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong behaviour of switch wallet #1646

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/components/WalletConnection/WalletSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,21 @@ export const WalletSelector = () => {
const mainnetProvider = getENSProvider();
const [unsTlds, setUnsTlds] = useState<string[]>([]);
const trackEvent = useRootStore((store) => store.trackEvent);
const [blockingError, setBlockingError] = useState<ErrorType | undefined>();

let blockingError: ErrorType | undefined = undefined;
if (error) {
if (error instanceof UnsupportedChainIdError) {
blockingError = ErrorType.UNSUPORTED_CHAIN;
} else if (error instanceof UserRejectedRequestError) {
blockingError = ErrorType.USER_REJECTED_REQUEST;
} else if (error instanceof NoEthereumProviderError) {
blockingError = ErrorType.NO_WALLET_DETECTED;
} else {
blockingError = ErrorType.UNDETERMINED_ERROR;
useEffect(() => {
if (error) {
if (error instanceof UnsupportedChainIdError) {
setBlockingError(ErrorType.UNSUPORTED_CHAIN);
} else if (error instanceof UserRejectedRequestError) {
setBlockingError(ErrorType.USER_REJECTED_REQUEST);
} else if (error instanceof NoEthereumProviderError) {
setBlockingError(ErrorType.NO_WALLET_DETECTED);
} else {
setBlockingError(ErrorType.UNDETERMINED_ERROR);
}
}
// TODO: add other errors
}
}, [error]);

// Get UNS Tlds. Grabbing this fron an endpoint since Unstoppable adds new TLDs frequently, so this wills tay updated
useEffect(() => {
Expand Down Expand Up @@ -203,7 +204,7 @@ export const WalletSelector = () => {
return (
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<TxModalTitle title="Connect a wallet" />
{error && <Warning severity="error">{handleBlocking()}</Warning>}
{blockingError && <Warning severity="error">{handleBlocking()}</Warning>}
<WalletRow
key="browser_wallet"
walletName="Browser wallet"
Expand Down
9 changes: 7 additions & 2 deletions src/libs/web3-data-provider/Web3Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil

// const [provider, setProvider] = useState<JsonRpcProvider>();
const [connector, setConnector] = useState<AbstractConnector>();
const [currentAccount, setCurrentAccount] = useState<string | undefined>(account?.toLowerCase());
const [loading, setLoading] = useState(false);
const [tried, setTried] = useState(false);
const [deactivated, setDeactivated] = useState(false);
Expand Down Expand Up @@ -120,6 +121,7 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
setLoading(false);
setDeactivated(true);
setSwitchNetworkError(undefined);
setCurrentAccount(undefined);
}, [provider, connector]);

const connectReadOnlyMode = (address: string): Promise<void> => {
Expand Down Expand Up @@ -424,7 +426,10 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil

// inject account into zustand as long as aave itnerface is using old web3 providers
useEffect(() => {
setAccount(account?.toLowerCase());
if (account && account.toLowerCase() !== currentAccount) {
setCurrentAccount(account?.toLowerCase());
setAccount(account?.toLowerCase());
}
}, [account]);

useEffect(() => {
Expand All @@ -446,7 +451,7 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
getTxError,
sendTx,
signTxData,
currentAccount: account?.toLowerCase() || '',
currentAccount: currentAccount || '',
addERC20Token,
error,
switchNetworkError,
Expand Down