Skip to content

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

memoyil
Copy link
Collaborator

@memoyil memoyil commented Mar 15, 2025


PR-Codex overview

This PR introduces a useEffect hook in the MevToggle component to handle the visibility of the MEV toggle based on the shouldShowMEVToggle state. It also removes the WalletProviders array and related functionality, streamlining the wallet support checks.

Detailed summary

  • Added useEffect in MevToggle to dismiss toggle if shouldShowMEVToggle is false.
  • Removed WalletProviders array and checkWalletSupportAddEthereumChain function from hooks/index.ts.
  • Updated useIsMEVEnabled to modify query parameters and conditions.
  • Simplified loading state management in useIsMEVEnabled.
  • Removed wallet support loading check in useShouldShowMEVToggle.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

changeset-bot bot commented Mar 15, 2025

⚠️ No Changeset found

Latest commit: eaef53a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Mar 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
solana ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2025 0:04am
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2025 0:04am
7 Skipped Deployments
Name Status Preview Comments Updated (UTC)
aptos-web ⬜️ Ignored (Inspect) Visit Preview Mar 20, 2025 0:04am
blog ⬜️ Ignored (Inspect) Visit Preview Mar 20, 2025 0:04am
bridge ⬜️ Ignored (Inspect) Visit Preview Mar 20, 2025 0:04am
games ⬜️ Ignored (Inspect) Visit Preview Mar 20, 2025 0:04am
gamification ⬜️ Ignored (Inspect) Visit Preview Mar 20, 2025 0:04am
uikit ⬜️ Ignored (Inspect) Visit Preview Mar 20, 2025 0:04am
ton ⬜️ Skipped (Inspect) Mar 20, 2025 0:04am

@memoyil memoyil changed the title fix: Mev toggle not shown when user doesnt have enough native and mod… fix: Mev toggle not shown when user doesnt have enough native and modal shown when changing chains Mar 15, 2025
@@ -100,26 +42,15 @@ async function fetchMEVStatus(walletClient: WalletClient): Promise<{ mevEnabled:
}
}

export function useWalletSupportsAddEthereumChain() {
Copy link
Collaborator Author

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,
Copy link
Collaborator Author

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],
Copy link
Collaborator Author

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),
Copy link
Collaborator Author

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

@vercel vercel bot temporarily deployed to Preview – ton March 15, 2025 10:32 Inactive
@@ -84,10 +28,8 @@ async function fetchMEVStatus(walletClient: WalletClient): Promise<{ mevEnabled:
method: 'eth_call',
params: [
{
from: walletClient.account?.address ?? '0x',
Copy link
Collaborator Author

@memoyil memoyil Mar 15, 2025

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) {
Copy link
Collaborator Author

@memoyil memoyil Mar 15, 2025

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant