Skip to content

Commit db5457f

Browse files
[SDK / Wallet UI] URI Connection (#4997)
Co-authored-by: Joaquim Verges <joaquim.verges@gmail.com>
1 parent df0388d commit db5457f

File tree

14 files changed

+131
-87
lines changed

14 files changed

+131
-87
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { ChainCombobox } from "@/components/ChainCombobox";
2-
import { getCurrentUser } from "@/lib/auth";
32
import { getChains } from "@/lib/chains";
43
import { client } from "@/lib/client";
54
import { getEcosystemInfo } from "@/lib/ecosystems";
65
import { SIMPLEHASH_NFT_SUPPORTED_CHAIN_IDS } from "@/util/simplehash";
76
import type { Metadata, ResolvingMetadata } from "next";
8-
import { redirect } from "next/navigation";
97
import { resolveName } from "thirdweb/extensions/ens";
108
import { shortenAddress } from "thirdweb/utils";
119

@@ -34,23 +32,17 @@ export default async function Layout({
3432
children: React.ReactNode;
3533
params: { ecosystem: string; address: string };
3634
}) {
37-
const userAddressPromise = getCurrentUser();
3835
const ensPromise = resolveName({
3936
client,
4037
address: params.address,
4138
});
4239
const thirdwebChainsPromise = getChains();
4340

44-
const [userAddress, ens, thirdwebChains] = await Promise.all([
45-
userAddressPromise,
41+
const [ens, thirdwebChains] = await Promise.all([
4642
ensPromise,
4743
thirdwebChainsPromise,
4844
]);
4945

50-
if (userAddress !== params.address) {
51-
redirect(`/wallet/${userAddress}`);
52-
}
53-
5446
const simpleHashChains = thirdwebChains.filter((chain) =>
5547
SIMPLEHASH_NFT_SUPPORTED_CHAIN_IDS.includes(chain.chainId),
5648
);
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)/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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export default async function Layout({
55
children,
66
}: { children: React.ReactNode }) {
77
const userAddress = await getCurrentUser();
8-
console.log("userAddress", userAddress);
98
if (userAddress) {
10-
console.log("redirecting to wallet", userAddress);
119
redirect(`/wallet/${userAddress}`);
1210
}
1311

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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use client";
2+
3+
import { useWalletConnect } from "@/hooks/useWalletConnect";
4+
5+
export function AutoConnectWalletConnect({ uri }: { uri?: string }) {
6+
useWalletConnect({ uri });
7+
return <></>;
8+
}

apps/wallet-ui/src/components/ConnectButton.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"use client";
2-
import { generatePayload, isLoggedIn, login, logout } from "@/lib/auth";
32
import { client } from "@/lib/client";
43
import { useTheme } from "next-themes";
54
import {
@@ -24,14 +23,6 @@ export default function ConnectButton({
2423
wallets={[ecosystemWallet(ecosystem)]}
2524
client={client}
2625
theme={theme === "light" ? "light" : "dark"}
27-
auth={{
28-
getLoginPayload: generatePayload,
29-
doLogin: async (p) => {
30-
login(p);
31-
},
32-
isLoggedIn,
33-
doLogout: logout,
34-
}}
3526
/>
3627
);
3728
}

0 commit comments

Comments
 (0)