Skip to content

Commit

Permalink
feat: allow expiration time shortcut to prefill custom expiration time
Browse files Browse the repository at this point in the history
  • Loading branch information
dib542 committed May 16, 2024
1 parent 4f0f5a6 commit b11da0d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/cards/LimitOrderCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ function LimitOrder({ tokenA, tokenB }: { tokenA: Token; tokenB: Token }) {
const formSetState = useContext(LimitOrderFormSetContext);

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);
}
},
[formSetState]
);
const hasExpiry = expiration !== 'none';

const switchModeTab = useCallback(
Expand Down Expand Up @@ -824,7 +837,7 @@ function LimitOrder({ tokenA, tokenB }: { tokenA: Token; tokenB: Token }) {
className="order-type-input text-s"
values={expirationOptions}
value={expiration}
onChange={setExpiration}
onChange={switchExpiration}
/>
</div>
</div>
Expand Down

0 comments on commit b11da0d

Please sign in to comment.