@@ -23,16 +23,10 @@ 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" ;
2726import { PlusIcon } from "lucide-react" ;
2827import { useFieldArray , useForm } from "react-hook-form" ;
2928import { toast } from "sonner" ;
3029import { isAddress } from "thirdweb" ;
31- import { getCachedChain } from "thirdweb/dist/types/chains/utils" ;
32- import {
33- useActiveWalletChain ,
34- useSwitchActiveWalletChain ,
35- } from "thirdweb/react" ;
3630import { getSocialIcon } from "thirdweb/wallets/in-app" ;
3731import {
3832 DEFAULT_ACCOUNT_FACTORY_V0_6 ,
@@ -50,6 +44,7 @@ type AuthOptionsFormData = {
5044 customHeaders : { key : string ; value : string } [ ] ;
5145 useSmartAccount : boolean ;
5246 sponsorGas : boolean ;
47+ defaultChainId : number ;
5348 accountFactoryType : "v0.6" | "v0.7" | "custom" ;
5449 customAccountFactoryAddress : string ;
5550} ;
@@ -63,6 +58,7 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
6358 customHeaders : ecosystem . customAuthOptions ?. authEndpoint ?. headers || [ ] ,
6459 useSmartAccount : ! ! ecosystem . smartAccountOptions ,
6560 sponsorGas : ecosystem . smartAccountOptions ?. sponsorGas || false ,
61+ defaultChainId : ecosystem . smartAccountOptions ?. defaultChainId ,
6662 accountFactoryType :
6763 ecosystem . smartAccountOptions ?. accountFactoryAddress ===
6864 DEFAULT_ACCOUNT_FACTORY_V0_7
@@ -90,6 +86,9 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
9086 . optional ( ) ,
9187 useSmartAccount : z . boolean ( ) ,
9288 sponsorGas : z . boolean ( ) ,
89+ defaultChainId : z . coerce . number ( {
90+ invalid_type_error : "Please enter a valid chain ID" ,
91+ } ) ,
9392 accountFactoryType : z . enum ( [ "v0.6" , "v0.7" , "custom" ] ) ,
9493 customAccountFactoryAddress : z . string ( ) . optional ( ) ,
9594 } )
@@ -139,17 +138,6 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
139138 } ,
140139 } ) ;
141140
142- const switchChain = useSwitchActiveWalletChain ( ) ;
143- const currentChain = useActiveWalletChain ( ) ;
144- if (
145- ecosystem . smartAccountOptions ?. defaultChainId &&
146- currentChain &&
147- currentChain . id !== ecosystem . smartAccountOptions ?. defaultChainId
148- ) {
149- const chainId = ecosystem . smartAccountOptions ?. defaultChainId ;
150- switchChain ( getCachedChain ( chainId ) ) ;
151- }
152-
153141 const onSubmit = ( data : AuthOptionsFormData ) => {
154142 let customAuthOptions : Ecosystem [ "customAuthOptions" ] | null = null ;
155143 if ( data . useCustomAuth && data . customAuthEndpoint ) {
@@ -187,14 +175,8 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
187175 break ;
188176 }
189177
190- if ( ! currentChain ?. id ) {
191- toast . error ( "Please select a default chain ID" ) ;
192- return ;
193- }
194178 smartAccountOptions = {
195- defaultChainId : currentChain ?. id ,
196- chainIds : [ ] , // TODO: remove once backend is updated
197-
179+ defaultChainId : data . defaultChainId ,
198180 sponsorGas : data . sponsorGas ,
199181 accountFactoryAddress,
200182 } ;
@@ -451,26 +433,33 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
451433 </ FormItem >
452434 ) }
453435 />
436+ < FormField
437+ control = { form . control }
438+ name = "defaultChainId"
439+ render = { ( { field } ) => (
440+ < FormItem >
441+ < FormLabel > Default Chain ID</ FormLabel >
442+ < FormControl >
443+ < Input { ...field } placeholder = "1" />
444+ </ FormControl >
445+ < FormDescription >
446+ This will be the chain ID the smart account will be
447+ initialized to on your{ " " }
448+ < a
449+ href = { `https://${ ecosystem . slug } .ecosystem.thirdweb.com` }
450+ className = "text-link-foreground"
451+ target = "_blank"
452+ rel = "noreferrer"
453+ >
454+ ecosystem page
455+ </ a >
456+ .
457+ </ FormDescription >
458+ < FormMessage />
459+ </ FormItem >
460+ ) }
461+ />
454462
455- < FormItem >
456- < FormLabel > Default Chain ID</ FormLabel >
457- < FormControl >
458- < NetworkSelectorButton />
459- </ FormControl >
460- < FormDescription >
461- This will be the chain ID the smart account will be
462- initialized to on your{ " " }
463- < a
464- href = { `https://${ ecosystem . slug } .ecosystem.thirdweb.com` }
465- className = "text-link-foreground"
466- target = "_blank"
467- rel = "noreferrer"
468- >
469- ecosystem page
470- </ a >
471- .
472- </ FormDescription >
473- </ FormItem >
474463 < FormField
475464 control = { form . control }
476465 name = "accountFactoryType"
0 commit comments