Skip to content

Commit cf9f68a

Browse files
Retrieving processingStarted events from backend (#27)
* fix: processingStarted call via backend * fix: relocating dapppnode hook * fix: remove comments
1 parent 0950a77 commit cf9f68a

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { useLidoSWR } from '@lido-sdk/react';
2+
import { STRATEGY_CONSTANT } from 'consts/swr-strategies';
3+
import { fetchWithRetry } from 'dappnode/utils/fetchWithRetry';
4+
import useDappnodeUrls from 'dappnode/hooks/use-dappnode-urls';
5+
6+
interface Event {
7+
RefSlot: number;
8+
Hash: number[];
9+
Raw: {
10+
address: string;
11+
topics: string[];
12+
data: string;
13+
blockNumber: string;
14+
transactionHash: string;
15+
transactionIndex: string;
16+
blockHash: string;
17+
logIndex: string;
18+
removed: boolean;
19+
};
20+
}
21+
22+
export const useLastRewrdsTx = (config = STRATEGY_CONSTANT) => {
23+
const { backendUrl } = useDappnodeUrls();
24+
25+
return useLidoSWR(
26+
['fee-oracle-report-tx'],
27+
async () => {
28+
const url = `${backendUrl}/api/v0/events_indexer/processing_started`;
29+
const options = {
30+
method: 'GET',
31+
headers: { 'Content-Type': 'application/json' },
32+
};
33+
const response = await fetchWithRetry(url, options, 5000);
34+
if (!response.ok) {
35+
throw new Error('Failed to fetch processing started events');
36+
}
37+
const events: Event[] = await response.json();
38+
const txs = events
39+
.sort(
40+
(a, b) =>
41+
parseInt(a.Raw.blockNumber, 16) - parseInt(b.Raw.blockNumber, 16),
42+
)
43+
.map((event) => {
44+
return event.Raw.transactionHash;
45+
});
46+
return txs[txs.length - 1];
47+
},
48+
config,
49+
);
50+
};

features/dashboard/bond/last-rewards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
getPrevRewardsFrame,
1818
useLastOperatorRewards,
1919
useLastRewardsSlot,
20-
useLastRewrdsTx,
2120
useNodeOperatorInfo,
2221
} from 'shared/hooks';
2322
import { formatDate, formatPercent } from 'utils';
@@ -29,6 +28,7 @@ import {
2928
RowHeader,
3029
RowTitle,
3130
} from './styles';
31+
import { useLastRewrdsTx } from 'dappnode/hooks/useLastRewardsFrame-api'; // DAPPNODE
3232

3333
export const LastRewards: FC = () => {
3434
const { data: lastRewards, initialLoading: isLoading } =

shared/hooks/useLastRewardsFrame.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export const useLastOperatorRewards = () => {
143143
);
144144
};
145145

146+
// DAPPNODE: Replaced by 'dappnode/hooks/useLastRewardsFrame-api'
146147
export const useLastRewrdsTx = (config = STRATEGY_CONSTANT) => {
147148
const feeOracle = useCSFeeOracleRPC();
148149
const { deploymentBlockNumber } = getCsmConstants();

0 commit comments

Comments
 (0)