Skip to content

Commit

Permalink
feat(connect): add network switching
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Nov 6, 2024
1 parent 2f997df commit 758fc6f
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions apps/docs/src/components/test-zkapp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const TestZkApp = () => {
mina_sign: "",
mina_signFields: "",
mina_signTransaction: "",
mina_switchChain: "",
});
const providers = useSyncExternalStore(store.subscribe, store.getProviders);
const provider = providers.find(
Expand Down Expand Up @@ -140,6 +141,14 @@ export const TestZkApp = () => {
mina_signTransaction: JSON.stringify(result, undefined, "\t"),
}));
};
const switchChain = async (networkId: string) => {
if (!provider) return;
const { result } = await provider.request({
method: "mina_switchChain",
params: [networkId],
});
setResults(() => ({ mina_switchChain: result }));
};
return (
<main className="flex flex-col gap-8">
<h1 className="text-3xl font-bold">Test zkApp</h1>
Expand Down Expand Up @@ -201,32 +210,56 @@ export const TestZkApp = () => {
Request Accounts
</button>
</div>
<label>mina_networkId</label>
<label>mina_getBalance</label>
<div className="flex justify-between items-center gap-4">
<input
value={results.mina_networkId}
value={results.mina_getBalance}
className="input input-bordered flex-1"
/>
<button
type="button"
className="btn btn-primary"
onClick={fetchNetworkId}
onClick={fetchBalance}
>
Get Network ID
Get Balance
</button>
</div>
<label>mina_getBalance</label>
</div>
</div>
</section>
<section className="card bg-neutral">
<div className="card-body gap-4">
<h2 className="card-title">Network</h2>
<div className="flex flex-col gap-2">
<label>mina_networkId</label>
<div className="flex justify-between items-center gap-4">
<input
value={results.mina_getBalance}
value={results.mina_networkId}
className="input input-bordered flex-1"
/>
<button
type="button"
className="btn btn-primary"
onClick={fetchBalance}
onClick={fetchNetworkId}
>
Get Balance
Get Network ID
</button>
</div>
<label>mina_switchChain</label>
<div className="flex items-center gap-4">
<button
type="button"
className="btn btn-primary"
onClick={() => switchChain("mina:devnet")}
>
Switch to Devnet
</button>
<button
type="button"
className="btn btn-primary"
onClick={() => switchChain("mina:mainnet")}
>
Switch to Mainnet
</button>
</div>
</div>
Expand Down

0 comments on commit 758fc6f

Please sign in to comment.