Skip to content

Commit eed086c

Browse files
committed
chore: revert changes
1 parent 8a68bd2 commit eed086c

File tree

5 files changed

+57
-150
lines changed

5 files changed

+57
-150
lines changed

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

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"use client";
2-
import { MultiNetworkSelector } from "@/components/blocks/NetworkSelectors";
32
import { SettingsCard } from "@/components/blocks/SettingsCard";
43
import { Button } from "@/components/ui/button";
54
import { Checkbox } from "@/components/ui/checkbox";
@@ -24,17 +23,22 @@ import { Skeleton } from "@/components/ui/skeleton";
2423
import { Switch } from "@/components/ui/switch";
2524
import { cn } from "@/lib/utils";
2625
import { zodResolver } from "@hookform/resolvers/zod";
26+
import { NetworkSelectorButton } from "components/selects/NetworkSelectorButton";
2727
import { PlusIcon } from "lucide-react";
2828
import { useFieldArray, useForm } from "react-hook-form";
2929
import { toast } from "sonner";
3030
import { isAddress } from "thirdweb";
31+
import { getCachedChain } from "thirdweb/dist/types/chains/utils";
32+
import {
33+
useActiveWalletChain,
34+
useSwitchActiveWalletChain,
35+
} from "thirdweb/react";
3136
import { getSocialIcon } from "thirdweb/wallets/in-app";
3237
import {
3338
DEFAULT_ACCOUNT_FACTORY_V0_6,
3439
DEFAULT_ACCOUNT_FACTORY_V0_7,
3540
} from "thirdweb/wallets/smart";
3641
import invariant from "tiny-invariant";
37-
import { FormErrorMessage } from "tw-components";
3842
import { z } from "zod";
3943
import { type Ecosystem, authOptions } from "../../../../../types";
4044
import { useUpdateEcosystem } from "../../hooks/use-update-ecosystem";
@@ -46,7 +50,6 @@ type AuthOptionsFormData = {
4650
customHeaders: { key: string; value: string }[];
4751
useSmartAccount: boolean;
4852
sponsorGas: boolean;
49-
chainIds: number[];
5053
accountFactoryType: "v0.6" | "v0.7" | "custom";
5154
customAccountFactoryAddress: string;
5255
};
@@ -60,7 +63,6 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
6063
customHeaders: ecosystem.customAuthOptions?.authEndpoint?.headers || [],
6164
useSmartAccount: !!ecosystem.smartAccountOptions,
6265
sponsorGas: ecosystem.smartAccountOptions?.sponsorGas || false,
63-
chainIds: ecosystem.smartAccountOptions?.chainIds ?? [],
6466
accountFactoryType:
6567
ecosystem.smartAccountOptions?.accountFactoryAddress ===
6668
DEFAULT_ACCOUNT_FACTORY_V0_7
@@ -88,7 +90,6 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
8890
.optional(),
8991
useSmartAccount: z.boolean(),
9092
sponsorGas: z.boolean(),
91-
chainIds: z.array(z.number()),
9293
accountFactoryType: z.enum(["v0.6", "v0.7", "custom"]),
9394
customAccountFactoryAddress: z.string().optional(),
9495
})
@@ -97,8 +98,7 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
9798
if (
9899
data.useSmartAccount &&
99100
data.customAccountFactoryAddress &&
100-
(!isAddress(data.customAccountFactoryAddress) ||
101-
!data.customAccountFactoryAddress)
101+
!isAddress(data.customAccountFactoryAddress)
102102
) {
103103
return false;
104104
}
@@ -109,18 +109,6 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
109109
path: ["customAccountFactoryAddress"],
110110
},
111111
)
112-
.refine(
113-
(data) => {
114-
if (data.useSmartAccount && data.chainIds.length === 0) {
115-
return false;
116-
}
117-
return true;
118-
},
119-
{
120-
message: "Please select at least one chain ID",
121-
path: ["chainIds"],
122-
},
123-
)
124112
.refine(
125113
(data) => {
126114
if (data.useCustomAuth && !data.customAuthEndpoint) {
@@ -151,6 +139,17 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
151139
},
152140
});
153141

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+
154153
const onSubmit = (data: AuthOptionsFormData) => {
155154
let customAuthOptions: Ecosystem["customAuthOptions"] | null = null;
156155
if (data.useCustomAuth && data.customAuthEndpoint) {
@@ -180,12 +179,22 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
180179
accountFactoryAddress = DEFAULT_ACCOUNT_FACTORY_V0_7;
181180
break;
182181
case "custom":
182+
if (!data.customAccountFactoryAddress) {
183+
toast.error("Please enter a custom account factory address");
184+
return;
185+
}
183186
accountFactoryAddress = data.customAccountFactoryAddress;
184187
break;
185188
}
186189

190+
if (!currentChain?.id) {
191+
toast.error("Please select a default chain ID");
192+
return;
193+
}
187194
smartAccountOptions = {
188-
chainIds: data.chainIds,
195+
defaultChainId: currentChain?.id,
196+
chainIds: [], // TODO: remove once backend is updated
197+
189198
sponsorGas: data.sponsorGas,
190199
accountFactoryAddress,
191200
};
@@ -443,42 +452,25 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
443452
)}
444453
/>
445454

