From d2ad317b8930af366612bd291101d25671f90314 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Mon, 28 Jun 2021 17:48:25 +0100 Subject: [PATCH] Copy abi and bytecode. --- .../copy-to-clipboard/copy-to-clipboard.tsx | 21 ++++++-- .../src/lib/contract-selection.tsx | 48 ++++++++++--------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/libs/remix-ui/clipboard/src/lib/copy-to-clipboard/copy-to-clipboard.tsx b/libs/remix-ui/clipboard/src/lib/copy-to-clipboard/copy-to-clipboard.tsx index 1f1a54d946..775f68b0d9 100644 --- a/libs/remix-ui/clipboard/src/lib/copy-to-clipboard/copy-to-clipboard.tsx +++ b/libs/remix-ui/clipboard/src/lib/copy-to-clipboard/copy-to-clipboard.tsx @@ -1,10 +1,21 @@ import React, { useState } from 'react' import copy from 'copy-to-clipboard' import { OverlayTrigger, Tooltip } from 'react-bootstrap' +import { Placement } from 'react-bootstrap/esm/Overlay' import './copy-to-clipboard.css' -export const CopyToClipboard = ({ content, tip = 'Copy', icon = 'fa-copy', direction = 'right', ...otherProps }) => { +interface ICopyToClipboard { + content: any, + tip?: string, + icon?: string, + direction?: Placement, + className?: string, + title?: string, + children?: JSX.Element +} +export const CopyToClipboard = (props: ICopyToClipboard) => { + let { content, tip = 'Copy', icon = 'fa-copy', direction = 'right', children, ...otherProps } = props const [message, setMessage] = useState(tip) const handleClick = (e) => { if (content && content !== '') { // module `copy` keeps last copied thing in the memory, so don't show tooltip if nothing is copied, because nothing was added to memory @@ -35,9 +46,11 @@ export const CopyToClipboard = ({ content, tip = 'Copy', icon = 'fa-copy', direc { message } }> - + { + children || () + } ) diff --git a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx index 75342f0556..eb13797beb 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx @@ -42,23 +42,23 @@ export const ContractSelection = (props: ContractSelectionProps) => { } const copyABI = () => { - copyContractProperty('abi') + return copyContractProperty('abi') } const copyContractProperty = (property) => { let content = getContractProperty(property) - // if (!content) { - // addTooltip('No content available for ' + property) - // return - // } - - // try { - // if (typeof content !== 'string') { - // content = JSON.stringify(content, null, '\t') - // } - // } catch (e) {} - - // copy(content) + if (!content) { + // addTooltip('No content available for ' + property) + return + } + + try { + if (typeof content !== 'string') { + content = JSON.stringify(content, null, '\t') + } + } catch (e) {} + + return content // addTooltip('Copied value to clipboard') } @@ -180,7 +180,7 @@ export const ContractSelection = (props: ContractSelectionProps) => { } const copyBytecode = () => { - copyContractProperty('bytecode') + return copyContractProperty('bytecode') } return ( @@ -211,14 +211,18 @@ export const ContractSelection = (props: ContractSelectionProps) => {
- - + + + + + +