Skip to content

Commit

Permalink
fix: change form values before animation makes the change visible
Browse files Browse the repository at this point in the history
  • Loading branch information
dib542 committed May 16, 2024
1 parent b11da0d commit 7512029
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/components/cards/LimitOrderCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,19 @@ function LimitOrder({ tokenA, tokenB }: { tokenA: Token; tokenB: Token }) {
const [expiration, setExpiration] = useState<ExpirationOptions>('none');
// allow an expiration change to change the custom time amount and period
const switchExpiration = useCallback(
(expiration: ExpirationOptions) => {
setExpiration(expiration);
const timeParts = expiration.split(' ') as [string, TimePeriod];
if (timeParts.length > 1) {
const [timeAmount, timePeriod] = timeParts;
formSetState.setTimeAmount?.(timeAmount);
formSetState.setTimePeriod?.(timePeriod);
(newExpiration: ExpirationOptions) => {
// when selecting custom time: prefill the form with the previous shortcut
if (newExpiration === 'custom') {
const timeParts = expiration.split(' ') as [string, TimePeriod];
if (timeParts.length > 1) {
const [timeAmount, timePeriod] = timeParts;
formSetState.setTimeAmount?.(timeAmount);
formSetState.setTimePeriod?.(timePeriod);
}
}
setExpiration(newExpiration);
},
[formSetState]
[formSetState, expiration]
);
const hasExpiry = expiration !== 'none';

Expand Down

0 comments on commit 7512029

Please sign in to comment.