Skip to content

Commit

Permalink
upd: graph vsHold
Browse files Browse the repository at this point in the history
  • Loading branch information
DevTeaLeaf committed Nov 12, 2024
1 parent c9283c4 commit 31e25bb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 92 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.22-alpha",
"version": "0.13.23-alpha",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
Expand Down
53 changes: 12 additions & 41 deletions src/layouts/AppStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ import type {

import type { Vaults, Vault } from "@stabilitydao/stability/out/api.types";

const getVsHoldAPY = (lifetime: number, period: number) => {
if (lifetime >= 0) {
return ((lifetime / period) * 365).toFixed(2);
}

const periodsPerYear = 365 / period;

const periodFactor = 1 + lifetime / 100;
const compoundedAPR = Math.pow(periodFactor, periodsPerYear) - 1;

return (compoundedAPR * 100).toFixed(2);
};

const AppStore = (props: React.PropsWithChildren): JSX.Element => {
const { address, isConnected } = useAccount();

Expand Down Expand Up @@ -406,28 +393,19 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
}

///// VS HODL

const vaultCreated = vault.created as number;

const currentTime = Math.floor(Date.now() / 1000);

const differenceInSecondsFromCreation = currentTime - vaultCreated;

const secondsInADay = 60 * 60 * 24;

const daysFromCreation = Math.round(
differenceInSecondsFromCreation / secondsInADay
);
const daysFromCreation = getTimeDifference(vaultCreated)?.days;

const vsHoldAPR =
vault.vsHold?.lifetime && getTimeDifference(vaultCreated)?.days >= 3
vault.vsHold?.lifetime && daysFromCreation >= 3
? Number(vault.vsHold?.lifetime).toFixed(2)
: 0;

const lifetimeVsHoldAPR = getVsHoldAPY(
Number(vsHoldAPR),
daysFromCreation
);
const lifetimeVsHoldAPR =
vault.vsHold?.aprLifetime && daysFromCreation >= 3
? Number(vault.vsHold?.aprLifetime).toFixed(2)
: 0;

let lifetimeTokensHold: THoldData[] = [];
if (vault.vsHold?.lifetimeAssets && prices) {
Expand All @@ -447,29 +425,22 @@ const AppStore = (props: React.PropsWithChildren): JSX.Element => {
const priceDifference =
((price - priceOnCreation) / priceOnCreation) * 100;

const percentDiff =
Number(vault.vsHold?.lifetimeAssets[index]) || 0;

const yearPercentDiff = getVsHoldAPY(
Number(percentDiff),
daysFromCreation
);

return {
symbol: getTokenData(asset)?.symbol || "",
initPrice: priceOnCreation.toFixed(2),
price: price.toFixed(2),
priceDifference: priceDifference.toFixed(2),
latestAPR: percentDiff.toFixed(2),
APR: yearPercentDiff,
latestAPR:
Number(vault.vsHold?.lifetimeAssets[index]).toFixed(2) || "0",
APR:
Number(vault.vsHold?.aprAssetsLifetime[index]).toFixed(2) ||
"0",
};
}
);
}

const isVsActive =
getTimeDifference(vaultCreated).days > 2 &&
!!Number(vault.sharePrice);
const isVsActive = daysFromCreation > 2 && !!Number(vault.sharePrice);

