Skip to content

chore(checkout): React hooks linting #2605

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@typescript-eslint/parser": "^7.11.0",
"@vitejs/plugin-react": "^4.3.0",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.7",
"typescript": "^5.2.2",
"vite": "^5.2.14",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@vitejs/plugin-react": "^4.3.0",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.7",
"vite": "^5.2.14",
"vite-plugin-node-polyfills": "^0.22.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@typescript-eslint/parser": "^7.1.1",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.7",
"typescript": "^5.2.2",
"vite": "^5.2.14",
Expand Down
5 changes: 4 additions & 1 deletion packages/checkout/widgets-lib/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
"extends": ["../../../.eslintrc"],
"extends": [
"../../../.eslintrc",
"plugin:react-hooks/recommended-legacy"
],
"ignorePatterns": ["jest.config.*", "rollup.config.*"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand Down
1 change: 1 addition & 0 deletions packages/checkout/widgets-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@types/react-dom": "^18.3.0",
"@types/uuid": "^8.3.4",
"eslint": "^8.40.0",
"eslint-plugin-react-hooks": "^5.2.0",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.4.3",
"react-scripts": "5.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function CoinSelector({
return options;
}
return filterOptions(searchValue, options);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [options, searchValue, filterOptions]);

const handleCloseDrawer = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export function ConnectLoader({
});
}
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [checkout, walletProviderName, browserProvider]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function SelectForm({
onSelectChange(option.id);
setCoinSelectorOpen(false);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
})), [options, onSelectChange, setCoinSelectorOpen]);

