@@ -23,10 +23,15 @@ import { Skeleton } from "@/components/ui/skeleton";
2323import { Switch } from "@/components/ui/switch" ;
2424import { cn } from "@/lib/utils" ;
2525import { zodResolver } from "@hookform/resolvers/zod" ;
26+ import { NetworkSelectorButton } from "components/selects/NetworkSelectorButton" ;
2627import { PlusIcon } from "lucide-react" ;
2728import { useFieldArray , useForm } from "react-hook-form" ;
2829import { toast } from "sonner" ;
29- import { isAddress } from "thirdweb" ;
30+ import { defineChain , isAddress } from "thirdweb" ;
31+ import {
32+ useActiveWalletChain ,
33+ useSwitchActiveWalletChain ,
34+ } from "thirdweb/react" ;
3035import { getSocialIcon } from "thirdweb/wallets/in-app" ;
3136import {
3237 DEFAULT_ACCOUNT_FACTORY_V0_6 ,
@@ -43,7 +48,6 @@ type AuthOptionsFormData = {
4348 customAuthEndpoint : string ;
4449 customHeaders : { key : string ; value : string } [ ] ;
4550 useSmartAccount : boolean ;
46- chainIds : number [ ] ;
4751 sponsorGas : boolean ;
4852 accountFactoryType : "v0.6" | "v0.7" | "custom" ;
4953 customAccountFactoryAddress : string ;
@@ -57,7 +61,6 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
5761 customAuthEndpoint : ecosystem . customAuthOptions ?. authEndpoint ?. url || "" ,
5862 customHeaders : ecosystem . customAuthOptions ?. authEndpoint ?. headers || [ ] ,
5963 useSmartAccount : ! ! ecosystem . smartAccountOptions ,
60- chainIds : [ ] , // unused - TODO: remove from service
6164 sponsorGas : ecosystem . smartAccountOptions ?. sponsorGas || false ,
6265 accountFactoryType :
6366 ecosystem . smartAccountOptions ?. accountFactoryAddress ===
@@ -85,7 +88,6 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
8588 )
8689 . optional ( ) ,
8790 useSmartAccount : z . boolean ( ) ,
88- chainIds : z . array ( z . number ( ) ) ,
8991 sponsorGas : z . boolean ( ) ,
9092 accountFactoryType : z . enum ( [ "v0.6" , "v0.7" , "custom" ] ) ,
9193 customAccountFactoryAddress : z . string ( ) . optional ( ) ,
@@ -136,6 +138,16 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
136138 } ,
137139 } ) ;
138140
141+ const switchChain = useSwitchActiveWalletChain ( ) ;
142+ const currentChain = useActiveWalletChain ( ) ;
143+ if (
144+ ecosystem . smartAccountOptions ?. defaultChainId &&
145+ currentChain &&
146+ currentChain . id !== ecosystem . smartAccountOptions ?. defaultChainId
147+ ) {
148+ switchChain ( defineChain ( ecosystem . smartAccountOptions ?. defaultChainId ) ) ;
149+ }
150+
139151 const onSubmit = ( data : AuthOptionsFormData ) => {
140152 let customAuthOptions : Ecosystem [ "customAuthOptions" ] | null = null ;
141153 if ( data . useCustomAuth && data . customAuthEndpoint ) {
@@ -165,12 +177,22 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
165177 accountFactoryAddress = DEFAULT_ACCOUNT_FACTORY_V0_7 ;
166178 break ;
167179 case "custom" :
180+ if ( ! data . customAccountFactoryAddress ) {
181+ toast . error ( "Please enter a custom account factory address" ) ;
182+ return ;
183+ }
168184 accountFactoryAddress = data . customAccountFactoryAddress ;
169185 break ;
170186 }
171187
188+ if ( ! currentChain ?. id ) {
189+ toast . error ( "Please select a default chain ID" ) ;
190+ return ;
191+ }
172192 smartAccountOptions = {
173- chainIds : [ ] , // unused - TODO remove from service
193+ defaultChainId : currentChain ?. id ,
194+ chainIds : [ ] , // TODO: remove once backend is updated
195+
174196 sponsorGas : data . sponsorGas ,
175197 accountFactoryAddress,
176198 } ;
@@ -427,6 +449,17 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
427449 </ FormItem >
428450 ) }
429451 />
452+
453+ < FormItem >
454+ < FormLabel > Default Chain ID</ FormLabel >
455+ < FormControl >
456+ < NetworkSelectorButton />
457+ </ FormControl >
458+ < FormDescription >
459+ This will be the chain ID where the smart account will be
460+ initialized on by default.
461+ </ FormDescription >
462+ </ FormItem >
430463 < FormField
431464 control = { form . control }
432465 name = "accountFactoryType"
0 commit comments