-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
'@coinbase/onchainkit': patch | ||
--- | ||
|
||
-**docs**: Auto logged in components on landing page. @cpcramer #1754 |
This file contains 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,118 @@ | ||
'use client'; | ||
import { OnchainKitProvider } from '@coinbase/onchainkit'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import type { ReactNode } from 'react'; | ||
import { http, WagmiProvider, createConfig } from 'wagmi'; | ||
import { base, baseSepolia } from 'wagmi/chains'; | ||
import { coinbaseWallet } from 'wagmi/connectors'; | ||
import '@coinbase/onchainkit/styles.css'; | ||
import { createWalletClient } from 'viem'; | ||
import { privateKeyToAccount } from 'viem/accounts'; | ||
import { useTheme } from '../contexts/Theme.tsx'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
// WARNING: This is a publicly exposed private key used only for documentation demos. | ||
// Do not use this key for any real transactions or store any assets in this account. | ||
const DUMMY_PK = | ||
'0xa67bdd8a49324aa36cb3f7f7064b9b560e3aa653b774be9793415c0a6fc62cf8'; | ||
|
||
const demoWalletConnector = (_config: any) => { | ||
const account = privateKeyToAccount(DUMMY_PK as `0x${string}`); | ||
|
||
const client = createWalletClient({ | ||
account, | ||
chain: baseSepolia, | ||
transport: http(), | ||
}); | ||
|
||
return { | ||
id: 'testWallet', | ||
name: 'Test Wallet', | ||
type: 'injected' as const, | ||
async connect() { | ||
return { | ||
accounts: [account.address], | ||
chainId: baseSepolia.id, | ||
}; | ||
}, | ||
async switchChain({ chainId }: { chainId: number }) { | ||
if (chainId === baseSepolia.id) { | ||
return baseSepolia; | ||
} | ||
if (chainId === base.id) { | ||
return base; | ||
} | ||
throw new Error('Unsupported chain'); | ||
}, | ||
async disconnect() {}, | ||
async getAccount() { | ||
return account.address; | ||
}, | ||
async getChainId() { | ||
return baseSepolia.id; | ||
}, | ||
async isAuthorized() { | ||
return true; | ||
}, | ||
onAccountsChanged() {}, | ||
onChainChanged() {}, | ||
onDisconnect() {}, | ||
async getAccounts() { | ||
return [account.address]; | ||
}, | ||
async getProvider() { | ||
return client; | ||
}, | ||
}; | ||
}; | ||
|
||
const wagmiConfig = createConfig({ | ||
chains: [base, baseSepolia], | ||
connectors: [ | ||
demoWalletConnector, | ||
coinbaseWallet({ | ||
appName: 'OnchainKit', | ||
}), | ||
], | ||
ssr: true, | ||
transports: { | ||
[base.id]: http(), | ||
[baseSepolia.id]: http(), | ||
}, | ||
}); | ||
|
||
export default function AppDemo({ children }: { children: ReactNode }) { | ||
const isServer = typeof window === 'undefined'; | ||
if (isServer) { | ||
return null; | ||
} | ||
const viteCdpApiKey = import.meta.env.VITE_CDP_API_KEY; | ||
const viteProjectId = import.meta.env.VITE_CDP_PROJECT_ID; | ||
const { theme } = useTheme(); | ||
|
||
return ( | ||
<WagmiProvider config={wagmiConfig}> | ||
<QueryClientProvider client={queryClient}> | ||
<OnchainKitProvider | ||
apiKey={viteCdpApiKey} | ||
chain={base} | ||
projectId={viteProjectId} | ||
schemaId="0xf8b05c79f090979bf4a80270aba232dff11a10d9ca55c4f88de95317970f0de9" | ||
config={{ | ||
appearance: { | ||
mode: 'auto', | ||
theme: theme, | ||
}, | ||
autoConnect: true, | ||
chains: [base, baseSepolia], | ||
}} | ||
> | ||
<div style={{ display: 'flex', flexDirection: 'column' }}> | ||
{children} | ||
</div> | ||
</OnchainKitProvider> | ||
</QueryClientProvider> | ||
</WagmiProvider> | ||
); | ||
} |
This file contains 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 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