Skip to content

Commit 293305b

Browse files
committed
Move /connect/in-app-wallets to app router
1 parent 63c4517 commit 293305b

File tree

4 files changed

+61
-60
lines changed

4 files changed

+61
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
1-
import { Spinner } from "@/components/ui/Spinner/Spinner";
1+
"use client";
2+
23
import { TrackedLinkTW } from "@/components/ui/tracked-link";
3-
import { type ApiKey, useApiKeys } from "@3rdweb-sdk/react/hooks/useApi";
4-
import { useLoggedInUser } from "@3rdweb-sdk/react/hooks/useLoggedInUser";
5-
import { AppLayout } from "components/app-layouts/app";
4+
import type { ApiKey } from "@3rdweb-sdk/react/hooks/useApi";
65
import { EmbeddedWallets } from "components/embedded-wallets";
76
import { ApiKeysMenu } from "components/settings/ApiKeys/Menu";
87
import { NoApiKeys } from "components/settings/ApiKeys/NoApiKeys";
9-
// import { ConnectSidebar } from "core-ui/sidebar/connect";
10-
import { useRouter } from "next/router";
11-
import { PageId } from "page-id";
128
import { useMemo, useState } from "react";
13-
import type { ThirdwebNextPage } from "utils/types";
14-
import { ConnectSidebarLayout } from "../../../app/(dashboard)/dashboard/connect/DashboardConnectLayout";
15-
import { AnalyticsCallout } from "../../../app/team/[team_slug]/[project_slug]/connect/in-app-wallets/_components/AnalyticsCallout";
16-
import { InAppWaletFooterSection } from "../../../app/team/[team_slug]/[project_slug]/connect/in-app-wallets/_components/footer";
9+
import { AnalyticsCallout } from "../../../../team/[team_slug]/[project_slug]/connect/in-app-wallets/_components/AnalyticsCallout";
10+
import { InAppWaletFooterSection } from "../../../../team/[team_slug]/[project_slug]/connect/in-app-wallets/_components/footer";
1711

1812
const TRACKING_CATEGORY = "embedded-wallet";
1913

