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
This commit is contained in:
infinite-persistence 2021-04-21 23:36:34 +08:00 committed by GitHub
parent e1be0f30bd
commit 47d5de1fca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -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');
}

View file

@ -533,7 +533,18 @@ function WalletSwap(props: Props) {
</>
)}
<div className="confirm__label">{__('Send')}</div>
<CopyableText primaryButton copyable={getCoinSendAmountStr(coin)} snackMessage={__('Amount copied.')} />
<CopyableText
primaryButton
copyable={getCoinSendAmountStr(coin)}
snackMessage={__('Amount copied.')}
onCopy={(inputElem) => {
const inputStr = inputElem.value;
const selectEndIndex = inputStr.lastIndexOf(' ');
if (selectEndIndex > -1 && inputStr.substring(0, selectEndIndex).match(/[\d.]/)) {
inputElem.setSelectionRange(0, selectEndIndex, 'forward');
}
}}
/>
{getGap()}
<div className="confirm__label">{__('To')}</div>
<CopyableText primaryButton copyable={getCoinAddress(coin)} snackMessage={__('Address copied.')} />
@ -665,7 +676,9 @@ function WalletSwap(props: Props) {
<Form onSubmit={handleStartSwap}>
<Card
title={<I18nMessage tokens={{ lbc: <LbcSymbol size={22} /> }}>Swap Crypto for %lbc%</I18nMessage>}
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 ? <Nag relative type={nag.type} message={__(nag.msg)} /> : null}
/>