Skip to content

Commit

Permalink
♻️ fix types & typos
Browse files Browse the repository at this point in the history
  • Loading branch information
sebipap committed May 10, 2024
1 parent 89b0221 commit 4af7e75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
15 changes: 5 additions & 10 deletions components/common/MainActionButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { MouseEvent, useCallback } from 'react';
import { useNetwork, useSwitchNetwork } from 'wagmi';
import { useTranslation } from 'react-i18next';
import { LoadingButton, type LoadingButtonProps } from '@mui/lab';
Expand All @@ -7,12 +7,7 @@ import { Button } from '@mui/material';
import { useWeb3 } from 'hooks/useWeb3';
import { useModal } from 'contexts/ModalContext';

interface MainActionButtonProps extends LoadingButtonProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onClick?: (event?: any) => void;
}

function MainActionButton({ onClick, ...props }: MainActionButtonProps) {
function MainActionButton({ onClick, ...props }: LoadingButtonProps) {
const { t } = useTranslation();
const { isConnected, chain: displayNetwork, connect, impersonateActive, exitImpersonate } = useWeb3();
const { chain } = useNetwork();
Expand All @@ -24,8 +19,8 @@ function MainActionButton({ onClick, ...props }: MainActionButtonProps) {
close();
}, [close, exitImpersonate]);

const handleSwitchNetworkAndExecuteMainAction = useCallback(
async (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
const handleClick = useCallback(
async (event: MouseEvent<HTMLButtonElement>) => {
if (chain && chain.id !== displayNetwork.id && switchNetworkAsync) {
try {
const result = await switchNetworkAsync(displayNetwork.id);
Expand Down Expand Up @@ -59,7 +54,7 @@ function MainActionButton({ onClick, ...props }: MainActionButtonProps) {
);
}

return <LoadingButton {...props} loading={isLoading} onClick={handleSwitchNetworkAndExecuteMainAction} />;
return <LoadingButton {...props} loading={isLoading} onClick={handleClick} />;
}

export default React.memo(MainActionButton);
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,18 @@ function SwitchCollateral({ symbol }: Props) {
}
}, [marketAccount, auditor, opts, checked, symbol, refreshAccountData]);

const siwtchNetworkAndToggle = useCallback(async () => {
if (chain && chain.id !== displayNetwork.id && switchNetworkAsync) {
try {
const result = await switchNetworkAsync(displayNetwork.id);

if (result.id === displayNetwork.id) {
onToggle();
}
} catch (error) {
return;
const switchNetworkAndToggle = useCallback(async () => {
if (!(chain && chain.id !== displayNetwork.id && switchNetworkAsync)) {
return onToggle();
}
try {
const result = await switchNetworkAsync(displayNetwork.id);

if (result.id === displayNetwork.id) {
onToggle();
}
} else {
onToggle();
} catch (error) {
return;
}
}, [chain, displayNetwork.id, onToggle, switchNetworkAsync]);

Expand Down Expand Up @@ -140,7 +139,7 @@ function SwitchCollateral({ symbol }: Props) {
<span data-testid={`switch-collateral-${symbol}-wrapper`}>
<StyledSwitch
checked={checked}
onChange={siwtchNetworkAndToggle}
onChange={switchNetworkAndToggle}
inputProps={{
'aria-label': t('Use this asset as collateral'),
'data-testid': `switch-collateral-${symbol}`,
Expand Down

0 comments on commit 4af7e75

Please sign in to comment.