-
Notifications
You must be signed in to change notification settings - Fork 619
[SDK / Wallet UI] URI Connection #4997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
apps/wallet-ui/src/app/[ecosystem]/(authed)/wallet/[address]/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { AutoConnectWalletConnect } from "@/components/AutoConnectWalletConnect"; | ||
| import NftGallery from "@/components/NftGallery"; | ||
| import { getAddress } from "thirdweb"; | ||
|
|
||
| export default function Page({ | ||
| params: { address }, | ||
| searchParams: { chainId, uri }, | ||
| }: { | ||
| params: { address: string }; | ||
| searchParams: { chainId?: string; uri?: string }; | ||
| }) { | ||
| return ( | ||
| <> | ||
| <AutoConnectWalletConnect uri={uri} /> | ||
| <NftGallery owner={getAddress(address)} chainId={Number(chainId)} /> | ||
| </> | ||
| ); | ||
| } |
12 changes: 0 additions & 12 deletions
12
apps/wallet-ui/src/app/[ecosystem]/(ui)/wallet/[address]/page.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,5 @@ | ||
| "use client"; | ||
| import { generatePayload, getCurrentUser, login, logout } from "@/lib/auth"; | ||
| import { client } from "@/lib/client"; | ||
| import { useTheme } from "next-themes"; | ||
| import { useRouter } from "next/navigation"; | ||
| import type { VerifyLoginPayloadParams } from "thirdweb/auth"; | ||
| import { ConnectEmbed } from "thirdweb/react"; | ||
| import { ecosystemWallet } from "thirdweb/wallets"; | ||
| import { ConnectEmbed } from "@/components/ConnectEmbed"; | ||
|
|
||
| export default function Page({ params }: { params: { ecosystem: string } }) { | ||
| const { theme } = useTheme(); | ||
| const router = useRouter(); | ||
|
|
||
| return ( | ||
| <ConnectEmbed | ||
| theme={theme === "light" ? "light" : "dark"} | ||
| autoConnect={true} | ||
| wallets={[ecosystemWallet(`ecosystem.${params.ecosystem}`)]} | ||
| client={client} | ||
| auth={{ | ||
| getLoginPayload: generatePayload, | ||
| doLogin: async (loginParams: VerifyLoginPayloadParams) => { | ||
| const success = await login(loginParams); | ||
| if (success) { | ||
| router.push(`/wallet/${loginParams.payload.address}`); | ||
| } | ||
| }, | ||
| isLoggedIn: async () => !!(await getCurrentUser()), | ||
| doLogout: logout, | ||
| }} | ||
| /> | ||
| ); | ||
| export default function Page() { | ||
| return <ConnectEmbed />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // This page is to accept a Wallet Connect request | ||
| import { getCurrentUser } from "@/lib/auth"; | ||
| import { redirect } from "next/navigation"; | ||
|
|
||
| export default async function Page({ | ||
| searchParams: { uri }, | ||
| }: { | ||
| searchParams: { uri: string }; | ||
| }) { | ||
| const currentUser = await getCurrentUser(); | ||
|
|
||
| if (!currentUser) { | ||
| redirect(`/login?uri=${encodeURIComponent(uri)}`); | ||
| } | ||
|
|
||
| redirect(`/wallet/${currentUser}?uri=${encodeURIComponent(uri)}`); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| "use client"; | ||
|
|
||
| import { useWalletConnect } from "@/hooks/useWalletConnect"; | ||
|
|
||
| export function AutoConnectWalletConnect({ uri }: { uri?: string }) { | ||
| useWalletConnect({ uri }); | ||
| return <></>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| "use client"; | ||
| import { generatePayload, getCurrentUser, login, logout } from "@/lib/auth"; | ||
| import { client } from "@/lib/client"; | ||
| import { useTheme } from "next-themes"; | ||
| import { useParams, useRouter, useSearchParams } from "next/navigation"; | ||
| import type { VerifyLoginPayloadParams } from "thirdweb/auth"; | ||
| import { ConnectEmbed as ThirdwebConnectEmbed } from "thirdweb/react"; | ||
| import { ecosystemWallet } from "thirdweb/wallets"; | ||
|
|
||
| export function ConnectEmbed() { | ||
| const { theme } = useTheme(); | ||
| const router = useRouter(); | ||
| const params = useParams(); | ||
| const searchParams = useSearchParams(); | ||
|
|
||
| return ( | ||
| <ThirdwebConnectEmbed | ||
| theme={theme === "light" ? "light" : "dark"} | ||
| autoConnect={true} | ||
| wallets={[ecosystemWallet(`ecosystem.${params.ecosystem}`)]} | ||
| client={client} | ||
| auth={{ | ||
| getLoginPayload: generatePayload, | ||
| doLogin: async (loginParams: VerifyLoginPayloadParams) => { | ||
| const success = await login(loginParams); | ||
| if (success) { | ||
| router.push( | ||
| `/wallet/${loginParams.payload.address}?${searchParams.toString()}`, | ||
| ); | ||
| } | ||
| }, | ||
| isLoggedIn: async () => !!(await getCurrentUser()), | ||
| doLogout: logout, | ||
| }} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { client } from "@/lib/client"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import { CheckIcon } from "lucide-react"; | ||
| import { toast } from "sonner"; | ||
| import { useActiveWallet } from "thirdweb/react"; | ||
| import { | ||
| createWalletConnectClient, | ||
| createWalletConnectSession, | ||
| } from "thirdweb/wallets"; | ||
|
|
||
| export function useWalletConnect({ uri }: { uri?: string }) { | ||
| const wallet = useActiveWallet(); | ||
|
|
||
| useQuery({ | ||
| queryKey: ["wallet-connect", uri], | ||
| queryFn: async () => { | ||
| if (!wallet || !uri) throw new Error("Unreachable"); | ||
| const wcClient = await createWalletConnectClient({ | ||
| wallet: wallet, | ||
| client: client, | ||
| }); | ||
|
|
||
| createWalletConnectSession({ | ||
| walletConnectClient: wcClient, | ||
| uri, | ||
| }); | ||
|
|
||
| toast.success("Wallet connected.", { | ||
| id: "wallet-connect", | ||
| icon: <CheckIcon className="h-4 w-4" />, | ||
| duration: 5000, | ||
| }); | ||
|
|
||
| return true; | ||
| }, | ||
| enabled: !!uri || !!wallet, | ||
| }); | ||
|
|
||
| return; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.