From bea405e98b94fd2ef477109cb270d069345cb4ac Mon Sep 17 00:00:00 2001 From: siegfried Date: Wed, 6 Apr 2022 06:20:33 +0800 Subject: [PATCH] Tx create UI improvement (#53) * Extract AddAssetButton * Add placeholder to transaction message * Style tx creating form * Extract path methods * Fix address input padding * Improve NativeScriptInfoViewer * Remove unused import * Add ShareCurrentURLButton * Apply CopyButton to CopyVkeysButton * Improve validation * Add more tips * Split input and output * Remove warning * Use CopyButton * Remove CopyToClipboardButton * Add CardanoScanLink --- src/components/layout.tsx | 59 ++++++- src/components/transaction.tsx | 166 +++++++++++--------- src/pages/transactions/[base64CBOR].tsx | 26 ++- src/pages/treasuries/[base64CBOR]/index.tsx | 10 +- src/pages/treasuries/[base64CBOR]/new.tsx | 21 +-- src/pages/treasuries/new.tsx | 2 +- src/route.ts | 13 ++ 7 files changed, 188 insertions(+), 109 deletions(-) create mode 100644 src/route.ts 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 ( -