feat(market-depth): use i18next (#5267)
This commit is contained in:
parent
48e4ab53a1
commit
19b95832c4
5
libs/i18n/src/locales/en/market-depth.json
Normal file
5
libs/i18n/src/locales/en/market-depth.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"Last traded price": "Last traded price",
|
||||
"No open orders": "No open orders",
|
||||
"Spread": "Spread"
|
||||
}
|
15
libs/market-depth/__mocks__/react-i18next.ts
Normal file
15
libs/market-depth/__mocks__/react-i18next.ts
Normal file
@ -0,0 +1,15 @@
|
||||
export const useTranslation = () => ({
|
||||
t: (label: string, replacements?: Record<string, string>) => {
|
||||
const replace =
|
||||
replacements?.replace && typeof replacements === 'object'
|
||||
? replacements?.replace
|
||||
: replacements;
|
||||
let translatedLabel = replacements?.defaultValue || label;
|
||||
if (typeof replace === 'object' && replace !== null) {
|
||||
Object.keys(replace).forEach((key) => {
|
||||
translatedLabel = translatedLabel.replace(`{{${key}}}`, replace[key]);
|
||||
});
|
||||
}
|
||||
return translatedLabel;
|
||||
},
|
||||
});
|
@ -2,7 +2,6 @@ import { DepthChart } from 'pennant';
|
||||
import throttle from 'lodash/throttle';
|
||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||
import { addDecimal, getNumberFormat } from '@vegaprotocol/utils';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { useThemeSwitcher } from '@vegaprotocol/react-helpers';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { marketDepthProvider } from './market-depth-provider';
|
||||
@ -16,6 +15,7 @@ import {
|
||||
} from './__generated__/MarketDepth';
|
||||
import { type DepthChartProps } from 'pennant';
|
||||
import { parseLevel, updateLevels } from './depth-chart-utils';
|
||||
import { useT } from './use-t';
|
||||
|
||||
interface DepthChartManagerProps {
|
||||
marketId: string;
|
||||
@ -39,6 +39,7 @@ const getMidPrice = (
|
||||
type DepthData = Pick<DepthChartProps, 'data' | 'midPrice'>;
|
||||
|
||||
export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
|
||||
const t = useT();
|
||||
const { theme } = useThemeSwitcher();
|
||||
const variables = useMemo(() => ({ marketId }), [marketId]);
|
||||
const [depthData, setDepthData] = useState<DepthData | null>(null);
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { useMemo, useRef, useState } from 'react';
|
||||
import ReactVirtualizedAutoSizer from 'react-virtualized-auto-sizer';
|
||||
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { usePrevious } from '@vegaprotocol/react-helpers';
|
||||
import { OrderbookRow } from './orderbook-row';
|
||||
import type { OrderbookRowData } from './orderbook-data';
|
||||
@ -10,6 +9,7 @@ import { Splash, VegaIcon, VegaIconNames } from '@vegaprotocol/ui-toolkit';
|
||||
import classNames from 'classnames';
|
||||
import type { PriceLevelFieldsFragment } from './__generated__/MarketDepth';
|
||||
import { OrderbookControls } from './orderbook-controls';
|
||||
import { useT } from './use-t';
|
||||
|
||||
// Sets row height, will be used to calculate number of rows that can be
|
||||
// displayed each side of the book without overflow
|
||||
@ -85,6 +85,7 @@ export const OrderbookMid = ({
|
||||
bestAskPrice: string;
|
||||
bestBidPrice: string;
|
||||
}) => {
|
||||
const t = useT();
|
||||
const previousLastTradedPrice = usePrevious(lastTradedPrice);
|
||||
const priceChangeRef = useRef<'up' | 'down' | 'none'>('none');
|
||||
const spread = (BigInt(bestAskPrice) - BigInt(bestBidPrice)).toString();
|
||||
@ -153,6 +154,7 @@ export const Orderbook = ({
|
||||
bids,
|
||||
assetSymbol,
|
||||
}: OrderbookProps) => {
|
||||
const t = useT();
|
||||
const [resolution, setResolution] = useState(1);
|
||||
|
||||
const groupedAsks = useMemo(() => {
|
||||
|
3
libs/market-depth/src/lib/use-t.jsx
Normal file
3
libs/market-depth/src/lib/use-t.jsx
Normal file
@ -0,0 +1,3 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export const useT = () => useTranslation('market-depth').t;
|
Loading…
Reference in New Issue
Block a user