1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 20:02:58 +01:00
metamask-extension/ui/hooks/useCopyToClipboard.js

36 lines
769 B
JavaScript
Raw Normal View History

import { useState, useCallback } from 'react';
import copyToClipboard from 'copy-to-clipboard';
import { MINUTE } from '../../shared/constants/time';
import { useTimeout } from './useTimeout';
/**
* useCopyToClipboard
*
* @param {number} [delay=3000] - delay in ms
* @returns {[boolean, Function]}
*/
const DEFAULT_DELAY = MINUTE;
2020-11-03 00:41:28 +01:00
export function useCopyToClipboard(delay = DEFAULT_DELAY) {
const [copied, setCopied] = useState(false);
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
const startTimeout = useTimeout(
() => {
copyToClipboard(' ');
setCopied(false);
},
delay,
false,
);
const handleCopy = useCallback(
(text) => {
setCopied(true);
startTimeout();
copyToClipboard(text);
},
[startTimeout],
);
return [copied, handleCopy];
}