Skip to content

Commit 1416a47

Browse files
committed
feat: walletconnect uri connection
1 parent 79f029c commit 1416a47

File tree

20 files changed

+312
-261
lines changed

20 files changed

+312
-261
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import ConnectButton from "@/components/ConnectButton";
2+
import { authedOnly } from "@/lib/auth";
3+
import { getEcosystemInfo } from "@/lib/ecosystems";
4+
5+
export default async function Layout({
6+
children,
7+
params,
8+
}: {
9+
children: React.ReactNode;
10+
params: { ecosystem: string };
11+
}) {
12+
await authedOnly();
13+
const ecosystem = await getEcosystemInfo(params.ecosystem);
14+
return (
15+
<div className="flex w-full flex-col items-stretch">
16+
<header className="hidden w-full border-accent border-b bg-card py-4 sm:block">
17+
<div className="container mx-auto flex justify-between">
18+
<div className="flex items-center gap-2">
19+
<img
20+
className="h-8 w-8"
21+
src={ecosystem.imageUrl}
22+
alt={ecosystem.name}
23+
width={100}
24+
height={100}
25+
/>
26+
<h1 className="font-semibold text-xl">{ecosystem.name}</h1>
27+
</div>
28+
<ConnectButton ecosystem={`ecosystem.${params.ecosystem}`} />
29+
</div>
30+
</header>
31+
32+
<main className="flex h-full w-full">{children}</main>
33+
</div>
34+
);
35+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { ChainCombobox } from "@/components/ChainCombobox";
2+
import { getChains } from "@/lib/chains";
3+
import { client } from "@/lib/client";
4+
import { getEcosystemInfo } from "@/lib/ecosystems";
5+
import { SIMPLEHASH_NFT_SUPPORTED_CHAIN_IDS } from "@/util/simplehash";
6+
import type { Metadata, ResolvingMetadata } from "next";
7+
import { resolveName } from "thirdweb/extensions/ens";
8+
import { shortenAddress } from "thirdweb/utils";
9+
10+
export async function generateMetadata(
11+
{ params }: { params: { ecosystem: string; address: string } },
12+
parent: ResolvingMetadata,
13+
): Promise<Metadata> {
14+
const [ecosystem, parentMetadata] = await Promise.all([
15+
getEcosystemInfo(params.ecosystem),
16+
parent,
17+
]);
18+
const previousImages = parentMetadata.openGraph?.images || [];
19+
20+
return {
21+
title: `${ecosystem.name} | ${shortenAddress(params.address)}`,
22+
openGraph: {
23+
images: [ecosystem.imageUrl, ...previousImages],
24+
},
25+
};
26+
}
27+
28+
export default async function Layout({
29+
children,
30+
params,
31+
}: {
32+
children: React.ReactNode;
33+
params: { ecosystem: string; address: string };
34+
}) {
35+
const ensPromise = resolveName({
36+
client,
37+
address: params.address,
38+
});
39+
const thirdwebChainsPromise = getChains();
40+
41+
const [ens, thirdwebChains] = await Promise.all([
42+
ensPromise,
43+
thirdwebChainsPromise,
44+
]);
45+
46+
const simpleHashChains = thirdwebChains.filter((chain) =>
47+
SIMPLEHASH_NFT_SUPPORTED_CHAIN_IDS.includes(chain.chainId),
48+
);
49+
50+
return (
51+
<div className="flex w-full flex-col">
52+
<div className="mb-4 border-b bg-card pt-36">
53+
<div className="container flex w-full flex-col items-end justify-between gap-4 bg-card py-4 md:flex-row">
54+
<h2 className="font-bold text-4xl">
55+
{ens || shortenAddress(params.address)}
56+
</h2>
57+
<ChainCombobox chains={simpleHashChains} />
58+
</div>
59+
</div>
60+
<div className="container flex-1 py-4">
61+
<div className="h-full">{children}</div>
62+
</div>
63+
</div>
64+
);
65+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { AutoConnectWalletConnect } from "@/components/AutoConnectWalletConnect";
2+
import NftGallery from "@/components/NftGallery";
3+
import { getAddress } from "thirdweb";
4+
5+
export default function Page({
6+
params: { address },
7+
searchParams: { chainId, uri },
8+
}: {
9+
params: { address: string };
10+
searchParams: { chainId?: string; uri?: string };
11+
}) {
12+
return (
13+
<>
14+
<AutoConnectWalletConnect uri={uri} />
15+
<NftGallery owner={getAddress(address)} chainId={Number(chainId)} />
16+
</>
17+
);
18+
}

apps/wallet-ui/src/app/[ecosystem]/(ui)/layout.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

apps/wallet-ui/src/app/[ecosystem]/(ui)/wallet/[address]/layout.tsx

Lines changed: 0 additions & 73 deletions
This file was deleted.

apps/wallet-ui/src/app/[ecosystem]/(ui)/wallet/[address]/page.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

apps/wallet-ui/src/app/[ecosystem]/login/layout.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ import { redirect } from "next/navigation";
22
import { getCurrentUser } from "../../../lib/auth";
33

44
export default async function Layout({
5-
children,
5+
children,
66
}: { children: React.ReactNode }) {
7-
const userAddress = await getCurrentUser();
8-
console.log("userAddress", userAddress);
9-
if (userAddress) {
10-
console.log("redirecting to wallet", userAddress);
11-
redirect(`/wallet/${userAddress}`);
12-
}
7+
const userAddress = await getCurrentUser();
8+
if (userAddress) {
9+
redirect(`/wallet/${userAddress}`);
10+
}
1311

14-
return (
15-
<main className="flex w-full flex-col items-center justify-center">
16-
{children}
17-
</main>
18-
);
12+
return (
13+
<main className="flex w-full flex-col items-center justify-center">
14+
{children}
15+
</main>
16+
);
1917
}
Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,5 @@
1-
"use client";
2-
import { generatePayload, getCurrentUser, login, logout } from "@/lib/auth";
3-
import { client } from "@/lib/client";
4-
import { useTheme } from "next-themes";
5-
import { useRouter } from "next/navigation";
6-
import type { VerifyLoginPayloadParams } from "thirdweb/auth";
7-
import { ConnectEmbed } from "thirdweb/react";
8-
import { ecosystemWallet } from "thirdweb/wallets";
1+
import { ConnectEmbed } from "@/components/ConnectEmbed";
92

10-
export default function Page({ params }: { params: { ecosystem: string } }) {
11-
const { theme } = useTheme();
12-
const router = useRouter();
13-
14-
return (
15-
<ConnectEmbed
16-
theme={theme === "light" ? "light" : "dark"}
17-
autoConnect={true}
18-
wallets={[ecosystemWallet(`ecosystem.${params.ecosystem}`)]}
19-
client={client}
20-
auth={{
21-
getLoginPayload: generatePayload,
22-
doLogin: async (loginParams: VerifyLoginPayloadParams) => {
23-
const success = await login(loginParams);
24-
if (success) {
25-
router.push(`/wallet/${loginParams.payload.address}`);
26-
}
27-
},
28-
isLoggedIn: async () => !!(await getCurrentUser()),
29-
doLogout: logout,
30-
}}
31-
/>
32-
);
3+
export default function Page() {
4+
return <ConnectEmbed />;
335
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This page is to accept a Wallet Connect request
2+
import { getCurrentUser } from "@/lib/auth";
3+
import { redirect } from "next/navigation";
4+
5+
export default async function Page({
6+
searchParams: { uri },
7+
}: {
8+
searchParams: { uri: string };
9+
}) {
10+
const currentUser = await getCurrentUser();
11+
12+
if (!currentUser) {
13+
redirect(`/login?uri=${encodeURIComponent(uri)}`);
14+
}
15+
16+
redirect(`/wallet/${currentUser}?uri=${encodeURIComponent(uri)}`);
17+
}

0 commit comments

Comments
 (0)