vega-frontend-monorepo/apps/trading/client-pages/markets/settlement-price-cell.tsx
Bartłomiej Głownia f377e07996
feat(trading): use i18next (#5238)
Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
2023-11-15 19:10:39 -08:00

60 lines
1.6 KiB
TypeScript

import { DApp, EXPLORER_ORACLE, useLinks } from '@vegaprotocol/environment';
import type { DataSourceFilterFragment } from '@vegaprotocol/markets';
import { useOracleSpecBindingData } from '@vegaprotocol/markets';
import { PropertyKeyType } from '@vegaprotocol/types';
import { Link } from '@vegaprotocol/ui-toolkit';
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
import { useT } from '../../lib/use-t';
export interface SettlementPriceCellProps {
oracleSpecId: string | undefined;
settlementDataSpecBinding: string | undefined;
filter: DataSourceFilterFragment | undefined;
}
export const SettlementPriceCell = ({
oracleSpecId,
settlementDataSpecBinding,
filter,
}: SettlementPriceCellProps) => {
const t = useT();
const linkCreator = useLinks(DApp.Explorer);
const { property, loading } = useOracleSpecBindingData(
oracleSpecId,
settlementDataSpecBinding
);
if (!oracleSpecId || loading) {
return <span>-</span>;
}
const renderText = () => {
if (!property || !filter) {
return t('Unknown');
}
if (
filter.key.type === PropertyKeyType.TYPE_INTEGER &&
filter.key.numberDecimalPlaces !== null &&
filter.key.numberDecimalPlaces !== undefined
) {
return addDecimalsFormatNumber(
property.value,
filter.key.numberDecimalPlaces
);
}
return property.value;
};
return (
<Link
href={linkCreator(EXPLORER_ORACLE.replace(':id', oracleSpecId))}
className="underline font-mono"
target="_blank"
>
{renderText()}
</Link>
);
};