-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
151 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Button, Flex, Menu } from "@mantine/core"; | ||
import { useChainId, useChains, useSwitchChain } from "@zerodev/waas"; | ||
import { useState } from "react"; | ||
|
||
export const CustomChevronDown = () => ( | ||
<svg fill="none" height="7" width="14" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
d="M12.75 1.54001L8.51647 5.0038C7.77974 5.60658 6.72026 5.60658 5.98352 5.0038L1.75 1.54001" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="1.3" | ||
xmlns="http://www.w3.org/2000/svg" | ||
></path> | ||
</svg> | ||
); | ||
|
||
export function SelectChainButton() { | ||
const chainId = useChainId(); | ||
const chains = useChains(); | ||
const [chainSwitching, setChainSwitching] = useState(); | ||
const { switchChain, isPending } = useSwitchChain(); | ||
|
||
return ( | ||
<Menu> | ||
<Menu.Target> | ||
<Button miw={78} px="12px"> | ||
<Flex gap="sm" align="center" mah={24} pr="2px"> | ||
<div | ||
style={{ | ||
display: "block", | ||
}} | ||
> | ||
{chains.filter((c) => c.id === chainId)[0].name} | ||
</div> | ||
<Flex miw={14}> | ||
<CustomChevronDown /> | ||
</Flex> | ||
</Flex> | ||
</Button> | ||
</Menu.Target> | ||
<Menu.Dropdown> | ||
<Flex direction="column" gap={4}> | ||
{chains.map((chn: any, idx: number) => { | ||
const isSelected = chainId === chn.id; | ||
return ( | ||
<Button | ||
loading={isPending && chainSwitching === chn.id} | ||
key={idx} | ||
onClick={() => { | ||
setChainSwitching(chn.id); | ||
switchChain({ chainId: chn.id }); | ||
}} | ||
disabled={isSelected} | ||
> | ||
<Flex w="100%" justify="space-between" align="center"> | ||
<Flex align="center" gap="xs"> | ||
<Flex>{chn.name}</Flex> | ||
</Flex> | ||
</Flex> | ||
</Button> | ||
); | ||
})} | ||
</Flex> | ||
</Menu.Dropdown> | ||
</Menu> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
export const ZERODEV_APP_ID = process.env.NEXT_PUBLIC_ZERODEV_APP_ID || ""; | ||
|
||
export const ZERODEV_ARB_APP_ID = | ||
process.env.NEXT_PUBLIC_ZERODEV_APP_ARBITRUM_ID || ""; | ||
|
||
export const ZERODEV_SEP_APP_ID = | ||
process.env.NEXT_PUBLIC_ZERODEV_APP_SEPOLIA_ID || ""; | ||
|
||
export const ZERODEV_BUNDLER_URL = `https://rpc.zerodev.app/api/v2/bundler/${ZERODEV_APP_ID}`; | ||
|
||
export const ZERODEV_PAYMASTER_URL = `https://rpc.zerodev.app/api/v2/paymaster/${ZERODEV_APP_ID}`; | ||
|
||
export const getBundler = (chainId: number) => { | ||
if (chainId === 42161) { | ||
return `https://rpc.zerodev.app/api/v2/bundler/${ZERODEV_ARB_APP_ID}`; | ||
} else return `https://rpc.zerodev.app/api/v2/bundler/${ZERODEV_SEP_APP_ID}`; | ||
}; | ||
|
||
export const getPaymaster = (chainId: number) => { | ||
if (chainId === 42161) { | ||
return `https://rpc.zerodev.app/api/v2/paymaster/${ZERODEV_ARB_APP_ID}`; | ||
} else if (chainId === 11155111) { | ||
return `https://rpc.zerodev.app/api/v2/paymaster/${ZERODEV_SEP_APP_ID}`; | ||
} | ||
return ""; | ||
}; |