-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix: Mev toggle not shown when user doesnt have enough native and modal shown when changing chains #11339
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
base: develop
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
7 Skipped Deployments
|
@@ -100,26 +42,15 @@ async function fetchMEVStatus(walletClient: WalletClient): Promise<{ mevEnabled: | |||
} | |||
} | |||
|
|||
export function useWalletSupportsAddEthereumChain() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function not needed
@@ -129,22 +60,20 @@ export function useIsMEVEnabled() { | |||
(walletType !== WalletType.mevNotSupported && | |||
(data?.mevEnabled || (walletType === WalletType.mevDefaultOnBSC && chainId === ChainId.BSC))) ?? | |||
false, | |||
isLoading, | |||
isLoading: isPending || isLoading, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to not show toggle when in first render
const { data, isLoading, refetch } = useQuery({ | ||
queryKey: ['isMEVEnabled', walletClient, account, chainId, walletType], | ||
const { data, isLoading, isPending, refetch } = useQuery({ | ||
queryKey: ['isMEVEnabled', walletClient?.uid, account, chainId, walletType], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serializing the walletclient is a heavy operation, uid is enough to make it unique
queryFn: () => fetchMEVStatus(walletClient!), | ||
enabled: Boolean(account) && walletClient && chainId === ChainId.BSC, | ||
enabled: Boolean(account && walletClient && chainId === ChainId.BSC), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when there is account but not walletclient (on initial render) enabled becomes undefined which makes query hook to be fetched with undefined walletclient. So the whole condition needs to be wrapped with boolean
@@ -84,10 +28,8 @@ async function fetchMEVStatus(walletClient: WalletClient): Promise<{ mevEnabled: | |||
method: 'eth_call', | |||
params: [ | |||
{ | |||
from: walletClient.account?.address ?? '0x', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user's address shouldnt be used, because it cannot correctly query if user doesn't have enough native token
@@ -55,6 +56,12 @@ export const MevToggle: React.FC = () => { | |||
}, | |||
) | |||
|
|||
useEffect(() => { | |||
if (!shouldShowMEVToggle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for to prevent, after adding the rpc modal isOpen stays true which results opening the modal again (without user clicking the toggle) when switching back to bsc (on some wallets it switches back to default rpc which results mev become disabled)
…al shown when changing chains
…al shown when changing chains
978cc93
to
eaef53a
Compare
PR-Codex overview
This PR introduces a
useEffect
hook in theMevToggle
component to handle the visibility of the MEV toggle based on theshouldShowMEVToggle
state. It also removes theWalletProviders
array and related functionality, streamlining the wallet support checks.Detailed summary
useEffect
inMevToggle
to dismiss toggle ifshouldShowMEVToggle
is false.WalletProviders
array andcheckWalletSupportAddEthereumChain
function fromhooks/index.ts
.useIsMEVEnabled
to modify query parameters and conditions.useIsMEVEnabled
.useShouldShowMEVToggle
.