Skip to content

Commit

Permalink
feat(interest): form validation withdraw coin
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Jun 6, 2020
1 parent fca7480 commit 4767dbf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
Expand Up @@ -73,9 +73,10 @@ export type State = {
}

export type SuccessStateType = {
accountBalances: InterestAccountBalanceType
availToWithdrawFiat: number
coin: CoinType
accountBalanceStandard: number,
accountBalances: InterestAccountBalanceType,
availToWithdrawFiat: number,
coin: CoinType,
interestLimits: InterestLimitsType
lockedCoin: number
rates: RatesType
Expand Down
Expand Up @@ -23,6 +23,10 @@ export const getData = state => {
interestLimits
) => ({
accountBalances,
accountBalanceStandard: convertBaseToStandard(
coin,
accountBalances[coin].balance
),
lockedCoin: convertBaseToStandard(coin, accountBalances[coin].locked),
availToWithdrawFiat:
Exchange.convertCoinToFiat(
Expand Down
Expand Up @@ -126,14 +126,16 @@ const WithdrawalForm: React.FC<InjectedFormProps<{}, Props> &
Props> = props => {
const {
accountBalances,
lockedCoin,

availToWithdrawFiat,
coin,
accountBalanceStandard,
displayCoin,
formActions,
handleDisplayToggle,
interestActions,
invalid,
lockedCoin,
rates,
submitting,
supportedCoins,
Expand All @@ -148,13 +150,13 @@ const WithdrawalForm: React.FC<InjectedFormProps<{}, Props> &
const currencySymbol = Exchange.getSymbol(walletCurrency) as string
const { coinTicker, displayName } = supportedCoins[coin]
const account = accountBalances[coin]
const accountCryptoBalance = account && account.balance
const accountInterestBalance = account && account.totalInterest
const withdrawalAmount = (values && values.withdrawalAmount) || 0

const withdrawalAmountFiat = displayCoin
? Exchange.convertCoinToFiat(withdrawalAmount, coin, walletCurrency, rates)
: formatFiat(withdrawalAmount)

const withdrawalAmountCrypto = displayCoin
? withdrawalAmount
: Exchange.convertFiatToBtc({
Expand All @@ -177,18 +179,12 @@ const WithdrawalForm: React.FC<InjectedFormProps<{}, Props> &
baseToStandard: true
}).value

const coinBalanceStandard = Exchange.convertCoinToCoin({
value: accountCryptoBalance || 0,
coin: 'BTC',
baseToStandard: true
}).value

const interestBalanceStandard = Exchange.convertCoinToCoin({
value: accountInterestBalance || 0,
coin: 'BTC',
baseToStandard: true
}).value
const availToWithdrawCrypto = coinBalanceStandard - lockedCoin
const availToWithdrawCrypto = accountBalanceStandard - lockedCoin

if (!account) return null

Expand Down Expand Up @@ -253,7 +249,7 @@ const WithdrawalForm: React.FC<InjectedFormProps<{}, Props> &
style={{ marginTop: '8px' }}
weight={600}
>
{coinBalanceStandard}
{accountBalanceStandard}
</Text>
) : (
<FiatDisplay
Expand Down
Expand Up @@ -9,16 +9,30 @@ export const maximumWithdrawalAmount = (
allValues: InterestWithdrawalFormType,
props: any
) => {
return new BigNumber(Number(props.availToWithdraw)).isLessThan(
Number(value)
) ? (
<FormattedMessage
id='interest.withdrawal.validation.abovemax'
defaultMessage='Amount is above the maximum withdrawal amount.'
/>
) : (
false
)
const availToWithdrawCrypto = props.accountBalanceStandard - props.lockedCoin
if (props.displayCoin) {
return new BigNumber(Number(availToWithdrawCrypto)).isLessThan(
Number(value)
) ? (
<FormattedMessage
id='interest.withdrawal.validation.abovemax'
defaultMessage='Amount is above the maximum withdrawal amount.'
/>
) : (
false
)
} else {
return new BigNumber(Number(props.availToWithdraw)).isLessThan(
Number(value)
) ? (
<FormattedMessage
id='interest.withdrawal.validation.abovemax'
defaultMessage='Amount is above the maximum withdrawal amount.'
/>
) : (
false
)
}
}

export const minimumWithdrawalAmount = (value: string) => {
Expand Down

0 comments on commit 4767dbf

Please sign in to comment.