From a62017176ae7bb930222b226aab00584de0160b5 Mon Sep 17 00:00:00 2001 From: Evan Gray Date: Mon, 20 Sep 2021 21:29:11 -0400 Subject: [PATCH] bridge_ui: improve NFTViewer Change-Id: I576441d6516f2a45bd86586369b3b83b71194df4 --- bridge_ui/package-lock.json | 5 +- bridge_ui/package.json | 1 + .../src/components/NFT/SourcePreview.tsx | 2 +- bridge_ui/src/components/SmartAddress.tsx | 37 +-- .../EthereumSourceTokenSelector.tsx | 16 +- .../components/TokenSelectors/NFTViewer.tsx | 218 +++++++++++++++--- .../SolanaSourceTokenSelector.tsx | 5 +- bridge_ui/src/hooks/useCopyToClipboard.ts | 12 + .../hooks/useGetSourceParsedTokenAccounts.ts | 12 +- bridge_ui/src/icons/eth.svg | 13 ++ bridge_ui/src/icons/solana.svg | 16 ++ bridge_ui/src/store/nftSlice.ts | 3 +- bridge_ui/src/utils/ethereum.ts | 9 +- bridge_ui/src/utils/pushToClipboard.ts | 7 + 14 files changed, 289 insertions(+), 67 deletions(-) create mode 100644 bridge_ui/src/hooks/useCopyToClipboard.ts create mode 100644 bridge_ui/src/icons/eth.svg create mode 100644 bridge_ui/src/icons/solana.svg create mode 100644 bridge_ui/src/utils/pushToClipboard.ts diff --git a/bridge_ui/package-lock.json b/bridge_ui/package-lock.json index 347a709f..900d012e 100644 --- a/bridge_ui/package-lock.json +++ b/bridge_ui/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "test_ui", "version": "0.1.0", - "hasInstallScript": true, "dependencies": { "@certusone/wormhole-sdk": "file:..\\sdk\\js", "@material-ui/core": "^4.12.2", @@ -36,6 +35,7 @@ "bn.js": "^5.1.3", "borsh": "^0.4.0", "bs58": "^4.0.1", + "clsx": "^1.1.1", "ethers": "^5.4.1", "js-base64": "^3.6.1", "notistack": "^1.0.10", @@ -58,7 +58,8 @@ } }, "../sdk/js": { - "version": "0.0.2", + "name": "@certusone/wormhole-sdk", + "version": "0.0.4", "license": "Apache-2.0", "dependencies": { "@improbable-eng/grpc-web": "^0.14.0", diff --git a/bridge_ui/package.json b/bridge_ui/package.json index f0b58db4..99b56aa8 100644 --- a/bridge_ui/package.json +++ b/bridge_ui/package.json @@ -30,6 +30,7 @@ "bn.js": "^5.1.3", "borsh": "^0.4.0", "bs58": "^4.0.1", + "clsx": "^1.1.1", "ethers": "^5.4.1", "js-base64": "^3.6.1", "notistack": "^1.0.10", diff --git a/bridge_ui/src/components/NFT/SourcePreview.tsx b/bridge_ui/src/components/NFT/SourcePreview.tsx index 7ac099f6..7742f80b 100644 --- a/bridge_ui/src/components/NFT/SourcePreview.tsx +++ b/bridge_ui/src/components/NFT/SourcePreview.tsx @@ -50,7 +50,7 @@ export default function SourcePreview() { {explainerContent} {sourceParsedTokenAccount ? ( - + ) : null} ); diff --git a/bridge_ui/src/components/SmartAddress.tsx b/bridge_ui/src/components/SmartAddress.tsx index 23536d01..da209991 100644 --- a/bridge_ui/src/components/SmartAddress.tsx +++ b/bridge_ui/src/components/SmartAddress.tsx @@ -4,13 +4,13 @@ import { CHAIN_ID_SOLANA, } from "@certusone/wormhole-sdk"; import { Button, makeStyles, Tooltip, Typography } from "@material-ui/core"; +import { FileCopy, OpenInNew } from "@material-ui/icons"; import { withStyles } from "@material-ui/styles"; -import { useSnackbar } from "notistack"; -import { useCallback } from "react"; +import clsx from "clsx"; +import useCopyToClipboard from "../hooks/useCopyToClipboard"; import { ParsedTokenAccount } from "../store/transferSlice"; import { CLUSTER } from "../utils/consts"; import { shortenAddress } from "../utils/solana"; -import { FileCopy, OpenInNew } from "@material-ui/icons"; const useStyles = makeStyles((theme) => ({ mainTypog: { @@ -20,20 +20,19 @@ const useStyles = makeStyles((theme) => ({ textDecoration: "underline", textUnderlineOffset: "2px", }, + noGutter: { + marginLeft: 0, + marginRight: 0, + }, + noUnderline: { + textDecoration: "none", + }, buttons: { marginLeft: ".5rem", marginRight: ".5rem", }, })); -function pushToClipboard(content: any) { - if (!navigator.clipboard) { - // Clipboard API not available - return; - } - return navigator.clipboard.writeText(content); -} - const tooltipStyles = { tooltip: { minWidth: "max-content", @@ -54,6 +53,8 @@ export default function SmartAddress({ symbol, tokenName, variant, + noGutter, + noUnderline, }: { chainId: ChainId; parsedTokenAccount?: ParsedTokenAccount; @@ -62,13 +63,14 @@ export default function SmartAddress({ tokenName?: string; symbol?: string; variant?: any; + noGutter?: boolean; + noUnderline?: boolean; }) { const classes = useStyles(); const useableAddress = parsedTokenAccount?.mintKey || address || ""; const useableSymbol = parsedTokenAccount?.symbol || symbol || ""; const isNative = parsedTokenAccount?.isNativeAsset || false; const addressShort = shortenAddress(useableAddress) || ""; - const { enqueueSnackbar } = useSnackbar(); const useableName = isNative ? "Native Currency" @@ -95,11 +97,7 @@ export default function SmartAddress({ : undefined; const explorerName = chainId === CHAIN_ID_ETH ? "Etherscan" : "Explorer"; - const copyToClipboard = useCallback(() => { - pushToClipboard(useableAddress)?.then(() => { - enqueueSnackbar("Copied address to clipboard.", { variant: "success" }); - }); - }, [useableAddress, enqueueSnackbar]); + const copyToClipboard = useCopyToClipboard(useableAddress); const explorerButton = !explorerAddress ? null : (