From fb5cb8fb4aa33a8282e0371d64303f632e58f33d Mon Sep 17 00:00:00 2001
From: Reckless_Satoshi
Date: Thu, 20 Jan 2022 12:50:25 -0800
Subject: [PATCH] Cancel frontend clean up. Try and go for management commands
---
api/admin.py | 4 ++--
api/logics.py | 23 ++++++++++++++++------
api/management/commands/clean_orders.py | 12 ++++++++++-
api/management/commands/follow_invoices.py | 17 +++++++++++++---
clean_orders | 2 --
frontend/src/components/Chat.js | 5 ++---
frontend/src/components/InfoDialog.js | 12 +++++------
frontend/src/components/OrderPage.js | 2 +-
8 files changed, 53 insertions(+), 24 deletions(-)
delete mode 100644 clean_orders
diff --git a/api/admin.py b/api/admin.py
index 1cac1499..19875946 100644
--- a/api/admin.py
+++ b/api/admin.py
@@ -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)
diff --git a/api/logics.py b/api/logics.py
index 43c798df..2cb803e0 100644
--- a/api/logics.py
+++ b/api/logics.py
@@ -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.'}
diff --git a/api/management/commands/clean_orders.py b/api/management/commands/clean_orders.py
index 9d4cfc67..923ba3e7 100644
--- a/api/management/commands/clean_orders.py
+++ b/api/management/commands/clean_orders.py
@@ -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)
diff --git a/api/management/commands/follow_invoices.py b/api/management/commands/follow_invoices.py
index 5a9840bd..c88ee749 100644
--- a/api/management/commands/follow_invoices.py
+++ b/api/management/commands/follow_invoices.py
@@ -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
\ No newline at end of file
+ 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)
\ No newline at end of file
diff --git a/clean_orders b/clean_orders
deleted file mode 100644
index dbc4464b..00000000
--- a/clean_orders
+++ /dev/null
@@ -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'}]}
diff --git a/frontend/src/components/Chat.js b/frontend/src/components/Chat.js
index e1b3dc22..d38441fd 100644
--- a/frontend/src/components/Chat.js
+++ b/frontend/src/components/Chat.js
@@ -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 {
+ This chat has no memory. If you reload the page messages are lost.
)
}
diff --git a/frontend/src/components/InfoDialog.js b/frontend/src/components/InfoDialog.js
index f48ac387..d06baf6b 100644
--- a/frontend/src/components/InfoDialog.js
+++ b/frontend/src/components/InfoDialog.js
@@ -10,7 +10,7 @@ export default class InfoDialog extends Component {
What is RoboSats?
It is a BTC/FIAT peer-to-peer exchange over lightning. It simplifies
- matchmaking and minimizes the trust needed to trade with a peer.
+ matchmaking and minimizes the need of trust. RoboSats focuses in privacy and speed.
RoboSats is an open source project (GitHub).
@@ -19,18 +19,18 @@ export default class InfoDialog extends Component {
How does it work?
- Anonymous AdequateAlice01 wants to sell bitcoin. She posts a sell order.
+
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. RoboSats locks the invoice until Bob confirms he sent
- the fiat to Alice. Once Alice confirms she received the fiat, she
- tells RoboSats to release the satoshis to Bob. Enjoy your satoshis,
+ hold invoice. RoboSats locks the invoice until Alice confirms she
+ received the fiat. Then the satoshis to Bob. Enjoy your satoshis,
Bob!
At no point, AdequateAlice01 and BafflingBob02 have to trust the
bitcoin to each other. In case they have a conflict, RoboSats staff
- will help resolving the dispute.
+ will help resolving the dispute. You can find an step-by-step
+ description of the trade pipeline on our GitHub Readme
What payment methods are accepted?
diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js
index 6e5ebd0c..1b27044d 100644
--- a/frontend/src/components/OrderPage.js
+++ b/frontend/src/components/OrderPage.js
@@ -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(