fix(trading): add a timeout to show subscriptions as failed (#3073)
This commit is contained in:
parent
47b81188d4
commit
96bf12d4dd
@ -27,6 +27,7 @@ export const RowData = ({
|
|||||||
highestBlock,
|
highestBlock,
|
||||||
onBlockHeight,
|
onBlockHeight,
|
||||||
}: RowDataProps) => {
|
}: RowDataProps) => {
|
||||||
|
const [subFailed, setSubFailed] = useState(false);
|
||||||
const [time, setTime] = useState<number>();
|
const [time, setTime] = useState<number>();
|
||||||
// no use of data here as we need the data nodes reference to block height
|
// no use of data here as we need the data nodes reference to block height
|
||||||
const { data, error, loading, startPolling, stopPolling } =
|
const { data, error, loading, startPolling, stopPolling } =
|
||||||
@ -46,9 +47,18 @@ export const RowData = ({
|
|||||||
} = useBlockTimeSubscription();
|
} = useBlockTimeSubscription();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// stop polling if row has errored
|
const timeout = setTimeout(() => {
|
||||||
}, [error, stopPolling]);
|
if (!subData) {
|
||||||
|
setSubFailed(true);
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
|
}, [subData]);
|
||||||
|
|
||||||
|
// handle polling
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleStartPoll = () => startPolling(POLL_INTERVAL);
|
const handleStartPoll = () => startPolling(POLL_INTERVAL);
|
||||||
const handleStopPoll = () => stopPolling();
|
const handleStopPoll = () => stopPolling();
|
||||||
@ -68,6 +78,7 @@ export const RowData = ({
|
|||||||
};
|
};
|
||||||
}, [startPolling, stopPolling, error]);
|
}, [startPolling, stopPolling, error]);
|
||||||
|
|
||||||
|
// measure response time
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isValidUrl(url)) return;
|
if (!isValidUrl(url)) return;
|
||||||
// every time we get data measure response speed
|
// every time we get data measure response speed
|
||||||
@ -131,6 +142,15 @@ export const RowData = ({
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSubFailed = (
|
||||||
|
subError: ApolloError | undefined,
|
||||||
|
subFailed: boolean
|
||||||
|
) => {
|
||||||
|
if (subError) return true;
|
||||||
|
if (subFailed) return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{id !== CUSTOM_NODE_KEY && (
|
{id !== CUSTOM_NODE_KEY && (
|
||||||
@ -161,11 +181,11 @@ export const RowData = ({
|
|||||||
</LayoutCell>
|
</LayoutCell>
|
||||||
<LayoutCell
|
<LayoutCell
|
||||||
label={t('Subscription')}
|
label={t('Subscription')}
|
||||||
isLoading={subLoading}
|
isLoading={subFailed ? false : subLoading}
|
||||||
hasError={Boolean(subError)}
|
hasError={getSubFailed(subError, subFailed)}
|
||||||
dataTestId="subscription-cell"
|
dataTestId="subscription-cell"
|
||||||
>
|
>
|
||||||
{getSubscriptionDisplayValue(subData?.busEvents, subError)}
|
{getSubscriptionDisplayValue(subFailed, subData?.busEvents, subError)}
|
||||||
</LayoutCell>
|
</LayoutCell>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@ -195,10 +215,11 @@ const getBlockDisplayValue = (block?: number, error?: ApolloError) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getSubscriptionDisplayValue = (
|
const getSubscriptionDisplayValue = (
|
||||||
|
subFailed: boolean,
|
||||||
events?: { id: string }[] | null,
|
events?: { id: string }[] | null,
|
||||||
error?: ApolloError
|
error?: ApolloError
|
||||||
) => {
|
) => {
|
||||||
if (error) {
|
if (subFailed || error) {
|
||||||
return t('No');
|
return t('No');
|
||||||
}
|
}
|
||||||
if (events?.length) {
|
if (events?.length) {
|
||||||
|
Loading…
Reference in New Issue
Block a user