fix: stop trying to process payment more than once
All checks were successful
Build Docker / Build Image (push) Successful in 25s

This commit is contained in:
Nathan Woodburn 2024-02-14 23:02:23 +11:00
parent 607e11f8ec
commit ca5e54449c
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 37 additions and 3 deletions

15
main.py
View File

@ -86,7 +86,20 @@ def account():
link = accounts.getAccountLink(account)
webhook = accounts.getAccountWebhook(account)
return render_template('account.html', account=account, address=address, link=link, name=name, webhook=webhook)
userPayments = payments.getUserPayments(account)
userPayments = [payment for payment in userPayments if payment['status'] == 'Confirmed']
paymentHTML = '<ul class="list-group" style="max-width: 700px;margin: auto;">'
for payment in userPayments:
paymentHTML += f'<li class="list-group-item"><span>{payment["amount"]} HNS'
if payment['data']:
paymentHTML += f' - {payment["data"]}'
paymentHTML += '</span></li>'
paymentHTML += '</ul>'
return render_template('account.html', account=account, address=address, link=link, name=name, webhook=webhook, payments=paymentHTML)
@app.route('/account/edit', methods=['POST'])
def payout():

View File

@ -77,6 +77,14 @@ def check_payments():
continue
for address in addresses:
if tx['address'] == address['address']:
if 'hashes' in address:
if tx['txid'] in address['hashes']:
print("Already confirmed")
continue
address['hashes'].append(tx['txid'])
address['hashes'] = [tx['txid']]
address['status'] = 'Confirmed'
finalise_payment(address,tx)
@ -98,11 +106,22 @@ def generateAddress():
return resp.json()["address"]
def getUserPayments(email):
# Get all payments for a user
with open('data/addresses.json', 'r') as f:
addresses = json.load(f)
userPayments = []
for address in addresses:
if address['email'] == email:
userPayments.append(address)
return userPayments
def finalise_payment(payment,tx):
print(payment)
# Send webhook
print("Finalising payment")
print(payment)
print(tx)
email = payment['email']
payout = accounts.getAccountAddress(email)

View File

@ -49,7 +49,9 @@
</div>
</section>
<section>
<div>{{payments|safe}}</div>
<div>
<h1 class="text-center">Payment History</h1>{{payments|safe}}
</div>
</section>
<footer class="bg-dark">
<div class="container py-4 py-lg-5">