Cancel frontend clean up. Try and go for management commands

This commit is contained in:
Reckless_Satoshi 2022-01-20 12:50:25 -08:00
parent 4eaad57475
commit fb5cb8fb4a
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
8 changed files with 53 additions and 24 deletions

View File

@ -32,9 +32,9 @@ class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
@admin.register(LNPayment)
class LNPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
list_display = ('hash','concept','status','num_satoshis','type','expires_at','sender_link','receiver_link','order_made','order_taken','order_escrow','order_paid')
list_display = ('hash','concept','status','num_satoshis','type','expires_at','sender_link','receiver_link','order_made_link','order_taken_link','order_escrow_link','order_paid_link')
list_display_links = ('hash','concept')
change_links = ('sender','receiver')
change_links = ('sender','receiver','order_made','order_taken','order_escrow','order_paid')
list_filter = ('type','concept','status')
@admin.register(Profile)

View File

@ -111,13 +111,13 @@ class Logics():
# Do not change order status if an order in any with
# any of these status is sent to expire here
do_nothing = [Order.Status.DEL, Order.Status.UCA,
does_not_expire = [Order.Status.DEL, Order.Status.UCA,
Order.Status.EXP, Order.Status.TLD,
Order.Status.DIS, Order.Status.CCA,
Order.Status.PAY, Order.Status.SUC,
Order.Status.FAI, Order.Status.MLD]
if order.status in do_nothing:
if order.status in does_not_expire:
return False
elif order.status == Order.Status.WFB:
@ -283,7 +283,7 @@ class Logics():
if not order.taker_bond:
return False, {'bad_request':'Wait for your order to be taken.'}
if not (order.taker_bond.status == order.maker_bond.status == LNPayment.Status.LOCKED):
return False, {'bad_request':'You cannot a invoice while bonds are not posted.'}
return False, {'bad_request':'You cannot submit a invoice while bonds are not locked.'}
num_satoshis = cls.buyer_invoice_amount(order, user)[1]['invoice_amount']
buyer_invoice = LNNode.validate_ln_invoice(invoice, num_satoshis)
@ -357,6 +357,17 @@ class Logics():
@classmethod
def cancel_order(cls, order, user, state=None):
# Do not change order status if an order in any with
# any of these status is sent to expire here
do_not_cancel = [Order.Status.DEL, Order.Status.UCA,
Order.Status.EXP, Order.Status.TLD,
Order.Status.DIS, Order.Status.CCA,
Order.Status.PAY, Order.Status.SUC,
Order.Status.FAI, Order.Status.MLD]
if order.status in do_not_cancel:
return False, {'bad_request':'You cannot cancel this order'}
# 1) When maker cancels before bond
'''The order never shows up on the book and order
status becomes "cancelled". That's it.'''
@ -685,8 +696,8 @@ class Logics():
@classmethod
def confirm_fiat(cls, order, user):
''' If Order is in the CHAT states:
If user is buyer: mark FIAT SENT!
If User is the seller and FIAT is SENT: Settle escrow and pay buyer invoice!'''
If user is buyer: fiat_sent goes to true.
If User is tseller and fiat_sent is true: settle the escrow and pay buyer invoice!'''
if order.status == Order.Status.CHA or order.status == Order.Status.FSE: # TODO Alternatively, if all collateral is locked? test out
@ -695,7 +706,7 @@ class Logics():
order.status = Order.Status.FSE
order.is_fiat_sent = True
# If seller and fiat was sent, SETTLE ESCROw AND PAY BUYER INVOICE
# If seller and fiat was sent, SETTLE ESCROW AND PAY BUYER INVOICE
elif cls.is_seller(order, user):
if not order.is_fiat_sent:
return False, {'bad_request':'You cannot confirm to have received the fiat before it is confirmed to be sent by the buyer.'}

View File

@ -11,7 +11,7 @@ class Command(BaseCommand):
# def add_arguments(self, parser):
# parser.add_argument('debug', nargs='+', type=boolean)
def handle(self, *args, **options):
def clean_orders(self, *args, **options):
''' Continuously checks order expiration times for 1 hour. If order
has expires, it calls the logics module for expiration handling.'''
@ -53,3 +53,13 @@ class Command(BaseCommand):
if debug['num_expired_orders'] > 0:
self.stdout.write(str(timezone.now()))
self.stdout.write(str(debug))
def handle(self, *args, **options):
''' Never mind database locked error, keep going, print them out'''
try:
self.clean_orders()
except Exception as e:
if 'database is locked' in str(e):
self.stdout.write('database is locked')
self.stdout.write(e)

View File

@ -27,7 +27,7 @@ class Command(BaseCommand):
# def add_arguments(self, parser):
# parser.add_argument('debug', nargs='+', type=boolean)
def handle(self, *args, **options):
def follow_invoices(self, *args, **options):
''' Follows and updates LNpayment objects
until settled or canceled'''
@ -66,7 +66,7 @@ class Command(BaseCommand):
# If it fails at finding the invoice it has been canceled.
# On RoboSats DB we make a distinction between cancelled and returned (LND does not)
if 'unable to locate invoice' in str(e):
self.stdout.write('unable to locate invoice')
self.stdout.write(str(e))
hold_lnpayment.status = LNPayment.Status.CANCEL
# LND restarted.
if 'wallet locked, unlock it' in str(e):
@ -130,4 +130,15 @@ class Command(BaseCommand):
# TODO If a lnpayment goes from LOCKED to INVGED. Totally weird
# halt the order
if lnpayment.status == LNPayment.Status.LOCKED:
pass
pass
def handle(self, *args, **options):
''' Never mind database locked error, keep going, print them out'''
try:
self.follow_invoices()
except Exception as e:
if 'database is locked' in str(e):
self.stdout.write('database is locked')
self.stdout.write(e)

View File

@ -1,2 +0,0 @@
2022-01-20 12:59:13.516882+00:00
{'num_expired_orders': 1, 'expired_orders': [{0: 'Order 56: SELL BTC for 40.0 USD was Public'}]}

View File

@ -1,8 +1,6 @@
import React, { Component } from 'react';
import { w3cwebsocket as W3CWebSocket } from "websocket";
import {Button, TextField, Link, Grid, Typography, Container, Card, CardHeader, Paper, Avatar} from "@mui/material";
import { withStyles } from "@mui/material";
import {Button, TextField, Grid, Container, Card, CardHeader, Paper, Avatar, FormHelperText} from "@mui/material";
export default class Chat extends Component {
@ -113,6 +111,7 @@ export default class Chat extends Component {
</Grid>
</Grid>
</form>
<FormHelperText>This chat has no memory. If you reload the page messages are lost.</FormHelperText>
</Container>
)
}

View File

@ -10,7 +10,7 @@ export default class InfoDialog extends Component {
<Typography component="h5" variant="h5">What is <i>RoboSats</i>?</Typography>
<Typography component="body2" variant="body2">
<p>It is a BTC/FIAT peer-to-peer exchange over lightning. It simplifies
matchmaking and minimizes the trust needed to trade with a peer.</p>
matchmaking and minimizes the need of trust. RoboSats focuses in privacy and speed.</p>
<p>RoboSats is an open source project <a
href='https://github.com/reckless-satoshi/robosats'>(GitHub).</a>
@ -19,18 +19,18 @@ export default class InfoDialog extends Component {
<Typography component="h5" variant="h5">How does it work?</Typography>
<Typography component="body2" variant="body2">
<p>Anonymous AdequateAlice01 wants to sell bitcoin. She posts a sell order.
<p> AnonymousAlice01 wants to sell bitcoin. She posts a sell order.
BafflingBob02 wants to buy bitcoin and he takes Alice's order.
Both have to post a small bond using lightning to prove they are real
robots. Then, Alice posts the trade collateral also using a lightning
hold invoice. <i>RoboSats</i> locks the invoice until Bob confirms he sent
the fiat to Alice. Once Alice confirms she received the fiat, she
tells <i>RoboSats</i> to release the satoshis to Bob. Enjoy your satoshis,
hold invoice. <i>RoboSats</i> locks the invoice until Alice confirms she
received the fiat. Then the satoshis to Bob. Enjoy your satoshis,
Bob!</p>
<p>At no point, AdequateAlice01 and BafflingBob02 have to trust the
bitcoin to each other. In case they have a conflict, <i>RoboSats</i> staff
will help resolving the dispute.</p>
will help resolving the dispute. You can find an step-by-step
description of the trade pipeline on our GitHub <a href='https://github.com/reckless-satoshi/robosats'>Readme</a></p>
</Typography>
<Typography component="h5" variant="h5">What payment methods are accepted?</Typography>

View File

@ -279,7 +279,7 @@ export default class OrderPage extends Component {
)}
// If the order does not yet have an escrow deposited. Show dialog
// to confirm forfeiting the bond
if (this.state.statusCode < 8){
if (this.state.statusCode in [0,1,3,6,7]){
return(
<Grid item xs={12} align="center">
<this.CancelDialog/>