From 2dbf9d97cb94180a0afb75e2f206ce5f3026c710 Mon Sep 17 00:00:00 2001 From: Tommy Verrall Date: Wed, 9 Apr 2025 11:47:10 +0200 Subject: [PATCH] yarn lint fix --- .../Clipboard/ClipboardFormFields.tsx | 7 +- .../components/CurrencyFormFieldWithPaste.tsx | 42 ++++---- .../components/Delegation/DelegationList.tsx | 99 ++++++++++--------- .../Delegation/PendingDelegationItem.tsx | 17 ++-- .../src/components/Send/SendInputModal.tsx | 4 +- .../src/components/TauriLinkWrapper.tsx | 2 +- nym-wallet/src/pages/delegation/index.tsx | 16 ++- nym-wallet/src/theme/NymWalletTheme.tsx | 11 ++- 8 files changed, 105 insertions(+), 93 deletions(-) diff --git a/nym-wallet/src/components/Clipboard/ClipboardFormFields.tsx b/nym-wallet/src/components/Clipboard/ClipboardFormFields.tsx index 12672e78b8..370fba1806 100644 --- a/nym-wallet/src/components/Clipboard/ClipboardFormFields.tsx +++ b/nym-wallet/src/components/Clipboard/ClipboardFormFields.tsx @@ -6,7 +6,10 @@ import { UseFormRegister, UseFormSetValue, FieldValues, Path, FieldErrors } from import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager'; import { PasteFromClipboard } from './ClipboardActions'; -export const useCopyAllSupport = (inputRef: React.MutableRefObject, onPasteValue?: (value: string) => void) => { +export const useCopyAllSupport = ( + inputRef: React.MutableRefObject, + onPasteValue?: (value: string) => void, +) => { useEffect(() => { if (!inputRef.current) return undefined; @@ -457,4 +460,4 @@ export const HookFormCurrencyFieldWithPaste = ); -}; \ No newline at end of file +}; diff --git a/nym-wallet/src/components/CurrencyFormFieldWithPaste.tsx b/nym-wallet/src/components/CurrencyFormFieldWithPaste.tsx index e9df8f2d07..5b636c8679 100644 --- a/nym-wallet/src/components/CurrencyFormFieldWithPaste.tsx +++ b/nym-wallet/src/components/CurrencyFormFieldWithPaste.tsx @@ -43,48 +43,48 @@ export const CurrencyFormFieldWithPaste = ({ }; onChanged(decCoin); - + if (inputRef.current) { inputRef.current.value = cleanedValue; - + const inputEvent = new Event('input', { bubbles: true }); inputRef.current.dispatchEvent(inputEvent); - + const changeEvent = new Event('change', { bubbles: true }); inputRef.current.dispatchEvent(changeEvent); - + inputRef.current.focus(); } }; useEffect(() => { + const pasteEventHandler = (e: ClipboardEvent) => { + e.preventDefault(); + + const { clipboardData } = e; + if (!clipboardData) return; + + const pastedText = clipboardData.getData('text'); + if (!pastedText) return; + + processPastedText(pastedText); + }; + const findInputElement = () => { if (fieldRef.current) { const input = fieldRef.current.querySelector('input'); if (input) { inputRef.current = input; - + // Set up paste event handler input.addEventListener('paste', pasteEventHandler as EventListener); } } }; - const pasteEventHandler = (e: ClipboardEvent) => { - e.preventDefault(); - - const clipboardData = e.clipboardData; - if (!clipboardData) return; - - const pastedText = clipboardData.getData('text'); - if (!pastedText) return; - - processPastedText(pastedText); - }; - findInputElement(); const timeoutId = setTimeout(findInputElement, 200); - + return () => { clearTimeout(timeoutId); if (inputRef.current) { @@ -98,7 +98,7 @@ export const CurrencyFormFieldWithPaste = ({ if (inputRef.current && document.activeElement === inputRef.current) { if ((e.metaKey || e.ctrlKey) && e.key === 'v') { e.preventDefault(); - + try { const clipboardText = await navigator.clipboard.readText(); if (clipboardText) { @@ -112,7 +112,7 @@ export const CurrencyFormFieldWithPaste = ({ }; document.addEventListener('keydown', handleKeyDown); - + return () => { document.removeEventListener('keydown', handleKeyDown); }; @@ -143,4 +143,4 @@ export const CurrencyFormFieldWithPaste = ({ ); -}; \ No newline at end of file +}; diff --git a/nym-wallet/src/components/Delegation/DelegationList.tsx b/nym-wallet/src/components/Delegation/DelegationList.tsx index 617a58dac5..3e84331f19 100644 --- a/nym-wallet/src/components/Delegation/DelegationList.tsx +++ b/nym-wallet/src/components/Delegation/DelegationList.tsx @@ -47,8 +47,7 @@ const shouldBeFiltered = (item: any): boolean => { // For pending delegations, keep "Delegate" events but filter out "Undelegate" events with empty node_identity if (isPendingDelegation(item)) { // If it's an undelegate event with empty node_identity, filter it out - if ((!item.node_identity || item.node_identity === '') && - item.event && item.event.kind === 'Undelegate') { + if ((!item.node_identity || item.node_identity === '') && item.event && item.event.kind === 'Undelegate') { return true; } @@ -112,7 +111,7 @@ const EnhancedTableHead: FCWithChildren = ({ order, orderBy, minWidth: headCell.id === 'node_identity' ? '120px' : '80px', whiteSpace: 'nowrap', overflow: 'hidden', - textOverflow: 'ellipsis' + textOverflow: 'ellipsis', }} > = ({ order, orderBy, maxWidth: '120px', whiteSpace: 'nowrap', overflow: 'hidden', - textAlign: 'center' + textAlign: 'center', }} > - Actions + + Actions + @@ -182,7 +183,7 @@ export const DelegationList: FCWithChildren<{ // Filter out empty placeholder rows const filteredItems = React.useMemo(() => { if (!sorted) return []; - return sorted.filter(item => !shouldBeFiltered(item)); + return sorted.filter((item) => !shouldBeFiltered(item)); }, [sorted]); // Check if any delegations have pruning errors @@ -223,14 +224,16 @@ export const DelegationList: FCWithChildren<{ )} {/* Add horizontal scrolling to the table container */} - + {isLoading && } {filteredItems?.length ? filteredItems.map((item: any, _index: number) => { - if (isPendingDelegation(item)) { - const pendingKey = `pending-${item.event.mix_id}-${item.event.address}-${Date.now()}-${Math.random()}`; + if (isPendingDelegation(item)) { + const pendingKey = `pending-${item.event.mix_id}-${ + item.event.address + }-${Date.now()}-${Math.random()}`; - if (item.event && item.event.kind === 'Delegate' && (!item.node_identity || item.node_identity === '')) { - return ; + if ( + item.event && + item.event.kind === 'Delegate' && + (!item.node_identity || item.node_identity === '') + ) { + return ( + + ); + } + + return ; } - return ; - } + if (isDelegation(item)) { + if (!item.node_identity || item.node_identity === '-' || item.node_identity === '...') { + return null; + } - if (isDelegation(item)) { - if (!item.node_identity || item.node_identity === '-' || item.node_identity === '...') { - return null; + return ( + + ); } - return ( - - ); - } - - return null; - }) + return null; + }) : null} ); -}; \ No newline at end of file +}; diff --git a/nym-wallet/src/components/Delegation/PendingDelegationItem.tsx b/nym-wallet/src/components/Delegation/PendingDelegationItem.tsx index bd2ff825c7..fc3c070625 100644 --- a/nym-wallet/src/components/Delegation/PendingDelegationItem.tsx +++ b/nym-wallet/src/components/Delegation/PendingDelegationItem.tsx @@ -20,9 +20,7 @@ export const PendingDelegationItem = ({ item, explorerUrl }: { item: WrappedDele - - - - {item.event.amount?.amount} NYM - + {item.event.amount?.amount} NYM - @@ -30,18 +28,17 @@ export const PendingDelegationItem = ({ item, explorerUrl }: { item: WrappedDele - Your delegation of {item.event.amount?.amount} {item.event.amount?.denom} will take effect - when the new epoch starts. There is a new - epoch every hour. + Your delegation of {item.event.amount?.amount} {item.event.amount?.denom} will take effect when the new + epoch starts. There is a new epoch every hour. } arrow PopperProps={{ sx: { '& .MuiTooltip-tooltip': { - textAlign: 'center' - } - } + textAlign: 'center', + }, + }, }} > @@ -49,4 +46,4 @@ export const PendingDelegationItem = ({ item, explorerUrl }: { item: WrappedDele -); \ No newline at end of file +); diff --git a/nym-wallet/src/components/Send/SendInputModal.tsx b/nym-wallet/src/components/Send/SendInputModal.tsx index f9c9d186e1..f561675cae 100644 --- a/nym-wallet/src/components/Send/SendInputModal.tsx +++ b/nym-wallet/src/components/Send/SendInputModal.tsx @@ -69,7 +69,7 @@ export const SendInputModal = ({ const [addressIsValid, setAddressIsValid] = useState(false); const [errorAmount, setErrorAmount] = useState(); const [errorFee, setErrorFee] = useState(); - + // Calculate noAccount at the component root level instead of using useEffect const noAccount = !balance || balance === '0' || parseFloat(balance) === 0; @@ -295,4 +295,4 @@ export const SendInputModal = ({ )} ); -}; \ No newline at end of file +}; diff --git a/nym-wallet/src/components/TauriLinkWrapper.tsx b/nym-wallet/src/components/TauriLinkWrapper.tsx index 0df07e245c..f3632a1557 100644 --- a/nym-wallet/src/components/TauriLinkWrapper.tsx +++ b/nym-wallet/src/components/TauriLinkWrapper.tsx @@ -18,4 +18,4 @@ export const TauriLink: React.FC = (props) => { }; return ; -}; \ No newline at end of file +}; diff --git a/nym-wallet/src/pages/delegation/index.tsx b/nym-wallet/src/pages/delegation/index.tsx index c250e8dd4f..67af5247da 100644 --- a/nym-wallet/src/pages/delegation/index.tsx +++ b/nym-wallet/src/pages/delegation/index.tsx @@ -402,10 +402,10 @@ export const Delegation: FC<{ isStorybook?: boolean }> = ({ isStorybook }) => { return ( <> {/* Main container - make sure it constrains width properly */} - = ({ isStorybook }) => { )} )} - + {/* Add a container to ensure delegations are constrained */} - - {delegationsComponent(delegations)} - + {delegationsComponent(delegations)} @@ -556,4 +554,4 @@ export const DelegationPage: FC<{ isStorybook?: boolean }> = ({ isStorybook }) = -); \ No newline at end of file +); diff --git a/nym-wallet/src/theme/NymWalletTheme.tsx b/nym-wallet/src/theme/NymWalletTheme.tsx index 6b6864bc45..aa408ef129 100644 --- a/nym-wallet/src/theme/NymWalletTheme.tsx +++ b/nym-wallet/src/theme/NymWalletTheme.tsx @@ -10,15 +10,18 @@ let interFontLink: HTMLLinkElement | null = null; const FontLoader = () => { useEffect(() => { // Skip if already initialized - if (fontsInitialized === true) { return; } - + if (fontsInitialized === true) { + return; + } + fontsInitialized = true; - + interFontLink = document.createElement('link'); interFontLink.rel = 'stylesheet'; interFontLink.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap'; document.head.appendChild(interFontLink); + // eslint-disable-next-line consistent-return return () => { // Only clean up if the component is truly being unmounted if (interFontLink && document.head.contains(interFontLink)) { @@ -46,4 +49,4 @@ export const NymWalletThemeWithMode: FCWithChildren<{ mode: PaletteMode; childre {children} ); -}; \ No newline at end of file +};