const getSelectedOption = () => {
Expand All @@ -76,6 +77,7 @@ export function SelectForm({
controlType: 'Select',
action: 'Opened',
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setCoinSelectorOpen, track]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function NetworkSwitchDrawer({
switchNetworkEthImage.src = ethImageUrl;
const switchNetworkzkEVMImage = new Image();
switchNetworkzkEVMImage.src = zkevmImageUrl;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function RouteFees({
},
prefix: '',
})) ?? [],
// eslint-disable-next-line react-hooks/exhaustive-deps
[routeData],
);

Expand All @@ -54,6 +55,7 @@ export function RouteFees({
},
prefix: '',
})) ?? [],
// eslint-disable-next-line react-hooks/exhaustive-deps
[routeData],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function RouteOptionsDrawer({
routesAvailable: routes?.length ?? 0,
},
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [visible]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function SelectedRouteOption({
onClick?.(event);
return true;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[onClick, loading, routeData],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function StatusView({
firstRender.current = false;
onRenderEvent();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [firstRender.current, onRenderEvent]);

const onStatusActionClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function TokenImage({
|| (theme && getDefaultTokenImage(environment, theme))
|| ''
: src),
// eslint-disable-next-line react-hooks/exhaustive-deps
[src, error],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function ChangeWallet({ onChangeWalletClick }: ChangeWalletProps) {
})();
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isWalletConnectEnabled, from]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function ClaimWithdrawalInProgress({ transactionResponse }: ClaimWithdraw
userJourney: UserJourney.BRIDGE,
screen: 'ClaimWithdrawalInProgress',
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
Expand Down Expand Up @@ -68,6 +69,7 @@ export function ClaimWithdrawalInProgress({ transactionResponse }: ClaimWithdraw
});
}
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [transactionResponse]);

return <LoadingView loadingText={t('views.CLAIM_WITHDRAWAL.IN_PROGRESS.loading.text')} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function NoTransactions(
userJourney: UserJourney.BRIDGE,
screen: 'NoTransactions',
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ export function TransactionItemWithdrawPending({
}
const timeDiffDays = timeDiffHours / 24; // days
return relativeTimeFormat.format(Math.ceil(timeDiffDays), 'day');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dateNowUnixMs, translation[1].language]);

const withdrawalReadyToClaim = withdrawalReadyDate ? withdrawalReadyDate.getTime() < dateNowUnixMs : false;
const actionMessage = useMemo(
() => (withdrawalReadyToClaim === true
? translation.t('views.TRANSACTIONS.status.withdrawalPending.withdrawalReadyText')
: `${translation.t('views.TRANSACTIONS.status.withdrawalPending.withdrawalDelayText')} ${delayTimeString}`),
// eslint-disable-next-line react-hooks/exhaustive-deps
[delayTimeString, translation[1].language],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export function Transactions({
setShowWalletDrawer(false);
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[checkout],
);

Expand Down Expand Up @@ -330,6 +331,7 @@ export function Transactions({
tokens: await getTokensDetails(tokensWithChainSlug),
transactions: localTxs.result,
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [from, getTransactionsDetails]);

const { providers } = useInjectedProviders({ checkout });
Expand Down Expand Up @@ -360,13 +362,15 @@ export function Transactions({

setLoading(false);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [from, checkout]);

useEffect(() => {
page({
userJourney: UserJourney.BRIDGE,
screen: 'Transactions',
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const useTransakEvents = (props: UseTransakEventsProps) => {
},
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handleEvents = useCallback((event: TransakEvent) => {
Expand Down Expand Up @@ -141,6 +142,7 @@ export const useTransakEvents = (props: UseTransakEventsProps) => {
default:
break;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handleMessageEvent = useCallback(
Expand All @@ -156,6 +158,7 @@ export const useTransakEvents = (props: UseTransakEventsProps) => {

console.log('@@@ Transak event', event); // eslint-disable-line no-console
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[ref],
);

Expand All @@ -165,6 +168,7 @@ export const useTransakEvents = (props: UseTransakEventsProps) => {
clearTimeout(timeout.current);
window.removeEventListener('message', handleMessageEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const useTransakIframe = (props: UseTransakIframeProps) => {
const checkoutUrl = await getNFTCheckoutURL();
setIframeSrc(checkoutUrl);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return { iframeSrc };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function PayWithWalletDrawer({
<MenuItem.Label>{t('drawers.wallet.payWithCard')}</MenuItem.Label>
</MenuItem>
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [onClose, onPayWithCard]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function SetupAnalytics(
if (!config) return;
updateWriteKey(config.segmentPublishableKey);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [telemetry]);

// eslint-disable-next-line react/jsx-no-useless-fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function CryptoFiatProvider({ environment, children }: CryptoFiatProvider
})),
},
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function CryptoFiatTestComponent({ tokenSymbols }: CryptoFiatTestComponen
},
});
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cryptoFiatDispatch]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export function HandoverProvider({ children }: HandoverProviderProps) {
[handoverQueue, handoverBusy, handovers, closeHandover],
);

// eslint-disable-next-line react-hooks/exhaustive-deps
const addHandover = (
handoverContent: HandoverContent,
handoverId: HandoverTarget = HandoverTarget.GLOBAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export function ProvidersContextProvider({
/** TODO: handle error */
}
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [toProvider, providersState.lockedToProvider]);

return (
Expand Down
1 change: 1 addition & 0 deletions packages/checkout/widgets-lib/src/hooks/useMount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export const useMount = (

fn();
isMounted.current = true;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps || []);
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const useAsyncMemo = <T>(
return () => {
isMounted = false;
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, dependencies);

return value as T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const useBalance = ({
setBalancesLoading(false);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [checkout, provider]);

useInterval(() => refreshBalances(true), REFRESH_BALANCE_INTERVAL_MS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const useInjectedProviders = ({ checkout }: UseInjectedProvidersParams) =

filterAndProcessProviders(injectedProviders);
return () => cancelSubscription();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [checkout]);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const useQuoteOrder = ({
fetching.current = false;
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[environment, environmentId, preferredCurrency, fetching],
);

Expand Down
4 changes: 4 additions & 0 deletions packages/checkout/widgets-lib/src/lib/hooks/useSignOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export const useSignOrder = (input: SignOrderInput) => {
}
return undefined;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[items, environmentId, environment, provider],
);

Expand Down Expand Up @@ -393,6 +394,7 @@ export const useSignOrder = (input: SignOrderInput) => {
}
return undefined;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[items, environmentId, environment, provider, getPostHooks],
);

Expand Down Expand Up @@ -473,6 +475,7 @@ export const useSignOrder = (input: SignOrderInput) => {

return executeResponse.transactions;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[
provider,
executeTransaction,
Expand Down Expand Up @@ -517,6 +520,7 @@ export const useSignOrder = (input: SignOrderInput) => {

return success;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[currentTransactionIndex, provider, filteredTransactions],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const useWalletConnect = () => {
openModal(ethereumProvider, resolve, reject);
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ethereumProvider, walletConnectModal, isWalletConnectEnabled]);

const getWalletLogoUrl = useCallback(async () => await WalletConnectManager.getInstance().getWalletLogoUrl(), []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ export const useRouteCalculation = () => {
calculateFromAmount,
calculateFromAmountFromRoute,
convertToFormattedFromAmount,
// eslint-disable-next-line react-hooks/exhaustive-deps
}), []);
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ export const useSlippage = () => {
return useMemo(() => ({
getSlippageTier,
calculateAdjustedAmount,
// eslint-disable-next-line react-hooks/exhaustive-deps
}), []);
};
Loading