From 8e609b9e471ba5251ece1ae8bff0ba417ba77d8f Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sat, 15 Jan 2022 04:00:11 -0800 Subject: [PATCH] Add dynamic refresh rate to OrderPage based on order status --- README.md | 6 ++--- api/logics.py | 7 +++--- api/utils.py | 1 + frontend/src/components/OrderPage.js | 32 ++++++++++++++++++++---- frontend/src/components/TradeBox.js | 37 ++++++++++++++-------------- 5 files changed, 53 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index eeb59a3e..8fc2e3b4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# RoboSats: Buy and sell non-KYC Satoshis. +# RoboSats: Buy and sell Satoshis Privately. ## What is RoboSats? RoboSats is a simple and private way to exchange bitcoin for national currencies. Robosats aims to simplify the peer-to-peer experience and uses lightning hodl invoices to minimize the trust needed to trade. In addition, your Robotic Satoshi will help you stick to best privacy practices. @@ -15,11 +15,11 @@ RoboSats is a simple and private way to exchange bitcoin for national currencies - Url: testnet.robosats.com (Registered - Not active) - Commit height: v0.0.0 Latest commit. -*Use [Tor Browser](https://www.torproject.org/download/) and .onion for best anonymity.* +*Always use [Tor Browser](https://www.torproject.org/download/) and .onion for best anonymity.* ## Contribute to the Robotic Satoshis Open Source Project See [CONTRIBUTING.md](CONTRIBUTING.md) ## License -RoboSats is released under the terms of the AGPL3.0 license. See [LICENSE](LICENSE) for more details. +The Robotic Satoshis Open Source Project is released under the terms of the AGPL3.0 license. See [LICENSE](LICENSE) for more details. diff --git a/api/logics.py b/api/logics.py index 56953e24..d752618e 100644 --- a/api/logics.py +++ b/api/logics.py @@ -369,7 +369,8 @@ class Logics(): order.last_satoshis = cls.satoshis_now(order) bond_satoshis = int(order.last_satoshis * BOND_SIZE) pos_text = 'Buying' if cls.is_buyer(order, user) else 'Selling' - description = f"RoboSats - Taking 'Order {order.id}' {pos_text} BTC for {order.amount} - This is a taker bond, it will freeze in your wallet temporarily and automatically return. It will be charged if you cheat or cancel." + description = (f"RoboSats - Taking 'Order {order.id}' {pos_text} BTC for {float(order.amount) + Order.currency_dict[str(order.currency)]}" + + " - This is a taker bond, it will freeze in your wallet temporarily and automatically return. It will be charged if you cheat or cancel.") # Gen hold Invoice hold_payment = LNNode.gen_hold_invoice(bond_satoshis, description, BOND_EXPIRY*3600) @@ -482,8 +483,8 @@ class Logics(): def pay_buyer_invoice(order): ''' Pay buyer invoice''' # TODO ERROR HANDLING - if LNNode.pay_invoice(order.buyer_invoice.invoice, order.buyer_invoice.num_satoshis): - return True + suceeded, context = LNNode.pay_invoice(order.buyer_invoice.invoice, order.buyer_invoice.num_satoshis) + return suceeded, context @classmethod def confirm_fiat(cls, order, user): diff --git a/api/utils.py b/api/utils.py index 645d8084..96e58ffa 100644 --- a/api/utils.py +++ b/api/utils.py @@ -2,6 +2,7 @@ import requests, ring, os from decouple import config from statistics import median + market_cache = {} @ring.dict(market_cache, expire=30) #keeps in cache for 30 seconds diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js index c50fd40a..b1f00449 100644 --- a/frontend/src/components/OrderPage.js +++ b/frontend/src/components/OrderPage.js @@ -38,7 +38,7 @@ export default class OrderPage extends Component { super(props); this.state = { isExplicit: false, - delay: 3000, // Refresh every 3 seconds by default + delay: 60000, // Refresh every 60 seconds by default currencies_dict: {"1":"USD"}, total_secs_expiry: 300, loading: true, @@ -46,6 +46,28 @@ export default class OrderPage extends Component { this.orderId = this.props.match.params.orderId; this.getCurrencyDict(); this.getOrderDetails(); + + // Change refresh delay according to Order status + this.statusToDelay = { + "0": 3000, //'Waiting for maker bond' + "1": 30000, //'Public' + "2": 999999, //'Deleted' + "3": 3000, //'Waiting for taker bond' + "4": 999999, //'Cancelled' + "5": 999999, //'Expired' + "6": 3000, //'Waiting for trade collateral and buyer invoice' + "7": 3000, //'Waiting only for seller trade collateral' + "8": 10000, //'Waiting only for buyer invoice' + "9": 10000, //'Sending fiat - In chatroom' + "10": 15000, //'Fiat sent - In chatroom' + "11": 300000, //'In dispute' + "12": 999999, //'Collaboratively cancelled' + "13": 120000, //'Sending satoshis to buyer' + "14": 999999, //'Sucessful trade' + "15": 15000, //'Failed lightning network routing' + "16": 999999, //'Maker lost dispute' + "17": 999999, //'Taker lost dispute' + } } getOrderDetails() { @@ -55,6 +77,7 @@ export default class OrderPage extends Component { .then((data) => {console.log(data) & this.setState({ loading: false, + delay: this.statusToDelay[data.status.toString()], id: data.id, statusCode: data.status, statusText: data.status_message, @@ -99,12 +122,11 @@ export default class OrderPage extends Component { componentDidMount() { this.interval = setInterval(this.tick, this.state.delay); } - componentDidUpdate(prevProps, prevState) { - if (prevState.delay !== this.state.delay) { - clearInterval(this.interval); + componentDidUpdate() { + clearInterval(this.interval); this.interval = setInterval(this.tick, this.state.delay); - } } + componentWillUnmount() { clearInterval(this.interval); } diff --git a/frontend/src/components/TradeBox.js b/frontend/src/components/TradeBox.js index 011f348b..c71f2f08 100644 --- a/frontend/src/components/TradeBox.js +++ b/frontend/src/components/TradeBox.js @@ -5,7 +5,6 @@ import QRCode from "react-qr-code"; import Chat from "./Chat" // Icons -import LockIcon from '@mui/icons-material/Lock'; import SmartToyIcon from '@mui/icons-material/SmartToy'; import PercentIcon from '@mui/icons-material/Percent'; import BookIcon from '@mui/icons-material/Book'; @@ -238,24 +237,24 @@ export default class TradeBox extends Component { valid invoice for {pn(this.props.data.invoiceAmount)} Satoshis. -
- - - - - - -
+ + + + + + + + {this.showBondIsLocked()} )