Skip to content

Commit

Permalink
pause remaining time when quote loading or tx pending
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed Jul 8, 2024
1 parent e8d8576 commit 6db1321
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/web/components/bridge/amount-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ const TransferDetails: FunctionComponent<{
successfulQuotes,
setSelectedBridgeProvider,
isRefetchingQuote,
isTxPending,
} = quote;

return (
Expand Down Expand Up @@ -1264,6 +1265,7 @@ const TransferDetails: FunctionComponent<{
refetchInterval={refetchInterval}
selectedQuote={selectedQuote}
open={open}
isRemainingTimePaused={isRefetchingQuote || isTxPending}
showRemainingTime
/>
</div>
Expand Down
15 changes: 12 additions & 3 deletions packages/web/components/bridge/bridge-quote-remaining-time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ export const BridgeQuoteRemainingTime: FunctionComponent<
className?: string;
refetchInterval: number;
dataUpdatedAt: number;
isPaused?: boolean;
strokeWidth?: number;
}>
> = ({ className, refetchInterval, dataUpdatedAt, children, strokeWidth }) => {
> = ({
className,
refetchInterval,
dataUpdatedAt,
isPaused = false,
children,
strokeWidth,
}) => {
const [progress, setProgress] = useState(100);

useEffect(() => {
if (!dataUpdatedAt) return;

const updateProgress = () => {
const elapsed = Date.now() - dataUpdatedAt;
const now = isPaused ? dataUpdatedAt : Date.now();
const elapsed = now - dataUpdatedAt;
const percentage = Math.max((1 - elapsed / refetchInterval) * 100, 0);
setProgress(percentage);
};
Expand All @@ -37,7 +46,7 @@ export const BridgeQuoteRemainingTime: FunctionComponent<
);

return () => clearInterval(intervalId);
}, [dataUpdatedAt, refetchInterval]);
}, [dataUpdatedAt, refetchInterval, isPaused]);

return (
<div className={classNames("relative h-7 w-7 md:h-5 md:w-5", className)}>
Expand Down
3 changes: 3 additions & 0 deletions packages/web/components/bridge/quote-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const ExpandDetailsControlContent: FunctionComponent<{
selectedQuoteUpdatedAt: number | undefined;
refetchInterval: number;
open: boolean;
isRemainingTimePaused: boolean;
showRemainingTime?: boolean;
}> = ({
selectedQuote,
Expand All @@ -181,6 +182,7 @@ export const ExpandDetailsControlContent: FunctionComponent<{
selectedQuoteUpdatedAt,
refetchInterval,
open,
isRemainingTimePaused,
showRemainingTime = false,
}) => {
const totalFees = calcSelectedQuoteTotalFee(selectedQuote);
Expand All @@ -191,6 +193,7 @@ export const ExpandDetailsControlContent: FunctionComponent<{
<BridgeQuoteRemainingTime
dataUpdatedAt={selectedQuoteUpdatedAt}
refetchInterval={refetchInterval}
isPaused={isRemainingTimePaused}
/>
)}
<div className="flex items-center gap-2 md:gap-1">
Expand Down
3 changes: 3 additions & 0 deletions packages/web/components/bridge/review-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ const TransferDetails: FunctionComponent<
fromDisplayChain,
selectedQuoteUpdatedAt,
refetchInterval,
isRefetchingQuote,
isTxPending,
} = quote;

if (!selectedQuote) return null;
Expand Down Expand Up @@ -328,6 +330,7 @@ const TransferDetails: FunctionComponent<
className="flex !h-12 !w-12 items-center justify-center rounded-full md:!h-8 md:!w-8"
dataUpdatedAt={selectedQuoteUpdatedAt}
refetchInterval={refetchInterval}
isPaused={isRefetchingQuote || isTxPending}
strokeWidth={2}
>
<Icon id="down-arrow" className="md:h-4 md:w-4" />
Expand Down

0 comments on commit 6db1321

Please sign in to comment.