-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(widget): deadline widget param (#4991)
* feat: add deadlines widget parameter * refactor: remove dead code * feat: rename OrderDeadlines to ForcedOrderDeadline and use FlexibleConfig * feat: add useInjectedWidgetDeadline * fix: add spaces to tooltip * feat: use widget deadline on swap form * chore: remove duplicated css property * feat: use widget deadline on limit form * feat: use widget deadline on twap form * chore: remove debug logs * chore: fix build * fix: round timestamp * refactor: rename limitOrdersDeadlines to LIMIT_ORDERS_DEADLINES * fix: use deadlineMilliseconds instead of customDeadline for forcedOrderDeadline * fix: allow deadline input to be cleared * fix: add chainId to hook deps
- Loading branch information
1 parent
0f53ad2
commit ce3b5b8
Showing
19 changed files
with
324 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
apps/cowswap-frontend/src/modules/injectedWidget/hooks/useInjectedWidgetDeadline.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { isInjectedWidget } from '@cowprotocol/common-utils' | ||
import { useWalletInfo } from '@cowprotocol/wallet' | ||
import { ForcedOrderDeadline, resolveFlexibleConfig, SupportedChainId, TradeType } from '@cowprotocol/widget-lib' | ||
|
||
import { useInjectedWidgetParams } from './useInjectedWidgetParams' | ||
|
||
/** | ||
* Returns the deadline set in the widget for the specific order type in minutes, if any | ||
* | ||
* Additional validation is needed | ||
*/ | ||
export function useInjectedWidgetDeadline(tradeType: TradeType): number | undefined { | ||
const { forcedOrderDeadline } = useInjectedWidgetParams() | ||
const { chainId } = useWalletInfo() | ||
|
||
return useMemo(() => { | ||
if (!isInjectedWidget()) { | ||
return | ||
} | ||
|
||
return getDeadline(forcedOrderDeadline, chainId, tradeType) | ||
}, [tradeType, forcedOrderDeadline, chainId]) | ||
} | ||
|
||
function getDeadline(deadline: ForcedOrderDeadline | undefined, chainId: SupportedChainId, tradeType: TradeType) { | ||
if (!deadline) { | ||
return | ||
} | ||
|
||
return resolveFlexibleConfig(deadline, chainId, tradeType) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.