Skip to content

Commit

Permalink
Fix InfoTab oracleLogs refetching upon clicking Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed May 31, 2024
1 parent 965caae commit 1c2958e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions earn/src/components/markets/monitor/InfoTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ALOE_II_ORACLE_ADDRESS, APPROX_SECONDS_PER_BLOCK } from 'shared/lib/dat
import { GN } from 'shared/lib/data/GoodNumber';
import { LendingPair } from 'shared/lib/data/LendingPair';
import { useChainDependentState } from 'shared/lib/hooks/UseChainDependentState';
import { Address, Hash } from 'viem';
import { Address } from 'viem';

import InfoGraph, { InfoGraphColors, InfoGraphData, InfoGraphLabel } from './InfoGraph';
import StatsTable from './StatsTable';
Expand Down Expand Up @@ -78,14 +78,6 @@ export default function InfoTab(props: InfoTabProps) {
setOracleLogs(map);
}, [chainId, provider, lendingPairs.length, setOracleLogs]);

const setPendingTxnAndRefresh = useCallback(
(data: Hash) => {
setPendingTxn(data);
fetchOracleLogs();
},
[setPendingTxn, fetchOracleLogs]
);

// Fetch `oracleLogs`
useEffect(() => {
fetchOracleLogs();
Expand Down Expand Up @@ -131,6 +123,20 @@ export default function InfoTab(props: InfoTabProps) {
});
}, [lendingPairs, oracleLogs, blockNumbersToTimestamps]);

// NOTE: This is a roundabout way of refetching oracle logs after clicking "Update". TODO: Improve!!
useEffect(() => {
if (
lendingPairs.some((pair, i) => {
const latestTimestamp = latestTimestamps[i];
return (
latestTimestamp !== undefined && latestTimestamp > 0 && latestTimestamp < pair.lastWrite.getTime() / 1000
);
})
) {
fetchOracleLogs();
}
}, [lendingPairs, latestTimestamps, fetchOracleLogs]);

// Compute graph data
const graphData: InfoGraphData | undefined = useMemo(() => {
if (blockNumbersToTimestamps.size === 0) return undefined;
Expand Down Expand Up @@ -186,7 +192,7 @@ export default function InfoTab(props: InfoTabProps) {
rows={lendingPairs.map((lendingPair, i) => ({
lendingPair,
lastUpdatedTimestamp: latestTimestamps.at(i),
setPendingTxn: setPendingTxnAndRefresh,
setPendingTxn,
onMouseEnter: setHoveredPair,
}))}
chainId={chainId}
Expand Down

0 comments on commit 1c2958e

Please sign in to comment.