From dfdc31b500a88ceba495298d8e852a77c47413a3 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 4 Jul 2022 00:55:07 -0400 Subject: [PATCH 01/69] =?UTF-8?q?=F0=9F=9A=A7=20Update=20Inverted=20Trade?= =?UTF-8?q?=20Title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/ChartOverlay.jsx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/components/Asset/Chart/ChartOverlay.jsx b/components/Asset/Chart/ChartOverlay.jsx index 7985cd3f8..290731a6d 100644 --- a/components/Asset/Chart/ChartOverlay.jsx +++ b/components/Asset/Chart/ChartOverlay.jsx @@ -178,7 +178,7 @@ export const Volume = styled.div` ` function ChartOverlay(props) { - const { asset, ohlc, bid, ask, spread, volume } = props + const { asset, ohlc, bid, ask, spread, volume, inverted } = props const setShowAssetInfo = useUserStore((state) => state.setShowAssetInfo) const currentPrice = asset.price ? new Big(asset.price) : new Big(0) const changeAmt = asset.priceChange24hr @@ -207,9 +207,16 @@ function ChartOverlay(props) { color={theme.palette.gray['500']} /> )} -
-  {`${asset.name} `} / ALGO -
+ {!inverted && ( +
+  {`${asset.name} `} / ALGO +
+ )} + {inverted && ( +
+  ALGO / {`${asset.name} `} +
+ )}
@@ -259,7 +266,11 @@ ChartOverlay.propTypes = { bid: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), ask: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), spread: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - volume: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) + volume: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + inverted: PropTypes.bool } +ChartOverlay.defaultProps = { + inverted: false +} export default ChartOverlay From 5cc17afc22e2e311e576428b8d7ab4a28a535a72 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 4 Jul 2022 02:30:16 -0400 Subject: [PATCH 02/69] Update Chart with inverted --- components/Asset/Chart/Chart.jsx | 6 ++++++ components/StableAssets.js | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 components/StableAssets.js diff --git a/components/Asset/Chart/Chart.jsx b/components/Asset/Chart/Chart.jsx index 419f99911..6ae5a4175 100644 --- a/components/Asset/Chart/Chart.jsx +++ b/components/Asset/Chart/Chart.jsx @@ -10,6 +10,7 @@ import styled from '@emotion/styled' import useAreaChart from '@/hooks/use-area-chart' import useCandleChart from '@/hooks/use-candle-chart' import { withAssetChartQuery } from '@/hooks/withAlgodex' +import { StableAssets } from '@/components/StableAssets' const Container = styled.div` position: relative; @@ -130,6 +131,9 @@ export function Chart({ const { candleChart } = useCandleChart(candleChartRef, volume, ohlc, autoScaleProvider) const { areaChart } = useAreaChart(areaChartRef, ohlc, autoScaleProvider) + // Check whether asset is stablecoin + const isStableAsset = StableAssets.includes(asset.id) + const onSettingsChange = useCallback( (e) => { if (e?.target?.name === 'mode') { @@ -232,6 +236,7 @@ export function Chart({ ask={overlay.orderbook.ask} spread={overlay.orderbook.spread} volume={overlay.volume} + inverted={isStableAsset} /> )} {typeof overlay.ohlc === 'undefined' && ( @@ -242,6 +247,7 @@ export function Chart({ ask={_overlay.orderbook.ask} spread={_overlay.orderbook.spread} volume={_overlay.volume} + inverted={isStableAsset} /> )} diff --git a/components/StableAssets.js b/components/StableAssets.js new file mode 100644 index 000000000..cb0dfb31b --- /dev/null +++ b/components/StableAssets.js @@ -0,0 +1,5 @@ +// Current StableCoin List. +// Should check whether to decide using of assetid or asset name +export const StableAssets = [ + 51435943 // USDC +] From b71d6345a5d452a30cb0bd3d0b651e5218ed0053 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 4 Jul 2022 19:50:43 -0400 Subject: [PATCH 03/69] =?UTF-8?q?=F0=9F=8E=A8:=20Update=20custom=20hook=20?= =?UTF-8?q?for=20stable=20coin=20detection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useAlgodex.js | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 2d61fe761..def75ca20 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -14,6 +14,8 @@ import { getIsRestricted, getIsRestrictedCountry } from '@/utils/restrictedAssets' +import { StableAssets } from '@/components/StableAssets' + import { useEffect, useMemo, useState } from 'react' import Big from 'big.js' @@ -136,17 +138,28 @@ function mapPriceData(data) { return prices.sort((a, b) => (a.time < b.time ? -1 : a.time > b.time ? 1 : 0)) } -function getOhlc(data) { - const lastPriceData = data?.chart_data[0] +function getOhlc(data, isStableAsset) { + let lastPriceData = {} - return lastPriceData - ? { - open: floatToFixed(lastPriceData.formatted_open), - high: floatToFixed(lastPriceData.formatted_high), - low: floatToFixed(lastPriceData.formatted_low), - close: floatToFixed(lastPriceData.formatted_close) + if (data?.chart_data[0]) { + if (isStableAsset) { + lastPriceData = { + open: floatToFixed(1 / data?.chart_data[0].formatted_open), + low: floatToFixed(1 / data?.chart_data[0].formatted_high), + high: floatToFixed(1 / data?.chart_data[0].formatted_low), + close: floatToFixed(1 / data?.chart_data[0].formatted_close) + } + } else { + lastPriceData = { + open: floatToFixed(data?.chart_data[0].formatted_open), + high: floatToFixed(data?.chart_data[0].formatted_high), + low: floatToFixed(data?.chart_data[0].formatted_low), + close: floatToFixed(data?.chart_data[0].formatted_close) } - : {} + } + } + + return lastPriceData } function mapVolumeData(data, volUpColor, volDownColor) { @@ -218,9 +231,10 @@ export function useAssetChartQuery({ ...rest } = useQuery(['assetChart', { id, interval }], () => fetchAssetChart(id, interval), options) + const isStableAsset = useMemo(() => StableAssets.includes(data?.asset_info.asset.index), [data]) const priceData = useMemo(() => mapPriceData(data), [data]) const volumeData = useMemo(() => mapVolumeData(data, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), [data]) - const ohlcOverlay = useMemo(() => getOhlc(data), [data]) + const ohlcOverlay = useMemo(() => getOhlc(data, isStableAsset), [data, isStableAsset]) const volume = millify(data?.chart_data[data?.chart_data.length - 1]?.asaVolume || 0) @@ -237,7 +251,8 @@ export function useAssetChartQuery({ volume: volumeData, ohlc: priceData, isLoading, - isError + isError, + isStableAsset }, isLoading, isError, From 2c9fe8f6f158dea24edbcb5820eca814a650d301 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 4 Jul 2022 20:12:02 -0400 Subject: [PATCH 04/69] =?UTF-8?q?=F0=9F=92=84:=20Update=20Chart=20Map=20Da?= =?UTF-8?q?ta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useAlgodex.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index def75ca20..0f6ea8148 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -121,9 +121,24 @@ export function useAssetPriceQuery({ return { data: { asset }, ...rest } } -function mapPriceData(data) { - const prices = - data?.chart_data.map( +function mapPriceData(data, isStableAsset) { + let prices = [] + // Use if-else condition for isStableAsset outside of iteration to speed up + if (isStableAsset) { + prices = data?.chart_data.map( + ({ formatted_open, formatted_high, formatted_low, formatted_close, unixTime }) => { + const time = parseInt(unixTime) + return { + time: time, + open: floatToFixed(1 / formatted_open), + high: floatToFixed(1 / formatted_high), + low: floatToFixed(1 / formatted_low), + close: floatToFixed(1 / formatted_close) + } + } + ) + } else { + prices = data?.chart_data.map( ({ formatted_open, formatted_high, formatted_low, formatted_close, unixTime }) => { const time = parseInt(unixTime) return { @@ -134,7 +149,9 @@ function mapPriceData(data) { close: floatToFixed(formatted_close) } } - ) || [] + ) + } + return prices.sort((a, b) => (a.time < b.time ? -1 : a.time > b.time ? 1 : 0)) } @@ -232,7 +249,7 @@ export function useAssetChartQuery({ } = useQuery(['assetChart', { id, interval }], () => fetchAssetChart(id, interval), options) const isStableAsset = useMemo(() => StableAssets.includes(data?.asset_info.asset.index), [data]) - const priceData = useMemo(() => mapPriceData(data), [data]) + const priceData = useMemo(() => mapPriceData(data, isStableAsset), [data, isStableAsset]) const volumeData = useMemo(() => mapVolumeData(data, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), [data]) const ohlcOverlay = useMemo(() => getOhlc(data, isStableAsset), [data, isStableAsset]) From fc4f24f2c9c03641ffdf3cf60ae31cd621e7038c Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 4 Jul 2022 22:52:53 -0400 Subject: [PATCH 05/69] =?UTF-8?q?=F0=9F=92=84:=20Update=20empty=20array=20?= =?UTF-8?q?handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useAlgodex.js | 47 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 0f6ea8148..237536d1f 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -125,31 +125,33 @@ function mapPriceData(data, isStableAsset) { let prices = [] // Use if-else condition for isStableAsset outside of iteration to speed up if (isStableAsset) { - prices = data?.chart_data.map( - ({ formatted_open, formatted_high, formatted_low, formatted_close, unixTime }) => { - const time = parseInt(unixTime) - return { - time: time, - open: floatToFixed(1 / formatted_open), - high: floatToFixed(1 / formatted_high), - low: floatToFixed(1 / formatted_low), - close: floatToFixed(1 / formatted_close) + prices = + data?.chart_data.map( + ({ formatted_open, formatted_high, formatted_low, formatted_close, unixTime }) => { + const time = parseInt(unixTime) + return { + time: time, + open: floatToFixed(1 / formatted_open), + high: floatToFixed(1 / formatted_high), + low: floatToFixed(1 / formatted_low), + close: floatToFixed(1 / formatted_close) + } } - } - ) + ) || [] } else { - prices = data?.chart_data.map( - ({ formatted_open, formatted_high, formatted_low, formatted_close, unixTime }) => { - const time = parseInt(unixTime) - return { - time: time, - open: floatToFixed(formatted_open), - high: floatToFixed(formatted_high), - low: floatToFixed(formatted_low), - close: floatToFixed(formatted_close) + prices = + data?.chart_data.map( + ({ formatted_open, formatted_high, formatted_low, formatted_close, unixTime }) => { + const time = parseInt(unixTime) + return { + time: time, + open: floatToFixed(formatted_open), + high: floatToFixed(formatted_high), + low: floatToFixed(formatted_low), + close: floatToFixed(formatted_close) + } } - } - ) + ) || [] } return prices.sort((a, b) => (a.time < b.time ? -1 : a.time > b.time ? 1 : 0)) @@ -222,6 +224,7 @@ export function useAssetChartQuery({ } }) { // console.log(`useAssetChartQuery(${JSON.stringify({ interval, asset })})`) + console.log('UseAlgodex:-----') const { id } = asset const { data: assetOrders, From b28db2584a9bf684c16489b6a01b9d86f0168c4b Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 4 Jul 2022 23:31:38 -0400 Subject: [PATCH 06/69] =?UTF-8?q?=F0=9F=92=84:=20Remove=20stablecoin=20che?= =?UTF-8?q?ckin=20from=20Chart=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/Chart.jsx | 14 ++++++-------- components/Asset/Chart/ChartOverlay.jsx | 8 ++++---- hooks/useAlgodex.js | 1 - 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/components/Asset/Chart/Chart.jsx b/components/Asset/Chart/Chart.jsx index 6ae5a4175..58dd53cf4 100644 --- a/components/Asset/Chart/Chart.jsx +++ b/components/Asset/Chart/Chart.jsx @@ -10,7 +10,6 @@ import styled from '@emotion/styled' import useAreaChart from '@/hooks/use-area-chart' import useCandleChart from '@/hooks/use-candle-chart' import { withAssetChartQuery } from '@/hooks/withAlgodex' -import { StableAssets } from '@/components/StableAssets' const Container = styled.div` position: relative; @@ -104,7 +103,8 @@ export function Chart({ volume, ohlc, overlay: _overlay, - onChange + onChange, + isStableAsset }) { // console.log(`Chart(`, arguments[0], `)`) const [interval, setInterval] = useState(_interval) @@ -131,9 +131,6 @@ export function Chart({ const { candleChart } = useCandleChart(candleChartRef, volume, ohlc, autoScaleProvider) const { areaChart } = useAreaChart(areaChartRef, ohlc, autoScaleProvider) - // Check whether asset is stablecoin - const isStableAsset = StableAssets.includes(asset.id) - const onSettingsChange = useCallback( (e) => { if (e?.target?.name === 'mode') { @@ -236,7 +233,7 @@ export function Chart({ ask={overlay.orderbook.ask} spread={overlay.orderbook.spread} volume={overlay.volume} - inverted={isStableAsset} + isStableAsset={isStableAsset} /> )} {typeof overlay.ohlc === 'undefined' && ( @@ -247,7 +244,7 @@ export function Chart({ ask={_overlay.orderbook.ask} spread={_overlay.orderbook.spread} volume={_overlay.volume} - inverted={isStableAsset} + isStableAsset={isStableAsset} /> )} @@ -280,7 +277,8 @@ Chart.propTypes = { }), ohlc: PropTypes.array.isRequired, volume: PropTypes.array.isRequired, - onChange: PropTypes.func + onChange: PropTypes.func, + isStableAsset: PropTypes.bool } Chart.defaultProps = { diff --git a/components/Asset/Chart/ChartOverlay.jsx b/components/Asset/Chart/ChartOverlay.jsx index 290731a6d..62f04ceb6 100644 --- a/components/Asset/Chart/ChartOverlay.jsx +++ b/components/Asset/Chart/ChartOverlay.jsx @@ -178,7 +178,7 @@ export const Volume = styled.div` ` function ChartOverlay(props) { - const { asset, ohlc, bid, ask, spread, volume, inverted } = props + const { asset, ohlc, bid, ask, spread, volume, isStableAsset } = props const setShowAssetInfo = useUserStore((state) => state.setShowAssetInfo) const currentPrice = asset.price ? new Big(asset.price) : new Big(0) const changeAmt = asset.priceChange24hr @@ -207,12 +207,12 @@ function ChartOverlay(props) { color={theme.palette.gray['500']} /> )} - {!inverted && ( + {!isStableAsset && (
 {`${asset.name} `} / ALGO
)} - {inverted && ( + {isStableAsset && (
 ALGO / {`${asset.name} `}
@@ -267,7 +267,7 @@ ChartOverlay.propTypes = { ask: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), spread: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), volume: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - inverted: PropTypes.bool + isStableAsset: PropTypes.bool } ChartOverlay.defaultProps = { diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 237536d1f..e5b2ff24b 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -224,7 +224,6 @@ export function useAssetChartQuery({ } }) { // console.log(`useAssetChartQuery(${JSON.stringify({ interval, asset })})`) - console.log('UseAlgodex:-----') const { id } = asset const { data: assetOrders, From 45a3b312f299177568dca84ef426d8ef2b207e52 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 4 Jul 2022 23:53:08 -0400 Subject: [PATCH 07/69] =?UTF-8?q?=F0=9F=92=84:=20Show=20inverted=20number?= =?UTF-8?q?=20for=20bid,=20ask,=20spread=20in=20Chart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useAlgodex.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index e5b2ff24b..209c1122d 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -195,15 +195,17 @@ function mapVolumeData(data, volUpColor, volDownColor) { return mappedData?.map((md, i) => ({ ...md, color: volumeColors[i] })) || [] } -function getBidAskSpread(orderBook) { +function getBidAskSpread(orderBook, isStableAsset) { const { buyOrders, sellOrders } = orderBook const bidPrice = buyOrders.sort((a, b) => b.asaPrice - a.asaPrice)?.[0]?.formattedPrice || 0 const askPrice = sellOrders.sort((a, b) => a.asaPrice - b.asaPrice)?.[0]?.formattedPrice || 0 - const bid = floatToFixed(bidPrice) - const ask = floatToFixed(askPrice) - const spread = floatToFixed(new Big(ask).minus(bid).abs()) + const bid = isStableAsset ? floatToFixed(1 / bidPrice) : floatToFixed(bidPrice) + const ask = isStableAsset ? floatToFixed(1 / askPrice) : floatToFixed(askPrice) + const spread = isStableAsset + ? floatToFixed(1 / new Big(ask).minus(bid).abs()) + : floatToFixed(new Big(ask).minus(bid).abs()) return { bid, ask, spread } } @@ -241,8 +243,6 @@ export function useAssetChartQuery({ [assetOrders] ) - const { bid, ask, spread } = useMemo(() => getBidAskSpread(orderBook), [orderBook]) - const { isLoading: isChartLoading, isError: isChartError, @@ -251,6 +251,10 @@ export function useAssetChartQuery({ } = useQuery(['assetChart', { id, interval }], () => fetchAssetChart(id, interval), options) const isStableAsset = useMemo(() => StableAssets.includes(data?.asset_info.asset.index), [data]) + const { bid, ask, spread } = useMemo( + () => getBidAskSpread(orderBook, isStableAsset), + [orderBook, isStableAsset] + ) const priceData = useMemo(() => mapPriceData(data, isStableAsset), [data, isStableAsset]) const volumeData = useMemo(() => mapVolumeData(data, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), [data]) const ohlcOverlay = useMemo(() => getOhlc(data, isStableAsset), [data, isStableAsset]) From 22fa8c9d16009354dc8d5170f0243777d2755777 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Wed, 6 Jul 2022 08:37:45 -0400 Subject: [PATCH 08/69] =?UTF-8?q?=F0=9F=92=84=20Add=20isStable=20to=20Sear?= =?UTF-8?q?chTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Nav/SearchSidebar/SearchTable.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/Nav/SearchSidebar/SearchTable.jsx b/components/Nav/SearchSidebar/SearchTable.jsx index 5019cdb06..ea0a729cd 100644 --- a/components/Nav/SearchSidebar/SearchTable.jsx +++ b/components/Nav/SearchSidebar/SearchTable.jsx @@ -52,7 +52,8 @@ export const mapToSearchResults = ({ unitName, isGeoBlocked, formattedASALiquidity, - formattedAlgoLiquidity + formattedAlgoLiquidity, + isStable }) => { const price = formattedPrice ? floatToFixed(formattedPrice) : hasOrders ? '--' : null @@ -72,7 +73,8 @@ export const mapToSearchResults = ({ liquidityAlgo: formattedAlgoLiquidity, liquidityAsa: formattedASALiquidity, price, - change + change, + isStable } } From 9b2024ebd795900bcf7beed5cd1fecadbe358d93 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Wed, 6 Jul 2022 09:15:12 -0400 Subject: [PATCH 09/69] =?UTF-8?q?=F0=9F=92=84=20Add=20isStable=20in=20id.j?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/trade/[id].js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pages/trade/[id].js b/pages/trade/[id].js index 4126c7f06..f9d4631a2 100644 --- a/pages/trade/[id].js +++ b/pages/trade/[id].js @@ -19,6 +19,7 @@ import { useRouter } from 'next/router' import useUserStore from '@/store/use-user-state' import useDebounce from '@/hooks/useDebounce' import detectMobileDisplay from '@/utils/detectMobileDisplay' +import { StableAssets } from '@/components/StableAssets' /** * Fetch Traded Asset Paths @@ -45,6 +46,7 @@ export async function getStaticProps({ params: { id } }) { let staticAssetPrice = {} try { staticExplorerAsset = await fetchExplorerAssetInfo(id) + console.log('staticExplorerAsset: ', staticExplorerAsset) } catch ({ response: { status } }) { switch (status) { case 404: @@ -72,6 +74,8 @@ export async function getStaticProps({ params: { id } }) { staticExplorerAsset.price_info = staticAssetPrice } + staticExplorerAsset.isStable = StableAssets.includes(id) + return { props: { staticExplorerAsset } } From 00e6c075f7a86e2cec6924a0488a5709ab5d9009 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Wed, 6 Jul 2022 09:32:05 -0400 Subject: [PATCH 10/69] =?UTF-8?q?=F0=9F=92=84=20Add=20isStable=20varialbe?= =?UTF-8?q?=20into=20asset=20in=20id.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/trade/[id].js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pages/trade/[id].js b/pages/trade/[id].js index f9d4631a2..efbc24cfe 100644 --- a/pages/trade/[id].js +++ b/pages/trade/[id].js @@ -74,7 +74,9 @@ export async function getStaticProps({ params: { id } }) { staticExplorerAsset.price_info = staticAssetPrice } - staticExplorerAsset.isStable = StableAssets.includes(id) + console.log('Page StableAssets: ', StableAssets) + console.log('Page isStable: ', id, StableAssets.includes(parseInt(id))) + staticExplorerAsset.isStable = StableAssets.includes(parseInt(id)) return { props: { staticExplorerAsset } @@ -163,7 +165,6 @@ function TradePage({ staticExplorerAsset, deviceType }) { }, [asset, setAsset, staticExplorerAsset]) const isTraded = useMemo(() => { - console.log(asset, data) return asset?.price_info?.isTraded || data?.asset?.price_info?.isTraded }, [asset, data]) From 771bf47671498101ef9fc4b0486ece98e62ba3b7 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 7 Jul 2022 08:56:11 -0400 Subject: [PATCH 11/69] =?UTF-8?q?=F0=9F=92=84=20OrderBook=20inversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 02acfabf4..d6ea6aff3 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -312,12 +312,26 @@ export function OrderBook({ isMobile, asset, orders, components }) { const dispatcher = useEventDispatch() const reduceOrders = (result, order) => { - const _price = floatToFixedDynamic(order.price, selectedPrecision, selectedPrecision) + /** + * We can implement inversion of price in custom hook + * But we can have more dynamic options here for some incidents + * For example hide when price is 0, to prevent division by 0 + */ + if (order.price === 0) { + return result + } + + let _price = asset.isStable + ? floatToFixedDynamic(1 / order.price, selectedPrecision, selectedPrecision) + : floatToFixedDynamic(order.price, selectedPrecision, selectedPrecision) const _amount = order.amount - const index = result.findIndex( - (obj) => floatToFixedDynamic(obj.price, selectedPrecision, selectedPrecision) === _price - ) + const index = result.findIndex((obj) => { + let objPrice = asset.isStable + ? floatToFixedDynamic(1 / obj.price, selectedPrecision, selectedPrecision) + : floatToFixedDynamic(obj.price, selectedPrecision, selectedPrecision) + return objPrice === _price + }) if (index !== -1) { result[index].amount += _amount From 2b221216702d7edb1ea733c11bd67fe60ac0b11c Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 7 Jul 2022 09:38:54 -0400 Subject: [PATCH 12/69] =?UTF-8?q?=F0=9F=92=84=20Invert=20TradeHistory=20pr?= =?UTF-8?q?ices=20when=20it=20is=20stable=20coin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/TradeHistory/TradeHistory.jsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/components/Asset/TradeHistory/TradeHistory.jsx b/components/Asset/TradeHistory/TradeHistory.jsx index d3ff1b49b..5d751d2b7 100644 --- a/components/Asset/TradeHistory/TradeHistory.jsx +++ b/components/Asset/TradeHistory/TradeHistory.jsx @@ -141,16 +141,19 @@ export function TradeHistory({ isMobile, asset, orders: tradesData }) { }) .map((row) => { const amount = new Big(row.amount) - + if (row.price === 0) { + return + } + const price = asset.isStable ? 1 / row.price : row.price return ( - {floatToFixed(row.price)} + {floatToFixed(price)} Date: Thu, 7 Jul 2022 11:54:30 -0400 Subject: [PATCH 13/69] Update Wallet Open Orders --- components/Wallet/Table/OpenOrdersTable.jsx | 29 ++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/components/Wallet/Table/OpenOrdersTable.jsx b/components/Wallet/Table/OpenOrdersTable.jsx index 109c8950c..1e89bf865 100644 --- a/components/Wallet/Table/OpenOrdersTable.jsx +++ b/components/Wallet/Table/OpenOrdersTable.jsx @@ -14,6 +14,7 @@ import toast from 'react-hot-toast' import useTranslation from 'next-translate/useTranslation' import useUserStore from '@/store/use-user-state' import { withWalletOrdersQuery } from '@/hooks/withAlgodex' +import { StableAssets } from '@/components/StableAssets' const OpenOrdersContainer = styled.div` display: flex; @@ -52,7 +53,29 @@ const OrderCancelButton = styled.button` export function OpenOrdersTable({ orders: _orders }) { // console.log(`OpenOrdersTable(`, arguments[0], `)`) const { t } = useTranslation('orders') - // console.log(_orders, 'orders') + // Update price in case it includes StableCoin + _orders.forEach((_order, index) => { + if (StableAssets.includes(_order.asset.id)) { + // Invert the Pair and Price + const pairs = _order.pair.split('/') + if (pairs.length > 1) { + _orders[index].calculated_pair = 'ALGO/' + pairs[0] + // _orders[index].calculated_pair = 'sdfsdf/sdfsdf' + } else { + _orders[index].calculated_pair = 'Invalid Pair' + } + + if (_order.price === 0) { + _orders[index].calculated_price = 'Invalid Price' + } else { + _orders[index].calculated_price = 1 / _orders[index].price + } + } else { + _orders[index].calculated_pair = _orders[index].pair + _orders[index].calculated_price = _orders[index].price + } + }) + const [openOrdersData, setOpenOrdersData] = useState(_orders) useEffect(() => { @@ -129,12 +152,12 @@ export function OpenOrdersTable({ orders: _orders }) { }, { Header: t('pair'), - accessor: 'pair', + accessor: 'calculated_pair', Cell: AssetNameCell }, { Header: t('price') + ' (ALGO)', - accessor: 'price', + accessor: 'calculated_price', Cell: DefaultCell }, { From e65a4cebac8b94c94fc0c3c7d8c8775eb3cc0ae1 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 7 Jul 2022 15:23:13 -0400 Subject: [PATCH 14/69] =?UTF-8?q?=F0=9F=92=84=20Update=20Wallet=20Open=20O?= =?UTF-8?q?rders,=20Order=20History=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/Table/OpenOrdersTable.jsx | 15 +++++------ components/Wallet/Table/TradeHistoryTable.jsx | 27 +++++++++++++++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/components/Wallet/Table/OpenOrdersTable.jsx b/components/Wallet/Table/OpenOrdersTable.jsx index 1e89bf865..8efdc3cb6 100644 --- a/components/Wallet/Table/OpenOrdersTable.jsx +++ b/components/Wallet/Table/OpenOrdersTable.jsx @@ -54,25 +54,24 @@ export function OpenOrdersTable({ orders: _orders }) { // console.log(`OpenOrdersTable(`, arguments[0], `)`) const { t } = useTranslation('orders') // Update price in case it includes StableCoin - _orders.forEach((_order, index) => { + _orders.forEach((_order) => { if (StableAssets.includes(_order.asset.id)) { // Invert the Pair and Price const pairs = _order.pair.split('/') if (pairs.length > 1) { - _orders[index].calculated_pair = 'ALGO/' + pairs[0] - // _orders[index].calculated_pair = 'sdfsdf/sdfsdf' + _order.calculated_pair = 'ALGO/' + pairs[0] } else { - _orders[index].calculated_pair = 'Invalid Pair' + _order.calculated_pair = 'Invalid Pair' } if (_order.price === 0) { - _orders[index].calculated_price = 'Invalid Price' + _order.calculated_price = 'Invalid Price' } else { - _orders[index].calculated_price = 1 / _orders[index].price + _order.calculated_price = 1 / _order.price } } else { - _orders[index].calculated_pair = _orders[index].pair - _orders[index].calculated_price = _orders[index].price + _order.calculated_pair = _order.pair + _order.calculated_price = _order.price } }) diff --git a/components/Wallet/Table/TradeHistoryTable.jsx b/components/Wallet/Table/TradeHistoryTable.jsx index 1aeecab37..09d38a1eb 100644 --- a/components/Wallet/Table/TradeHistoryTable.jsx +++ b/components/Wallet/Table/TradeHistoryTable.jsx @@ -11,6 +11,7 @@ import { useMemo } from 'react' import useTranslation from 'next-translate/useTranslation' import useUserStore from '@/store/use-user-state' import { withWalletTradeHistoryQuery } from '@/hooks/withAlgodex' +import { StableAssets } from '@/components/StableAssets' const OrderHistoryContainer = styled.div` display: flex; @@ -40,6 +41,28 @@ const TableWrapper = styled.div` export function TradeHistoryTable({ orders }) { //console.log(`TradeHistoryTable(`, arguments[0], `)`) const { t } = useTranslation('orders') + // Update price in case it includes StableCoin + orders.forEach((_order) => { + if (StableAssets.includes(_order.id)) { + // Invert the Pair and Price + const pairs = _order.pair.split('/') + if (pairs.length > 1) { + _order.calculated_pair = 'ALGO/' + pairs[0] + } else { + _order.calculated_pair = 'Invalid Pair' + } + + if (_order.price === 0) { + _order.calculated_price = 'Invalid Price' + } else { + _order.calculated_price = 1 / _order.price + } + } else { + _order.calculated_pair = _order.pair + _order.calculated_price = _order.price + } + }) + const walletOrderHistoryTableState = useUserStore((state) => state.walletOrderHistoryTableState) const setWalletOrderHistoryTableState = useUserStore( (state) => state.setWalletOrderHistoryTableState @@ -57,7 +80,7 @@ export function TradeHistoryTable({ orders }) { }, { Header: t('pair'), - accessor: 'pair', + accessor: 'calculated_pair', Cell: AssetNameCell }, { @@ -68,7 +91,7 @@ export function TradeHistoryTable({ orders }) { { Header: t('price') + ' (ALGO)', - accessor: 'price', + accessor: 'calculated_price', Cell: DefaultCell }, { From d5a2360a1ab26a8f2f4f8b94b2377af8513c274b Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 7 Jul 2022 15:40:19 -0400 Subject: [PATCH 15/69] =?UTF-8?q?=F0=9F=94=A5=20Removed=20temporary=20isSt?= =?UTF-8?q?able=20in=20Chart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/Chart.jsx | 8 ++------ components/StableAssets.js | 3 ++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/components/Asset/Chart/Chart.jsx b/components/Asset/Chart/Chart.jsx index 58dd53cf4..419f99911 100644 --- a/components/Asset/Chart/Chart.jsx +++ b/components/Asset/Chart/Chart.jsx @@ -103,8 +103,7 @@ export function Chart({ volume, ohlc, overlay: _overlay, - onChange, - isStableAsset + onChange }) { // console.log(`Chart(`, arguments[0], `)`) const [interval, setInterval] = useState(_interval) @@ -233,7 +232,6 @@ export function Chart({ ask={overlay.orderbook.ask} spread={overlay.orderbook.spread} volume={overlay.volume} - isStableAsset={isStableAsset} /> )} {typeof overlay.ohlc === 'undefined' && ( @@ -244,7 +242,6 @@ export function Chart({ ask={_overlay.orderbook.ask} spread={_overlay.orderbook.spread} volume={_overlay.volume} - isStableAsset={isStableAsset} /> )} @@ -277,8 +274,7 @@ Chart.propTypes = { }), ohlc: PropTypes.array.isRequired, volume: PropTypes.array.isRequired, - onChange: PropTypes.func, - isStableAsset: PropTypes.bool + onChange: PropTypes.func } Chart.defaultProps = { diff --git a/components/StableAssets.js b/components/StableAssets.js index cb0dfb31b..2e5844d4c 100644 --- a/components/StableAssets.js +++ b/components/StableAssets.js @@ -1,5 +1,6 @@ // Current StableCoin List. // Should check whether to decide using of assetid or asset name export const StableAssets = [ - 51435943 // USDC + 51435943, // USDC, + 37074699 // USDC ] From b6b482502285c4489030c4546ba22501ed56b085 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 7 Jul 2022 15:44:23 -0400 Subject: [PATCH 16/69] =?UTF-8?q?=F0=9F=94=A5=20Removed=20temporary=20isSt?= =?UTF-8?q?able=20in=20ChartOverLay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/ChartOverlay.jsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/components/Asset/Chart/ChartOverlay.jsx b/components/Asset/Chart/ChartOverlay.jsx index 62f04ceb6..4012f5a52 100644 --- a/components/Asset/Chart/ChartOverlay.jsx +++ b/components/Asset/Chart/ChartOverlay.jsx @@ -178,7 +178,7 @@ export const Volume = styled.div` ` function ChartOverlay(props) { - const { asset, ohlc, bid, ask, spread, volume, isStableAsset } = props + const { asset, ohlc, bid, ask, spread, volume } = props const setShowAssetInfo = useUserStore((state) => state.setShowAssetInfo) const currentPrice = asset.price ? new Big(asset.price) : new Big(0) const changeAmt = asset.priceChange24hr @@ -207,12 +207,12 @@ function ChartOverlay(props) { color={theme.palette.gray['500']} /> )} - {!isStableAsset && ( + {!asset.isStable && (
 {`${asset.name} `} / ALGO
)} - {isStableAsset && ( + {asset.isStable && (
 ALGO / {`${asset.name} `}
@@ -266,8 +266,7 @@ ChartOverlay.propTypes = { bid: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), ask: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), spread: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - volume: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - isStableAsset: PropTypes.bool + volume: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) } ChartOverlay.defaultProps = { From d92be6cf6315ccb5b629923c28133d63a776185d Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 7 Jul 2022 15:45:18 -0400 Subject: [PATCH 17/69] =?UTF-8?q?=F0=9F=94=A5=20Removed=20temporary=20inve?= =?UTF-8?q?rted=20in=20ChartOverLay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/ChartOverlay.jsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/Asset/Chart/ChartOverlay.jsx b/components/Asset/Chart/ChartOverlay.jsx index 4012f5a52..7b79f79a5 100644 --- a/components/Asset/Chart/ChartOverlay.jsx +++ b/components/Asset/Chart/ChartOverlay.jsx @@ -268,8 +268,4 @@ ChartOverlay.propTypes = { spread: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), volume: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) } - -ChartOverlay.defaultProps = { - inverted: false -} export default ChartOverlay From 808e6a1901ef176006e098ddfb3aad3553889b2b Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 7 Jul 2022 15:53:33 -0400 Subject: [PATCH 18/69] =?UTF-8?q?=F0=9F=92=84=20Invert=20Bid,=20ask,=20spr?= =?UTF-8?q?ead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useAlgodex.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 209c1122d..321c1d2b2 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -76,7 +76,8 @@ export function useSearchResultsQuery({ return { ...asset, isRestricted, - isGeoBlocked: getIsRestrictedCountry(router.query) && isRestricted + isGeoBlocked: getIsRestrictedCountry(router.query) && isRestricted, + isStable: StableAssets.includes(asset.assetId) } }) } @@ -201,6 +202,10 @@ function getBidAskSpread(orderBook, isStableAsset) { const bidPrice = buyOrders.sort((a, b) => b.asaPrice - a.asaPrice)?.[0]?.formattedPrice || 0 const askPrice = sellOrders.sort((a, b) => a.asaPrice - b.asaPrice)?.[0]?.formattedPrice || 0 + // const bid = floatToFixed(bidPrice) + // const ask = floatToFixed(askPrice) + // const spread = floatToFixed(new Big(ask).minus(bid).abs()) + const bid = isStableAsset ? floatToFixed(1 / bidPrice) : floatToFixed(bidPrice) const ask = isStableAsset ? floatToFixed(1 / askPrice) : floatToFixed(askPrice) const spread = isStableAsset @@ -250,14 +255,13 @@ export function useAssetChartQuery({ ...rest } = useQuery(['assetChart', { id, interval }], () => fetchAssetChart(id, interval), options) - const isStableAsset = useMemo(() => StableAssets.includes(data?.asset_info.asset.index), [data]) const { bid, ask, spread } = useMemo( - () => getBidAskSpread(orderBook, isStableAsset), - [orderBook, isStableAsset] + () => getBidAskSpread(orderBook, asset.isStable), + [orderBook] ) - const priceData = useMemo(() => mapPriceData(data, isStableAsset), [data, isStableAsset]) + const priceData = useMemo(() => mapPriceData(data, asset.isStable), [data]) const volumeData = useMemo(() => mapVolumeData(data, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), [data]) - const ohlcOverlay = useMemo(() => getOhlc(data, isStableAsset), [data, isStableAsset]) + const ohlcOverlay = useMemo(() => getOhlc(data, asset.isStable), [data]) const volume = millify(data?.chart_data[data?.chart_data.length - 1]?.asaVolume || 0) @@ -274,8 +278,7 @@ export function useAssetChartQuery({ volume: volumeData, ohlc: priceData, isLoading, - isError, - isStableAsset + isError }, isLoading, isError, From c965c88a74f303a180f8d88b77de5f737142c023 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 11 Jul 2022 15:46:49 -0400 Subject: [PATCH 19/69] =?UTF-8?q?=F0=9F=92=84:=20Update=20mapOpenOrderData?= =?UTF-8?q?=20in=20customHooks=20for=20OpenOrderPrice=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/Table/OpenOrdersTable.jsx | 27 ++------------------- hooks/useAlgodex.js | 11 +++++++-- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/components/Wallet/Table/OpenOrdersTable.jsx b/components/Wallet/Table/OpenOrdersTable.jsx index 8efdc3cb6..c1ee7d45e 100644 --- a/components/Wallet/Table/OpenOrdersTable.jsx +++ b/components/Wallet/Table/OpenOrdersTable.jsx @@ -14,7 +14,6 @@ import toast from 'react-hot-toast' import useTranslation from 'next-translate/useTranslation' import useUserStore from '@/store/use-user-state' import { withWalletOrdersQuery } from '@/hooks/withAlgodex' -import { StableAssets } from '@/components/StableAssets' const OpenOrdersContainer = styled.div` display: flex; @@ -53,28 +52,6 @@ const OrderCancelButton = styled.button` export function OpenOrdersTable({ orders: _orders }) { // console.log(`OpenOrdersTable(`, arguments[0], `)`) const { t } = useTranslation('orders') - // Update price in case it includes StableCoin - _orders.forEach((_order) => { - if (StableAssets.includes(_order.asset.id)) { - // Invert the Pair and Price - const pairs = _order.pair.split('/') - if (pairs.length > 1) { - _order.calculated_pair = 'ALGO/' + pairs[0] - } else { - _order.calculated_pair = 'Invalid Pair' - } - - if (_order.price === 0) { - _order.calculated_price = 'Invalid Price' - } else { - _order.calculated_price = 1 / _order.price - } - } else { - _order.calculated_pair = _order.pair - _order.calculated_price = _order.price - } - }) - const [openOrdersData, setOpenOrdersData] = useState(_orders) useEffect(() => { @@ -151,12 +128,12 @@ export function OpenOrdersTable({ orders: _orders }) { }, { Header: t('pair'), - accessor: 'calculated_pair', + accessor: 'pair', Cell: AssetNameCell }, { Header: t('price') + ' (ALGO)', - accessor: 'calculated_price', + accessor: 'price', Cell: DefaultCell }, { diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 321c1d2b2..6c89640ef 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -506,13 +506,20 @@ const mapOpenOrdersData = (data) => { const buyOrders = buyOrdersData.map((order) => { const { assetId, formattedPrice, formattedASAAmount, unix_time } = order + let pair = `${assetsInfo[assetId].params['unit-name']}/ALGO` + let price = floatToFixed(formattedPrice) + + if (StableAssets.includes(assetId)) { + pair = `ALGO/${assetsInfo[assetId].params['unit-name']}` + price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) : 'Invalid Price' + } return { asset: { id: assetId }, date: dayjs.unix(unix_time).format('YYYY-MM-DD HH:mm:ss'), // date: moment(unix_time, 'YYYY-MM-DD HH:mm').format(), unix_time: unix_time, - price: floatToFixed(formattedPrice), - pair: `${assetsInfo[assetId].params['unit-name']}/ALGO`, + price: price, + pair: pair, type: 'BUY', status: 'OPEN', amount: formattedASAAmount, From 64e65160e22623d4f55c09482d79a8b06461476d Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 11 Jul 2022 16:15:00 -0400 Subject: [PATCH 20/69] =?UTF-8?q?=F0=9F=92=84=20Update=20TradeHistory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/Table/TradeHistoryTable.jsx | 27 ++----------------- hooks/useAlgodex.js | 10 +++++-- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/components/Wallet/Table/TradeHistoryTable.jsx b/components/Wallet/Table/TradeHistoryTable.jsx index 09d38a1eb..1aeecab37 100644 --- a/components/Wallet/Table/TradeHistoryTable.jsx +++ b/components/Wallet/Table/TradeHistoryTable.jsx @@ -11,7 +11,6 @@ import { useMemo } from 'react' import useTranslation from 'next-translate/useTranslation' import useUserStore from '@/store/use-user-state' import { withWalletTradeHistoryQuery } from '@/hooks/withAlgodex' -import { StableAssets } from '@/components/StableAssets' const OrderHistoryContainer = styled.div` display: flex; @@ -41,28 +40,6 @@ const TableWrapper = styled.div` export function TradeHistoryTable({ orders }) { //console.log(`TradeHistoryTable(`, arguments[0], `)`) const { t } = useTranslation('orders') - // Update price in case it includes StableCoin - orders.forEach((_order) => { - if (StableAssets.includes(_order.id)) { - // Invert the Pair and Price - const pairs = _order.pair.split('/') - if (pairs.length > 1) { - _order.calculated_pair = 'ALGO/' + pairs[0] - } else { - _order.calculated_pair = 'Invalid Pair' - } - - if (_order.price === 0) { - _order.calculated_price = 'Invalid Price' - } else { - _order.calculated_price = 1 / _order.price - } - } else { - _order.calculated_pair = _order.pair - _order.calculated_price = _order.price - } - }) - const walletOrderHistoryTableState = useUserStore((state) => state.walletOrderHistoryTableState) const setWalletOrderHistoryTableState = useUserStore( (state) => state.setWalletOrderHistoryTableState @@ -80,7 +57,7 @@ export function TradeHistoryTable({ orders }) { }, { Header: t('pair'), - accessor: 'calculated_pair', + accessor: 'pair', Cell: AssetNameCell }, { @@ -91,7 +68,7 @@ export function TradeHistoryTable({ orders }) { { Header: t('price') + ' (ALGO)', - accessor: 'calculated_price', + accessor: 'price', Cell: DefaultCell }, { diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 6c89640ef..a7104378b 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -529,13 +529,19 @@ const mapOpenOrdersData = (data) => { const sellOrders = sellOrdersData.map((order) => { const { assetId, formattedPrice, formattedASAAmount, unix_time } = order + let pair = `${assetsInfo[assetId].params['unit-name']}/ALGO` + let price = floatToFixed(formattedPrice) + if (StableAssets.includes(assetId)) { + pair = `ALGO/${assetsInfo[assetId].params['unit-name']}` + price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) : 'Invalid Price' + } return { asset: { id: assetId }, date: dayjs.unix(unix_time).format('YYYY-MM-DD HH:mm:ss'), unix_time: unix_time, - price: floatToFixed(formattedPrice), - pair: `${assetsInfo[assetId].params['unit-name']}/ALGO`, + price: price, + pair: pair, type: 'SELL', status: 'OPEN', amount: formattedASAAmount, From 814f1c819ad4311810908f87d86eb5334b8e077c Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 11 Jul 2022 18:21:15 -0400 Subject: [PATCH 21/69] =?UTF-8?q?=F0=9F=92=84=20Handle=20division=20by=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 13 +++++++++++-- hooks/useAlgodex.js | 22 ++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index d6ea6aff3..9fb4fdfc2 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -316,8 +316,11 @@ export function OrderBook({ isMobile, asset, orders, components }) { * We can implement inversion of price in custom hook * But we can have more dynamic options here for some incidents * For example hide when price is 0, to prevent division by 0 + * Compare using double equal operator instead of triple equal operator + * because the value is string value */ - if (order.price === 0) { + console.log('Obj Price: ', order.price, typeof order.price, order.price == 0) + if (order.price == 0) { return result } @@ -327,8 +330,14 @@ export function OrderBook({ isMobile, asset, orders, components }) { const _amount = order.amount const index = result.findIndex((obj) => { + /* + * Compare using double equal operator instead of triple equal operator + * because the value is string value + */ let objPrice = asset.isStable - ? floatToFixedDynamic(1 / obj.price, selectedPrecision, selectedPrecision) + ? obj.price == 0 + ? 'Invalid Price' + : floatToFixedDynamic(1 / obj.price, selectedPrecision, selectedPrecision) : floatToFixedDynamic(obj.price, selectedPrecision, selectedPrecision) return objPrice === _price }) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index a7104378b..69f72a767 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -198,7 +198,7 @@ function mapVolumeData(data, volUpColor, volDownColor) { function getBidAskSpread(orderBook, isStableAsset) { const { buyOrders, sellOrders } = orderBook - + console.log('buyOrders: ', buyOrders) const bidPrice = buyOrders.sort((a, b) => b.asaPrice - a.asaPrice)?.[0]?.formattedPrice || 0 const askPrice = sellOrders.sort((a, b) => a.asaPrice - b.asaPrice)?.[0]?.formattedPrice || 0 @@ -206,11 +206,21 @@ function getBidAskSpread(orderBook, isStableAsset) { // const ask = floatToFixed(askPrice) // const spread = floatToFixed(new Big(ask).minus(bid).abs()) - const bid = isStableAsset ? floatToFixed(1 / bidPrice) : floatToFixed(bidPrice) - const ask = isStableAsset ? floatToFixed(1 / askPrice) : floatToFixed(askPrice) - const spread = isStableAsset - ? floatToFixed(1 / new Big(ask).minus(bid).abs()) - : floatToFixed(new Big(ask).minus(bid).abs()) + let bid = floatToFixed(bidPrice) + let ask = floatToFixed(askPrice) + let spread = floatToFixed(new Big(ask).minus(bid).abs()) + + if (isStableAsset) { + bid = bidPrice === 0 ? 'Invalid Price' : floatToFixed(1 / bidPrice) + ask = askPrice === 0 ? 'Invalid Price' : floatToFixed(1 / askPrice) + if (bidPrice === 0 || bidPrice === 0 || bidPrice === askPrice) { + spread = 'Invalid Price' + } else { + console.log('ask: ', ask, 'bid: ', bid) + console.log('askPrice: ', askPrice, 'bidPrice: ', bidPrice) + spread = floatToFixed(1 / new Big(ask).minus(bid).abs()) + } + } return { bid, ask, spread } } From 47ce30c05232793f3bc3d7a2fdd9519f803acd74 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 12 Jul 2022 08:46:55 -0400 Subject: [PATCH 22/69] =?UTF-8?q?=F0=9F=92=84=20Fix=20duplication=20price?= =?UTF-8?q?=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 22 +++++++++++++--------- pages/trade/[id].js | 2 -- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 9fb4fdfc2..79d8fbe3e 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -319,7 +319,6 @@ export function OrderBook({ isMobile, asset, orders, components }) { * Compare using double equal operator instead of triple equal operator * because the value is string value */ - console.log('Obj Price: ', order.price, typeof order.price, order.price == 0) if (order.price == 0) { return result } @@ -334,12 +333,12 @@ export function OrderBook({ isMobile, asset, orders, components }) { * Compare using double equal operator instead of triple equal operator * because the value is string value */ - let objPrice = asset.isStable - ? obj.price == 0 - ? 'Invalid Price' - : floatToFixedDynamic(1 / obj.price, selectedPrecision, selectedPrecision) - : floatToFixedDynamic(obj.price, selectedPrecision, selectedPrecision) - return objPrice === _price + // let objPrice = asset.isStable + // ? obj.price == 0 + // ? 'Invalid Price' + // : floatToFixedDynamic(1 / obj.price, selectedPrecision, selectedPrecision) + // : floatToFixedDynamic(obj.price, selectedPrecision, selectedPrecision) + return obj.price === order.price }) if (index !== -1) { @@ -380,7 +379,12 @@ export function OrderBook({ isMobile, asset, orders, components }) { const renderOrders = (data, type) => { const color = type === 'buy' ? 'green' : 'red' - return data.map((row) => { + /*** + * Use index variable to be used as key in + * When it use the price as the key for stable coin sometimes there might be duplicated same prices divided by 1 + * */ + + return data.map((row, index) => { const amount = new Big(row.amount) const total = new Big(row.total) @@ -398,7 +402,7 @@ export function OrderBook({ isMobile, asset, orders, components }) { return ( diff --git a/pages/trade/[id].js b/pages/trade/[id].js index efbc24cfe..08d9bc53c 100644 --- a/pages/trade/[id].js +++ b/pages/trade/[id].js @@ -74,8 +74,6 @@ export async function getStaticProps({ params: { id } }) { staticExplorerAsset.price_info = staticAssetPrice } - console.log('Page StableAssets: ', StableAssets) - console.log('Page isStable: ', id, StableAssets.includes(parseInt(id))) staticExplorerAsset.isStable = StableAssets.includes(parseInt(id)) return { From e0e2ed524fb7ce3580851618a3234cd53b931e21 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 12 Jul 2022 11:03:06 -0400 Subject: [PATCH 23/69] =?UTF-8?q?=F0=9F=91=94=20Update=20Logic=20for=20agg?= =?UTF-8?q?regate=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 79d8fbe3e..84f8b5673 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -328,18 +328,9 @@ export function OrderBook({ isMobile, asset, orders, components }) { : floatToFixedDynamic(order.price, selectedPrecision, selectedPrecision) const _amount = order.amount - const index = result.findIndex((obj) => { - /* - * Compare using double equal operator instead of triple equal operator - * because the value is string value - */ - // let objPrice = asset.isStable - // ? obj.price == 0 - // ? 'Invalid Price' - // : floatToFixedDynamic(1 / obj.price, selectedPrecision, selectedPrecision) - // : floatToFixedDynamic(obj.price, selectedPrecision, selectedPrecision) - return obj.price === order.price - }) + const index = result.findIndex( + (obj) => floatToFixedDynamic(obj.price, selectedPrecision, selectedPrecision) === _price + ) if (index !== -1) { result[index].amount += _amount From f04ef9c3ee66ad4967f0a3831e001a64fff2cf72 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 12 Jul 2022 11:08:09 -0400 Subject: [PATCH 24/69] =?UTF-8?q?=F0=9F=91=94=20Update=20Logic=20for=20agg?= =?UTF-8?q?regate=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 9 ++------- hooks/useAlgodex.js | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 84f8b5673..6a489d640 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -370,12 +370,7 @@ export function OrderBook({ isMobile, asset, orders, components }) { const renderOrders = (data, type) => { const color = type === 'buy' ? 'green' : 'red' - /*** - * Use index variable to be used as key in - * When it use the price as the key for stable coin sometimes there might be duplicated same prices divided by 1 - * */ - - return data.map((row, index) => { + return data.map((row) => { const amount = new Big(row.amount) const total = new Big(row.total) @@ -393,7 +388,7 @@ export function OrderBook({ isMobile, asset, orders, components }) { return ( diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 69f72a767..fc735998e 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -198,7 +198,6 @@ function mapVolumeData(data, volUpColor, volDownColor) { function getBidAskSpread(orderBook, isStableAsset) { const { buyOrders, sellOrders } = orderBook - console.log('buyOrders: ', buyOrders) const bidPrice = buyOrders.sort((a, b) => b.asaPrice - a.asaPrice)?.[0]?.formattedPrice || 0 const askPrice = sellOrders.sort((a, b) => a.asaPrice - b.asaPrice)?.[0]?.formattedPrice || 0 From 727544740948732d8bb9494c14864a250c7ab29f Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 12 Jul 2022 17:34:45 -0400 Subject: [PATCH 25/69] =?UTF-8?q?=F0=9F=92=84=20Update=20required=20as=20n?= =?UTF-8?q?umber/string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/order-form.jsx | 2 +- components/Wallet/PriceConversion/USDPrice.jsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index ac6378bf7..a41150212 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -29,7 +29,7 @@ export const USDInputPrice = ({ value, id }) => { } USDInputPrice.propTypes = { - value: PropTypes.number, + value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), id: PropTypes.string } diff --git a/components/Wallet/PriceConversion/USDPrice.jsx b/components/Wallet/PriceConversion/USDPrice.jsx index 8a2bd8632..23572c4f9 100644 --- a/components/Wallet/PriceConversion/USDPrice.jsx +++ b/components/Wallet/PriceConversion/USDPrice.jsx @@ -12,8 +12,8 @@ export function USDPrice({ asaWorth, algoPrice, priceToConvert, currency }) { USDPrice.propTypes = { algoPrice: PropTypes.any, - priceToConvert: PropTypes.number, - asaWorth: PropTypes.number, + priceToConvert: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, + asaWorth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, currency: PropTypes.string } From 97dee881e5c6328789f358bce4fd9d32713c248e Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 12 Jul 2022 23:23:26 -0400 Subject: [PATCH 26/69] =?UTF-8?q?=F0=9F=92=84=20Update=20required=20as=20n?= =?UTF-8?q?umber/string=20in=20OrderBook=20&=20Slider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 4 ++-- components/Wallet/PlaceOrder/Original/amount-range/index.jsx | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 6a489d640..572e2a060 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -498,7 +498,7 @@ OrderBook.propTypes = { sell: PropTypes.arrayOf( PropTypes.shape({ amount: PropTypes.number.isRequired, - price: PropTypes.number.isRequired, + price: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, total: PropTypes.number.isRequired }) ), @@ -508,7 +508,7 @@ OrderBook.propTypes = { buy: PropTypes.arrayOf( PropTypes.shape({ amount: PropTypes.number.isRequired, - price: PropTypes.number.isRequired, + price: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, total: PropTypes.number.isRequired }) ) diff --git a/components/Wallet/PlaceOrder/Original/amount-range/index.jsx b/components/Wallet/PlaceOrder/Original/amount-range/index.jsx index 8683532d7..8d50f7572 100644 --- a/components/Wallet/PlaceOrder/Original/amount-range/index.jsx +++ b/components/Wallet/PlaceOrder/Original/amount-range/index.jsx @@ -103,7 +103,6 @@ function AmountRange(props) { value={value || 0} marks={marks} defaultValue={0} - orderType={order.type} max={100} /> From 5f0547771b201f5835390d7818bff7ef1ee7b55a Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 12 Jul 2022 23:49:21 -0400 Subject: [PATCH 27/69] =?UTF-8?q?=F0=9F=92=84=20Update=20th-child=20to=20t?= =?UTF-8?q?h-of-type=20due=20to=20SSR=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 2 +- components/Asset/TradeHistory/TradeHistory.jsx | 2 +- components/Table/Table.jsx | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 572e2a060..ff16eb446 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -154,7 +154,7 @@ const BookRow = styled.div` }}; p { - &:not(:first-child) { + &:not(:first-of-type) { color: ${({ theme }) => theme.palette.gray['000']}; } } diff --git a/components/Asset/TradeHistory/TradeHistory.jsx b/components/Asset/TradeHistory/TradeHistory.jsx index 5d751d2b7..3c761fe55 100644 --- a/components/Asset/TradeHistory/TradeHistory.jsx +++ b/components/Asset/TradeHistory/TradeHistory.jsx @@ -88,7 +88,7 @@ const TradesRow = styled.div` }}; p { - &:not(:first-child) { + &:not(:first-of-type) { color: ${({ theme }) => theme.palette.gray['000']}; } } diff --git a/components/Table/Table.jsx b/components/Table/Table.jsx index 8a53842fe..5f6333884 100644 --- a/components/Table/Table.jsx +++ b/components/Table/Table.jsx @@ -42,14 +42,14 @@ const Container = styled.div` // cursor: pointer; } - &:nth-child(odd) { + &:nth-of-type(odd) { td { background-color: ${({ theme }) => rgba(theme.palette.gray['000'], 0.01)}; } } - &:nth-child(odd), - &:nth-child(even) { + &:nth-of-type(odd), + &:nth-of-type(even) { &:hover { td { background-color: ${({ theme }) => rgba(theme.palette.gray['000'], 0.04)}; @@ -66,7 +66,7 @@ const Container = styled.div` font-size: 0.75rem; line-height: 1.25; - &:first-child { + &:first-of-type { padding-left: 1.125rem; box-sizing: border-box; flex: 45 0 auto; From 383d40cd1a76501e7b1c8f4244885f9a9c9ff27f Mon Sep 17 00:00:00 2001 From: G Iacono Date: Wed, 13 Jul 2022 00:06:33 -0400 Subject: [PATCH 28/69] =?UTF-8?q?=F0=9F=92=84=20Update=20th-child=20to=20t?= =?UTF-8?q?h-of-type=20due=20to=20SSR=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlaceOrder/Original/order-options/order-options.css.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Wallet/PlaceOrder/Original/order-options/order-options.css.js b/components/Wallet/PlaceOrder/Original/order-options/order-options.css.js index 95e4212a4..6d4a8965d 100644 --- a/components/Wallet/PlaceOrder/Original/order-options/order-options.css.js +++ b/components/Wallet/PlaceOrder/Original/order-options/order-options.css.js @@ -98,7 +98,7 @@ export const OptionsButton = styled(Button)` background-color: ${({ theme }) => lighten(0.05, theme.colors.gray['700'])}; } - &:nth-child(2) { + &:nth-of-type(2) { border-top-left-radius: 3px; border-bottom-left-radius: 3px; } From fec2b82b265a5c9ed9066228d24b2358661c016d Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 15 Jul 2022 00:32:41 -0400 Subject: [PATCH 29/69] =?UTF-8?q?=F0=9F=92=84=20Remove=20confusing=20Limit?= =?UTF-8?q?Order=20element?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/order-form.jsx | 5 ++--- .../Wallet/PlaceOrder/Original/place-order.css.js | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index a41150212..aa152f630 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -2,7 +2,6 @@ import { BodyCopy, BodyCopyTiny } from '@/components/Typography' import AmountRange from './amount-range' import Big from 'big.js' -import { LimitOrder } from './place-order.css' import OrderInput from './order-input' import OrderOptions from './order-options' import PropTypes from 'prop-types' @@ -68,7 +67,7 @@ export const OrderForm = ({ return ( <> - +
)} - +
) } diff --git a/components/Wallet/PlaceOrder/Original/place-order.css.js b/components/Wallet/PlaceOrder/Original/place-order.css.js index 88249a540..3a130b54f 100644 --- a/components/Wallet/PlaceOrder/Original/place-order.css.js +++ b/components/Wallet/PlaceOrder/Original/place-order.css.js @@ -179,11 +179,11 @@ export const Tabs = styled(_Tabs)` justify-content: flex-start; ` -export const LimitOrder = styled.div` - display: flex; - flex-direction: column; - margin-bottom: 1rem; -` +// export const LimitOrder = styled.div` +// display: flex; +// flex-direction: column; +// margin-bottom: 1rem; +// ` // export const TxnFeeContainer = styled.div` // margin-bottom: 0.75rem; From 6fdaed93a12f79a9bbecd0344c129d46152b2985 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 15 Jul 2022 02:13:55 -0400 Subject: [PATCH 30/69] =?UTF-8?q?=F0=9F=92=84=20Remove=20confusing=20Limit?= =?UTF-8?q?Order=20element,=20updating=20LimitOrder=20Section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Form.jsx | 14 +- .../Wallet/PlaceOrder/Original/order-form.jsx | 231 ++++++++++++------ .../PlaceOrder/Original/order-input/index.jsx | 2 +- 3 files changed, 164 insertions(+), 83 deletions(-) diff --git a/components/Wallet/PlaceOrder/Form.jsx b/components/Wallet/PlaceOrder/Form.jsx index 83bc83c09..0ce1cdaf6 100644 --- a/components/Wallet/PlaceOrder/Form.jsx +++ b/components/Wallet/PlaceOrder/Form.jsx @@ -195,11 +195,11 @@ const Tabs = styled(_Tabs)` } ` -const LimitOrder = styled.div` - display: flex; - flex-direction: column; - margin-bottom: 1rem; -` +// const LimitOrder = styled.div` +// display: flex; +// flex-direction: column; +// margin-bottom: 1rem; +// ` const SubmitButton = styled(Button)` &:focus { @@ -384,7 +384,7 @@ export function PlaceOrderForm({ showTitle = true, asset, wallet, onSubmit }) { )} {hasBalance && ( - +
- +
)} -
- - + {!asset.isStable && ( +
+ + - { - handleChange(e) - }} - autocomplete="false" - min="0" - step={new Big(10).pow(-1 * asset.decimals).toString()} - inputMode="decimal" - /> - - - - {/* - - Algorand transaction fees: {' '} - {txnFee.toFixed(3)} - - */} - {orderType === 'limit' && ( - { + handleChange(e) + }} + autocomplete="false" + min="0" + step={new Big(10).pow(-1 * asset.decimals).toString()} + inputMode="decimal" + /> + + + + {/* + + Algorand transaction fees: {' '} + {txnFee.toFixed(3)} + + */} + {orderType === 'limit' && ( + {} : handleOptionsChange} + allowTaker={typeof asset !== 'undefined'} + orderFilter={newOrderSizeFilter} + setOrderFilter={setNewOrderSizeFilter} + /> + )} +
+ )} + {asset.isStable && ( +
+ + + + { + handleChange(e) + }} + autocomplete="false" + min="0" + step={new Big(10).pow(-1 * asset.decimals).toString()} + inputMode="decimal" + /> + {} : handleOptionsChange} - allowTaker={typeof asset !== 'undefined'} - orderFilter={newOrderSizeFilter} - setOrderFilter={setNewOrderSizeFilter} + algoBalance={maxSpendableAlgo} + asaBalance={asaBalance} + asset={asset} + // txnFee={txnFee} + onChange={handleRangeChange} + /> + - )} -
+ + {/* + + Algorand transaction fees: {' '} + {txnFee.toFixed(3)} + + */} + {orderType === 'limit' && ( + {} : handleOptionsChange} + allowTaker={typeof asset !== 'undefined'} + orderFilter={newOrderSizeFilter} + setOrderFilter={setNewOrderSizeFilter} + /> + )} +
+ )} ) } diff --git a/components/Wallet/PlaceOrder/Original/order-input/index.jsx b/components/Wallet/PlaceOrder/Original/order-input/index.jsx index f407de27d..507c19a69 100644 --- a/components/Wallet/PlaceOrder/Original/order-input/index.jsx +++ b/components/Wallet/PlaceOrder/Original/order-input/index.jsx @@ -38,7 +38,7 @@ function OrderInput({ label, asset, orderType, usdEquivalent, hasError, errorMes - {asset} + {/* {asset} */} {asset} {hasError && } From 6cfca4e874f642fddd76ff42d5b0aa34574e0550 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 15 Jul 2022 05:27:51 -0400 Subject: [PATCH 31/69] =?UTF-8?q?=F0=9F=92=84=20Update=20Spread=20price?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useAlgodex.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index fc735998e..aaa37ad26 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -201,10 +201,6 @@ function getBidAskSpread(orderBook, isStableAsset) { const bidPrice = buyOrders.sort((a, b) => b.asaPrice - a.asaPrice)?.[0]?.formattedPrice || 0 const askPrice = sellOrders.sort((a, b) => a.asaPrice - b.asaPrice)?.[0]?.formattedPrice || 0 - // const bid = floatToFixed(bidPrice) - // const ask = floatToFixed(askPrice) - // const spread = floatToFixed(new Big(ask).minus(bid).abs()) - let bid = floatToFixed(bidPrice) let ask = floatToFixed(askPrice) let spread = floatToFixed(new Big(ask).minus(bid).abs()) @@ -212,12 +208,11 @@ function getBidAskSpread(orderBook, isStableAsset) { if (isStableAsset) { bid = bidPrice === 0 ? 'Invalid Price' : floatToFixed(1 / bidPrice) ask = askPrice === 0 ? 'Invalid Price' : floatToFixed(1 / askPrice) - if (bidPrice === 0 || bidPrice === 0 || bidPrice === askPrice) { + + if (Number(bidPrice) === 0 || Number(bidPrice) === 0) { spread = 'Invalid Price' } else { - console.log('ask: ', ask, 'bid: ', bid) - console.log('askPrice: ', askPrice, 'bidPrice: ', bidPrice) - spread = floatToFixed(1 / new Big(ask).minus(bid).abs()) + spread = floatToFixed(new Big(ask).minus(bid).abs()) } } From 8990963f9a23b77576694040cf7c811f33c77a3c Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 15 Jul 2022 09:35:38 -0400 Subject: [PATCH 32/69] =?UTF-8?q?=F0=9F=92=84=20Update=20OrderBookPrice=20?= =?UTF-8?q?Info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBookPriceInfo.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/Asset/OrderBook/OrderBookPriceInfo.js b/components/Asset/OrderBook/OrderBookPriceInfo.js index b392bc30f..d17298cf6 100644 --- a/components/Asset/OrderBook/OrderBookPriceInfo.js +++ b/components/Asset/OrderBook/OrderBookPriceInfo.js @@ -9,7 +9,13 @@ import { mdiApproximatelyEqual } from '@mdi/js' import { withAlgorandPriceQuery } from 'hooks/withAlgoExplorer' export function OrderBookPriceInfo({ algoPrice, asset }) { - const asaValue = floatToFixed(convertFromAsaUnits(asset?.price_info?.price, asset.decimals)) + const asaUnit = convertFromAsaUnits(asset?.price_info?.price, asset.decimals) + let asaValue = !asset.isStable + ? floatToFixed(asaUnit) + : asaUnit === 0 + ? 'Invalid Number' + : floatToFixed(1 / asaUnit) + return ( <> {asaValue} From 1629bd7d2eed24e111285c8a9f8a3b2f4e6ca268 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 15 Jul 2022 09:40:05 -0400 Subject: [PATCH 33/69] =?UTF-8?q?=F0=9F=92=84=20Change=20Sell=20and=20Buyo?= =?UTF-8?q?rders=20in=20Orderbook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index ff16eb446..8d36b35e7 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -462,7 +462,9 @@ export function OrderBook({ isMobile, asset, orders, components }) { - {renderOrders(aggregatedSellOrder, 'sell')} + + {renderOrders(asset.isStable ? aggregatedBuyOrder : aggregatedSellOrder, 'sell')} + @@ -471,7 +473,7 @@ export function OrderBook({ isMobile, asset, orders, components }) { - {renderOrders(aggregatedBuyOrder, 'buy')} + {renderOrders(asset.isStable ? aggregatedSellOrder : aggregatedBuyOrder, 'buy')} From 7bb4055ff5a0b9c49318056ae79652d7458e1644 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 15 Jul 2022 15:04:17 -0400 Subject: [PATCH 34/69] =?UTF-8?q?=F0=9F=9A=A7=20fetchCurrentAssetPrices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 +++- hooks/useAlgodex.js | 7 ++++++- services/algodex.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.env.development b/.env.development index 12995a4a7..a76ae750f 100644 --- a/.env.development +++ b/.env.development @@ -8,4 +8,6 @@ NEXT_PUBLIC_PORTAL_ID=20146426 NEXT_PUBLIC_SUBSCRIBER_FORM_ID=f4023600-6995-433b-894a-2a1ab09dc2f6 NEXT_PUBLIC_SUPPORT_FORM_ID=282959ce-3633-4a73-907a-ef84cebe1123 -NEXT_PUBLIC_HUBSPOT_APIKEY=3382e6ff-1c9c-43f1-a622-52f60c30cce3 \ No newline at end of file +NEXT_PUBLIC_HUBSPOT_APIKEY=3382e6ff-1c9c-43f1-a622-52f60c30cce3 + +ANALYTICS_TINYMAN_V1_API=https://testnet.analytics.tinyman.org/api/v1 \ No newline at end of file diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index aaa37ad26..9204dd1c0 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -7,7 +7,8 @@ import { fetchWalletAssets, fetchWalletOrders, fetchWalletTradeHistory, - searchAssets + searchAssets, + fetchCurrentAssetPrices } from '@/services/algodex' import { getAssetTotalStatus, @@ -663,3 +664,7 @@ export function useWalletsQuery({ }) { return useQuery('wallets', () => WalletService.fetchWallets(wallets), options) } + +export function useCurrentAssetPricesQuery({ options = {} }) { + return useQuery(['currentAssetPrices'], () => fetchCurrentAssetPrices(), options) +} diff --git a/services/algodex.js b/services/algodex.js index 3915fbddf..3a12ee288 100644 --- a/services/algodex.js +++ b/services/algodex.js @@ -361,3 +361,15 @@ export const createTicket = async (payload) => { }) return response } + +/** + * Fetch Current Asset Prices + * @returns {Promise<*>} + */ +export async function fetchCurrentAssetPrices() { + console.debug(`fetchCurrentAssetPrices()`) + const { + data: { data } + } = await getEtagResponse(`${process.env.ANALYTICS_TINYMAN_V1_API}/current-asset-prices`) + return typeof data !== 'undefined' ? data[0] : {} +} From 833167bb477b4063b82c9f94bcd18db757668b56 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 18 Jul 2022 00:42:45 -0400 Subject: [PATCH 35/69] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/order-form.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index 4dcd230d3..76f536737 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -99,7 +99,7 @@ export const OrderForm = ({ hasError={isErrorMsgVisible()} errorMessage={`Price cannot be less than ${microAlgo}`} /> - + Date: Mon, 18 Jul 2022 05:19:50 -0400 Subject: [PATCH 36/69] =?UTF-8?q?=F0=9F=9A=A7=20implement=20current=20asse?= =?UTF-8?q?t=20price?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wallet/PriceConversion/USDPrice.jsx | 4 +++ hooks/useAlgoExplorer.js | 29 +++++++++++++++++-- hooks/useAlgodex.js | 7 +---- hooks/withAlgodex.js | 11 ++++++- services/algodex.js | 12 -------- services/algoexplorer.js | 15 ++++++++++ 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/components/Wallet/PriceConversion/USDPrice.jsx b/components/Wallet/PriceConversion/USDPrice.jsx index 23572c4f9..138538352 100644 --- a/components/Wallet/PriceConversion/USDPrice.jsx +++ b/components/Wallet/PriceConversion/USDPrice.jsx @@ -1,7 +1,11 @@ import PropTypes from 'prop-types' import { formatUSDPrice } from '@/components/helpers' import { withAlgorandPriceQuery } from '@/hooks/withAlgoExplorer' +import { useCurrentAssetPricesQuery } from '@/hooks/useAlgoExplorer' + export function USDPrice({ asaWorth, algoPrice, priceToConvert, currency }) { + const currentPrices = useCurrentAssetPricesQuery({}) + console.log('CurrentPrices: ', currentPrices) return ( {currency} diff --git a/hooks/useAlgoExplorer.js b/hooks/useAlgoExplorer.js index 7b04ce923..f64c50562 100644 --- a/hooks/useAlgoExplorer.js +++ b/hooks/useAlgoExplorer.js @@ -1,7 +1,11 @@ -import { fetchAlgorandPrice, fetchExplorerAssetInfo } from 'services/algoexplorer' +import { + fetchAlgorandPrice, + fetchExplorerAssetInfo, + fetchCurrentAssetPrices +} from 'services/algoexplorer' import { routeQueryError } from './useAlgodex' -import { useEffect } from 'react' +import { useEffect, useMemo } from 'react' import { useQuery } from 'react-query' import { useRouter } from 'next/router' @@ -49,3 +53,24 @@ export const useAlgorandPriceQuery = ({ refetchInterval: query === '' ? refetchInterval : 20000 } } = {}) => useQuery(['fetchAlgorandPrice', { query }], () => fetchAlgorandPrice(query), options) + +/** + * Use Search Results Query + * @param {Object} props The props of the parent + * @param {Object} [props.options] useQuery Options + * @returns {UseQueryResult<{assets: *}, unknown>} + */ +export function useCurrentAssetPricesQuery({ options = { refetchInterval: 30000 } }) { + // return useQuery(['currentAssetPrices'], () => fetchCurrentAssetPrices(), options) + const { data: _prices } = useQuery( + ['currentAssetPrices'], + () => fetchCurrentAssetPrices(), + options + ) + + const currentPrices = useMemo(() => { + return _prices + }, [_prices]) + + return currentPrices +} diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 5cf6a979e..f139e8eac 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -7,8 +7,7 @@ import { fetchWalletAssets, fetchWalletOrders, fetchWalletTradeHistory, - searchAssets, - fetchCurrentAssetPrices + searchAssets } from '@/services/algodex' import { getAssetTotalStatus, @@ -681,7 +680,3 @@ export function useWalletsQuery({ }) { return useQuery('wallets', () => WalletService.fetchWallets(wallets), options) } - -export function useCurrentAssetPricesQuery({ options = {} }) { - return useQuery(['currentAssetPrices'], () => fetchCurrentAssetPrices(), options) -} diff --git a/hooks/withAlgodex.js b/hooks/withAlgodex.js index d3c649f5e..23a97a129 100644 --- a/hooks/withAlgodex.js +++ b/hooks/withAlgodex.js @@ -7,7 +7,8 @@ import { useAssetChartQuery, useWalletAssetsQuery, useWalletOrdersQuery, - useWalletTradeHistoryQuery + useWalletTradeHistoryQuery, + useCurrentAssetPricesQuery } from '@/hooks/useAlgodex' import { withQuery } from '@/hooks/withQuery' @@ -112,3 +113,11 @@ export function withWalletTradeHistoryQuery(Component, options) { ...options }) } + +// export function withCurrentAssetPricesQuery(Component, options) { +// return withQuery(Component, { +// hook: useCurrentAssetPricesQuery, +// components, +// ...options +// }) +// } diff --git a/services/algodex.js b/services/algodex.js index 3a12ee288..3915fbddf 100644 --- a/services/algodex.js +++ b/services/algodex.js @@ -361,15 +361,3 @@ export const createTicket = async (payload) => { }) return response } - -/** - * Fetch Current Asset Prices - * @returns {Promise<*>} - */ -export async function fetchCurrentAssetPrices() { - console.debug(`fetchCurrentAssetPrices()`) - const { - data: { data } - } = await getEtagResponse(`${process.env.ANALYTICS_TINYMAN_V1_API}/current-asset-prices`) - return typeof data !== 'undefined' ? data[0] : {} -} diff --git a/services/algoexplorer.js b/services/algoexplorer.js index 8852016b9..45089d96c 100644 --- a/services/algoexplorer.js +++ b/services/algoexplorer.js @@ -9,6 +9,8 @@ export const ALGO_EXPLORER_V1_API = export const ALGO_EXPLORER_V2_API = process.env.NEXT_PUBLIC_ALGO_EXPLORER_V2_API || 'https://indexer.testnet.algoexplorerapi.io' export const EXPLORER_ALGORAND_PRICE = 'https://price.algoexplorerapi.io/price/algo-usd' +export const EXPLORER_CURRENT_ASSET_PRICES = + 'https://testnet.analytics.tinyman.org/api/v1/current-asset-prices' console.debug('NEXT_PUBLIC_EXPLORER_API: ' + process.env.NEXT_PUBLIC_EXPLORER_API) console.debug('EXPLORER_API: ' + EXPLORER_API) @@ -163,3 +165,16 @@ export async function fetchAlgorandPrice() { const { data } = await axios.get(`${EXPLORER_ALGORAND_PRICE}`) return { algoPrice: data.price } } + +/** + * Fetch Current Asset Prices + * @see https://testnet.analytics.tinyman.org/api/v1/current-asset-prices + * @see https://mainnet.analytics.tinyman.org/api/v1/current-asset-prices + */ +export async function fetchCurrentAssetPrices() { + console.log('Env: ', process.env) + // console.debug(`fetchCurrentAssetPrices(): ${EXPLORER_CURRENT_ASSET_PRICES}`) + const { data } = await axios.get(`${EXPLORER_CURRENT_ASSET_PRICES}`) + console.debug(`fetchCurrentAssetPrices(): `, data) + return typeof data !== 'undefined' ? data : {} +} From 800607f31b5846b04dda6cecf1327c7b005b4568 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 18 Jul 2022 23:23:54 -0400 Subject: [PATCH 37/69] =?UTF-8?q?=F0=9F=8E=A8=20Update=20USDPrice=20with?= =?UTF-8?q?=20StableCoin=20Options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wallet/PlaceOrder/Original/order-form.jsx | 25 +++++++---- .../Wallet/PriceConversion/USDPrice.jsx | 21 ++++++---- hooks/useAlgoExplorer.js | 41 ++++++++++++++----- hooks/withAlgoExplorer.js | 20 ++++++++- hooks/withAlgodex.js | 11 +---- services/algoexplorer.js | 15 +++++-- 6 files changed, 92 insertions(+), 41 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index 76f536737..b50dd9509 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -15,14 +15,14 @@ import useTranslation from 'next-translate/useTranslation' * @param {*} { value, id } * @return {*} */ -export const USDInputPrice = ({ value, id, showFee }) => { +export const USDInputPrice = ({ value, id, showFee, stableUSDPrice, asset }) => { return ( <> {showFee && (
Fee - + USD
@@ -30,7 +30,7 @@ export const USDInputPrice = ({ value, id, showFee }) => {
USD {id === 'price' ? 'Price' : 'Total'} - + USD
@@ -39,9 +39,11 @@ export const USDInputPrice = ({ value, id, showFee }) => { } USDInputPrice.propTypes = { + stableUSDPrice: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), showFee: PropTypes.boolean, value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - id: PropTypes.string + id: PropTypes.string, + asset: PropTypes.object } export const OrderForm = ({ @@ -76,6 +78,7 @@ export const OrderForm = ({ return true } } + return ( <> {!asset.isStable && ( @@ -99,7 +102,7 @@ export const OrderForm = ({ hasError={isErrorMsgVisible()} errorMessage={`Price cannot be less than ${microAlgo}`} /> - + - + {/* Algorand transaction fees: {' '} @@ -179,7 +182,13 @@ export const OrderForm = ({ hasError={isErrorMsgVisible()} errorMessage={`Price cannot be less than ${microAlgo}`} /> - + - + {/* Algorand transaction fees: {' '} diff --git a/components/Wallet/PriceConversion/USDPrice.jsx b/components/Wallet/PriceConversion/USDPrice.jsx index 138538352..f3f0443f6 100644 --- a/components/Wallet/PriceConversion/USDPrice.jsx +++ b/components/Wallet/PriceConversion/USDPrice.jsx @@ -1,15 +1,17 @@ import PropTypes from 'prop-types' import { formatUSDPrice } from '@/components/helpers' -import { withAlgorandPriceQuery } from '@/hooks/withAlgoExplorer' -import { useCurrentAssetPricesQuery } from '@/hooks/useAlgoExplorer' +// import { withAlgorandPriceQuery } from '@/hooks/withAlgoExplorer' +import { withCurrentAssetPricesQuery } from '@/hooks/withAlgoExplorer' + +export function USDPrice({ asaWorth, algoPrice, priceToConvert, currency, usdPrice, asset }) { + const displayPrice = asset?.isStable + ? asaWorth * priceToConvert * usdPrice + : asaWorth * priceToConvert * algoPrice -export function USDPrice({ asaWorth, algoPrice, priceToConvert, currency }) { - const currentPrices = useCurrentAssetPricesQuery({}) - console.log('CurrentPrices: ', currentPrices) return ( {currency} - {formatUSDPrice(asaWorth * priceToConvert * algoPrice)} + {formatUSDPrice(displayPrice)} ) } @@ -18,7 +20,9 @@ USDPrice.propTypes = { algoPrice: PropTypes.any, priceToConvert: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, asaWorth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, - currency: PropTypes.string + currency: PropTypes.string, + usdPrice: PropTypes.any, + asset: PropTypes.any } USDPrice.defaultProps = { @@ -28,4 +32,5 @@ USDPrice.defaultProps = { currency: '' } -export default withAlgorandPriceQuery(USDPrice) +// export default withAlgorandPriceQuery(USDPrice) +export default withCurrentAssetPricesQuery(USDPrice) diff --git a/hooks/useAlgoExplorer.js b/hooks/useAlgoExplorer.js index f64c50562..17ce8926e 100644 --- a/hooks/useAlgoExplorer.js +++ b/hooks/useAlgoExplorer.js @@ -56,21 +56,42 @@ export const useAlgorandPriceQuery = ({ /** * Use Search Results Query + * Use Asset * @param {Object} props The props of the parent + * @param {string} props.query Search Query * @param {Object} [props.options] useQuery Options * @returns {UseQueryResult<{assets: *}, unknown>} */ -export function useCurrentAssetPricesQuery({ options = { refetchInterval: 30000 } }) { - // return useQuery(['currentAssetPrices'], () => fetchCurrentAssetPrices(), options) - const { data: _prices } = useQuery( - ['currentAssetPrices'], - () => fetchCurrentAssetPrices(), +export const useCurrentAssetPricesQuery = ({ + query = '', + asset = {}, + options = { + refetchInterval: query === '' ? refetchInterval : 20000 + } +} = {}) => + useQuery( + ['fetchCurrentAssetPrices', { query, asset }], + () => fetchCurrentAssetPrices(query, asset?.id ?? -1), options ) - const currentPrices = useMemo(() => { - return _prices - }, [_prices]) +/** + * Use Search Results Query + * @param {Object} props The props of the parent + * @param {Object} [props.options] useQuery Options + * @returns {UseQueryResult<{assets: *}, unknown>} + */ +// export function useCurrentAssetPricesQuery({ options = { refetchInterval: 30000 } }) { +// // return useQuery(['currentAssetPrices'], () => fetchCurrentAssetPrices(), options) +// const { data: _prices } = useQuery( +// ['currentAssetPrices'], +// () => fetchCurrentAssetPrices(), +// options +// ) + +// const currentPrices = useMemo(() => { +// return _prices +// }, [_prices]) - return currentPrices -} +// return currentPrices +// } diff --git a/hooks/withAlgoExplorer.js b/hooks/withAlgoExplorer.js index 830d0c56e..653c8f183 100644 --- a/hooks/withAlgoExplorer.js +++ b/hooks/withAlgoExplorer.js @@ -1,4 +1,8 @@ -import { useAlgorandPriceQuery, useExplorerAssetInfo } from '@/hooks/useAlgoExplorer' +import { + useAlgorandPriceQuery, + useExplorerAssetInfo, + useCurrentAssetPricesQuery +} from '@/hooks/useAlgoExplorer' import ServiceError from '@/components/ServiceError' import Spinner from '@/components/Spinner' @@ -29,3 +33,17 @@ export function withExplorerAssetInfo(Component, options) { ...options }) } + +/** + * With Algorand Price Query + * @param {JSX.Element| Function} Component Component to wrap + * @param {object} [options] Options to pass to withQuery + * @returns {JSX.Element} + */ +export function withCurrentAssetPricesQuery(Component, options) { + return withQuery(Component, { + hook: useCurrentAssetPricesQuery, + components, + ...options + }) +} diff --git a/hooks/withAlgodex.js b/hooks/withAlgodex.js index 23a97a129..d3c649f5e 100644 --- a/hooks/withAlgodex.js +++ b/hooks/withAlgodex.js @@ -7,8 +7,7 @@ import { useAssetChartQuery, useWalletAssetsQuery, useWalletOrdersQuery, - useWalletTradeHistoryQuery, - useCurrentAssetPricesQuery + useWalletTradeHistoryQuery } from '@/hooks/useAlgodex' import { withQuery } from '@/hooks/withQuery' @@ -113,11 +112,3 @@ export function withWalletTradeHistoryQuery(Component, options) { ...options }) } - -// export function withCurrentAssetPricesQuery(Component, options) { -// return withQuery(Component, { -// hook: useCurrentAssetPricesQuery, -// components, -// ...options -// }) -// } diff --git a/services/algoexplorer.js b/services/algoexplorer.js index 45089d96c..0e894a2fb 100644 --- a/services/algoexplorer.js +++ b/services/algoexplorer.js @@ -167,14 +167,21 @@ export async function fetchAlgorandPrice() { } /** - * Fetch Current Asset Prices + * Fetch Current Asset Prices and AlgorandPrice * @see https://testnet.analytics.tinyman.org/api/v1/current-asset-prices * @see https://mainnet.analytics.tinyman.org/api/v1/current-asset-prices */ -export async function fetchCurrentAssetPrices() { +export async function fetchCurrentAssetPrices(query, assetId) { console.log('Env: ', process.env) // console.debug(`fetchCurrentAssetPrices(): ${EXPLORER_CURRENT_ASSET_PRICES}`) + const algoPriceRes = await axios.get(`${EXPLORER_ALGORAND_PRICE}`) const { data } = await axios.get(`${EXPLORER_CURRENT_ASSET_PRICES}`) - console.debug(`fetchCurrentAssetPrices(): `, data) - return typeof data !== 'undefined' ? data : {} + console.debug(`algorandPrice: `, algoPriceRes.data.price) + console.debug(`fetchCurrentAssetPrices(): `, data?.[assetId]?.['price'] ?? 1) + + return { + algoPrice: algoPriceRes.data.price, + usdPrice: data?.[assetId]?.['price'] ?? 1 + } + // return typeof data !== 'undefined' ? data : {} } From 84b1fcac2503483294d281fd8d021baf44c1f425 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 19 Jul 2022 01:03:11 -0400 Subject: [PATCH 38/69] =?UTF-8?q?=F0=9F=8E=A8=20Create=20Separate=20Stable?= =?UTF-8?q?AssetUSDPrice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wallet/PlaceOrder/Original/order-form.jsx | 43 ++++++++++++++++--- .../PriceConversion/StableAssetUSDPrice.jsx | 32 ++++++++++++++ .../StableAssetUSDPrice.spec.js | 19 ++++++++ .../StableAssetUSDPrice.stories.jsx | 29 +++++++++++++ .../Wallet/PriceConversion/USDPrice.jsx | 18 +++----- hooks/useAlgoExplorer.js | 6 +-- 6 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 components/Wallet/PriceConversion/StableAssetUSDPrice.jsx create mode 100644 components/Wallet/PriceConversion/StableAssetUSDPrice.spec.js create mode 100644 components/Wallet/PriceConversion/StableAssetUSDPrice.stories.jsx diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index b50dd9509..1985d1032 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -7,6 +7,7 @@ import OrderOptions from './order-options' import PropTypes from 'prop-types' import React from 'react' import USDPrice from '@/components/Wallet/PriceConversion/USDPrice' +import StableAssetUSDPrice from '@/components/Wallet/PriceConversion/StableAssetUSDPrice' import useTranslation from 'next-translate/useTranslation' /** @@ -15,14 +16,14 @@ import useTranslation from 'next-translate/useTranslation' * @param {*} { value, id } * @return {*} */ -export const USDInputPrice = ({ value, id, showFee, stableUSDPrice, asset }) => { +export const USDInputPrice = ({ value, id, showFee }) => { return ( <> {showFee && (
Fee - + USD
@@ -30,7 +31,7 @@ export const USDInputPrice = ({ value, id, showFee, stableUSDPrice, asset }) =>
USD {id === 'price' ? 'Price' : 'Total'} - + USD
@@ -39,6 +40,37 @@ export const USDInputPrice = ({ value, id, showFee, stableUSDPrice, asset }) => } USDInputPrice.propTypes = { + showFee: PropTypes.boolean, + value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + id: PropTypes.string, + asset: PropTypes.object +} + +/** + * + * Render USD Price for an input component + * @param {*} { value, id } + * @return {*} + */ +export const StableAssetUSDInputPrice = ({ value, id, stableUSDPrice, asset }) => { + return ( + <> +
+ USD {id === 'price' ? 'Price' : 'Total'} + + + USD + +
+ + ) +} + +StableAssetUSDInputPrice.propTypes = { stableUSDPrice: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), showFee: PropTypes.boolean, value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), @@ -182,10 +214,9 @@ export const OrderForm = ({ hasError={isErrorMsgVisible()} errorMessage={`Price cannot be less than ${microAlgo}`} /> - @@ -228,7 +259,7 @@ export const OrderForm = ({ readOnly disabled /> - + {/* Algorand transaction fees: {' '} diff --git a/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx b/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx new file mode 100644 index 000000000..81c5d8f9a --- /dev/null +++ b/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx @@ -0,0 +1,32 @@ +import PropTypes from 'prop-types' +import { formatUSDPrice } from '@/components/helpers' +// import { withAlgorandPriceQuery } from '@/hooks/withAlgoExplorer' +import { withCurrentAssetPricesQuery } from '@/hooks/withAlgoExplorer' + +export function StableAssetUSDPrice({ asaWorth, priceToConvert, currency, usdPrice, assetId }) { + console.log(assetId) + return ( + + {currency} + {formatUSDPrice(asaWorth * priceToConvert * usdPrice)} + + ) +} + +StableAssetUSDPrice.propTypes = { + priceToConvert: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, + asaWorth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, + currency: PropTypes.string, + usdPrice: PropTypes.any, + assetId: PropTypes.number +} + +StableAssetUSDPrice.defaultProps = { + priceToConvert: 0, + algoPrice: 0, + asaWorth: 1, + currency: '' +} + +// export default withAlgorandPriceQuery(USDPrice) +export default withCurrentAssetPricesQuery(StableAssetUSDPrice) diff --git a/components/Wallet/PriceConversion/StableAssetUSDPrice.spec.js b/components/Wallet/PriceConversion/StableAssetUSDPrice.spec.js new file mode 100644 index 000000000..64cfcb8fc --- /dev/null +++ b/components/Wallet/PriceConversion/StableAssetUSDPrice.spec.js @@ -0,0 +1,19 @@ +import React from 'react' +import { render } from 'test/test-utils' +import { StableAssetUSDPrice } from './USDPrice' + +const algoPrice = 2.3423 + +describe('StableAssetUSDPrice', () => { + it('should show price once it gets data', () => { + const { queryByTestId } = render( + + ) + + expect(queryByTestId('StableAssetUSDprice-element')).not.toBeNull() + }) +}) diff --git a/components/Wallet/PriceConversion/StableAssetUSDPrice.stories.jsx b/components/Wallet/PriceConversion/StableAssetUSDPrice.stories.jsx new file mode 100644 index 000000000..b4f404852 --- /dev/null +++ b/components/Wallet/PriceConversion/StableAssetUSDPrice.stories.jsx @@ -0,0 +1,29 @@ +import React from 'react' +import { StableAssetUSDPrice as Component } from './StableAssetUSDPrice' + +export default { + title: '@algodex/recipes/Wallet/Stable Asset Price Conversion', + component: Component, + parameters: { layout: 'fullscreen' }, + args: { + isRegenerate: false, + algoPrice: 260, + priceToConvert: 3000, + currency: '$' + } +} + +/* eslint-disable */ +export const StableAssetUSDPrice = ({ isRegenerate, algoPrice, priceToConvert, currency, ...props }) => { + if (isRegenerate) { + algoPrice = 0 + } + return ( + + ) +} diff --git a/components/Wallet/PriceConversion/USDPrice.jsx b/components/Wallet/PriceConversion/USDPrice.jsx index f3f0443f6..f3571ac2f 100644 --- a/components/Wallet/PriceConversion/USDPrice.jsx +++ b/components/Wallet/PriceConversion/USDPrice.jsx @@ -1,17 +1,12 @@ import PropTypes from 'prop-types' import { formatUSDPrice } from '@/components/helpers' -// import { withAlgorandPriceQuery } from '@/hooks/withAlgoExplorer' -import { withCurrentAssetPricesQuery } from '@/hooks/withAlgoExplorer' - -export function USDPrice({ asaWorth, algoPrice, priceToConvert, currency, usdPrice, asset }) { - const displayPrice = asset?.isStable - ? asaWorth * priceToConvert * usdPrice - : asaWorth * priceToConvert * algoPrice +import { withAlgorandPriceQuery } from '@/hooks/withAlgoExplorer' +export function USDPrice({ asaWorth, algoPrice, priceToConvert, currency }) { return ( {currency} - {formatUSDPrice(displayPrice)} + {formatUSDPrice(asaWorth * priceToConvert * algoPrice)} ) } @@ -20,9 +15,7 @@ USDPrice.propTypes = { algoPrice: PropTypes.any, priceToConvert: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, asaWorth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, - currency: PropTypes.string, - usdPrice: PropTypes.any, - asset: PropTypes.any + currency: PropTypes.string } USDPrice.defaultProps = { @@ -32,5 +25,4 @@ USDPrice.defaultProps = { currency: '' } -// export default withAlgorandPriceQuery(USDPrice) -export default withCurrentAssetPricesQuery(USDPrice) +export default withAlgorandPriceQuery(USDPrice) diff --git a/hooks/useAlgoExplorer.js b/hooks/useAlgoExplorer.js index 17ce8926e..d567b1716 100644 --- a/hooks/useAlgoExplorer.js +++ b/hooks/useAlgoExplorer.js @@ -64,14 +64,14 @@ export const useAlgorandPriceQuery = ({ */ export const useCurrentAssetPricesQuery = ({ query = '', - asset = {}, + assetId = -1, options = { refetchInterval: query === '' ? refetchInterval : 20000 } } = {}) => useQuery( - ['fetchCurrentAssetPrices', { query, asset }], - () => fetchCurrentAssetPrices(query, asset?.id ?? -1), + ['fetchCurrentAssetPrices', { query, assetId }], + () => fetchCurrentAssetPrices(query, assetId), options ) From f01a417d67823aa30a8e63a1ee7d1da59372ec3e Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 19 Jul 2022 03:20:28 -0400 Subject: [PATCH 39/69] =?UTF-8?q?=F0=9F=8E=A8=20Create=20new=20Hook/Servic?= =?UTF-8?q?e=20for=20Separate=20StableAssetUSDPrice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wallet/PlaceOrder/Original/order-form.jsx | 21 +++++-------------- .../PriceConversion/StableAssetUSDPrice.jsx | 12 ++++------- hooks/useAlgoExplorer.js | 7 +++---- services/algoexplorer.js | 7 ++----- 4 files changed, 14 insertions(+), 33 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index 1985d1032..a537b2f54 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -52,17 +52,13 @@ USDInputPrice.propTypes = { * @param {*} { value, id } * @return {*} */ -export const StableAssetUSDInputPrice = ({ value, id, stableUSDPrice, asset }) => { +export const StableAssetUSDInputPrice = ({ value, id, assetId }) => { return ( <>
USD {id === 'price' ? 'Price' : 'Total'} - + USD
@@ -71,11 +67,9 @@ export const StableAssetUSDInputPrice = ({ value, id, stableUSDPrice, asset }) = } StableAssetUSDInputPrice.propTypes = { - stableUSDPrice: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - showFee: PropTypes.boolean, value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), id: PropTypes.string, - asset: PropTypes.object + assetId: PropTypes.number } export const OrderForm = ({ @@ -214,12 +208,7 @@ export const OrderForm = ({ hasError={isErrorMsgVisible()} errorMessage={`Price cannot be less than ${microAlgo}`} /> - + - + {/* Algorand transaction fees: {' '} diff --git a/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx b/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx index 81c5d8f9a..54a7af81b 100644 --- a/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx +++ b/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx @@ -1,10 +1,8 @@ import PropTypes from 'prop-types' import { formatUSDPrice } from '@/components/helpers' -// import { withAlgorandPriceQuery } from '@/hooks/withAlgoExplorer' import { withCurrentAssetPricesQuery } from '@/hooks/withAlgoExplorer' -export function StableAssetUSDPrice({ asaWorth, priceToConvert, currency, usdPrice, assetId }) { - console.log(assetId) +export function StableAssetUSDPrice({ asaWorth, priceToConvert, currency, usdPrice }) { return ( {currency} @@ -17,16 +15,14 @@ StableAssetUSDPrice.propTypes = { priceToConvert: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, asaWorth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, currency: PropTypes.string, - usdPrice: PropTypes.any, - assetId: PropTypes.number + usdPrice: PropTypes.any } StableAssetUSDPrice.defaultProps = { priceToConvert: 0, - algoPrice: 0, asaWorth: 1, - currency: '' + currency: '', + usdPrice: 1 } -// export default withAlgorandPriceQuery(USDPrice) export default withCurrentAssetPricesQuery(StableAssetUSDPrice) diff --git a/hooks/useAlgoExplorer.js b/hooks/useAlgoExplorer.js index d567b1716..b4246473c 100644 --- a/hooks/useAlgoExplorer.js +++ b/hooks/useAlgoExplorer.js @@ -63,15 +63,14 @@ export const useAlgorandPriceQuery = ({ * @returns {UseQueryResult<{assets: *}, unknown>} */ export const useCurrentAssetPricesQuery = ({ - query = '', assetId = -1, options = { - refetchInterval: query === '' ? refetchInterval : 20000 + refetchInterval: 20000 } } = {}) => useQuery( - ['fetchCurrentAssetPrices', { query, assetId }], - () => fetchCurrentAssetPrices(query, assetId), + ['fetchCurrentAssetPrices', { assetId }], + () => fetchCurrentAssetPrices(assetId), options ) diff --git a/services/algoexplorer.js b/services/algoexplorer.js index 0e894a2fb..04d258465 100644 --- a/services/algoexplorer.js +++ b/services/algoexplorer.js @@ -171,17 +171,14 @@ export async function fetchAlgorandPrice() { * @see https://testnet.analytics.tinyman.org/api/v1/current-asset-prices * @see https://mainnet.analytics.tinyman.org/api/v1/current-asset-prices */ -export async function fetchCurrentAssetPrices(query, assetId) { +export async function fetchCurrentAssetPrices(assetId) { console.log('Env: ', process.env) + console.log('AssetId: ', assetId) // console.debug(`fetchCurrentAssetPrices(): ${EXPLORER_CURRENT_ASSET_PRICES}`) - const algoPriceRes = await axios.get(`${EXPLORER_ALGORAND_PRICE}`) const { data } = await axios.get(`${EXPLORER_CURRENT_ASSET_PRICES}`) - console.debug(`algorandPrice: `, algoPriceRes.data.price) console.debug(`fetchCurrentAssetPrices(): `, data?.[assetId]?.['price'] ?? 1) return { - algoPrice: algoPriceRes.data.price, usdPrice: data?.[assetId]?.['price'] ?? 1 } - // return typeof data !== 'undefined' ? data : {} } From 608561a084328634305ad1fbbc90bd4695592069 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 19 Jul 2022 04:06:36 -0400 Subject: [PATCH 40/69] =?UTF-8?q?=F0=9F=8E=A8=20Update=20the=20StableAsset?= =?UTF-8?q?USDPrice=20spec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.test | 2 ++ components/Wallet/PriceConversion/StableAssetUSDPrice.jsx | 2 +- .../Wallet/PriceConversion/StableAssetUSDPrice.spec.js | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.env.test b/.env.test index 9ccd51f64..eedb77c77 100644 --- a/.env.test +++ b/.env.test @@ -2,3 +2,5 @@ NEXT_PUBLIC_ENV=development NEXT_PUBLIC_API=https://api-testnet-public.algodex.com NEXT_PUBLIC_DEBUG=true DISABLE_SENTRY=true + +ANALYTICS_TINYMAN_V1_API=https://testnet.analytics.tinyman.org/api/v1 \ No newline at end of file diff --git a/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx b/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx index 54a7af81b..118fc873e 100644 --- a/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx +++ b/components/Wallet/PriceConversion/StableAssetUSDPrice.jsx @@ -4,7 +4,7 @@ import { withCurrentAssetPricesQuery } from '@/hooks/withAlgoExplorer' export function StableAssetUSDPrice({ asaWorth, priceToConvert, currency, usdPrice }) { return ( - + {currency} {formatUSDPrice(asaWorth * priceToConvert * usdPrice)} diff --git a/components/Wallet/PriceConversion/StableAssetUSDPrice.spec.js b/components/Wallet/PriceConversion/StableAssetUSDPrice.spec.js index 64cfcb8fc..ca48f8a1b 100644 --- a/components/Wallet/PriceConversion/StableAssetUSDPrice.spec.js +++ b/components/Wallet/PriceConversion/StableAssetUSDPrice.spec.js @@ -1,15 +1,15 @@ import React from 'react' import { render } from 'test/test-utils' -import { StableAssetUSDPrice } from './USDPrice' +import { StableAssetUSDPrice } from './StableAssetUSDPrice' -const algoPrice = 2.3423 +const usdPrice = 1 describe('StableAssetUSDPrice', () => { it('should show price once it gets data', () => { const { queryByTestId } = render( ) From ed505d392dcc601de034353f172e719cedfb7a2b Mon Sep 17 00:00:00 2001 From: G Iacono Date: Tue, 19 Jul 2022 10:04:06 -0400 Subject: [PATCH 41/69] =?UTF-8?q?=F0=9F=8E=A8=20Update=20the=20StableAsset?= =?UTF-8?q?USDPrice=20under=20amount=20element?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/order-form.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index a537b2f54..ac5e73766 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -48,7 +48,7 @@ USDInputPrice.propTypes = { /** * - * Render USD Price for an input component + * Render Stable Asset USD Price for an input component * @param {*} { value, id } * @return {*} */ @@ -240,7 +240,7 @@ export const OrderForm = ({ type="number" id="total" label={t('total')} - asset="ALGO" + asset={asset.name} decimals={6} orderType={order.type} value={order.total} From e8a811b11731cf2aeb8be61938981dbde07a3d3f Mon Sep 17 00:00:00 2001 From: G Iacono Date: Wed, 20 Jul 2022 05:29:35 -0400 Subject: [PATCH 42/69] =?UTF-8?q?=F0=9F=8E=A8=20Update=20the=20StableAsset?= =?UTF-8?q?USDPrice=20under=20amount=20element?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wallet/PlaceOrder/Original/view.jsx | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/view.jsx b/components/Wallet/PlaceOrder/Original/view.jsx index 2ec7c96f3..3fd653087 100644 --- a/components/Wallet/PlaceOrder/Original/view.jsx +++ b/components/Wallet/PlaceOrder/Original/view.jsx @@ -204,6 +204,22 @@ function PlaceOrderView(props) { target: { value: orderView === LIMIT_PANEL ? order.execution : 'market' } }) console.log('order submitted') + console.log('Order: ') + console.log(order) + + // amount: "0.999998" + // decimals: 6 + // execution: "both" + // price: "1.000000" + // total: "0.999998" + // type: "buy" + + // amount: "0.08973" + // decimals: 6 + // execution: "both" + // price: "1" + // total: "0.08973" + // type: "sell" e.preventDefault() setStatus((prev) => ({ ...prev, submitting: true })) @@ -219,6 +235,7 @@ function PlaceOrderView(props) { toast.error(t('fund-wallet')) return } + const orderData = { ...order, execution: orderView === LIMIT_PANEL ? order.execution : 'market', @@ -297,9 +314,16 @@ function PlaceOrderView(props) { } const isBelowMinOrderAmount = () => { - if (order.type === 'buy') { + let _type = order.type + if (asset.isStable) { + // if asset is stable invert sell/buy option + _type = order.type === 'buy' ? 'sell' : 'buy' + } + if (_type === 'buy') { + console.log('BuyCondition: isBelowMinOrderAmount: ', order.total) return new Big(order.total).lt(0.5) } + console.log('BuyCondition: isBelowMinOrderAmount: ', order.total) return new Big(order.total).eq(0) } @@ -308,7 +332,14 @@ function PlaceOrderView(props) { } const isBalanceExceeded = () => { - if (order.type === 'buy') { + let _type = order.type + if (asset.isStable) { + // if asset is stable invert sell/buy option + _type = order.type === 'buy' ? 'sell' : 'buy' + } + if (_type === 'buy') { + console.log('BuyCondition: order.price : ', order.price) + console.log('BuyCondition: order.amount : ', order.amount) return new Big(order.price).times(order.amount).gt(maxSpendableAlgo) } return new Big(order.amount).gt(asaBalance) @@ -326,6 +357,14 @@ function PlaceOrderView(props) { asset.isGeoBlocked || status.submitting + console.log('BuyCondition: isBelowMinOrderAmount: ', isBelowMinOrderAmount()) + console.log('BuyCondition: isInvalid: ', isInvalid()) + // console.log('BuyCondition: isBalanceExceeded: ', isBalanceExceeded()) + console.log('BuyCondition: isLessThanMicroAlgo: ', isLessThanMicroAlgo()) + console.log('BuyCondition: asset.isGeoBlocked: ', asset.isGeoBlocked) + console.log('BuyCondition: status.submitting: ', status.submitting) + + console.log('isDisabled: ', isDisabled) return ( Date: Wed, 20 Jul 2022 08:38:12 -0400 Subject: [PATCH 43/69] =?UTF-8?q?=F0=9F=91=94=20Update=20StableCoin=20Orde?= =?UTF-8?q?r=20Code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/view.jsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/view.jsx b/components/Wallet/PlaceOrder/Original/view.jsx index 3fd653087..ad0f335fe 100644 --- a/components/Wallet/PlaceOrder/Original/view.jsx +++ b/components/Wallet/PlaceOrder/Original/view.jsx @@ -240,7 +240,8 @@ function PlaceOrderView(props) { ...order, execution: orderView === LIMIT_PANEL ? order.execution : 'market', address: activeWalletAddress, - asset + asset, + type: asset.isStable ? (order.type === 'buy' ? 'sell' : 'buy') : order.type } Sentry.addBreadcrumb({ @@ -314,11 +315,8 @@ function PlaceOrderView(props) { } const isBelowMinOrderAmount = () => { - let _type = order.type - if (asset.isStable) { - // if asset is stable invert sell/buy option - _type = order.type === 'buy' ? 'sell' : 'buy' - } + // if asset is stable invert sell/buy option + let _type = asset.isStable ? (order.type === 'buy' ? 'sell' : 'buy') : order.type if (_type === 'buy') { console.log('BuyCondition: isBelowMinOrderAmount: ', order.total) return new Big(order.total).lt(0.5) @@ -332,11 +330,7 @@ function PlaceOrderView(props) { } const isBalanceExceeded = () => { - let _type = order.type - if (asset.isStable) { - // if asset is stable invert sell/buy option - _type = order.type === 'buy' ? 'sell' : 'buy' - } + let _type = asset.isStable ? (order.type === 'buy' ? 'sell' : 'buy') : order.type if (_type === 'buy') { console.log('BuyCondition: order.price : ', order.price) console.log('BuyCondition: order.amount : ', order.amount) From 42d03b4efd63c63df44dfee73ed5c01d4446eae0 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 21 Jul 2022 05:20:28 -0400 Subject: [PATCH 44/69] =?UTF-8?q?=F0=9F=91=94=20Swap=20sell/buy=20info=20f?= =?UTF-8?q?or=20StableAsset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wallet/PlaceOrder/Original/view.jsx | 70 +++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/view.jsx b/components/Wallet/PlaceOrder/Original/view.jsx index ad0f335fe..019a7f197 100644 --- a/components/Wallet/PlaceOrder/Original/view.jsx +++ b/components/Wallet/PlaceOrder/Original/view.jsx @@ -203,23 +203,6 @@ function PlaceOrderView(props) { handleOptionsChange({ target: { value: orderView === LIMIT_PANEL ? order.execution : 'market' } }) - console.log('order submitted') - console.log('Order: ') - console.log(order) - - // amount: "0.999998" - // decimals: 6 - // execution: "both" - // price: "1.000000" - // total: "0.999998" - // type: "buy" - - // amount: "0.08973" - // decimals: 6 - // execution: "both" - // price: "1" - // total: "0.08973" - // type: "sell" e.preventDefault() setStatus((prev) => ({ ...prev, submitting: true })) @@ -240,10 +223,53 @@ function PlaceOrderView(props) { ...order, execution: orderView === LIMIT_PANEL ? order.execution : 'market', address: activeWalletAddress, - asset, - type: asset.isStable ? (order.type === 'buy' ? 'sell' : 'buy') : order.type + asset } + console.log('Order Submitted: ', order) + + // Adjust OrderData if it is stablecoin + if (asset.isStable) { + orderData.amount = order.price + orderData.price = order.amount + orderData.type = order.type === 'buy' ? 'sell' : 'buy' + } + // amount: "0.999998" + // decimals: 6 + // execution: "both" + // price: "1.000000" + // total: "0.999998" + // type: "buy" + + // amount: "0.08973" + // decimals: 6 + // execution: "both" + // price: "1" + // total: "0.08973" + // type: "sell" + + // Changed + // address: "4VBQQU66PR2MOHJ5PXNQTBCRBNJ2WRLMIAX5O6EQWIZREAEKR4GSDG56N4" + // amount: "0.1" + // asset: {id: 37074699, deleted: false, txid: 'JGNZUFHKV6SANVFQBI5CBNCJZVQMR233TKQIVIII3RGYLMGRBT6Q', decimals: 6, name: 'USDC', …} + // decimals: 6 + // execution: "both" + // price: "1.00" + // total: "0.1" + // type: "sell" + + //Current + // address: "4VBQQU66PR2MOHJ5PXNQTBCRBNJ2WRLMIAX5O6EQWIZREAEKR4GSDG56N4" + // amount: "0.2" + // asset: {id: 15322902, deleted: false, txid: 'NOFSUK4EXHFFXJK3ZA6DZMGE6CAGQ7G5JT2X7FYTYQBSQEBZHY4Q', decimals: 6, name: 'LAMP', …} + // decimals: 6 + // execution: "both" + // price: "0.1" + // total: "0.02" + // type: "sell" + + console.log('Order Submitted: OrderData', orderData) + Sentry.addBreadcrumb({ category: 'order', message: `${orderData.execution} ${orderData.type} order placed`, @@ -318,10 +344,10 @@ function PlaceOrderView(props) { // if asset is stable invert sell/buy option let _type = asset.isStable ? (order.type === 'buy' ? 'sell' : 'buy') : order.type if (_type === 'buy') { - console.log('BuyCondition: isBelowMinOrderAmount: ', order.total) + console.log(`BuyCondition: isBelowMinOrderAmount: ${_type}: `, order.total) return new Big(order.total).lt(0.5) } - console.log('BuyCondition: isBelowMinOrderAmount: ', order.total) + console.log(`BuyCondition: isBelowMinOrderAmount: ${_type}: `, order.total) return new Big(order.total).eq(0) } @@ -467,7 +493,7 @@ function PlaceOrderView(props) { {asset.name} - {asaBalance} + **{asaBalance}**
From 7591829495fae5f6569c88f5cad819cd57ff01b5 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 21 Jul 2022 14:13:03 -0400 Subject: [PATCH 45/69] =?UTF-8?q?=F0=9F=91=94=20Swap=20sell/buy=20amount?= =?UTF-8?q?=20range?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wallet/PlaceOrder/Original/order-form.jsx | 4 ++-- .../Wallet/PlaceOrder/Original/view.jsx | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index ac5e73766..007a30813 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -230,8 +230,8 @@ export const OrderForm = ({ /> { - let _type = asset.isStable ? (order.type === 'buy' ? 'sell' : 'buy') : order.type - if (_type === 'buy') { - console.log('BuyCondition: order.price : ', order.price) + // let _type = asset.isStable ? (order.type === 'buy' ? 'sell' : 'buy') : order.type + if (asset.isStable) { + if (order.type === 'sell') { + console.log('BuyCondition: order.price : ', order.price) + console.log('BuyCondition: order.amount : ', order.amount) + return new Big(order.amount).times(order.price).gt(maxSpendableAlgo) + } + console.log('BuyCondition: order.amount : ', order.amount) + console.log('BuyCondition: asaBalance : ', asaBalance) + return new Big(order.price).gt(asaBalance) + } else { + if (order.type === 'buy') { + console.log('BuyCondition: order.price : ', order.price) + console.log('BuyCondition: order.amount : ', order.amount) + return new Big(order.price).times(order.amount).gt(maxSpendableAlgo) + } console.log('BuyCondition: order.amount : ', order.amount) - return new Big(order.price).times(order.amount).gt(maxSpendableAlgo) + console.log('BuyCondition: asaBalance : ', asaBalance) + return new Big(order.amount).gt(asaBalance) } - return new Big(order.amount).gt(asaBalance) } const isLessThanMicroAlgo = () => { From 754c9efe54a8bca5d49eccae27bce638b64b9280 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Sun, 24 Jul 2022 18:33:56 -0400 Subject: [PATCH 46/69] =?UTF-8?q?=F0=9F=92=84=20Update=20OrderBook=20Heade?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 14 +++++++++++--- components/Table/PriceHeader.jsx | 8 +++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 0ef9aeec7..332d204cf 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -457,13 +457,21 @@ export function OrderBook({ isMobile, asset, orders, components }) { )}

- + - {t('amount')} ({assetVeryShortName}) + {t('amount')} ({asset.isStable ? 'ALGO' : assetVeryShortName}) - +
diff --git a/components/Table/PriceHeader.jsx b/components/Table/PriceHeader.jsx index 095297f50..895ebd750 100644 --- a/components/Table/PriceHeader.jsx +++ b/components/Table/PriceHeader.jsx @@ -14,19 +14,21 @@ export const PriceHeaderText = styled(BodyCopyTiny)` } ` -export const TablePriceHeader = ({ title, textAlign }) => { +export const TablePriceHeader = ({ title, textAlign, currenySymbol }) => { const { t } = useTranslation('common') return ( {t(title)} - + {!currenySymbol && } + {currenySymbol &&  {currenySymbol}} ) } TablePriceHeader.propTypes = { title: PropTypes.string.isRequired, - textAlign: PropTypes.string.isRequired + textAlign: PropTypes.string.isRequired, + currenySymbol: PropTypes.string } export default TablePriceHeader From fb8debd67a19c8c830535c2f0eb903af8ae30287 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Sun, 24 Jul 2022 19:27:52 -0400 Subject: [PATCH 47/69] =?UTF-8?q?=F0=9F=92=84=20Descending=20Orders=20for?= =?UTF-8?q?=20StableAsset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useAlgodex.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index bd9dd6942..a9c5028ed 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -296,7 +296,7 @@ export function useAssetChartQuery({ * @param type * @returns {*} */ -function aggregateOrders(orders, asaDecimals, type) { +function aggregateOrders(orders, asaDecimals, type, ascending) { const isBuyOrder = type === 'buy' let total = 0 @@ -349,7 +349,14 @@ function aggregateOrders(orders, asaDecimals, type) { return b.price - a.price } - return orders.sort(sortOrdersToAggregate).reduce(reduceAggregateData, []).sort(sortRowsByPrice) + const sortRowsByPriceInAscending = (a, b) => { + return a.price - b.price + } + + return orders + .sort(sortOrdersToAggregate) + .reduce(reduceAggregateData, []) + .sort(ascending ? sortRowsByPriceInAscending : sortRowsByPrice) } /** @@ -366,7 +373,7 @@ export function useAssetOrderbookQuery({ } } = {}) { // console.log(`useAssetOrderbookQuery(${JSON.stringify({ asset })})`) - const { id, decimals } = asset + const { id, decimals, isStable } = asset const [sell, setSellOrders] = useState([]) const [buy, setBuyOrders] = useState([]) @@ -385,8 +392,8 @@ export function useAssetOrderbookQuery({ typeof data.sellASAOrdersInEscrow !== 'undefined' && typeof data.buyASAOrdersInEscrow !== 'undefined' ) { - setSellOrders(aggregateOrders(data.sellASAOrdersInEscrow, decimals, 'sell')) - setBuyOrders(aggregateOrders(data.buyASAOrdersInEscrow, decimals, 'buy')) + setSellOrders(aggregateOrders(data.sellASAOrdersInEscrow, decimals, 'sell', isStable && true)) + setBuyOrders(aggregateOrders(data.buyASAOrdersInEscrow, decimals, 'buy', isStable && true)) } }, [isLoading, data, setSellOrders, setBuyOrders, decimals]) From 7df8c57e895de6b0fc3a88cedb1a1f95d34dd1da Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 25 Jul 2022 00:53:53 -0400 Subject: [PATCH 48/69] =?UTF-8?q?=F0=9F=92=84=20TradeHistory=20Header=20St?= =?UTF-8?q?ableCoin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/TradeHistory/TradeHistory.jsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/Asset/TradeHistory/TradeHistory.jsx b/components/Asset/TradeHistory/TradeHistory.jsx index 3c761fe55..2dd5fc205 100644 --- a/components/Asset/TradeHistory/TradeHistory.jsx +++ b/components/Asset/TradeHistory/TradeHistory.jsx @@ -106,16 +106,21 @@ const PriceHeaderText = styled(BodyCopyTiny)` } ` -const PriceHeader = () => { +const PriceHeader = ({ currenySymbol }) => { const { t } = useTranslation('common') return ( {t('price')} - + {!currenySymbol && } + {currenySymbol &&  {currenySymbol}} ) } +PriceHeader.propTypes = { + currenySymbol: PropTypes.string +} + /** * Asset Trade History * @@ -185,7 +190,7 @@ export function TradeHistory({ isMobile, asset, orders: tradesData }) { {!isMobile && {t('trade-history')}}
- + {t('amount')} From 45e0f0ec70e8b92302dafe6c008f3bc7fcbeb407 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 25 Jul 2022 03:16:08 -0400 Subject: [PATCH 49/69] =?UTF-8?q?=F0=9F=92=84=20Buy/Sell=20button=20captio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/view.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/view.jsx b/components/Wallet/PlaceOrder/Original/view.jsx index 9e7c3c1f4..b061d3d7b 100644 --- a/components/Wallet/PlaceOrder/Original/view.jsx +++ b/components/Wallet/PlaceOrder/Original/view.jsx @@ -336,8 +336,8 @@ function PlaceOrderView(props) { const renderSubmit = () => { const buttonProps = { - buy: { variant: 'primary', text: `${t('buy')} ${asset.name}` }, - sell: { variant: 'danger', text: `${t('sell')} ${asset.name}` } + buy: { variant: 'primary', text: `${t('buy')} ${asset.isStable ? 'ALGO' : asset.name}` }, + sell: { variant: 'danger', text: `${t('sell')} ${asset.isStable ? 'ALGO' : asset.name}` } } const isBelowMinOrderAmount = () => { From 41e7fd8638821d25cfa02a83fedb7e00db85d70c Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 25 Jul 2022 03:26:23 -0400 Subject: [PATCH 50/69] =?UTF-8?q?=F0=9F=92=84=20Buy/Sell=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/view.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/view.jsx b/components/Wallet/PlaceOrder/Original/view.jsx index b061d3d7b..4a7e948f5 100644 --- a/components/Wallet/PlaceOrder/Original/view.jsx +++ b/components/Wallet/PlaceOrder/Original/view.jsx @@ -86,8 +86,8 @@ function PlaceOrderView(props) { * Sell orders are enabled if active wallet has an ASA balance > 0 */ const enableOrder = { - buy: maxSpendableAlgo > 0, - sell: asaBalance > 0 + buy: asset.isStable ? asaBalance > 0 : maxSpendableAlgo > 0, + sell: asset.isStable ? maxSpendableAlgo > 0 : asaBalance > 0 } const order = useStore((state) => state.order) From 29e3ccf9ddc671f573aec0bcbe8d2583898a5a74 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Mon, 25 Jul 2022 13:07:59 -0400 Subject: [PATCH 51/69] =?UTF-8?q?=F0=9F=92=84=20Add=20Stable=20Coinname=20?= =?UTF-8?q?in=20OrderBook/Trade=20history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 4 ++-- components/Asset/TradeHistory/TradeHistory.jsx | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 332d204cf..12a0b3212 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -460,7 +460,7 @@ export function OrderBook({ isMobile, asset, orders, components }) { @@ -470,7 +470,7 @@ export function OrderBook({ isMobile, asset, orders, components }) {
diff --git a/components/Asset/TradeHistory/TradeHistory.jsx b/components/Asset/TradeHistory/TradeHistory.jsx index 2dd5fc205..5ffa5171f 100644 --- a/components/Asset/TradeHistory/TradeHistory.jsx +++ b/components/Asset/TradeHistory/TradeHistory.jsx @@ -9,6 +9,7 @@ import { floatToFixed } from 'services/display' import localizedFormat from 'dayjs/plugin/localizedFormat' import { rgba } from 'polished' import styled from '@emotion/styled' +import { useMemo } from 'react' import useTranslation from 'next-translate/useTranslation' import { withAssetTradeHistoryQuery } from '@/hooks/withAlgodex' @@ -134,6 +135,10 @@ export function TradeHistory({ isMobile, asset, orders: tradesData }) { const { t } = useTranslation('common') const hasTradeHistory = tradesData.length > 0 + const assetVeryShortName = useMemo(() => { + return asset?.name && asset.name.length >= 1 ? asset.name : 'NO-NAME' + }, [asset]) + const renderHistory = () => { const getColor = (type) => (type === 'buyASA' ? 'green.500' : 'red.500') @@ -190,7 +195,7 @@ export function TradeHistory({ isMobile, asset, orders: tradesData }) { {!isMobile && {t('trade-history')}}
- + {t('amount')} From 48c41f1c0d6213ced2252954bf47b2f15e69c92e Mon Sep 17 00:00:00 2001 From: G Iacono Date: Wed, 27 Jul 2022 11:15:33 -0400 Subject: [PATCH 52/69] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20PriceHeader=20variab?= =?UTF-8?q?le=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 4 ++-- components/Asset/TradeHistory/TradeHistory.jsx | 10 +++++----- components/Table/PriceHeader.jsx | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 12a0b3212..d99bd77b0 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -460,7 +460,7 @@ export function OrderBook({ isMobile, asset, orders, components }) { @@ -470,7 +470,7 @@ export function OrderBook({ isMobile, asset, orders, components }) {
diff --git a/components/Asset/TradeHistory/TradeHistory.jsx b/components/Asset/TradeHistory/TradeHistory.jsx index 5ffa5171f..268b310db 100644 --- a/components/Asset/TradeHistory/TradeHistory.jsx +++ b/components/Asset/TradeHistory/TradeHistory.jsx @@ -107,19 +107,19 @@ const PriceHeaderText = styled(BodyCopyTiny)` } ` -const PriceHeader = ({ currenySymbol }) => { +const PriceHeader = ({ currencySymbol }) => { const { t } = useTranslation('common') return ( {t('price')} - {!currenySymbol && } - {currenySymbol &&  {currenySymbol}} + {!currencySymbol && } + {currencySymbol &&  {currencySymbol}} ) } PriceHeader.propTypes = { - currenySymbol: PropTypes.string + currencySymbol: PropTypes.string } /** @@ -195,7 +195,7 @@ export function TradeHistory({ isMobile, asset, orders: tradesData }) { {!isMobile && {t('trade-history')}}
- + {t('amount')} diff --git a/components/Table/PriceHeader.jsx b/components/Table/PriceHeader.jsx index 895ebd750..9a08ce8c0 100644 --- a/components/Table/PriceHeader.jsx +++ b/components/Table/PriceHeader.jsx @@ -14,13 +14,13 @@ export const PriceHeaderText = styled(BodyCopyTiny)` } ` -export const TablePriceHeader = ({ title, textAlign, currenySymbol }) => { +export const TablePriceHeader = ({ title, textAlign, currencySymbol }) => { const { t } = useTranslation('common') return ( {t(title)} - {!currenySymbol && } - {currenySymbol &&  {currenySymbol}} + {!currencySymbol && } + {currencySymbol &&  {currencySymbol}} ) } @@ -28,7 +28,7 @@ export const TablePriceHeader = ({ title, textAlign, currenySymbol }) => { TablePriceHeader.propTypes = { title: PropTypes.string.isRequired, textAlign: PropTypes.string.isRequired, - currenySymbol: PropTypes.string + currencySymbol: PropTypes.string } export default TablePriceHeader From b6c82d1171d516411531203a3cc739e72408c1c0 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Wed, 27 Jul 2022 11:24:30 -0400 Subject: [PATCH 53/69] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20showFee=20variable?= =?UTF-8?q?=20bool=20type=20correction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/order-form.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Wallet/PlaceOrder/Original/order-form.jsx b/components/Wallet/PlaceOrder/Original/order-form.jsx index 007a30813..c0ffee530 100644 --- a/components/Wallet/PlaceOrder/Original/order-form.jsx +++ b/components/Wallet/PlaceOrder/Original/order-form.jsx @@ -40,7 +40,7 @@ export const USDInputPrice = ({ value, id, showFee }) => { } USDInputPrice.propTypes = { - showFee: PropTypes.boolean, + showFee: PropTypes.bool, value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), id: PropTypes.string, asset: PropTypes.object From 27c98762f9fc7c2e2f189513009d0e5605ee6af7 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Wed, 27 Jul 2022 23:32:01 -0400 Subject: [PATCH 54/69] =?UTF-8?q?=F0=9F=92=84=20Switch=20Stable=20&=20Algo?= =?UTF-8?q?=20Balance=20Row=20in=20StableAssets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/StableAssets.js | 3 +- .../Wallet/PlaceOrder/Original/view.jsx | 325 ++++++++++-------- 2 files changed, 179 insertions(+), 149 deletions(-) diff --git a/components/StableAssets.js b/components/StableAssets.js index 2e5844d4c..c4647aea9 100644 --- a/components/StableAssets.js +++ b/components/StableAssets.js @@ -2,5 +2,6 @@ // Should check whether to decide using of assetid or asset name export const StableAssets = [ 51435943, // USDC, - 37074699 // USDC + 37074699, // USDC, + 38718614 // USDC ] diff --git a/components/Wallet/PlaceOrder/Original/view.jsx b/components/Wallet/PlaceOrder/Original/view.jsx index 4a7e948f5..d4c0b0964 100644 --- a/components/Wallet/PlaceOrder/Original/view.jsx +++ b/components/Wallet/PlaceOrder/Original/view.jsx @@ -412,160 +412,189 @@ function PlaceOrderView(props) { ) } - const renderForm = () => { - return ( -
- - !asset.isGeoBlocked && handleChange(e, 'type')} - /> - - - - !asset.isGeoBlocked && handleChange(e, 'type')} - /> - - - - - - - - {t('available-balance')} - ( - - - - )} - > - + const renderForm = () => ( + + + !asset.isGeoBlocked && handleChange(e, 'type')} + /> + + + + !asset.isGeoBlocked && handleChange(e, 'type')} + /> + + + + + + + + {t('available-balance')} + ( + + + + )} + > + + + {t('orders:available')}: + + - {t('orders:available')}: + {maxSpendableAlgo} - - - {maxSpendableAlgo} - - - - - + + + + + + {t('total')}: + + - {t('total')}: + {algoBalance} - - - {algoBalance} - - - - - - -  * - {t('max-spend-explanation', { - amount: new Big(algoBalance) - .minus(new Big(maxSpendableAlgo)) - .round(6) - .toString() - })} - - - - - - - ALGO - - - {maxSpendableAlgo} -
- - - -
-
- - - {asset.name} - - - **{asaBalance}** -
- - + + +
+ + +  * + {t('max-spend-explanation', { + amount: new Big(algoBalance).minus(new Big(maxSpendableAlgo)).round(6).toString() + })} - - -
- - - { - !asset.isGeoBlocked && setOrderView(LIMIT_PANEL) - !asset.isGeoBlocked && handleOptionsChange({ target: { value: 'both' } }) - }} - > - {t('limit')} - - { - !asset.isGeoBlocked && setOrderView(MARKET_PANEL) - !asset.isGeoBlocked && handleOptionsChange({ target: { value: 'market' } }) - }} - > - {t('market')} - - - {orderView === LIMIT_PANEL ? ( - {} : handleChange} - asset={asset} - maxSpendableAlgo={maxSpendableAlgo} - asaBalance={asaBalance} - handleRangeChange={!asset.isGeoBlocked && handleRangeChange} - enableOrder={enableOrder} - handleOptionsChange={!asset.isGeoBlocked && handleOptionsChange} - newOrderSizeFilter={newOrderSizeFilter} - microAlgo={MICROALGO} - setNewOrderSizeFilter={setNewOrderSizeFilter} - /> - ) : ( - {} : handleChange} - asset={asset} - maxSpendableAlgo={maxSpendableAlgo} - asaBalance={asaBalance} - handleRangeChange={!asset.isGeoBlocked && handleRangeChange} - enableOrder={enableOrder} - /> + + + + + {asset.isStable && ( + <> + + + {asset.name} + + + {asaBalance} +
+ + + +
+
+ + + ALGO + + + {maxSpendableAlgo} +
+ + + +
+
+ )} - {renderSubmit()} - - ) - } + + {!asset.isStable && ( + <> + + + ALGO + + + {maxSpendableAlgo} +
+ + + +
+
+ + + {asset.name} + + + {asaBalance} +
+ + + +
+
+ + )} + + + + { + !asset.isGeoBlocked && setOrderView(LIMIT_PANEL) + !asset.isGeoBlocked && handleOptionsChange({ target: { value: 'both' } }) + }} + > + {t('limit')} + + { + !asset.isGeoBlocked && setOrderView(MARKET_PANEL) + !asset.isGeoBlocked && handleOptionsChange({ target: { value: 'market' } }) + }} + > + {t('market')} + + + {orderView === LIMIT_PANEL ? ( + {} : handleChange} + asset={asset} + maxSpendableAlgo={maxSpendableAlgo} + asaBalance={asaBalance} + handleRangeChange={!asset.isGeoBlocked && handleRangeChange} + enableOrder={enableOrder} + handleOptionsChange={!asset.isGeoBlocked && handleOptionsChange} + newOrderSizeFilter={newOrderSizeFilter} + microAlgo={MICROALGO} + setNewOrderSizeFilter={setNewOrderSizeFilter} + /> + ) : ( + {} : handleChange} + asset={asset} + maxSpendableAlgo={maxSpendableAlgo} + asaBalance={asaBalance} + handleRangeChange={!asset.isGeoBlocked && handleRangeChange} + enableOrder={enableOrder} + /> + )} + {renderSubmit()} + + ) return ( From 0cb20dbf485c3f26bb0b4d9ace5871dead07a4be Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 28 Jul 2022 02:28:36 -0400 Subject: [PATCH 55/69] =?UTF-8?q?=F0=9F=91=94=20Update=20OrderBook=20Logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 3 ++- hooks/useAlgodex.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index d99bd77b0..37e0c6132 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -330,7 +330,8 @@ export function OrderBook({ isMobile, asset, orders, components }) { ? floatToFixedDynamic(1 / order.price, selectedPrecision, selectedPrecision) : floatToFixedDynamic(order.price, selectedPrecision, selectedPrecision) - const _amount = order.amount + const _amount = asset.isStable ? order.amount * order.price : order.amount + const index = result.findIndex( (obj) => floatToFixedDynamic(obj.price, selectedPrecision, selectedPrecision) === _price ) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index a9c5028ed..3af42c8e3 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -534,10 +534,12 @@ const mapOpenOrdersData = (data, assetList = []) => { const unitName = assetsInfo[assetId]?.params['unit-name'] || unitNameMap.get(assetId) let pair = `${unitName}/ALGO` let price = floatToFixed(formattedPrice) + let amount = formattedASAAmount if (StableAssets.includes(assetId)) { pair = `ALGO/${unitName}` - price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) : 'Invalid Price' + amount = `${formattedPrice * formattedASAAmount} (ALGO) ` + price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) + ' (USDC) ' : 'Invalid Price' } return { asset: { id: assetId }, @@ -548,7 +550,7 @@ const mapOpenOrdersData = (data, assetList = []) => { pair: pair, type: 'BUY', status: 'OPEN', - amount: formattedASAAmount, + amount: amount, metadata: order } }) @@ -558,10 +560,12 @@ const mapOpenOrdersData = (data, assetList = []) => { const unitName = assetsInfo[assetId]?.params['unit-name'] || unitNameMap.get(assetId) let pair = `${unitName}/ALGO` let price = floatToFixed(formattedPrice) + let amount = formattedASAAmount if (StableAssets.includes(assetId)) { pair = `ALGO/${unitName}` - price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) : 'Invalid Price' + amount = `${formattedPrice * formattedASAAmount} (ALGO) ` + price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) + ' (USDC) ' : 'Invalid Price' } return { asset: { id: assetId }, @@ -571,7 +575,7 @@ const mapOpenOrdersData = (data, assetList = []) => { pair: pair, type: 'SELL', status: 'OPEN', - amount: formattedASAAmount, + amount: amount, metadata: order } }) From 88d63aed57e2b4be17130dc0897b3f61a131648d Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 28 Jul 2022 14:25:10 -0400 Subject: [PATCH 56/69] =?UTF-8?q?=F0=9F=92=84=20Update=20AssetName=20in=20?= =?UTF-8?q?ORderbook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useAlgodex.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 3af42c8e3..0547962e7 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -565,7 +565,10 @@ const mapOpenOrdersData = (data, assetList = []) => { if (StableAssets.includes(assetId)) { pair = `ALGO/${unitName}` amount = `${formattedPrice * formattedASAAmount} (ALGO) ` - price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) + ' (USDC) ' : 'Invalid Price' + price = + formattedPrice !== 0 + ? floatToFixed(1 / formattedPrice) + ` (${unitName}) ` + : 'Invalid Price' } return { asset: { id: assetId }, @@ -581,7 +584,6 @@ const mapOpenOrdersData = (data, assetList = []) => { }) const allOrders = [...buyOrders, ...sellOrders] allOrders.sort((a, b) => (a.unix_time < b.unix_time ? 1 : -1)) - return allOrders } From 407783132d3ec2774bd85c182791e5dfedc10735 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 28 Jul 2022 14:49:20 -0400 Subject: [PATCH 57/69] =?UTF-8?q?=F0=9F=92=84=20Volume=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/ChartOverlay.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/Asset/Chart/ChartOverlay.jsx b/components/Asset/Chart/ChartOverlay.jsx index 7b79f79a5..6152a2e6d 100644 --- a/components/Asset/Chart/ChartOverlay.jsx +++ b/components/Asset/Chart/ChartOverlay.jsx @@ -253,7 +253,8 @@ function ChartOverlay(props) {
Vol:
-
{`${volume} ${asset.name}`}
+ {asset.isStable &&
{`${volume} ALGO`}
} + {!asset.isStable &&
{`${volume} ${asset.name}`}
}
From a7b3d15e2589398ae4fb2dd8bbff27706bed7b60 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 28 Jul 2022 15:24:35 -0400 Subject: [PATCH 58/69] =?UTF-8?q?=F0=9F=92=84:=20Inverted=20Volume=20in=20?= =?UTF-8?q?ChartOverlay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/ChartOverlay.jsx | 4 ++++ hooks/useAlgodex.js | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/components/Asset/Chart/ChartOverlay.jsx b/components/Asset/Chart/ChartOverlay.jsx index 6152a2e6d..22705b998 100644 --- a/components/Asset/Chart/ChartOverlay.jsx +++ b/components/Asset/Chart/ChartOverlay.jsx @@ -243,6 +243,10 @@ function ChartOverlay(props) {
{openCloseChange()}
+ +
Volume:
+
{volume}
+
diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 0547962e7..2418778c0 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -182,12 +182,12 @@ function getOhlc(data, isStableAsset) { return lastPriceData } -function mapVolumeData(data, volUpColor, volDownColor) { +function mapVolumeData(data, isStableAsset, volUpColor, volDownColor) { const mappedData = data?.chart_data?.map(({ asaVolume, unixTime }) => { const time = parseInt(unixTime) return { time: time, - value: asaVolume + value: isStableAsset ? (asaVolume == 0 ? 'Invalid' : 1 / asaVolume) : asaVolume } }) const volumeColors = data?.chart_data.map(({ open, close }) => @@ -264,14 +264,21 @@ export function useAssetChartQuery({ [orderBook] ) const priceData = useMemo(() => mapPriceData(data, asset.isStable), [data]) - const volumeData = useMemo(() => mapVolumeData(data, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), [data]) + const volumeData = useMemo( + () => mapVolumeData(data, asset.isStable, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), + [data] + ) const ohlcOverlay = useMemo(() => getOhlc(data, asset.isStable), [data]) - const volume = millify(data?.chart_data[data?.chart_data.length - 1]?.asaVolume || 0) + let volume = millify(data?.chart_data[data?.chart_data.length - 1]?.asaVolume || 0) + + if (asset.isStable) { + volume = volume == 0 ? 'Invalid' : 1 / volume + } const isLoading = isOrdersLoading || isChartLoading const isError = isOrdersError || isChartError - + console.log('VolumeData: ', volumeData) return { data: { overlay: { From 9fffc4718edd1b9711df18250da1e96f6f5aba75 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 29 Jul 2022 02:08:12 -0400 Subject: [PATCH 59/69] =?UTF-8?q?=F0=9F=92=84=20Update=20Open=20Headers=20?= =?UTF-8?q?Table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/Table/OpenOrdersTable.jsx | 2 +- hooks/useAlgodex.js | 15 +++++++++------ services/algoexplorer.js | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/components/Wallet/Table/OpenOrdersTable.jsx b/components/Wallet/Table/OpenOrdersTable.jsx index 2137dad2a..b6d611784 100644 --- a/components/Wallet/Table/OpenOrdersTable.jsx +++ b/components/Wallet/Table/OpenOrdersTable.jsx @@ -132,7 +132,7 @@ export function OpenOrdersTable({ orders: _orders }) { Cell: AssetNameCell }, { - Header: t('price') + ' (ALGO)', + Header: t('price'), accessor: 'price', Cell: DefaultCell }, diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 2418778c0..65aa406f1 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -540,13 +540,16 @@ const mapOpenOrdersData = (data, assetList = []) => { const { assetId, formattedPrice, formattedASAAmount, unix_time } = order const unitName = assetsInfo[assetId]?.params['unit-name'] || unitNameMap.get(assetId) let pair = `${unitName}/ALGO` - let price = floatToFixed(formattedPrice) - let amount = formattedASAAmount + let price = floatToFixed(formattedPrice) + ' (ALGO)' + let amount = formattedASAAmount + ` (${unitName}) ` if (StableAssets.includes(assetId)) { pair = `ALGO/${unitName}` amount = `${formattedPrice * formattedASAAmount} (ALGO) ` - price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) + ' (USDC) ' : 'Invalid Price' + price = + formattedPrice !== 0 + ? floatToFixed(1 / formattedPrice) + ` (${unitName}) ` + : 'Invalid Price' } return { asset: { id: assetId }, @@ -566,12 +569,12 @@ const mapOpenOrdersData = (data, assetList = []) => { const { assetId, formattedPrice, formattedASAAmount, unix_time } = order const unitName = assetsInfo[assetId]?.params['unit-name'] || unitNameMap.get(assetId) let pair = `${unitName}/ALGO` - let price = floatToFixed(formattedPrice) - let amount = formattedASAAmount + let price = floatToFixed(formattedPrice) + ' (ALGO)' + let amount = formattedASAAmount + ` (${unitName}) ` if (StableAssets.includes(assetId)) { pair = `ALGO/${unitName}` - amount = `${formattedPrice * formattedASAAmount} (ALGO) ` + amount = `${formattedPrice * formattedASAAmount} (1ALGO) ` price = formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) + ` (${unitName}) ` diff --git a/services/algoexplorer.js b/services/algoexplorer.js index 14405943d..97d1ca02a 100644 --- a/services/algoexplorer.js +++ b/services/algoexplorer.js @@ -179,6 +179,6 @@ export async function fetchCurrentAssetPrices(assetId) { console.debug(`fetchCurrentAssetPrices(): `, data?.[assetId]?.['price'] ?? 1) return { - usdPrice: data?.[assetId]?.['price'] ?? 1 + usdPrice: data?.[assetId]?.['price'] ?? 0.99 } } From 39b84d8113ff46ee0a6f5b0dbb252ace3c98a2c5 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 29 Jul 2022 02:18:12 -0400 Subject: [PATCH 60/69] =?UTF-8?q?=F0=9F=92=84=20Update=20Oders=20History?= =?UTF-8?q?=20Table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/Table/TradeHistoryTable.jsx | 2 +- hooks/useAlgodex.js | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/components/Wallet/Table/TradeHistoryTable.jsx b/components/Wallet/Table/TradeHistoryTable.jsx index 1aeecab37..16c78a9ef 100644 --- a/components/Wallet/Table/TradeHistoryTable.jsx +++ b/components/Wallet/Table/TradeHistoryTable.jsx @@ -67,7 +67,7 @@ export function TradeHistoryTable({ orders }) { }, { - Header: t('price') + ' (ALGO)', + Header: t('price'), accessor: 'price', Cell: DefaultCell }, diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 65aa406f1..b202c1103 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -633,7 +633,7 @@ export function useWalletTradeHistoryQuery({ } }) { const { address } = wallet - const mapTradeHistoryData = (data) => { + const mapTradeHistoryData = (data, assetList = []) => { const buyText = 'BUY' const sellText = 'SELL' if (!data || !data.transactions || !data.allAssets) { @@ -646,18 +646,34 @@ export function useWalletTradeHistoryQuery({ allAssetsInfo[currentAssetInfo.index] = currentAssetInfo return allAssetsInfo }, {}) + const unitNameMap = + Object.keys(assetsInfo).length === 0 ? getFormattedPairMap(assetList) : new Map() return tradeHistoryData.map( ({ unix_time, group_id, asset_id, tradeType, formattedPrice, formattedASAAmount }) => { const side = tradeType === 'buyASA' ? buyText : sellText + // const unitName = assetsInfo[asset_id]?.params['unit-name'] || unitNameMap.get(asset_id) + const unitName = assetsInfo[asset_id].params['unit-name'] + let price = floatToFixed(formattedPrice) + ' (ALGO)' + let amount = formattedASAAmount + ` (${unitName}) ` + let pair = `${unitName}/ALGO` + + if (StableAssets.includes(asset_id)) { + pair = `ALGO/${unitName}` + amount = `${formattedPrice * formattedASAAmount} (ALGO) ` + price = + formattedPrice !== 0 + ? floatToFixed(1 / formattedPrice) + ` (${unitName}) ` + : 'Invalid Price' + } return { id: asset_id, groupId: encodeURIComponent(group_id), date: dayjs(unix_time * 1000).format('YYYY-MM-DD HH:mm:ss'), - price: floatToFixed(formattedPrice), - pair: `${assetsInfo[asset_id].params['unit-name']}/ALGO`, + price: price, + pair: pair, side, - amount: formattedASAAmount + amount: amount } } ) @@ -667,7 +683,9 @@ export function useWalletTradeHistoryQuery({ () => fetchWalletTradeHistory(address), options ) - const orders = useMemo(() => mapTradeHistoryData(data), [data]) + const assetsList = useSearchResultsQuery() + + const orders = useMemo(() => mapTradeHistoryData(data, assetsList), [data, assetsList]) return { data: { orders }, ...rest } } /** From 820ae239044b5604176d311cea3ab630d32bf635 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 29 Jul 2022 05:02:01 -0400 Subject: [PATCH 61/69] =?UTF-8?q?=F0=9F=92=84=20Update=20volume=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/Chart.jsx | 11 +++++++--- hooks/useAlgodex.js | 36 ++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/components/Asset/Chart/Chart.jsx b/components/Asset/Chart/Chart.jsx index 419f99911..7ff36fbeb 100644 --- a/components/Asset/Chart/Chart.jsx +++ b/components/Asset/Chart/Chart.jsx @@ -206,6 +206,8 @@ export function Chart({ ] ) + console.log('asset.isStable: ', asset.isStable) + return ( mouseMove(ev)} onMouseOut={() => mouseOut()}> {/*{!isFetched && isFetching && }*/} @@ -231,7 +233,7 @@ export function Chart({ bid={overlay.orderbook.bid} ask={overlay.orderbook.ask} spread={overlay.orderbook.spread} - volume={overlay.volume} + volume={asset.isStable ? overlay.algoVolume : overlay.volume} /> )} {typeof overlay.ohlc === 'undefined' && ( @@ -241,7 +243,7 @@ export function Chart({ bid={_overlay.orderbook.bid} ask={_overlay.orderbook.ask} spread={_overlay.orderbook.spread} - volume={_overlay.volume} + volume={asset.isStable ? _overlay.algoVolume : _overlay.volume} /> )} @@ -254,7 +256,8 @@ export function Chart({ Chart.propTypes = { asset: PropTypes.shape({ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, - decimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired + decimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, + isStable: PropTypes.bool }).isRequired, interval: PropTypes.string.isRequired, mode: PropTypes.string.isRequired, @@ -266,6 +269,7 @@ Chart.propTypes = { close: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) }), volume: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + algoVolume: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), orderbook: PropTypes.shape({ bid: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), ask: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), @@ -274,6 +278,7 @@ Chart.propTypes = { }), ohlc: PropTypes.array.isRequired, volume: PropTypes.array.isRequired, + algoVolume: PropTypes.array, onChange: PropTypes.func } diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index b202c1103..1e4f803e1 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -182,12 +182,26 @@ function getOhlc(data, isStableAsset) { return lastPriceData } -function mapVolumeData(data, isStableAsset, volUpColor, volDownColor) { +function mapVolumeData(data, volUpColor, volDownColor) { const mappedData = data?.chart_data?.map(({ asaVolume, unixTime }) => { const time = parseInt(unixTime) return { time: time, - value: isStableAsset ? (asaVolume == 0 ? 'Invalid' : 1 / asaVolume) : asaVolume + value: asaVolume + } + }) + const volumeColors = data?.chart_data.map(({ open, close }) => + open > close ? volDownColor : volUpColor + ) + return mappedData?.map((md, i) => ({ ...md, color: volumeColors[i] })) || [] +} + +function mapAlgoVolumeData(data, volUpColor, volDownColor) { + const mappedData = data?.chart_data?.map(({ algoVolume, unixTime }) => { + const time = parseInt(unixTime) + return { + time: time, + value: algoVolume } }) const volumeColors = data?.chart_data.map(({ open, close }) => @@ -264,29 +278,29 @@ export function useAssetChartQuery({ [orderBook] ) const priceData = useMemo(() => mapPriceData(data, asset.isStable), [data]) - const volumeData = useMemo( - () => mapVolumeData(data, asset.isStable, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), + const volumeData = useMemo(() => mapVolumeData(data, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), [data]) + const algoVolumeData = useMemo( + () => mapAlgoVolumeData(data, VOLUME_UP_COLOR, VOLUME_DOWN_COLOR), [data] ) const ohlcOverlay = useMemo(() => getOhlc(data, asset.isStable), [data]) - let volume = millify(data?.chart_data[data?.chart_data.length - 1]?.asaVolume || 0) - - if (asset.isStable) { - volume = volume == 0 ? 'Invalid' : 1 / volume - } + const volume = millify(data?.chart_data[data?.chart_data.length - 1]?.asaVolume || 0) + const algoVolume = millify(data?.chart_data[data?.chart_data.length - 1]?.algoVolume || 0) const isLoading = isOrdersLoading || isChartLoading const isError = isOrdersError || isChartError - console.log('VolumeData: ', volumeData) + console.log('VolumeData: ', algoVolumeData) return { data: { overlay: { ohlc: ohlcOverlay, orderbook: { bid, ask, spread }, - volume + volume, + algoVolume }, volume: volumeData, + algoVolume: algoVolumeData, ohlc: priceData, isLoading, isError From 0b138a127400e1c2b967b21609a1be9b842e0a2f Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 29 Jul 2022 14:57:49 -0400 Subject: [PATCH 62/69] =?UTF-8?q?=E2=9C=A8=20Implement=20AlgoVolume=20in?= =?UTF-8?q?=20Chart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/Chart.jsx | 36 ++++++++++++++++++++++++-------- hooks/useAlgodex.js | 3 +-- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/components/Asset/Chart/Chart.jsx b/components/Asset/Chart/Chart.jsx index 7ff36fbeb..e4755fb81 100644 --- a/components/Asset/Chart/Chart.jsx +++ b/components/Asset/Chart/Chart.jsx @@ -101,11 +101,13 @@ export function Chart({ interval: _interval, mode: _mode, volume, + algoVolume, ohlc, overlay: _overlay, onChange }) { // console.log(`Chart(`, arguments[0], `)`) + const [interval, setInterval] = useState(_interval) const [overlay, setOverlay] = useState(_overlay) const [chartMode, setChartMode] = useState(_mode) @@ -151,19 +153,28 @@ export function Chart({ const updateHoverPrices = useCallback( (logical) => { - if (ohlc == null || volume == null) { - return + if (asset.isStable) { + if (ohlc == null || algoVolume == null) { + return + } + } else { + if (ohlc == null || volume == null) { + return + } } + const priceEntry = ohlc[logical] const volumeEntry = volume[logical] + const algoVolumeEntry = algoVolume[logical] setOverlay({ ...overlay, ohlc: priceEntry, - volume: volumeEntry != null ? millify(volumeEntry.value) : '0' + volume: volumeEntry != null ? millify(volumeEntry.value) : '0', + algoVolume: algoVolumeEntry != null ? millify(algoVolumeEntry.value) : '0' }) }, - [ohlc, volume, setOverlay, overlay] + [ohlc, volume, setOverlay, overlay, asset, algoVolume] ) const mouseOut = useCallback(() => { @@ -182,9 +193,16 @@ export function Chart({ const x = ev.clientX - rect.left const logical = candleChart.timeScale().coordinateToLogical(x) - if (logical >= ohlc.length || logical >= volume.length) { - setOverlay(_overlay) - return + if (asset.isStable) { + if (logical >= ohlc.length || logical >= algoVolume.length) { + setOverlay(_overlay) + return + } + } else { + if (logical >= ohlc.length || logical >= volume.length) { + setOverlay(_overlay) + return + } } if (logical !== currentLogical) { @@ -202,12 +220,12 @@ export function Chart({ setCurrentLogical, updateHoverPrices, volume, + algoVolume, + asset.isStable, ohlc ] ) - console.log('asset.isStable: ', asset.isStable) - return ( mouseMove(ev)} onMouseOut={() => mouseOut()}> {/*{!isFetched && isFetching && }*/} diff --git a/hooks/useAlgodex.js b/hooks/useAlgodex.js index 1e4f803e1..a99227f35 100644 --- a/hooks/useAlgodex.js +++ b/hooks/useAlgodex.js @@ -287,10 +287,9 @@ export function useAssetChartQuery({ const volume = millify(data?.chart_data[data?.chart_data.length - 1]?.asaVolume || 0) const algoVolume = millify(data?.chart_data[data?.chart_data.length - 1]?.algoVolume || 0) - const isLoading = isOrdersLoading || isChartLoading const isError = isOrdersError || isChartError - console.log('VolumeData: ', algoVolumeData) + return { data: { overlay: { From 372348ba653c8406a750110a63c3b2f86588871f Mon Sep 17 00:00:00 2001 From: G Iacono Date: Thu, 4 Aug 2022 12:32:19 -0400 Subject: [PATCH 63/69] =?UTF-8?q?=F0=9F=92=84=20Update=20Buy=20Sell=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Wallet/PlaceOrder/Original/view.jsx | 1 - hooks/useAlgodex.js | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Wallet/PlaceOrder/Original/view.jsx b/components/Wallet/PlaceOrder/Original/view.jsx index d4c0b0964..14e83bb28 100644 --- a/components/Wallet/PlaceOrder/Original/view.jsx +++ b/components/Wallet/PlaceOrder/Original/view.jsx @@ -397,7 +397,6 @@ function PlaceOrderView(props) { console.log('BuyCondition: asset.isGeoBlocked: ', asset.isGeoBlocked) console.log('BuyCondition: status.submitting: ', status.submitting) - console.log('isDisabled: ', isDisabled) return ( { - const side = tradeType === 'buyASA' ? buyText : sellText + let side = tradeType === 'buyASA' ? buyText : sellText // const unitName = assetsInfo[asset_id]?.params['unit-name'] || unitNameMap.get(asset_id) const unitName = assetsInfo[asset_id].params['unit-name'] let price = floatToFixed(formattedPrice) + ' (ALGO)' @@ -677,6 +677,7 @@ export function useWalletTradeHistoryQuery({ formattedPrice !== 0 ? floatToFixed(1 / formattedPrice) + ` (${unitName}) ` : 'Invalid Price' + side = side === buyText ? sellText : buyText } return { From 9fb00920d8e1f3d2ef7f292b638831cc2c93a570 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 5 Aug 2022 04:17:48 -0400 Subject: [PATCH 64/69] =?UTF-8?q?=F0=9F=92=84:=20Inverse=20Pair=20String?= =?UTF-8?q?=20in=20AssetSearch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Nav/SearchSidebar/SearchTable.jsx | 28 ++++++++++++++------ components/StableAssets.js | 4 ++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/components/Nav/SearchSidebar/SearchTable.jsx b/components/Nav/SearchSidebar/SearchTable.jsx index ea0a729cd..431a5ea38 100644 --- a/components/Nav/SearchSidebar/SearchTable.jsx +++ b/components/Nav/SearchSidebar/SearchTable.jsx @@ -283,14 +283,26 @@ export const NavSearchTable = ({ style={{ minWidth: '0.75rem' }} color={handleFavoritesFn(row?.original?.id)} /> - - {value} - {`/`} - - ALGO - {/* {row.original.verified && } */} - - + {row?.original.isStable && ( + + ALGO + {`/`} + + {value} + {/* {row.original.verified && } */} + + + )} + {!row?.original.isStable && ( + + {value} + {`/`} + + ALGO + {/* {row.original.verified && } */} + + + )}

diff --git a/components/StableAssets.js b/components/StableAssets.js index c4647aea9..02b696a13 100644 --- a/components/StableAssets.js +++ b/components/StableAssets.js @@ -3,5 +3,7 @@ export const StableAssets = [ 51435943, // USDC, 37074699, // USDC, - 38718614 // USDC + 38718614, // USDC, + 42279195, // USDT + 94115664 //USDT ] From 24da41e5ebe0c7dd2b4a795207641e8ef1cbce29 Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 12 Aug 2022 06:55:27 -0400 Subject: [PATCH 65/69] =?UTF-8?q?=F0=9F=92=84=20Fake=20use=20of=20AlgoVolu?= =?UTF-8?q?me=20in=20Chart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/Chart.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/Asset/Chart/Chart.jsx b/components/Asset/Chart/Chart.jsx index 90da28d50..67c5210f5 100644 --- a/components/Asset/Chart/Chart.jsx +++ b/components/Asset/Chart/Chart.jsx @@ -10,6 +10,7 @@ import styled from '@emotion/styled' import useAreaChart from './hooks/useAreaChart' import useCandleChart from './hooks/useCandleChart' import { withAssetChartQuery } from '@algodex/algodex-hooks' +import floatToFixed from '@algodex/algodex-sdk/lib/utils/format/floatToFixed' const Container = styled.div` position: relative; @@ -113,6 +114,17 @@ export function Chart({ const [chartMode, setChartMode] = useState(_mode) const [currentLogical, setCurrentLogical] = useState(ohlc.length - 1) + // Update ohlc data when it is stable asset + algoVolume = [...volume] // temporary solution: should be updated from backend + if (asset.isStable) { + ohlc.forEach((ele, index) => { + ohlc[index].open = ele.open != 0 ? floatToFixed(1 / ele.open) : 'Invalid' + ohlc[index].low = ele.low != 0 ? floatToFixed(1 / ele.low) : 'Invalid' + ohlc[index].high = ele.high != 0 ? floatToFixed(1 / ele.high) : 'Invalid' + ohlc[index].close = ele.close != 0 ? floatToFixed(1 / ele.close) : 'Invalid' + }) + } + useEffect(() => { setOverlay(_overlay) setCurrentLogical(ohlc.length - 1) From f2d93599db5a473cb234863af7f68a953b49662a Mon Sep 17 00:00:00 2001 From: G Iacono Date: Fri, 12 Aug 2022 08:00:04 -0400 Subject: [PATCH 66/69] =?UTF-8?q?=F0=9F=92=84=20Remove=20merging=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Table/Table.jsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/Table/Table.jsx b/components/Table/Table.jsx index 2cf725b6b..9093d909a 100644 --- a/components/Table/Table.jsx +++ b/components/Table/Table.jsx @@ -91,12 +91,9 @@ const Container = styled.div` color: ${({ theme }) => theme.palette.gray['600']}; font-size: 0.75rem; line-height: 1.25; -<<<<<<< HEAD - -======= border-right: solid 1px ${({ theme }) => theme.palette.gray['700']}; border-bottom: solid 1px ${({ theme }) => theme.palette.gray['700']}; ->>>>>>> next3 + &:first-of-type { padding-left: 1.125rem; box-sizing: border-box; From 9ec3f33799f5b75e397fe2b6bdbff3925daacf97 Mon Sep 17 00:00:00 2001 From: Ikechi Date: Thu, 1 Sep 2022 22:10:33 +0100 Subject: [PATCH 67/69] =?UTF-8?q?=E2=9A=A1=EF=B8=8FFix=20chart=20inversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/Chart/Chart.jsx | 19 ++++++------ components/Asset/Chart/ChartOverlay.jsx | 7 +++-- components/Asset/OrderBook/OrderBook.jsx | 16 ++++++++-- .../PlaceOrder/Form/AvailableBalance.jsx | 31 +++++++++++++++++-- 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/components/Asset/Chart/Chart.jsx b/components/Asset/Chart/Chart.jsx index 67c5210f5..dcc93c9f0 100644 --- a/components/Asset/Chart/Chart.jsx +++ b/components/Asset/Chart/Chart.jsx @@ -5,12 +5,12 @@ import { useCallback, useEffect, useRef, useState } from 'react' import ChartOverlay from './ChartOverlay' import ChartSettings from './ChartSettings' import PropTypes from 'prop-types' +import floatToFixed from '@algodex/algodex-sdk/lib/utils/format/floatToFixed' import millify from 'millify' import styled from '@emotion/styled' import useAreaChart from './hooks/useAreaChart' import useCandleChart from './hooks/useCandleChart' import { withAssetChartQuery } from '@algodex/algodex-hooks' -import floatToFixed from '@algodex/algodex-sdk/lib/utils/format/floatToFixed' const Container = styled.div` position: relative; @@ -113,7 +113,6 @@ export function Chart({ const [overlay, setOverlay] = useState(_overlay) const [chartMode, setChartMode] = useState(_mode) const [currentLogical, setCurrentLogical] = useState(ohlc.length - 1) - // Update ohlc data when it is stable asset algoVolume = [...volume] // temporary solution: should be updated from backend if (asset.isStable) { @@ -126,7 +125,7 @@ export function Chart({ } useEffect(() => { - setOverlay(_overlay) + // setOverlay(_overlay) setCurrentLogical(ohlc.length - 1) }, [ohlc, _overlay, setOverlay]) @@ -178,7 +177,6 @@ export function Chart({ const priceEntry = ohlc[logical] const volumeEntry = volume[logical] const algoVolumeEntry = algoVolume[logical] - setOverlay({ ...overlay, ohlc: priceEntry, @@ -190,7 +188,12 @@ export function Chart({ ) const mouseOut = useCallback(() => { - setOverlay(_overlay) + if (asset.isStable) { + const __overlay = { ...overlay, ..._overlay } + setOverlay(__overlay) + } else { + setOverlay(_overlay) + } }, [setOverlay, _overlay]) const mouseMove = useCallback( @@ -204,19 +207,17 @@ export function Chart({ const rect = ReactDOM.findDOMNode(ev.target).getBoundingClientRect() const x = ev.clientX - rect.left const logical = candleChart.timeScale().coordinateToLogical(x) - if (asset.isStable) { if (logical >= ohlc.length || logical >= algoVolume.length) { - setOverlay(_overlay) + // setOverlay(_overlay) return } } else { if (logical >= ohlc.length || logical >= volume.length) { - setOverlay(_overlay) + // setOverlay(_overlay) return } } - if (logical !== currentLogical) { setCurrentLogical(logical) updateHoverPrices(logical) diff --git a/components/Asset/Chart/ChartOverlay.jsx b/components/Asset/Chart/ChartOverlay.jsx index 4a239b4d7..cc4a05de1 100644 --- a/components/Asset/Chart/ChartOverlay.jsx +++ b/components/Asset/Chart/ChartOverlay.jsx @@ -228,7 +228,7 @@ function ChartOverlay(props) { )} {asset.isStable && (
-  ALGO / {`${asset.name} `} + ALGO / {`${asset.name} `}
)}
@@ -257,10 +257,10 @@ function ChartOverlay(props) {
{openCloseChange()}
- + {/*
Volume:
{volume}
-
+
*/} @@ -271,6 +271,7 @@ function ChartOverlay(props) {
Vol:
+ {/*
{`${volume} ${asset.name}`}
*/} {asset.isStable &&
{`${volume} ALGO`}
} {!asset.isStable &&
{`${volume} ${asset.name}`}
}
diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 70a82874b..d25bdc0c7 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -479,10 +479,22 @@ export function OrderBook({ asset, orders, components }) {
- + {t('amount')} ({asset.isStable ? 'ALGO' : assetVeryShortName}) - + {t('total')} ({asset.isStable ? 'ALGO' : assetVeryShortName})
diff --git a/components/Wallet/PlaceOrder/Form/AvailableBalance.jsx b/components/Wallet/PlaceOrder/Form/AvailableBalance.jsx index 4cea7dcc5..7b71e5124 100644 --- a/components/Wallet/PlaceOrder/Form/AvailableBalance.jsx +++ b/components/Wallet/PlaceOrder/Form/AvailableBalance.jsx @@ -47,6 +47,34 @@ const IconButton = styled.button` } ` +const AsaBalance = ({ amount, asaName, type, decimal = 6 }) => { + // const _amount = amount + // const _price = price + // const _usdPrice = amount + return ( + + + {asaName} + + + + {fromBaseUnits(amount)} + + + + + + + ) +} + +AsaBalance.propTypes = { + amount: PropTypes.number, + asaName: PropTypes.string, + type: PropTypes.string, + decimal: PropTypes.number +} + export const AvailableBalance = ({ wallet, asset }) => { const { t } = useTranslation('place-order') const { address: activeWalletAddr } = wallet @@ -135,13 +163,12 @@ export const AvailableBalance = ({ wallet, asset }) => { - + {/* */} {asset.name || asset.id} {fromBaseUnits(assetBalance, asset.decimals)} - {/* {assetBalance} */} From 21cdcbf9b85a3e0a30698c5ed128fd94365b553b Mon Sep 17 00:00:00 2001 From: Ikechi Date: Mon, 5 Sep 2022 21:03:06 +0100 Subject: [PATCH 68/69] =?UTF-8?q?=E2=9A=A1=EF=B8=8FComplete=20implementati?= =?UTF-8?q?on=20for=20inversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 13 +- components/Nav/SearchSidebar/SearchTable.jsx | 10 +- components/Wallet/PlaceOrder/Form.jsx | 20 ++- .../PlaceOrder/Form/AvailableBalance.jsx | 62 ++++---- .../Wallet/PlaceOrder/Form/TradeInputs.jsx | 132 +++++++++++++++++- 5 files changed, 189 insertions(+), 48 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index d25bdc0c7..282a32718 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -18,6 +18,7 @@ import { floatToFixedDynamic } from '@/services/display' // import convertFromAsaUnits from '@algodex/algodex-sdk/lib/utils/units/fromAsaUnits' // import floatToFixed from '@algodex/algodex-sdk/lib/utils/format/floatToFixed' import { isUndefined } from 'lodash/lang' +import { orderBy } from 'lodash' import { rgba } from 'polished' import styled from '@emotion/styled' import { useEventDispatch } from '@/hooks/useEvents' @@ -402,6 +403,14 @@ export function OrderBook({ asset, orders, components }) { return orders.sell.reduce(reduceOrders, []) }, [orders.sell, selectedPrecision]) + const sortedBuyOrder = useMemo(() => { + return aggregatedBuyOrder.sort((a, b) => b.price - a.price) + }, [aggregatedBuyOrder]) + + const sortedSellOrder = useMemo(() => { + return aggregatedSellOrder.sort((a, b) => a.price - b.price) + }, [aggregatedSellOrder]) + const renderOrders = (data, type) => { const color = type === 'buy' ? 'green' : 'red' return data.map((row, index) => { @@ -502,7 +511,7 @@ export function OrderBook({ asset, orders, components }) { - {renderOrders(asset.isStable ? aggregatedBuyOrder : aggregatedSellOrder, 'sell')} + {renderOrders(asset.isStable ? sortedBuyOrder : aggregatedSellOrder, 'sell')} @@ -512,7 +521,7 @@ export function OrderBook({ asset, orders, components }) { - {renderOrders(asset.isStable ? aggregatedSellOrder : aggregatedBuyOrder, 'buy')} + {renderOrders(asset.isStable ? sortedSellOrder : aggregatedBuyOrder, 'buy')} diff --git a/components/Nav/SearchSidebar/SearchTable.jsx b/components/Nav/SearchSidebar/SearchTable.jsx index 9d4375408..8cac88b8a 100644 --- a/components/Nav/SearchSidebar/SearchTable.jsx +++ b/components/Nav/SearchSidebar/SearchTable.jsx @@ -13,12 +13,12 @@ import { DelistedAssets } from '@/components/DelistedAssets' import Icon from '@mdi/react' import PropTypes from 'prop-types' import SearchFlyover from './SearchFlyover' +import { StableAssets } from '@/components/StableAssets' import Table from '@/components/Table' import Tooltip from 'components/Tooltip' import { flatten } from 'lodash' // import { floatToFixedDynamic } from '@/services/display' import floatToFixed from '@algodex/algodex-sdk/lib/utils/format/floatToFixed' - import { formatUSDPrice } from '@/components/helpers' import { sortBy } from 'lodash' import styled from '@emotion/styled' @@ -212,6 +212,10 @@ export const NavSearchTable = ({ }, [favoritesState] ) + const formattedStableAsa = {} + const formattedAssets = StableAssets.forEach( + (asa, index) => (formattedStableAsa[StableAssets[index]] = asa) + ) /** * Handle Search Data * @type {Array} @@ -285,7 +289,7 @@ export const NavSearchTable = ({ style={{ minWidth: '0.75rem' }} color={handleFavoritesFn(row?.original?.id)} /> - {row?.original.isStable && ( + {formattedStableAsa[row?.original.id] && ( ALGO {`/`} @@ -295,7 +299,7 @@ export const NavSearchTable = ({ )} - {!row?.original.isStable && ( + {!formattedStableAsa[row?.original.id] && ( {value} {`/`} diff --git a/components/Wallet/PlaceOrder/Form.jsx b/components/Wallet/PlaceOrder/Form.jsx index 546a8105a..56e603f2b 100644 --- a/components/Wallet/PlaceOrder/Form.jsx +++ b/components/Wallet/PlaceOrder/Form.jsx @@ -103,8 +103,14 @@ export function PlaceOrderForm({ showTitle = true, asset, onSubmit, components: const buttonProps = useMemo( () => ({ - buy: { variant: 'primary', text: `${t('buy')} ${asset.name || asset.id}` }, - sell: { variant: 'danger', text: `${t('sell')} ${asset.name || asset.id}` } + buy: { + variant: 'primary', + text: `${t('buy')} ${(asset.isStable ? 'ALGO' : asset.name) || asset.id}` + }, + sell: { + variant: 'danger', + text: `${t('sell')} ${(asset.isStable ? 'ALGO' : asset.name) || asset.id}` + } }), [asset] ) @@ -232,6 +238,8 @@ export function PlaceOrderForm({ showTitle = true, asset, onSubmit, components: (e) => { e.preventDefault() let orderPromise + const { isStable } = asset + const _order = { ...order, type: isStable && order.type === 'buy' ? 'sell' : 'buy' } if (typeof onSubmit === 'function') { orderPromise = onSubmit({ ...order, @@ -241,6 +249,7 @@ export function PlaceOrderForm({ showTitle = true, asset, onSubmit, components: } else { console.log( { + _order, ...order, address: wallet.address, wallet, @@ -250,9 +259,9 @@ export function PlaceOrderForm({ showTitle = true, asset, onSubmit, components: }, { wallet } ) - orderPromise = placeOrder( { + _order, ...order, address: wallet.address, wallet, @@ -277,7 +286,7 @@ export function PlaceOrderForm({ showTitle = true, asset, onSubmit, components: } }) }, - [onSubmit, asset, order] + [onSubmit, asset, asset, order] ) const handleMarketTabSwitching = (e, tabId) => { setTabSwitch(tabId) @@ -400,7 +409,8 @@ PlaceOrderForm.propTypes = { asset: PropTypes.shape({ id: PropTypes.number.isRequired, decimals: PropTypes.number.isRequired, - name: PropTypes.string + name: PropTypes.string, + isStable: PropTypes.bool }).isRequired, /** * Wallet to execute Orders from diff --git a/components/Wallet/PlaceOrder/Form/AvailableBalance.jsx b/components/Wallet/PlaceOrder/Form/AvailableBalance.jsx index 7b71e5124..ba5723fae 100644 --- a/components/Wallet/PlaceOrder/Form/AvailableBalance.jsx +++ b/components/Wallet/PlaceOrder/Form/AvailableBalance.jsx @@ -47,10 +47,9 @@ const IconButton = styled.button` } ` -const AsaBalance = ({ amount, asaName, type, decimal = 6 }) => { - // const _amount = amount - // const _price = price - // const _usdPrice = amount +const AsaBalance = ({ amount, asaName, type, decimal }) => { + const _amount = type === 'others' ? fromBaseUnits(amount, decimal) : fromBaseUnits(amount) + const _usdPrice = type === 'others' ? fromBaseUnits(amount, decimal) : fromBaseUnits(amount) return ( @@ -58,10 +57,10 @@ const AsaBalance = ({ amount, asaName, type, decimal = 6 }) => { - {fromBaseUnits(amount)} + {_amount} - + @@ -148,33 +147,27 @@ export const AvailableBalance = ({ wallet, asset }) => { - - - ALGO - - - - {fromBaseUnits(wallet.amount)} - - - - - - - - - {/* */} - {asset.name || asset.id} - - - - {fromBaseUnits(assetBalance, asset.decimals)} - - - - - - + {asset.isStable ? ( + <> + + + + ) : ( + <> + + + + )} ) } @@ -182,7 +175,8 @@ AvailableBalance.propTypes = { asset: PropTypes.shape({ id: PropTypes.number.isRequired, name: PropTypes.string, - decimals: PropTypes.number.isRequired + decimals: PropTypes.number.isRequired, + isStable: PropTypes.bool }), wallet: PropTypes.shape({ address: PropTypes.string, diff --git a/components/Wallet/PlaceOrder/Form/TradeInputs.jsx b/components/Wallet/PlaceOrder/Form/TradeInputs.jsx index 3a875363e..6149e6f73 100644 --- a/components/Wallet/PlaceOrder/Form/TradeInputs.jsx +++ b/components/Wallet/PlaceOrder/Form/TradeInputs.jsx @@ -36,6 +36,77 @@ USDInputPrice.propTypes = { id: PropTypes.string } +const OutlinedInputComp = ({ + microAlgo, + value, + id, + name, + assetName, + errorMsgVisible, + executionType, + handleChange, + fieldName +}) => { + const { t } = useTranslation('place-order') + return ( + <> + + {fieldName} + + } + endAdornment={ + + {assetName} + + } + error={errorMsgVisible} + /> + {errorMsgVisible && executionType !== 'market' ? ( + + Price cannot be less than {microAlgo} + + ) : ( + + )} + + ) +} + +OutlinedInputComp.propTypes = { + microAlgo: PropTypes.number, + value: PropTypes.string, + assetName: PropTypes.string, + errorMsgVisible: PropTypes.bool, + executionType: PropTypes.string, + handleChange: PropTypes.func, + name: PropTypes.string, + id: PropTypes.string, + fieldName: PropTypes.string +} + export const TradeInputs = ({ order, handleChange, @@ -96,7 +167,7 @@ export const TradeInputs = ({ }, [order, microAlgo]) return ( - ) : ( + )} */} + {asset.isStable ? ( + <> + + + + ) : ( + <> + + + )} - {asset.name} } - /> + /> */} - ALGO + + {asset.isStable ? asset.name : 'ALGO'} + } /> From e162586a23d210684771daf164462a7e0cd64f52 Mon Sep 17 00:00:00 2001 From: Ikechi Date: Tue, 6 Sep 2022 08:11:05 +0100 Subject: [PATCH 69/69] =?UTF-8?q?=F0=9F=90=9B=20Fix=20sorting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Asset/OrderBook/OrderBook.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/Asset/OrderBook/OrderBook.jsx b/components/Asset/OrderBook/OrderBook.jsx index 282a32718..c786f0fe6 100644 --- a/components/Asset/OrderBook/OrderBook.jsx +++ b/components/Asset/OrderBook/OrderBook.jsx @@ -18,7 +18,6 @@ import { floatToFixedDynamic } from '@/services/display' // import convertFromAsaUnits from '@algodex/algodex-sdk/lib/utils/units/fromAsaUnits' // import floatToFixed from '@algodex/algodex-sdk/lib/utils/format/floatToFixed' import { isUndefined } from 'lodash/lang' -import { orderBy } from 'lodash' import { rgba } from 'polished' import styled from '@emotion/styled' import { useEventDispatch } from '@/hooks/useEvents' @@ -408,7 +407,7 @@ export function OrderBook({ asset, orders, components }) { }, [aggregatedBuyOrder]) const sortedSellOrder = useMemo(() => { - return aggregatedSellOrder.sort((a, b) => a.price - b.price) + return aggregatedSellOrder.sort((a, b) => b.price - a.price) }, [aggregatedSellOrder]) const renderOrders = (data, type) => {