Skip to content

Commit

Permalink
cancel order
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser committed Aug 25, 2023
1 parent fa41c78 commit 07ca9eb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 44 deletions.
42 changes: 9 additions & 33 deletions centrifuge-app/src/components/InvestRedeem/InvestRedeem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import {
Thumbnail,
useControlledState,
} from '@centrifuge/fabric'
import css from '@styled-system/css'
import Decimal from 'decimal.js-light'
import { Field, FieldProps, Form, FormikErrors, FormikProvider, useFormik } from 'formik'
import * as React from 'react'
import { useHistory, useParams } from 'react-router-dom'
import styled from 'styled-components'
import { ethConfig } from '../../config'
import { Dec } from '../../utils/Decimal'
import { formatBalance, roundDown } from '../../utils/formatting'
Expand All @@ -47,6 +45,7 @@ import { LoadBoundary } from '../LoadBoundary'
import { Spinner } from '../Spinner'
import { AnchorTextLink } from '../TextLink'
import { InvestRedeemProvider, useInvestRedeem } from './InvestRedeemProvider'
import { LightButton } from './LightButton'
import { InvestRedeemState as InvestRedeemContextState } from './types'

export type ActionsRef = React.MutableRefObject<
Expand Down Expand Up @@ -786,31 +785,6 @@ const SuccessBanner: React.FC<{ title: string; body?: string }> = ({ title, body
)
}

const LightButton = styled.button<{ $left?: boolean }>(
{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
border: 0,
appearance: 'none',
height: 36,
cursor: 'pointer',
},
(props) =>
css({
color: 'textPrimary',
borderBottomLeftRadius: props.$left ? 'card' : undefined,
borderBottomRightRadius: props.$left ? undefined : 'card',
backgroundColor: 'secondarySelectedBackground',
'&:hover, &:focus-visible': {
color: 'textSelected',
},
'&:disabled': {
cursor: 'not-allowed',
},
})
)

const PendingOrder: React.FC<{
type: 'invest' | 'redeem'
amount: Decimal
Expand Down Expand Up @@ -846,7 +820,7 @@ const PendingOrder: React.FC<{
</Text>
</Stack>
<Grid gap="1px" columns={2} equalColumns>
<LightButton type="button" $left onClick={onCancelOrder} disabled={isCancelling || calculatingOrders}>
<LightButton type="button" onClick={onCancelOrder} disabled={isCancelling || calculatingOrders}>
{isCancelling ? (
<Spinner size="iconSmall" />
) : (
Expand All @@ -855,11 +829,13 @@ const PendingOrder: React.FC<{
</Text>
)}
</LightButton>
<LightButton type="button" onClick={onChangeOrder} disabled={isCancelling || calculatingOrders}>
<Text variant="body2" color="inherit">
Change order
</Text>
</LightButton>
{state.canChangeOrder && (
<LightButton type="button" onClick={onChangeOrder} disabled={isCancelling || calculatingOrders}>
<Text variant="body2" color="inherit">
Change order
</Text>
</LightButton>
)}
</Grid>
</Stack>
<TransactionsLink />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export function InvestRedeemCentrifugeProvider({ poolId, trancheId, children }:
needsToCollectBeforeOrder: false,
needsPoolCurrencyApproval: false,
needsTrancheTokenApproval: false,
canChangeOrder: true,
pendingAction,
pendingTransaction: pendingAction && txActions[pendingAction]?.lastCreatedTransaction,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export function InvestRedeemLiquidityPoolsProvider({ poolId, trancheId, children
needsToCollectBeforeOrder: investToCollect.gt(0) || currencyToCollect.gt(0),
needsPoolCurrencyApproval: lpInvest?.managerCurrencyAllowance.isZero() ?? false,
needsTrancheTokenApproval: lpInvest?.managerTrancheTokenAllowance.isZero() ?? false,
canChangeOrder: false,
pendingAction,
pendingTransaction: pendingAction && txActions[pendingAction]?.lastCreatedTransaction,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export function InvestRedeemTinlakeProvider({ poolId, trancheId, children }: Pro
needsToCollectBeforeOrder: !collectAmount.isZero(),
needsPoolCurrencyApproval: !!trancheInvestment?.poolCurrencyAllowance.isZero(),
needsTrancheTokenApproval: !!trancheInvestment?.tokenAllowance.isZero(),
canChangeOrder: true,
pendingAction,
pendingTransaction: pendingAction && txActions[pendingAction]?.lastCreatedTransaction,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import css from '@styled-system/css'
import styled from 'styled-components'

export const LightButton = styled.button<{ $left?: boolean; $right?: boolean }>(
export const LightButton = styled.button(
{
display: 'flex',
justifyContent: 'center',
Expand All @@ -14,14 +14,18 @@ export const LightButton = styled.button<{ $left?: boolean; $right?: boolean }>(
(props) =>
css({
color: 'textPrimary',
borderBottomLeftRadius: props.$left ? 'card' : undefined,
borderBottomRightRadius: props.$right ? 'card' : undefined,
backgroundColor: 'secondarySelectedBackground',
'&:hover, &:focus-visible': {
color: 'textSelected',
},
'&:disabled': {
cursor: 'not-allowed',
},
'&:first-child': {
borderBottomLeftRadius: 'card',
},
'&:last-child': {
borderBottomRightRadius: 'card',
},
})
)
1 change: 1 addition & 0 deletions centrifuge-app/src/components/InvestRedeem/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type InvestRedeemState = {
needsToCollectBeforeOrder: boolean
needsPoolCurrencyApproval: boolean
needsTrancheTokenApproval: boolean
canChangeOrder: boolean
pendingAction?: InvestRedeemAction | null
pendingTransaction?: Transaction | null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Box, Divider, Grid, IconCheckInCircle, Shelf, Stack, Text } from '@cent
import * as React from 'react'
import { millisecondsToDays } from '../../utils/date'
import { formatBalance } from '../../utils/formatting'
import { LightButton } from '../InvestRedeem/LightButton'
import { useActiveEpochData } from './hooks'
import { LightButton } from './LightButton'
import { useLiquidityRewards } from './LiquidityRewardsContext'

export function LiquidityRewardsStaker() {
Expand Down Expand Up @@ -69,19 +69,14 @@ export function LiquidityRewardsStaker() {

<Grid mt="1px" gap="1px" columns={canStake && canUnstake ? 2 : 1}>
{canStake && (
<LightButton onClick={stake} $left $right={!canUnstake} disabled={isLoading.unstake || isLoading.stake}>
<LightButton onClick={stake} disabled={isLoading.unstake || isLoading.stake}>
<Text variant="body2" color="inherit">
Stake
</Text>
</LightButton>
)}
{canUnstake && (
<LightButton
onClick={() => unstake()}
$left={!canStake}
$right
disabled={isLoading.unstake || isLoading.stake}
>
<LightButton onClick={() => unstake()} disabled={isLoading.unstake || isLoading.stake}>
<Text variant="body2" color="inherit">
Unstake
</Text>
Expand Down

0 comments on commit 07ca9eb

Please sign in to comment.