-
Notifications
You must be signed in to change notification settings - Fork 78
Migrate nextjs-anchor template to Kit plugins #323
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
cxalem
merged 4 commits into
solana-foundation:main
from
cxalem:feat/kit-plugins-migration
Mar 25, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9ee5693
refactor(nextjs-anchor): migrate to Kit plugins for wallet and transa…
cxalem f289c77
refactor(nextjs-anchor): finalize kit plugin flow and template baseline
cxalem e555549
chore(nextjs-anchor): format wallet signer
cxalem 4842405
Merge branch 'main' into feat/kit-plugins-migration
cxalem 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
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 |
|---|---|---|
|
|
@@ -43,3 +43,6 @@ next-env.d.ts | |
| # anchor build artifacts | ||
| /anchor/.anchor/ | ||
| /anchor/target/ | ||
|
|
||
| # solana local validator | ||
| test-ledger/ | ||
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,61 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| createContext, | ||
| useContext, | ||
| useState, | ||
| useCallback, | ||
| type ReactNode, | ||
| } from "react"; | ||
| import type { ClusterMoniker } from "../lib/solana-client"; | ||
| import { CLUSTERS } from "../lib/solana-client"; | ||
| import { getExplorerUrl } from "../lib/explorer"; | ||
|
|
||
| type ClusterContextValue = { | ||
| cluster: ClusterMoniker; | ||
| setCluster: (cluster: ClusterMoniker) => void; | ||
| getExplorerUrl: (path: string) => string; | ||
| }; | ||
|
|
||
| const ClusterContext = createContext<ClusterContextValue | null>(null); | ||
|
|
||
| const STORAGE_KEY = "solana-cluster"; | ||
| function getInitialCluster(): ClusterMoniker { | ||
| if (typeof window === "undefined") return "devnet"; | ||
| const stored = localStorage.getItem(STORAGE_KEY); | ||
| if (stored && CLUSTERS.includes(stored as ClusterMoniker)) { | ||
| return stored as ClusterMoniker; | ||
| } | ||
| return "devnet"; | ||
| } | ||
|
|
||
| export { CLUSTERS }; | ||
|
|
||
| export function ClusterProvider({ children }: { children: ReactNode }) { | ||
| const [cluster, setClusterState] = | ||
| useState<ClusterMoniker>(getInitialCluster); | ||
|
|
||
| const setCluster = useCallback((c: ClusterMoniker) => { | ||
| setClusterState(c); | ||
| localStorage.setItem(STORAGE_KEY, c); | ||
| }, []); | ||
|
|
||
| const explorerUrl = useCallback( | ||
| (path: string) => getExplorerUrl(path, cluster), | ||
| [cluster] | ||
| ); | ||
|
|
||
| return ( | ||
| <ClusterContext.Provider | ||
| value={{ cluster, setCluster, getExplorerUrl: explorerUrl }} | ||
| > | ||
| {children} | ||
| </ClusterContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| export function useCluster() { | ||
| const ctx = useContext(ClusterContext); | ||
| if (!ctx) throw new Error("useCluster must be used within ClusterProvider"); | ||
| return ctx; | ||
| } |
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,78 @@ | ||
| "use client"; | ||
|
|
||
| import { useState, useRef, useEffect } from "react"; | ||
| import { useCluster, CLUSTERS } from "./cluster-context"; | ||
|
|
||
| export function ClusterSelect() { | ||
| const { cluster, setCluster } = useCluster(); | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const ref = useRef<HTMLDivElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| function handleClickOutside(e: MouseEvent) { | ||
| if (ref.current && !ref.current.contains(e.target as Node)) { | ||
| setIsOpen(false); | ||
| } | ||
| } | ||
| document.addEventListener("mousedown", handleClickOutside); | ||
| return () => document.removeEventListener("mousedown", handleClickOutside); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div className="relative" ref={ref}> | ||
| <button | ||
| onClick={() => setIsOpen(!isOpen)} | ||
| className="flex cursor-pointer items-center gap-2 rounded-lg border border-border-low bg-card px-3 py-2 text-xs font-medium transition hover:bg-cream" | ||
| > | ||
| <span | ||
| className="h-2 w-2 rounded-full" | ||
| style={{ | ||
| backgroundColor: | ||
| cluster === "mainnet" | ||
| ? "#22c55e" | ||
| : cluster === "devnet" | ||
| ? "#3b82f6" | ||
| : cluster === "testnet" | ||
| ? "#eab308" | ||
| : "#a3a3a3", | ||
| }} | ||
| /> | ||
| {cluster} | ||
| </button> | ||
|
|
||
| {isOpen && ( | ||
| <div className="absolute right-0 top-full z-50 mt-2 w-40 rounded-xl border border-border-low bg-card p-2 shadow-lg"> | ||
| <div className="space-y-1"> | ||
| {CLUSTERS.map((c) => ( | ||
| <button | ||
| key={c} | ||
| onClick={() => { | ||
| setCluster(c); | ||
| setIsOpen(false); | ||
| }} | ||
| className={`flex w-full cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-left text-xs font-medium transition hover:bg-cream ${ | ||
| c === cluster ? "bg-cream" : "" | ||
| }`} | ||
| > | ||
| <span | ||
| className="h-2 w-2 rounded-full" | ||
| style={{ | ||
| backgroundColor: | ||
| c === "mainnet" | ||
| ? "#22c55e" | ||
| : c === "devnet" | ||
| ? "#3b82f6" | ||
| : c === "testnet" | ||
| ? "#eab308" | ||
| : "#a3a3a3", | ||
| }} | ||
| /> | ||
| {c} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
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,78 @@ | ||
| "use client"; | ||
|
|
||
| export function GridBackground() { | ||
| return ( | ||
| <div className="pointer-events-none fixed inset-0 z-0" aria-hidden="true"> | ||
| {/* Ambient glow */} | ||
| <div | ||
| className="absolute inset-0 transition-opacity duration-500" | ||
| style={{ | ||
| background: [ | ||
| "radial-gradient(ellipse 30% 28% at 30% 50%, rgba(153,69,255,0.08) 0%, transparent 70%)", | ||
| "radial-gradient(ellipse 30% 28% at 70% 50%, rgba(20,241,149,0.08) 0%, transparent 70%)", | ||
| ].join(", "), | ||
| }} | ||
| /> | ||
|
|
||
| {/* Large grid — purple (left) */} | ||
| <div | ||
| className="absolute inset-0 opacity-80 dark:opacity-60" | ||
| style={{ | ||
| backgroundImage: ` | ||
| linear-gradient(to right, rgba(153,69,255,0.18) 1px, transparent 1px), | ||
| linear-gradient(to bottom, rgba(153,69,255,0.18) 1px, transparent 1px) | ||
| `, | ||
| backgroundSize: "80px 80px", | ||
| mask: "radial-gradient(ellipse 30% 35% at 30% 50%, black, transparent)", | ||
| WebkitMask: | ||
| "radial-gradient(ellipse 30% 35% at 30% 50%, black, transparent)", | ||
| }} | ||
| /> | ||
|
|
||
| {/* Large grid — green (right) */} | ||
| <div | ||
| className="absolute inset-0 opacity-80 dark:opacity-60" | ||
| style={{ | ||
| backgroundImage: ` | ||
| linear-gradient(to right, rgba(20,241,149,0.18) 1px, transparent 1px), | ||
| linear-gradient(to bottom, rgba(20,241,149,0.18) 1px, transparent 1px) | ||
| `, | ||
| backgroundSize: "80px 80px", | ||
| mask: "radial-gradient(ellipse 30% 35% at 70% 50%, black, transparent)", | ||
| WebkitMask: | ||
| "radial-gradient(ellipse 30% 35% at 70% 50%, black, transparent)", | ||
| }} | ||
| /> | ||
|
|
||
| {/* Small grid — purple (left) */} | ||
| <div | ||
| className="absolute inset-0 opacity-80 dark:opacity-60" | ||
| style={{ | ||
| backgroundImage: ` | ||
| linear-gradient(to right, rgba(153,69,255,0.10) 1px, transparent 1px), | ||
| linear-gradient(to bottom, rgba(153,69,255,0.10) 1px, transparent 1px) | ||
| `, | ||
| backgroundSize: "16px 16px", | ||
| mask: "radial-gradient(ellipse 30% 35% at 30% 50%, black, transparent)", | ||
| WebkitMask: | ||
| "radial-gradient(ellipse 30% 35% at 30% 50%, black, transparent)", | ||
| }} | ||
| /> | ||
|
|
||
| {/* Small grid — green (right) */} | ||
| <div | ||
| className="absolute inset-0 opacity-80 dark:opacity-60" | ||
| style={{ | ||
| backgroundImage: ` | ||
| linear-gradient(to right, rgba(20,241,149,0.10) 1px, transparent 1px), | ||
| linear-gradient(to bottom, rgba(20,241,149,0.10) 1px, transparent 1px) | ||
| `, | ||
| backgroundSize: "16px 16px", | ||
| mask: "radial-gradient(ellipse 30% 35% at 70% 50%, black, transparent)", | ||
| WebkitMask: | ||
| "radial-gradient(ellipse 30% 35% at 70% 50%, black, transparent)", | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
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,15 +1,21 @@ | ||
| "use client"; | ||
|
|
||
| import { SolanaProvider } from "@solana/react-hooks"; | ||
| import { ThemeProvider } from "next-themes"; | ||
| import { Toaster } from "sonner"; | ||
| import { PropsWithChildren } from "react"; | ||
|
|
||
| import { autoDiscover, createClient } from "@solana/client"; | ||
|
|
||
| const client = createClient({ | ||
| endpoint: "https://api.devnet.solana.com", | ||
| walletConnectors: autoDiscover(), | ||
| }); | ||
| import { ClusterProvider } from "./cluster-context"; | ||
| import { WalletProvider } from "../lib/wallet/context"; | ||
| import { SolanaClientProvider } from "../lib/solana-client-context"; | ||
|
|
||
| export function Providers({ children }: PropsWithChildren) { | ||
| return <SolanaProvider client={client}>{children}</SolanaProvider>; | ||
| return ( | ||
| <ThemeProvider attribute="class" defaultTheme="dark"> | ||
| <ClusterProvider> | ||
| <SolanaClientProvider> | ||
| <WalletProvider>{children}</WalletProvider> | ||
| </SolanaClientProvider> | ||
| <Toaster position="bottom-right" richColors /> | ||
| </ClusterProvider> | ||
| </ThemeProvider> | ||
| ); | ||
| } |
Oops, something went wrong.
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.