Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #21169 - Ensure Copy format is plain text #21387

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions shared/constants/copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const COPY_OPTIONS = {
format: 'text/plain',
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CustodyLabels from '../../institutional/custody-labels/custody-labels';
///: END:ONLY_INCLUDE_IN
import { Icon, IconName, IconSize } from '../../component-library';
import { IconColor } from '../../../helpers/constants/design-system';
import { COPY_OPTIONS } from '../../../../shared/constants/copy';

class SelectedAccount extends Component {
state = {
Expand Down Expand Up @@ -104,7 +105,7 @@ class SelectedAccount extends Component {
() => this.setState({ copied: false }),
SECOND * 3,
);
copyToClipboard(checksummedAddress);
copyToClipboard(checksummedAddress, COPY_OPTIONS);
}}
>
<div className="selected-account__name">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getMemoizedAddressBook,
} from '../../../../../../selectors';
import NicknamePopovers from '../../../../modals/nickname-popovers';
import { COPY_OPTIONS } from '../../../../../../../shared/constants/copy';

const Address = ({
checksummedRecipientAddress,
Expand Down Expand Up @@ -47,7 +48,7 @@ const Address = ({
<div
className="tx-insight tx-insight-component tx-insight-component-address"
onClick={() => {
copyToClipboard(checksummedRecipientAddress);
copyToClipboard(checksummedRecipientAddress, COPY_OPTIONS);
if (onRecipientClick) {
onRecipientClick();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { getURLHostName } from '../../../helpers/utils/util';
import TransactionDecoding from '../transaction-decoding';
import { NETWORKS_ROUTE } from '../../../helpers/constants/routes';
import TransactionInsightsDeprecationAlert from '../confirm-data/transaction-insights-deprecation-alert';
import { COPY_OPTIONS } from '../../../../shared/constants/copy';

export default class TransactionListItemDetails extends PureComponent {
static contextTypes = {
Expand Down Expand Up @@ -138,7 +139,7 @@ export default class TransactionListItemDetails extends PureComponent {
});

this.setState({ justCopied: true }, () => {
copyToClipboard(hash);
copyToClipboard(hash, COPY_OPTIONS);
setTimeout(() => this.setState({ justCopied: false }), SECOND);
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { shortenAddress } from '../../../helpers/utils/util';
import AccountMismatchWarning from '../account-mismatch-warning/account-mismatch-warning.component';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils';
import { COPY_OPTIONS } from '../../../../shared/constants/copy';
import NicknamePopovers from '../../app/modals/nickname-popovers';
import { Icon, IconName } from '../../component-library';
import {
Expand Down Expand Up @@ -51,7 +52,7 @@ function SenderAddress({
)}
onClick={() => {
setAddressCopied(true);
copyToClipboard(checksummedSenderAddress);
copyToClipboard(checksummedSenderAddress, COPY_OPTIONS);
if (onSenderClick) {
onSenderClick();
}
Expand Down Expand Up @@ -130,7 +131,7 @@ export function RecipientWithAddress({
onClick={() => {
if (recipientIsOwnedAccount) {
setAddressCopied(true);
copyToClipboard(checksummedRecipientAddress);
copyToClipboard(checksummedRecipientAddress, COPY_OPTIONS);
} else {
setShowNicknamePopovers(true);
if (onRecipientClick) {
Expand Down
5 changes: 3 additions & 2 deletions ui/hooks/useCopyToClipboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState, useCallback } from 'react';
import copyToClipboard from 'copy-to-clipboard';
import { MINUTE } from '../../shared/constants/time';
import { COPY_OPTIONS } from '../../shared/constants/copy';
import { useTimeout } from './useTimeout';

/**
Expand All @@ -15,7 +16,7 @@ export function useCopyToClipboard(delay = DEFAULT_DELAY) {
const [copied, setCopied] = useState(false);
const startTimeout = useTimeout(
() => {
copyToClipboard(' ');
copyToClipboard(' ', COPY_OPTIONS);
setCopied(false);
},
delay,
Expand All @@ -26,7 +27,7 @@ export function useCopyToClipboard(delay = DEFAULT_DELAY) {
(text) => {
setCopied(true);
startTimeout();
copyToClipboard(text);
copyToClipboard(text, COPY_OPTIONS);
},
[startTimeout],
);
Expand Down
3 changes: 2 additions & 1 deletion ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AlertTypes } from '../shared/constants/alerts';
import { maskObject } from '../shared/modules/object.utils';
import { SENTRY_UI_STATE } from '../app/scripts/lib/setupSentry';
import { ENVIRONMENT_TYPE_POPUP } from '../shared/constants/app';
import { COPY_OPTIONS } from '../shared/constants/copy';
import switchDirection from '../shared/lib/switch-direction';
import { setupLocale } from '../shared/lib/error-utils';
import * as actions from './store/actions';
Expand Down Expand Up @@ -274,7 +275,7 @@ window.logState = function (toClipboard) {
if (err) {
console.error(err.message);
} else if (toClipboard) {
copyToClipboard(result);
copyToClipboard(result, COPY_OPTIONS);
console.log('State log copied');
} else {
console.log(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import UserPreferencedCurrencyDisplay from '../../../components/app/user-prefere
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
import { ConfirmGasDisplay } from '../../../components/app/confirm-gas-display';
import CustomNonce from '../../../components/app/custom-nonce';
import { COPY_OPTIONS } from '../../../../shared/constants/copy';

export default class ConfirmApproveContent extends Component {
static contextTypes = {
Expand Down Expand Up @@ -274,7 +275,7 @@ export default class ConfirmApproveContent extends Component {
<div className="confirm-approve-content__medium-text">
<ButtonIcon
ariaLabel="copy"
onClick={() => copyToClipboard(toAddress)}
onClick={() => copyToClipboard(toAddress, COPY_OPTIONS)}
color={IconColor.iconDefault}
iconName={
this.state.copied ? IconName.CopySuccess : IconName.Copy
Expand Down Expand Up @@ -420,7 +421,7 @@ export default class ConfirmApproveContent extends Component {
<span
className="confirm-approve-content__approval-asset-title"
onClick={() => {
copyToClipboard(tokenAddress);
copyToClipboard(tokenAddress, COPY_OPTIONS);
}}
title={tokenAddress}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Icon, IconName } from '../../components/component-library';
import { IconColor } from '../../helpers/constants/design-system';
import { formatCurrency } from '../../helpers/utils/confirm-tx.util';
import { getValueFromWeiHex } from '../../../shared/modules/conversion.utils';
import { COPY_OPTIONS } from '../../../shared/constants/copy';

export default class ConfirmDecryptMessage extends Component {
static contextTypes = {
Expand Down Expand Up @@ -50,7 +51,7 @@ export default class ConfirmDecryptMessage extends Component {
};

copyMessage = () => {
copyToClipboard(this.state.rawMessage);
copyToClipboard(this.state.rawMessage, COPY_OPTIONS);
this.context.trackEvent({
category: MetaMetricsEventCategory.Messages,
event: 'Copy',
Expand Down
Loading