Skip to content

Commit

Permalink
safe fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mstfash committed Mar 4, 2022
1 parent 7c99fe5 commit aa32459
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/containers/OnBoarding/ModifySafe.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from 'ethers'
import { BigNumber, ethers } from 'ethers'
import React, { useCallback, useMemo, useState } from 'react'
import styled from 'styled-components'
import Button from '../../components/Button'
Expand Down Expand Up @@ -90,20 +90,25 @@ const ModifySafe = ({
onLeftInput(availableEth as string)
}
}

const onMaxRightInput = () => {
if (isDeposit) {
onRightInput(availableRai.toString())
} else {
const availableRaiBN = ethers.utils.parseEther(availableRai)

const raiBalanceBN = ethers.utils.parseEther(
balances.rai.toString()
)
const raiBalanceBN = balances.rai
? ethers.utils.parseEther(balances.rai.toString())
: BigNumber.from('0')

const isMore = raiBalanceBN.gt(availableRaiBN)

onRightInput(
isMore ? availableRai.toString() : balances.rai.toString()
isMore
? availableRai.toString()
: balances.rai
? balances.rai.toString()
: '0'
)
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/hooks/useSafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getLiquidationPrice,
getRatePercentage,
returnAvaiableDebt,
returnPercentAmount,
returnTotalDebt,
returnTotalValue,
safeIsSafe,
Expand Down Expand Up @@ -261,6 +262,22 @@ export function useSafeInfo(type: SafeTypes = 'create') {
error = error ?? `RAI to repay cannot exceed owed amount`
}

if (!rightInputBN.isZero()) {
const repayPercent = returnPercentAmount(
rightInput,
availableRai as string
)

if (
rightInputBN.lt(BigNumber.from(availableRaiBN)) &&
repayPercent > 95
) {
error =
error ??
`You can only repay a minimum of ${availableRai} RAI to avoid leaving residual values`
}
}

if (!rightInputBN.isZero() && rightInputBN.gt(raiBalanceBN)) {
error = error ?? `balance_issue`
}
Expand Down

0 comments on commit aa32459

Please sign in to comment.