diff --git a/apps/trading-e2e/src/integration/market-info.cy.ts b/apps/trading-e2e/src/integration/market-info.cy.ts index 9ebd9445d..ea34519d1 100644 --- a/apps/trading-e2e/src/integration/market-info.cy.ts +++ b/apps/trading-e2e/src/integration/market-info.cy.ts @@ -1,4 +1,5 @@ import { MarketTradingModeMapping } from '@vegaprotocol/types'; +import { MarketState } from '@vegaprotocol/types'; const marketInfoBtn = 'Info'; const row = 'key-value-table-row'; @@ -12,7 +13,12 @@ describe('market info is displayed', { tags: '@smoke' }, () => { }); before(() => { - cy.mockTradingPage(); + cy.mockTradingPage( + MarketState.STATE_ACTIVE, + undefined, + undefined, + 'COMPROMISED' + ); cy.mockSubscription(); cy.visit('/#/markets/market-0'); cy.wait('@Markets'); @@ -20,6 +26,11 @@ describe('market info is displayed', { tags: '@smoke' }, () => { cy.wait('@MarketInfo'); }); + it('show oracle banner', () => { + cy.getByTestId(marketTitle).contains('Oracle').click(); + cy.getByTestId('oracle-status').should('contain.text', 'COMPROMISED'); + }); + it('current fees displayed', () => { cy.getByTestId(marketTitle).contains('Current fees').click(); validateMarketDataRow(0, 'Maker Fee', '0.02%'); diff --git a/apps/trading-e2e/src/support/trading.ts b/apps/trading-e2e/src/support/trading.ts index ccf1d9b63..8d8202d6d 100644 --- a/apps/trading-e2e/src/support/trading.ts +++ b/apps/trading-e2e/src/support/trading.ts @@ -1,6 +1,7 @@ import { aliasGQLQuery } from '@vegaprotocol/cypress'; import * as Schema from '@vegaprotocol/types'; import type { CyHttpMessages } from 'cypress/types/net-stubbing'; +import type { Provider, Status } from '@vegaprotocol/oracles'; import { accountsQuery, assetQuery, @@ -155,7 +156,6 @@ const mockTradingPage = ( aliasGQLQuery(req, 'ProposalsList', proposalListQuery()); aliasGQLQuery(req, 'Deposits', depositsQuery()); }; - declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { @@ -164,50 +164,56 @@ declare global { mockTradingPage( state?: Schema.MarketState, tradingMode?: Schema.MarketTradingMode, - trigger?: Schema.AuctionTrigger + trigger?: Schema.AuctionTrigger, + oracleStatus?: Status ): void; } } } + export const addMockTradingPage = () => { Cypress.Commands.add( 'mockTradingPage', - (state = Schema.MarketState.STATE_ACTIVE, tradingMode, trigger) => { + ( + state = Schema.MarketState.STATE_ACTIVE, + tradingMode, + trigger, + oracleStatus + ) => { cy.mockGQL((req) => { mockTradingPage(req, state, tradingMode, trigger); }); + const oracle: Provider = { + name: 'Another oracle', + url: 'https://zombo.com', + description_markdown: + 'Some markdown describing the oracle provider.\n\nTwitter: @FacesPics2\n', + oracle: { + status: oracleStatus || 'GOOD', + status_reason: '', + first_verified: '2022-01-01T00:00:00.000Z', + last_verified: '2022-12-31T00:00:00.000Z', + type: 'public_key', + public_key: ORACLE_PUBKEY, + }, + proofs: [ + { + format: 'signed_message', + available: true, + type: 'public_key', + public_key: ORACLE_PUBKEY, + message: 'SOMEHEX', + }, + ], + github_link: `https://github.com/vegaprotocol/well-known/blob/main/oracle-providers/public_key-${ORACLE_PUBKEY}.toml`, + }; // Prevent request to github, return some dummy content cy.intercept( 'GET', /^https:\/\/raw.githubusercontent.com\/vegaprotocol\/well-known/, { - body: [ - { - name: 'Another oracle', - url: 'https://zombo.com', - description_markdown: - 'Some markdown describing the oracle provider.\n\nTwitter: @FacesPics2\n', - oracle: { - status: 'GOOD', - status_reason: '', - first_verified: '2022-01-01T00:00:00.000Z', - last_verified: '2022-12-31T00:00:00.000Z', - type: 'public_key', - public_key: ORACLE_PUBKEY, - }, - proofs: [ - { - format: 'signed_message', - available: true, - type: 'public_key', - public_key: ORACLE_PUBKEY, - message: 'SOMEHEX', - }, - ], - github_link: `https://github.com/vegaprotocol/well-known/blob/main/oracle-providers/public_key-${ORACLE_PUBKEY}.toml`, - }, - ], + body: [oracle], } ); } diff --git a/apps/trading/client-pages/market/trade-grid.tsx b/apps/trading/client-pages/market/trade-grid.tsx index b6f326a8d..ef31ef630 100644 --- a/apps/trading/client-pages/market/trade-grid.tsx +++ b/apps/trading/client-pages/market/trade-grid.tsx @@ -350,7 +350,10 @@ export const TradePanels = ({ return (
- +
+ + +
{({ width, height }) => ( diff --git a/apps/trading/components/banner/oracle-banner.tsx b/apps/trading/components/banner/oracle-banner.tsx index 08a27e9ed..894651fec 100644 --- a/apps/trading/components/banner/oracle-banner.tsx +++ b/apps/trading/components/banner/oracle-banner.tsx @@ -26,7 +26,8 @@ export const OracleBanner = ({ marketId }: { marketId: string }) => { return (
- Oracle status for this market is {oracle.status}.{' '} + Oracle status for this market is{' '} + {oracle.status}.{' '} {oracleStatuses[oracle.status]}
{oracle.status_reason ? ( diff --git a/libs/market-info/src/hooks/use-market-oracle.ts b/libs/market-info/src/hooks/use-market-oracle.ts index 95930f60a..5ccbd5254 100644 --- a/libs/market-info/src/hooks/use-market-oracle.ts +++ b/libs/market-info/src/hooks/use-market-oracle.ts @@ -19,25 +19,29 @@ export const useMarketOracle = (marketId: string) => { marketInfo.tradableInstrument.instrument.product .dataSourceSpecForSettlementData.data; return data.find((provider) => - provider.proofs.some( - (proof) => - (proof.type === 'eth_address' && - dataSource.sourceType.__typename === - 'DataSourceDefinitionExternal' && - dataSource.sourceType.sourceType.signers?.some( - (signer) => - signer.signer.__typename === 'ETHAddress' && - signer.signer.address === proof.eth_address - )) || - (proof.type === 'public_key' && - dataSource.sourceType.__typename === - 'DataSourceDefinitionExternal' && - dataSource.sourceType.sourceType.signers?.some( - (signer) => - signer.signer.__typename === 'PubKey' && - signer.signer.key === proof.public_key - )) - ) + provider.proofs.some((proof) => { + if ( + proof.type === 'eth_address' && + dataSource.sourceType.__typename === 'DataSourceDefinitionExternal' + ) { + return dataSource.sourceType.sourceType.signers?.some( + (signer) => + signer.signer.__typename === 'ETHAddress' && + signer.signer.address === proof.eth_address + ); + } + if ( + proof.type === 'public_key' && + dataSource.sourceType.__typename === 'DataSourceDefinitionExternal' + ) { + return dataSource.sourceType.sourceType.signers?.some( + (signer) => + signer.signer.__typename === 'PubKey' && + signer.signer.key === proof.public_key + ); + } + return false; + }) )?.oracle; }, [data, marketInfo]); };