Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64bf2b3b52 | ||
|
|
28f9e169e7 | ||
|
|
162b167860 |
@@ -38,7 +38,7 @@
|
||||
"tranche_end": "2023-06-11T00:00:00.000Z",
|
||||
"total_added": "15949",
|
||||
"total_removed": "215.8495183664",
|
||||
"locked_amount": "12086.6850242682186761",
|
||||
"locked_amount": "11959.0406231332146841",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "11447",
|
||||
@@ -329,7 +329,7 @@
|
||||
"tranche_end": "2023-05-20T00:00:00.000Z",
|
||||
"total_added": "20967.125",
|
||||
"total_removed": "4313.169927159795",
|
||||
"locked_amount": "1043.349054639274308255",
|
||||
"locked_amount": "869.949636622298931016875",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "897",
|
||||
@@ -2501,7 +2501,7 @@
|
||||
"tranche_start": "2023-03-06T00:00:00.000Z",
|
||||
"tranche_end": "2023-04-06T00:00:00.000Z",
|
||||
"total_added": "14099",
|
||||
"total_removed": "4403.49002352036",
|
||||
"total_removed": "5107.49002352036",
|
||||
"locked_amount": "0",
|
||||
"deposits": [
|
||||
{
|
||||
@@ -3286,6 +3286,11 @@
|
||||
"user": "0xd8489848Ee545DB18859B3e03dE01aD99a22a807",
|
||||
"tx": "0xf8f66ba448c7711852effc4782d944f50061c1b077c9e9e6dfbc93a0ec45c297"
|
||||
},
|
||||
{
|
||||
"amount": "704",
|
||||
"user": "0x0b5739816AB0097C43F77479048a0A6093DD0441",
|
||||
"tx": "0x0ed882c629ec1b0154e769f86e3ecd9f4680de6d3bcec67556225eaaaa1bddf2"
|
||||
},
|
||||
{
|
||||
"amount": "30",
|
||||
"user": "0xBe9F912Ad481C61B653463E8F1D2b2b310D49861",
|
||||
@@ -4021,10 +4026,17 @@
|
||||
"tx": "0x46d80a145d2f49ef3152cbfaa6d2bb054deabe21396ab43553a3f076e2db62e1"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"withdrawals": [
|
||||
{
|
||||
"amount": "704",
|
||||
"user": "0x0b5739816AB0097C43F77479048a0A6093DD0441",
|
||||
"tranche_id": 53,
|
||||
"tx": "0x0ed882c629ec1b0154e769f86e3ecd9f4680de6d3bcec67556225eaaaa1bddf2"
|
||||
}
|
||||
],
|
||||
"total_tokens": "704",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "704"
|
||||
"withdrawn_tokens": "704",
|
||||
"remaining_tokens": "0"
|
||||
},
|
||||
{
|
||||
"address": "0x981D29D939cAa4ADC04A5e44224dBB45539E8730",
|
||||
@@ -5584,7 +5596,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "86666.297",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "47605.4017552180739029016",
|
||||
"locked_amount": "47546.4919777417822259639",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "86666.297",
|
||||
@@ -5650,7 +5662,7 @@
|
||||
"tranche_end": "2023-06-01T00:00:00.000Z",
|
||||
"total_added": "2500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "185.341149013024125",
|
||||
"locked_amount": "181.933156542531675",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "2500",
|
||||
@@ -5683,7 +5695,7 @@
|
||||
"tranche_end": "2023-11-01T00:00:00.000Z",
|
||||
"total_added": "15000.000000000000015",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "13572.785514794685013572785514794685",
|
||||
"locked_amount": "13552.559820350241013552559820350241",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1.5e-14",
|
||||
@@ -5791,7 +5803,7 @@
|
||||
"tranche_end": "2023-09-01T00:00:00.000Z",
|
||||
"total_added": "17500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "10033.28599914452525",
|
||||
"locked_amount": "10009.68935562600725",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "12500",
|
||||
@@ -6058,7 +6070,7 @@
|
||||
"tranche_end": "2023-08-01T00:00:00.000Z",
|
||||
"total_added": "37500",
|
||||
"total_removed": "18592.291570575",
|
||||
"locked_amount": "15433.59854588704875",
|
||||
"locked_amount": "15382.196228514426375",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
@@ -6510,7 +6522,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "129999.45",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "47561.9678160577578038775",
|
||||
"locked_amount": "47503.1117863411078668825",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "129999.45",
|
||||
@@ -6543,7 +6555,7 @@
|
||||
"tranche_end": "2024-04-01T00:00:00.000Z",
|
||||
"total_added": "54144.7663",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "47116.7217333150004818831",
|
||||
"locked_amount": "47080.01840876004104699305",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "54144.7663",
|
||||
@@ -6576,7 +6588,7 @@
|
||||
"tranche_end": "2023-09-03T00:00:00.000Z",
|
||||
"total_added": "62600",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "18435.7575659563655",
|
||||
"locked_amount": "18393.206399036021604",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "10000",
|
||||
@@ -6769,7 +6781,7 @@
|
||||
"tranche_end": "2023-09-17T00:00:00.000Z",
|
||||
"total_added": "5000",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "1664.285419837646",
|
||||
"locked_amount": "1660.88676433282625",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "5000",
|
||||
@@ -7838,7 +7850,7 @@
|
||||
"tranche_end": "2023-06-02T00:00:00.000Z",
|
||||
"total_added": "1939928.38",
|
||||
"total_removed": "1709370.7872515768348",
|
||||
"locked_amount": "77027.5703575844087789349",
|
||||
"locked_amount": "75708.9407040557483188244",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1852091.69",
|
||||
@@ -41915,7 +41927,7 @@
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "3732368.4671",
|
||||
"total_removed": "747515.181114080043393",
|
||||
"locked_amount": "142865.8822173107416572269134",
|
||||
"locked_amount": "140839.6075379211948069455415",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1998.95815",
|
||||
@@ -43319,7 +43331,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "15870102.715470999700000001",
|
||||
"total_removed": "889552.43313356066956852",
|
||||
"locked_amount": "5806280.83111707407448955866311495377399295",
|
||||
"locked_amount": "5799095.79120322791577005129823294316842385",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "16249.93",
|
||||
@@ -60271,7 +60283,7 @@
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "472355.6199999996",
|
||||
"total_removed": "45798.0743154683416",
|
||||
"locked_amount": "22637.900715233350373427636631164",
|
||||
"locked_amount": "22316.8408879026950634697130999496",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "3000",
|
||||
|
||||
@@ -115,7 +115,19 @@ export function createClient({
|
||||
)
|
||||
: httpLink;
|
||||
|
||||
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
||||
const errorLink = onError(({ graphQLErrors, networkError, operation }) => {
|
||||
// if any of these queries error don't capture any errors, its
|
||||
// likely the user is connecting to a dodgy node, NodeGuard gets
|
||||
// called on startup, NodeCheck and NodeCheckTimeUpdate are called
|
||||
// by the NodeSwitcher component and the useNodeHealth hook
|
||||
if (
|
||||
['NodeGuard', 'NodeCheck', 'NodeCheckTimeUpdate'].includes(
|
||||
operation.operationName
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (graphQLErrors) {
|
||||
graphQLErrors.forEach((e) => {
|
||||
if (e.extensions && e.extensions['type'] !== NOT_FOUND) {
|
||||
|
||||
@@ -3,11 +3,13 @@ import { MockedProvider } from '@apollo/react-testing';
|
||||
import { act, render, screen, waitFor } from '@testing-library/react';
|
||||
import { RadioGroup } from '@vegaprotocol/ui-toolkit';
|
||||
import type {
|
||||
BlockTimeSubscription,
|
||||
StatisticsQuery,
|
||||
} from '../../utils/__generated__/Node';
|
||||
import { BlockTimeDocument } from '../../utils/__generated__/Node';
|
||||
import { StatisticsDocument } from '../../utils/__generated__/Node';
|
||||
NodeCheckTimeUpdateSubscription,
|
||||
NodeCheckQuery,
|
||||
} from '../../utils/__generated__/NodeCheck';
|
||||
import {
|
||||
NodeCheckDocument,
|
||||
NodeCheckTimeUpdateDocument,
|
||||
} from '../../utils/__generated__/NodeCheck';
|
||||
import type { RowDataProps } from './row-data';
|
||||
import { POLL_INTERVAL } from './row-data';
|
||||
import { BLOCK_THRESHOLD, RowData } from './row-data';
|
||||
@@ -19,9 +21,9 @@ jest.mock('@vegaprotocol/apollo-client', () => ({
|
||||
useHeaderStore: jest.fn().mockReturnValue({}),
|
||||
}));
|
||||
|
||||
const statsQueryMock: MockedResponse<StatisticsQuery> = {
|
||||
const statsQueryMock: MockedResponse<NodeCheckQuery> = {
|
||||
request: {
|
||||
query: StatisticsDocument,
|
||||
query: NodeCheckDocument,
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
@@ -34,9 +36,9 @@ const statsQueryMock: MockedResponse<StatisticsQuery> = {
|
||||
},
|
||||
};
|
||||
|
||||
const subMock: MockedResponse<BlockTimeSubscription> = {
|
||||
const subMock: MockedResponse<NodeCheckTimeUpdateSubscription> = {
|
||||
request: {
|
||||
query: BlockTimeDocument,
|
||||
query: NodeCheckTimeUpdateDocument,
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
@@ -71,8 +73,8 @@ const mockHeaders = (
|
||||
|
||||
const renderComponent = (
|
||||
props: RowDataProps,
|
||||
queryMock: MockedResponse<StatisticsQuery>,
|
||||
subMock: MockedResponse<BlockTimeSubscription>
|
||||
queryMock: MockedResponse<NodeCheckQuery>,
|
||||
subMock: MockedResponse<NodeCheckTimeUpdateSubscription>
|
||||
) => {
|
||||
return (
|
||||
<MockedProvider mocks={[queryMock, subMock, subMock, subMock]}>
|
||||
@@ -127,16 +129,16 @@ describe('RowData', () => {
|
||||
it('radio button still enabled if query fails', async () => {
|
||||
mockHeaders(props.url, {});
|
||||
|
||||
const failedQueryMock: MockedResponse<StatisticsQuery> = {
|
||||
const failedQueryMock: MockedResponse<NodeCheckQuery> = {
|
||||
request: {
|
||||
query: StatisticsDocument,
|
||||
query: NodeCheckDocument,
|
||||
},
|
||||
error: new Error('failed'),
|
||||
};
|
||||
|
||||
const failedSubMock: MockedResponse<BlockTimeSubscription> = {
|
||||
const failedSubMock: MockedResponse<NodeCheckTimeUpdateSubscription> = {
|
||||
request: {
|
||||
query: BlockTimeDocument,
|
||||
query: NodeCheckTimeUpdateDocument,
|
||||
},
|
||||
error: new Error('failed'),
|
||||
};
|
||||
@@ -244,10 +246,10 @@ describe('RowData', () => {
|
||||
jest.useFakeTimers();
|
||||
const createStatsQueryMock = (
|
||||
blockHeight: string
|
||||
): MockedResponse<StatisticsQuery> => {
|
||||
): MockedResponse<NodeCheckQuery> => {
|
||||
return {
|
||||
request: {
|
||||
query: StatisticsDocument,
|
||||
query: NodeCheckDocument,
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
@@ -261,10 +263,10 @@ describe('RowData', () => {
|
||||
};
|
||||
};
|
||||
|
||||
const createFailedStatsQueryMock = (): MockedResponse<StatisticsQuery> => {
|
||||
const createFailedStatsQueryMock = (): MockedResponse<NodeCheckQuery> => {
|
||||
return {
|
||||
request: {
|
||||
query: StatisticsDocument,
|
||||
query: NodeCheckDocument,
|
||||
},
|
||||
result: {
|
||||
data: undefined,
|
||||
|
||||
@@ -6,9 +6,9 @@ import { Radio } from '@vegaprotocol/ui-toolkit';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { CUSTOM_NODE_KEY } from '../../types';
|
||||
import {
|
||||
useBlockTimeSubscription,
|
||||
useStatisticsQuery,
|
||||
} from '../../utils/__generated__/Node';
|
||||
useNodeCheckQuery,
|
||||
useNodeCheckTimeUpdateSubscription,
|
||||
} from '../../utils/__generated__/NodeCheck';
|
||||
import { LayoutCell } from './layout-cell';
|
||||
|
||||
export const POLL_INTERVAL = 1000;
|
||||
@@ -30,13 +30,14 @@ export const RowData = ({
|
||||
const [subFailed, setSubFailed] = useState(false);
|
||||
const [time, setTime] = useState<number>();
|
||||
// no use of data here as we need the data nodes reference to block height
|
||||
const { data, error, loading, startPolling, stopPolling } =
|
||||
useStatisticsQuery({
|
||||
const { data, error, loading, startPolling, stopPolling } = useNodeCheckQuery(
|
||||
{
|
||||
pollInterval: POLL_INTERVAL,
|
||||
// fix for pollInterval
|
||||
// https://github.com/apollographql/apollo-client/issues/9819
|
||||
ssr: false,
|
||||
});
|
||||
}
|
||||
);
|
||||
const headerStore = useHeaderStore();
|
||||
const headers = headerStore[url];
|
||||
|
||||
@@ -44,7 +45,7 @@ export const RowData = ({
|
||||
data: subData,
|
||||
error: subError,
|
||||
loading: subLoading,
|
||||
} = useBlockTimeSubscription();
|
||||
} = useNodeCheckTimeUpdateSubscription();
|
||||
|
||||
useEffect(() => {
|
||||
const timeout = setTimeout(() => {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
StatisticsDocument,
|
||||
BlockTimeDocument,
|
||||
} from '../../utils/__generated__/Node';
|
||||
NodeCheckDocument,
|
||||
NodeCheckTimeUpdateDocument,
|
||||
} from '../../utils/__generated__/NodeCheck';
|
||||
import type {
|
||||
StatisticsQuery,
|
||||
BlockTimeSubscription,
|
||||
} from '../../utils/__generated__/Node';
|
||||
NodeCheckQuery,
|
||||
NodeCheckTimeUpdateSubscription,
|
||||
} from '../../utils/__generated__/NodeCheck';
|
||||
import { Networks } from '../../types';
|
||||
import type { RequestHandlerResponse } from 'mock-apollo-client';
|
||||
import { createMockClient } from 'mock-apollo-client';
|
||||
@@ -21,7 +21,7 @@ type MockClientProps = {
|
||||
busEvents?: MockRequestConfig;
|
||||
};
|
||||
|
||||
export const getMockBusEventsResult = (): BlockTimeSubscription => ({
|
||||
export const getMockBusEventsResult = (): NodeCheckTimeUpdateSubscription => ({
|
||||
busEvents: [
|
||||
{
|
||||
__typename: 'BusEvent',
|
||||
@@ -32,19 +32,21 @@ export const getMockBusEventsResult = (): BlockTimeSubscription => ({
|
||||
|
||||
export const getMockStatisticsResult = (
|
||||
env: Networks = Networks.TESTNET
|
||||
): StatisticsQuery => ({
|
||||
): NodeCheckQuery => ({
|
||||
statistics: {
|
||||
__typename: 'Statistics',
|
||||
chainId: `${env.toLowerCase()}-0123`,
|
||||
blockHeight: '11',
|
||||
vegaTime: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
|
||||
export const getMockQueryResult = (env: Networks): StatisticsQuery => ({
|
||||
export const getMockQueryResult = (env: Networks): NodeCheckQuery => ({
|
||||
statistics: {
|
||||
__typename: 'Statistics',
|
||||
chainId: `${env.toLowerCase()}-0123`,
|
||||
blockHeight: '11',
|
||||
vegaTime: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -72,11 +74,11 @@ export default function ({
|
||||
const mockClient = createMockClient();
|
||||
|
||||
mockClient.setRequestHandler(
|
||||
StatisticsDocument,
|
||||
NodeCheckDocument,
|
||||
getHandler(statistics, getMockStatisticsResult(network))
|
||||
);
|
||||
mockClient.setRequestHandler(
|
||||
BlockTimeDocument,
|
||||
NodeCheckTimeUpdateDocument,
|
||||
getHandler(busEvents, getMockBusEventsResult())
|
||||
);
|
||||
|
||||
|
||||
@@ -5,11 +5,13 @@ import { useEffect } from 'react';
|
||||
import { create } from 'zustand';
|
||||
import { createClient } from '@vegaprotocol/apollo-client';
|
||||
import type {
|
||||
BlockTimeSubscription,
|
||||
StatisticsQuery,
|
||||
} from '../utils/__generated__/Node';
|
||||
import { BlockTimeDocument } from '../utils/__generated__/Node';
|
||||
import { StatisticsDocument } from '../utils/__generated__/Node';
|
||||
NodeCheckTimeUpdateSubscription,
|
||||
NodeCheckQuery,
|
||||
} from '../utils/__generated__/NodeCheck';
|
||||
import {
|
||||
NodeCheckDocument,
|
||||
NodeCheckTimeUpdateDocument,
|
||||
} from '../utils/__generated__/NodeCheck';
|
||||
import type { Environment } from '../types';
|
||||
import { Networks } from '../types';
|
||||
import { compileErrors } from '../utils/compile-errors';
|
||||
@@ -220,8 +222,8 @@ const testNode = async (
|
||||
*/
|
||||
const testQuery = async (client: Client) => {
|
||||
try {
|
||||
const result = await client.query<StatisticsQuery>({
|
||||
query: StatisticsDocument,
|
||||
const result = await client.query<NodeCheckQuery>({
|
||||
query: NodeCheckDocument,
|
||||
});
|
||||
if (!result || result.error) {
|
||||
return false;
|
||||
@@ -240,8 +242,8 @@ const testQuery = async (client: Client) => {
|
||||
const testSubscription = (client: Client) => {
|
||||
return new Promise((resolve) => {
|
||||
const sub = client
|
||||
.subscribe<BlockTimeSubscription>({
|
||||
query: BlockTimeDocument,
|
||||
.subscribe<NodeCheckTimeUpdateSubscription>({
|
||||
query: NodeCheckTimeUpdateDocument,
|
||||
errorPolicy: 'all',
|
||||
})
|
||||
.subscribe({
|
||||
|
||||
@@ -2,8 +2,8 @@ import { renderHook, waitFor } from '@testing-library/react';
|
||||
import { useNodeHealth } from './use-node-health';
|
||||
import type { MockedResponse } from '@apollo/react-testing';
|
||||
import { MockedProvider } from '@apollo/react-testing';
|
||||
import type { StatisticsQuery } from '../utils/__generated__/Node';
|
||||
import { StatisticsDocument } from '../utils/__generated__/Node';
|
||||
import type { NodeCheckQuery } from '../utils/__generated__/NodeCheck';
|
||||
import { NodeCheckDocument } from '../utils/__generated__/NodeCheck';
|
||||
import { useHeaderStore } from '@vegaprotocol/apollo-client';
|
||||
import { Intent } from '@vegaprotocol/ui-toolkit';
|
||||
|
||||
@@ -16,10 +16,10 @@ jest.mock('@vegaprotocol/apollo-client');
|
||||
|
||||
const createStatsMock = (
|
||||
blockHeight: number
|
||||
): MockedResponse<StatisticsQuery> => {
|
||||
): MockedResponse<NodeCheckQuery> => {
|
||||
return {
|
||||
request: {
|
||||
query: StatisticsDocument,
|
||||
query: NodeCheckDocument,
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
@@ -34,7 +34,7 @@ const createStatsMock = (
|
||||
};
|
||||
|
||||
function setup(
|
||||
mock: MockedResponse<StatisticsQuery>,
|
||||
mock: MockedResponse<NodeCheckQuery>,
|
||||
headers:
|
||||
| {
|
||||
blockHeight: number;
|
||||
@@ -93,9 +93,9 @@ describe('useNodeHealth', () => {
|
||||
);
|
||||
|
||||
it('block diff is null if query fails indicating non operational', async () => {
|
||||
const failedQuery: MockedResponse<StatisticsQuery> = {
|
||||
const failedQuery: MockedResponse<NodeCheckQuery> = {
|
||||
request: {
|
||||
query: StatisticsDocument,
|
||||
query: NodeCheckDocument,
|
||||
},
|
||||
result: {
|
||||
// @ts-ignore failed query with no result
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useStatisticsQuery } from '../utils/__generated__/Node';
|
||||
import { useNodeCheckQuery } from '../utils/__generated__/NodeCheck';
|
||||
import { useHeaderStore } from '@vegaprotocol/apollo-client';
|
||||
import { useEnvironment } from './use-environment';
|
||||
import { useNavigatorOnline } from '@vegaprotocol/react-helpers';
|
||||
@@ -16,7 +16,7 @@ export const useNodeHealth = () => {
|
||||
const url = useEnvironment((store) => store.VEGA_URL);
|
||||
const headerStore = useHeaderStore();
|
||||
const headers = url ? headerStore[url] : undefined;
|
||||
const { data, error, startPolling, stopPolling } = useStatisticsQuery({
|
||||
const { data, error, startPolling, stopPolling } = useNodeCheckQuery({
|
||||
fetchPolicy: 'no-cache',
|
||||
});
|
||||
|
||||
|
||||
@@ -8,4 +8,4 @@ export * from './hooks';
|
||||
export * from './types';
|
||||
|
||||
// Utils
|
||||
export * from './utils/__generated__/Node';
|
||||
export * from './utils/__generated__/NodeCheck';
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
query Statistics {
|
||||
query NodeCheck {
|
||||
statistics {
|
||||
chainId
|
||||
blockHeight
|
||||
@@ -6,7 +6,7 @@ query Statistics {
|
||||
}
|
||||
}
|
||||
|
||||
subscription BlockTime {
|
||||
subscription NodeCheckTimeUpdate {
|
||||
busEvents(types: TimeUpdate, batchSize: 1) {
|
||||
id
|
||||
}
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
import * as Types from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type StatisticsQueryVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type StatisticsQuery = { __typename?: 'Query', statistics: { __typename?: 'Statistics', chainId: string, blockHeight: string, vegaTime: any } };
|
||||
|
||||
export type BlockTimeSubscriptionVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type BlockTimeSubscription = { __typename?: 'Subscription', busEvents?: Array<{ __typename?: 'BusEvent', id: string }> | null };
|
||||
|
||||
|
||||
export const StatisticsDocument = gql`
|
||||
query Statistics {
|
||||
statistics {
|
||||
chainId
|
||||
blockHeight
|
||||
vegaTime
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useStatisticsQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useStatisticsQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useStatisticsQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useStatisticsQuery({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useStatisticsQuery(baseOptions?: Apollo.QueryHookOptions<StatisticsQuery, StatisticsQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<StatisticsQuery, StatisticsQueryVariables>(StatisticsDocument, options);
|
||||
}
|
||||
export function useStatisticsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<StatisticsQuery, StatisticsQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<StatisticsQuery, StatisticsQueryVariables>(StatisticsDocument, options);
|
||||
}
|
||||
export type StatisticsQueryHookResult = ReturnType<typeof useStatisticsQuery>;
|
||||
export type StatisticsLazyQueryHookResult = ReturnType<typeof useStatisticsLazyQuery>;
|
||||
export type StatisticsQueryResult = Apollo.QueryResult<StatisticsQuery, StatisticsQueryVariables>;
|
||||
export const BlockTimeDocument = gql`
|
||||
subscription BlockTime {
|
||||
busEvents(types: TimeUpdate, batchSize: 1) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useBlockTimeSubscription__
|
||||
*
|
||||
* To run a query within a React component, call `useBlockTimeSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useBlockTimeSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useBlockTimeSubscription({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useBlockTimeSubscription(baseOptions?: Apollo.SubscriptionHookOptions<BlockTimeSubscription, BlockTimeSubscriptionVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useSubscription<BlockTimeSubscription, BlockTimeSubscriptionVariables>(BlockTimeDocument, options);
|
||||
}
|
||||
export type BlockTimeSubscriptionHookResult = ReturnType<typeof useBlockTimeSubscription>;
|
||||
export type BlockTimeSubscriptionResult = Apollo.SubscriptionResult<BlockTimeSubscription>;
|
||||
@@ -0,0 +1,81 @@
|
||||
import * as Types from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type NodeCheckQueryVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type NodeCheckQuery = { __typename?: 'Query', statistics: { __typename?: 'Statistics', chainId: string, blockHeight: string, vegaTime: any } };
|
||||
|
||||
export type NodeCheckTimeUpdateSubscriptionVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type NodeCheckTimeUpdateSubscription = { __typename?: 'Subscription', busEvents?: Array<{ __typename?: 'BusEvent', id: string }> | null };
|
||||
|
||||
|
||||
export const NodeCheckDocument = gql`
|
||||
query NodeCheck {
|
||||
statistics {
|
||||
chainId
|
||||
blockHeight
|
||||
vegaTime
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useNodeCheckQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useNodeCheckQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useNodeCheckQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useNodeCheckQuery({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useNodeCheckQuery(baseOptions?: Apollo.QueryHookOptions<NodeCheckQuery, NodeCheckQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<NodeCheckQuery, NodeCheckQueryVariables>(NodeCheckDocument, options);
|
||||
}
|
||||
export function useNodeCheckLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<NodeCheckQuery, NodeCheckQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<NodeCheckQuery, NodeCheckQueryVariables>(NodeCheckDocument, options);
|
||||
}
|
||||
export type NodeCheckQueryHookResult = ReturnType<typeof useNodeCheckQuery>;
|
||||
export type NodeCheckLazyQueryHookResult = ReturnType<typeof useNodeCheckLazyQuery>;
|
||||
export type NodeCheckQueryResult = Apollo.QueryResult<NodeCheckQuery, NodeCheckQueryVariables>;
|
||||
export const NodeCheckTimeUpdateDocument = gql`
|
||||
subscription NodeCheckTimeUpdate {
|
||||
busEvents(types: TimeUpdate, batchSize: 1) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useNodeCheckTimeUpdateSubscription__
|
||||
*
|
||||
* To run a query within a React component, call `useNodeCheckTimeUpdateSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useNodeCheckTimeUpdateSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useNodeCheckTimeUpdateSubscription({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useNodeCheckTimeUpdateSubscription(baseOptions?: Apollo.SubscriptionHookOptions<NodeCheckTimeUpdateSubscription, NodeCheckTimeUpdateSubscriptionVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useSubscription<NodeCheckTimeUpdateSubscription, NodeCheckTimeUpdateSubscriptionVariables>(NodeCheckTimeUpdateDocument, options);
|
||||
}
|
||||
export type NodeCheckTimeUpdateSubscriptionHookResult = ReturnType<typeof useNodeCheckTimeUpdateSubscription>;
|
||||
export type NodeCheckTimeUpdateSubscriptionResult = Apollo.SubscriptionResult<NodeCheckTimeUpdateSubscription>;
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { StatisticsQuery } from './__generated__/Node';
|
||||
import type { NodeCheckQuery } from './__generated__/NodeCheck';
|
||||
import merge from 'lodash/merge';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
|
||||
export const statisticsQuery = (
|
||||
override?: PartialDeep<StatisticsQuery>
|
||||
): StatisticsQuery => {
|
||||
const defaultResult: StatisticsQuery = {
|
||||
override?: PartialDeep<NodeCheckQuery>
|
||||
): NodeCheckQuery => {
|
||||
const defaultResult: NodeCheckQuery = {
|
||||
statistics: {
|
||||
__typename: 'Statistics',
|
||||
chainId: 'chain-id',
|
||||
|
||||
@@ -5,7 +5,7 @@ import { AssetDetailsTable, useAssetDataProvider } from '@vegaprotocol/assets';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { marketDataProvider } from '../../market-data-provider';
|
||||
import { totalFeesPercentage } from '../../market-utils';
|
||||
import { ExternalLink, Splash } from '@vegaprotocol/ui-toolkit';
|
||||
import { Dialog, ExternalLink, Splash } from '@vegaprotocol/ui-toolkit';
|
||||
import {
|
||||
addDecimalsFormatNumber,
|
||||
formatNumber,
|
||||
@@ -25,9 +25,12 @@ import { ConditionOperatorMapping } from '@vegaprotocol/types';
|
||||
import { MarketTradingModeMapping } from '@vegaprotocol/types';
|
||||
import { useEnvironment } from '@vegaprotocol/environment';
|
||||
import type { Provider } from '../../oracle-schema';
|
||||
import { OracleBasicProfile } from '../../components/oracle-basic-profile';
|
||||
import { useOracleProofs } from '../../hooks';
|
||||
import { OracleDialog } from '../oracle-dialog/oracle-dialog';
|
||||
import {
|
||||
OracleBasicProfile,
|
||||
OracleProfileTitle,
|
||||
OracleFullProfile,
|
||||
} from '../../components';
|
||||
import { useOracleProofs, useOracleMarkets } from '../../hooks';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
|
||||
type PanelProps = Pick<
|
||||
@@ -610,6 +613,34 @@ const NoOracleProof = ({
|
||||
);
|
||||
};
|
||||
|
||||
export const OracleDialog = ({
|
||||
provider,
|
||||
dataSourceSpecId,
|
||||
open,
|
||||
onChange,
|
||||
}: {
|
||||
dataSourceSpecId: string;
|
||||
provider: Provider;
|
||||
open: boolean;
|
||||
onChange?: (isOpen: boolean) => void;
|
||||
}) => {
|
||||
const oracleMarkets = useOracleMarkets(provider);
|
||||
return (
|
||||
<Dialog
|
||||
title={<OracleProfileTitle provider={provider} />}
|
||||
aria-labelledby="oracle-proof-dialog"
|
||||
open={open}
|
||||
onChange={onChange}
|
||||
>
|
||||
<OracleFullProfile
|
||||
provider={provider}
|
||||
dataSourceSpecId={dataSourceSpecId}
|
||||
markets={oracleMarkets}
|
||||
/>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
const OracleProfile = (props: {
|
||||
provider: Provider;
|
||||
dataSourceSpecId: string;
|
||||
|
||||
@@ -143,7 +143,7 @@ export const marketInfoQuery = (
|
||||
__typename: 'Signer',
|
||||
signer: {
|
||||
__typename: 'PubKey',
|
||||
key: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
|
||||
key: '69464e35bcb8e8a2900ca0f87acaf252d50cf2ab2fc73694845a16b7c8a0dc6f',
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -164,7 +164,7 @@ export const marketInfoQuery = (
|
||||
__typename: 'Signer',
|
||||
signer: {
|
||||
__typename: 'PubKey',
|
||||
key: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
|
||||
key: '69464e35bcb8e8a2900ca0f87acaf252d50cf2ab2fc73694845a16b7c8a0dc6f',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useEnvironment } from '@vegaprotocol/environment';
|
||||
import { Icon } from '@vegaprotocol/ui-toolkit';
|
||||
import type { IconName } from '@blueprintjs/icons';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { getMatchingOracleProvider, useOracleProofs } from '../../hooks';
|
||||
import type { Market } from '../../markets-provider';
|
||||
import { getVerifiedStatusIcon } from '../oracle-basic-profile';
|
||||
|
||||
export const OracleStatus = ({
|
||||
dataSourceSpecForSettlementData,
|
||||
@@ -25,15 +23,22 @@ export const OracleStatus = ({
|
||||
dataSourceSpecForTradingTermination.data,
|
||||
providers
|
||||
);
|
||||
let maliciousOracleProvider = null;
|
||||
if (settlementDataProvider?.oracle.status !== 'GOOD') {
|
||||
maliciousOracleProvider = settlementDataProvider;
|
||||
} else if (tradingTerminationDataProvider?.oracle.status !== 'GOOD') {
|
||||
maliciousOracleProvider = tradingTerminationDataProvider;
|
||||
if (
|
||||
(settlementDataProvider &&
|
||||
settlementDataProvider.oracle.status !== 'GOOD') ||
|
||||
(tradingTerminationDataProvider &&
|
||||
tradingTerminationDataProvider.oracle.status !== 'GOOD')
|
||||
) {
|
||||
return (
|
||||
<span
|
||||
className="ml-1"
|
||||
role="img"
|
||||
aria-label={t('oracle status not healthy')}
|
||||
>
|
||||
⛔
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (!maliciousOracleProvider) return null;
|
||||
const { icon } = getVerifiedStatusIcon(maliciousOracleProvider);
|
||||
return <Icon size={3} name={icon as IconName} className="ml-1" />;
|
||||
}
|
||||
return null;
|
||||
}, [
|
||||
|
||||
@@ -6,13 +6,27 @@ import {
|
||||
NotificationBanner,
|
||||
ButtonLink,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { OracleDialog } from '../oracle-dialog';
|
||||
import { oracleStatuses } from './oracle-statuses';
|
||||
import { OracleDialog } from '../market-info';
|
||||
|
||||
export const oracleStatuses = {
|
||||
UNKNOWN: t(
|
||||
"This public key's proofs have not been verified yet, or no proofs have been provided yet."
|
||||
),
|
||||
GOOD: t("This public key's proofs have been verified."),
|
||||
SUSPICIOUS: t(
|
||||
'This public key is suspected to be acting in bad faith, pending investigation.'
|
||||
),
|
||||
MALICIOUS: t('This public key has been observed acting in bad faith.'),
|
||||
RETIRED: t('This public key is no longer in use.'),
|
||||
COMPROMISED: t(
|
||||
'This public key is no longer in the control of its original owners.'
|
||||
),
|
||||
};
|
||||
|
||||
export const OracleBanner = ({ marketId }: { marketId: string }) => {
|
||||
const [open, onChange] = useState(false);
|
||||
const { data: settlementOracle } = useMarketOracle(marketId);
|
||||
const { data: tradingTerminationOracle } = useMarketOracle(
|
||||
const settlementOracle = useMarketOracle(marketId);
|
||||
const tradingTerminationOracle = useMarketOracle(
|
||||
marketId,
|
||||
'dataSourceSpecForTradingTermination'
|
||||
);
|
||||
@@ -22,7 +36,15 @@ export const OracleBanner = ({ marketId }: { marketId: string }) => {
|
||||
} else if (tradingTerminationOracle?.provider.oracle.status !== 'GOOD') {
|
||||
maliciousOracle = tradingTerminationOracle;
|
||||
}
|
||||
|
||||
if (!maliciousOracle) return null;
|
||||
if (!settlementOracle && !tradingTerminationOracle) {
|
||||
return (
|
||||
<NotificationBanner intent={Intent.Primary}>
|
||||
<div>{t('There is no oracle for this market.')} </div>
|
||||
</NotificationBanner>
|
||||
);
|
||||
}
|
||||
|
||||
const { provider } = maliciousOracle;
|
||||
return (
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
|
||||
export const oracleStatuses = {
|
||||
UNKNOWN: t(
|
||||
"This public key's proofs have not been verified yet, or no proofs have been provided yet."
|
||||
),
|
||||
GOOD: t("This public key's proofs have been verified."),
|
||||
SUSPICIOUS: t(
|
||||
'This public key is suspected to be acting in bad faith, pending investigation.'
|
||||
),
|
||||
MALICIOUS: t('This public key has been observed acting in bad faith.'),
|
||||
RETIRED: t('This public key is no longer in use.'),
|
||||
COMPROMISED: t(
|
||||
'This public key is no longer in the control of its original owners.'
|
||||
),
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
export * from './oracle-dialog';
|
||||
@@ -1,35 +0,0 @@
|
||||
import { Dialog } from '@vegaprotocol/ui-toolkit';
|
||||
import {
|
||||
OracleProfileTitle,
|
||||
OracleFullProfile,
|
||||
} from '../../components/oracle-full-profile';
|
||||
import { useOracleMarkets } from '../../hooks';
|
||||
import type { Provider } from '../../oracle-schema';
|
||||
|
||||
export const OracleDialog = ({
|
||||
provider,
|
||||
dataSourceSpecId,
|
||||
open,
|
||||
onChange,
|
||||
}: {
|
||||
dataSourceSpecId: string;
|
||||
provider: Provider;
|
||||
open: boolean;
|
||||
onChange?: (isOpen: boolean) => void;
|
||||
}) => {
|
||||
const oracleMarkets = useOracleMarkets(provider);
|
||||
return (
|
||||
<Dialog
|
||||
title={<OracleProfileTitle provider={provider} />}
|
||||
aria-labelledby="oracle-proof-dialog"
|
||||
open={open}
|
||||
onChange={onChange}
|
||||
>
|
||||
<OracleFullProfile
|
||||
provider={provider}
|
||||
dataSourceSpecId={dataSourceSpecId}
|
||||
markets={oracleMarkets}
|
||||
/>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -1 +1,2 @@
|
||||
export * from './oracle-full-profile.stories';
|
||||
export * from './oracle-full-profile';
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
VegaIcon,
|
||||
VegaIconNames,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { oracleStatuses } from '../oracle-banner/oracle-statuses';
|
||||
import { oracleStatuses } from '../oracle-banner';
|
||||
import type { IconName } from '@blueprintjs/icons';
|
||||
import classNames from 'classnames';
|
||||
import { getLinkIcon, getVerifiedStatusIcon } from '../oracle-basic-profile';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useMarketOracle } from './use-market-oracle';
|
||||
import type { MarketFieldsFragment } from '../__generated__/markets';
|
||||
import type { MarketInfoQuery } from '../components/market-info/__generated__/MarketInfo';
|
||||
import type { Provider } from '../oracle-schema';
|
||||
|
||||
const ORACLE_PROOFS_URL = 'ORACLE_PROOFS_URL';
|
||||
@@ -10,42 +10,43 @@ const key = 'key';
|
||||
const dataSourceSpecId = 'dataSourceSpecId';
|
||||
|
||||
const mockEnvironment = jest.fn(() => ({ ORACLE_PROOFS_URL }));
|
||||
const mockMarket = jest.fn<{ data: MarketFieldsFragment | null }, unknown[]>(
|
||||
() => ({
|
||||
data: {
|
||||
tradableInstrument: {
|
||||
instrument: {
|
||||
product: {
|
||||
dataSourceSpecForSettlementData: {
|
||||
id: dataSourceSpecId,
|
||||
data: {
|
||||
const mockDataProvider = jest.fn<
|
||||
{ data: MarketInfoQuery['market'] },
|
||||
unknown[]
|
||||
>(() => ({
|
||||
data: {
|
||||
tradableInstrument: {
|
||||
instrument: {
|
||||
product: {
|
||||
dataSourceSpecForSettlementData: {
|
||||
id: dataSourceSpecId,
|
||||
data: {
|
||||
sourceType: {
|
||||
__typename: 'DataSourceDefinitionExternal',
|
||||
sourceType: {
|
||||
__typename: 'DataSourceDefinitionExternal',
|
||||
sourceType: {
|
||||
signers: [
|
||||
{
|
||||
signer: {
|
||||
__typename: 'ETHAddress',
|
||||
address,
|
||||
},
|
||||
signers: [
|
||||
{
|
||||
signer: {
|
||||
__typename: 'ETHAddress',
|
||||
address,
|
||||
},
|
||||
{
|
||||
signer: {
|
||||
__typename: 'PubKey',
|
||||
key,
|
||||
},
|
||||
},
|
||||
{
|
||||
signer: {
|
||||
__typename: 'PubKey',
|
||||
key,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as MarketFieldsFragment,
|
||||
})
|
||||
);
|
||||
},
|
||||
} as MarketInfoQuery['market'],
|
||||
}));
|
||||
|
||||
const mockOracleProofs = jest.fn<{ data?: Provider[] }, unknown[]>(() => ({}));
|
||||
|
||||
@@ -53,8 +54,9 @@ jest.mock('@vegaprotocol/environment', () => ({
|
||||
useEnvironment: jest.fn((args) => mockEnvironment()),
|
||||
}));
|
||||
|
||||
jest.mock('../markets-provider', () => ({
|
||||
useMarket: jest.fn((args) => mockMarket()),
|
||||
jest.mock('@vegaprotocol/data-provider', () => ({
|
||||
...jest.requireActual('@vegaprotocol/data-provider'),
|
||||
useDataProvider: jest.fn((args) => mockDataProvider()),
|
||||
}));
|
||||
|
||||
jest.mock('./use-oracle-proofs', () => ({
|
||||
@@ -64,15 +66,15 @@ jest.mock('./use-oracle-proofs', () => ({
|
||||
const marketId = 'marketId';
|
||||
describe('useMarketOracle', () => {
|
||||
it('returns undefined if no market info present', () => {
|
||||
mockMarket.mockReturnValueOnce({ data: null });
|
||||
mockDataProvider.mockReturnValueOnce({ data: null });
|
||||
const { result } = renderHook(() => useMarketOracle(marketId));
|
||||
expect(result.current?.data).toBeUndefined();
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns undefined if no oracle proofs present', () => {
|
||||
mockOracleProofs.mockReturnValueOnce({ data: undefined });
|
||||
const { result } = renderHook(() => useMarketOracle(marketId));
|
||||
expect(result.current?.data).toBeUndefined();
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns oracle matched by eth_address', () => {
|
||||
@@ -100,8 +102,8 @@ describe('useMarketOracle', () => {
|
||||
data,
|
||||
});
|
||||
const { result } = renderHook(() => useMarketOracle(marketId));
|
||||
expect(result.current?.data?.dataSourceSpecId).toBe(dataSourceSpecId);
|
||||
expect(result.current?.data?.provider).toBe(data[1]);
|
||||
expect(result.current?.dataSourceSpecId).toBe(dataSourceSpecId);
|
||||
expect(result.current?.provider).toBe(data[1]);
|
||||
});
|
||||
|
||||
it('returns oracle matching by public_key', () => {
|
||||
@@ -129,7 +131,7 @@ describe('useMarketOracle', () => {
|
||||
data,
|
||||
});
|
||||
const { result } = renderHook(() => useMarketOracle(marketId));
|
||||
expect(result.current?.data?.dataSourceSpecId).toBe(dataSourceSpecId);
|
||||
expect(result.current?.data?.provider).toBe(data[1]);
|
||||
expect(result.current?.dataSourceSpecId).toBe(dataSourceSpecId);
|
||||
expect(result.current?.provider).toBe(data[1]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEnvironment } from '@vegaprotocol/environment';
|
||||
import { useOracleProofs } from './use-oracle-proofs';
|
||||
import { useMarket } from '../markets-provider';
|
||||
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { marketInfoProvider } from '../components/market-info/market-info-data-provider';
|
||||
import { useMemo } from 'react';
|
||||
import type { Provider } from '../oracle-schema';
|
||||
import type { DataSourceSpecFragment } from '../__generated__/OracleMarketsSpec';
|
||||
@@ -41,30 +41,23 @@ export const useMarketOracle = (
|
||||
dataSourceType:
|
||||
| 'dataSourceSpecForSettlementData'
|
||||
| 'dataSourceSpecForTradingTermination' = 'dataSourceSpecForSettlementData'
|
||||
): {
|
||||
data?: {
|
||||
provider: NonNullable<ReturnType<typeof getMatchingOracleProvider>>;
|
||||
dataSourceSpecId: string;
|
||||
};
|
||||
loading?: boolean;
|
||||
} => {
|
||||
) => {
|
||||
const { ORACLE_PROOFS_URL } = useEnvironment();
|
||||
const { data: market, loading: marketLoading } = useMarket(marketId);
|
||||
const { data: providers, loading: providersLoading } =
|
||||
useOracleProofs(ORACLE_PROOFS_URL);
|
||||
const { data: marketInfo } = useDataProvider({
|
||||
dataProvider: marketInfoProvider,
|
||||
variables: { marketId },
|
||||
});
|
||||
const { data: providers } = useOracleProofs(ORACLE_PROOFS_URL);
|
||||
return useMemo(() => {
|
||||
if (marketLoading || providersLoading) {
|
||||
return { loading: true };
|
||||
}
|
||||
if (!providers || !market) {
|
||||
return { data: undefined };
|
||||
if (!providers || !marketInfo) {
|
||||
return undefined;
|
||||
}
|
||||
const dataSourceSpec =
|
||||
market.tradableInstrument.instrument.product[dataSourceType];
|
||||
marketInfo.tradableInstrument.instrument.product[dataSourceType];
|
||||
const provider = getMatchingOracleProvider(dataSourceSpec.data, providers);
|
||||
if (provider) {
|
||||
return { data: { provider, dataSourceSpecId: dataSourceSpec.id } };
|
||||
return { provider, dataSourceSpecId: dataSourceSpec.id };
|
||||
}
|
||||
return { data: undefined };
|
||||
}, [market, dataSourceType, providers, marketLoading, providersLoading]);
|
||||
return undefined;
|
||||
}, [marketInfo, dataSourceType, providers]);
|
||||
};
|
||||
|
||||
@@ -64,44 +64,26 @@ export const createMarketFragment = (
|
||||
},
|
||||
dataSourceSpecForTradingTermination: {
|
||||
__typename: 'DataSourceSpec',
|
||||
id: 'f028fe5ea7de3890962a05a7163fdde562629af649ed81b8c8902fafb6eef04f',
|
||||
id: 'oracleId',
|
||||
data: {
|
||||
__typename: 'DataSourceDefinition',
|
||||
sourceType: {
|
||||
__typename: 'DataSourceDefinitionExternal',
|
||||
sourceType: {
|
||||
__typename: 'DataSourceSpecConfiguration',
|
||||
signers: [
|
||||
{
|
||||
__typename: 'Signer',
|
||||
signer: {
|
||||
__typename: 'PubKey',
|
||||
key: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
dataSourceSpecForSettlementData: {
|
||||
__typename: 'DataSourceSpec',
|
||||
id: 'f028fe5ea7de3890962a05a7163fdde562629af649ed81b8c8902fafb6eef04f',
|
||||
id: 'oracleId',
|
||||
data: {
|
||||
__typename: 'DataSourceDefinition',
|
||||
sourceType: {
|
||||
__typename: 'DataSourceDefinitionExternal',
|
||||
sourceType: {
|
||||
__typename: 'DataSourceSpecConfiguration',
|
||||
signers: [
|
||||
{
|
||||
__typename: 'Signer',
|
||||
signer: {
|
||||
__typename: 'PubKey',
|
||||
key: '6d9d35f657589e40ddfb448b7ad4a7463b66efb307527fedd2aa7df1bbd5ea61',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user