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) @admin.register(LNPayment)
class LNPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin): 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') 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') list_filter = ('type','concept','status')
@admin.register(Profile) @admin.register(Profile)

View File

@ -111,13 +111,13 @@ class Logics():
# Do not change order status if an order in any with # Do not change order status if an order in any with
# any of these status is sent to expire here # 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.EXP, Order.Status.TLD,
Order.Status.DIS, Order.Status.CCA, Order.Status.DIS, Order.Status.CCA,
Order.Status.PAY, Order.Status.SUC, Order.Status.PAY, Order.Status.SUC,
Order.Status.FAI, Order.Status.MLD] Order.Status.FAI, Order.Status.MLD]
if order.status in do_nothing: if order.status in does_not_expire:
return False return False
elif order.status == Order.Status.WFB: elif order.status == Order.Status.WFB:
@ -283,7 +283,7 @@ class Logics():
if not order.taker_bond: if not order.taker_bond:
return False, {'bad_request':'Wait for your order to be taken.'} return False, {'bad_request':'Wait for your order to be taken.'}
if not (order.taker_bond.status == order.maker_bond.status == LNPayment.Status.LOCKED): 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'] num_satoshis = cls.buyer_invoice_amount(order, user)[1]['invoice_amount']
buyer_invoice = LNNode.validate_ln_invoice(invoice, num_satoshis) buyer_invoice = LNNode.validate_ln_invoice(invoice, num_satoshis)
@ -357,6 +357,17 @@ class Logics():
@classmethod @classmethod
def cancel_order(cls, order, user, state=None): 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 # 1) When maker cancels before bond
'''The order never shows up on the book and order '''The order never shows up on the book and order
status becomes "cancelled". That's it.''' status becomes "cancelled". That's it.'''
@ -685,8 +696,8 @@ class Logics():
@classmethod @classmethod
def confirm_fiat(cls, order, user): def confirm_fiat(cls, order, user):
''' If Order is in the CHAT states: ''' If Order is in the CHAT states:
If user is buyer: mark FIAT SENT! If user is buyer: fiat_sent goes to true.
If User is the seller and FIAT is SENT: Settle escrow and pay buyer invoice!''' 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 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.status = Order.Status.FSE
order.is_fiat_sent = True 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): elif cls.is_seller(order, user):
if not order.is_fiat_sent: 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.'} 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): # def add_arguments(self, parser):
# parser.add_argument('debug', nargs='+', type=boolean) # 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 ''' Continuously checks order expiration times for 1 hour. If order
has expires, it calls the logics module for expiration handling.''' has expires, it calls the logics module for expiration handling.'''
@ -53,3 +53,13 @@ class Command(BaseCommand):
if debug['num_expired_orders'] > 0: if debug['num_expired_orders'] > 0:
self.stdout.write(str(timezone.now())) self.stdout.write(str(timezone.now()))
self.stdout.write(str(debug)) 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): # def add_arguments(self, parser):
# parser.add_argument('debug', nargs='+', type=boolean) # parser.add_argument('debug', nargs='+', type=boolean)
def handle(self, *args, **options): def follow_invoices(self, *args, **options):
''' Follows and updates LNpayment objects ''' Follows and updates LNpayment objects
until settled or canceled''' until settled or canceled'''
@ -66,7 +66,7 @@ class Command(BaseCommand):
# If it fails at finding the invoice it has been canceled. # 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) # On RoboSats DB we make a distinction between cancelled and returned (LND does not)
if 'unable to locate invoice' in str(e): 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 hold_lnpayment.status = LNPayment.Status.CANCEL
# LND restarted. # LND restarted.
if 'wallet locked, unlock it' in str(e): if 'wallet locked, unlock it' in str(e):
@ -131,3 +131,14 @@ class Command(BaseCommand):
# halt the order # halt the order
if lnpayment.status == LNPayment.Status.LOCKED: 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 React, { Component } from 'react';
import { w3cwebsocket as W3CWebSocket } from "websocket"; import { w3cwebsocket as W3CWebSocket } from "websocket";
import {Button, TextField, Link, Grid, Typography, Container, Card, CardHeader, Paper, Avatar} from "@mui/material"; import {Button, TextField, Grid, Container, Card, CardHeader, Paper, Avatar, FormHelperText} from "@mui/material";
import { withStyles } from "@mui/material";
export default class Chat extends Component { export default class Chat extends Component {
@ -113,6 +111,7 @@ export default class Chat extends Component {
</Grid> </Grid>
</Grid> </Grid>
</form> </form>
<FormHelperText>This chat has no memory. If you reload the page messages are lost.</FormHelperText>
</Container> </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="h5" variant="h5">What is <i>RoboSats</i>?</Typography>
<Typography component="body2" variant="body2"> <Typography component="body2" variant="body2">
<p>It is a BTC/FIAT peer-to-peer exchange over lightning. It simplifies <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 <p>RoboSats is an open source project <a
href='https://github.com/reckless-satoshi/robosats'>(GitHub).</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="h5" variant="h5">How does it work?</Typography>
<Typography component="body2" variant="body2"> <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. 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 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 robots. Then, Alice posts the trade collateral also using a lightning
hold invoice. <i>RoboSats</i> locks the invoice until Bob confirms he sent hold invoice. <i>RoboSats</i> locks the invoice until Alice confirms she
the fiat to Alice. Once Alice confirms she received the fiat, she received the fiat. Then the satoshis to Bob. Enjoy your satoshis,
tells <i>RoboSats</i> to release the satoshis to Bob. Enjoy your satoshis,
Bob!</p> Bob!</p>
<p>At no point, AdequateAlice01 and BafflingBob02 have to trust the <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 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>
<Typography component="h5" variant="h5">What payment methods are accepted?</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 // If the order does not yet have an escrow deposited. Show dialog
// to confirm forfeiting the bond // to confirm forfeiting the bond
if (this.state.statusCode < 8){ if (this.state.statusCode in [0,1,3,6,7]){
return( return(
<Grid item xs={12} align="center"> <Grid item xs={12} align="center">
<this.CancelDialog/> <this.CancelDialog/>