Browse Source

Display maker status in the NavBar and an alert if maker is offline

Warn the users that some functionality might be unavailable if there is no maker
online.

Co-authored-by: rishflab <rishflab@hotmail.com>
debug-collab-settlement
Mariusz Klochowicz 3 years ago
parent
commit
cd3335e20f
No known key found for this signature in database GPG Key ID: 470C865699C8D4D
  1. 5
      taker-frontend/src/App.tsx
  2. 6
      taker-frontend/src/components/NavBar.tsx
  3. 39
      taker-frontend/src/components/Trade.tsx

5
taker-frontend/src/App.tsx

@ -93,6 +93,8 @@ export const App = () => {
const cfdsOrUndefined = useLatestEvent<Cfd[]>(source, "cfds", intoCfd); const cfdsOrUndefined = useLatestEvent<Cfd[]>(source, "cfds", intoCfd);
let cfds = cfdsOrUndefined ? cfdsOrUndefined! : []; let cfds = cfdsOrUndefined ? cfdsOrUndefined! : [];
cfds.sort((a, b) => a.order_id.localeCompare(b.order_id)); cfds.sort((a, b) => a.order_id.localeCompare(b.order_id));
const connectedToMakerOrUndefined = useLatestEvent<boolean>(source, "maker_status");
const connectedToMaker = connectedToMakerOrUndefined ? connectedToMakerOrUndefined! : false;
let [quantity, setQuantity] = useState("0"); let [quantity, setQuantity] = useState("0");
let [margin, setMargin] = useState("0"); let [margin, setMargin] = useState("0");
@ -145,7 +147,7 @@ export const App = () => {
return ( return (
<> <>
<Nav walletInfo={walletInfo} /> <Nav walletInfo={walletInfo} connectedToMaker={connectedToMaker} />
<Box textAlign="center" padding={3}> <Box textAlign="center" padding={3}>
<Routes> <Routes>
<Route path="/wallet" element={<Wallet walletInfo={walletInfo} />} /> <Route path="/wallet" element={<Wallet walletInfo={walletInfo} />} />
@ -157,6 +159,7 @@ export const App = () => {
</Center> </Center>
<VStack divider={<StackDivider borderColor="gray.500" />} spacing={4}> <VStack divider={<StackDivider borderColor="gray.500" />} spacing={4}>
<Trade <Trade
connectedToMaker={connectedToMaker}
orderId={order?.id} orderId={order?.id}
quantity={format(effectiveQuantity)} quantity={format(effectiveQuantity)}
maxQuantity={max_quantity || 0} maxQuantity={max_quantity || 0}

6
taker-frontend/src/components/NavBar.tsx

@ -3,6 +3,7 @@ import {
Box, Box,
Button, Button,
Flex, Flex,
Heading,
Image, Image,
Menu, Menu,
MenuButton, MenuButton,
@ -20,9 +21,10 @@ import { WalletInfo } from "./Types";
interface NavProps { interface NavProps {
walletInfo: WalletInfo | null; walletInfo: WalletInfo | null;
connectedToMaker: boolean;
} }
export default function Nav({ walletInfo }: NavProps) { export default function Nav({ walletInfo, connectedToMaker }: NavProps) {
const navigate = useNavigate(); const navigate = useNavigate();
const { toggleColorMode } = useColorMode(); const { toggleColorMode } = useColorMode();
@ -55,7 +57,7 @@ export default function Nav({ walletInfo }: NavProps) {
<MenuItem>Settings</MenuItem> <MenuItem>Settings</MenuItem>
</MenuList> </MenuList>
</Menu> </Menu>
<Heading size={"sm"}>{"Maker status: " + (connectedToMaker ? "Online" : "Offline")}</Heading>
<Flex alignItems={"center"}> <Flex alignItems={"center"}>
<Stack direction={"row"} spacing={7}> <Stack direction={"row"} spacing={7}>
<Button onClick={toggleColorMode} bg={"transparent"}> <Button onClick={toggleColorMode} bg={"transparent"}>

39
taker-frontend/src/components/Trade.tsx

@ -51,6 +51,7 @@ import { CfdOrderRequestPayload } from "./Types";
const MotionBox = motion<BoxProps>(Box); const MotionBox = motion<BoxProps>(Box);
interface TradeProps { interface TradeProps {
connectedToMaker: boolean;
orderId?: string; orderId?: string;
minQuantity: number; minQuantity: number;
maxQuantity: number; maxQuantity: number;
@ -81,6 +82,7 @@ function AlertBox({ title, description }: AlertBoxProps) {
const Trade = ( const Trade = (
{ {
connectedToMaker,
minQuantity, minQuantity,
maxQuantity, maxQuantity,
referencePrice: referencePriceAsNumber, referencePrice: referencePriceAsNumber,
@ -130,20 +132,33 @@ const Trade = (
let alertBox; let alertBox;
if (balanceTooLow) { if (!connectedToMaker) {
alertBox = <AlertBox title={"Your balance is too low!"} description={"Pleas deposit more into you wallet."} />;
}
if (quantityTooHigh) {
alertBox = <AlertBox title={"Quantity too high!"} description={`Max available liquidity is ${maxQuantity}`} />;
}
if (quantityTooLow || !quantityGreaterZero) {
alertBox = <AlertBox title={"Quantity too low!"} description={`Min quantity is ${minQuantity}`} />;
}
if (!orderId) {
alertBox = <AlertBox alertBox = <AlertBox
title={"No liquidity!"} title={"No maker!"}
description={"The maker you are connected has not create any offers"} description={"You are not connected to any maker. Functionality may be limited"}
/>; />;
} else {
if (balanceTooLow) {
alertBox = <AlertBox
title={"Your balance is too low!"}
description={"Pleas deposit more into you wallet."}
/>;
}
if (quantityTooHigh) {
alertBox = <AlertBox
title={"Quantity too high!"}
description={`Max available liquidity is ${maxQuantity}`}
/>;
}
if (quantityTooLow || !quantityGreaterZero) {
alertBox = <AlertBox title={"Quantity too low!"} description={`Min quantity is ${minQuantity}`} />;
}
if (!orderId) {
alertBox = <AlertBox
title={"No liquidity!"}
description={"The maker you are connected has not create any offers"}
/>;
}
} }
return ( return (

Loading…
Cancel
Save