diff --git a/src/components/layout.tsx b/src/components/layout.tsx index 78fbbe82..6e55cdb6 100644 --- a/src/components/layout.tsx +++ b/src/components/layout.tsx @@ -8,6 +8,7 @@ import { useLiveQuery } from 'dexie-react-hooks' import { db, Treasury } from '../db' import { useRouter } from 'next/router' import Image from 'next/image' +import { getTreasuriesPath } from '../route' const Toggle: NextPage<{ isOn: boolean @@ -31,6 +32,49 @@ const Panel: NextPage<{ className?: string }> = ({ children, className }) => { ) } +const CopyButton: NextPage<{ + disabled?: boolean + className?: string + getContent: () => string + ms?: number +}> = ({ children, className, disabled, getContent, ms }) => { + const [isCopied, setIsCopied] = useState(false) + + const clickHandle = () => { + navigator.clipboard.writeText(getContent()) + setIsCopied(true) + } + + useEffect(() => { + let isMounted = true + + const timer = setTimeout(() => { + if (isMounted && isCopied) setIsCopied(false) + }, ms) + + return () => { + isMounted = false + clearTimeout(timer) + } + }, [isCopied, ms]) + + return ( + + ) +} + +const ShareCurrentURLButton: NextPage<{ + className?: string +}> = ({ children, className }) => { + return ( + document.location.href} ms={500}> + {children} + + ) +} + const BackButton: NextPage<{ className?: string }> = ({ children, className }) => { @@ -100,7 +144,7 @@ const TreasuryListing: NextPage<{ const { name, script } = treasury return ( {name} @@ -127,6 +171,17 @@ const SecondaryBar: NextPage = () => { ) } +const CardanoScanLink: NextPage<{ + className?: string + type: 'transaction' + id: string +}> = ({ className, children, type, id }) => { + const [config, _] = useContext(ConfigContext) + const host = config.isMainnet ? 'https://cardanoscan.io' : 'https://testnet.cardanoscan.io' + const href = [host, type, id].join('/') + return {children}; +} + const Hero: NextPage<{ className?: string }> = ({ className, children }) => { return
{children}
; } @@ -151,4 +206,4 @@ const Layout: NextPage = ({ children }) => { ) } -export { Layout, Panel, Toggle, Hero, BackButton } +export { Layout, Panel, Toggle, Hero, BackButton, CardanoScanLink, CopyButton, ShareCurrentURLButton } diff --git a/src/components/transaction.tsx b/src/components/transaction.tsx index 762197ac..ed01566d 100644 --- a/src/components/transaction.tsx +++ b/src/components/transaction.tsx @@ -5,10 +5,10 @@ import { Cardano, encodeCardanoData, getResult, toHex, toIter } from '../cardano import type { Result } from '../cardano/serialization-lib' import type { Address, NativeScript, NativeScripts, Transaction, TransactionBody, TransactionHash, TransactionOutput, Vkeywitness } from '@adaocommunity/cardano-serialization-lib-browser' import { nanoid } from 'nanoid' -import { ArrowRightIcon, CheckIcon, DuplicateIcon, PlusIcon, TrashIcon, XIcon } from '@heroicons/react/solid' +import { CheckIcon, DuplicateIcon, PlusIcon, SearchIcon, TrashIcon, XIcon } from '@heroicons/react/solid' import Link from 'next/link' import { Config, ConfigContext } from '../cardano/config' -import { BackButton, Panel, Toggle } from './layout' +import { BackButton, CardanoScanLink, CopyButton, Panel, Toggle } from './layout' import { NextPage } from 'next' import { NotificationContext } from './notification' import Image from 'next/image' @@ -17,6 +17,7 @@ import Gun from 'gun' import type { IGunInstance } from 'gun' import { useRouter } from 'next/router' import { useLiveQuery } from 'dexie-react-hooks' +import { getTreasuriesPath, getTreasuryPath } from '../route' type Recipient = { id: string @@ -54,22 +55,66 @@ const LabeledCurrencyInput: NextPage<{ } return ( -