I'm writing a webapp in Flask. Within one of my routes, I have a function that listens to an API and waits for a payment to be registered. The function is called confirm(). I pass it in the render_template as confirm=confirm and I call it on the page using Jinja2: {{ confirm(cost) }}
I've realised that the function needs to be called asynchronously because otherwise the page doesn't load until the payment is made. However, I'm getting the titular error that the function needs to be awaited. Having read around, I've tried changing the route to async def qr() but Flask won't load it so I'm not sure how await should be used in this case.
async def confirm(cost):
json = { "action": "account_history", "account": app.config['NANO'], "count": 5, "raw": False, "reverse": False }
now = datetime.now()
delta = timedelta(seconds=60)
while datetime.now() < now+delta:
test = requests.post("https://nanoverse.io/api/node",json=json).json()
for item in test["history"]:
if item["amount"] == cost:
flash("Payment Received!")
break
else:
continue
break