dkforest

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

commit a06e6b45e921ef56741c0d09ff22424704ca97c9
parent 96c4533a0c480f9b6df649386c3e7127caae4d6d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri, 15 Dec 2023 03:15:01 -0500

fix

Diffstat:
Mpkg/database/tableUsers.go | 4++--
Mpkg/web/handlers/handlers.go | 12++++++------
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -673,8 +673,8 @@ func (u *User) GetImage() (image.Image, error) { return b, nil } -func (u *User) GetXmrBalance(db *DkfDB) (amount int64, err error) { - var tmp struct{ XmrBalance int64 } +func (u *User) GetXmrBalance(db *DkfDB) (amount Piconero, err error) { + var tmp struct{ XmrBalance Piconero } err = db.db.Table("users").Select("xmr_balance").First(&tmp, "id = ?", u.ID).Error return tmp.XmrBalance, err } diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -873,19 +873,19 @@ func PokerHomeHandler(c echo.Context) error { dutils.RootAdminNotify(db, fmt.Sprintf("new withdraw %s xmr by %s", withdrawAmount.XmrStr(), authUser.Username)) tx := db.Begin() - if err := authUser.SubXmrBalance(tx, withdrawAmount+transactionFee); err != nil { + xmrBalance, err := authUser.GetXmrBalance(tx) + if err != nil { data.Error = err.Error() tx.Rollback() return c.Render(http.StatusOK, "poker", data) } - xmrBalance, err := authUser.GetXmrBalance(tx) - if err != nil { - data.Error = err.Error() + if withdrawAmount+transactionFee > xmrBalance { + data.Error = "not enough funds" tx.Rollback() return c.Render(http.StatusOK, "poker", data) } - if xmrBalance < 0 { - data.Error = "negative balance" + if err := authUser.SubXmrBalance(tx, withdrawAmount+transactionFee); err != nil { + data.Error = err.Error() tx.Rollback() return c.Render(http.StatusOK, "poker", data) }