import React, { Component } from "react"; import { Paper, Button, Grid, Typography, TextField, List, ListItem, ListItemText, Divider} from "@material-ui/core" import QRCode from "react-qr-code"; function getCookie(name) { let cookieValue = null; if (document.cookie && document.cookie !== '') { const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) === (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } const csrftoken = getCookie('csrftoken'); // pretty numbers function pn(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } export default class TradeBox extends Component { constructor(props) { super(props); } showQRInvoice=()=>{ return ( Robots around here usually show commitment {this.props.data.isMaker ? Lock {pn(this.props.data.bondSatoshis)} Sats to PUBLISH order : Lock {pn(this.props.data.bondSatoshis)} Sats to TAKE the order } ); } showEscrowQRInvoice=()=>{ return ( Deposit {pn(this.props.data.escrowSatoshis)} Sats as trade collateral ); } showTakerFound=()=>{ // TODO Make some sound here! The maker might have been waiting for long return ( A taker has been found! Please wait for the taker to confirm his commitment by locking a bond. ); } showMakerWait=()=>{ return ( Your order is public, wait for a taker.

Be patient while robots check the book. It might take some time. This box will ring 🔊 once a robot takes your order.

Please note that if your premium is too high, or if your currency or payment methods are not popular, your order might expire untaken. Your bond will return to you (no action needed).

{/* TODO API sends data for a more confortable wait */}
) } 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)); } 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({ // }) // showFiatSentButton(){ // } // showFiatReceivedButton(){ // } // showOpenDisputeButton(){ // } // showRateSelect(){ // } render() { return ( TradeBox {/* Maker and taker Bond request */} {this.props.data.bondInvoice ? this.showQRInvoice() : ""} {/* Waiting for taker and taker bond request */} {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.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.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.props.data.isSeller & this.props.data.statusCode > 12 & this.props.data.statusCode < 15 ? this.showRateSelect() : ""} {/* TODO */} {/* */} {/* */} ); } }