2022-09-09 17:18:04 +00:00
import React , { Component } from 'react' ;
import { withTranslation } from 'react-i18next' ;
import {
TextField ,
Chip ,
Tooltip ,
IconButton ,
Badge ,
Tab ,
Tabs ,
Alert ,
Paper ,
CircularProgress ,
Button ,
Grid ,
Typography ,
List ,
ListItem ,
ListItemIcon ,
ListItemText ,
ListItemAvatar ,
Avatar ,
Divider ,
Box ,
LinearProgress ,
Dialog ,
DialogActions ,
DialogContent ,
DialogContentText ,
DialogTitle ,
} from '@mui/material' ;
2022-05-05 21:28:54 +00:00
import Countdown , { zeroPad } from 'react-countdown' ;
2022-09-09 17:18:04 +00:00
import { StoreTokenDialog , NoRobotDialog } from './Dialogs' ;
2022-01-27 22:51:57 +00:00
2022-05-08 22:07:49 +00:00
import currencyDict from '../../static/assets/currencies.json' ;
2022-09-09 17:18:04 +00:00
import PaymentText from './PaymentText' ;
import TradeBox from './TradeBox' ;
import FlagWithProps from './FlagWithProps' ;
2022-05-08 22:07:49 +00:00
import LinearDeterminate from './LinearDeterminate' ;
2022-09-09 17:18:04 +00:00
import MediaQuery from 'react-responsive' ;
import { t } from 'i18next' ;
2022-01-02 00:19:18 +00:00
2022-01-14 12:00:53 +00:00
// icons
import AccessTimeIcon from '@mui/icons-material/AccessTime' ;
import NumbersIcon from '@mui/icons-material/Numbers' ;
import PriceChangeIcon from '@mui/icons-material/PriceChange' ;
import PaymentsIcon from '@mui/icons-material/Payments' ;
import ArticleIcon from '@mui/icons-material/Article' ;
2022-04-29 18:54:20 +00:00
import HourglassTopIcon from '@mui/icons-material/HourglassTop' ;
2022-08-25 08:50:48 +00:00
import CheckIcon from '@mui/icons-material/Check' ;
2022-09-09 17:18:04 +00:00
import { SendReceiveIcon } from './Icons' ;
2022-01-08 15:34:09 +00:00
2022-09-09 17:18:04 +00:00
import { getCookie } from '../utils/cookies' ;
import { pn } from '../utils/prettyNumbers' ;
import { copyToClipboard } from '../utils/clipboard' ;
import { getWebln } from '../utils/webln' ;
2022-01-03 14:27:25 +00:00
2022-04-05 14:25:53 +00:00
class OrderPage extends Component {
2022-01-02 12:59:48 +00:00
constructor ( props ) {
super ( props ) ;
this . state = {
2022-09-09 17:18:04 +00:00
is _explicit : false ,
delay : 60000 , // Refresh every 60 seconds by default
total _secs _exp : 300 ,
loading : true ,
openCancel : false ,
openCollaborativeCancel : false ,
openInactiveMaker : false ,
openWeblnDialog : false ,
waitingWebln : false ,
openStoreToken : false ,
tabValue : 1 ,
orderId : this . props . match . params . orderId ,
2022-01-02 12:59:48 +00:00
} ;
2022-01-15 12:00:11 +00:00
2022-01-23 19:02:25 +00:00
// Refresh delays according to Order status
2022-01-15 12:00:11 +00:00
this . statusToDelay = {
2022-09-09 17:33:29 +00:00
0 : 2000 , // 'Waiting for maker bond'
1 : 25000 , // 'Public'
2 : 90000 , // 'Paused'
3 : 2000 , // 'Waiting for taker bond'
4 : 999999 , // 'Cancelled'
5 : 999999 , // 'Expired'
6 : 6000 , // 'Waiting for trade collateral and buyer invoice'
7 : 8000 , // 'Waiting only for seller trade collateral'
8 : 8000 , // 'Waiting only for buyer invoice'
9 : 10000 , // 'Sending fiat - In chatroom'
10 : 10000 , // 'Fiat sent - In chatroom'
11 : 30000 , // 'In dispute'
12 : 999999 , // 'Collaboratively cancelled'
13 : 3000 , // 'Sending satoshis to buyer'
14 : 999999 , // 'Sucessful trade'
15 : 10000 , // 'Failed lightning network routing'
16 : 180000 , // 'Wait for dispute resolution'
17 : 180000 , // 'Maker lost dispute'
18 : 180000 , // 'Taker lost dispute'
2022-09-09 17:18:04 +00:00
} ;
2022-01-02 12:59:48 +00:00
}
2022-01-02 00:19:18 +00:00
2022-09-09 17:18:04 +00:00
completeSetState = ( newStateVars ) => {
2022-01-23 20:23:25 +00:00
// In case the reply only has "bad_request"
// Do not substitute these two for "undefined" as
// otherStateVars will fail to assign values
2022-09-09 17:18:04 +00:00
if ( newStateVars . currency == null ) {
newStateVars . currency = this . state . currency ;
newStateVars . amount = this . state . amount ;
newStateVars . status = this . state . status ;
2022-01-23 20:23:25 +00:00
}
2022-09-09 17:33:29 +00:00
const otherStateVars = {
2022-03-22 17:49:57 +00:00
amount : newStateVars . amount ? newStateVars . amount : null ,
2022-01-19 22:44:31 +00:00
loading : false ,
2022-01-22 23:05:03 +00:00
delay : this . setDelay ( newStateVars . status ) ,
currencyCode : this . getCurrencyCode ( newStateVars . currency ) ,
2022-01-24 18:34:52 +00:00
penalty : newStateVars . penalty , // in case penalty time has finished, it goes back to null
2022-09-09 17:18:04 +00:00
invoice _expired : newStateVars . invoice _expired , // in case invoice had expired, it goes back to null when it is valid again
2022-01-22 23:05:03 +00:00
} ;
2022-01-24 17:54:44 +00:00
2022-09-09 17:33:29 +00:00
const completeStateVars = Object . assign ( { } , newStateVars , otherStateVars ) ;
2022-01-22 23:05:03 +00:00
this . setState ( completeStateVars ) ;
2022-09-09 17:18:04 +00:00
} ;
2022-01-23 19:02:25 +00:00
2022-09-09 17:18:04 +00:00
getOrderDetails = ( id ) => {
this . setState ( { orderId : id } ) ;
2022-04-29 18:54:20 +00:00
fetch ( '/api/order' + '?order_id=' + id )
2022-01-02 12:59:48 +00:00
. then ( ( response ) => response . json ( ) )
2022-08-25 08:50:48 +00:00
. then ( this . orderDetailsReceived ) ;
2022-09-09 17:18:04 +00:00
} ;
2022-08-25 08:50:48 +00:00
2022-09-09 17:18:04 +00:00
orderDetailsReceived = ( data ) => {
if ( data . status !== this . state . status ) {
this . handleWebln ( data ) ;
}
this . completeSetState ( data ) ;
this . setState ( { pauseLoading : false } ) ;
} ;
2022-01-02 12:59:48 +00:00
2022-01-09 01:23:13 +00:00
// These are used to refresh the data
componentDidMount ( ) {
2022-05-08 15:43:08 +00:00
this . getOrderDetails ( this . props . match . params . orderId ) ;
2022-01-09 01:23:13 +00:00
this . interval = setInterval ( this . tick , this . state . delay ) ;
}
2022-05-08 15:43:08 +00:00
2022-01-15 12:00:11 +00:00
componentDidUpdate ( ) {
clearInterval ( this . interval ) ;
2022-08-25 08:50:48 +00:00
this . interval = setInterval ( this . tick , this . state . delay ) ;
2022-01-09 01:23:13 +00:00
}
2022-01-15 12:00:11 +00:00
2022-01-09 01:23:13 +00:00
componentWillUnmount ( ) {
clearInterval ( this . interval ) ;
}
2022-09-09 17:33:29 +00:00
2022-01-09 01:23:13 +00:00
tick = ( ) => {
2022-04-29 18:54:20 +00:00
this . getOrderDetails ( this . state . orderId ) ;
2022-09-09 17:18:04 +00:00
} ;
2022-01-09 01:23:13 +00:00
2022-08-25 08:50:48 +00:00
handleWebln = async ( data ) => {
const webln = await getWebln ( ) ;
// If Webln implements locked payments compatibility, this logic might be simplier
2022-09-09 17:18:04 +00:00
if ( data . is _maker & ( data . status == 0 ) ) {
2022-08-25 08:50:48 +00:00
webln . sendPayment ( data . bond _invoice ) ;
2022-09-09 17:18:04 +00:00
this . setState ( { waitingWebln : true , openWeblnDialog : true } ) ;
} else if ( data . is _taker & ( data . status == 3 ) ) {
2022-08-25 08:50:48 +00:00
webln . sendPayment ( data . bond _invoice ) ;
2022-09-09 17:18:04 +00:00
this . setState ( { waitingWebln : true , openWeblnDialog : true } ) ;
} else if ( data . is _seller & ( data . status == 6 || data . status == 7 ) ) {
2022-08-25 08:50:48 +00:00
webln . sendPayment ( data . escrow _invoice ) ;
2022-09-09 17:18:04 +00:00
this . setState ( { waitingWebln : true , openWeblnDialog : true } ) ;
} else if ( data . is _buyer & ( data . status == 6 || data . status == 8 ) ) {
this . setState ( { waitingWebln : true , openWeblnDialog : true } ) ;
webln
. makeInvoice ( data . trade _satoshis )
2022-08-25 08:50:48 +00:00
. then ( ( invoice ) => {
if ( invoice ) {
this . sendWeblnInvoice ( invoice . paymentRequest ) ;
this . setState ( { waitingWebln : false , openWeblnDialog : false } ) ;
}
2022-09-09 17:18:04 +00:00
} )
. catch ( ( ) => {
2022-08-25 08:50:48 +00:00
this . setState ( { waitingWebln : false , openWeblnDialog : false } ) ;
} ) ;
} else {
this . setState ( { waitingWebln : false } ) ;
}
2022-09-09 17:18:04 +00:00
} ;
2022-08-25 08:50:48 +00:00
sendWeblnInvoice = ( invoice ) => {
const requestOptions = {
method : 'POST' ,
2022-09-09 17:18:04 +00:00
headers : { 'Content-Type' : 'application/json' , 'X-CSRFToken' : getCookie ( 'csrftoken' ) } ,
2022-08-25 08:50:48 +00:00
body : JSON . stringify ( {
2022-09-09 17:18:04 +00:00
action : 'update_invoice' ,
2022-09-09 17:33:29 +00:00
invoice ,
2022-08-25 08:50:48 +00:00
} ) ,
} ;
fetch ( '/api/order/' + '?order_id=' + this . state . orderId , requestOptions )
2022-09-09 17:18:04 +00:00
. then ( ( response ) => response . json ( ) )
. then ( ( data ) => this . completeSetState ( data ) ) ;
} ;
2022-08-25 08:50:48 +00:00
2022-04-15 16:22:49 +00:00
// Countdown Renderer callback with condition
2022-01-14 00:43:26 +00:00
countdownRenderer = ( { total , hours , minutes , seconds , completed } ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
if ( completed ) {
// Render a completed state
return < span > { t ( 'The order has expired' ) } < / s p a n > ;
} else {
2022-09-09 17:33:29 +00:00
let col = 'inherit' ;
const fraction _left = total / 1000 / this . state . total _secs _exp ;
2022-09-09 17:18:04 +00:00
// Make orange at 25% of time left
if ( fraction _left < 0.25 ) {
col = 'orange' ;
}
// Make red at 10% of time left
if ( fraction _left < 0.1 ) {
col = 'red' ;
}
// Render a countdown, bold when less than 25%
return fraction _left < 0.25 ? (
< b >
< span style = { { color : col } } >
{ hours } h { zeroPad ( minutes ) } m { zeroPad ( seconds ) } s { ' ' }
< / s p a n >
< / b >
) : (
< span style = { { color : col } } >
{ hours } h { zeroPad ( minutes ) } m { zeroPad ( seconds ) } s { ' ' }
< / s p a n >
) ;
}
2022-01-14 00:43:26 +00:00
} ;
2022-09-09 17:18:04 +00:00
timerRenderer ( seconds ) {
2022-09-09 17:33:29 +00:00
const hours = parseInt ( seconds / 3600 ) ;
const minutes = parseInt ( ( seconds - hours * 3600 ) / 60 ) ;
2022-09-09 17:18:04 +00:00
return (
< span >
{ hours > 0 ? hours + 'h' : '' } { minutes > 0 ? zeroPad ( minutes ) + 'm' : '' } { ' ' }
< / s p a n >
) ;
2022-04-29 18:54:20 +00:00
}
2022-04-15 16:22:49 +00:00
// Countdown Renderer callback with condition
2022-01-26 11:44:45 +00:00
countdownPenaltyRenderer = ( { minutes , seconds , completed } ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-01-26 11:44:45 +00:00
if ( completed ) {
// Render a completed state
2022-09-09 17:18:04 +00:00
return < span > { t ( 'Penalty lifted, good to go!' ) } < / s p a n > ;
2022-01-26 11:44:45 +00:00
} else {
return (
2022-09-09 17:18:04 +00:00
< span >
{ ' ' }
{ t ( 'You cannot take an order yet! Wait {{timeMin}}m {{timeSec}}s' , {
timeMin : zeroPad ( minutes ) ,
timeSec : zeroPad ( seconds ) ,
} ) } { ' ' }
< / s p a n >
2022-01-26 11:44:45 +00:00
) ;
}
2022-09-09 17:18:04 +00:00
} ;
2022-04-15 16:22:49 +00:00
2022-03-22 17:49:57 +00:00
handleTakeAmountChange = ( e ) => {
2022-09-09 17:18:04 +00:00
if ( ( e . target . value != '' ) & ( e . target . value != null ) ) {
this . setState ( { takeAmount : parseFloat ( e . target . value ) } ) ;
} else {
this . setState ( { takeAmount : e . target . value } ) ;
2022-03-22 17:49:57 +00:00
}
2022-09-09 17:18:04 +00:00
} ;
2022-03-22 17:49:57 +00:00
2022-09-09 17:18:04 +00:00
amountHelperText = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
if ( ( this . state . takeAmount < this . state . min _amount ) & ( this . state . takeAmount != '' ) ) {
return t ( 'Too low' ) ;
} else if ( ( this . state . takeAmount > this . state . max _amount ) & ( this . state . takeAmount != '' ) ) {
return t ( 'Too high' ) ;
} else {
return null ;
2022-03-22 17:49:57 +00:00
}
2022-09-09 17:18:04 +00:00
} ;
2022-03-22 17:49:57 +00:00
takeOrderButton = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
if ( this . state . has _range ) {
return (
< Grid
container
align = 'center'
alignItems = 'stretch'
justifyContent = 'center'
style = { { display : 'flex' } }
>
2022-05-08 16:46:27 +00:00
{ this . InactiveMakerDialog ( ) }
2022-05-08 22:07:49 +00:00
{ this . tokenDialog ( ) }
2022-09-09 17:18:04 +00:00
< div style = { { maxWidth : 120 } } >
< Tooltip
placement = 'top'
enterTouchDelay = { 500 }
enterDelay = { 700 }
enterNextDelay = { 2000 }
title = { t ( 'Enter amount of fiat to exchange for bitcoin' ) }
>
< Paper elevation = { 5 } sx = { { maxHeight : 40 } } >
< TextField
error = {
( this . state . takeAmount < this . state . min _amount ||
this . state . takeAmount > this . state . max _amount ) &
( this . state . takeAmount != '' )
}
2022-03-22 17:49:57 +00:00
helperText = { this . amountHelperText ( ) }
2022-09-09 17:18:04 +00:00
label = { t ( 'Amount {{currencyCode}}' , { currencyCode : this . state . currencyCode } ) }
size = 'small'
type = 'number'
2022-05-02 19:28:34 +00:00
required = { true }
2022-03-22 17:49:57 +00:00
value = { this . state . takeAmount }
inputProps = { {
2022-09-09 17:18:04 +00:00
min : this . state . min _amount ,
max : this . state . max _amount ,
style : { textAlign : 'center' } ,
2022-03-22 17:49:57 +00:00
} }
onChange = { this . handleTakeAmountChange }
2022-09-09 17:18:04 +00:00
/ >
< / P a p e r >
< / T o o l t i p >
2022-03-22 17:49:57 +00:00
< / d i v >
2022-09-09 17:18:04 +00:00
< div
style = { {
height : 38 ,
top : '1px' ,
position : 'relative' ,
display :
this . state . takeAmount < this . state . min _amount ||
this . state . takeAmount > this . state . max _amount ||
this . state . takeAmount == '' ||
this . state . takeAmount == null
? ''
: 'none' ,
} }
>
< Tooltip
placement = 'top'
enterTouchDelay = { 0 }
enterDelay = { 500 }
enterNextDelay = { 1200 }
title = { t ( 'You must specify an amount first' ) }
>
2022-03-24 15:43:31 +00:00
< Paper elevation = { 4 } >
2022-09-09 17:18:04 +00:00
< Button sx = { { height : 38 } } variant = 'contained' color = 'primary' disabled = { true } >
{ t ( 'Take Order' ) }
2022-03-24 15:43:31 +00:00
< / B u t t o n >
< / P a p e r >
< / T o o l t i p >
< / d i v >
2022-09-09 17:18:04 +00:00
< div
style = { {
height : 38 ,
top : '1px' ,
position : 'relative' ,
display :
this . state . takeAmount < this . state . min _amount ||
this . state . takeAmount > this . state . max _amount ||
this . state . takeAmount == '' ||
this . state . takeAmount == null
? 'none'
: '' ,
} }
>
< Paper elevation = { 4 } >
< Button
sx = { { height : 38 } }
variant = 'contained'
color = 'primary'
onClick = {
this . props . copiedToken
? this . state . maker _status == 'Inactive'
? this . handleClickOpenInactiveMakerDialog
: this . takeOrder
: ( ) => this . setState ( { openStoreToken : true } )
}
>
{ t ( 'Take Order' ) }
2022-03-24 15:43:31 +00:00
< / B u t t o n >
< / P a p e r >
2022-03-22 17:49:57 +00:00
< / d i v >
< / G r i d >
2022-09-09 17:18:04 +00:00
) ;
} else {
return (
2022-03-22 17:49:57 +00:00
< >
2022-09-09 17:18:04 +00:00
{ this . InactiveMakerDialog ( ) }
{ this . tokenDialog ( ) }
< Button
sx = { { height : 38 } }
variant = 'contained'
color = 'primary'
onClick = {
this . props . copiedToken
? this . state . maker _status == 'Inactive'
? this . handleClickOpenInactiveMakerDialog
: this . takeOrder
: ( ) => this . setState ( { openStoreToken : true } )
}
>
{ t ( 'Take Order' ) }
< / B u t t o n >
2022-03-22 17:49:57 +00:00
< / >
2022-09-09 17:18:04 +00:00
) ;
2022-02-01 16:27:02 +00:00
}
2022-09-09 17:18:04 +00:00
} ;
2022-03-22 17:49:57 +00:00
countdownTakeOrderRenderer = ( { seconds , completed } ) => {
2022-09-09 17:18:04 +00:00
if ( isNaN ( seconds ) ) {
return this . takeOrderButton ( ) ;
}
2022-02-01 16:27:02 +00:00
if ( completed ) {
// Render a completed state
2022-05-05 21:28:54 +00:00
return this . takeOrderButton ( ) ;
2022-09-09 17:18:04 +00:00
} else {
return (
< Tooltip enterTouchDelay = { 0 } title = { t ( 'Wait until you can take an order' ) } >
< div >
< Button disabled = { true } variant = 'contained' color = 'primary' >
{ t ( 'Take Order' ) }
< / B u t t o n >
< / d i v >
< / T o o l t i p >
) ;
2022-02-01 16:27:02 +00:00
}
} ;
2022-01-26 11:44:45 +00:00
2022-09-09 17:18:04 +00:00
takeOrder = ( ) => {
this . setState ( { loading : true } ) ;
2022-02-01 16:27:02 +00:00
const requestOptions = {
2022-09-09 17:18:04 +00:00
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' , 'X-CSRFToken' : getCookie ( 'csrftoken' ) } ,
body : JSON . stringify ( {
action : 'take' ,
amount : this . state . takeAmount ,
} ) ,
} ;
fetch ( '/api/order/' + '?order_id=' + this . state . orderId , requestOptions )
2022-01-05 00:13:08 +00:00
. then ( ( response ) => response . json ( ) )
2022-08-25 08:50:48 +00:00
. then ( ( data ) => this . handleWebln ( data ) & this . completeSetState ( data ) ) ;
2022-09-09 17:18:04 +00:00
} ;
2022-04-15 16:22:49 +00:00
2022-01-15 15:12:26 +00:00
// set delay to the one matching the order status. If null order status, delay goes to 9999999.
2022-09-09 17:18:04 +00:00
setDelay = ( status ) => {
2022-01-15 15:12:26 +00:00
return status >= 0 ? this . statusToDelay [ status . toString ( ) ] : 99999999 ;
2022-09-09 17:18:04 +00:00
} ;
2022-01-15 14:22:07 +00:00
2022-09-09 17:18:04 +00:00
getCurrencyCode ( val ) {
2022-09-09 17:33:29 +00:00
const code = val ? currencyDict [ val . toString ( ) ] : '' ;
2022-09-09 17:18:04 +00:00
return code ;
2022-01-08 12:48:03 +00:00
}
2022-01-05 00:13:08 +00:00
2022-09-09 17:18:04 +00:00
handleClickConfirmCancelButton = ( ) => {
this . setState ( { loading : true } ) ;
2022-02-01 16:27:02 +00:00
const requestOptions = {
2022-09-09 17:18:04 +00:00
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' , 'X-CSRFToken' : getCookie ( 'csrftoken' ) } ,
body : JSON . stringify ( {
action : 'cancel' ,
} ) ,
2022-02-01 16:27:02 +00:00
} ;
2022-04-29 18:54:20 +00:00
fetch ( '/api/order/' + '?order_id=' + this . state . orderId , requestOptions )
2022-09-09 17:18:04 +00:00
. then ( ( response ) => response . json ( ) )
. then ( ( ) => this . getOrderDetails ( this . state . orderId ) & this . setState ( { status : 4 } ) ) ;
2022-01-18 15:23:57 +00:00
this . handleClickCloseConfirmCancelDialog ( ) ;
2022-09-09 17:18:04 +00:00
} ;
2022-01-18 15:23:57 +00:00
handleClickOpenConfirmCancelDialog = ( ) => {
2022-09-09 17:18:04 +00:00
this . setState ( { openCancel : true } ) ;
2022-01-18 15:23:57 +00:00
} ;
2022-09-09 17:33:29 +00:00
2022-01-18 15:23:57 +00:00
handleClickCloseConfirmCancelDialog = ( ) => {
2022-09-09 17:18:04 +00:00
this . setState ( { openCancel : false } ) ;
2022-01-18 15:23:57 +00:00
} ;
2022-09-09 17:18:04 +00:00
CancelDialog = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
return (
2022-01-18 15:23:57 +00:00
< Dialog
2022-09-09 17:18:04 +00:00
open = { this . state . openCancel }
onClose = { this . handleClickCloseConfirmCancelDialog }
aria - labelledby = 'cancel-dialog-title'
aria - describedby = 'cancel-dialog-description'
2022-01-18 15:23:57 +00:00
>
2022-09-09 17:18:04 +00:00
< DialogTitle id = 'cancel-dialog-title' > { t ( 'Cancel the order?' ) } < / D i a l o g T i t l e >
2022-01-18 15:23:57 +00:00
< DialogContent >
2022-09-09 17:18:04 +00:00
< DialogContentText id = 'cancel-dialog-description' >
{ t ( 'If the order is cancelled now you will lose your bond.' ) }
2022-01-18 15:23:57 +00:00
< / D i a l o g C o n t e n t T e x t >
< / D i a l o g C o n t e n t >
< DialogActions >
2022-09-09 17:18:04 +00:00
< Button onClick = { this . handleClickCloseConfirmCancelDialog } autoFocus >
{ t ( 'Go back' ) }
< / B u t t o n >
< Button onClick = { this . handleClickConfirmCancelButton } > { t ( 'Confirm Cancel' ) } < / B u t t o n >
2022-01-18 15:23:57 +00:00
< / D i a l o g A c t i o n s >
< / D i a l o g >
2022-09-09 17:18:04 +00:00
) ;
} ;
2022-01-18 15:23:57 +00:00
2022-02-03 18:27:39 +00:00
handleClickOpenInactiveMakerDialog = ( ) => {
2022-09-09 17:18:04 +00:00
this . setState ( { openInactiveMaker : true } ) ;
2022-02-03 18:27:39 +00:00
} ;
2022-09-09 17:33:29 +00:00
2022-02-03 18:27:39 +00:00
handleClickCloseInactiveMakerDialog = ( ) => {
2022-09-09 17:18:04 +00:00
this . setState ( { openInactiveMaker : false } ) ;
2022-02-03 18:27:39 +00:00
} ;
2022-09-09 17:18:04 +00:00
InactiveMakerDialog = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
return (
2022-02-03 18:27:39 +00:00
< Dialog
2022-09-09 17:18:04 +00:00
open = { this . state . openInactiveMaker }
onClose = { this . handleClickCloseInactiveMakerDialog }
aria - labelledby = 'inactive-maker-dialog-title'
aria - describedby = 'inactive-maker-description'
2022-02-03 18:27:39 +00:00
>
2022-09-09 17:18:04 +00:00
< DialogTitle id = 'inactive-maker-dialog-title' > { t ( 'The maker is away' ) } < / D i a l o g T i t l e >
2022-02-03 18:27:39 +00:00
< DialogContent >
2022-09-09 17:18:04 +00:00
< DialogContentText id = 'cancel-dialog-description' >
{ t (
'By taking this order you risk wasting your time. If the maker does not proceed in time, you will be compensated in satoshis for 50% of the maker bond.' ,
) }
2022-02-03 18:27:39 +00:00
< / D i a l o g C o n t e n t T e x t >
< / D i a l o g C o n t e n t >
< DialogActions >
2022-09-09 17:18:04 +00:00
< Button onClick = { this . handleClickCloseInactiveMakerDialog } autoFocus >
{ t ( 'Go back' ) }
< / B u t t o n >
< Button onClick = { this . takeOrder } > { t ( 'Take Order' ) } < / B u t t o n >
2022-02-03 18:27:39 +00:00
< / D i a l o g A c t i o n s >
< / D i a l o g >
2022-09-09 17:18:04 +00:00
) ;
} ;
2022-05-04 15:13:35 +00:00
2022-09-09 17:18:04 +00:00
tokenDialog = ( ) => {
return getCookie ( 'robot_token' ) ? (
2022-05-08 22:07:49 +00:00
< StoreTokenDialog
open = { this . state . openStoreToken }
2022-09-09 17:18:04 +00:00
onClose = { ( ) => this . setState ( { openStoreToken : false } ) }
onClickCopy = { ( ) =>
copyToClipboard ( getCookie ( 'robot_token' ) ) & this . props . setAppState ( { copiedToken : true } )
}
copyIconColor = { this . props . copiedToken ? 'inherit' : 'primary' }
onClickBack = { ( ) => this . setState ( { openStoreToken : false } ) }
onClickDone = { ( ) =>
this . setState ( { openStoreToken : false } ) &
( this . state . maker _status == 'Inactive'
? this . handleClickOpenInactiveMakerDialog ( )
2022-05-08 22:07:49 +00:00
: this . takeOrder ( ) )
2022-09-09 17:18:04 +00:00
}
/ >
) : (
2022-05-08 22:07:49 +00:00
< NoRobotDialog
open = { this . state . openStoreToken }
2022-09-09 17:18:04 +00:00
onClose = { ( ) => this . setState ( { openStoreToken : false } ) }
/ >
) ;
} ;
2022-05-04 15:13:35 +00:00
2022-09-09 17:18:04 +00:00
handleClickConfirmCollaborativeCancelButton = ( ) => {
const requestOptions = {
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' , 'X-CSRFToken' : getCookie ( 'csrftoken' ) } ,
body : JSON . stringify ( {
action : 'cancel' ,
} ) ,
} ;
fetch ( '/api/order/' + '?order_id=' + this . state . orderId , requestOptions )
2022-01-23 19:02:25 +00:00
. then ( ( response ) => response . json ( ) )
2022-09-09 17:18:04 +00:00
. then ( ( ) => this . getOrderDetails ( this . state . orderId ) & this . setState ( { status : 4 } ) ) ;
2022-01-23 19:02:25 +00:00
this . handleClickCloseCollaborativeCancelDialog ( ) ;
2022-09-09 17:18:04 +00:00
} ;
2022-01-23 19:02:25 +00:00
handleClickOpenCollaborativeCancelDialog = ( ) => {
2022-09-09 17:18:04 +00:00
this . setState ( { openCollaborativeCancel : true } ) ;
2022-01-23 19:02:25 +00:00
} ;
2022-09-09 17:33:29 +00:00
2022-01-23 19:02:25 +00:00
handleClickCloseCollaborativeCancelDialog = ( ) => {
2022-09-09 17:18:04 +00:00
this . setState ( { openCollaborativeCancel : false } ) ;
2022-01-23 19:02:25 +00:00
} ;
2022-09-09 17:18:04 +00:00
CollaborativeCancelDialog = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
return (
2022-01-23 19:02:25 +00:00
< Dialog
2022-09-09 17:18:04 +00:00
open = { this . state . openCollaborativeCancel }
onClose = { this . handleClickCloseCollaborativeCancelDialog }
aria - labelledby = 'collaborative-cancel-dialog-title'
aria - describedby = 'collaborative-cancel-dialog-description'
2022-01-23 19:02:25 +00:00
>
2022-09-09 17:18:04 +00:00
< DialogTitle id = 'cancel-dialog-title' > { t ( 'Collaborative cancel the order?' ) } < / D i a l o g T i t l e >
2022-01-23 19:02:25 +00:00
< DialogContent >
2022-09-09 17:18:04 +00:00
< DialogContentText id = 'cancel-dialog-description' >
{ t (
'The trade escrow has been posted. The order can be cancelled only if both, maker and taker, agree to cancel.' ,
) }
2022-01-23 19:02:25 +00:00
< / D i a l o g C o n t e n t T e x t >
< / D i a l o g C o n t e n t >
< DialogActions >
2022-09-09 17:18:04 +00:00
< Button onClick = { this . handleClickCloseCollaborativeCancelDialog } autoFocus >
{ t ( 'Go back' ) }
< / B u t t o n >
< Button onClick = { this . handleClickConfirmCollaborativeCancelButton } >
{ t ( 'Ask for Cancel' ) }
< / B u t t o n >
2022-01-23 19:02:25 +00:00
< / D i a l o g A c t i o n s >
< / D i a l o g >
2022-09-09 17:18:04 +00:00
) ;
} ;
2022-01-23 19:02:25 +00:00
2022-03-12 11:24:11 +00:00
BackButton = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-03-12 11:24:11 +00:00
// If order has expired, show back button.
2022-09-09 17:18:04 +00:00
if ( this . state . status == 5 ) {
return (
< Grid item xs = { 12 } align = 'center' >
< Button variant = 'contained' color = 'secondary' onClick = { this . props . history . goBack } >
{ t ( 'Back' ) }
< / B u t t o n >
2022-03-12 11:24:11 +00:00
< / G r i d >
2022-09-09 17:18:04 +00:00
) ;
}
return null ;
} ;
2022-03-12 11:24:11 +00:00
2022-01-18 15:23:57 +00:00
CancelButton = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-01-18 15:23:57 +00:00
// If maker and Waiting for Bond. Or if taker and Waiting for bond.
2022-04-15 16:22:49 +00:00
// Simply allow to cancel without showing the cancel dialog.
2022-09-09 17:18:04 +00:00
if (
this . state . is _maker & [ 0 , 1 , 2 ] . includes ( this . state . status ) ||
this . state . is _taker & ( this . state . status == 3 )
) {
return (
< Grid item xs = { 12 } align = 'center' >
< Button
variant = 'contained'
color = 'secondary'
onClick = { this . handleClickConfirmCancelButton }
>
{ t ( 'Cancel' ) }
< / B u t t o n >
2022-01-18 15:23:57 +00:00
< / G r i d >
2022-09-09 17:18:04 +00:00
) ;
}
2022-01-18 15:23:57 +00:00
// If the order does not yet have an escrow deposited. Show dialog
// to confirm forfeiting the bond
2022-09-09 17:18:04 +00:00
if ( [ 3 , 6 , 7 ] . includes ( this . state . status ) ) {
return (
< div id = 'openDialogCancelButton' >
< Grid item xs = { 12 } align = 'center' >
2022-05-05 21:28:54 +00:00
{ this . CancelDialog ( ) }
2022-09-09 17:18:04 +00:00
< Button
variant = 'contained'
color = 'secondary'
onClick = { this . handleClickOpenConfirmCancelDialog }
>
{ t ( 'Cancel' ) }
< / B u t t o n >
2022-01-23 19:02:25 +00:00
< / G r i d >
< / d i v >
2022-09-09 17:18:04 +00:00
) ;
}
2022-04-15 16:22:49 +00:00
2022-01-23 19:02:25 +00:00
// If the escrow is Locked, show the collaborative cancel button.
2022-04-15 16:22:49 +00:00
2022-09-09 17:18:04 +00:00
if ( [ 8 , 9 ] . includes ( this . state . status ) ) {
return (
< Grid item xs = { 12 } align = 'center' >
2022-05-05 21:28:54 +00:00
{ this . CollaborativeCancelDialog ( ) }
2022-09-09 17:18:04 +00:00
< Button
variant = 'contained'
color = 'secondary'
onClick = { this . handleClickOpenCollaborativeCancelDialog }
>
{ t ( 'Collaborative Cancel' ) }
< / B u t t o n >
2022-01-18 15:23:57 +00:00
< / G r i d >
2022-09-09 17:18:04 +00:00
) ;
}
2022-01-23 19:02:25 +00:00
2022-01-18 15:23:57 +00:00
// If none of the above do not return a cancel button.
2022-09-09 17:18:04 +00:00
return null ;
} ;
2022-01-08 15:34:09 +00:00
2022-01-30 19:45:37 +00:00
// Colors for the status badges
2022-09-09 17:18:04 +00:00
statusBadgeColor ( status ) {
if ( status == 'Active' ) {
return 'success' ;
}
if ( status == 'Seen recently' ) {
return 'warning' ;
}
if ( status == 'Inactive' ) {
return 'error' ;
}
2022-01-30 19:45:37 +00:00
}
2022-02-01 16:27:02 +00:00
2022-09-09 17:18:04 +00:00
orderBox = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
return (
< Grid container spacing = { 1 } >
< Grid item xs = { 12 } align = 'center' >
2022-01-27 22:51:57 +00:00
< MediaQuery minWidth = { 920 } >
2022-09-09 17:18:04 +00:00
< Typography component = 'h5' variant = 'h5' >
{ t ( 'Order Box' ) }
2022-01-27 22:51:57 +00:00
< / T y p o g r a p h y >
< / M e d i a Q u e r y >
2022-09-09 17:18:04 +00:00
< Paper elevation = { 12 } >
< List dense = { true } >
< ListItem >
< ListItemAvatar sx = { { width : 56 , height : 56 } } >
< Tooltip placement = 'top' enterTouchDelay = { 0 } title = { t ( this . state . maker _status ) } >
< Badge
variant = 'dot'
overlap = 'circular'
badgeContent = ''
color = { this . statusBadgeColor ( this . state . maker _status ) }
>
< Badge
overlap = 'circular'
anchorOrigin = { { horizontal : 'right' , vertical : 'bottom' } }
badgeContent = {
< div style = { { position : 'relative' , left : '5px' , top : '2px' } } >
{ ' ' }
{ ! this . state . type ? (
< SendReceiveIcon
sx = { { transform : 'scaleX(-1)' , height : '18px' , width : '18px' } }
color = 'secondary'
2022-04-24 16:01:25 +00:00
/ >
2022-09-09 17:18:04 +00:00
) : (
< SendReceiveIcon
sx = { { height : '18px' , width : '18px' } }
color = 'primary'
/ >
) }
< / d i v >
}
>
< Avatar
className = 'flippedSmallAvatar'
alt = { this . state . maker _nick }
src = {
window . location . origin +
'/static/assets/avatars/' +
this . state . maker _nick +
'.png'
}
/ >
< / B a d g e >
< / B a d g e >
< / T o o l t i p >
< / L i s t I t e m A v a t a r >
< ListItemText
primary = {
this . state . maker _nick +
( this . state . type ? ' ' + t ( '(Seller)' ) : ' ' + t ( '(Buyer)' ) )
2022-01-05 02:03:03 +00:00
}
2022-09-09 17:18:04 +00:00
secondary = { t ( 'Order maker' ) }
align = 'right'
/ >
< / L i s t I t e m >
{ this . state . is _participant ? (
< >
{ this . state . taker _nick != 'None' ? (
< >
< Divider / >
< ListItem align = 'left' >
< ListItemText
primary = {
this . state . taker _nick +
( this . state . type ? ' ' + t ( '(Buyer)' ) : ' ' + t ( '(Seller)' ) )
}
secondary = { t ( 'Order taker' ) }
/ >
< ListItemAvatar >
< Tooltip enterTouchDelay = { 0 } title = { t ( this . state . taker _status ) } >
< Badge
variant = 'dot'
overlap = 'circular'
badgeContent = ''
color = { this . statusBadgeColor ( this . state . taker _status ) }
>
< Badge
overlap = 'circular'
anchorOrigin = { { horizontal : 'left' , vertical : 'bottom' } }
badgeContent = {
< div style = { { position : 'relative' , right : '5px' , top : '2px' } } >
{ ' ' }
{ this . state . type ? (
< SendReceiveIcon
sx = { { height : '18px' , width : '18px' } }
color = 'secondary'
/ >
) : (
< SendReceiveIcon
sx = { {
transform : 'scaleX(-1)' ,
height : '18px' ,
width : '18px' ,
} }
color = 'primary'
/ >
) }
< / d i v >
}
>
< Avatar
className = 'smallAvatar'
alt = { this . state . taker _nick }
src = {
window . location . origin +
'/static/assets/avatars/' +
this . state . taker _nick +
'.png'
}
/ >
< / B a d g e >
< / B a d g e >
< / T o o l t i p >
< / L i s t I t e m A v a t a r >
< / L i s t I t e m >
< / >
) : (
''
) }
< Divider >
< Chip label = { t ( 'Order Details' ) } / >
< / D i v i d e r >
2022-01-05 12:18:54 +00:00
< ListItem >
2022-01-14 12:00:53 +00:00
< ListItemIcon >
2022-09-09 17:18:04 +00:00
< ArticleIcon / >
2022-01-14 12:00:53 +00:00
< / L i s t I t e m I c o n >
2022-09-09 17:18:04 +00:00
< ListItemText
primary = { t ( this . state . status _message ) }
secondary = { t ( 'Order status' ) }
/ >
2022-01-05 12:18:54 +00:00
< / L i s t I t e m >
2022-09-09 17:18:04 +00:00
< Divider / >
< / >
) : (
< Divider >
< Chip label = { t ( 'Order Details' ) } / >
< / D i v i d e r >
) }
< ListItem >
< ListItemIcon >
< div
style = { {
zoom : 1.25 ,
opacity : 0.7 ,
msZoom : 1.25 ,
WebkitZoom : 1.25 ,
MozTransform : 'scale(1.25,1.25)' ,
MozTransformOrigin : 'left center' ,
} }
>
< FlagWithProps code = { this . state . currencyCode } / >
< / d i v >
< / L i s t I t e m I c o n >
{ this . state . has _range & ( this . state . amount == null ) ? (
< ListItemText
primary = {
pn ( parseFloat ( Number ( this . state . min _amount ) . toPrecision ( 4 ) ) ) +
'-' +
pn ( parseFloat ( Number ( this . state . max _amount ) . toPrecision ( 4 ) ) ) +
' ' +
this . state . currencyCode
}
secondary = { t ( 'Amount range' ) }
/ >
) : (
< ListItemText
primary = {
pn (
parseFloat (
parseFloat ( this . state . amount ) . toFixed (
this . state . currency == 1000 ? 8 : 4 ,
) ,
) ,
) +
' ' +
this . state . currencyCode
}
secondary = { t ( 'Amount' ) }
/ >
) }
< / L i s t I t e m >
< Divider / >
2022-04-15 16:22:49 +00:00
2022-09-09 17:18:04 +00:00
< ListItem >
< ListItemIcon >
< PaymentsIcon / >
< / L i s t I t e m I c o n >
< ListItemText
primary = {
< PaymentText
size = { 20 }
othersText = { t ( 'Others' ) }
verbose = { true }
text = { this . state . payment _method }
/ >
}
secondary = {
this . state . currency == 1000
? t ( 'Swap destination' )
: t ( 'Accepted payment methods' )
}
/ >
< / L i s t I t e m >
< Divider / >
{ /* If there is live Price and Premium data, show it. Otherwise show the order maker settings */ }
< ListItem >
< ListItemIcon >
< PriceChangeIcon / >
< / L i s t I t e m I c o n >
{ this . state . price _now ? (
< ListItemText
primary = { t ( '{{price}} {{currencyCode}}/BTC - Premium: {{premium}}%' , {
price : pn ( this . state . price _now ) ,
currencyCode : this . state . currencyCode ,
premium : this . state . premium _now ,
} ) }
secondary = { t ( 'Price and Premium' ) }
/ >
) : this . state . is _explicit ? (
< ListItemText
primary = { pn ( this . state . satoshis ) }
secondary = { t ( 'Amount of Satoshis' ) }
/ >
) : (
< ListItemText
primary = { parseFloat ( parseFloat ( this . state . premium ) . toFixed ( 2 ) ) + '%' }
secondary = { t ( 'Premium over market price' ) }
/ >
) }
< / L i s t I t e m >
< Divider / >
< ListItem >
< ListItemIcon >
< NumbersIcon / >
< / L i s t I t e m I c o n >
< Grid container >
< Grid item xs = { 4.5 } >
< ListItemText primary = { this . state . orderId } secondary = { t ( 'Order ID' ) } / >
< / G r i d >
< Grid item xs = { 7.5 } >
< Grid container >
< Grid item xs = { 2 } >
< ListItemIcon sx = { { position : 'relative' , top : '12px' , left : '-5px' } } >
< HourglassTopIcon / >
< / L i s t I t e m I c o n >
< / G r i d >
< Grid item xs = { 10 } >
< ListItemText
primary = { this . timerRenderer ( this . state . escrow _duration ) }
secondary = { t ( 'Deposit timer' ) }
> < / L i s t I t e m T e x t >
< / G r i d >
2022-04-29 18:54:20 +00:00
< / G r i d >
< / G r i d >
< / G r i d >
2022-09-09 17:18:04 +00:00
< / L i s t I t e m >
2022-07-02 19:51:29 +00:00
2022-09-09 17:18:04 +00:00
{ /* if order is in a status that does not expire, do not show countdown */ }
{ [ 4 , 12 , 13 , 14 , 15 , 16 , 17 , 18 ] . includes ( this . state . status ) ? null : (
< >
< Divider / >
< ListItem >
< ListItemIcon >
< AccessTimeIcon / >
< / L i s t I t e m I c o n >
< ListItemText secondary = { t ( 'Expires in' ) } >
< Countdown
date = { new Date ( this . state . expires _at ) }
renderer = { this . countdownRenderer }
/ >
< / L i s t I t e m T e x t >
< / L i s t I t e m >
< LinearDeterminate
key = { this . state . total _secs _exp }
totalSecsExp = { this . state . total _secs _exp }
expiresAt = { this . state . expires _at }
/ >
< / >
) }
2022-01-03 12:11:33 +00:00
< / L i s t >
2022-04-15 16:22:49 +00:00
2022-01-10 12:10:32 +00:00
{ /* If the user has a penalty/limit */ }
2022-09-09 17:18:04 +00:00
{ this . state . penalty ? (
< >
< Divider / >
< Grid item xs = { 12 } align = 'center' >
< Alert severity = 'warning' sx = { { maxWidth : 360 } } >
< Countdown
date = { new Date ( this . state . penalty ) }
renderer = { this . countdownPenaltyRenderer }
/ >
< / A l e r t >
< / G r i d >
< / >
) : null }
2022-04-15 16:22:49 +00:00
2022-01-23 19:02:25 +00:00
{ /* If the counterparty asked for collaborative cancel */ }
2022-09-09 17:18:04 +00:00
{ this . state . pending _cancel ? (
< >
< Divider / >
< Grid item xs = { 12 } align = 'center' >
< Alert severity = 'warning' sx = { { maxWidth : 360 } } >
{ t ( '{{nickname}} is asking for a collaborative cancel' , {
nickname : this . state . is _maker ? this . state . taker _nick : this . state . maker _nick ,
} ) }
< / A l e r t >
< / G r i d >
< / >
) : null }
2022-01-23 19:02:25 +00:00
{ /* If the user has asked for a collaborative cancel */ }
2022-09-09 17:18:04 +00:00
{ this . state . asked _for _cancel ? (
< >
< Divider / >
< Grid item xs = { 12 } align = 'center' >
< Alert severity = 'warning' sx = { { maxWidth : 360 } } >
{ t ( 'You asked for a collaborative cancellation' ) }
< / A l e r t >
< / G r i d >
< / >
) : null }
2022-01-05 00:13:08 +00:00
< / P a p e r >
2022-01-08 13:08:03 +00:00
< / G r i d >
2022-04-15 16:22:49 +00:00
2022-09-09 17:18:04 +00:00
< Grid item xs = { 12 } align = 'center' >
2022-01-23 19:02:25 +00:00
{ /* Participants can see the "Cancel" Button, but cannot see the "Back" or "Take Order" buttons */ }
2022-09-09 17:18:04 +00:00
{ this . state . is _participant ? (
2022-03-12 11:24:11 +00:00
< >
2022-05-05 21:28:54 +00:00
{ this . CancelButton ( ) }
{ this . BackButton ( ) }
2022-04-15 16:22:49 +00:00
< / >
2022-09-09 17:18:04 +00:00
) : (
2022-01-23 19:02:25 +00:00
< Grid container spacing = { 1 } >
2022-09-09 17:18:04 +00:00
< Grid item xs = { 12 } align = 'center' >
< Countdown
date = { new Date ( this . state . penalty ) }
renderer = { this . countdownTakeOrderRenderer }
/ >
2022-01-23 19:02:25 +00:00
< / G r i d >
2022-09-09 17:18:04 +00:00
< Grid item xs = { 12 } align = 'center' >
< Button variant = 'contained' color = 'secondary' onClick = { this . props . history . goBack } >
{ t ( 'Back' ) }
< / B u t t o n >
2022-01-23 19:02:25 +00:00
< / G r i d >
2022-01-08 13:08:03 +00:00
< / G r i d >
2022-09-09 17:18:04 +00:00
) }
2022-01-23 19:02:25 +00:00
< / G r i d >
2022-01-18 15:23:57 +00:00
< / G r i d >
2022-09-09 17:18:04 +00:00
) ;
} ;
2022-04-15 16:22:49 +00:00
2022-09-09 17:18:04 +00:00
doubleOrderPageDesktop = ( ) => {
return (
< Grid container align = 'center' spacing = { 2 } >
< Grid item xs = { 6 } align = 'left' style = { { width : 330 } } >
{ this . orderBox ( ) }
2022-01-27 22:51:57 +00:00
< / G r i d >
2022-09-09 17:18:04 +00:00
< Grid item xs = { 6 } align = 'left' >
< TradeBox
push = { this . props . history . push }
getOrderDetails = { this . getOrderDetails }
pauseLoading = { this . state . pauseLoading }
width = { 330 }
data = { this . state }
completeSetState = { this . completeSetState }
/ >
2022-01-27 22:51:57 +00:00
< / G r i d >
< / G r i d >
2022-09-09 17:18:04 +00:00
) ;
} ;
2022-04-15 16:22:49 +00:00
2022-01-29 14:42:54 +00:00
a11yProps ( index ) {
return {
id : ` simple-tab- ${ index } ` ,
'aria-controls' : ` simple-tabpanel- ${ index } ` ,
} ;
}
2022-09-09 17:18:04 +00:00
doubleOrderPagePhone = ( ) => {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-01-27 22:51:57 +00:00
2022-09-09 17:18:04 +00:00
return (
< Box sx = { { width : '100%' } } >
2022-01-27 22:51:57 +00:00
< Box sx = { { borderBottom : 1 , borderColor : 'divider' } } >
2022-09-09 17:18:04 +00:00
< Tabs value = { this . state . tabValue } variant = 'fullWidth' >
< Tab
label = { t ( 'Order' ) }
{ ... this . a11yProps ( 0 ) }
onClick = { ( ) => this . setState ( { tabValue : 0 } ) }
/ >
< Tab
label = { t ( 'Contract' ) }
{ ... this . a11yProps ( 1 ) }
onClick = { ( ) => this . setState ( { tabValue : 1 } ) }
/ >
2022-01-27 22:51:57 +00:00
< / T a b s >
< / B o x >
2022-01-29 14:42:54 +00:00
< Grid container spacing = { 2 } >
2022-09-09 17:18:04 +00:00
< Grid item >
< div style = { { width : 330 , display : this . state . tabValue == 0 ? '' : 'none' } } >
{ this . orderBox ( ) }
2022-01-29 14:42:54 +00:00
< / d i v >
2022-09-09 17:18:04 +00:00
< div style = { { display : this . state . tabValue == 1 ? '' : 'none' } } >
< TradeBox
push = { this . props . history . push }
getOrderDetails = { this . getOrderDetails }
pauseLoading = { this . state . pauseLoading }
width = { 330 }
data = { this . state }
completeSetState = { this . completeSetState }
/ >
2022-01-29 14:42:54 +00:00
< / d i v >
2022-01-27 22:51:57 +00:00
< / G r i d >
2022-01-29 14:42:54 +00:00
< / G r i d >
2022-01-27 22:51:57 +00:00
< / B o x >
2022-09-09 17:18:04 +00:00
) ;
} ;
2022-01-27 22:51:57 +00:00
2022-09-09 17:18:04 +00:00
orderDetailsPage ( ) {
2022-04-05 14:25:53 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
return this . state . bad _request ? (
< div align = 'center' >
< Typography variant = 'subtitle2' color = 'secondary' >
{ /* IMPLEMENT I18N for bad_request */ }
{ t ( this . state . bad _request ) }
< br / >
< / T y p o g r a p h y >
< Button variant = 'contained' color = 'secondary' onClick = { this . props . history . goBack } >
{ t ( 'Back' ) }
< / B u t t o n >
< / d i v >
) : this . state . is _participant ? (
< >
{ this . weblnDialog ( ) }
{ /* Desktop View */ }
< MediaQuery minWidth = { 920 } > { this . doubleOrderPageDesktop ( ) } < / M e d i a Q u e r y >
{ /* SmarPhone View */ }
< MediaQuery maxWidth = { 919 } > { this . doubleOrderPagePhone ( ) } < / M e d i a Q u e r y >
< / >
) : (
< Grid item xs = { 12 } align = 'center' style = { { width : 330 } } >
{ this . orderBox ( ) }
< / G r i d >
) ;
2022-01-09 20:05:19 +00:00
}
2022-08-25 08:50:48 +00:00
handleCloseWeblnDialog = ( ) => {
2022-09-09 17:18:04 +00:00
this . setState ( { openWeblnDialog : false } ) ;
} ;
2022-08-25 08:50:48 +00:00
2022-09-09 17:18:04 +00:00
weblnDialog = ( ) => {
2022-08-25 08:50:48 +00:00
const { t } = this . props ;
2022-09-09 17:18:04 +00:00
return (
2022-08-25 08:50:48 +00:00
< Dialog
open = { this . state . openWeblnDialog }
onClose = { this . handleCloseWeblnDialog }
2022-09-09 17:18:04 +00:00
aria - labelledby = 'webln-dialog-title'
aria - describedby = 'webln-dialog-description'
2022-08-25 08:50:48 +00:00
>
2022-09-09 17:18:04 +00:00
< DialogTitle id = 'webln-dialog-title' > { t ( 'WebLN' ) } < / D i a l o g T i t l e >
2022-08-25 08:50:48 +00:00
< DialogContent >
2022-09-09 17:18:04 +00:00
< DialogContentText id = 'webln-dialog-description' >
{ this . state . waitingWebln ? (
2022-08-25 08:50:48 +00:00
< >
2022-09-09 17:18:04 +00:00
< CircularProgress size = { 16 } thickness = { 5 } style = { { marginRight : 10 } } / >
{ this . state . is _buyer
? t ( 'Invoice not received, please check your WebLN wallet.' )
: t ( 'Payment not received, please check your WebLN wallet.' ) }
< / >
) : (
< >
< CheckIcon color = 'success' / >
{ t ( 'You can close now your WebLN wallet popup.' ) }
< / >
) }
2022-08-25 08:50:48 +00:00
< / D i a l o g C o n t e n t T e x t >
< / D i a l o g C o n t e n t >
< DialogActions >
2022-09-09 17:18:04 +00:00
< Button onClick = { this . handleCloseWeblnDialog } autoFocus >
{ t ( 'Done' ) }
< / B u t t o n >
2022-08-25 08:50:48 +00:00
< / D i a l o g A c t i o n s >
< / D i a l o g >
2022-09-09 17:18:04 +00:00
) ;
} ;
2022-08-25 08:50:48 +00:00
2022-09-09 17:18:04 +00:00
render ( ) {
2022-04-15 16:22:49 +00:00
return (
2022-01-09 20:05:19 +00:00
// Only so nothing shows while requesting the first batch of data
2022-01-14 14:19:25 +00:00
this . state . loading ? < CircularProgress / > : this . orderDetailsPage ( )
2022-01-02 12:59:48 +00:00
) ;
}
2022-01-09 14:29:10 +00:00
}
2022-04-05 14:25:53 +00:00
2022-04-15 16:22:49 +00:00
export default withTranslation ( ) ( OrderPage ) ;