Skip to content

Commit

Permalink
fix max amount value
Browse files Browse the repository at this point in the history
  • Loading branch information
tuhalang committed May 9, 2021
1 parent 8636970 commit 5c132cf
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions ui/send_page.go
Expand Up @@ -983,15 +983,38 @@ func (pg *sendPage) fetchExchangeValue() {
}

func (pg *sendPage) setMaxAmount(c pageCommon) {

// Get spendable balance
sendWallet := c.info.Wallets[c.wallAcctSelector.selectedSendWallet]
sendAcct := sendWallet.Accounts[c.wallAcctSelector.selectedSendAccount]
spendableBalance := sendAcct.SpendableBalance

pg.getTxFee()
fee := pg.txFee
atomValue := sendAcct.SpendableBalance

// Estimate max send value
amount, err := pg.txAuthor.EstimateMaxSendAmount()
if err == nil {
atomValue = amount.AtomValue
dcrValue := amount.DcrValue
pg.updateAmountField(dcrValue)
pg.calculateValues(c, false)
}

spendableBalanceDCR := dcrutil.Amount(spendableBalance - fee).ToCoin()
// Adjust value
step := int64(10)
for {
_, err := pg.txAuthor.EstimateFeeAndSize()
if err != nil {
atomValue -= step
pg.updateAmountField(dcrutil.Amount(atomValue).ToCoin())
pg.calculateValues(c, false)
} else {
pg.updateAmountField(dcrutil.Amount(atomValue).ToCoin())
pg.calculateValues(c, false)
break
}
}
}

func (pg *sendPage) updateAmountField(spendableBalanceDCR float64) {
if !pg.usdExchangeSet {
pg.leftAmountEditor.Editor.SetText(strconv.FormatFloat(spendableBalanceDCR, 'f', 7, 64))
} else {
Expand All @@ -1008,8 +1031,6 @@ func (pg *sendPage) setMaxAmount(c pageCommon) {
pg.rightAmountEditor.Editor.SetText(strconv.FormatFloat(spendableBalanceUSD, 'f', 7, 64))
}
}

pg.calculateValues(c, false)
}

func (pg *sendPage) Handle(c pageCommon) {
Expand Down

0 comments on commit 5c132cf

Please sign in to comment.