import { Box, Button, Center, Divider, Flex, HStack, SimpleGrid, StackDivider, Text, useToast, VStack, } from "@chakra-ui/react"; import React, { useState } from "react"; import { useAsync } from "react-async"; import { Route, Routes } from "react-router-dom"; import { useEventSource } from "react-sse-hooks"; import "./App.css"; import CfdTile from "./components/CfdTile"; import CurrencyInputField from "./components/CurrencyInputField"; import useLatestEvent from "./components/Hooks"; import NavLink from "./components/NavLink"; import OrderTile from "./components/OrderTile"; import { Cfd, Order, WalletInfo } from "./components/Types"; import Wallet from "./components/Wallet"; interface CfdSellOrderPayload { price: number; min_quantity: number; max_quantity: number; } async function postCfdSellOrderRequest(payload: CfdSellOrderPayload) { let res = await fetch(`/api/order/sell`, { method: "POST", body: JSON.stringify(payload), credentials: "include" }); if (!res.status.toString().startsWith("2")) { console.log("Status: " + res.status + ", " + res.statusText); throw new Error("failed to publish new order"); } } export default function App() { let source = useEventSource({ source: "/api/feed", options: { withCredentials: true } }); const cfds = useLatestEvent(source, "cfds"); const order = useLatestEvent(source, "order"); console.log(cfds); const walletInfo = useLatestEvent(source, "wallet"); const toast = useToast(); let [minQuantity, setMinQuantity] = useState("100"); let [maxQuantity, setMaxQuantity] = useState("1000"); let [orderPrice, setOrderPrice] = useState("10000"); const format = (val: any) => `$` + val; const parse = (val: any) => val.replace(/^\$/, ""); let { run: makeNewCfdSellOrder, isLoading: isCreatingNewCfdOrder } = useAsync({ deferFn: async ([payload]: any[]) => { try { await postCfdSellOrderRequest(payload as CfdSellOrderPayload); } catch (e) { const description = typeof e === "string" ? e : JSON.stringify(e); toast({ title: "Error", description, status: "error", duration: 9000, isClosable: true, }); } }, }); return (
} > {cfds && cfds.map((cfd, index) => )} Current Price: {49000} Min Quantity: setMinQuantity(parse(valueString))} value={format(minQuantity)} /> Min Quantity: setMaxQuantity(parse(valueString))} value={format(maxQuantity)} /> Order Price: setOrderPrice(parse(valueString))} value={format(orderPrice)} /> Leverage:
Maker UI
{order && }
} >
Wallet
} > Settings } > ); }