import { Card, CardDescription, CardTitle } from "@/components/ui/card" import { ScrollArea } from "@/components/ui/scroll-area" import { Button } from "@/components/ui/button" import { Skeleton } from "@/components/ui/skeleton" import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select" import { ArrowRight, Trash2, KeyRound, GitFork } from "lucide-react" import { useMemo, useState, useEffect } from "react" import { Layout } from "@/components/Layout" import { useParams, useNavigate, Link } from "react-router-dom" import useSWR, { mutate } from "swr" import { cn } from "@/lib/utils" import { rpc } from "@/containers/WalletPopup/api" import { ss58Address } from "@polkadot-labs/hdkd-helpers" import { CreateDeriveFn, ecdsaCreateDerive, ed25519CreateDerive, sr25519CreateDerive, } from "@polkadot-labs/hdkd" import React from "react" import { Header, BottomNavBar } from "../../components" import { useAccounts, useChain } from "../../hooks" import { networks } from "@/constants" import { Pencil, Copy, Check } from 'lucide-react' import { AccountTree, DerivationWithAddress } from "@/background/keystore/types" type Scheme = "Sr25519" | "Ed25519" | "Ecdsa" function truncate(address: string, startChars = 10, endChars = 10): string { if (!address || address.length <= (startChars + endChars)) { return address } const start = address.slice(0, startChars) const end = address.slice(-endChars) return `${start}...${end}` } type DerivationCardProps = React.ComponentProps & { derivation?: DerivationWithAddress | undefined } type AccountCardProps = React.ComponentProps & { accountTree?: AccountTree | undefined } const DerivationCard: React.FC = ({ derivation }) => { const [copied, setCopied] = useState(false) const handleCopy = async (e: React.MouseEvent) => { e.stopPropagation() if (copied || !derivation) return await navigator.clipboard.writeText(derivation.address) setCopied(true) setTimeout(() => setCopied(false), 2000) } return ( {`${derivation?.path ?? ""} ● ${derivation?.name ?? ""}`} handleCopy(e)} > {copied ? "Address copied to clipboard" : truncate(derivation?.address ?? "") } ) } const AccountCard: React.FC = ({ accountTree }) => { const [copied, setCopied] = useState(false) const handleCopy = async (e: React.MouseEvent) => { e.stopPropagation() if (copied || !accountTree) return await navigator.clipboard.writeText(accountTree.address) setCopied(true) setTimeout(() => setCopied(false), 2000) } return (
{accountTree?.name ?? ""} handleCopy(e)} > {copied ? "Address copied to clipboard" : truncate(accountTree?.address ?? "") } {accountTree && accountTree.derivations && (
{accountTree.derivations.map((derivation, j) => { return })}
)}
) } const AccountsSkeleton: React.FC = () => { return new Array(4).fill(null).map((_, i) => (
)) } export const DeleteAccount = () => { const navigate = useNavigate() const { currentChain } = useChain() const { activeAccountName, accountTree, requestPassword, accountsStorageMutate, isFetchingAccountTree, isFetchingAccounts, isFetchingActiveAccounts, } = useAccounts() const { derivation } = useParams<{ derivation?: string }>() const derivationPath = useMemo(() => { return derivation ? decodeURIComponent(derivation) : undefined; }, [derivation]) const isFetching = useMemo(() => { return isFetchingAccountTree || isFetchingAccounts || isFetchingActiveAccounts }, [isFetchingAccountTree, isFetchingAccounts, isFetchingActiveAccounts]) const deleteAccount = async () => { await requestPassword(async (password) => { await rpc.client.removeAccount({ publicKey: accountTree?.publicKey ?? "", path: derivationPath, password, }) }) await accountsStorageMutate() navigate("/accounts") } return (

Delete {derivationPath ? "Derivation" : "Account Tree"}

{isFetching && } {!isFetching && (
{derivationPath ? d.path === derivationPath)} /> : }
)}
) }