mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 10:31:35 +00:00
Refactor tradebox states as switch, fix websocket first connect, show PGP erros.
This commit is contained in:
parent
28ef253020
commit
7665a2bb22
@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useLayoutEffect, useState } from 'react';
|
import React, { useEffect, useLayoutEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Button, Tooltip, TextField, Grid, Paper } from '@mui/material';
|
import { Button, Tooltip, TextField, Grid, Paper, Typography } from '@mui/material';
|
||||||
import { encryptMessage, decryptMessage } from '../../../../pgp';
|
import { encryptMessage, decryptMessage } from '../../../../pgp';
|
||||||
import { AuditPGPDialog } from '../../../Dialogs';
|
import { AuditPGPDialog } from '../../../Dialogs';
|
||||||
import { websocketClient, WebsocketConnection } from '../../../../services/Websocket';
|
import { websocketClient, WebsocketConnection } from '../../../../services/Websocket';
|
||||||
@ -46,10 +46,7 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
const audio = new Audio(`/static/assets/sounds/chat-open.mp3`);
|
const audio = new Audio(`/static/assets/sounds/chat-open.mp3`);
|
||||||
const [connected, setConnected] = useState<boolean>(false);
|
const [connected, setConnected] = useState<boolean>(false);
|
||||||
const [peerConnected, setPeerConnected] = useState<boolean>(false);
|
const [peerConnected, setPeerConnected] = useState<boolean>(false);
|
||||||
const [ownPubKey] = useState<string>(robot.pubKey);
|
|
||||||
const [ownEncPrivKey] = useState<string>(robot.encPrivKey);
|
|
||||||
const [peerPubKey, setPeerPubKey] = useState<string>();
|
const [peerPubKey, setPeerPubKey] = useState<string>();
|
||||||
const [token] = useState<string>(robot.token);
|
|
||||||
const [serverMessages, setServerMessages] = useState<ServerMessage[]>([]);
|
const [serverMessages, setServerMessages] = useState<ServerMessage[]>([]);
|
||||||
const [value, setValue] = useState<string>('');
|
const [value, setValue] = useState<string>('');
|
||||||
const [connection, setConnection] = useState<WebsocketConnection>();
|
const [connection, setConnection] = useState<WebsocketConnection>();
|
||||||
@ -58,12 +55,13 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
const [lastSent, setLastSent] = useState<string>('---BLANK---');
|
const [lastSent, setLastSent] = useState<string>('---BLANK---');
|
||||||
const [messageCount, setMessageCount] = useState<number>(0);
|
const [messageCount, setMessageCount] = useState<number>(0);
|
||||||
const [receivedIndexes, setReceivedIndexes] = useState<number[]>([]);
|
const [receivedIndexes, setReceivedIndexes] = useState<number[]>([]);
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!connected) {
|
if (!connected && robot.avatarLoaded) {
|
||||||
connectWebsocket();
|
connectWebsocket();
|
||||||
}
|
}
|
||||||
}, [connected]);
|
}, [connected, robot]);
|
||||||
|
|
||||||
// Make sure to not keep reconnecting once status is not Chat
|
// Make sure to not keep reconnecting once status is not Chat
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -99,7 +97,7 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
setConnected(true);
|
setConnected(true);
|
||||||
|
|
||||||
connection.send({
|
connection.send({
|
||||||
message: ownPubKey,
|
message: robot.pubKey,
|
||||||
nick: userNick,
|
nick: userNick,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -112,10 +110,10 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
const createJsonFile: () => object = () => {
|
const createJsonFile: () => object = () => {
|
||||||
return {
|
return {
|
||||||
credentials: {
|
credentials: {
|
||||||
own_public_key: ownPubKey,
|
own_public_key: robot.pubKey,
|
||||||
peer_public_key: peerPubKey,
|
peer_public_key: peerPubKey,
|
||||||
encrypted_private_key: ownEncPrivKey,
|
encrypted_private_key: robot.encPrivKey,
|
||||||
passphrase: token,
|
passphrase: robot.token,
|
||||||
},
|
},
|
||||||
messages,
|
messages,
|
||||||
};
|
};
|
||||||
@ -131,7 +129,7 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
if (
|
if (
|
||||||
connection != null &&
|
connection != null &&
|
||||||
dataFromServer.message.substring(0, 36) == `-----BEGIN PGP PUBLIC KEY BLOCK-----` &&
|
dataFromServer.message.substring(0, 36) == `-----BEGIN PGP PUBLIC KEY BLOCK-----` &&
|
||||||
dataFromServer.message != ownPubKey
|
dataFromServer.message != robot.pubKey
|
||||||
) {
|
) {
|
||||||
setPeerPubKey(dataFromServer.message);
|
setPeerPubKey(dataFromServer.message);
|
||||||
connection.send({
|
connection.send({
|
||||||
@ -143,9 +141,9 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
else if (dataFromServer.message.substring(0, 27) == `-----BEGIN PGP MESSAGE-----`) {
|
else if (dataFromServer.message.substring(0, 27) == `-----BEGIN PGP MESSAGE-----`) {
|
||||||
decryptMessage(
|
decryptMessage(
|
||||||
dataFromServer.message.split('\\').join('\n'),
|
dataFromServer.message.split('\\').join('\n'),
|
||||||
dataFromServer.user_nick == userNick ? ownPubKey : peerPubKey,
|
dataFromServer.user_nick == userNick ? robot.pubKey : peerPubKey,
|
||||||
ownEncPrivKey,
|
robot.encPrivKey,
|
||||||
token,
|
robot.token,
|
||||||
).then((decryptedData) => {
|
).then((decryptedData) => {
|
||||||
setWaitingEcho(waitingEcho ? decryptedData.decryptedMessage !== lastSent : false);
|
setWaitingEcho(waitingEcho ? decryptedData.decryptedMessage !== lastSent : false);
|
||||||
setLastSent(decryptedData.decryptedMessage === lastSent ? '----BLANK----' : lastSent);
|
setLastSent(decryptedData.decryptedMessage === lastSent ? '----BLANK----' : lastSent);
|
||||||
@ -197,9 +195,9 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onButtonClicked = (e: any) => {
|
const onButtonClicked = (e: any) => {
|
||||||
if (token && value.includes(token)) {
|
if (robot.token && value.includes(robot.token)) {
|
||||||
alert(
|
alert(
|
||||||
`Aye! You just sent your own robot token to your peer in chat, that's a catastrophic idea! So bad your message was blocked.`,
|
`Aye! You just sent your own robot robot.token to your peer in chat, that's a catastrophic idea! So bad your message was blocked.`,
|
||||||
);
|
);
|
||||||
setValue('');
|
setValue('');
|
||||||
}
|
}
|
||||||
@ -217,16 +215,16 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
setValue('');
|
setValue('');
|
||||||
setWaitingEcho(true);
|
setWaitingEcho(true);
|
||||||
setLastSent(value);
|
setLastSent(value);
|
||||||
encryptMessage(value, ownPubKey, peerPubKey, ownEncPrivKey, token).then(
|
encryptMessage(value, robot.pubKey, peerPubKey, robot.encPrivKey, robot.token)
|
||||||
(encryptedMessage) => {
|
.then((encryptedMessage) => {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.send({
|
connection.send({
|
||||||
message: encryptedMessage.toString().split('\n').join('\\'),
|
message: encryptedMessage.toString().split('\n').join('\\'),
|
||||||
nick: userNick,
|
nick: userNick,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
);
|
.catch((error) => setError(error.toString()));
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
@ -244,10 +242,10 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
onClose={() => setAudit(false)}
|
onClose={() => setAudit(false)}
|
||||||
orderId={Number(orderId)}
|
orderId={Number(orderId)}
|
||||||
messages={messages}
|
messages={messages}
|
||||||
own_pub_key={ownPubKey || ''}
|
own_pub_key={robot.pubKey || ''}
|
||||||
own_enc_priv_key={ownEncPrivKey || ''}
|
own_enc_priv_key={robot.encPrivKey || ''}
|
||||||
peer_pub_key={peerPubKey || 'Not received yet'}
|
peer_pub_key={peerPubKey || 'Not received yet'}
|
||||||
passphrase={token || ''}
|
passphrase={robot.token || ''}
|
||||||
onClickBack={() => setAudit(false)}
|
onClickBack={() => setAudit(false)}
|
||||||
/>
|
/>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
@ -343,6 +341,9 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Typography color='error' variant='caption'>
|
||||||
|
{error}
|
||||||
|
</Typography>
|
||||||
</form>
|
</form>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Button, TextField, Grid, Paper } from '@mui/material';
|
import { Button, TextField, Grid, Paper, Typography } from '@mui/material';
|
||||||
import { encryptMessage, decryptMessage } from '../../../../pgp';
|
import { encryptMessage, decryptMessage } from '../../../../pgp';
|
||||||
import { AuditPGPDialog } from '../../../Dialogs';
|
import { AuditPGPDialog } from '../../../Dialogs';
|
||||||
import { Robot } from '../../../../models';
|
import { Robot } from '../../../../models';
|
||||||
@ -45,10 +45,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
|
|
||||||
const audio = new Audio(`/static/assets/sounds/chat-open.mp3`);
|
const audio = new Audio(`/static/assets/sounds/chat-open.mp3`);
|
||||||
const [peerConnected, setPeerConnected] = useState<boolean>(false);
|
const [peerConnected, setPeerConnected] = useState<boolean>(false);
|
||||||
const [ownPubKey] = useState<string>(robot.pubKey || '');
|
|
||||||
const [ownEncPrivKey] = useState<string>(robot.encPrivKey || '');
|
|
||||||
const [peerPubKey, setPeerPubKey] = useState<string>();
|
const [peerPubKey, setPeerPubKey] = useState<string>();
|
||||||
const [token] = useState<string>(robot.token || '');
|
|
||||||
const [value, setValue] = useState<string>('');
|
const [value, setValue] = useState<string>('');
|
||||||
const [audit, setAudit] = useState<boolean>(false);
|
const [audit, setAudit] = useState<boolean>(false);
|
||||||
const [waitingEcho, setWaitingEcho] = useState<boolean>(false);
|
const [waitingEcho, setWaitingEcho] = useState<boolean>(false);
|
||||||
@ -56,6 +53,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
const [messageCount, setMessageCount] = useState<number>(0);
|
const [messageCount, setMessageCount] = useState<number>(0);
|
||||||
const [serverMessages, setServerMessages] = useState<ServerMessage[]>([]);
|
const [serverMessages, setServerMessages] = useState<ServerMessage[]>([]);
|
||||||
const [lastIndex, setLastIndex] = useState<number>(0);
|
const [lastIndex, setLastIndex] = useState<number>(0);
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (messages.length > messageCount) {
|
if (messages.length > messageCount) {
|
||||||
@ -91,10 +89,10 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
const createJsonFile: () => object = () => {
|
const createJsonFile: () => object = () => {
|
||||||
return {
|
return {
|
||||||
credentials: {
|
credentials: {
|
||||||
own_public_key: ownPubKey,
|
own_public_key: robot.pubKey,
|
||||||
peer_public_key: peerPubKey,
|
peer_public_key: peerPubKey,
|
||||||
encrypted_private_key: ownEncPrivKey,
|
encrypted_private_key: robot.encPrivKey,
|
||||||
passphrase: token,
|
passphrase: robot.token,
|
||||||
},
|
},
|
||||||
messages,
|
messages,
|
||||||
};
|
};
|
||||||
@ -106,9 +104,9 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
if (dataFromServer.message.substring(0, 27) == `-----BEGIN PGP MESSAGE-----`) {
|
if (dataFromServer.message.substring(0, 27) == `-----BEGIN PGP MESSAGE-----`) {
|
||||||
decryptMessage(
|
decryptMessage(
|
||||||
dataFromServer.message.split('\\').join('\n'),
|
dataFromServer.message.split('\\').join('\n'),
|
||||||
dataFromServer.nick == userNick ? ownPubKey : peerPubKey,
|
dataFromServer.nick == userNick ? robot.pubKey : peerPubKey,
|
||||||
ownEncPrivKey,
|
robot.encPrivKey,
|
||||||
token,
|
robot.token,
|
||||||
).then((decryptedData) => {
|
).then((decryptedData) => {
|
||||||
setLastSent(decryptedData.decryptedMessage === lastSent ? '----BLANK----' : lastSent);
|
setLastSent(decryptedData.decryptedMessage === lastSent ? '----BLANK----' : lastSent);
|
||||||
setLastIndex(lastIndex < dataFromServer.index ? dataFromServer.index : lastIndex);
|
setLastIndex(lastIndex < dataFromServer.index ? dataFromServer.index : lastIndex);
|
||||||
@ -160,9 +158,9 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onButtonClicked = (e: any) => {
|
const onButtonClicked = (e: any) => {
|
||||||
if (token && value.includes(token)) {
|
if (robot.token && value.includes(robot.token)) {
|
||||||
alert(
|
alert(
|
||||||
`Aye! You just sent your own robot token to your peer in chat, that's a catastrophic idea! So bad your message was blocked.`,
|
`Aye! You just sent your own robot robot.token to your peer in chat, that's a catastrophic idea! So bad your message was blocked.`,
|
||||||
);
|
);
|
||||||
setValue('');
|
setValue('');
|
||||||
}
|
}
|
||||||
@ -191,8 +189,8 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
else if (value != '') {
|
else if (value != '') {
|
||||||
setWaitingEcho(true);
|
setWaitingEcho(true);
|
||||||
setLastSent(value);
|
setLastSent(value);
|
||||||
encryptMessage(value, ownPubKey, peerPubKey, ownEncPrivKey, token).then(
|
encryptMessage(value, robot.pubKey, peerPubKey, robot.encPrivKey, robot.token)
|
||||||
(encryptedMessage) => {
|
.then((encryptedMessage) => {
|
||||||
apiClient
|
apiClient
|
||||||
.post(baseUrl, `/api/chat/`, {
|
.post(baseUrl, `/api/chat/`, {
|
||||||
PGP_message: encryptedMessage.toString().split('\n').join('\\'),
|
PGP_message: encryptedMessage.toString().split('\n').join('\\'),
|
||||||
@ -211,8 +209,8 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
setWaitingEcho(false);
|
setWaitingEcho(false);
|
||||||
setValue('');
|
setValue('');
|
||||||
});
|
});
|
||||||
},
|
})
|
||||||
);
|
.catch((error) => setError(error.toString()));
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
@ -230,10 +228,10 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
onClose={() => setAudit(false)}
|
onClose={() => setAudit(false)}
|
||||||
orderId={Number(orderId)}
|
orderId={Number(orderId)}
|
||||||
messages={messages}
|
messages={messages}
|
||||||
own_pub_key={ownPubKey || ''}
|
own_pub_key={robot.pubKey || ''}
|
||||||
own_enc_priv_key={ownEncPrivKey || ''}
|
own_enc_priv_key={robot.encPrivKey || ''}
|
||||||
peer_pub_key={peerPubKey || 'Not received yet'}
|
peer_pub_key={peerPubKey || 'Not received yet'}
|
||||||
passphrase={token || ''}
|
passphrase={robot.token || ''}
|
||||||
onClickBack={() => setAudit(false)}
|
onClickBack={() => setAudit(false)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -323,6 +321,9 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Typography color='error' variant='caption'>
|
||||||
|
{error}
|
||||||
|
</Typography>
|
||||||
</form>
|
</form>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ import { Order, Robot, Settings } from '../../models';
|
|||||||
import { EncryptedChatMessage } from './EncryptedChat';
|
import { EncryptedChatMessage } from './EncryptedChat';
|
||||||
import CollabCancelAlert from './CollabCancelAlert';
|
import CollabCancelAlert from './CollabCancelAlert';
|
||||||
import { Bolt } from '@mui/icons-material';
|
import { Bolt } from '@mui/icons-material';
|
||||||
|
import es from 'date-fns/esm/locale/es/index.js';
|
||||||
|
|
||||||
interface loadingButtonsProps {
|
interface loadingButtonsProps {
|
||||||
cancel: boolean;
|
cancel: boolean;
|
||||||
@ -304,276 +305,250 @@ const TradeBox = ({
|
|||||||
let prompt = () => <span>Wops!</span>;
|
let prompt = () => <span>Wops!</span>;
|
||||||
let bondStatus: 'hide' | 'locked' | 'unlocked' | 'settled' = 'hide';
|
let bondStatus: 'hide' | 'locked' | 'unlocked' | 'settled' = 'hide';
|
||||||
|
|
||||||
// 0: 'Waiting for maker bond'
|
switch (status) {
|
||||||
if (status == 0) {
|
// 0: 'Waiting for maker bond'
|
||||||
if (isMaker) {
|
case 0:
|
||||||
title = 'Lock {{amountSats}} Sats to PUBLISH order';
|
if (isMaker) {
|
||||||
titleVariables = { amountSats: pn(order.bond_satoshis) };
|
title = 'Lock {{amountSats}} Sats to PUBLISH order';
|
||||||
prompt = () => {
|
titleVariables = { amountSats: pn(order.bond_satoshis) };
|
||||||
return <LockInvoicePrompt order={order} concept={'bond'} />;
|
prompt = () => {
|
||||||
};
|
return <LockInvoicePrompt order={order} concept={'bond'} />;
|
||||||
bondStatus = 'hide';
|
};
|
||||||
}
|
bondStatus = 'hide';
|
||||||
|
}
|
||||||
|
break;
|
||||||
// 1: 'Public'
|
// 1: 'Public'
|
||||||
} else if (status == 1) {
|
case 1:
|
||||||
if (isMaker) {
|
if (isMaker) {
|
||||||
title = 'Your order is public';
|
title = 'Your order is public';
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return (
|
return (
|
||||||
<PublicWaitPrompt
|
<PublicWaitPrompt
|
||||||
order={order}
|
order={order}
|
||||||
pauseLoading={loadingButtons.pauseOrder}
|
pauseLoading={loadingButtons.pauseOrder}
|
||||||
onClickPauseOrder={pauseOrder}
|
onClickPauseOrder={pauseOrder}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
bondStatus = 'locked';
|
bondStatus = 'locked';
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
// 2: 'Paused'
|
// 2: 'Paused'
|
||||||
} else if (status == 2) {
|
case 2:
|
||||||
if (isMaker) {
|
if (isMaker) {
|
||||||
title = 'Your order is paused';
|
title = 'Your order is paused';
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return (
|
return (
|
||||||
<PausedPrompt
|
<PausedPrompt
|
||||||
pauseLoading={loadingButtons.pauseOrder}
|
pauseLoading={loadingButtons.pauseOrder}
|
||||||
onClickResumeOrder={pauseOrder}
|
onClickResumeOrder={pauseOrder}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
bondStatus = 'locked';
|
bondStatus = 'locked';
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 3: 'Waiting for taker bond'
|
// 3: 'Waiting for taker bond'
|
||||||
} else if (status == 3) {
|
case 3:
|
||||||
if (isMaker) {
|
if (isMaker) {
|
||||||
title = 'A taker has been found!';
|
title = 'A taker has been found!';
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return <TakerFoundPrompt />;
|
return <TakerFoundPrompt />;
|
||||||
};
|
};
|
||||||
bondStatus = 'locked';
|
bondStatus = 'locked';
|
||||||
} else {
|
} else {
|
||||||
title = 'Lock {{amountSats}} Sats to TAKE order';
|
title = 'Lock {{amountSats}} Sats to TAKE order';
|
||||||
titleVariables = { amountSats: pn(order.bond_satoshis) };
|
titleVariables = { amountSats: pn(order.bond_satoshis) };
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return <LockInvoicePrompt order={order} concept={'bond'} />;
|
return <LockInvoicePrompt order={order} concept={'bond'} />;
|
||||||
};
|
};
|
||||||
bondStatus = 'hide';
|
bondStatus = 'hide';
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 5: 'Expired'
|
// 5: 'Expired'
|
||||||
} else if (status == 5) {
|
case 5:
|
||||||
title = 'The order has expired';
|
title = 'The order has expired';
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return (
|
return (
|
||||||
<ExpiredPrompt
|
<ExpiredPrompt
|
||||||
loadingRenew={loadingButtons.renewOrder}
|
loadingRenew={loadingButtons.renewOrder}
|
||||||
order={order}
|
order={order}
|
||||||
onClickRenew={() => {
|
onClickRenew={() => {
|
||||||
onRenewOrder();
|
onRenewOrder();
|
||||||
setLoadingButtons({ ...noLoadingButtons, renewOrder: true });
|
setLoadingButtons({ ...noLoadingButtons, renewOrder: true });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
bondStatus = 'hide'; // To do: show bond status according to expiry message.
|
bondStatus = 'hide'; // To do: show bond status according to expiry message.
|
||||||
|
|
||||||
// 6: 'Waiting for trade collateral and buyer invoice'
|
// 6: 'Waiting for trade collateral and buyer invoice'
|
||||||
} else if (status == 6) {
|
case 6:
|
||||||
bondStatus = 'locked';
|
bondStatus = 'locked';
|
||||||
if (isBuyer) {
|
if (isBuyer) {
|
||||||
title = 'Submit payout info';
|
title = 'Submit payout info';
|
||||||
titleVariables = { amountSats: pn(order.invoice_amount) };
|
titleVariables = { amountSats: pn(order.invoice_amount) };
|
||||||
prompt = function () {
|
prompt = function () {
|
||||||
return (
|
return (
|
||||||
<PayoutPrompt
|
<PayoutPrompt
|
||||||
order={order}
|
order={order}
|
||||||
settings={settings}
|
settings={settings}
|
||||||
onClickSubmitInvoice={updateInvoice}
|
onClickSubmitInvoice={updateInvoice}
|
||||||
loadingLightning={loadingButtons.submitInvoice}
|
loadingLightning={loadingButtons.submitInvoice}
|
||||||
lightning={lightning}
|
lightning={lightning}
|
||||||
setLightning={setLightning}
|
setLightning={setLightning}
|
||||||
onClickSubmitAddress={updateAddress}
|
onClickSubmitAddress={updateAddress}
|
||||||
loadingOnchain={loadingButtons.submitAddress}
|
loadingOnchain={loadingButtons.submitAddress}
|
||||||
onchain={onchain}
|
onchain={onchain}
|
||||||
setOnchain={setOnchain}
|
setOnchain={setOnchain}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
title = 'Lock {{amountSats}} Sats as collateral';
|
title = 'Lock {{amountSats}} Sats as collateral';
|
||||||
titleVariables = { amountSats: pn(order.escrow_satoshis) };
|
titleVariables = { amountSats: pn(order.escrow_satoshis) };
|
||||||
titleColor = 'warning';
|
titleColor = 'warning';
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return <LockInvoicePrompt order={order} concept={'escrow'} />;
|
return <LockInvoicePrompt order={order} concept={'escrow'} />;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 7: 'Waiting only for seller trade collateral'
|
// 7: 'Waiting only for seller trade collateral'
|
||||||
} else if (status == 7) {
|
case 7:
|
||||||
bondStatus = 'locked';
|
bondStatus = 'locked';
|
||||||
if (isBuyer) {
|
if (isBuyer) {
|
||||||
title = 'Your info looks good!';
|
title = 'Your info looks good!';
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return <EscrowWaitPrompt />;
|
return <EscrowWaitPrompt />;
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
title = 'Lock {{amountSats}} Sats as collateral';
|
title = 'Lock {{amountSats}} Sats as collateral';
|
||||||
titleVariables = { amountSats: pn(order.escrow_satoshis) };
|
titleVariables = { amountSats: pn(order.escrow_satoshis) };
|
||||||
titleColor = 'warning';
|
titleColor = 'warning';
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return <LockInvoicePrompt order={order} concept={'escrow'} />;
|
return <LockInvoicePrompt order={order} concept={'escrow'} />;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 8: 'Waiting only for buyer invoice'
|
// 8: 'Waiting only for buyer invoice'
|
||||||
} else if (status == 8) {
|
case 8:
|
||||||
bondStatus = 'locked';
|
bondStatus = 'locked';
|
||||||
if (isBuyer) {
|
if (isBuyer) {
|
||||||
title = 'Submit payout info';
|
title = 'Submit payout info';
|
||||||
titleVariables = { amountSats: pn(order.invoice_amount) };
|
titleVariables = { amountSats: pn(order.invoice_amount) };
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return (
|
return (
|
||||||
<PayoutPrompt
|
<PayoutPrompt
|
||||||
order={order}
|
order={order}
|
||||||
settings={settings}
|
settings={settings}
|
||||||
onClickSubmitInvoice={updateInvoice}
|
onClickSubmitInvoice={updateInvoice}
|
||||||
loadingLightning={loadingButtons.submitInvoice}
|
loadingLightning={loadingButtons.submitInvoice}
|
||||||
lightning={lightning}
|
lightning={lightning}
|
||||||
setLightning={setLightning}
|
setLightning={setLightning}
|
||||||
onClickSubmitAddress={updateAddress}
|
onClickSubmitAddress={updateAddress}
|
||||||
loadingOnchain={loadingButtons.submitAddress}
|
loadingOnchain={loadingButtons.submitAddress}
|
||||||
onchain={onchain}
|
onchain={onchain}
|
||||||
setOnchain={setOnchain}
|
setOnchain={setOnchain}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
title = 'The trade collateral is locked!';
|
title = 'The trade collateral is locked!';
|
||||||
prompt = () => {
|
prompt = () => {
|
||||||
return <PayoutWaitPrompt />;
|
return <PayoutWaitPrompt />;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 9: 'Sending fiat - In chatroom'
|
// 9: 'Sending fiat - In chatroom'
|
||||||
// 10: 'Fiat sent - In chatroom'
|
// 10: 'Fiat sent - In chatroom'
|
||||||
} else if (status == 9 || status == 10) {
|
case 9:
|
||||||
title = isBuyer ? 'Chat with the seller' : 'Chat with the buyer';
|
case 10:
|
||||||
prompt = function () {
|
title = isBuyer ? 'Chat with the seller' : 'Chat with the buyer';
|
||||||
return (
|
prompt = function () {
|
||||||
<ChatPrompt
|
return (
|
||||||
order={order}
|
<ChatPrompt
|
||||||
robot={robot}
|
order={order}
|
||||||
onClickConfirmSent={() => setOpen({ ...open, confirmFiatSent: true })}
|
robot={robot}
|
||||||
onClickConfirmReceived={() => setOpen({ ...open, confirmFiatReceived: true })}
|
onClickConfirmSent={() => setOpen({ ...open, confirmFiatSent: true })}
|
||||||
loadingSent={loadingButtons.fiatSent}
|
onClickConfirmReceived={() => setOpen({ ...open, confirmFiatReceived: true })}
|
||||||
loadingReceived={loadingButtons.fiatReceived}
|
loadingSent={loadingButtons.fiatSent}
|
||||||
onClickDispute={() => setOpen({ ...open, confirmDispute: true })}
|
loadingReceived={loadingButtons.fiatReceived}
|
||||||
loadingDispute={loadingButtons.openDispute}
|
onClickDispute={() => setOpen({ ...open, confirmDispute: true })}
|
||||||
baseUrl={baseUrl}
|
loadingDispute={loadingButtons.openDispute}
|
||||||
messages={messages}
|
baseUrl={baseUrl}
|
||||||
setMessages={setMessages}
|
messages={messages}
|
||||||
/>
|
setMessages={setMessages}
|
||||||
);
|
/>
|
||||||
};
|
);
|
||||||
bondStatus = 'locked';
|
};
|
||||||
|
bondStatus = 'locked';
|
||||||
|
break;
|
||||||
|
|
||||||
// 11: 'In dispute'
|
// 11: 'In dispute'
|
||||||
} else if (status == 11) {
|
case 11:
|
||||||
bondStatus = 'settled';
|
bondStatus = 'settled';
|
||||||
if (order.statement_submitted) {
|
if (order.statement_submitted) {
|
||||||
title = 'We have received your statement';
|
title = 'We have received your statement';
|
||||||
prompt = function () {
|
prompt = function () {
|
||||||
return <DisputeWaitPeerPrompt />;
|
return <DisputeWaitPeerPrompt />;
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
title = 'A dispute has been opened';
|
title = 'A dispute has been opened';
|
||||||
prompt = function () {
|
prompt = function () {
|
||||||
return (
|
return (
|
||||||
<DisputePrompt
|
<DisputePrompt
|
||||||
loading={loadingButtons.submitStatement}
|
loading={loadingButtons.submitStatement}
|
||||||
dispute={dispute}
|
dispute={dispute}
|
||||||
setDispute={setDispute}
|
setDispute={setDispute}
|
||||||
onClickSubmit={submitStatement}
|
onClickSubmit={submitStatement}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 12: 'Collaboratively cancelled'
|
// 12: 'Collaboratively cancelled'
|
||||||
} else if (status == 12) {
|
case 12:
|
||||||
|
break;
|
||||||
// 13: 'Sending satoshis to buyer'
|
// 13: 'Sending satoshis to buyer'
|
||||||
} else if (status == 13) {
|
case 13:
|
||||||
if (isBuyer) {
|
if (isBuyer) {
|
||||||
bondStatus = 'unlocked';
|
bondStatus = 'unlocked';
|
||||||
title = 'Attempting Lightning Payment';
|
title = 'Attempting Lightning Payment';
|
||||||
prompt = function () {
|
prompt = function () {
|
||||||
return <SendingSatsPrompt />;
|
return <SendingSatsPrompt />;
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
title = 'Trade finished!';
|
title = 'Trade finished!';
|
||||||
titleColor = 'success';
|
titleColor = 'success';
|
||||||
titleIcon = function () {
|
titleIcon = function () {
|
||||||
return <Bolt xs={{ width: '1em', height: '1em' }} color='warning' />;
|
return <Bolt xs={{ width: '1em', height: '1em' }} color='warning' />;
|
||||||
};
|
};
|
||||||
prompt = function () {
|
prompt = function () {
|
||||||
return (
|
return (
|
||||||
<SuccessfulPrompt
|
<SuccessfulPrompt
|
||||||
baseUrl={baseUrl}
|
baseUrl={baseUrl}
|
||||||
order={order}
|
order={order}
|
||||||
ratePlatform={ratePlatform}
|
ratePlatform={ratePlatform}
|
||||||
onClickStartAgain={onStartAgain}
|
onClickStartAgain={onStartAgain}
|
||||||
loadingRenew={loadingButtons.renewOrder}
|
loadingRenew={loadingButtons.renewOrder}
|
||||||
onClickRenew={() => {
|
onClickRenew={() => {
|
||||||
onRenewOrder();
|
onRenewOrder();
|
||||||
setLoadingButtons({ ...noLoadingButtons, renewOrder: true });
|
setLoadingButtons({ ...noLoadingButtons, renewOrder: true });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 14: 'Sucessful trade'
|
// 14: 'Sucessful trade'
|
||||||
} else if (status == 14) {
|
case 14:
|
||||||
title = 'Trade finished!';
|
|
||||||
titleColor = 'success';
|
|
||||||
titleIcon = function () {
|
|
||||||
return <Bolt xs={{ width: '1em', height: '1em' }} color='warning' />;
|
|
||||||
};
|
|
||||||
prompt = function () {
|
|
||||||
return (
|
|
||||||
<SuccessfulPrompt
|
|
||||||
baseUrl={baseUrl}
|
|
||||||
order={order}
|
|
||||||
ratePlatform={ratePlatform}
|
|
||||||
onClickStartAgain={onStartAgain}
|
|
||||||
loadingRenew={loadingButtons.renewOrder}
|
|
||||||
onClickRenew={() => {
|
|
||||||
onRenewOrder();
|
|
||||||
setLoadingButtons({ ...noLoadingButtons, renewOrder: true });
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
// 15: 'Failed lightning network routing'
|
|
||||||
} else if (status == 15) {
|
|
||||||
if (isBuyer) {
|
|
||||||
bondStatus = 'unlocked';
|
|
||||||
title = 'Lightning Routing Failed';
|
|
||||||
prompt = function () {
|
|
||||||
return (
|
|
||||||
<RoutingFailedPrompt
|
|
||||||
order={order}
|
|
||||||
settings={settings}
|
|
||||||
onClickSubmitInvoice={updateInvoice}
|
|
||||||
loadingLightning={loadingButtons.submitInvoice}
|
|
||||||
lightning={lightning}
|
|
||||||
setLightning={setLightning}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
title = 'Trade finished!';
|
title = 'Trade finished!';
|
||||||
titleColor = 'success';
|
titleColor = 'success';
|
||||||
titleIcon = function () {
|
titleIcon = function () {
|
||||||
@ -594,29 +569,78 @@ const TradeBox = ({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
break;
|
||||||
|
|
||||||
|
// 15: 'Failed lightning network routing'
|
||||||
|
case 15:
|
||||||
|
if (isBuyer) {
|
||||||
|
bondStatus = 'unlocked';
|
||||||
|
title = 'Lightning Routing Failed';
|
||||||
|
prompt = function () {
|
||||||
|
return (
|
||||||
|
<RoutingFailedPrompt
|
||||||
|
order={order}
|
||||||
|
settings={settings}
|
||||||
|
onClickSubmitInvoice={updateInvoice}
|
||||||
|
loadingLightning={loadingButtons.submitInvoice}
|
||||||
|
lightning={lightning}
|
||||||
|
setLightning={setLightning}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
title = 'Trade finished!';
|
||||||
|
titleColor = 'success';
|
||||||
|
titleIcon = function () {
|
||||||
|
return <Bolt xs={{ width: '1em', height: '1em' }} color='warning' />;
|
||||||
|
};
|
||||||
|
prompt = function () {
|
||||||
|
return (
|
||||||
|
<SuccessfulPrompt
|
||||||
|
baseUrl={baseUrl}
|
||||||
|
order={order}
|
||||||
|
ratePlatform={ratePlatform}
|
||||||
|
onClickStartAgain={onStartAgain}
|
||||||
|
loadingRenew={loadingButtons.renewOrder}
|
||||||
|
onClickRenew={() => {
|
||||||
|
onRenewOrder();
|
||||||
|
setLoadingButtons({ ...noLoadingButtons, renewOrder: true });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 16: 'Wait for dispute resolution'
|
// 16: 'Wait for dispute resolution'
|
||||||
} else if (status == 16) {
|
case 16:
|
||||||
bondStatus = 'settled';
|
bondStatus = 'settled';
|
||||||
title = 'We have the statements';
|
title = 'We have the statements';
|
||||||
prompt = function () {
|
prompt = function () {
|
||||||
return <DisputeWaitResolutionPrompt />;
|
return <DisputeWaitResolutionPrompt />;
|
||||||
};
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
// 17: 'Maker lost dispute'
|
// 17: 'Maker lost dispute'
|
||||||
// 18: 'Taker lost dispute'
|
// 18: 'Taker lost dispute'
|
||||||
} else if ((status == 17 && isMaker) || (status == 18 && !isMaker)) {
|
case 17:
|
||||||
title = 'You have lost the dispute';
|
case 18:
|
||||||
prompt = function () {
|
if ((status === 17 && isMaker) || (status === 18 && !isMaker)) {
|
||||||
return <DisputeLoserPrompt />;
|
title = 'You have lost the dispute';
|
||||||
};
|
prompt = function () {
|
||||||
bondStatus = 'settled';
|
return <DisputeLoserPrompt />;
|
||||||
} else if ((status == 17 && !isMaker) || (status == 18 && isMaker)) {
|
};
|
||||||
title = 'You have won the dispute';
|
bondStatus = 'settled';
|
||||||
prompt = function () {
|
} else if ((status === 17 && !isMaker) || (status === 18 && isMaker)) {
|
||||||
return <DisputeWinnerPrompt />;
|
title = 'You have won the dispute';
|
||||||
};
|
prompt = function () {
|
||||||
|
return <DisputeWinnerPrompt />;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { title, titleVariables, titleColor, prompt, bondStatus, titleIcon };
|
return { title, titleVariables, titleColor, prompt, bondStatus, titleIcon };
|
||||||
|
Loading…
Reference in New Issue
Block a user