From 5dcb249bb38606de4b657ff63af334c9efbf106a Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sun, 9 Jan 2022 06:07:05 -0800 Subject: [PATCH] Invoice input --- api/models.py | 1 - frontend/src/components/OrderPage.js | 9 +- frontend/src/components/TradeBox.js | 155 ++++++++++++++++++--------- setup.md | 4 +- 4 files changed, 110 insertions(+), 59 deletions(-) diff --git a/api/models.py b/api/models.py index 359ba096..5ec761cb 100644 --- a/api/models.py +++ b/api/models.py @@ -86,7 +86,6 @@ class Order(models.Model): currency_dict = json.load(open('./api/currencies.json')) currency_choices = [(int(val), label) for val, label in list(currency_dict.items())] - print(currency_choices) # order info status = models.PositiveSmallIntegerField(choices=Status.choices, null=False, default=Status.WFB) diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js index 9eff532f..6bed6553 100644 --- a/frontend/src/components/OrderPage.js +++ b/frontend/src/components/OrderPage.js @@ -67,7 +67,7 @@ export default class OrderPage extends Component { super(props); this.state = { isExplicit: false, - delay: 5000, // Refresh every 5 seconds + delay: 10000, // Refresh every 10 seconds currencies_dict: {"1":"USD"} }; this.orderId = this.props.match.params.orderId; @@ -79,8 +79,9 @@ export default class OrderPage extends Component { this.setState(null) fetch('/api/order' + '?order_id=' + this.orderId) .then((response) => response.json()) - .then((data) => { + .then((data) => {console.log(data) & this.setState({ + id: data.id, statusCode: data.status, statusText: data.status_message, type: data.type, @@ -203,7 +204,7 @@ export default class OrderPage extends Component { src={window.location.origin +'/static/assets/avatars/' + this.state.makerNick + '.png'} /> - + @@ -212,7 +213,7 @@ export default class OrderPage extends Component { {this.state.takerNick!='None' ? <> - + { - this.setState({ delay: Number(e.target.value) }); - } - tick = () => { - this.data = this.props.data; } showQRInvoice=()=>{ @@ -42,25 +38,25 @@ export default class TradeBox extends Component { - {this.data.isMaker ? + {this.props.data.isMaker ? - Lock {this.data.bondSatoshis} Sats to PUBLISH order + Lock {pn(this.props.data.bondSatoshis)} Sats to PUBLISH order : - Lock {this.data.bondSatoshis} Sats to TAKE the order + Lock {pn(this.props.data.bondSatoshis)} Sats to TAKE the order } - + - Deposit {this.data.escrowSatoshis} Sats as trade collateral + Deposit {pn(this.props.data.escrowSatoshis)} Sats as trade collateral - + { - // Make some sound here! The maker might have been waiting for long + // TODO Make some sound here! The maker might have been waiting for long return ( @@ -147,7 +143,7 @@ export default class TradeBox extends Component { - + @@ -160,13 +156,66 @@ export default class TradeBox extends Component { ) } - // showInputInvoice(){ + handleInputInvoiceChanged=(e)=>{ + this.setState({ + invoice: e.target.value, + }); + } - // } + handleClickSubmitInvoiceButton=()=>{ + console.log(this.state) + const requestOptions = { + method: 'POST', + headers: {'Content-Type':'application/json', 'X-CSRFToken': getCookie('csrftoken'),}, + body: JSON.stringify({ + 'action':'update_invoice', + 'invoice': this.state.invoice, + }), + }; + fetch('/api/order/' + '?order_id=' + this.props.data.id, requestOptions) + .then((response) => response.json()) + .then((data) => (this.props.data = data)); + } - // showWaitingForEscrow(){ + showInputInvoice(){ + return ( - // } + // TODO Camera option to read QR + + + + + Submit a LN invoice for {pn(this.props.data.invoiceAmount)} Sats + + + + + The taker is committed! Before letting you send {" "+ parseFloat(parseFloat(this.props.data.amount).toFixed(4))+ + " "+ this.props.data.currencyCode}, we want to make sure you are able to receive the BTC. Please provide a + valid invoice for {pn(this.props.data.invoiceAmount)} Satoshis. + + + + + + + + + + ) + } + + showWaitingForEscrow(){ + + } // showWaitingForBuyerInvoice({ // }) @@ -196,26 +245,26 @@ export default class TradeBox extends Component { {/* Maker and taker Bond request */} - {this.data.bondInvoice ? this.showQRInvoice() : ""} + {this.props.data.bondInvoice ? this.showQRInvoice() : ""} {/* Waiting for taker and taker bond request */} - {this.data.isMaker & this.data.statusCode == 1 ? this.showMakerWait() : ""} - {this.data.isMaker & this.data.statusCode == 3 ? this.showTakerFound() : ""} + {this.props.data.isMaker & this.props.data.statusCode == 1 ? this.showMakerWait() : ""} + {this.props.data.isMaker & this.props.data.statusCode == 3 ? this.showTakerFound() : ""} {/* Send Invoice (buyer) and deposit collateral (seller) */} - {this.data.isSeller & this.data.escrowInvoice != null ? this.showEscrowQRInvoice() : ""} - {this.data.isBuyer & this.data.invoiceAmount != null ? this.showInputInvoice() : ""} - {this.data.isBuyer & this.data.statusCode == 7 ? this.showWaitingForEscrow() : ""} - {this.data.isSeller & this.data.statusCode == 8 ? this.showWaitingForBuyerInvoice() : ""} + {this.props.data.isSeller & this.props.data.escrowInvoice != null ? this.showEscrowQRInvoice() : ""} + {this.props.data.isBuyer & this.props.data.invoiceAmount != null ? this.showInputInvoice() : ""} + {this.props.data.isBuyer & this.props.data.statusCode == 7 ? this.showWaitingForEscrow() : ""} + {this.props.data.isSeller & this.props.data.statusCode == 8 ? this.showWaitingForBuyerInvoice() : ""} {/* In Chatroom */} - {this.data.isBuyer & this.data.statusCode == 9 ? this.showChat() & this.showFiatSentButton() : ""} - {this.data.isSeller & this.data.statusCode ==9 ? this.showChat() : ""} - {this.data.isBuyer & this.data.statusCode == 10 ? this.showChat() & this.showOpenDisputeButton() : ""} - {this.data.isSeller & this.data.statusCode == 10 ? this.showChat() & this.showFiatReceivedButton() & this.showOpenDisputeButton(): ""} + {this.props.data.isBuyer & this.props.data.statusCode == 9 ? this.showChat() & this.showFiatSentButton() : ""} + {this.props.data.isSeller & this.props.data.statusCode ==9 ? this.showChat() : ""} + {this.props.data.isBuyer & this.props.data.statusCode == 10 ? this.showChat() & this.showOpenDisputeButton() : ""} + {this.props.data.isSeller & this.props.data.statusCode == 10 ? this.showChat() & this.showFiatReceivedButton() & this.showOpenDisputeButton(): ""} {/* Trade Finished */} - {this.data.isSeller & this.data.statusCode > 12 & this.data.statusCode < 15 ? this.showRateSelect() : ""} + {this.props.data.isSeller & this.props.data.statusCode > 12 & this.props.data.statusCode < 15 ? this.showRateSelect() : ""} {/* TODO */} {/* */} {/* */} diff --git a/setup.md b/setup.md index ad945772..0a5d2b40 100644 --- a/setup.md +++ b/setup.md @@ -66,7 +66,9 @@ npm install react-router-dom@5.2.0 npm install @material-ui/icons npm install material-ui-image npm install @mui/system @emotion/react @emotion/styled -npm install qrcodejs +npm install react-native +npm install react-native-svg +npm install react-qr-code ``` ### Launch the React render