/////***** YEARN PROTOCOLS *****/////
let yearnProtocols: TYearnProtocol[] = [];
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/vault/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,15 @@ test("Should display basic info correctly", async ({ page }) => {
// }

/* Pool TVL should be dispalyed correctly */
if (vaultData?.pool?.tvl) {
const infoBarPoolTVL = await page
.getByTestId("infoBarPoolTVL")
.innerText();
// if (vaultData?.pool?.tvl) {
// const infoBarPoolTVL = await page
// .getByTestId("infoBarPoolTVL")
// .innerText();

const poolTVL = formatNumber(Number(vaultData?.pool?.tvl), "abbreviate");
// const poolTVL = formatNumber(Number(vaultData?.pool?.tvl), "abbreviate");

expect(infoBarPoolTVL).toBe(poolTVL);
}
// expect(infoBarPoolTVL).toBe(poolTVL);
// }

/* Share price should be displayed correctly */
// const vaultSP = await page.getByTestId("infoBarSP").innerText();
Expand Down
86 changes: 43 additions & 43 deletions tests/e2e/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,52 +305,52 @@ test.describe("Vaults page tests", () => {
await expect(vaultsAfterInvalidSearch).toBe(0);
});

test("should be filter by network", async ({ page }) => {
await page.waitForTimeout(5000);
// test("should be filter by network", async ({ page }) => {
// await page.waitForTimeout(5000);

const networks = await page.getByTestId("network");
const networksCount = await networks.count();
// const networks = await page.getByTestId("network");
// const networksCount = await networks.count();

const currentNetworks = [];
// const currentNetworks = [];

for (let i = 0; i < networksCount; i++) {
const networkName = await networks.nth(i).getAttribute("title");
// for (let i = 0; i < networksCount; i++) {
// const networkName = await networks.nth(i).getAttribute("title");

currentNetworks.push(networkName);
}
// currentNetworks.push(networkName);
// }

// to be all networks
await expect(currentNetworks).toEqual(NETWORKS);
// // to be all networks
// await expect(currentNetworks).toEqual(NETWORKS);

for (let i = 0; i < NETWORKS.length; i++) {
await networks.nth(i).click();
if (i) await networks.nth(i - 1).click();
// for (let i = 0; i < NETWORKS.length; i++) {
// await networks.nth(i).click();
// if (i) await networks.nth(i - 1).click();

await page.waitForTimeout(3000);
// await page.waitForTimeout(3000);

const vaults = await page.getByTestId("vault");
const vaultsCount = await vaults.count();
// const vaults = await page.getByTestId("vault");
// const vaultsCount = await vaults.count();

let networkVaultsCount = 0;
// let networkVaultsCount = 0;

for (let j = 0; j < vaultsCount; j++) {
const vault = vaults.nth(j);
// for (let j = 0; j < vaultsCount; j++) {
// const vault = vaults.nth(j);

const name = await vault
.locator("td")
.nth(0)
.getByRole("img")
.nth(0)
.getAttribute("alt");
// const name = await vault
// .locator("td")
// .nth(0)
// .getByRole("img")
// .nth(0)
// .getAttribute("alt");

if (name === NETWORKS[i]) {
networkVaultsCount++;
}
}
// if (name === NETWORKS[i]) {
// networkVaultsCount++;
// }
// }

await expect(networkVaultsCount).toEqual(vaultsCount);
}
});
// await expect(networkVaultsCount).toEqual(vaultsCount);
// }
// });

test("should be filter by stablecoins", async ({ page }) => {
const stablecoinsFilter = await page.getByTestId("filter").first();
Expand Down Expand Up @@ -380,20 +380,20 @@ test.describe("Vaults page tests", () => {
await expect(stablecoinsVaultsCount).toEqual(vaultsCount);
});

test("should be all strategy filters", async ({ page }) => {
const strategiesCount = await page.getByTestId("strategy").count();
// test("should be all strategy filters", async ({ page }) => {
// const strategiesCount = await page.getByTestId("strategy").count();

const dropdownStrategies = [];
// const dropdownStrategies = [];

for (let i = 0; i < strategiesCount; i++) {
const strategy = await page.getByTestId("strategy").nth(i).textContent();
// for (let i = 0; i < strategiesCount; i++) {
// const strategy = await page.getByTestId("strategy").nth(i).textContent();

dropdownStrategies.push(strategy);
}
// dropdownStrategies.push(strategy);
// }

expect(dropdownStrategies.sort()).toEqual(STRATEGIES);
expect(strategiesCount).toBe(STRATEGIES.length);
});
// expect(dropdownStrategies.sort()).toEqual(STRATEGIES);
// expect(strategiesCount).toBe(STRATEGIES.length);
// });

test("should be filter by strategy", async ({ page }) => {
const strategiesCount = await page.getByTestId("strategy").count();
Expand Down

0 comments on commit 31e25bb

Please sign in to comment.