Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-schrammel committed Dec 9, 2024
1 parent 0c277c1 commit 5df6915
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/entries/popup/hooks/swap/useSwapQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const useSwapQuote = ({

const { data, isLoading, isError, fetchStatus } = useQuery({
queryFn: async () => {
if (!quotesParams) return;
if (!quotesParams) throw 'unreacheable';
const quote = await (isCrosschainSwap ? getCrosschainQuote : getQuote)(
quotesParams,
);
Expand All @@ -127,7 +127,7 @@ export const useSwapQuote = ({
outputAmount: assetToBuyValue,
});
}
return quote;
return quote as Quote | CrosschainQuote | QuoteError;
},
queryKey: ['getSwapQuote', quotesParams],
enabled: !!quotesParams,
Expand Down
25 changes: 12 additions & 13 deletions src/entries/popup/hooks/useTimeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useLayoutEffect, useRef } from 'react';

export function useTimeoutEffect(
onTimeout: (e: { cancelled: boolean; elapsedTime: number }) => void,
delay: number,
{ timeout, enabled = true }: { timeout: number; enabled?: boolean },
) {
const callback = useRef(onTimeout);
useLayoutEffect(() => {
Expand All @@ -11,22 +11,21 @@ export function useTimeoutEffect(

const timeoutRef = useRef<NodeJS.Timeout>();
useEffect(() => {
if (!enabled) return;
const startedAt = Date.now();
timeoutRef.current = setTimeout(
() =>
callback.current({
cancelled: false,
elapsedTime: Date.now() - startedAt,
}),
delay,
);
const timeout = timeoutRef.current;
timeoutRef.current = setTimeout(() => {
callback.current({
cancelled: false,
elapsedTime: Date.now() - startedAt,
});
}, timeout);
return () => {
clearTimeout(timeout);
if (!timeoutRef.current) return;
clearTimeout(timeoutRef.current);
const elapsedTime = Date.now() - startedAt;
if (elapsedTime < delay) {
if (elapsedTime < timeout) {
callback.current({ cancelled: true, elapsedTime });
}
};
}, [delay]);
}, [timeout, enabled]);
}
2 changes: 1 addition & 1 deletion src/entries/popup/pages/home/NFTs/NFTDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default function NFTDetails() {
},
});
},
5 * 1000, // 5s
{ timeout: 2 * 1000, enabled: !!nft },
);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/entries/popup/pages/home/TokenDetails/TokenDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ export function TokenDetails() {
},
});
},
5 * 1000, // 5s
{ timeout: 2 * 1000, enabled: !!token },
);

const { explainerSheetParams, showExplainerSheet, hideExplainerSheet } =
Expand Down

0 comments on commit 5df6915

Please sign in to comment.