-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
8d38fca
commit c557339
Showing
12 changed files
with
451 additions
and
60 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
137 changes: 137 additions & 0 deletions
137
...ges/nextjs/components/scaffold-nft/RainbowKitCustomConnectButton2/AddressInfoDropdown.tsx
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,137 @@ | ||
import { useRef, useState } from "react"; | ||
import { NetworkOptions } from "./NetworkOptions"; | ||
import CopyToClipboard from "react-copy-to-clipboard"; | ||
import { getAddress } from "viem"; | ||
import { Address } from "viem"; | ||
import { useDisconnect } from "wagmi"; | ||
import { | ||
ArrowLeftOnRectangleIcon, | ||
ArrowTopRightOnSquareIcon, | ||
ArrowsRightLeftIcon, | ||
CheckCircleIcon, | ||
ChevronDownIcon, | ||
DocumentDuplicateIcon, | ||
QrCodeIcon, | ||
} from "@heroicons/react/24/outline"; | ||
import { BlockieAvatar, isENS } from "~~/components/scaffold-eth"; | ||
import { useOutsideClick } from "~~/hooks/scaffold-eth"; | ||
import { getTargetNetworks } from "~~/utils/scaffold-eth"; | ||
|
||
const allowedNetworks = getTargetNetworks(); | ||
|
||
type AddressInfoDropdownProps = { | ||
address: Address; | ||
blockExplorerAddressLink: string | undefined; | ||
displayName: string; | ||
ensAvatar?: string; | ||
}; | ||
|
||
export const AddressInfoDropdown = ({ | ||
address, | ||
ensAvatar, | ||
displayName, | ||
blockExplorerAddressLink, | ||
}: AddressInfoDropdownProps) => { | ||
const { disconnect } = useDisconnect(); | ||
const checkSumAddress = getAddress(address); | ||
|
||
const [addressCopied, setAddressCopied] = useState(false); | ||
|
||
const [selectingNetwork, setSelectingNetwork] = useState(false); | ||
const dropdownRef = useRef<HTMLDetailsElement>(null); | ||
const closeDropdown = () => { | ||
setSelectingNetwork(false); | ||
dropdownRef.current?.removeAttribute("open"); | ||
}; | ||
useOutsideClick(dropdownRef, closeDropdown); | ||
|
||
return ( | ||
<> | ||
<details ref={dropdownRef} className="dropdown dropdown-end leading-3"> | ||
<summary tabIndex={0} className="btn btn-secondary btn-sm pl-0 pr-2 shadow-md dropdown-toggle gap-0 !h-auto"> | ||
<BlockieAvatar address={checkSumAddress} size={30} ensImage={ensAvatar} /> | ||
<span className="ml-2 mr-1"> | ||
{isENS(displayName) ? displayName : checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4)} | ||
</span> | ||
<ChevronDownIcon className="h-6 w-4 ml-2 sm:ml-0" /> | ||
</summary> | ||
<ul | ||
tabIndex={0} | ||
className="dropdown-content menu z-[2] p-2 mt-2 shadow-center shadow-accent bg-base-200 rounded-box gap-1" | ||
> | ||
<NetworkOptions hidden={!selectingNetwork} /> | ||
<li className={selectingNetwork ? "hidden" : ""}> | ||
{addressCopied ? ( | ||
<div className="btn-sm !rounded-xl flex gap-3 py-3"> | ||
<CheckCircleIcon | ||
className="text-xl font-normal h-6 w-4 cursor-pointer ml-2 sm:ml-0" | ||
aria-hidden="true" | ||
/> | ||
<span className=" whitespace-nowrap">Copy address</span> | ||
</div> | ||
) : ( | ||
<CopyToClipboard | ||
text={checkSumAddress} | ||
onCopy={() => { | ||
setAddressCopied(true); | ||
setTimeout(() => { | ||
setAddressCopied(false); | ||
}, 800); | ||
}} | ||
> | ||
<div className="btn-sm !rounded-xl flex gap-3 py-3"> | ||
<DocumentDuplicateIcon | ||
className="text-xl font-normal h-6 w-4 cursor-pointer ml-2 sm:ml-0" | ||
aria-hidden="true" | ||
/> | ||
<span className=" whitespace-nowrap">Copy address</span> | ||
</div> | ||
</CopyToClipboard> | ||
)} | ||
</li> | ||
<li className={selectingNetwork ? "hidden" : ""}> | ||
<label htmlFor="qrcode-modal" className="btn-sm !rounded-xl flex gap-3 py-3"> | ||
<QrCodeIcon className="h-6 w-4 ml-2 sm:ml-0" /> | ||
<span className="whitespace-nowrap">View QR Code</span> | ||
</label> | ||
</li> | ||
<li className={selectingNetwork ? "hidden" : ""}> | ||
<button className="menu-item btn-sm !rounded-xl flex gap-3 py-3" type="button"> | ||
<ArrowTopRightOnSquareIcon className="h-6 w-4 ml-2 sm:ml-0" /> | ||
<a | ||
target="_blank" | ||
href={blockExplorerAddressLink} | ||
rel="noopener noreferrer" | ||
className="whitespace-nowrap" | ||
> | ||
View on Block Explorer | ||
</a> | ||
</button> | ||
</li> | ||
{allowedNetworks.length > 1 ? ( | ||
<li className={selectingNetwork ? "hidden" : ""}> | ||
<button | ||
className="btn-sm !rounded-xl flex gap-3 py-3" | ||
type="button" | ||
onClick={() => { | ||
setSelectingNetwork(true); | ||
}} | ||
> | ||
<ArrowsRightLeftIcon className="h-6 w-4 ml-2 sm:ml-0" /> <span>Switch Network</span> | ||
</button> | ||
</li> | ||
) : null} | ||
<li className={selectingNetwork ? "hidden" : ""}> | ||
<button | ||
className="menu-item text-error btn-sm !rounded-xl flex gap-3 py-3" | ||
type="button" | ||
onClick={() => disconnect()} | ||
> | ||
<ArrowLeftOnRectangleIcon className="h-6 w-4 ml-2 sm:ml-0" /> <span>Disconnect</span> | ||
</button> | ||
</li> | ||
</ul> | ||
</details> | ||
</> | ||
); | ||
}; |
33 changes: 33 additions & 0 deletions
33
...ages/nextjs/components/scaffold-nft/RainbowKitCustomConnectButton2/AddressQRCodeModal.tsx
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,33 @@ | ||
import { QRCodeSVG } from "qrcode.react"; | ||
import { Address as AddressType } from "viem"; | ||
import { Address } from "~~/components/scaffold-eth"; | ||
|
||
type AddressQRCodeModalProps = { | ||
address: AddressType; | ||
modalId: string; | ||
}; | ||
|
||
export const AddressQRCodeModal = ({ address, modalId }: AddressQRCodeModalProps) => { | ||
return ( | ||
<> | ||
<div> | ||
<input type="checkbox" id={`${modalId}`} className="modal-toggle" /> | ||
<label htmlFor={`${modalId}`} className="modal cursor-pointer"> | ||
<label className="modal-box relative"> | ||
{/* dummy input to capture event onclick on modal box */} | ||
<input className="h-0 w-0 absolute top-0 left-0" /> | ||
<label htmlFor={`${modalId}`} className="btn btn-ghost btn-sm btn-circle absolute right-3 top-3"> | ||
✕ | ||
</label> | ||
<div className="space-y-3 py-6"> | ||
<div className="flex space-x-4 flex-col items-center gap-6"> | ||
<QRCodeSVG value={address} size={256} /> | ||
<Address address={address} format="long" disableAddressLink /> | ||
</div> | ||
</div> | ||
</label> | ||
</label> | ||
</div> | ||
</> | ||
); | ||
}; |
58 changes: 58 additions & 0 deletions
58
packages/nextjs/components/scaffold-nft/RainbowKitCustomConnectButton2/NetworkOptions.tsx
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,58 @@ | ||
import { useTheme } from "next-themes"; | ||
import { | ||
//useAccount, | ||
useSwitchChain, | ||
} from "wagmi"; | ||
import { ArrowsRightLeftIcon } from "@heroicons/react/24/solid"; | ||
import { getNetworkColor } from "~~/hooks/scaffold-eth"; | ||
// import { useTargetNetwork2 } from "~~/hooks/scaffold-nft/useTargetNetwork2"; | ||
import { useGlobalState } from "~~/services/store/store"; | ||
|
||
// import { getTargetNetworks } from "~~/utils/scaffold-eth"; | ||
|
||
// const allowedNetworks = getTargetNetworks(); | ||
|
||
type NetworkOptionsProps = { | ||
hidden?: boolean; | ||
}; | ||
|
||
export const NetworkOptions = ({ hidden = false }: NetworkOptionsProps) => { | ||
const { switchChain } = useSwitchChain(); | ||
// const { chain } = useAccount(); | ||
const { resolvedTheme } = useTheme(); | ||
const isDarkMode = resolvedTheme === "dark"; | ||
|
||
const targetNetwork2 = useGlobalState(({ targetNetwork2 }) => targetNetwork2); | ||
|
||
return ( | ||
<> | ||
{ | ||
// allowedNetworks | ||
// .filter(allowedNetwork => allowedNetwork.id !== chain?.id) | ||
// .map(allowedNetwork => ( | ||
<li key={targetNetwork2!.id} className={hidden ? "hidden" : ""}> | ||
<button | ||
className="menu-item btn-sm !rounded-xl flex gap-3 py-3 whitespace-nowrap" | ||
type="button" | ||
onClick={() => { | ||
switchChain?.({ chainId: targetNetwork2!.id }); | ||
}} | ||
> | ||
<ArrowsRightLeftIcon className="h-6 w-4 ml-2 sm:ml-0" /> | ||
<span> | ||
Switch to{" "} | ||
<span | ||
style={{ | ||
color: getNetworkColor(targetNetwork2!, isDarkMode), | ||
}} | ||
> | ||
{targetNetwork2!.name} | ||
</span> | ||
</span> | ||
</button> | ||
</li> | ||
// )) | ||
} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.