trying to fix weird dollars behaviour

This commit is contained in:
forest 2021-12-14 01:46:33 -06:00
parent 9dc5f43fa0
commit 80802370a3

View File

@ -25,7 +25,7 @@ from capsulflask.shared import my_exec_info_message
bp = Blueprint("payment", __name__, url_prefix="/payment")
def validate_dollars(min: decimal.Decimal, max: decimal.Decimal):
def validate_dollars(min: float, max: float):
errors = list()
dollars = None
if "dollars" not in request.form:
@ -33,7 +33,7 @@ def validate_dollars(min: decimal.Decimal, max: decimal.Decimal):
else:
dollars = None
try:
dollars = decimal.Decimal(request.form["dollars"])
dollars = float(request.form["dollars"])
except:
errors.append("dollars must be a number")
@ -45,7 +45,7 @@ def validate_dollars(min: decimal.Decimal, max: decimal.Decimal):
errors.append(f"dollars must be less than {format(max, '.2f')}")
current_app.logger.info(f"{len(errors)} {errors}")
return [dollars, errors]
return (dollars, errors)
@bp.route("/btcpay", methods=("GET", "POST"))
@account_required
@ -57,7 +57,7 @@ def btcpay_payment():
return redirect(url_for("console.account_balance"))
if request.method == "POST":
dollars, errors = validate_dollars(decimal.Decimal(0.01), decimal.Decimal(1000))
dollars, errors = validate_dollars(0.01, 1000.0)
#current_app.logger.info(f"{len(errors)} {errors}")
if len(errors) == 0:
@ -150,7 +150,7 @@ def stripe_payment():
errors = list()
if request.method == "POST":
dollars, errors = validate_dollars(decimal.Decimal(0.5), decimal.Decimal(1000000))
dollars, errors = validate_dollars(0.5, 1000000)
if len(errors) == 0: