Skip to content

Commit

Permalink
upd: error message + chart + tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DevTeaLeaf committed Nov 2, 2024
1 parent d14a718 commit e45c958
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 204 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stability-ui",
"type": "module",
"version": "0.13.16-alpha",
"version": "0.13.17-alpha",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
Expand Down
35 changes: 13 additions & 22 deletions src/layouts/AppStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import {

import { wagmiConfig, platforms, PlatformABI, IVaultManagerABI } from "@web3";

import { ErrorMessage } from "@ui";

import {
calculateAPY,
getStrategyInfo,
Expand Down Expand Up @@ -100,7 +98,8 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {

const $lastTx = useStore(lastTx);
const $reload = useStore(reload);
const $error = useStore(error);

let isError = false;

const localVaults: {
[network: string]: TVaults;
Expand All @@ -110,6 +109,11 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {

let stabilityAPIData: TAPIData = {};

const handleError = (errType: string, description: string) => {
error.set({ state: true, type: errType, description });
isError = true;
};

const getDataFromStabilityAPI = async () => {
const maxRetries = 3;
let currentRetry = 0;
Expand All @@ -121,11 +125,7 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
stabilityAPIData = response.data;

if (stabilityAPIData?.error) {
error.set({
state: true,
type: "API",
description: stabilityAPIData?.error,
});
handleError("API", stabilityAPIData?.error);
return;
}

Expand All @@ -143,11 +143,7 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
await new Promise((resolve) => setTimeout(resolve, 1000));
} else {
console.error("API error:", err);
error.set({
state: true,
type: "API",
description: err?.message,
});
handleError("API", err);
}
}
}
Expand Down Expand Up @@ -697,6 +693,7 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
isVaultsLoaded.set(true);
} catch (txError: any) {

Check warning on line 694 in src/layouts/AppStore.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
console.log("BLOCKCHAIN ERROR:", txError);

error.set({
state: true,
type: "WEB3",
Expand Down Expand Up @@ -724,7 +721,9 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {

await getDataFromStabilityAPI();

getData();
if (!isError) {
getData();
}

if (chain?.id) {
currentChainID.set(String(chain?.id));
Expand All @@ -739,14 +738,6 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
fetchAllData();
}, [address, chain?.id, isConnected, $lastTx, $reload]);

if ($error.state && $error.type === "API") {
return (
<div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
<ErrorMessage type="API" />
</div>
);
}

return (
<WagmiLayout>
<div className="flex flex-col flex-1">{props.children}</div>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/Platform/components/Chains/Chain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const Chain: React.FC<IProps> = ({ chain }) => {
},
{
name: "TVL",
content: `\$${formatNumber($apiData?.total.chainTvl[chain.toString()] ? $apiData?.total.chainTvl[chain.toString()].toFixed(0) : "-", "withSpaces")}`,
content: `${formatNumber($apiData?.total.chainTvl[chain.toString()] ? $apiData?.total.chainTvl[chain.toString()].toFixed(0) : "-", "abbreviate")}`,
},
];

Expand Down Expand Up @@ -101,7 +101,7 @@ const Chain: React.FC<IProps> = ({ chain }) => {
content: chainVaults.length,
},
{
name: "Vaults APR",
name: "APR",
content: `${weightedAverageAPR.toFixed(2)}%`,
},
{
Expand Down
Loading

0 comments on commit e45c958

Please sign in to comment.