diff --git a/spark-frontend/src/components/Select.tsx b/spark-frontend/src/components/Select.tsx index 26867283..840d2fa2 100644 --- a/spark-frontend/src/components/Select.tsx +++ b/spark-frontend/src/components/Select.tsx @@ -8,24 +8,24 @@ import { Column } from "./Flex"; import Text, { TEXT_TYPES, TEXT_TYPES_MAP } from "./Text"; import Tooltip from "./Tooltip"; -interface IOption { - key: string; +interface IOption { + key: T; title: string; disabled?: boolean; } -interface IProps extends Omit, "onSelect"> { - options: IOption[]; - selected?: string; - onSelect: (option: IOption, index: number) => void; +interface IProps extends Omit, "onSelect"> { + options: IOption[]; + selected?: T; + onSelect: (option: IOption, index: number) => void; label?: string; } -const Select: React.FC = ({ options, selected, onSelect, label, ...rest }) => { +const Select = ({ options, selected, onSelect, label, ...rest }: IProps) => { const [isVisible, setIsVisible] = useState(false); const selectedOption = options.find(({ key }) => selected === key); - const handleSelectClick = (v: IOption, index: number) => { + const handleSelectClick = (v: IOption, index: number) => { onSelect(v, index); setIsVisible(false); }; diff --git a/spark-frontend/src/screens/TradeScreen/BottomTables/BottomTablesInterfaceSpot/BottomTablesInterfaceSpotImpl.tsx b/spark-frontend/src/screens/TradeScreen/BottomTables/BottomTablesInterfaceSpot/BottomTablesInterfaceSpotImpl.tsx index 58d01b28..d4a1c918 100644 --- a/spark-frontend/src/screens/TradeScreen/BottomTables/BottomTablesInterfaceSpot/BottomTablesInterfaceSpotImpl.tsx +++ b/spark-frontend/src/screens/TradeScreen/BottomTables/BottomTablesInterfaceSpot/BottomTablesInterfaceSpotImpl.tsx @@ -40,7 +40,7 @@ const MAX_TABLE_HEIGHT = { const TABS = [ { title: "ORDERS", disabled: false }, { title: "BALANCES", disabled: false }, - { title: "HISTORY", disabled: false }, + // { title: "HISTORY", disabled: false }, ]; const TABLE_SIZES_CONFIG = [ @@ -124,26 +124,26 @@ const BottomTablesInterfaceSpotImpl: React.FC = observer(() => { ), })); - const getHistoryData = () => - vm.myOrdersHistory.map((order) => ({ - date: order.timestamp.format("DD MMM YY, HH:mm"), - pair: order.marketSymbol, - type: ( - - {order.type} - - ), - amount: ( - - {order.baseSizeUnits.toSignificant(2)} - - {order.baseToken.symbol} - - - ), - price: toCurrency(order.priceUnits.toSignificant(2)), - filled: BN.ZERO.toString(), - })); + // const getHistoryData = () => + // vm.myOrdersHistory.map((order) => ({ + // date: order.timestamp.format("DD MMM YY, HH:mm"), + // pair: order.marketSymbol, + // type: ( + // + // {order.type} + // + // ), + // amount: ( + // + // {order.baseSizeUnits.toSignificant(2)} + // + // {order.baseToken.symbol} + // + // + // ), + // price: toCurrency(order.priceUnits.toSignificant(2)), + // filled: BN.ZERO.toString(), + // })); const getBalanceData = () => Array.from(balanceStore.balances) @@ -207,45 +207,45 @@ const BottomTablesInterfaceSpotImpl: React.FC = observer(() => { )); - const orderHistoryData = vm.myOrdersHistory.map((ord, i) => ( - - - - {ord.marketSymbol} - - - Amount - - {ord.baseSizeUnits.toSignificant(2)} - - {ord.baseToken.symbol} - - - - - - Active - - - Side: - - {ord.type} - - - - Filled: - - - - - - - - Price: - {toCurrency(ord.priceUnits.toSignificant(2))} - - - - )); + // const orderHistoryData = vm.myOrdersHistory.map((ord, i) => ( + // + // + // + // {ord.marketSymbol} + // + // + // Amount + // + // {ord.baseSizeUnits.toSignificant(2)} + // + // {ord.baseToken.symbol} + // + // + // + // + // + // Active + // + // + // Side: + // + // {ord.type} + // + // + // + // Filled: + // - + // + // + // + // + // + // Price: + // {toCurrency(ord.priceUnits.toSignificant(2))} + // + // + // + // )); const balanceData = Array.from(balanceStore.balances) .filter(([, balance]) => balance && balance.gt(0)) @@ -275,7 +275,7 @@ const BottomTablesInterfaceSpotImpl: React.FC = observer(() => { ); }); - const tabToData = [orderData, balanceData, orderHistoryData]; + const tabToData = [orderData, balanceData]; return ( @@ -318,7 +318,7 @@ const BottomTablesInterfaceSpotImpl: React.FC = observer(() => { }; useEffect(() => { - const tabToData = [getOrderData, getBalanceData, getHistoryData]; + const tabToData = [getOrderData, getBalanceData]; setData(tabToData[tabIndex]()); }, [tabIndex, vm.myOrders, balanceStore.balances]); diff --git a/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx b/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx index 239858bd..5653d1b0 100644 --- a/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx +++ b/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx @@ -1,4 +1,4 @@ -import React, { ComponentProps } from "react"; +import React, { ComponentProps, useEffect, useState } from "react"; import styled from "@emotion/styled"; import { Accordion } from "@szhsin/react-accordion"; import { observer } from "mobx-react"; @@ -20,13 +20,22 @@ import { useStores } from "@stores"; interface IProps extends ComponentProps {} -const orderTypes = [ - { title: "Market", key: "market" }, - { title: "Limit", key: "limit", disabled: true }, - { title: "Stop Market", key: "stopmarket", disabled: true }, - { title: "Stop Limit", key: "stoplimit", disabled: true }, - { title: "Take Profit", key: "takeprofit", disabled: true }, - { title: "Take Profit Limit", key: "takeprofitlimit", disabled: true }, +enum ORDER_TYPE { + Market, + Limit, + StopMarket, + StopLimit, + TakeProfit, + TakeProfitLimit, +} + +const ORDER_OPTIONS = [ + { title: "Market", key: ORDER_TYPE.Market }, + { title: "Limit", key: ORDER_TYPE.Limit }, + { title: "Stop Market", key: ORDER_TYPE.StopMarket, disabled: true }, + { title: "Stop Limit", key: ORDER_TYPE.StopLimit, disabled: true }, + { title: "Take Profit", key: ORDER_TYPE.TakeProfit, disabled: true }, + { title: "Take Profit Limit", key: ORDER_TYPE.TakeProfitLimit, disabled: true }, ]; const CreateOrderSpot: React.FC = observer(({ ...rest }) => { @@ -38,6 +47,14 @@ const CreateOrderSpot: React.FC = observer(({ ...rest }) => { const isButtonDisabled = vm.loading || !vm.canProceed; + const [orderType, setOrderType] = useState(ORDER_OPTIONS[0].key); + + useEffect(() => { + if (orderType === ORDER_TYPE.Market) { + vm.setInputPrice(market?.price ?? BN.ZERO); + } + }); + if (!market) return null; const { baseToken, quoteToken } = market; @@ -56,6 +73,14 @@ const CreateOrderSpot: React.FC = observer(({ ...rest }) => { vm.setInputTotal(value, true); }; + const handleSetPrice = (amount: BN) => { + if (orderType === ORDER_TYPE.Market) return; + + vm.setInputPrice(amount); + }; + + const isInputPriceDisabled = orderType !== ORDER_TYPE.Limit; + return ( @@ -69,7 +94,12 @@ const CreateOrderSpot: React.FC = observer(({ ...rest }) => { - setOrderType(option.key)} + /> @@ -79,7 +109,13 @@ const CreateOrderSpot: React.FC = observer(({ ...rest }) => { - +