Compare commits

..

2 Commits

Author SHA1 Message Date
0ead6bd969
refactor(interfaces): add Wallet related properties in User and Crypto interfaces
The change adds Wallet related properties in both User and Crypto interfaces. Specifically, `IUserWallet` interface has been added to `userdata.interface.ts` and 'amount' field has been added to `IUserWalletCryptos` in `crypto.interface.ts`. Also, an extra type `ICryptoInUserWalletInfo` extending `ICryptoInWalletInfo` has been added with `owned_amount` field.
2024-06-14 10:08:44 +02:00
747cc1cdb4
feat(ui-component): add new copy button component
This commit introduces a new CopyButton component in the ui components. It also includes a feature to copy multiple choices. The button changes its icon after copying to clipboard, indicating that the copying has been done.
2024-06-14 10:07:58 +02:00
3 changed files with 132 additions and 1 deletions

View File

@ -0,0 +1,112 @@
"use client";
import type { DropdownMenuTriggerProps } from "@radix-ui/react-dropdown-menu";
import { CheckIcon, ClipboardIcon } from "lucide-react";
import { Button, type ButtonProps } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { cn } from "@/lib/utils";
import { useCallback, useEffect, useState } from "react";
interface CopyButtonProps extends ButtonProps {
value: string;
src?: string;
event?: Event["NONE"];
}
interface Value {
data: string;
title: string;
}
export async function copyToClipboardWithMeta(value: string) {
await window?.navigator.clipboard.writeText(value);
}
export function CopyButton({
value,
className,
src,
variant = "ghost",
event,
...props
}: CopyButtonProps) {
const [hasCopied, setHasCopied] = useState(false);
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
setTimeout(() => {
setHasCopied(false);
}, 2000);
}, [hasCopied]);
return (
<Button
size="icon"
variant={variant}
className={cn(
"relative z-10 h-6 w-6 text-zinc-50 hover:bg-zinc-700 hover:text-zinc-50 [&_svg]:size-3",
className,
)}
onClick={() => {
copyToClipboardWithMeta(value).then(() => setHasCopied(true));
}}
{...props}
>
<span className="sr-only">Copy</span>
{hasCopied ? <CheckIcon /> : <ClipboardIcon />}
</Button>
);
}
interface CopyMultipleChoiceButtonProps extends DropdownMenuTriggerProps {
values: Value[];
}
export function CopyMultipleChoiceButton({
values,
className,
...props
}: CopyMultipleChoiceButtonProps) {
const [hasCopied, setHasCopied] = useState(false);
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
setTimeout(() => {
setHasCopied(false);
}, 2000);
}, [hasCopied]);
const copyCommand = useCallback((value: string) => {
copyToClipboardWithMeta(value).then(() => setHasCopied(true));
}, []);
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
size="icon"
variant="ghost"
className={cn(
"relative z-10 h-6 w-6 text-zinc-50 hover:bg-zinc-700 hover:text-zinc-50",
className,
)}
>
{hasCopied ? (
<CheckIcon className="h-3 w-3" />
) : (
<ClipboardIcon className="h-3 w-3" />
)}
<span className="sr-only">Copy</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => copyCommand("npm")}>npm</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}

View File

@ -1,5 +1,6 @@
export interface IUserWalletCryptos { export interface IUserWalletCryptos {
Crypto?: ICryptoInWalletInfo; Crypto: ICryptoInWalletInfo;
amount: number;
} }
export interface ICryptoInWalletInfo { export interface ICryptoInWalletInfo {
@ -12,6 +13,10 @@ export interface ICryptoInWalletInfo {
updated_at: string; updated_at: string;
} }
export interface ICryptoInUserWalletInfo extends ICryptoInWalletInfo {
owned_amount: number;
}
export type IAllTrades = ITrade[]; export type IAllTrades = ITrade[];
export interface ITrade { export interface ITrade {

View File

@ -1,3 +1,9 @@
import {
ICryptoInUserWalletInfo,
type ICryptoInWalletInfo,
IUserWalletCryptos,
} from "@/interfaces/crypto.interface";
export interface IUserData { export interface IUserData {
id: string; id: string;
firstName: string; firstName: string;
@ -11,4 +17,12 @@ export interface IUserData {
age: number; age: number;
created_at: string; created_at: string;
updated_at: string; updated_at: string;
//TODO get on register
wallet: IUserWallet;
}
export interface IUserWallet {
uat: number;
update_interval: number;
owned_cryptos: ICryptoInUserWalletInfo[];
} }