From 8bea95fab2ce056ab9dd5a00601ae018b38ae1f0 Mon Sep 17 00:00:00 2001 From: Moody Salem Date: Wed, 12 May 2021 13:01:31 -0500 Subject: [PATCH] fix the transaction deadline errors --- src/components/Settings/index.tsx | 2 ++ src/components/TransactionSettings/index.tsx | 13 +++++++++---- src/state/user/reducer.ts | 7 ++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/Settings/index.tsx b/src/components/Settings/index.tsx index 8229cac170..8b8b9f77aa 100644 --- a/src/components/Settings/index.tsx +++ b/src/components/Settings/index.tsx @@ -94,6 +94,8 @@ const MenuFlyout = styled.span` ${({ theme }) => theme.mediaWidth.upToMedium` min-width: 18.125rem; `}; + + user-select: none; ` const Break = styled.div` diff --git a/src/components/TransactionSettings/index.tsx b/src/components/TransactionSettings/index.tsx index fb796dbf6c..8d68a4226d 100644 --- a/src/components/TransactionSettings/index.tsx +++ b/src/components/TransactionSettings/index.tsx @@ -136,11 +136,16 @@ export default function TransactionSettings({ placeholderSlippage }: Transaction if (value.length === 0) { setDeadline(DEFAULT_DEADLINE_FROM_NOW) } else { - const parsed: number = Math.floor(Number.parseFloat(value) * 60) - if (!Number.isInteger(parsed) || parsed < 60) { + try { + const parsed: number = Math.floor(Number.parseFloat(value) * 60) + if (!Number.isInteger(parsed) || parsed < 60 || parsed > 180 * 60) { + setDeadlineError(DeadlineError.InvalidInput) + } else { + setDeadline(parsed) + } + } catch (error) { + console.error(error) setDeadlineError(DeadlineError.InvalidInput) - } else { - setDeadline(parsed) } } } diff --git a/src/state/user/reducer.ts b/src/state/user/reducer.ts index 02755cc982..dfe1c574e9 100644 --- a/src/state/user/reducer.ts +++ b/src/state/user/reducer.ts @@ -96,7 +96,12 @@ export default createReducer(initialState, (builder) => // deadline isnt being tracked in local storage, reset to default // noinspection SuspiciousTypeOfGuard - if (typeof state.userDeadline !== 'number' || !Number.isInteger(state.userDeadline) || state.userDeadline < 60) { + if ( + typeof state.userDeadline !== 'number' || + !Number.isInteger(state.userDeadline) || + state.userDeadline < 60 || + state.userDeadline > 180 * 60 + ) { state.userDeadline = DEFAULT_DEADLINE_FROM_NOW }