diff --git a/src/app/execution/txLogger.js b/src/app/execution/txLogger.js index d7a5230e31..349ad50950 100644 --- a/src/app/execution/txLogger.js +++ b/src/app/execution/txLogger.js @@ -1,6 +1,6 @@ 'use strict' var yo = require('yo-yo') -const copy = require('clipboard-copy') +var copyToClipboard = require('../ui/copy-to-clipboard') // -------------- styling ---------------------- var csjs = require('csjs-inject') @@ -55,14 +55,6 @@ var css = csjs` margin-left: 5px; cursor: pointer; } - .clipboardCopy { - margin-left: 5px; - cursor: pointer; - color: ${styles.terminal.icon_Color_CopyToClipboard}; - } - .clipboardCopy:hover { - color: ${styles.terminal.icon_HoverColor_CopyToClipboard}; - } ` /** * This just export a function that register to `newTransaction` and forward them to the logger. @@ -324,22 +316,26 @@ function createTable (opts) { status ${opts.status}${msg} - `) + `) } var contractAddress = yo` contractAddress - ${opts.contractAddress} - + ${opts.contractAddress} + ${copyToClipboard(() => opts.contractAddress)} + + ` if (opts.contractAddress) table.appendChild(contractAddress) var from = yo` from - ${opts.from} - + ${opts.from} + ${copyToClipboard(() => opts.from)} + + ` if (opts.from) table.appendChild(from) @@ -353,16 +349,20 @@ function createTable (opts) { var to = yo` to - ${toHash} - + ${toHash} + ${copyToClipboard(() => data.to ? data.to : toHash)} + + ` if (opts.to) table.appendChild(to) var gas = yo` gas - ${opts.gas} gas - + ${opts.gas} gas + ${copyToClipboard(() => opts.gas)} + + ` if (opts.gas) table.appendChild(gas) @@ -374,31 +374,39 @@ function createTable (opts) { table.appendChild(yo` transaction cost - ${opts.transactionCost} gas ${callWarning} - `) + ${opts.transactionCost} gas ${callWarning} + ${copyToClipboard(() => opts.transactionCost)} + + `) } if (opts.executionCost) { table.appendChild(yo` execution cost - ${opts.executionCost} gas ${callWarning} - `) + ${opts.executionCost} gas ${callWarning} + ${copyToClipboard(() => opts.executionCost)} + + `) } var hash = yo` hash - ${opts.hash} - + ${opts.hash} + ${copyToClipboard(() => opts.hash)} + + ` if (opts.hash) table.appendChild(hash) var input = yo` input - ${opts.input} - + ${opts.input} + ${copyToClipboard(() => opts.input)} + + ` if (opts.input) table.appendChild(input) @@ -406,8 +414,10 @@ function createTable (opts) { var inputDecoded = yo` decoded input - ${opts['decoded input']} - ` + ${opts['decoded input']} + ${copyToClipboard(opts['decoded input'])} + + ` table.appendChild(inputDecoded) } @@ -416,7 +426,7 @@ function createTable (opts) { decoded output ${opts['decoded output']} - ` + ` table.appendChild(outputDecoded) } @@ -428,10 +438,11 @@ function createTable (opts) { logs - ${JSON.stringify(stringified, null, '\t')} - - - + ${JSON.stringify(stringified, null, '\t')} + ${copyToClipboard(() => JSON.stringify(stringified, null, '\t'))} + ${copyToClipboard(() => JSON.stringify(opts.logs.raw || '0'))} + + ` if (opts.logs) table.appendChild(logs) @@ -439,8 +450,10 @@ function createTable (opts) { val = yo` value - ${val} wei - + ${val} wei + ${copyToClipboard(() => `${val} wei`)} + + ` if (opts.val) table.appendChild(val) diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 85bdda7075..c3fc5edaee 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -2,13 +2,13 @@ var $ = require('jquery') var yo = require('yo-yo') -const copy = require('clipboard-copy') var parseContracts = require('../contract/contractParser') var publishOnSwarm = require('../contract/publishOnSwarm') var modalDialog = require('../ui/modaldialog') var modalDialogCustom = require('../ui/modal-dialog-custom') var TreeView = require('remix-debugger').ui.TreeView +var copyToClipboard = require('../ui/copy-to-clipboard') // -------------- styling ---------------------- var csjs = require('csjs-inject') @@ -96,6 +96,7 @@ var css = csjs` display: flex; flex-direction: column; margin-bottom: 5%; + overflow: visible; } .key { margin-right: 5px; @@ -108,13 +109,11 @@ var css = csjs` width: 100%; margin-top: 1.5%; } - .copyDetails, .questionMark { margin-left: 2%; cursor: pointer; color: ${styles.rightPanel.icon_Color_TogglePanel}; } - .copyDetails:hover, .questionMark:hover { color: ${styles.rightPanel.icon_HoverColor_TogglePanel}; } @@ -357,12 +356,15 @@ function compileTab (container, appAPI, appEvents, opts) { function details () { var select = el.querySelector('select') + if (select.children.length > 0 && select.selectedIndex >= 0) { var contractName = select.children[select.selectedIndex].innerHTML var contractProperties = contractsDetails[contractName] var log = yo`
` Object.keys(contractProperties).map(propertyName => { - var copyDetails = yo` { copy(contractProperties[propertyName]) }} aria-hidden="true">` + var copyDetails = yo` + ${copyToClipboard(() => contractProperties[propertyName])} + ` var questionMark = yo`` log.appendChild(yo`
diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 05a284d940..bde85668d8 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -7,7 +7,7 @@ var txFormat = require('../execution/txFormat') var txHelper = require('../execution/txHelper') var modalDialogCustom = require('../ui/modal-dialog-custom') var executionContext = require('../../execution-context') -const copy = require('clipboard-copy') +var copyToClipboard = require('../ui/copy-to-clipboard') // -------------- styling ---------------------- var csjs = require('csjs-inject') @@ -29,6 +29,7 @@ var css = csjs` .crow { margin-top: .5em; display: flex; + align-items: center; } .col1 { width: 30%; @@ -60,15 +61,6 @@ var css = csjs` font-weight: normal; min-width: 150px; } - .copyaddress { - margin-left: 0.5em; - margin-top: 0.7em; - cursor: pointer; - color: ${styles.rightPanel.runTab.icon_Color_Instance_CopyToClipboard}; - } - .copyaddress:hover { - color: ${styles.rightPanel.runTab.icon_HoverColor_Instance_CopyToClipboard}; - } .instanceContainer { ${styles.rightPanel.runTab.box_Instance} display: flex; @@ -374,11 +366,6 @@ function contractDropdown (appAPI, appEvents, instanceContainer) { section SETTINGS: Environment, Account, Gas, Value ------------------------------------------------ */ function settings (appAPI, appEvents) { - // COPY ADDRESS - function copyAddress () { - copy(document.querySelector('#runTabView #txorigin').value) - } - // SETTINGS HTML var el = yo`
@@ -411,7 +398,7 @@ function settings (appAPI, appEvents) {
Account
- + ${copyToClipboard(() => document.querySelector('#runTabView #txorigin').value)}
Gas limit
diff --git a/src/app/ui/copy-to-clipboard.js b/src/app/ui/copy-to-clipboard.js new file mode 100644 index 0000000000..435f956489 --- /dev/null +++ b/src/app/ui/copy-to-clipboard.js @@ -0,0 +1,32 @@ +var yo = require('yo-yo') +// -------------- copyToClipboard ---------------------- +const copy = require('clipboard-copy') +var addTooltip = require('./tooltip') +// -------------- styling ---------------------- +var csjs = require('csjs-inject') +var remixLib = require('remix-lib') +var styleGuide = remixLib.ui.styleGuide +var styles = styleGuide() + +var css = csjs` + .copyIcon { + margin-left: 5px; + cursor: pointer; + } +` + +module.exports = function copyToClipboard (getContent) { + var copyIcon = yo`` + copyIcon.style.color = styles.remix.icon_Color_CopyToClipboard + copyIcon.onmouseenter = function (event) { copyIcon.style.color = styles.remix.icon_HoverColor_CopyToClipboard } + copyIcon.onmouseleave = function (event) { copyIcon.style.color = styles.remix.icon_Color_CopyToClipboard } + copyIcon.onclick = (event) => { + event.stopPropagation() + var copiableContent = getContent() + if (copiableContent) { // module `copy` keeps last copied thing in the memory, so don't show tooltip if nothing is copied, because nothing was added to memory + copy(copiableContent) + addTooltip(event) + } + } + return copyIcon +} diff --git a/src/app/ui/tooltip.js b/src/app/ui/tooltip.js new file mode 100644 index 0000000000..dcba10aba9 --- /dev/null +++ b/src/app/ui/tooltip.js @@ -0,0 +1,52 @@ +var yo = require('yo-yo') +// -------------- styling ---------------------- +var csjs = require('csjs-inject') +var remixLib = require('remix-lib') +var styleGuide = remixLib.ui.styleGuide +var styles = styleGuide() + +var css = csjs` + .tooltip { + visibility: hidden; + width: 100px; + background-color: ${styles.remix.tooltip_CopyToClipboard_BackgroundColor}; + color: ${styles.remix.tooltip_CopyToClipboard_Color}; + font-weight: bold; + font-size: 12px; + text-transform: initial; + text-align: center; + border-radius: 3px; + padding: 5px 0; + position: absolute; + z-index: 1; + bottom: 160%; + left: 100%; + margin-left: -60px; + opacity: 0; + transition: opacity 1s; + } + .tooltip::after { + content: ""; + position: absolute; + top: 100%; + left: 50%; + margin-left: -5px; + border-width: 5px; + border-style: solid; + border-color: ${styles.remix.tooltip_CopyToClipboard_BackgroundColor} transparent transparent transparent; + } +` + +module.exports = function addTooltip (event) { + var icon = event.target + icon.style.position = 'relative' + var tooltip = yo`
Copied!
` + icon.appendChild(tooltip) + var copiedToolbox = event.target.children[0] + copiedToolbox.style.visibility = 'visible' + copiedToolbox.style.opacity = 1 + setTimeout(function () { + copiedToolbox.style.visibility = 'hidden' + copiedToolbox.style.opacity = 0 + }, 1000) +} diff --git a/src/universal-dapp.js b/src/universal-dapp.js index a19f4b7234..a3753b78c7 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -15,9 +15,7 @@ var txHelper = require('./app/execution/txHelper') var txExecution = require('./app/execution/txExecution') var helper = require('./lib/helper') var executionContext = require('./execution-context') - -// copy to copyToClipboard -const copy = require('clipboard-copy') +var copyToClipboard = require('./app/ui/copy-to-clipboard') // -------------- styling ---------------------- var csjs = require('csjs-inject') @@ -42,6 +40,7 @@ var css = csjs` overflow: hidden; word-break: break-word; line-height: initial; + overflow: visible; } .titleLine { display: flex; @@ -71,14 +70,6 @@ var css = csjs` .instance.hidesub .titleLine { display: flex; } - .copy { - cursor: pointer; - margin-left: 3%; - color: ${styles.rightPanel.runTab.icon_Color_Instance_CopyToClipboard}; - } - .copy:hover{ - color: ${styles.rightPanel.runTab.icon_HoverColor_Instance_CopyToClipboard}; - } .buttonsContainer { margin-top: 2%; display: flex; @@ -299,28 +290,20 @@ UniversalDApp.prototype.renderInstance = function (contract, address, contractNa address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex') var shortAddress = helper.shortenAddress(address) - var title = yo` -
-
-
${contractName} at ${shortAddress} (${context})
-
- -
- ` + var title = yo`
+
${contractName} at ${shortAddress} (${context})
+ ${copyToClipboard(() => address)} +
` + if (self.removable_instances) { var close = yo`
` - title.querySelector(`.${css.title}`).appendChild(close) + instance.append(close) } function toggleClass () { instance.classList.toggle(`${css.hidesub}`) } - function copyToClipboard (event) { - event.stopPropagation() - copy(address) - } - var abi = txHelper.sortAbiFunction(contract) instance.appendChild(title)