-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): restore kwenta redeem function (#1041)
- Loading branch information
Showing
11 changed files
with
276 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Head from 'next/head' | ||
import { FC, ReactNode } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import DashboardLayout from 'sections/dashboard/DashboardLayout' | ||
import RedemptionTab from 'sections/dashboard/RedemptionTab' | ||
|
||
type RedemptionComponent = FC & { getLayout: (page: ReactNode) => JSX.Element } | ||
|
||
const RedeemPage: RedemptionComponent = () => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>{t('dashboard-redeem.page-title')}</title> | ||
</Head> | ||
<RedemptionTab /> | ||
</> | ||
) | ||
} | ||
|
||
RedeemPage.getLayout = (page) => <DashboardLayout>{page}</DashboardLayout> | ||
|
||
export default RedeemPage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useTranslation } from 'react-i18next' | ||
import styled from 'styled-components' | ||
|
||
import { FlexDivRowCentered } from 'components/layout/flex' | ||
import { SplitContainer } from 'components/layout/grid' | ||
import { Heading } from 'components/Text' | ||
import media from 'styles/media' | ||
|
||
import RedeemInputCard from './Stake/InputCards/RedeempInputCard' | ||
|
||
const RedemptionTab = () => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<Container> | ||
<TitleContainer> | ||
<StyledHeading variant="h4">{t('dashboard.stake.tabs.redeem.title')}</StyledHeading> | ||
</TitleContainer> | ||
<SplitContainer> | ||
<RedeemInputCard | ||
inputLabel={t('dashboard.stake.tabs.stake-table.vkwenta-token')} | ||
isVKwenta | ||
/> | ||
<RedeemInputCard | ||
inputLabel={t('dashboard.stake.tabs.stake-table.vekwenta-token')} | ||
isVKwenta={false} | ||
/> | ||
</SplitContainer> | ||
</Container> | ||
) | ||
} | ||
|
||
const StyledHeading = styled(Heading)` | ||
font-weight: 400; | ||
` | ||
|
||
const TitleContainer = styled(FlexDivRowCentered)` | ||
margin: 30px 0px; | ||
column-gap: 10%; | ||
` | ||
|
||
const Container = styled.div` | ||
${media.lessThan('lg')` | ||
padding: 0px 15px; | ||
`} | ||
margin-top: 20px; | ||
` | ||
|
||
export default RedemptionTab |
130 changes: 130 additions & 0 deletions
130
packages/app/src/sections/dashboard/Stake/InputCards/RedeempInputCard.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,130 @@ | ||
import { truncateNumbers } from '@kwenta/sdk/utils' | ||
import { FC, useCallback, useMemo } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import styled from 'styled-components' | ||
|
||
import Button from 'components/Button' | ||
import ErrorView from 'components/ErrorView' | ||
import { FlexDivRowCentered } from 'components/layout/flex' | ||
import { StakingCard } from 'sections/dashboard/Stake/card' | ||
import { useAppDispatch, useAppSelector } from 'state/hooks' | ||
import { approveKwentaToken, redeemToken } from 'state/staking/actions' | ||
import { | ||
selectIsVeKwentaTokenApproved, | ||
selectIsVKwentaTokenApproved, | ||
selectVeKwentaBalance, | ||
selectVKwentaBalance, | ||
} from 'state/staking/selectors' | ||
import { selectDisableRedeemEscrowKwenta } from 'state/stakingMigration/selectors' | ||
import { numericValueCSS } from 'styles/common' | ||
|
||
type RedeemInputCardProps = { | ||
inputLabel: string | ||
isVKwenta: boolean | ||
} | ||
|
||
const RedeemInputCard: FC<RedeemInputCardProps> = ({ inputLabel, isVKwenta }) => { | ||
const { t } = useTranslation() | ||
const dispatch = useAppDispatch() | ||
|
||
const vKwentaBalance = useAppSelector(selectVKwentaBalance) | ||
const veKwentaBalance = useAppSelector(selectVeKwentaBalance) | ||
const isVKwentaApproved = useAppSelector(selectIsVKwentaTokenApproved) | ||
const isVeKwentaApproved = useAppSelector(selectIsVeKwentaTokenApproved) | ||
const VeKwentaDisableRedeem = useAppSelector(selectDisableRedeemEscrowKwenta) | ||
|
||
const isApproved = useMemo( | ||
() => (isVKwenta ? isVKwentaApproved : isVeKwentaApproved), | ||
[isVKwenta, isVKwentaApproved, isVeKwentaApproved] | ||
) | ||
|
||
const balance = useMemo( | ||
() => (isVKwenta ? vKwentaBalance : veKwentaBalance), | ||
[isVKwenta, vKwentaBalance, veKwentaBalance] | ||
) | ||
|
||
const DisableRedeem = useMemo( | ||
() => (isVKwenta ? false : VeKwentaDisableRedeem), | ||
[isVKwenta, VeKwentaDisableRedeem] | ||
) | ||
|
||
const buttonLabel = useMemo(() => { | ||
return isApproved | ||
? t('dashboard.stake.tabs.stake-table.redeem') | ||
: t('dashboard.stake.tabs.stake-table.approve') | ||
}, [isApproved, t]) | ||
|
||
const submitRedeem = useCallback(() => { | ||
const token = isVKwenta ? 'vKwenta' : 'veKwenta' | ||
|
||
if (!isApproved) { | ||
dispatch(approveKwentaToken(token)) | ||
} else { | ||
dispatch(redeemToken(token)) | ||
} | ||
}, [dispatch, isApproved, isVKwenta]) | ||
|
||
return ( | ||
<> | ||
<StakingInputCardContainer> | ||
<div> | ||
<StakeInputHeader> | ||
<div>{inputLabel}</div> | ||
<StyledFlexDivRowCentered> | ||
<div>{t('dashboard.stake.tabs.stake-table.balance')}</div> | ||
<div className="max">{truncateNumbers(balance, 4)}</div> | ||
</StyledFlexDivRowCentered> | ||
</StakeInputHeader> | ||
</div> | ||
{DisableRedeem ? ( | ||
<ErrorView | ||
messageType="warn" | ||
message={t('dashboard.stake.tabs.redeem.warning')} | ||
containerStyle={{ | ||
margin: '0', | ||
marginTop: '25px', | ||
padding: '10px 0', | ||
}} | ||
/> | ||
) : ( | ||
<Button | ||
fullWidth | ||
variant="flat" | ||
size="small" | ||
disabled={balance.eq(0) || DisableRedeem} | ||
onClick={submitRedeem} | ||
> | ||
{buttonLabel} | ||
</Button> | ||
)} | ||
</StakingInputCardContainer> | ||
</> | ||
) | ||
} | ||
|
||
const StyledFlexDivRowCentered = styled(FlexDivRowCentered)` | ||
column-gap: 5px; | ||
` | ||
|
||
const StakingInputCardContainer = styled(StakingCard)` | ||
min-height: 125px; | ||
max-height: 250px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
` | ||
|
||
const StakeInputHeader = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 10px; | ||
color: ${(props) => props.theme.colors.selectedTheme.title}; | ||
font-size: 14px; | ||
.max { | ||
color: ${(props) => props.theme.colors.selectedTheme.button.text.primary}; | ||
${numericValueCSS}; | ||
} | ||
` | ||
|
||
export default RedeemInputCard |
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
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