Skip to content

Commit

Permalink
Take in to account transfer type when changing max
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Mar 27, 2023
1 parent 134a27d commit f1c258d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/app/pages/ParaTimesPage/TransactionAmount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ const StyledMaxButton = styled(Button)`
`

const getMaxAmount = (
isDepositing: boolean,
consensusDecimals: number,
layerDecimals: number,
balance: StringifiedBigInt,
feeAmount: string,
) => {
const fee = parseNanoRoseFeeAmountToBigNumber(feeAmount, layerDecimals)
const maxAmount = new BigNumber(balance)
.minus(fee)
.shiftedBy(-layerDecimals)
.decimalPlaces(consensusDecimals, BigNumber.ROUND_DOWN)
.toFixed()
const shiftBy = isDepositing ? consensusDecimals : layerDecimals
const fee = parseNanoRoseFeeAmountToBigNumber(feeAmount, shiftBy)
const maxAmount = new BigNumber(balance).minus(fee).shiftedBy(-shiftBy)

return maxAmount
// Make value valid for Consensus input
if (layerDecimals > consensusDecimals) {
maxAmount.decimalPlaces(consensusDecimals, BigNumber.ROUND_DOWN)
}

return maxAmount.toFixed()
}

export const TransactionAmount = () => {
Expand Down Expand Up @@ -149,6 +152,7 @@ export const TransactionAmount = () => {
isAmountGreaterThan(
amount,
getMaxAmount(
isDepositing,
consensusDecimals,
paraTimeConfig.decimals,
balance!,
Expand Down Expand Up @@ -186,6 +190,7 @@ export const TransactionAmount = () => {
setTransactionForm({
...transactionForm,
amount: getMaxAmount(
isDepositing,
consensusDecimals,
paraTimeConfig.decimals,
balance,
Expand Down

0 comments on commit f1c258d

Please sign in to comment.