From 094b3f5d9e2541a193962949eb5050f20f4affec Mon Sep 17 00:00:00 2001 From: saml33 Date: Mon, 25 Sep 2023 10:17:19 +1000 Subject: [PATCH] fix market select search --- components/trade/MarketSelectDropdown.tsx | 194 +++++++++++----------- public/locales/en/trade.json | 1 + public/locales/es/trade.json | 1 + public/locales/ru/trade.json | 1 + public/locales/zh/trade.json | 1 + public/locales/zh_tw/trade.json | 1 + 6 files changed, 105 insertions(+), 94 deletions(-) diff --git a/components/trade/MarketSelectDropdown.tsx b/components/trade/MarketSelectDropdown.tsx index 322b5131..f642d62f 100644 --- a/components/trade/MarketSelectDropdown.tsx +++ b/components/trade/MarketSelectDropdown.tsx @@ -67,7 +67,7 @@ const startSearch = ( } const MarketSelectDropdown = () => { - const { t } = useTranslation('common') + const { t } = useTranslation(['common', 'trade']) const { selectedMarket } = useSelectedMarket() const [spotOrPerp, setSpotOrPerp] = useState( selectedMarket instanceof PerpMarket ? 'perp' : 'spot', @@ -307,7 +307,7 @@ const MarketSelectDropdown = () => { })} ) : null} - {spotOrPerp === 'spot' && serumMarketsToShow.length ? ( + {spotOrPerp === 'spot' ? ( <>
@@ -372,104 +372,110 @@ const MarketSelectDropdown = () => { />

- {serumMarketsToShow.map((m) => { - const baseBank = group?.getFirstBankByTokenIndex( - m.baseTokenIndex, - ) - const quoteBank = group?.getFirstBankByTokenIndex( - m.quoteTokenIndex, - ) - const market = group?.getSerum3ExternalMarket( - m.serumMarketExternal, - ) - let leverage - if (group) { - leverage = m.maxBidLeverage(group) - } - let price - if (baseBank && market && quoteBank) { - price = floorToDecimal( - baseBank.uiPrice / quoteBank.uiPrice, - getDecimalCount(market.tickSize), - ).toNumber() - } + {serumMarketsToShow.length ? ( + serumMarketsToShow.map((m) => { + const baseBank = group?.getFirstBankByTokenIndex( + m.baseTokenIndex, + ) + const quoteBank = group?.getFirstBankByTokenIndex( + m.quoteTokenIndex, + ) + const market = group?.getSerum3ExternalMarket( + m.serumMarketExternal, + ) + let leverage + if (group) { + leverage = m.maxBidLeverage(group) + } + let price + if (baseBank && market && quoteBank) { + price = floorToDecimal( + baseBank.uiPrice / quoteBank.uiPrice, + getDecimalCount(market.tickSize), + ).toNumber() + } - const volumeData = m?.marketData?.quote_volume_24h + const volumeData = m?.marketData?.quote_volume_24h - const volume = volumeData ? volumeData : 0 + const volume = volumeData ? volumeData : 0 - return ( -
- { - close() - setSearch('') - }} - shallow={true} - > -
-
- + return ( +
+ { + close() + setSearch('') + }} + shallow={true} + > +
+
+ +
+ + {m.name} + + {leverage ? ( + + ) : null}
- - {m.name} - - {leverage ? ( - - ) : null} +
+ {price && market?.tickSize ? ( + + {quoteBank?.name === 'USDC' ? '$' : ''} + {getDecimalCount(market.tickSize) <= 6 + ? formatNumericValue( + price, + getDecimalCount(market.tickSize), + ) + : price.toExponential(3)} + {quoteBank?.name !== 'USDC' ? ( + + {' '} + {quoteBank?.name} + + ) : null} + + ) : null} +
+
+ +
+
+ {loadingMarketData ? ( + +
+ + ) : ( + + {quoteBank?.name === 'USDC' ? '$' : ''} + {volume ? numberCompacter.format(volume) : 0} + {quoteBank?.name !== 'USDC' ? ( + + {' '} + {quoteBank?.name} + + ) : null} + + )} +
+ +
+
-
- {price && market?.tickSize ? ( - - {quoteBank?.name === 'USDC' ? '$' : ''} - {getDecimalCount(market.tickSize) <= 6 - ? formatNumericValue( - price, - getDecimalCount(market.tickSize), - ) - : price.toExponential(3)} - {quoteBank?.name !== 'USDC' ? ( - - {' '} - {quoteBank?.name} - - ) : null} - - ) : null} -
-
- -
-
- {loadingMarketData ? ( - -
- - ) : ( - - {quoteBank?.name === 'USDC' ? '$' : ''} - {volume ? numberCompacter.format(volume) : 0} - {quoteBank?.name !== 'USDC' ? ( - - {' '} - {quoteBank?.name} - - ) : null} - - )} -
- -
-
-
- ) - })} + ) + }) + ) : ( +

+ {t('trade:no-markets-found')} +

+ )} ) : null}
diff --git a/public/locales/en/trade.json b/public/locales/en/trade.json index b0838600..f6025a9a 100644 --- a/public/locales/en/trade.json +++ b/public/locales/en/trade.json @@ -53,6 +53,7 @@ "min-order-size-error": "Min order size is {{minSize}} {{symbol}}", "more-details": "More Details", "no-balances": "No balances", + "no-markets-found": "No markets found...", "no-orders": "No open orders", "no-positions": "No perp positions", "no-unsettled": "No unsettled funds", diff --git a/public/locales/es/trade.json b/public/locales/es/trade.json index 13690f8b..deec2828 100644 --- a/public/locales/es/trade.json +++ b/public/locales/es/trade.json @@ -53,6 +53,7 @@ "min-order-size-error": "Min order size is {{minSize}} {{symbol}}", "more-details": "More Details", "no-balances": "No balances", + "no-markets-found": "No markets found...", "no-orders": "No open orders", "no-positions": "No perp positions", "no-unsettled": "No unsettled funds", diff --git a/public/locales/ru/trade.json b/public/locales/ru/trade.json index 13690f8b..deec2828 100644 --- a/public/locales/ru/trade.json +++ b/public/locales/ru/trade.json @@ -53,6 +53,7 @@ "min-order-size-error": "Min order size is {{minSize}} {{symbol}}", "more-details": "More Details", "no-balances": "No balances", + "no-markets-found": "No markets found...", "no-orders": "No open orders", "no-positions": "No perp positions", "no-unsettled": "No unsettled funds", diff --git a/public/locales/zh/trade.json b/public/locales/zh/trade.json index dc700801..47bdcf3f 100644 --- a/public/locales/zh/trade.json +++ b/public/locales/zh/trade.json @@ -53,6 +53,7 @@ "min-order-size-error": "订单的最小数量是 {{minSize}} {{symbol}}", "more-details": "看细节", "no-balances": "无余额", + "no-markets-found": "No markets found...", "no-orders": "无订单", "no-positions": "无持仓", "no-unsettled": "无未结清余额", diff --git a/public/locales/zh_tw/trade.json b/public/locales/zh_tw/trade.json index 481c7608..856d3aa7 100644 --- a/public/locales/zh_tw/trade.json +++ b/public/locales/zh_tw/trade.json @@ -53,6 +53,7 @@ "min-order-size-error": "訂單的最小數量是 {{minSize}} {{symbol}}", "more-details": "看細節", "no-balances": "無餘額", + "no-markets-found": "No markets found...", "no-orders": "無訂單", "no-positions": "無持倉", "no-unsettled": "無未結清餘額",