-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dynamic crypto providers (#1248)
* dynamic crypto providers * fixed typo
- Loading branch information
1 parent
d11bf62
commit 0c7febf
Showing
9 changed files
with
165 additions
and
100 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
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
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,22 @@ | ||
'use client'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { useErrors } from 'apps/web/contexts/Errors'; | ||
|
||
export function DynamicCryptoProviders({ children }: { children: React.ReactNode }) { | ||
const [CryptoProvidersDynamic, setCryptoProvidersDynamic] = | ||
useState<React.ComponentType<{ children: React.ReactNode }>>(); | ||
const { logError } = useErrors(); | ||
|
||
useEffect(() => { | ||
import('apps/web/app/CryptoProviders') | ||
.then((mod) => { | ||
setCryptoProvidersDynamic(() => mod.default); | ||
}) | ||
.catch((error) => logError(error, 'Failed to load CryptoProviders')); | ||
}, [logError]); | ||
|
||
if (!CryptoProvidersDynamic) return null; | ||
|
||
return <CryptoProvidersDynamic>{children}</CryptoProvidersDynamic>; | ||
} |
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,78 @@ | ||
'use client'; | ||
|
||
import { AppConfig, OnchainKitProvider } from '@coinbase/onchainkit'; | ||
import { connectorsForWallets, RainbowKitProvider } from '@rainbow-me/rainbowkit'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { isDevelopment } from 'apps/web/src/constants'; | ||
import { createConfig, http, WagmiProvider } from 'wagmi'; | ||
import { base, baseSepolia, mainnet } from 'wagmi/chains'; | ||
import { | ||
coinbaseWallet, | ||
metaMaskWallet, | ||
phantomWallet, | ||
rainbowWallet, | ||
uniswapWallet, | ||
walletConnectWallet, | ||
} from '@rainbow-me/rainbowkit/wallets'; | ||
|
||
const connectors = connectorsForWallets( | ||
[ | ||
{ | ||
groupName: 'Recommended', | ||
wallets: [ | ||
coinbaseWallet, | ||
metaMaskWallet, | ||
uniswapWallet, | ||
rainbowWallet, | ||
phantomWallet, | ||
walletConnectWallet, | ||
], | ||
}, | ||
], | ||
{ | ||
projectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID ?? 'dummy-id', | ||
walletConnectParameters: {}, | ||
appName: 'Base.org', | ||
appDescription: '', | ||
appUrl: 'https://www.base.org/', | ||
appIcon: '', | ||
}, | ||
); | ||
|
||
const config = createConfig({ | ||
connectors, | ||
chains: [base, baseSepolia, mainnet], | ||
transports: { | ||
[base.id]: http(), | ||
[baseSepolia.id]: http(), | ||
[mainnet.id]: http(), | ||
}, | ||
ssr: true, | ||
}); | ||
const queryClient = new QueryClient(); | ||
|
||
type CryptoProvidersProps = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
const onchainKitConfig: AppConfig = { | ||
appearance: { | ||
mode: 'light', | ||
}, | ||
}; | ||
|
||
export default function CryptoProviders({ children }: CryptoProvidersProps) { | ||
return ( | ||
<WagmiProvider config={config}> | ||
<QueryClientProvider client={queryClient}> | ||
<OnchainKitProvider | ||
chain={isDevelopment ? baseSepolia : base} | ||
apiKey={process.env.NEXT_PUBLIC_ONCHAINKIT_API_KEY} | ||
config={onchainKitConfig} | ||
> | ||
<RainbowKitProvider modalSize="compact">{children}</RainbowKitProvider> | ||
</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
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