From 1a274a67c3c9986b80e63e329ba1ee7693c0787f Mon Sep 17 00:00:00 2001 From: "m.ray" <16125548+MadalinaRaicu@users.noreply.github.com> Date: Tue, 16 May 2023 16:12:22 +0300 Subject: [PATCH] feat(trading): oracle banner check termination and settlement data oracles (#3707) --- .../src/integration/market-info.cy.ts | 1 - .../oracle-banner/oracle-banner.tsx | 26 ++++++++-- .../oracle-full-profile.tsx | 47 +++++++++++++++++-- .../src/lib/hooks/use-market-oracle.ts | 12 +++-- 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/apps/trading-e2e/src/integration/market-info.cy.ts b/apps/trading-e2e/src/integration/market-info.cy.ts index 65b344833..e9dd4bfb1 100644 --- a/apps/trading-e2e/src/integration/market-info.cy.ts +++ b/apps/trading-e2e/src/integration/market-info.cy.ts @@ -199,7 +199,6 @@ describe('market info is displayed', { tags: '@smoke' }, () => { .within(() => { cy.getByTestId('block-explorer-link').contains('Block explorer'); cy.getByTestId('github-link').contains('Oracle repository'); - cy.getByTestId('verified-accounts').contains('0 proofs of ownership'); }); cy.getByTestId('dialog-close').click(); diff --git a/libs/market-info/src/lib/components/oracle-banner/oracle-banner.tsx b/libs/market-info/src/lib/components/oracle-banner/oracle-banner.tsx index 162047597..71eabcaf0 100644 --- a/libs/market-info/src/lib/components/oracle-banner/oracle-banner.tsx +++ b/libs/market-info/src/lib/components/oracle-banner/oracle-banner.tsx @@ -25,14 +25,30 @@ export const oracleStatuses = { export const OracleBanner = ({ marketId }: { marketId: string }) => { const [open, onChange] = useState(false); - const oracle = useMarketOracle(marketId); - if (!oracle || oracle.provider.oracle.status === 'GOOD') { - return null; + const settlementOracle = useMarketOracle(marketId); + const tradingTerminationOracle = useMarketOracle( + marketId, + 'dataSourceSpecForTradingTermination' + ); + let maliciousOracle = null; + if (settlementOracle?.provider.oracle.status !== 'GOOD') { + maliciousOracle = settlementOracle; + } else if (tradingTerminationOracle?.provider.oracle.status !== 'GOOD') { + maliciousOracle = tradingTerminationOracle; } - const { provider } = oracle; + if (!settlementOracle && !tradingTerminationOracle) { + return ( + +
{t('There is no oracle for this market yet.')}
+
+ ); + } + if (!maliciousOracle) return null; + + const { provider } = maliciousOracle; return ( <> - +
Oracle status for this market is{' '} diff --git a/libs/market-info/src/lib/components/oracle-full-profile/oracle-full-profile.tsx b/libs/market-info/src/lib/components/oracle-full-profile/oracle-full-profile.tsx index d480790e3..8800d5864 100644 --- a/libs/market-info/src/lib/components/oracle-full-profile/oracle-full-profile.tsx +++ b/libs/market-info/src/lib/components/oracle-full-profile/oracle-full-profile.tsx @@ -2,6 +2,7 @@ import { t } from '@vegaprotocol/i18n'; import type { Provider } from '../../oracle-schema'; import { MarketState, MarketStateMapping } from '@vegaprotocol/types'; import { + ButtonLink, ExternalLink, Icon, Intent, @@ -15,6 +16,7 @@ import { getLinkIcon, getVerifiedStatusIcon } from '../oracle-basic-profile'; import { useEnvironment } from '@vegaprotocol/environment'; import type { OracleMarketSpecFieldsFragment } from '../../__generated__/OracleMarketsSpec'; import ReactMarkdown from 'react-markdown'; +import { useState } from 'react'; export const OracleProfileTitle = ({ provider }: { provider: Provider }) => { const { icon, intent } = getVerifiedStatusIcon(provider); @@ -78,6 +80,7 @@ export const OracleFullProfile = ({ }) => { const { message } = getVerifiedStatusIcon(provider); const { VEGA_EXPLORER_URL } = useEnvironment(); + const [showMore, setShowMore] = useState(false); const links = provider.proofs .filter((proof) => proof.format === 'url' && proof.available === true) @@ -86,6 +89,9 @@ export const OracleFullProfile = ({ url: 'url' in proof ? proof.url : '', icon: getLinkIcon(proof.type), })); + const signedMessageProofs = provider.proofs.filter( + (proof) => proof.format === 'signed_message' && proof.available === true + ); return (
@@ -103,8 +109,15 @@ export const OracleFullProfile = ({ disallowedElements={['img']} linkTarget="_blank" > - {provider.description_markdown} + {showMore + ? provider.description_markdown + : provider.description_markdown.slice(0, 100) + '...'} + + setShowMore(!showMore)}> + {!showMore ? t('Read more') : t('Show less')} + +
@@ -113,9 +126,12 @@ export const OracleFullProfile = ({ className="dark:text-vega-light-300 text-vega-dark-300 uppercase" data-testid="verified-accounts" > - {t('%s proofs of ownership', links.length.toString())} + {t('%s %s of ownership', [ + provider.proofs.length.toString(), + provider.proofs.length === 1 ? 'proof' : 'proofs', + ])}

- {links.length > 0 ? ( + {provider.proofs.length > 0 ? (
{links.map((link) => ( ))} + {signedMessageProofs.length > 0 && ( + + {links.length > 0 ? ( + + {t('And %s more %s', [ + signedMessageProofs.length.toString(), + signedMessageProofs.length === 1 ? 'proof' : 'proofs', + ])}{' '} + + + ) : ( + + {t('Verify %s %s of ownership', [ + signedMessageProofs.length.toString(), + signedMessageProofs.length === 1 ? 'proof' : 'proofs', + ])}{' '} + + + )} + + )}
) : (

diff --git a/libs/market-info/src/lib/hooks/use-market-oracle.ts b/libs/market-info/src/lib/hooks/use-market-oracle.ts index efb0d72a6..05418f7d1 100644 --- a/libs/market-info/src/lib/hooks/use-market-oracle.ts +++ b/libs/market-info/src/lib/hooks/use-market-oracle.ts @@ -4,7 +4,12 @@ import { useDataProvider } from '@vegaprotocol/data-provider'; import { marketInfoProvider } from '../components/market-info/market-info-data-provider'; import { useMemo } from 'react'; -export const useMarketOracle = (marketId: string) => { +export const useMarketOracle = ( + marketId: string, + dataSourceSpecKey: + | 'dataSourceSpecForSettlementData' + | 'dataSourceSpecForTradingTermination' = 'dataSourceSpecForSettlementData' +) => { const { ORACLE_PROOFS_URL } = useEnvironment(); const { data: marketInfo } = useDataProvider({ dataProvider: marketInfoProvider, @@ -16,8 +21,7 @@ export const useMarketOracle = (marketId: string) => { return undefined; } const dataSourceSpec = - marketInfo.tradableInstrument.instrument.product - .dataSourceSpecForSettlementData; + marketInfo.tradableInstrument.instrument.product[dataSourceSpecKey]; const { data: dataSource, id: dataSourceSpecId } = dataSourceSpec; const provider = data.find((provider) => provider.proofs.some((proof) => { @@ -48,5 +52,5 @@ export const useMarketOracle = (marketId: string) => { return { provider, dataSourceSpecId }; } return undefined; - }, [data, marketInfo]); + }, [data, dataSourceSpecKey, marketInfo]); };