Skip to content

Instantly share code, notes, and snippets.

@martincik
Created July 29, 2024 18:17
Show Gist options
  • Save martincik/f2da907342b3c9dcb046eb435b54884c to your computer and use it in GitHub Desktop.
Save martincik/f2da907342b3c9dcb046eb435b54884c to your computer and use it in GitHub Desktop.
"use client";
import { useMemo } from "react";
import { useSearchParams } from "next/navigation";
import {
ConnectionProvider,
WalletProvider,
} from "@solana/wallet-adapter-react";
import { TipLinkWalletAutoConnectV2 } from "@tiplink/wallet-adapter-react-ui";
import { TipLinkWalletAdapter } from "@tiplink/wallet-adapter";
import { CoinbaseWalletAdapter } from "@solana/wallet-adapter-coinbase";
import { WalletConnectWalletAdapter } from "@solana/wallet-adapter-walletconnect";
import { TipLinkWalletModalProvider } from "@/components/tiplink/tiplink-wallet-modal-provider";
import { env } from "@/env.mjs";
interface WalletConnectProviderProps {
autoConnect?: boolean;
children: React.ReactNode;
}
export function WalletConnectProvider({
autoConnect,
children,
}: WalletConnectProviderProps) {
const searchParams = useSearchParams();
const endpoint = env.NEXT_PUBLIC_SOLANA_RPC_ENDPOINT;
const network = env.NEXT_PUBLIC_SOLANA_NETWORK;
console.log(`Connecting to ${endpoint} network ${network}.`);
const wallets = useMemo(
() => [
new TipLinkWalletAdapter({
clientId: "55b3ab2b-8dfb-4b58-949e-9237c60700db",
title: "Access Protocol",
theme: "system",
}),
new CoinbaseWalletAdapter({
network: network,
options: {
appName: "Access Protocol",
appLogo: `${env.NEXT_PUBLIC_APP_URL}/favicon.ico`,
darkMode: false,
},
}),
new WalletConnectWalletAdapter({
network: network,
options: {
relayUrl: "wss://relay.walletconnect.com",
projectId: env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID,
metadata: {
name: "Access Protocol",
description: "Access Protocol",
url: env.NEXT_PUBLIC_APP_URL,
icons: [`${env.NEXT_PUBLIC_APP_URL}/favicon.ico`],
},
},
}),
],
[network],
);
return (
<ConnectionProvider endpoint={endpoint}>
<TipLinkWalletAutoConnectV2 isReady query={searchParams}>
<WalletProvider wallets={wallets} autoConnect={autoConnect || false}>
<TipLinkWalletModalProvider>{children}</TipLinkWalletModalProvider>
</WalletProvider>
</TipLinkWalletAutoConnectV2>
</ConnectionProvider>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment