-
Notifications
You must be signed in to change notification settings - Fork 4
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
15 changed files
with
186 additions
and
164 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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,18 @@ | ||
import { Button } from '@radix-ui/themes'; | ||
import { useConnectWallet } from '@web3-onboard/react'; | ||
import { FC } from 'react'; | ||
|
||
export const ConnectWalletButton: FC = () => { | ||
const [{ wallet }, connectWallet] = useConnectWallet(); | ||
|
||
return ( | ||
<Button | ||
onClick={async () => { | ||
if (wallet) return; | ||
await connectWallet(); | ||
}} | ||
> | ||
Connect wallet | ||
</Button> | ||
); | ||
}; |
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,85 @@ | ||
import { Button, DropdownMenu } from '@radix-ui/themes'; | ||
import { useConnectWallet, useSetChain } from '@web3-onboard/react'; | ||
import { FC } from 'react'; | ||
|
||
import { ConnectWalletButton } from './ConnectWalletButton'; | ||
import { supportedChains } from './helpers'; | ||
|
||
export const WalletConnection: FC = () => { | ||
const [{ wallet }, _, disconnectWallet] = useConnectWallet(); | ||
const [{ connectedChain }, setChain] = useSetChain(); | ||
|
||
const chainIcon = | ||
supportedChains.find(({ id }) => id === connectedChain?.id)?.icon ?? '/assets/questionmark.svg'; | ||
|
||
const selectChain = (chainId: string) => () => { | ||
setChain({ | ||
chainId | ||
}); | ||
}; | ||
|
||
return wallet ? ( | ||
<DropdownMenu.Root> | ||
<DropdownMenu.Trigger> | ||
<Button> | ||
<img | ||
src={chainIcon} | ||
alt="connected chain" | ||
style={{ marginRight: '0.3rem', height: '1.8rem' }} | ||
/> | ||
{`${wallet.accounts[0].address.substring( | ||
0, | ||
6 | ||
)}...${wallet.accounts[0].address.substr(-4)}`} | ||
</Button> | ||
</DropdownMenu.Trigger> | ||
<DropdownMenu.Content> | ||
<DropdownMenu.Label>Mainnet</DropdownMenu.Label> | ||
{supportedChains | ||
.filter(({ network }) => network === 'mainnet') | ||
.map(({ id, icon, label }) => ( | ||
<DropdownMenu.Item | ||
key={id} | ||
onSelect={selectChain(id)} | ||
style={{ | ||
backgroundColor: connectedChain?.id === id ? 'lightgrey' : undefined, | ||
color: connectedChain?.id === id ? 'black' : undefined, | ||
fontWeight: connectedChain?.id === id ? '600' : undefined | ||
}} | ||
> | ||
<img src={icon} alt={label} style={{ marginRight: '0.3rem', height: '1.8rem' }} /> | ||
{label} | ||
</DropdownMenu.Item> | ||
))} | ||
<DropdownMenu.Separator /> | ||
<DropdownMenu.Label>Testnet</DropdownMenu.Label> | ||
{supportedChains | ||
.filter(({ network }) => network === 'testnet') | ||
.map(({ id, icon, label }) => ( | ||
<DropdownMenu.Item | ||
key={id} | ||
onSelect={selectChain(id)} | ||
style={{ | ||
backgroundColor: connectedChain?.id === id ? 'lightgrey' : undefined, | ||
color: connectedChain?.id === id ? 'black' : undefined, | ||
fontWeight: connectedChain?.id === id ? '600' : undefined | ||
}} | ||
> | ||
<img src={icon} alt={label} style={{ marginRight: '0.3rem', height: '1.8rem' }} /> | ||
{label} | ||
</DropdownMenu.Item> | ||
))} | ||
<DropdownMenu.Separator /> | ||
<DropdownMenu.Item | ||
onSelect={() => { | ||
disconnectWallet({ label: wallet.label }); | ||
}} | ||
> | ||
Disconnect | ||
</DropdownMenu.Item> | ||
</DropdownMenu.Content> | ||
</DropdownMenu.Root> | ||
) : ( | ||
<ConnectWalletButton /> | ||
); | ||
}; |
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,56 @@ | ||
import type { Chain } from '@web3-onboard/common'; | ||
|
||
type SupportedChain = Chain & { network: 'mainnet' | 'testnet'; icon: string }; | ||
|
||
export const supportedChains: SupportedChain[] = [ | ||
{ | ||
network: 'mainnet', | ||
icon: '/assets/arbitrum.svg', | ||
id: '0xa4b1', | ||
token: 'ETH', | ||
label: 'Arbitrum One', | ||
rpcUrl: 'https://arbitrum-one.publicnode.com' | ||
}, | ||
{ | ||
network: 'mainnet', | ||
icon: '/assets/optimism.svg', | ||
id: '0xa', | ||
token: 'ETH', | ||
label: 'OP Mainnet', | ||
rpcUrl: 'https://mainnet.optimism.io' | ||
}, | ||
{ | ||
network: 'mainnet', | ||
icon: '/assets/base.svg', | ||
id: '0x2105', | ||
token: 'ETH', | ||
label: 'Base', | ||
rpcUrl: 'https://base-rpc.publicnode.com' | ||
}, | ||
{ | ||
network: 'testnet', | ||
icon: '/assets/arbitrum_sepolia.svg', | ||
id: '0x66eee', | ||
token: 'ETH', | ||
label: 'Arbitrum Sepolia', | ||
rpcUrl: 'https://arbitrum-sepolia.publicnode.com' | ||
}, | ||
{ | ||
network: 'testnet', | ||
icon: '/assets/optimism_sepolia.svg', | ||
id: '0xaa37dc', | ||
token: 'ETH', | ||
label: 'OP Sepolia', | ||
rpcUrl: 'https://optimism-sepolia.publicnode.com' | ||
}, | ||
{ | ||
network: 'testnet', | ||
icon: '/assets/base_sepolia.svg', | ||
id: '0x14a34', | ||
token: 'ETH', | ||
label: 'Base Sepolia', | ||
rpcUrl: 'https://base-sepolia-rpc.publicnode.com' | ||
} | ||
]; | ||
|
||
export const supportedChainIds = supportedChains.map(({ id }) => Number(id)); |
Oops, something went wrong.