2023-05-02 17:41:21 +00:00
|
|
|
import { DApp, EXPLORER_ORACLE, useLinks } from '@vegaprotocol/environment';
|
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2023-05-19 20:29:24 +00:00
|
|
|
import type { DataSourceFilterFragment } from '@vegaprotocol/markets';
|
2023-05-18 11:22:54 +00:00
|
|
|
import { useOracleSpecBindingData } from '@vegaprotocol/markets';
|
2023-05-19 20:29:24 +00:00
|
|
|
import { PropertyKeyType } from '@vegaprotocol/types';
|
2023-05-02 17:41:21 +00:00
|
|
|
import { Link } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
|
|
|
|
|
|
|
export interface SettlementPriceCellProps {
|
|
|
|
oracleSpecId: string | undefined;
|
|
|
|
settlementDataSpecBinding: string | undefined;
|
2023-05-19 20:29:24 +00:00
|
|
|
filter: DataSourceFilterFragment | undefined;
|
2023-05-02 17:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const SettlementPriceCell = ({
|
|
|
|
oracleSpecId,
|
|
|
|
settlementDataSpecBinding,
|
2023-05-19 20:29:24 +00:00
|
|
|
filter,
|
2023-05-02 17:41:21 +00:00
|
|
|
}: SettlementPriceCellProps) => {
|
|
|
|
const linkCreator = useLinks(DApp.Explorer);
|
|
|
|
const { property, loading } = useOracleSpecBindingData(
|
|
|
|
oracleSpecId,
|
|
|
|
settlementDataSpecBinding
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!oracleSpecId || loading) {
|
|
|
|
return <span>-</span>;
|
|
|
|
}
|
|
|
|
|
2023-05-19 20:29:24 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2023-05-02 17:41:21 +00:00
|
|
|
return (
|
|
|
|
<Link
|
|
|
|
href={linkCreator(EXPLORER_ORACLE.replace(':id', oracleSpecId))}
|
|
|
|
className="underline font-mono"
|
|
|
|
target="_blank"
|
|
|
|
>
|
2023-05-19 20:29:24 +00:00
|
|
|
{renderText()}
|
2023-05-02 17:41:21 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
};
|