-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3] feat(twap): add generic trade form validation to TWAP #2592
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
cf0074e
chore: group trade form states
shoom3301 cd8d21f
feat(trade-form-validation): validate basic trade form states
shoom3301 8a9845c
feat(trade-form-validation): component TradeFormButton
shoom3301 128dcf0
fix(trade-form-validation): extract primary validation from Limit orders
shoom3301 c5acec8
refactor(wrap-native-flow): narrow down WrapUnwrapContext
shoom3301 903c39b
feat(trade): add wrap native flow to TradeWidget
shoom3301 6570cab
feat(twap): add general trade form validation
shoom3301 16830fd
refactor: remove code duplicates by useTradeFormButtonContext
shoom3301 372a8b8
refactor: rename TradeFormButtons
shoom3301 6b91e98
Merge branch 'feat/2417' of https://github.com/cowprotocol/cowswap in…
shoom3301 bdf83fd
Merge branch 'feat/2417-1' of https://github.com/cowprotocol/cowswap …
shoom3301 d70b570
fix: fix performance issues
shoom3301 63a2dd9
refactor: refactor
shoom3301 7423946
Merge branch 'feat/2417' of https://github.com/cowprotocol/cowswap in…
shoom3301 9b1d871
refactor: refactor
shoom3301 c88e03f
Merge branch 'feat/2417-1' of https://github.com/cowprotocol/cowswap …
shoom3301 2382f45
refactor: refactor
shoom3301 d52111e
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 4e55ed9
Merge branch 'feat/2417' of https://github.com/cowprotocol/cowswap in…
shoom3301 e9b1d83
chore: fix style errors
shoom3301 ce25f41
Merge branch 'feat/2417-1' of https://github.com/cowprotocol/cowswap …
shoom3301 f9b0a61
chore: fix e2e test
shoom3301 3266be7
Merge branch 'feat/2417' of https://github.com/cowprotocol/cowswap in…
shoom3301 e91513d
Merge branch 'feat/2417-1' of https://github.com/cowprotocol/cowswap …
shoom3301 2177b62
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 ac8fbeb
refactor: align imports and fix namings
shoom3301 d1d0f78
Merge branch 'feat/2417' of https://github.com/cowprotocol/cowswap in…
shoom3301 486611b
fix(trade): change tokens places for wrap eth flow
shoom3301 5a7d5bd
Merge branch 'feat/2417-1' of https://github.com/cowprotocol/cowswap …
shoom3301 718a0a6
chore: merge changes
shoom3301 b382b45
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 42 additions & 0 deletions
42
src/modules/tradeFormValidation/hooks/useTradeFormButtonContext.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,42 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { useToggleWalletModal } from 'legacy/state/application/hooks' | ||
|
||
import { useWrapNativeFlow } from 'modules/trade' | ||
import { useDerivedTradeState } from 'modules/trade/hooks/useDerivedTradeState' | ||
import { useTradeQuote } from 'modules/tradeQuote' | ||
import { useWalletDetails } from 'modules/wallet' | ||
|
||
import { TradeFormButtonContext } from '../types' | ||
|
||
interface TradeFormCallbacks { | ||
doTrade(): void | ||
confirmTrade(): void | ||
} | ||
|
||
export function useTradeFormButtonContext( | ||
defaultText: string, | ||
callbacks: TradeFormCallbacks | ||
): TradeFormButtonContext | null { | ||
const { state: derivedState } = useDerivedTradeState() | ||
const wrapNativeFlow = useWrapNativeFlow() | ||
const { isSupportedWallet } = useWalletDetails() | ||
const quote = useTradeQuote() | ||
const toggleWalletModal = useToggleWalletModal() | ||
|
||
return useMemo(() => { | ||
if (!derivedState) return null | ||
|
||
return { | ||
defaultText, | ||
derivedState, | ||
quote, | ||
isSupportedWallet, | ||
...callbacks, | ||
wrapNativeFlow, | ||
connectWallet() { | ||
toggleWalletModal() | ||
}, | ||
} | ||
}, [defaultText, derivedState, quote, isSupportedWallet, callbacks, wrapNativeFlow, toggleWalletModal]) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './updaters/TradeFormValidationUpdater' | ||
export * from './hooks/useGetTradeFormValidation' | ||
export * from './hooks/useTradeFormButtonContext' | ||
export * from './pure/TradeFormButtons' | ||
export * from './pure/TradeFormBlankButton' | ||
export * from './types' |
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,43 @@ | ||
import React from 'react' | ||
|
||
import { useTradeConfirmActions } from 'modules/trade' | ||
import { TradeFormButtons, useGetTradeFormValidation } from 'modules/tradeFormValidation' | ||
import { useTradeFormButtonContext } from 'modules/tradeFormValidation' | ||
|
||
import { useSetupFallbackHandler } from '../../hooks/useSetupFallbackHandler' | ||
import { useTwapFormState } from '../../hooks/useTwapFormState' | ||
import { PrimaryActionButton } from '../../pure/PrimaryActionButton' | ||
|
||
export function ActionButtons() { | ||
const setFallbackHandler = useSetupFallbackHandler() | ||
const tradeConfirmActions = useTradeConfirmActions() | ||
const localFormValidation = useTwapFormState() | ||
const primaryFormValidation = useGetTradeFormValidation() | ||
|
||
const primaryActionContext = { | ||
setFallbackHandler, | ||
openConfirmModal: tradeConfirmActions.onOpen, | ||
} | ||
|
||
const confirmTrade = tradeConfirmActions.onOpen | ||
|
||
const tradeFormButtonContext = useTradeFormButtonContext('TWAP order', { doTrade: confirmTrade, confirmTrade }) | ||
|
||
if (!tradeFormButtonContext) return null | ||
|
||
if (!primaryFormValidation && localFormValidation) { | ||
return <PrimaryActionButton state={localFormValidation} context={primaryActionContext} /> | ||
} | ||
|
||
return ( | ||
<TradeFormButtons | ||
doTradeText="Place TWAP order" | ||
confirmText="Review TWAP order" | ||
validation={primaryFormValidation} | ||
context={tradeFormButtonContext} | ||
// TODO: bind isExpertMode to settings | ||
isExpertMode={false} | ||
isDisabled={false} | ||
/> | ||
) | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are still refactoring trade stuff, I say testing is needed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry for that :(
There are not so much changes in the existed code, anyway, there are