Compare commits

...
11 changed files with 75 additions and 34 deletions
@@ -54,7 +54,7 @@ const Block = () => {
</Button>
</Link>
</div>
{blockData && (
{blockData && 'result' in blockData && (
<>
<TableWithTbody className="mb-8">
<TableRow modifier="bordered">
@@ -95,7 +95,7 @@ export const ProtocolUpgradeProposalContainer = () => {
time={
pending && time ? (
convertToCountdownString(time, '0:00:00:00')
) : blockInfo?.result ? (
) : blockInfo && 'result' in blockInfo && blockInfo?.result ? (
<span title={blockInfo.result.block.header.time}>
{formatDateWithLocalTimezone(
new Date(blockInfo.result.block.header.time)
@@ -9,8 +9,6 @@ import { TradeGrid } from './trade-grid';
import { TradePanels } from './trade-panels';
import { useNavigate, useParams } from 'react-router-dom';
import { Links } from '../../lib/links';
import { ViewType, useSidebar } from '../../components/sidebar';
import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id';
import { useT, ns } from '../../lib/use-t';
import { Trans } from 'react-i18next';
@@ -61,9 +59,6 @@ export const MarketPage = () => {
const t = useT();
const { marketId } = useParams();
const navigate = useNavigate();
const currentRouteId = useGetCurrentRouteId();
const { setViews, getView } = useSidebar();
const view = getView(currentRouteId);
const { screenSize } = useScreenDimensions();
const largeScreen = ['lg', 'xl', 'xxl', 'xxxl'].includes(screenSize);
const update = useGlobalStore((store) => store.update);
@@ -77,12 +72,6 @@ export const MarketPage = () => {
}
}, [update, lastMarketId, data?.id]);
useEffect(() => {
if (largeScreen && view === undefined) {
setViews({ type: ViewType.Order }, currentRouteId);
}
}, [setViews, view, currentRouteId, largeScreen]);
const pinnedAsset = data && getAsset(data);
const tradeView = useMemo(() => {
@@ -4,9 +4,26 @@ import {
SidebarButton,
SidebarDivider,
ViewType,
useSidebar,
} from '../../components/sidebar';
import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id';
import { useT } from '../../lib/use-t';
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
import { useEffect } from 'react';
const ViewInitializer = () => {
const currentRouteId = useGetCurrentRouteId();
const { setViews, getView } = useSidebar();
const view = getView(currentRouteId);
const { screenSize } = useScreenDimensions();
const largeScreen = ['lg', 'xl', 'xxl', 'xxxl'].includes(screenSize);
useEffect(() => {
if (largeScreen && view === undefined) {
setViews({ type: ViewType.Order }, currentRouteId);
}
}, [setViews, view, currentRouteId, largeScreen]);
return null;
};
export const MarketsSidebar = () => {
const t = useT();
@@ -37,6 +54,7 @@ export const MarketsSidebar = () => {
path=":marketId"
element={
<>
<ViewInitializer />
<SidebarDivider />
<SidebarButton
view={ViewType.Order}
@@ -39,11 +39,21 @@ const WithdrawalsIndicator = () => {
);
};
export const Portfolio = () => {
const t = useT();
const SidebarViewInitializer = () => {
const currentRouteId = useGetCurrentRouteId();
const { getView, setViews } = useSidebar();
const view = getView(currentRouteId);
// Make transfer sidebar open by default
useEffect(() => {
if (view === undefined) {
setViews({ type: ViewType.Transfer }, currentRouteId);
}
}, [view, setViews, currentRouteId]);
return null;
};
export const Portfolio = () => {
const t = useT();
const { updateTitle } = usePageTitleStore((store) => ({
updateTitle: store.updateTitle,
@@ -53,17 +63,11 @@ export const Portfolio = () => {
updateTitle(titlefy([t('Portfolio')]));
}, [updateTitle, t]);
// Make transfer sidebar open by default
useEffect(() => {
if (view === undefined) {
setViews({ type: ViewType.Transfer }, currentRouteId);
}
}, [view, setViews, currentRouteId]);
const [sizes, handleOnLayoutChange] = usePaneLayout({ id: 'portfolio' });
const wrapperClasses = 'p-0.5 h-full max-h-full flex flex-col';
return (
<div className={wrapperClasses}>
<SidebarViewInitializer />
<ResizableGrid vertical onChange={handleOnLayoutChange}>
<ResizableGridPanel minSize={75}>
<PortfolioGridChild>
@@ -135,7 +135,7 @@ describe('MarketInfoPanels', () => {
render(<DataSourceProof dataSourceSpecId={''} {...props} />);
expect(screen.getByText('Internal conditions')).toBeInTheDocument();
const dateFromUnixTimestamp = condition.value
? getDateTimeFormat().format(new Date(parseInt(condition.value)))
? getDateTimeFormat().format(new Date(parseInt(condition.value) * 1000))
: '-';
expect(
screen.getByText(
@@ -1263,7 +1263,9 @@ export const DataSourceProof = ({
{data.sourceType.sourceType?.conditions?.map((condition, i) => {
if (!condition) return null;
const dateFromUnixTimestamp = condition.value
? getDateTimeFormat().format(new Date(parseInt(condition.value)))
? getDateTimeFormat().format(
new Date(parseInt(condition.value) * 1000)
)
: '-';
return (
<p key={i}>
@@ -68,10 +68,13 @@ export const useBlockRising = (skip = false) => {
}
);
const heights = compact([
...results.map((r) => r?.blockHeight),
blockInfo?.result.block.header.height,
]);
const heights = compact([...results.map((r) => r?.blockHeight)]);
// Handles TendermintErrorResponses
if (blockInfo && 'result' in blockInfo) {
heights.push(blockInfo.result.block.header.height);
}
const current = max(heights);
if (current && Number(current) > prev) {
setBlock(Number(current));
+13 -3
View File
@@ -76,16 +76,26 @@ export const useFetch = <T>(
...options,
body: body ? body : options?.body,
});
if (!response.ok) {
data = (await response.json()) as T;
if (!response.ok && !data) {
throw new Error(response.statusText);
}
data = (await response.json()) as T;
// @ts-ignore - 'error' in data
if (data && 'error' in data) {
if (data && data.error) {
// Explicit check for TendermintErrorResponse style error
// @ts-ignore - 'error' in data
if (data.error.data) {
// @ts-ignore - 'error' in data
throw new Error(data.error.data);
}
// @ts-ignore - data.error
throw new Error(data.error);
}
if (cancelRequest.current) return;
dispatch({ type: ActionType.FETCHED, payload: data });
+7 -2
View File
@@ -1,6 +1,11 @@
import { useEnvironment } from '@vegaprotocol/environment';
import { useFetch } from '@vegaprotocol/react-helpers';
import { type TendermintBlockResponse } from '../types';
import type {
TendermintBlockResponse,
TendermintErrorResponse,
} from '../types';
type TendermintResponse = TendermintBlockResponse | TendermintErrorResponse;
export const useBlockInfo = (blockHeight?: number, canFetch = true) => {
const { TENDERMINT_URL } = useEnvironment();
@@ -10,7 +15,7 @@ export const useBlockInfo = (blockHeight?: number, canFetch = true) => {
TENDERMINT_URL && blockHeight && !isNaN(blockHeight) && canFetch
);
const { state, refetch } = useFetch<TendermintBlockResponse>(
const { state, refetch } = useFetch<TendermintResponse>(
url,
{ cache: 'force-cache' },
canFetchData
+11 -1
View File
@@ -7,6 +7,16 @@ export type TendermintBlockResponse = {
};
};
export type TendermintErrorResponse = {
jsonrpc: string;
id: number;
error: {
code: number;
message: string;
data: string;
};
};
type Id = {
hash: string;
parts: {
@@ -34,7 +44,7 @@ type Header = {
proposer_address: string;
};
type Block = {
export type Block = {
header: Header;
data: {
txs: string[];