-
Notifications
You must be signed in to change notification settings - Fork 45
refactor: form tabs #1730
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
Merged
Merged
refactor: form tabs #1730
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a15f5cb
refactor: manage loan tabs
DanielSchiavini 992bdab
fix: render cycle
DanielSchiavini 5957abb
feat: adapt soft liquidation
DanielSchiavini e8579b9
doc: FormTabs
DanielSchiavini 1f6825e
Merge branch 'main' of github.com:curvefi/curve-frontend into refacto…
DanielSchiavini c5fdc33
refactor: LoanCreateTabs
DanielSchiavini cd4101a
feat: FormTabs story
DanielSchiavini a45e4e0
refactor: VaultTabs
DanielSchiavini e703af0
refactor: remove rFormType from lend app
DanielSchiavini 15f69fc
feat: redirect to clean urls
DanielSchiavini ddc3e4e
fix: review comments
DanielSchiavini 47fcfa2
fix: getMarketPathname
DanielSchiavini 3523f81
fix: query errors
DanielSchiavini 8459e7b
chore: unused code & exports
DanielSchiavini e5c305f
fix: enable all fields for mint temporarily
DanielSchiavini 9c826fb
fix: review comments
DanielSchiavini 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 hidden or 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
66 changes: 66 additions & 0 deletions
66
apps/main/src/lend/components/PageLoanCreate/LoanCreateTabs.tsx
This file contains hidden or 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,66 @@ | ||
| import { useCallback } from 'react' | ||
| import LoanFormCreate from '@/lend/components/PageLoanCreate/LoanFormCreate' | ||
| import type { FormValues } from '@/lend/components/PageLoanCreate/types' | ||
| import { DEFAULT_FORM_VALUES } from '@/lend/components/PageLoanCreate/utils' | ||
| import networks from '@/lend/networks' | ||
| import useStore from '@/lend/store/useStore' | ||
| import { type MarketUrlParams, type PageContentProps } from '@/lend/types/lend.types' | ||
| import { CreateLoanForm } from '@/llamalend/features/borrow/components/CreateLoanForm' | ||
| import type { OnBorrowFormUpdate } from '@/llamalend/features/borrow/types' | ||
| import { hasLeverage } from '@/llamalend/llama.utils' | ||
| import { useCreateLoanMuiForm } from '@ui-kit/hooks/useFeatureFlags' | ||
| import { t } from '@ui-kit/lib/i18n' | ||
| import { type FormTab, FormTabs } from '@ui-kit/shared/ui/FormTabs/FormTabs' | ||
|
|
||
| type CreateLoanProps = PageContentProps<MarketUrlParams> | ||
|
|
||
| /** | ||
| * Callback that synchronizes the `ChartOhlc` component with the `RangeSlider` component in the new `BorrowTabContents`. | ||
| */ | ||
| const useOnFormUpdate = ({ api, market }: Pick<CreateLoanProps, 'api' | 'market'>): OnBorrowFormUpdate => | ||
| useCallback( | ||
| async ({ debt, userCollateral, range, slippage, leverageEnabled }) => { | ||
| const { setFormValues, setStateByKeys } = useStore.getState().loanCreate | ||
| const formValues: FormValues = { | ||
| ...DEFAULT_FORM_VALUES, | ||
| n: range, | ||
| debt: `${debt ?? ''}`, | ||
| userCollateral: `${userCollateral ?? ''}`, | ||
| } | ||
| await setFormValues(api, market, formValues, `${slippage}`, leverageEnabled) | ||
| setStateByKeys({ isEditLiqRange: true }) | ||
| }, | ||
| [api, market], | ||
| ) | ||
|
|
||
| function CreateLoanTab({ market, api, rChainId }: CreateLoanProps) { | ||
| const onLoanCreated = useStore((state) => state.loanCreate.onLoanCreated) | ||
| const onCreated = useCallback( | ||
| async () => api && market && (await onLoanCreated(api, market)), | ||
| [api, market, onLoanCreated], | ||
| ) | ||
| const onUpdate = useOnFormUpdate({ market, api }) | ||
| return ( | ||
| <CreateLoanForm networks={networks} chainId={rChainId} market={market} onUpdate={onUpdate} onCreated={onCreated} /> | ||
| ) | ||
| } | ||
|
|
||
| const LendCreateTabsNewMenu = [ | ||
| { value: 'create', label: t`Borrow`, component: CreateLoanTab }, | ||
| ] satisfies FormTab<CreateLoanProps>[] | ||
|
|
||
| const LendCreateTabsOldMenu = [ | ||
| { value: 'create', label: t`Create Loan`, component: LoanFormCreate }, | ||
| { | ||
| value: 'leverage', | ||
| label: t`Leverage`, | ||
| component: (p) => <LoanFormCreate {...p} isLeverage />, | ||
| visible: ({ market }) => market && hasLeverage(market), | ||
| }, | ||
| ] satisfies FormTab<CreateLoanProps>[] | ||
|
|
||
| export const LoanCreateTabs = (pageProps: CreateLoanProps) => { | ||
| const menu = useCreateLoanMuiForm() ? LendCreateTabsNewMenu : LendCreateTabsOldMenu | ||
| const shouldWrap = menu === LendCreateTabsOldMenu | ||
| return <FormTabs params={pageProps} menu={menu} shouldWrap={shouldWrap} /> | ||
| } | ||
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.