From 47d5de1fca21aa7cb1199e49a6a059003bfa1195 Mon Sep 17 00:00:00 2001 From: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com> Date: Wed, 21 Apr 2021 23:36:34 +0800 Subject: [PATCH] Swap: Don't copy the currency, only amount (#5915) * CopyableText: add 'onCopy' for clients to change the text-selection * Swap: only copy the amount (without currency) ## Issue 5873: Rounds 2 of LBC swaps ## Notes It was an intended feature to include the currency -- I can paste the full string into my note book, while pasting into wallet apps like Exodus will automatically trim off the currency anyway. Regardless, removed the 'feature' :D --- ui/component/copyableText/view.jsx | 7 ++++++- ui/component/walletSwap/view.jsx | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ui/component/copyableText/view.jsx b/ui/component/copyableText/view.jsx index 561b83a7e..195d8070b 100644 --- a/ui/component/copyableText/view.jsx +++ b/ui/component/copyableText/view.jsx @@ -11,10 +11,11 @@ type Props = { label?: string, primaryButton?: boolean, name?: string, + onCopy?: (string) => string, }; export default function CopyableText(props: Props) { - const { copyable, doToast, snackMessage, label, primaryButton = false, name } = props; + const { copyable, doToast, snackMessage, label, primaryButton = false, name, onCopy } = props; const input = useRef(); @@ -22,7 +23,11 @@ export default function CopyableText(props: Props) { const topRef = input.current; if (topRef && topRef.input && topRef.input.current) { topRef.input.current.select(); + if (onCopy) { + onCopy(topRef.input.current); + } } + document.execCommand('copy'); } diff --git a/ui/component/walletSwap/view.jsx b/ui/component/walletSwap/view.jsx index 24ff55969..f214f5b8b 100644 --- a/ui/component/walletSwap/view.jsx +++ b/ui/component/walletSwap/view.jsx @@ -533,7 +533,18 @@ function WalletSwap(props: Props) { )}
{__('Send')}
- + { + const inputStr = inputElem.value; + const selectEndIndex = inputStr.lastIndexOf(' '); + if (selectEndIndex > -1 && inputStr.substring(0, selectEndIndex).match(/[\d.]/)) { + inputElem.setSelectionRange(0, selectEndIndex, 'forward'); + } + }} + /> {getGap()}
{__('To')}
@@ -665,7 +676,9 @@ function WalletSwap(props: Props) {
}}>Swap Crypto for %lbc%} - subtitle={__('Send crypto to the address provided and you will be sent an equivalent amount of Credits. You can pay with BCH, LTC, ETH, USDC or DAI after starting the swap.')} + subtitle={__( + 'Send crypto to the address provided and you will be sent an equivalent amount of Credits. You can pay with BCH, LTC, ETH, USDC or DAI after starting the swap.' + )} actions={getActionElement()} nag={nag ? : null} />