Skip to content

Commit 758fc6f

Browse files
committed
feat(connect): add network switching
1 parent 2f997df commit 758fc6f

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

apps/docs/src/components/test-zkapp.tsx

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const TestZkApp = () => {
2626
mina_sign: "",
2727
mina_signFields: "",
2828
mina_signTransaction: "",
29+
mina_switchChain: "",
2930
});
3031
const providers = useSyncExternalStore(store.subscribe, store.getProviders);
3132
const provider = providers.find(
@@ -140,6 +141,14 @@ export const TestZkApp = () => {
140141
mina_signTransaction: JSON.stringify(result, undefined, "\t"),
141142
}));
142143
};
144+
const switchChain = async (networkId: string) => {
145+
if (!provider) return;
146+
const { result } = await provider.request({
147+
method: "mina_switchChain",
148+
params: [networkId],
149+
});
150+
setResults(() => ({ mina_switchChain: result }));
151+
};
143152
return (
144153
<main className="flex flex-col gap-8">
145154
<h1 className="text-3xl font-bold">Test zkApp</h1>
@@ -201,32 +210,56 @@ export const TestZkApp = () => {
201210
Request Accounts
202211
</button>
203212
</div>
204-
<label>mina_networkId</label>
213+
<label>mina_getBalance</label>
205214
<div className="flex justify-between items-center gap-4">
206215
<input
207-
value={results.mina_networkId}
216+
value={results.mina_getBalance}
208217
className="input input-bordered flex-1"
209218
/>
210219
<button
211220
type="button"
212221
className="btn btn-primary"
213-
onClick={fetchNetworkId}
222+
onClick={fetchBalance}
214223
>
215-
Get Network ID
224+
Get Balance
216225
</button>
217226
</div>
218-
<label>mina_getBalance</label>
227+
</div>
228+
</div>
229+
</section>
230+
<section className="card bg-neutral">
231+
<div className="card-body gap-4">
232+
<h2 className="card-title">Network</h2>
233+
<div className="flex flex-col gap-2">
234+
<label>mina_networkId</label>
219235
<div className="flex justify-between items-center gap-4">
220236
<input
221-
value={results.mina_getBalance}
237+
value={results.mina_networkId}
222238
className="input input-bordered flex-1"
223239
/>
224240
<button
225241
type="button"
226242
className="btn btn-primary"
227-
onClick={fetchBalance}
243+
onClick={fetchNetworkId}
228244
>
229-
Get Balance
245+
Get Network ID
246+
</button>
247+
</div>
248+
<label>mina_switchChain</label>
249+
<div className="flex items-center gap-4">
250+
<button
251+
type="button"
252+
className="btn btn-primary"
253+
onClick={() => switchChain("mina:devnet")}
254+
>
255+
Switch to Devnet
256+
</button>
257+
<button
258+
type="button"
259+
className="btn btn-primary"
260+
onClick={() => switchChain("mina:mainnet")}
261+
>
262+
Switch to Mainnet
230263
</button>
231264
</div>
232265
</div>

0 commit comments

Comments
 (0)