diff --git a/src/components/RowOrderLimit/index.tsx b/src/components/RowOrderLimit/index.tsx new file mode 100644 index 000000000..02a145cd2 --- /dev/null +++ b/src/components/RowOrderLimit/index.tsx @@ -0,0 +1,113 @@ +import { Currency } from '@tangoswapcash/sdk' +import React, { Key, useCallback, useState } from 'react' +import CurrencyLogo from '../CurrencyLogo' +import { InformationCircleIcon } from '@heroicons/react/solid' +import { Popover } from '@headlessui/react' +import { ClipboardCopyIcon } from '@heroicons/react/solid' +import useCopyClipboard from '../../hooks/useCopyClipboard' +import Button from '../Button' +import { i18n } from '@lingui/core' +import { t } from '@lingui/macro' +import useGetOrdersLocal from '../../hooks/useGetOrdersLocal' + +function RowOrderLimit({order, deleteOrderLocal}){ + const [isCopied, setCopied] = useCopyClipboard(1000) + + const cancelOrder = (order) => { + deleteOrderLocal(order.id) //esto solo lo borra del localstorage, no cancela la orden realmente + + //TODO cancel Order + + } + + return ( +
+
+
+
+
+ +
+
+
{order.output.value}
+
+ {order.output.currency.symbol} + + + + + + {({ close }) => { + isCopied && close() + return ( +
setCopied(order.output.currency.address)} + > + {order.output.currency.address} +
+ )} + } +
+
+
+
+
+ +
+
+
+ +
+
+
{order.input.value}
+
+ {order.input.currency.symbol} + + + + + + {({ close }) => { + isCopied && close() + return ( +
setCopied(order.input.currency.address)} + > + {order.input.currency.address} +
+ )} + } +
+
+
+
+
+
+
{order.rate}
+
+ {order.output.currency.symbol ? order.output.currency.symbol : order.output.currency.tokenInfo.symbol} per {order.input.currency.symbol} +
+
+
+ {/*
+ {order.filledPercent}% {i18n._(t`Filled`)} +
*/} +
+ +
+
+
+
+ ) +} + +export default RowOrderLimit \ No newline at end of file diff --git a/src/features/exchange-v1/limit-order/LimitOrderButton.tsx b/src/features/exchange-v1/limit-order/LimitOrderButton.tsx index 224a96047..ef020ced6 100644 --- a/src/features/exchange-v1/limit-order/LimitOrderButton.tsx +++ b/src/features/exchange-v1/limit-order/LimitOrderButton.tsx @@ -36,6 +36,7 @@ import { faTelegram } from '@fortawesome/free-brands-svg-icons'; import axios from 'axios' import { faCheck } from '@fortawesome/free-solid-svg-icons' import CashAddressInput from '../../../components/Input/Cashaddress' +import useGetOrdersLocal from '../../../hooks/useGetOrdersLocal' interface LimitOrderButtonProps extends ButtonProps { currency: Currency @@ -90,7 +91,6 @@ const LimitOrderButton: FC = ({ currency, color, ...rest const dispatch = useDispatch() const addPopup = useAddPopup() const toggleWalletModal = useWalletModalToggle() - const [openConfirmationModal, setOpenConfirmationModal] = useState(false) const [takeOrderURL, setTakeOrderURL] = useState(null) @@ -98,8 +98,10 @@ const LimitOrderButton: FC = ({ currency, color, ...rest const [clicked, wasClicked] = useState(false) const [endTimeState, setEndTimeState] = useState(null) + const orders = useGetOrdersLocal() + const { orderExpiration, recipient } = useLimitOrderState() - const { parsedAmounts, inputError } = useDerivedLimitOrderInfo() + const { parsedAmounts, inputError, currencies } = useDerivedLimitOrderInfo() const { mutate } = useLimitOrders() @@ -115,6 +117,10 @@ const LimitOrderButton: FC = ({ currency, color, ...rest (tokenApprovalState === ApprovalState.NOT_APPROVED || tokenApprovalState === ApprovalState.PENDING) const disabled = !!inputError || tokenApprovalState === ApprovalState.PENDING + + const postOrderLocal = (newOrder) => { + localStorage.setItem('orders', JSON.stringify([...orders, newOrder])) + } const handler = useCallback(async () => { const signer = library.getSigner() @@ -188,6 +194,18 @@ const LimitOrderButton: FC = ({ currency, color, ...rest } try { + let outputValue = parsedAmounts[Field.OUTPUT]?.toSignificant(6) + let inputValue = parsedAmounts[Field.INPUT]?.toSignificant(6) + let openOrderToLocalStorage = { + id: Date.now(), + status: 'open', + account, + input: {value: inputValue, currency: {...currencies[Field.INPUT], address: currencies[Field.INPUT]?.wrapped.address}}, + output: {value: outputValue, currency: currencies[Field.OUTPUT]?.tokenInfo ? currencies[Field.OUTPUT]?.tokenInfo : currencies[Field.OUTPUT]}, + orderExpiration: orderExpiration.label, + rate: Number((parseFloat(outputValue) / parseFloat(inputValue))?.toFixed(2)) + } + const sig = await signer._signTypedData(Domain, Types, msg) // o=ver8,coinsToMaker256,coinsToTaker256,dueTime80,r256,s256,v8 const order = '01' @@ -197,19 +215,19 @@ const LimitOrderButton: FC = ({ currency, color, ...rest + sig.substr(2) const url = 'https://orders.cash/take?o=' + base64EncArr(hexToArr(order)) - console.log('url: ', url) - setTakeOrderURL(url) + setTakeOrderURL(url) setOpenConfirmationModal(false) - + if (true) { + console.log('openOrderToLocalStorage: ',openOrderToLocalStorage) + postOrderLocal(openOrderToLocalStorage) addPopup({ txn: { hash: null, summary: 'Limit order created', success: true }, }) await mutate() } } catch (e) { - console.log('error: ', e) addPopup({ txn: { hash: null, @@ -337,7 +355,6 @@ const LimitOrderButton: FC = ({ currency, color, ...rest } - {button}