From 032d3a1369616b8fbc1917329bedc6a85fe7dd02 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Fri, 14 Jan 2022 06:19:25 -0800 Subject: [PATCH] Add taker bond lock expiry --- api/logics.py | 9 ++------- api/views.py | 9 +++++---- frontend/src/components/OrderPage.js | 6 ++++-- frontend/src/components/TradeBox.js | 21 ++++++--------------- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/api/logics.py b/api/logics.py index c8da042a..bdf2ddd9 100644 --- a/api/logics.py +++ b/api/logics.py @@ -238,13 +238,7 @@ class Logics(): LNPayment "order.taker_bond" is deleted() ''' elif order.status == Order.Status.TAK and order.taker == user: # adds a timeout penalty - user.profile.penalty_expiration = timezone.now() + timedelta(seconds=PENALTY_TIMEOUT) - user.profile.save() - - order.taker = None - order.status = Order.Status.PUB - order.save() - + cls.kick_taker(order) return True, None # 4) When taker or maker cancel after bond (before escrow) @@ -395,6 +389,7 @@ class Logics(): created_at = hold_payment['created_at'], expires_at = hold_payment['expires_at']) + order.expires_at = timezone.now() + timedelta(seconds=EXP_TAKER_BOND_INVOICE) order.save() return True, {'bond_invoice': hold_payment['invoice'], 'bond_satoshis': bond_satoshis} diff --git a/api/views.py b/api/views.py index 4d428cab..b41826d8 100644 --- a/api/views.py +++ b/api/views.py @@ -122,12 +122,12 @@ class OrderView(viewsets.ViewSet): if not data['is_participant'] and order.status != Order.Status.PUB: return Response({'bad_request':'You are not allowed to see this order'},status.HTTP_403_FORBIDDEN) - # 3.b If public - if order.status == Order.Status.PUB: + # 3.b If order is between public and WF2 + if order.status >= Order.Status.PUB and order.status > Order.Status.WFB: data['price_now'], data['premium_now'] = Logics.price_and_premium_now(order) # 3. c) If maker and Public, add num robots in book, premium percentile and num similar orders. - if data['is_maker']: + if data['is_maker'] and order.status == Order.Status.PUB: data['robots_in_book'] = None # TODO data['premium_percentile'] = None # TODO data['num_similar_orders'] = len(Order.objects.filter(currency=order.currency, status=Order.Status.PUB)) @@ -227,10 +227,11 @@ class OrderView(viewsets.ViewSet): if order.status == Order.Status.PUB: valid, context = Logics.validate_already_maker_or_taker(request.user) if not valid: return Response(context, status=status.HTTP_409_CONFLICT) - valid, context = Logics.take(order, request.user) if not valid: return Response(context, status=status.HTTP_403_FORBIDDEN) + return self.get(request) + else: Response({'bad_request':'This order is not public anymore.'}, status.HTTP_400_BAD_REQUEST) # Any other action is only allowed if the user is a participant diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js index 5a1820c9..30e01a08 100644 --- a/frontend/src/components/OrderPage.js +++ b/frontend/src/components/OrderPage.js @@ -41,6 +41,7 @@ export default class OrderPage extends Component { delay: 60000, // Refresh every 60 seconds by default currencies_dict: {"1":"USD"}, total_secs_expiry: 300, + loading: true, }; this.orderId = this.props.match.params.orderId; this.getCurrencyDict(); @@ -53,6 +54,7 @@ export default class OrderPage extends Component { .then((response) => response.json()) .then((data) => {console.log(data) & this.setState({ + loading: false, id: data.id, statusCode: data.status, statusText: data.status_message, @@ -294,7 +296,7 @@ export default class OrderPage extends Component { - + @@ -380,7 +382,7 @@ export default class OrderPage extends Component { render (){ return ( // Only so nothing shows while requesting the first batch of data - (this.state.statusCode == null & this.state.badRequest == null) ? : this.orderDetailsPage() + this.state.loading ? : this.orderDetailsPage() ); } } diff --git a/frontend/src/components/TradeBox.js b/frontend/src/components/TradeBox.js index 74856773..011f348b 100644 --- a/frontend/src/components/TradeBox.js +++ b/frontend/src/components/TradeBox.js @@ -68,14 +68,12 @@ export default class TradeBox extends Component { @@ -85,16 +83,9 @@ export default class TradeBox extends Component { showBondIsLocked=()=>{ return ( - - - - - - - Your {this.props.data.isMaker ? 'maker' : 'taker'} bond is locked - - - + + 🔒 Your {this.props.data.isMaker ? 'maker' : 'taker'} bond is locked + ); } @@ -118,7 +109,7 @@ export default class TradeBox extends Component { size="small" defaultValue={this.props.data.escrowInvoice} disabled="true" - helperText="This is a hold invoice. It will simply freeze in your wallet. It will be charged once the buyer confirms he sent the fiat." + helperText="This is a hold invoice. It will be charged once the buyer confirms he sent the fiat." color = "secondary" />