Skip to content

Commit

Permalink
feat: enable mev protection on base (#2577)
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv authored Jan 15, 2025
1 parent 3e79cb2 commit 5ca7103
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/components/SwapForm/AddMEVProtectionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ const Wrapper = styled.div`
}
`

const KYBER_SWAP_RPC = 'https://ethereum-mev-protection.kyberengineering.io/'
const KYBER_SWAP_RPC: { [key: number]: string } = {
[ChainId.MAINNET]: 'https://ethereum-mev-protection.kyberengineering.io/',
[ChainId.BASE]: 'https://base-mev-protection.kyberengineering.io/',
}

export default function AddMEVProtectionModal({ isOpen, onClose }: { isOpen: boolean; onClose: () => void }) {
const upToExtraSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToExtraSmall}px)`)
const { addNewNetwork } = useChangeNetwork()
const { mixpanelHandler } = useMixpanel()
const { walletKey } = useActiveWeb3React()
const { walletKey, chainId } = useActiveWeb3React()
const notify = useNotify()
const theme = useTheme()

Expand All @@ -55,11 +58,13 @@ export default function AddMEVProtectionModal({ isOpen, onClose }: { isOpen: boo
return
}

if (!KYBER_SWAP_RPC[chainId]) return

const name = 'Ethereum Mainnet (KyberSwap RPC)'
mixpanelHandler(MIXPANEL_TYPE.MEV_ADD_CLICK_MODAL, { type: name })
addNewNetwork(
ChainId.MAINNET,
KYBER_SWAP_RPC,
chainId,
KYBER_SWAP_RPC[chainId],
{
name,
title: t`Failed to switch to ${name} RPC Endpoint`,
Expand All @@ -80,7 +85,7 @@ export default function AddMEVProtectionModal({ isOpen, onClose }: { isOpen: boo
onClose?.()
},
)
}, [isUsingMetamask, onClose, mixpanelHandler, addNewNetwork, notify])
}, [isUsingMetamask, onClose, mixpanelHandler, addNewNetwork, notify, chainId])

return (
<Modal
Expand Down
2 changes: 1 addition & 1 deletion src/components/SwapForm/SlippageSettingGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function SlippageSettingGroup({
const { isSlippageControlPinned } = useSlippageSettingByPage()
const isPartnerSwap = window.location.pathname.startsWith(APP_PATHS.PARTNER_SWAP)
let rightButton =
chainId === ChainId.MAINNET && active && !isPartnerSwap && !isMobile && !isTablet ? (
[ChainId.MAINNET, ChainId.BASE].includes(chainId) && active && !isPartnerSwap && !isMobile && !isTablet ? (
<PriceAlertButton onClick={addMevProtectionHandler}>
<Shield size={14} color={theme.subText} />
<Text color={theme.subText} style={{ whiteSpace: 'nowrap' }}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SwapForm/SwapModal/SwapDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default function SwapDetails({
const upToXXSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToXXSmall}px)`)
const isPartnerSwap = window.location.pathname.startsWith(APP_PATHS.PARTNER_SWAP)
const addMevButton =
chainId === ChainId.MAINNET &&
(chainId === ChainId.MAINNET || chainId === ChainId.BASE) &&
active &&
!isPartnerSwap &&
slippageStatus === SLIPPAGE_STATUS.HIGH &&
Expand Down

0 comments on commit 5ca7103

Please sign in to comment.