From f87f53919c4fbb31bfddd9fb7f2c23c9a44cc707 Mon Sep 17 00:00:00 2001 From: Rorry Date: Fri, 5 Apr 2024 12:24:06 -0300 Subject: [PATCH] fix(STK-233): update the logic on order creation flow for submitted dates --- packages/app/components/stackbox/Stackbox.tsx | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/app/components/stackbox/Stackbox.tsx b/packages/app/components/stackbox/Stackbox.tsx index 14f495b1..48021f60 100644 --- a/packages/app/components/stackbox/Stackbox.tsx +++ b/packages/app/components/stackbox/Stackbox.tsx @@ -57,9 +57,11 @@ interface SelectTokenButtonProps { onAnimationEnd: AnimationEventHandler; } -const START_TIME_MINUTES_OFFSET = 10; -const getDateNowPlus10Mins = () => - new Date().setMinutes(new Date().getMinutes() + START_TIME_MINUTES_OFFSET); +const PAST_TIME_MINUTES_OFFSET = 10; +const getDatePlus10Mins = (oldDate: Date) => + new Date(oldDate).setMinutes( + new Date(oldDate).getMinutes() + PAST_TIME_MINUTES_OFFSET + ); const frequencyOptions = [ { option: FREQUENCY_OPTIONS.hour, name: "Hour" }, @@ -199,7 +201,9 @@ export const Stackbox = () => { const startDate = startDateTime.getTime(); const endDate = endDateTime.getTime(); const isEndTimeBeforeStartTime = endDate <= startDate; - const isStartTimeInThePast = startDate <= Date.now(); + const isStartTimeInThePast = + startDate <= Date.now() && + new Date(startDate).getMinutes() <= new Date().getMinutes(); const isTokenAmountZero = tokenAmount === "0"; setShowPastEndDateError(isEndTimeBeforeStartTime); @@ -585,9 +589,15 @@ export const Stackbox = () => { amount={tokenAmount} frequency={frequency} startTime={ - isPastStartDate ? new Date(getDateNowPlus10Mins()) : startDateTime + isPastStartDate + ? new Date(getDatePlus10Mins(startDateTime)) + : startDateTime + } + endTime={ + isPastStartDate + ? new Date(getDatePlus10Mins(endDateTime)) + : endDateTime } - endTime={endDateTime} isOpen={isModalOpen(ModalId.CONFIRM_STACK)} closeAction={() => { closeModal(ModalId.CONFIRM_STACK);