-
Notifications
You must be signed in to change notification settings - Fork 25
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
refactor: pool's Deposit, Withdraw and Swap forms #362
Open
amytsang
wants to merge
10
commits into
main
Choose a base branch
from
refactor/deposit-withdraw-swap-forms
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5e68ed6
refactor: TxInfoBar styles
amytsang e314b66
refactor: IconButton styles
amytsang 3e75f6c
refactor: AppFormWrapper height
amytsang ad56eb1
refactor: AlertBox
amytsang 7cfb659
task: add waitForTxStatuses
amytsang bdb2e1d
refactor: move showWrapped into global store
amytsang c8ba7bf
refactor: deposit, withdraw, swap and claim pool forms to use TanStack
amytsang 5fd15c6
task: add entities and features to locale list
amytsang 4ce226c
refactor: rename files
amytsang 10e87e2
task: partial feedback changes
amytsang 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
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
17 changes: 17 additions & 0 deletions
17
apps/main/src/components/PagePool/Claim/components/AlertRewardsNeedNudging.tsx
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,17 @@ | ||
import React from 'react' | ||
import { Trans } from '@lingui/macro' | ||
|
||
import AlertBox from '@/ui/AlertBox' | ||
|
||
const AlertRewardsNeedNudging: React.FC = () => { | ||
return ( | ||
<AlertBox alertType="info"> | ||
<Trans> | ||
This pool has CRV rewards that aren’t streaming yet. Click ‘Claim or Nudge CRV’ to resume | ||
reward streaming for you and everyone else! | ||
</Trans> | ||
</AlertBox> | ||
) | ||
} | ||
|
||
export default AlertRewardsNeedNudging |
14 changes: 14 additions & 0 deletions
14
apps/main/src/components/PagePool/Claim/components/BtnClaim.tsx
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,14 @@ | ||
import React from 'react' | ||
import { t } from '@lingui/macro' | ||
|
||
import Button from '@/ui/Button' | ||
|
||
const BtnClaim: React.FC = () => { | ||
return ( | ||
<Button disabled variant="filled" size="large"> | ||
{t`Claim`} | ||
</Button> | ||
) | ||
} | ||
|
||
export default BtnClaim |
46 changes: 46 additions & 0 deletions
46
apps/main/src/components/PagePool/Claim/components/BtnClaimCrv.tsx
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,46 @@ | ||
import type { ClaimableDetailsResp } from '@/entities/withdraw' | ||
|
||
import React from 'react' | ||
import { t } from '@lingui/macro' | ||
|
||
import { getClaimText } from '@/components/PagePool/Withdraw/utils' | ||
|
||
import Button from '@/ui/Button' | ||
|
||
type Props = { | ||
claimableCrv: string | ||
claimableRewards: ClaimableDetailsResp['claimableRewards'] | ||
isDisabled: boolean | ||
isPending: boolean | ||
isSuccess: boolean | ||
rewardsNeedNudgingAndHaveGauge: boolean | undefined | ||
handleClaimClick: () => void | ||
} | ||
|
||
const BtnClaimCrv: React.FC<Props> = ({ | ||
claimableCrv, | ||
claimableRewards, | ||
isDisabled, | ||
isPending, | ||
isSuccess, | ||
rewardsNeedNudgingAndHaveGauge, | ||
handleClaimClick, | ||
}) => { | ||
const haveClaimableCrvBtn = Number(claimableCrv) > 0 || !!rewardsNeedNudgingAndHaveGauge | ||
|
||
return ( | ||
<Button | ||
disabled={!haveClaimableCrvBtn || isDisabled || isSuccess} | ||
loading={isPending} | ||
variant="filled" | ||
size="large" | ||
onClick={handleClaimClick} | ||
> | ||
{isSuccess | ||
? t`Claimed` | ||
: getClaimText(claimableCrv, claimableRewards, 'CLAIM_CRV', 'claimCrvButton', rewardsNeedNudgingAndHaveGauge)} | ||
</Button> | ||
) | ||
} | ||
|
||
export default BtnClaimCrv |
32 changes: 32 additions & 0 deletions
32
apps/main/src/components/PagePool/Claim/components/BtnClaimRewards.tsx
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,32 @@ | ||
import type { ClaimableDetailsResp } from '@/entities/withdraw' | ||
|
||
import React from 'react' | ||
import { t } from '@lingui/macro' | ||
|
||
import Button from '@/ui/Button' | ||
|
||
type Props = { | ||
claimableRewards: ClaimableDetailsResp['claimableRewards'] | ||
isDisabled: boolean | ||
isPending: boolean | ||
isSuccess: boolean | ||
handleClaimClick: () => void | ||
} | ||
|
||
const BtnClaimRewards: React.FC<Props> = ({ claimableRewards, isDisabled, isPending, isSuccess, handleClaimClick }) => { | ||
const haveClaimableRewardsBtn = claimableRewards.length > 0 || isSuccess | ||
|
||
return ( | ||
<Button | ||
disabled={!haveClaimableRewardsBtn || isDisabled || isSuccess} | ||
loading={isPending} | ||
variant="filled" | ||
size="large" | ||
onClick={handleClaimClick} | ||
> | ||
{isSuccess ? t`Claimed` : t`Claim Rewards`} | ||
</Button> | ||
) | ||
} | ||
|
||
export default BtnClaimRewards |
22 changes: 22 additions & 0 deletions
22
apps/main/src/components/PagePool/Claim/components/DetailsClaimableCrv.tsx
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,22 @@ | ||
import React from 'react' | ||
|
||
import { formatNumber } from '@/ui/utils' | ||
import { useClaimContext } from '@/components/PagePool/Claim/contextClaim' | ||
|
||
import Stats from '@/ui/Stats' | ||
|
||
export const DetailsClaimableCrv = () => { | ||
const { claimableCrv, haveClaimableCrv, haveClaimableRewards } = useClaimContext() | ||
|
||
return ( | ||
<> | ||
{haveClaimableCrv && ( | ||
<Stats isOneLine isBorderBottom={haveClaimableRewards} label="CRV"> | ||
{formatNumber(claimableCrv)} | ||
</Stats> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default DetailsClaimableCrv |
25 changes: 25 additions & 0 deletions
25
apps/main/src/components/PagePool/Claim/components/DetailsClaimableRewards.tsx
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,25 @@ | ||
import React from 'react' | ||
|
||
import { formatNumber } from '@/ui/utils' | ||
import { useClaimContext } from '@/components/PagePool/Claim/contextClaim' | ||
|
||
import Stats from '@/ui/Stats' | ||
|
||
const DetailsClaimableRewards: React.FC = () => { | ||
const { claimableRewards } = useClaimContext() | ||
|
||
return ( | ||
<> | ||
{claimableRewards.map(({ token, symbol, amount }, idx) => { | ||
const showBottomBorder = idx !== claimableRewards.length - 1 | ||
return ( | ||
<Stats isOneLine isBorderBottom={showBottomBorder} key={token} label={symbol}> | ||
{formatNumber(amount)} | ||
</Stats> | ||
) | ||
})} | ||
</> | ||
) | ||
} | ||
|
||
export default DetailsClaimableRewards |
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,26 @@ | ||
import type { ClaimType, ClaimableDetailsResp } from '@/entities/withdraw' | ||
|
||
import React, { createContext, useContext } from 'react' | ||
|
||
type ClaimContextType = Pick<ClaimableDetailsResp, 'claimableCrv' | 'claimableRewards'> & { | ||
claimType: ClaimType | ||
haveClaimableCrv: boolean | ||
haveClaimableRewards: boolean | ||
haveClaimables: boolean | ||
isDisabled: boolean | ||
isLoading: boolean | ||
setClaimType: React.Dispatch<React.SetStateAction<ClaimType>> | ||
} | ||
|
||
export const ClaimContext = createContext<ClaimContextType | null>(null) | ||
export const ClaimContextProvider = ClaimContext.Provider | ||
|
||
export const useClaimContext = () => { | ||
const claimContext = useContext(ClaimContext) | ||
|
||
if (!claimContext) { | ||
throw new Error('useFormWithdraw has to be used within <ClaimContext.Provider>') | ||
} | ||
|
||
return claimContext | ||
} |
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.
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.
I understand you created the context so you don't have to use react-hook-forms?
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.
No, so I don't have to keep on passing it as a prop. This PR does not have anything to do with switching to react-hook-form
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, I can see why you did it. React-hook-forms also uses context to pass data between components, essentially does the same thing you did, but gives you the ability to work with the form. Migrating those forms to this library will be the next step.