-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): anvil connector, connect external wallets (#3164)
Co-authored-by: karooolis <[email protected]>
- Loading branch information
Showing
17 changed files
with
268 additions
and
129 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 @@ | ||
--- | ||
"@latticexyz/explorer": patch | ||
--- | ||
|
||
World Explorer now supports connecting external wallets. |
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
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 @@ | ||
import { Chain, anvil, garnet, redstone } from "viem/chains"; | ||
|
||
export const chains: Partial<Record<number, Chain>> = { | ||
[anvil.id]: anvil, | ||
[redstone.id]: redstone, | ||
[garnet.id]: garnet, | ||
}; | ||
|
||
export function getChain() { | ||
const chainId = Number(process.env.NEXT_PUBLIC_CHAIN_ID || anvil.id); | ||
const chain = chains[chainId]; | ||
if (!chain) { | ||
throw new Error(`Chain ID ${chainId} not supported. Supported chains are: ${Object.keys(chains).join(", ")}.`); | ||
} | ||
|
||
return chain; | ||
} | ||
|
||
export function isAnvil() { | ||
const chain = getChain(); | ||
return chain.id === anvil.id; | ||
} |
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,59 @@ | ||
import { PlugIcon, ZapIcon } from "lucide-react"; | ||
import { ConnectButton as RainbowConnectButton } from "@rainbow-me/rainbowkit"; | ||
import { isAnvil } from "../common"; | ||
import { cn } from "../lib/utils"; | ||
import { AccountSelect } from "./AccountSelect"; | ||
import { Button } from "./ui/Button"; | ||
|
||
export function ConnectButton() { | ||
return ( | ||
<RainbowConnectButton.Custom> | ||
{({ account, chain, openAccountModal, openChainModal, openConnectModal, mounted }) => { | ||
const connected = mounted && account && chain; | ||
|
||
return ( | ||
<div | ||
className={cn({ | ||
"pointer-events-none select-none opacity-0": !mounted, | ||
})} | ||
> | ||
{(() => { | ||
if (!connected) { | ||
if (isAnvil()) { | ||
return <AccountSelect />; | ||
} | ||
|
||
return ( | ||
<Button type="button" size="sm" onClick={openConnectModal}> | ||
<PlugIcon className="mr-2 inline-block h-4 w-4" /> Connect | ||
</Button> | ||
); | ||
} | ||
|
||
if (chain.unsupported) { | ||
return ( | ||
<Button type="button" size="sm" onClick={openChainModal}> | ||
<ZapIcon className="mr-2 inline-block h-4 w-4" /> | ||
Wrong network | ||
</Button> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex-wrap gap-2"> | ||
<Button type="button" size="sm" onClick={openAccountModal} variant="secondary"> | ||
<PlugIcon className="mr-2 inline-block h-4 w-4" /> | ||
{account.displayName} | ||
<span className="ml-2 font-normal opacity-70"> | ||
{account.displayBalance ? ` (${account.displayBalance})` : ""} | ||
</span> | ||
</Button> | ||
</div> | ||
); | ||
})()} | ||
</div> | ||
); | ||
}} | ||
</RainbowConnectButton.Custom> | ||
); | ||
} |
Oops, something went wrong.