Skip to content

Commit

Permalink
Catch 404 in reward v2 and accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
kacpersaw committed Jun 3, 2024
1 parent 6cdbd2d commit 032fc20
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/routes/accounts/account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ const Account = () => {
const [txData, setTxData] = useState();
const [smidge, setSmidge] = useState({ value: 0, unit: 'SMH' });

const [error, setError] = useState();
if (error) throw error;

useEffect(() => {
if (store.network.value === null) return;
fetchAPI(`${store.network.value}${name}/${params.id}`).then((res) => {
setData(res.data[0]);
setSmidge(parseSmidge(res.data[0].balance));
if (res.data) {
setData(res.data[0]);
setSmidge(parseSmidge(res.data[0].balance));
} else {
const err = new Error('Not found');
err.id = params.id;
setError(err);
}
});
}, [store.network.value, params.id]);

Expand Down
25 changes: 22 additions & 3 deletions src/routes/rewardv2.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,32 @@ const RewardV2 = () => {
const [data, setData] = useState();
const [smidge, setSmidge] = useState({ value: 0, unit: 'SMH' });

const [error, setError] = useState();
if (error) throw error;

useEffect(() => {
if (store.network.value === null) return;
if (!params.smesherId.startsWith('0x')) {
const err = new Error('Smesher ID should start with \'0x\'');
err.id = params.smesherId;
setError(err);
}

fetchAPI(`${store.network.value}v2/${name}/${params.smesherId}/${params.layer}`).then((res) => {
setData(res.data[0]);
setSmidge(parseSmidge(res.data[0].total));
if (res.data) {
setData(res.data[0]);
setSmidge(parseSmidge(res.data[0].total));
} else {
const err = new Error('Not found');
err.id = params.smesherId;
setError(err);
}
}).catch(() => {
const err = new Error('Not found');
err.id = params.smesherId;
setError(err);
});
}, [store.network.value]);
}, [store.network.value, params.smesherId, params.layer]);

return (
<>
Expand Down

0 comments on commit 032fc20

Please sign in to comment.