Skip to content

Commit

Permalink
fix: UI and add toast for address copy (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenlejoe authored Feb 28, 2024
1 parent b61e491 commit 0e81fd7
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/components/Atoms/Address/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
import { copyToClipboard, truncate } from "@/utils/functions";
import { IconWrapper } from "@/components/Shared";
import { type AddressProps } from "@/utils/types/atoms.types";
import { toast } from "@/utils/hooks/use-toast";
import { useState } from "react";

export const Address: React.FC<AddressProps> = ({ address }) => {
const [showCopy, setShowCopy] = useState(false);

const handleCopyClick = () => {
toast({
description: "Address copied!",
});
setShowCopy(true);
setTimeout(() => {
setShowCopy(false);
}, 3000);
};

return (
<div className="flex items-center gap-x-2">
<p>{truncate(address)}</p>
<button
className="cursor-pointer"
onClick={() => copyToClipboard(address)}
onClick={() => {
copyToClipboard(address);
}}
>
<IconWrapper
icon_class_name="content_copy"
icon_size="text-sm"
class_name="text-secondary dark:text-secondary"
/>
{showCopy ? (
<IconWrapper
icon_class_name="done"
icon_size="text-sm"
class_name="text-secondary dark:text-secondary"
/>
) : (
<IconWrapper
icon_class_name="content_copy"
icon_size="text-sm"
class_name="text-secondary dark:text-secondary"
on_click={() => handleCopyClick()}
/>
)}
</button>
</div>
);
Expand Down

0 comments on commit 0e81fd7

Please sign in to comment.