From 66f55855ae1efd1aacc376d25f708b64f732b8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Fri, 17 Nov 2023 20:54:17 +0100 Subject: [PATCH] feat(liquidity): use i18next (#5247) --- libs/i18n/src/locales/en/liquidity.json | 41 ++++++++++++++++++++++ libs/liquidity/__mocks__/react-i18next.ts | 14 ++++++++ libs/liquidity/src/lib/liquidity-table.tsx | 25 ++++++------- libs/liquidity/src/lib/use-t.jsx | 3 ++ 4 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 libs/i18n/src/locales/en/liquidity.json create mode 100644 libs/liquidity/__mocks__/react-i18next.ts create mode 100644 libs/liquidity/src/lib/use-t.jsx diff --git a/libs/i18n/src/locales/en/liquidity.json b/libs/i18n/src/locales/en/liquidity.json new file mode 100644 index 000000000..dfd79fa2f --- /dev/null +++ b/libs/i18n/src/locales/en/liquidity.json @@ -0,0 +1,41 @@ +{ + "Adjusted stake share": "Adjusted stake share", + "Commitment ({{symbol}})": "Commitment ({{symbol}})", + "Commitment details": "Commitment details", + "Created": "Created", + "Current epoch fraction of time on the book.": "Current epoch fraction of time on the book.", + "Fee": "Fee", + "Fees accrued this epoch": "Fees accrued this epoch", + "Last bond penalty": "Last bond penalty", + "Last epoch bond penalty.": "Last epoch bond penalty.", + "Last epoch fee penalty.": "Last epoch fee penalty.", + "Last epoch fraction of time on the book.": "Last epoch fraction of time on the book.", + "Last epoch SLA details": "Last epoch SLA details", + "Last fee penalty": "Last fee penalty", + "Last time on the book": "Last time on the book", + "Live liquidity data": "Live liquidity data", + "Live liquidity quality score (%)": "Live liquidity quality score (%)", + "Live supplied liquidity": "Live supplied liquidity", + "Live time on book": "Live time on book", + "No liquidity provisions": "No liquidity provisions", + "Obligation": "Obligation", + "Party": "Party", + "Share": "Share", + "Status": "Status", + "The amount committed to the market by this liquidity provider.": "The amount committed to the market by this liquidity provider.", + "The amount of liquidity volume supplied by the LP order in order to meet the obligation. If the obligation is already met in full by other limit orders from the same Vega key the LP order is not required and this value will be zero. Also note if the target stake for the market is less than the obligation the full value of the obligation may not be required.": "The amount of liquidity volume supplied by the LP order in order to meet the obligation. If the obligation is already met in full by other limit orders from the same Vega key the LP order is not required and this value will be zero. Also note if the target stake for the market is less than the obligation the full value of the obligation may not be required.", + "The average score of the liquidity provider.": "The average score of the liquidity provider.", + "The current status of this liquidity provision.": "The current status of this liquidity provision.", + "The date and time this liquidity provision was created.": "The date and time this liquidity provision was created.", + "The date and time this liquidity provision was last updated.": "The date and time this liquidity provision was last updated.", + "The equity-like share of liquidity of the market used to determine allocation of LP fees. Calculated based on share of total liquidity, with a premium added for length of commitment.": "The equity-like share of liquidity of the market used to determine allocation of LP fees. Calculated based on share of total liquidity, with a premium added for length of commitment.", + "The fee percentage (per trade) proposed by each liquidity provider.": "The fee percentage (per trade) proposed by each liquidity provider.", + "The liquidity fees accrued by each provider, which will be distributed at the end of the epoch after applying any penalties.": "The liquidity fees accrued by each provider, which will be distributed at the end of the epoch after applying any penalties.", + "The liquidity provider's obligation to the market, calculated as the liquidity commitment amount multiplied by the value of the stake_to_ccy_volume network parameter to convert into units of liquidity volume.": "The liquidity provider's obligation to the market, calculated as the liquidity commitment amount multiplied by the value of the stake_to_ccy_volume network parameter to convert into units of liquidity volume.", + "The public key of the party making this commitment.": "The public key of the party making this commitment.", + "The virtual stake of the liquidity provider.": "The virtual stake of the liquidity provider.", + "This LP's time on the book in the current epoch ({{currentEpoch}}) is less than 100%, so they could lose some fees to a better performing LP.": "This LP's time on the book in the current epoch ({{currentEpoch}}) is less than 100%, so they could lose some fees to a better performing LP.", + "This LP's time on the book in the current epoch ({{currentEpoch}}) is less than the minimum required ({{minimumRequired}}), so they could lose all fee revenue for this epoch.": "This LP's time on the book in the current epoch ({{currentEpoch}}) is less than the minimum required ({{minimumRequired}}), so they could lose all fee revenue for this epoch.", + "Updated": "Updated", + "Updating next epoch": "Updating next epoch" +} diff --git a/libs/liquidity/__mocks__/react-i18next.ts b/libs/liquidity/__mocks__/react-i18next.ts new file mode 100644 index 000000000..7c2343f52 --- /dev/null +++ b/libs/liquidity/__mocks__/react-i18next.ts @@ -0,0 +1,14 @@ +export const useTranslation = () => ({ + t: (label: string, replacements?: Record) => { + let translatedLabel = label; + if (typeof replacements === 'object' && replacements !== null) { + Object.keys(replacements).forEach((key) => { + translatedLabel = translatedLabel.replace( + `{{${key}}}`, + replacements[key] + ); + }); + } + return translatedLabel; + }, +}); diff --git a/libs/liquidity/src/lib/liquidity-table.tsx b/libs/liquidity/src/lib/liquidity-table.tsx index ded9057d0..2558cbce4 100644 --- a/libs/liquidity/src/lib/liquidity-table.tsx +++ b/libs/liquidity/src/lib/liquidity-table.tsx @@ -4,7 +4,6 @@ import { addDecimalsFormatNumberQuantum, getDateTimeFormat, } from '@vegaprotocol/utils'; -import { t } from '@vegaprotocol/i18n'; import type { TypedDataAgGrid, VegaICellRendererParams, @@ -27,6 +26,7 @@ import BigNumber from 'bignumber.js'; import { LiquidityProvisionStatus } from '@vegaprotocol/types'; import { LiquidityProvisionStatusMapping } from '@vegaprotocol/types'; import type { LiquidityProvisionData } from './liquidity-data-provider'; +import { useT } from './use-t'; const formatNumberPercentage = (value: BigNumber, decimals?: number) => { const decimalPlaces = @@ -81,6 +81,7 @@ export const LiquidityTable = ({ quantum, ...props }: LiquidityTableProps) => { + const t = useT(); const colDefs = useMemo(() => { const assetDecimalsFormatter = ({ value }: ITooltipParams) => { if (!value) return '-'; @@ -125,32 +126,32 @@ export const LiquidityTable = ({ } if (lessThanMinimum) { return t( - `This LP's time on the book in the current epoch (%s) is less than the minimum required (%s), so they could lose all fee revenue for this epoch.`, - [ - formatNumberPercentage( + "This LP's time on the book in the current epoch ({{currentEpoch}}) is less than the minimum required ({{minimumRequired}}), so they could lose all fee revenue for this epoch.", + { + currentEpoch: formatNumberPercentage( new BigNumber(data.sla.currentEpochFractionOfTimeOnBook).times( 100 ), 4 ), - formatNumberPercentage( + minimumRequired: formatNumberPercentage( new BigNumber(data.commitmentMinTimeFraction).times(100), 4 ), - ] + } ); } if (lessThanFull) { return t( - `This LP's time on the book in the current epoch (%s) is less than 100%, so they could lose some fees to a better performing LP.`, - [ - formatNumberPercentage( + "This LP's time on the book in the current epoch ({{currentEpoch}}) is less than 100%, so they could lose some fees to a better performing LP.", + { + currentEpoch: formatNumberPercentage( new BigNumber(data.sla.currentEpochFractionOfTimeOnBook).times( 100 ), 4 ), - ] + } ); } return addDecimalsFormatNumber(newValue, assetDecimalPlaces ?? 0); @@ -219,7 +220,7 @@ export const LiquidityTable = ({ }, }, { - headerName: t(`Commitment (${symbol})`), + headerName: t(`Commitment ({{symbol}})`, { symbol }), field: 'commitmentAmount', type: 'rightAligned', headerTooltip: t( @@ -495,7 +496,7 @@ export const LiquidityTable = ({ }, ]; return defs; - }, [assetDecimalPlaces, quantum, stakeToCcyVolume, symbol]); + }, [assetDecimalPlaces, quantum, stakeToCcyVolume, symbol, t]); return ( useTranslation('liquidity').t;