-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from bhavyagosai/page/account-details
Account Details Page
- Loading branch information
Showing
18 changed files
with
290 additions
and
71 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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
const AddressPage = ({ params: { address } }: { params: { address: string } }) => ( | ||
<h1>{address}</h1> | ||
); | ||
|
||
export default AddressPage; | ||
|
||
import AddressComponent from "@/components/pages/address"; | ||
import { Address } from "viem"; | ||
|
||
const AddressPage = ({ | ||
params: { address }, | ||
}: { | ||
params: { address: Address }; | ||
}) => <AddressComponent address={address} />; | ||
|
||
export default AddressPage; |
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,35 @@ | ||
"use client"; | ||
|
||
import { CommonTooltip } from "@/components/common/tooltip"; | ||
import { Copy, Check } from "lucide-react"; | ||
import React, { useState } from "react"; | ||
|
||
export function CopyButton({ toCopy }: { toCopy: string }) { | ||
const [copied, setCopied] = useState(false); // State to manage copy status | ||
|
||
const copyAddress = () => { | ||
navigator.clipboard | ||
.writeText(toCopy) | ||
.then(() => { | ||
setCopied(true); // Set copied state to true | ||
setTimeout(() => setCopied(false), 1000); // Revert back after 1 second | ||
}) | ||
.catch((err) => console.error("Failed to copy address: ", err)); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{copied ? ( | ||
<Check size={16} className="ml-4 text-green-500" /> | ||
) : ( | ||
<CommonTooltip tooltipMessage="Copy Address" asChild> | ||
<Copy | ||
size={16} | ||
className="ml-4 cursor-pointer" | ||
onClick={copyAddress} | ||
/> | ||
</CommonTooltip> | ||
)} | ||
</div> | ||
); | ||
} |
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 @@ | ||
export * from "./copy-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,57 @@ | ||
"use client"; | ||
|
||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger, | ||
} from "@/components/ui/tooltip"; | ||
import { ReactNode, useRef } from "react"; | ||
|
||
type Props = { | ||
className?: string; | ||
tooltipClassName?: string; | ||
children: ReactNode; | ||
tooltipMessage: ReactNode; | ||
asChild?: boolean; | ||
hideOnClick?: boolean; | ||
delayDuration?: number; | ||
}; | ||
|
||
export function CommonTooltip(props: Props) { | ||
const { | ||
className, | ||
children, | ||
tooltipMessage, | ||
asChild, | ||
hideOnClick = true, | ||
tooltipClassName, | ||
delayDuration = 0, | ||
} = props; | ||
const triggerRef = useRef(null); | ||
return ( | ||
<TooltipProvider> | ||
<Tooltip delayDuration={delayDuration}> | ||
<TooltipTrigger | ||
className={className} | ||
asChild={asChild} | ||
onClick={(event) => { | ||
if (!hideOnClick) event.preventDefault(); | ||
}} | ||
ref={triggerRef} | ||
> | ||
{children} | ||
</TooltipTrigger> | ||
<TooltipContent | ||
className={tooltipClassName} | ||
onPointerDownOutside={(event) => { | ||
if (event.target === triggerRef.current && !hideOnClick) | ||
event.preventDefault(); | ||
}} | ||
> | ||
{tooltipMessage} | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
} |
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 @@ | ||
export * from "./common-tooltip"; |
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,44 @@ | ||
import DescriptionListItem from "@/components/lib/description-list-item"; | ||
import EthereumIcon from "@/components/lib/ethereum-icon"; | ||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||
import { AddressDetails } from "@/lib/types"; | ||
import { formatEther } from "viem"; | ||
|
||
const AddressDetailsSection = ({ | ||
address, | ||
ethPriceToday, | ||
}: { | ||
address: AddressDetails; | ||
ethPriceToday: number; | ||
}) => ( | ||
<Card> | ||
<CardHeader className="p-4"> | ||
<CardTitle>Overview</CardTitle> | ||
</CardHeader> | ||
|
||
<CardContent> | ||
<dl> | ||
<DescriptionListItem secondary title="ETH BALANCE"> | ||
<EthereumIcon className="mr-1 size-4" /> | ||
{formatEther(address.balance)} ETH | ||
</DescriptionListItem> | ||
<DescriptionListItem secondary title="ETH VALUE"> | ||
{( | ||
Number(formatEther(address.balance)) * ethPriceToday | ||
).toLocaleString("en-US", { | ||
style: "currency", | ||
currency: "USD", | ||
})}{" "} | ||
(@{" "} | ||
{ethPriceToday.toLocaleString("en-US", { | ||
style: "currency", | ||
currency: "USD", | ||
})} | ||
/ETH) | ||
</DescriptionListItem> | ||
</dl> | ||
</CardContent> | ||
</Card> | ||
); | ||
|
||
export default AddressDetailsSection; |
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,31 @@ | ||
import { Address } from "viem"; | ||
import { l2PublicClient } from "@/lib/chains"; | ||
import AddressDetails from "./address-details"; | ||
import { fetchTokensPrices } from "@/lib/utils"; | ||
import { CopyButton } from "@/components/common/copy-button"; | ||
|
||
const AddressComponent = async ({ address }: { address: Address }) => { | ||
const ethPrice = await fetchTokensPrices(); | ||
const byteCode = await l2PublicClient.getCode({ address }); | ||
const balance = await l2PublicClient.getBalance({ address }); | ||
|
||
const addressType = byteCode ? "Contract" : "Address"; | ||
|
||
return ( | ||
<main className="flex flex-1 flex-col gap-4 p-4 md:gap-4 md:p-4"> | ||
<h2 className="mt-10 flex scroll-m-20 items-end border-b pb-2 text-3xl font-semibold tracking-tight transition-colors first:mt-0"> | ||
{addressType} | ||
<span className="ml-2 flex items-center text-base"> | ||
{address} | ||
<CopyButton toCopy={address} /> | ||
</span> | ||
</h2> | ||
<AddressDetails | ||
address={{ addressType, balance }} | ||
ethPriceToday={ethPrice.eth.today} | ||
/> | ||
</main> | ||
); | ||
}; | ||
|
||
export default AddressComponent; |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from './useSearch'; | ||
export * from "./useSearch"; |
Oops, something went wrong.