446-
<FormField
447-
control={form.control}
448-
name="chainIds"
449-
render={({ field }) => (
450-
<FormItem>
451-
<FormLabel>Allowed Chain Ids</FormLabel>
452-
<div className="flex flex-col">
453-
<MultiNetworkSelector
454-
selectedChainIds={field.value}
455-
onChange={field.onChange}
456-
/>
457-
</div>
458-
<FormDescription>
459-
Select which blockchain networks will be supported by the
460-
smart account. The first value will be the chain that
461-
users are connected to by default when logging into the
462-
<a
463-
href={`https://${ecosystem.slug}.ecosystem.thirdweb.com`}
464-
className="text-link-foreground"
465-
target="_blank"
466-
rel="noreferrer"
467-
>
468-
ecosystem homepage
469-
</a>
470-
.
471-
</FormDescription>
472-
<FormErrorMessage>
473-
{
474-
form.getFieldState("chainIds", form.formState).error
475-
?.message
476-
}
477-
</FormErrorMessage>
478-
</FormItem>
479-
)}
480-
/>
481-
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>
482474
<FormField
483475
control={form.control}
484476
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 ecosystem: remove 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.test.ts

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe("createInAppWallet", () => {
100100
it("should handle ecosystem wallet connection with smart account settings", async () => {
101101
vi.mocked(getEcosystemInfo).mockResolvedValue({
102102
smartAccountOptions: {
103-
chainIds: [mockChain.id],
103+
defaultChainId: mockChain.id,
104104
sponsorGas: true,
105105
accountFactoryAddress: "0x456",
106106
},
@@ -143,7 +143,7 @@ describe("createInAppWallet", () => {
143143
it("should handle ecosystem wallet connection with smart account settings even when no chain is set", async () => {
144144
vi.mocked(getEcosystemInfo).mockResolvedValue({
145145
smartAccountOptions: {
146-
chainIds: [mockChain.id],
146+
defaultChainId: mockChain.id,
147147
sponsorGas: true,
148148
accountFactoryAddress: "0x456",
149149
},
@@ -185,7 +185,7 @@ describe("createInAppWallet", () => {
185185
it("should handle ecosystem wallet auto connection with smart account settings", async () => {
186186
vi.mocked(getEcosystemInfo).mockResolvedValue({
187187
smartAccountOptions: {
188-
chainIds: [mockChain.id],
188+
defaultChainId: mockChain.id,
189189
sponsorGas: true,
190190
accountFactoryAddress: "0x456",
191191
},
@@ -229,7 +229,7 @@ describe("createInAppWallet", () => {
229229
it("should handle ecosystem wallet auto connection with smart account settings even when no chain is set", async () => {
230230
vi.mocked(getEcosystemInfo).mockResolvedValue({
231231
smartAccountOptions: {
232-
chainIds: [mockChain.id],
232+
defaultChainId: mockChain.id,
233233
sponsorGas: true,
234234
accountFactoryAddress: "0x456",
235235
},
@@ -267,68 +267,4 @@ describe("createInAppWallet", () => {
267267
expect.any(Object),
268268
);
269269
});
270-
271-
it("should throw error for unsupported chain in ecosystem", async () => {
272-
const { getEcosystemInfo } = await import(
273-
"../../../ecosystem/get-ecosystem-wallet-auth-options.js"
274-
);
275-
276-
vi.mocked(getEcosystemInfo).mockResolvedValue({
277-
smartAccountOptions: {
278-
chainIds: [1],
279-
sponsorGas: true,
280-
accountFactoryAddress: "0x456",
281-
},
282-
authOptions: [],
283-
name: "hello world",
284-
slug: "test-ecosystem",
285-
});
286-
287-
const wallet = createInAppWallet({
288-
connectorFactory: mockConnectorFactory,
289-
ecosystem: { id: "ecosystem.test-ecosystem" },
290-
});
291-
292-
await expect(
293-
wallet.connect({
294-
client: mockClient,
295-
chain: mockChain,
296-
strategy: "email",
297-
email: "",
298-
verificationCode: "",
299-
}),
300-
).rejects.toThrow(
301-
`Chain ID ${mockChain.id} is not supported for ecosystem smart accounts.`,
302-
);
303-
});
304-
it("should throw error for unsupported chain in ecosystem when auto-connecting", async () => {
305-
const { getEcosystemInfo } = await import(
306-
"../../../ecosystem/get-ecosystem-wallet-auth-options.js"
307-
);
308-
309-
vi.mocked(getEcosystemInfo).mockResolvedValue({
310-
smartAccountOptions: {
311-
chainIds: [1],
312-
sponsorGas: true,
313-
accountFactoryAddress: "0x456",
314-
},
315-
authOptions: [],
316-
name: "hello world",
317-
slug: "test-ecosystem",
318-
});
319-
320-
const wallet = createInAppWallet({
321-
connectorFactory: mockConnectorFactory,
322-
ecosystem: { id: "ecosystem.test-ecosystem" },
323-
});
324-
325-
await expect(
326-
wallet.autoConnect({
327-
client: mockClient,
328-
chain: mockChain,
329-
}),
330-
).rejects.toThrow(
331-
`Chain ID ${mockChain.id} is not supported for ecosystem smart accounts.`,
332-
);
333-
});
334270
});

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ export function createInAppWallet(args: {
7777
const ecosystemOptions = await getEcosystemInfo(ecosystem.id);
7878
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
7979
if (smartAccountOptions) {
80-
const defaultChainId =
81-
ecosystemOptions.smartAccountOptions.chainIds?.[0];
80+
const { defaultChainId } = ecosystemOptions.smartAccountOptions;
8281
if (!defaultChainId) {
8382
throw new Error(
8483
"No default chain ID found for ecosystem smart accounts. Please reach out to the ecosystem owner.",
@@ -87,16 +86,6 @@ export function createInAppWallet(args: {
8786
const preferredChain =
8887
options.chain ?? getCachedChain(defaultChainId);
8988

90-
if (
91-
!ecosystemOptions.smartAccountOptions.chainIds?.includes(
92-
preferredChain?.id,
93-
)
94-
) {
95-
throw new Error(
96-
`Chain ID ${preferredChain.id} is not supported for ecosystem smart accounts.`,
97-
);
98-
}
99-
10089
createOptions = {
10190
...createOptions,
10291
smartAccount: {
@@ -140,8 +129,7 @@ export function createInAppWallet(args: {
140129
const ecosystemOptions = await getEcosystemInfo(ecosystem.id);
141130
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
142131
if (smartAccountOptions) {
143-
const defaultChainId =
144-
ecosystemOptions.smartAccountOptions.chainIds?.[0];
132+
const { defaultChainId } = ecosystemOptions.smartAccountOptions;
145133
if (!defaultChainId) {
146134
throw new Error(
147135
"No default chain ID found for ecosystem smart accounts. Please reach out to the ecosystem owner.",
@@ -150,16 +138,6 @@ export function createInAppWallet(args: {
150138
const preferredChain =
151139
options.chain ?? getCachedChain(defaultChainId);
152140

153-
if (
154-
!ecosystemOptions.smartAccountOptions.chainIds?.includes(
155-
preferredChain?.id,
156-
)
157-
) {
158-
throw new Error(
159-
`Chain ID ${preferredChain.id} is not supported for ecosystem smart accounts.`,
160-
);
161-
}
162-
163141
createOptions = {
164142
...createOptions,
165143
smartAccount: {

0 commit comments

Comments
 (0)