dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 69532bf4c3f0241577b1dff205efde72939b7003
parent 47f483529ff235a0346d2c99a6d8a1e79dfc7e58
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 13 Dec 2023 15:06:42 -0500

improve errors on withdraw form

Diffstat:
Mpkg/web/handlers/handlers.go | 19+++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -790,19 +790,22 @@ func PokerHomeHandler(c echo.Context) error { data.Error = "invalid xmr address" return c.Render(http.StatusOK, "poker", data) } - withdrawChips := data.WithdrawAmount - userChips := authUser.GetChips(true) - chips := utils.Clamp(withdrawChips, minWithdrawAmount, userChips) - chips = utils.MinInt(chips, userChips) - if chips < minWithdrawAmount { // not enough for withdraw + withdrawAmount := data.WithdrawAmount + if withdrawAmount < minWithdrawAmount { data.Error = "minimum withdraw amount is 100 chips" return c.Render(http.StatusOK, "poker", data) } - authUser.IncrChips(-chips, true) + userChips := authUser.GetChips(true) + if withdrawAmount > userChips { + data.Error = fmt.Sprintf("maximum withdraw amount is %d chips", userChips) + return c.Render(http.StatusOK, "poker", data) + } + withdrawAmount = utils.Clamp(withdrawAmount, minWithdrawAmount, userChips) + authUser.IncrChips(-withdrawAmount, true) authUser.DoSave(db) - fee := int(pokerHouseFee * float64(chips)) - chips -= fee + fee := int(pokerHouseFee * float64(withdrawAmount)) + withdrawAmount -= fee res, err := config.Xmr().Transfer(&wallet1.RequestTransfer{ Destinations: []*wallet1.Destination{