mirror of
https://github.com/luxfhe/example-dapps.git
synced 2026-10-30 18:13:32 +00:00
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
"use client";
|
|
|
|
// @refresh reset
|
|
import { Balance } from "../Balance";
|
|
import { AddressInfoDropdown } from "./AddressInfoDropdown";
|
|
import { WrongNetworkDropdown } from "./WrongNetworkDropdown";
|
|
import { ConnectButton } from "@rainbow-me/rainbowkit";
|
|
import { Address } from "viem";
|
|
import { useTargetNetwork } from "~~/hooks/helper/useTargetNetwork";
|
|
import { getBlockExplorerAddressLink } from "~~/utils/helper";
|
|
|
|
/**
|
|
* Custom Wagmi Connect Button (watch balance + custom design)
|
|
*/
|
|
export const RainbowKitCustomConnectButton = () => {
|
|
const { targetNetwork } = useTargetNetwork();
|
|
|
|
return (
|
|
<ConnectButton.Custom>
|
|
{({ account, chain, openConnectModal, mounted }) => {
|
|
const connected = mounted && account && chain;
|
|
const blockExplorerAddressLink = account
|
|
? getBlockExplorerAddressLink(targetNetwork, account.address)
|
|
: undefined;
|
|
|
|
return (
|
|
<>
|
|
{(() => {
|
|
if (!connected) {
|
|
return (
|
|
<button className="glass-button px-6 py-3 text-[#2D2D2D] font-semibold cursor-pointer" onClick={openConnectModal} type="button">
|
|
Connect Wallet
|
|
</button>
|
|
);
|
|
}
|
|
|
|
if (chain.unsupported || chain.id !== targetNetwork.id) {
|
|
return <WrongNetworkDropdown />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="flex flex-col items-center mr-1 text-[#2D2D2D]">
|
|
<Balance address={account.address as Address} className="min-h-0 h-auto" />
|
|
<span className="text-xs text-[#2D2D2D] font-medium">{chain.name}</span>
|
|
</div>
|
|
<AddressInfoDropdown
|
|
address={account.address as Address}
|
|
displayName={account.displayName}
|
|
ensAvatar={account.ensAvatar}
|
|
blockExplorerAddressLink={blockExplorerAddressLink}
|
|
/>
|
|
</>
|
|
);
|
|
})()}
|
|
</>
|
|
);
|
|
}}
|
|
</ConnectButton.Custom>
|
|
);
|
|
};
|