Skip to content

Commit 1777bd8

Browse files
committed
fix: enable default smart wallet chain for ecosystem page
1 parent c3d7b66 commit 1777bd8

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/[slug]/(active)/configuration/components/client/auth-options-form.client.tsx

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ import { Skeleton } from "@/components/ui/skeleton";
2323
import { Switch } from "@/components/ui/switch";
2424
import { cn } from "@/lib/utils";
2525
import { zodResolver } from "@hookform/resolvers/zod";
26+
import { NetworkSelectorButton } from "components/selects/NetworkSelectorButton";
2627
import { PlusIcon } from "lucide-react";
2728
import { useFieldArray, useForm } from "react-hook-form";
2829
import { toast } from "sonner";
29-
import { isAddress } from "thirdweb";
30+
import { defineChain, isAddress } from "thirdweb";
31+
import {
32+
useActiveWalletChain,
33+
useSwitchActiveWalletChain,
34+
} from "thirdweb/react";
3035
import { getSocialIcon } from "thirdweb/wallets/in-app";
3136
import {
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"

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export type Ecosystem = {
3636
};
3737
} | null;
3838
smartAccountOptions?: {
39-
chainIds: number[];
39+
defaultChainId: number;
40+
chainIds: number[]; // TODO: Remove this once we update the backend to stop requiring this
4041
sponsorGas: boolean;
4142
accountFactoryAddress: string;
4243
} | null;

packages/thirdweb/src/wallets/ecosystem/get-ecosystem-wallet-auth-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type EcosystemOptions = {
1313
};
1414

1515
type SmartAccountOptions = {
16-
chainIds: number[];
16+
defaultChainId: number;
1717
sponsorGas: boolean;
1818
accountFactoryAddress: string;
1919
};

packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { trackConnect } from "../../../../analytics/track/connect.js";
22
import type { Chain } from "../../../../chains/types.js";
3-
import { getCachedChainIfExists } from "../../../../chains/utils.js";
3+
import {
4+
defineChain,
5+
getCachedChainIfExists,
6+
} from "../../../../chains/utils.js";
47
import type { ThirdwebClient } from "../../../../client/client.js";
58
import { stringify } from "../../../../utils/json.js";
69
import { getEcosystemInfo } from "../../../ecosystem/get-ecosystem-wallet-auth-options.js";
@@ -74,7 +77,9 @@ export function createInAppWallet(args: {
7477
const ecosystemOptions = await getEcosystemInfo(ecosystem.id);
7578
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
7679
if (smartAccountOptions) {
77-
const preferredChain = options.chain;
80+
const preferredChain =
81+
options.chain ??
82+
defineChain(ecosystemOptions.smartAccountOptions.defaultChainId);
7883
if (!preferredChain) {
7984
throw new Error(
8085
"Chain is required for ecosystem smart accounts, pass it via connect() or via UI components",

0 commit comments

Comments
 (0)