20-
const DashboardConnectEmbeddedWallets: ThirdwebNextPage = () => {
21-
const router = useRouter();
22-
const defaultClientId = router.query.clientId?.toString();
23-
const { isPending } = useLoggedInUser();
24-
const keysQuery = useApiKeys();
25-
14+
export function InAppWalletsPage(props: {
15+
defaultClientId: string | undefined;
16+
apiKeys: ApiKey[];
17+
}) {
18+
const { defaultClientId, apiKeys: allApiKeys } = props;
2619
const [selectedKey_, setSelectedKey] = useState<undefined | ApiKey>();
2720

2821
const apiKeys = useMemo(() => {
29-
return (keysQuery?.data || []).filter((key) => {
22+
return allApiKeys.filter((key) => {
3023
return !!(key.services || []).find(
3124
(srv) => srv.name === "embeddedWallets",
3225
);
3326
});
34-
}, [keysQuery]);
27+
}, [allApiKeys]);
3528

3629
const hasApiKeys = apiKeys.length > 0;
3730

@@ -49,14 +42,6 @@ const DashboardConnectEmbeddedWallets: ThirdwebNextPage = () => {
4942
return undefined;
5043
}, [apiKeys, defaultClientId, selectedKey_]);
5144

52-
if (isPending) {
53-
return (
54-
<div className="grid w-full place-items-center">
55-
<Spinner className="size-14" />
56-
</div>
57-
);
58-
}
59-
6045
return (
6146
<div>
6247
<div className="flex flex-col gap-4 lg:flex-row lg:justify-between">
@@ -88,50 +73,35 @@ const DashboardConnectEmbeddedWallets: ThirdwebNextPage = () => {
8873
<ApiKeysMenu
8974
apiKeys={apiKeys}
9075
selectedKey={selectedKey}
91-
onSelect={setSelectedKey}
76+
onSelect={(key) => {
77+
setSelectedKey(key);
78+
// add clientId search param to the url without affecting router
79+
window.history.replaceState(
80+
{},
81+
"",
82+
`/dashboard/connect/in-app-wallets?clientId=${key.key}`,
83+
);
84+
}}
9285
/>
9386
)}
9487
</div>
9588
</div>
9689

9790
<div className="h-8" />
9891

99-
{keysQuery.isPending ? (
100-
<div className="flex h-[500px] items-center justify-center">
101-
<Spinner className="size-10" />
102-
</div>
103-
) : (
104-
<>
105-
{!hasApiKeys && <NoApiKeys service="in-app wallets" />}
92+
{!hasApiKeys && <NoApiKeys service="in-app wallets" />}
10693

107-
{hasApiKeys && selectedKey && (
108-
<EmbeddedWallets
109-
apiKey={selectedKey}
110-
trackingCategory={TRACKING_CATEGORY}
111-
/>
112-
)}
113-
</>
94+
{hasApiKeys && selectedKey && (
95+
<EmbeddedWallets
96+
apiKey={selectedKey}
97+
trackingCategory={TRACKING_CATEGORY}
98+
/>
11499
)}
115100

116101
<div className="h-16" />
117102
<AnalyticsCallout trackingCategory={TRACKING_CATEGORY} />
118103
<div className="h-5" />
119-
120104
<InAppWaletFooterSection trackingCategory={TRACKING_CATEGORY} />
121105
</div>
122106
);
123-
};
124-
125-
DashboardConnectEmbeddedWallets.getLayout = (page, props) => (
126-
<AppLayout
127-
{...props}
128-
pageContainerClassName="!max-w-full !px-0"
129-
mainClassName="!pt-0"
130-
>
131-
<ConnectSidebarLayout>{page}</ConnectSidebarLayout>
132-
</AppLayout>
133-
);
134-
135-
DashboardConnectEmbeddedWallets.pageId = PageId.DashboardConnectEmbeddedWallets;
136-
137-
export default DashboardConnectEmbeddedWallets;
107+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Suspense } from "react";
2+
3+
export default function Layout(props: { children: React.ReactNode }) {
4+
return <Suspense fallback={null}>{props.children}</Suspense>;
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { redirect } from "next/navigation";
2+
import { getApiKeys } from "../../../../api/lib/getAPIKeys";
3+
import { getAuthToken } from "../../../../api/lib/getAuthToken";
4+
import { InAppWalletsPage } from "./InAppWalletsPage";
5+
6+
export default async function Page(props: {
7+
searchParams: {
8+
clientId?: string;
9+
};
10+
}) {
11+
const authToken = getAuthToken();
12+
const { clientId } = props.searchParams;
13+
14+
if (!authToken) {
15+
const params = new URLSearchParams();
16+
params.append("next", "/dashboard/connect/in-app-wallets");
17+
if (clientId) {
18+
params.append("clientId", clientId);
19+
}
20+
redirect(`/login?${params.toString()}`);
21+
}
22+
23+
const apiKeys = await getApiKeys();
24+
25+
return <InAppWalletsPage defaultClientId={clientId} apiKeys={apiKeys} />;
26+
}
27+
28+
export const dynamic = "force-dynamic";

apps/dashboard/src/page-id.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ export enum PageId {
9898

9999
// thirdweb.com/dashboard/connect/smart-wallet
100100
DashboardConnectAccountAbstraction = "dashboard-wallets-smart-wallet",
101-
// thirdweb.com/dashboard/connect/embedded
102-
DashboardConnectEmbeddedWallets = "dashboard-wallets-embedded",
103101
// thirdweb.com/dashboard/contracts/build
104102
DashboardContractsBuild = "dashboard-contracts-build",
105103

0 commit comments

Comments
 (0)