Skip to content

Commit

Permalink
feat: set transport in config (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstinhw authored May 9, 2024
1 parent 0495981 commit 61936db
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@zerodev/permissions": "^5.2.5",
"@zerodev/sdk": "^5.2.11",
"@zerodev/session-key": "^5.2.2",
"@zerodev/waas": "0.1.11-alpha.0",
"@zerodev/waas": "0.1.11-alpha.1",
"encoding": "^0.1.13",
"next": "14.1.4",
"permissionless": "^0.1.16",
Expand Down
35 changes: 21 additions & 14 deletions src/components/Button/CreateCustomizedKernelButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,36 @@ import {
createKernelAccountClient,
createZeroDevPaymasterClient,
} from "@zerodev/sdk";
import { useSetKernelClient } from "@zerodev/waas";
import { useChainId, useChains, useSetKernelClient } from "@zerodev/waas";
import { ENTRYPOINT_ADDRESS_V07 } from "permissionless";
import { EntryPoint } from "permissionless/types";
import { useState } from "react";
import { getAbiItem, http, toFunctionSelector, zeroAddress } from "viem";
import {
createPublicClient,
getAbiItem,
http,
toFunctionSelector,
zeroAddress,
type Chain,
} from "viem";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { useChains, usePublicClient } from "wagmi";

export function CreateCustomizedKernelButton() {
const [isLoading, setIsLoading] = useState(false);
const publicClient = usePublicClient();
const chains = useChains();
const chainId = useChainId();
const { setKernelClient, error } = useSetKernelClient();

const createKernelClient = async () => {
const chain = chains[0];
if (!publicClient || !chain) return;
const chain = chains.find((c: Chain) => c.id === chainId);
if (!chain) return;
setIsLoading(true);

const publicClient = createPublicClient({
chain: chain,
transport: http(getBundler(chain.id)),
});

try {
const entryPoint = ENTRYPOINT_ADDRESS_V07 as EntryPoint;
const generatedAccount = privateKeyToAccount(generatePrivateKey());
Expand Down Expand Up @@ -65,20 +76,16 @@ export function CreateCustomizedKernelButton() {
},
},
});

setKernelClient(kernelClient);
} catch (err) {}
} catch (err) {
console.log(err);
}

setIsLoading(false);
};

return (
<Button
disabled={isLoading || !publicClient}
loading={isLoading}
variant="outline"
onClick={createKernelClient}
>
<Button loading={isLoading} variant="outline" onClick={createKernelClient}>
Generate Private key
</Button>
);
Expand Down
14 changes: 12 additions & 2 deletions src/components/Button/SelectChainButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button, Flex, Menu } from "@mantine/core";
import { notifications } from "@mantine/notifications";
import { useChainId, useChains, useSwitchChain } from "@zerodev/waas";
import { useState } from "react";
import { useEffect, useState } from "react";

export const CustomChevronDown = () => (
<svg fill="none" height="7" width="14" xmlns="http://www.w3.org/2000/svg">
Expand All @@ -19,7 +20,16 @@ export function SelectChainButton() {
const chainId = useChainId();
const chains = useChains();
const [chainSwitching, setChainSwitching] = useState();
const { switchChain, isPending } = useSwitchChain();
const { switchChain, isPending, error } = useSwitchChain();

useEffect(() => {
if (error) {
notifications.show({
color: "red",
message: error?.message || "Switch chain failed",
});
}
}, [error]);

return (
<Menu>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Provider/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default function Providers({ children }: { children: ReactNode }) {
[arbitrum.id]: process.env.NEXT_PUBLIC_ZERODEV_APP_ARBITRUM_ID || "",
[sepolia.id]: process.env.NEXT_PUBLIC_ZERODEV_APP_SEPOLIA_ID || "",
},
transports: {
[arbitrum.id]: http(getBundler(arbitrum.id)),
[sepolia.id]: http(getBundler(sepolia.id)),
},
});

return (
Expand Down

0 comments on commit 61936db

Please sign in to comment.