Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions src/components/ConnectWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
'use client'
import * as React from 'react'
import { tempo } from 'viem/chains'
import { useChains, useConnect, useConnection, useConnectors, useSwitchChain } from 'wagmi'
import { Button, Logout } from './guides/Demo'
import { filterSupportedInjectedConnectors } from './lib/wallets'

export function ConnectWallet({ showAddChain = true }: { showAddChain?: boolean }) {
const mainnetParams = {
chainId: tempo.id,
addEthereumChainParameter: {
chainName: tempo.name,
nativeCurrency: { name: 'USD', decimals: 18, symbol: 'USD' },
rpcUrls: [tempo.rpcUrls.default.http[0]],
blockExplorerUrls: ['https://explore.tempo.xyz'],
},
}

export function ConnectWallet({
showAddChain = true,
network = 'testnet',
}: { showAddChain?: boolean; network?: 'mainnet' | 'testnet' }) {
const { address, chain, connector } = useConnection()
const connect = useConnect()
const connectors = useConnectors()
Expand All @@ -14,7 +28,9 @@ export function ConnectWallet({ showAddChain = true }: { showAddChain?: boolean
)
const switchChain = useSwitchChain()
const chains = useChains()
const isSupported = chains.some((c) => c.id === chain?.id)
const targetChainId = network === 'mainnet' ? tempo.id : chains[0].id
const isSupported =
network === 'mainnet' ? chain?.id === targetChainId : chains.some((c) => c.id === chain?.id)
if (!injectedConnectors.length)
return (
<div className="flex items-center text-[14px] -tracking-[2%]">No browser wallets found.</div>
Expand All @@ -39,26 +55,26 @@ export function ConnectWallet({ showAddChain = true }: { showAddChain?: boolean
))}
</div>
)

const switchParams =
network === 'mainnet'
? mainnetParams
: {
chainId: chains[0].id,
addEthereumChainParameter: {
nativeCurrency: { name: 'USD', decimals: 18, symbol: 'USD' },
blockExplorerUrls: ['https://explore.testnet.tempo.xyz'],
},
}

return (
<div className="flex flex-col gap-2">
<Logout />
{showAddChain && !isSupported && (
<Button
className="w-fit"
variant="accent"
onClick={() =>
switchChain.switchChain({
chainId: chains[0].id,
addEthereumChainParameter: {
nativeCurrency: {
name: 'USD',
decimals: 18,
symbol: 'USD',
},
blockExplorerUrls: ['https://explore.tempo.xyz'],
},
})
}
onClick={() => switchChain.switchChain(switchParams)}
>
Add Tempo to {connector?.name ?? 'Wallet'}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/quickstart/connection-details.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can connect with Tempo like you would with any other EVM chain.

Click on your browser wallet below to automatically connect it to the Tempo network.

<ConnectWallet />
<ConnectWallet network="mainnet" />

:::warning
Note that on some wallets, you might see an unusually high "balance". This is because, historically, blockchain wallets have always assumed that a blockchain has a "native gas token". On Tempo, there is no native gas token, and so the value shown is a placeholder. See [EVM Differences](/quickstart/evm-compatibility#handling-eth-balance-checks) for more information on this quirk.
Expand Down
5 changes: 3 additions & 2 deletions src/wagmi.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { QueryClient } from '@tanstack/react-query'
import { Expiry } from 'accounts'
import * as React from 'react'
import { parseUnits } from 'viem'
import { tempoDevnet, tempoLocalnet, tempoModerato } from 'viem/chains'
import { tempo, tempoDevnet, tempoLocalnet, tempoModerato } from 'viem/chains'
import { withRelay } from 'viem/tempo'
import {
type CreateConfigParameters,
Expand Down Expand Up @@ -48,7 +48,7 @@ export function getConfig(options: getConfig.Options = {}) {
batch: {
multicall: false,
},
chains: [chain],
chains: [chain, tempo],
connectors: [
...(import.meta.env.VITE_E2E === 'true'
? [webAuthn()]
Expand Down Expand Up @@ -97,6 +97,7 @@ export function getConfig(options: getConfig.Options = {}) {
http('https://sponsor.devnet.tempo.xyz'),
{ policy: 'sign-only' },
),
[tempo.id]: http(tempo.rpcUrls.default.http[0]),
[tempoLocalnet.id]: http(undefined, { batch: true }),
},
})
Expand Down
Loading