-
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.
Modifications in menus, new config menu
- Loading branch information
Showing
17 changed files
with
658 additions
and
118 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
128 changes: 128 additions & 0 deletions
128
packages/nextjs/components/punk-society/ConfigMenu/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,128 @@ | ||
import { useRef, useState } from "react"; | ||
import { NetworkOptions } from "./NetworkOptions"; | ||
import { Address } from "viem"; | ||
import { useDisconnect } from "wagmi"; | ||
import { Cog6ToothIcon } from "@heroicons/react/20/solid"; | ||
import { KeyIcon as KeyIconOutline } from "@heroicons/react/24/outline"; | ||
import { | ||
ArrowLeftOnRectangleIcon, | ||
ArrowTopRightOnSquareIcon, | ||
ArrowsRightLeftIcon, | ||
QrCodeIcon, | ||
} from "@heroicons/react/24/outline"; | ||
import { KeyIcon as KeyIconSolid, LanguageIcon } from "@heroicons/react/24/solid"; | ||
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 = ({ blockExplorerAddressLink }: AddressInfoDropdownProps) => { | ||
const [selectingNetwork, setSelectingNetwork] = useState(false); | ||
|
||
const { disconnect } = useDisconnect(); | ||
|
||
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 shadow-none bg-transparent border-0 btn-sm p-2 dropdown-toggle gap-0 !h-auto" | ||
> | ||
<Cog6ToothIcon className="h-5 w-5 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" : ""}> | ||
<label | ||
htmlFor="qrcode-modal" | ||
className="bg-red-600 text-white hover:bg-red-500 active:bg-red-500 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 your address</span> | ||
</label> | ||
</li> | ||
<li className={selectingNetwork ? "hidden" : ""}> | ||
<label | ||
htmlFor="private-key-modal" | ||
className="btn-sm bg-red-600 text-white hover:bg-red-500 active:bg-red-500 !rounded-xl flex gap-3 py-3" | ||
> | ||
<KeyIconOutline className="h-6 w-4 ml-2 sm:ml-0" /> | ||
<span className="whitespace-nowrap">View Private Key</span> | ||
</label> | ||
</li> | ||
|
||
<li className={selectingNetwork ? "hidden" : ""}> | ||
<label | ||
htmlFor="load-private-key-modal" | ||
className="btn-sm bg-red-600 text-white hover:bg-red-500 active:bg-red-500 !rounded-xl flex gap-3 py-3" | ||
> | ||
<KeyIconSolid className="h-6 w-4 ml-2 sm:ml-0" /> | ||
<span className="whitespace-nowrap">Load Private Key</span> | ||
</label> | ||
</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-4 w-4 ml-2 sm:ml-0" /> <span>Switch Network</span> | ||
</button> | ||
</li> | ||
) : null} | ||
<li className={selectingNetwork ? "hidden" : ""}> | ||
<label htmlFor="switch-language-modal" className="btn-sm !rounded-xl flex gap-3 py-3"> | ||
<LanguageIcon className="h-6 w-4 ml-2 sm:ml-0" /> | ||
<span className="whitespace-nowrap">Switch languages</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> | ||
|
||
<li className={selectingNetwork ? "hidden" : ""}> | ||
<button | ||
className="menu-item text-red-600 dark:text-red-500 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> | ||
</> | ||
); | ||
}; |
50 changes: 50 additions & 0 deletions
50
packages/nextjs/components/punk-society/ConfigMenu/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,50 @@ | ||
import React, { useState } from "react"; | ||
import { QRCodeSVG } from "qrcode.react"; | ||
import { CopyToClipboard } from "react-copy-to-clipboard"; | ||
import { Address as AddressType } from "viem"; | ||
import { notification } from "~~/utils/scaffold-eth"; | ||
|
||
type AddressQRCodeModalProps = { | ||
address: AddressType; | ||
modalId: string; | ||
}; | ||
|
||
export const AddressQRCodeModal = ({ address, modalId }: AddressQRCodeModalProps) => { | ||
const [copied, setCopied] = useState(false); | ||
|
||
const handleCopy = () => { | ||
setCopied(true); | ||
notification.success("Address copied to clipboard"); | ||
setTimeout(() => setCopied(false), 2000); // Reset copied state after 2 seconds | ||
}; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<input type="checkbox" id={`${modalId}`} className="modal-toggle" /> | ||
<label htmlFor={`${modalId}`} className="modal cursor-pointer"> | ||
<label className="modal-box relative"> | ||
<div className="flex flex-col justify-center items-center text-center"> | ||
<h2 className="text-xl font-bold mb-4">Your Address</h2> | ||
<div className="bg-white p-4 rounded-lg shadow-lg mb-4"> | ||
<QRCodeSVG value={address} size={256} /> | ||
</div> | ||
<div className="break-words whitespace-pre-wrap text-center w-full">{address}</div> | ||
<CopyToClipboard text={address} onCopy={handleCopy}> | ||
<button className="btn btn-primary bg-green-600 hover:bg-green-500 active:bg-green-500 mt-4"> | ||
{copied ? "Copied!" : "Copy Address"} | ||
</button> | ||
</CopyToClipboard> | ||
<label | ||
htmlFor={`${modalId}`} | ||
className="btn text-xl rounded-full bg-red-600 hover:bg-red-500 btn-ghost btn-sm btn-circle absolute right-3 top-3" | ||
> | ||
✕ | ||
</label> | ||
</div> | ||
</label> | ||
</label> | ||
</div> | ||
</> | ||
); | ||
}; |
74 changes: 74 additions & 0 deletions
74
packages/nextjs/components/punk-society/ConfigMenu/Balance.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,74 @@ | ||
"use client"; | ||
|
||
import { Address, formatEther } from "viem"; | ||
import { useDisplayUsdMode } from "~~/hooks/scaffold-eth/useDisplayUsdMode"; | ||
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork"; | ||
import { useWatchBalance } from "~~/hooks/scaffold-eth/useWatchBalance"; | ||
import { useGlobalState } from "~~/services/store/store"; | ||
|
||
type BalanceProps = { | ||
address?: Address; | ||
className?: string; | ||
usdMode?: boolean; | ||
}; | ||
|
||
/** | ||
* Display (ETH & USD) balance of an ETH address. | ||
*/ | ||
export const Balance = ({ address, className = "", usdMode }: BalanceProps) => { | ||
const { targetNetwork } = useTargetNetwork(); | ||
const nativeCurrencyPrice = useGlobalState(state => state.nativeCurrency.price); | ||
const isNativeCurrencyPriceFetching = useGlobalState(state => state.nativeCurrency.isFetching); | ||
|
||
const { | ||
data: balance, | ||
isError, | ||
isLoading, | ||
} = useWatchBalance({ | ||
address, | ||
}); | ||
|
||
const { displayUsdMode, toggleDisplayUsdMode } = useDisplayUsdMode({ defaultUsdMode: usdMode }); | ||
|
||
if (!address || isLoading || balance === null || (isNativeCurrencyPriceFetching && nativeCurrencyPrice === 0)) { | ||
return ( | ||
<div className="animate-pulse flex space-x-4"> | ||
<div className="rounded-md bg-slate-300 h-6 w-6"></div> | ||
<div className="flex items-center space-y-6"> | ||
<div className="h-2 w-28 bg-slate-300 rounded"></div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
if (isError) { | ||
return ( | ||
<div className={`border-2 border-gray-400 rounded-md px-2 flex flex-col items-center max-w-fit cursor-pointer`}> | ||
<div className="text-warning">Error</div> | ||
</div> | ||
); | ||
} | ||
|
||
const formattedBalance = balance ? Number(formatEther(balance.value)) : 0; | ||
|
||
return ( | ||
<button | ||
className={`btn btn-sm btn-ghost flex flex-col font-normal items-center hover:bg-transparent ${className}`} | ||
onClick={toggleDisplayUsdMode} | ||
> | ||
<div className="w-full flex items-center justify-center"> | ||
{displayUsdMode ? ( | ||
<> | ||
<span className="text-[0.8em] font-bold mr-1">$</span> | ||
<span>{(formattedBalance * nativeCurrencyPrice).toFixed(2)}</span> | ||
</> | ||
) : ( | ||
<> | ||
<span>{formattedBalance.toFixed(4)}</span> | ||
<span className="text-[0.8em] font-bold ml-1">{targetNetwork.nativeCurrency.symbol}</span> | ||
</> | ||
)} | ||
</div> | ||
</button> | ||
); | ||
}; |
Oops, something went wrong.