Skip to content

Instantly share code, notes, and snippets.

@ajb413

ajb413/App.tsx Secret

Last active December 10, 2022 00:00
Show Gist options
  • Save ajb413/3b15101a0a7a845ed239de0824c2b78d to your computer and use it in GitHub Desktop.
Save ajb413/3b15101a0a7a845ed239de0824c2b78d to your computer and use it in GitHub Desktop.
useAsyncEffect(async () => {
let borrowerData;
try {
borrowerData = JSON.parse(window.localStorage.getItem('borrowerData'));
borrowerData = borrowerData[market] || {};
} catch(e) {
borrowerData = {};
}
if ((!borrowerData.lastFetch || borrowerData.lastFetch < (Date.now() - 60 * 1000)) && market) {
const res = await fetch(`http://localhost:3000/borrowers/${market}`);
borrowerData = await res.json();
borrowerData.lastFetch = Date.now();
window.localStorage.setItem('borrowerData', JSON.stringify({ [market]: borrowerData }));
}
setBorrowers(borrowerData);
}, [web3, timer]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment