diff --git a/batcher-ui/package-lock.json b/batcher-ui/package-lock.json index 35098a51..d536d3a8 100644 --- a/batcher-ui/package-lock.json +++ b/batcher-ui/package-lock.json @@ -18,6 +18,7 @@ "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-radio-group": "^1.1.3", "@radix-ui/react-select": "^1.2.2", + "@radix-ui/react-tooltip": "^1.0.6", "@taquito/beacon-wallet": "^16.0.0", "@taquito/taquito": "^16.0.0", "@taquito/tzip12": "^16.0.0", @@ -1695,6 +1696,40 @@ } } }, + "node_modules/@radix-ui/react-tooltip": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.0.6.tgz", + "integrity": "sha512-DmNFOiwEc2UDigsYj6clJENma58OelxD24O4IODoZ+3sQc3Zb+L8w1EP+y9laTuKCLAysPw4fD6/v0j4KNV8rg==", + "dependencies": { + "@babel/runtime": "^7.13.10", + "@radix-ui/primitive": "1.0.1", + "@radix-ui/react-compose-refs": "1.0.1", + "@radix-ui/react-context": "1.0.1", + "@radix-ui/react-dismissable-layer": "1.0.4", + "@radix-ui/react-id": "1.0.1", + "@radix-ui/react-popper": "1.1.2", + "@radix-ui/react-portal": "1.0.3", + "@radix-ui/react-presence": "1.0.1", + "@radix-ui/react-primitive": "1.0.3", + "@radix-ui/react-slot": "1.0.2", + "@radix-ui/react-use-controllable-state": "1.0.1", + "@radix-ui/react-visually-hidden": "1.0.3" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0", + "react-dom": "^16.8 || ^17.0 || ^18.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-use-callback-ref": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.0.1.tgz", diff --git a/batcher-ui/package.json b/batcher-ui/package.json index 347ea74c..81e4ba89 100644 --- a/batcher-ui/package.json +++ b/batcher-ui/package.json @@ -36,6 +36,7 @@ "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-radio-group": "^1.1.3", "@radix-ui/react-select": "^1.2.2", + "@radix-ui/react-tooltip": "^1.0.6", "@taquito/beacon-wallet": "^16.0.0", "@taquito/taquito": "^16.0.0", "@taquito/tzip12": "^16.0.0", diff --git a/batcher-ui/src/components/Copy.tsx b/batcher-ui/src/components/Copy.tsx new file mode 100644 index 00000000..d7454300 --- /dev/null +++ b/batcher-ui/src/components/Copy.tsx @@ -0,0 +1,47 @@ +import { ReactNode, useEffect, useState } from 'react'; +import Tooltip from './Tooltip'; + +export type copyProps = { + children: ReactNode; + value: string; + disabled?: boolean; + text?: string; +}; + +const Copy = ({ children, value, disabled = false, text }: copyProps) => { + const [isCopying, setIsCopying] = useState(false); + + useEffect(() => { + if (!isCopying) return; + + setTimeout(() => { + setIsCopying(false); + }, 1500); + }); + + return ( + + { + if (disabled) return; + + setIsCopying(true); + + try { + await navigator.clipboard.writeText(value); + } catch (err) { + console.error('Failed to copy: ', err); + } + }} + data-name="copy"> + {children} + + + ); +}; + +export default Copy; diff --git a/batcher-ui/src/components/NavBar.tsx b/batcher-ui/src/components/NavBar.tsx index 626e8569..15e9df34 100644 --- a/batcher-ui/src/components/NavBar.tsx +++ b/batcher-ui/src/components/NavBar.tsx @@ -7,6 +7,7 @@ import Menu from './Menu'; import LinkComponent from './Link'; import { faBars } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import Copy from './Copy'; interface NavBarProps { isMenuOpen: boolean; @@ -46,10 +47,12 @@ const NavBar = ({ isMenuOpen, setIsMenuOpen }: NavBarProps) => {
{userAddress ? ( -

{`${userAddress.substring( - 0, - 3 - )}...${userAddress.substring(userAddress.length - 3)}`}

+ +

{`${userAddress.substring( + 0, + 3 + )}...${userAddress.substring(userAddress.length - 3)}`}

+
) : null}