From 9e85c6e0dfd096dea6b3e741e46c3d49fa901fd3 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Mon, 7 Jun 2021 14:34:36 +0200 Subject: [PATCH] Get APY results from backend endpoint Get APY result from the website-backend instead of counring it on the frontend. --- src/hooks/useLiquidityRewardsAPY.js | 19 +++++++++++-------- src/redux.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/hooks/useLiquidityRewardsAPY.js b/src/hooks/useLiquidityRewardsAPY.js index 15181c45..85f67427 100644 --- a/src/hooks/useLiquidityRewardsAPY.js +++ b/src/hooks/useLiquidityRewardsAPY.js @@ -3,6 +3,7 @@ import { useEffect, useState } from "react" import LiquidityRewardsFactory, { SUPPORTED_LIQUIDITY_POOLS, } from "../lib/liquidity-rewards" +import { API_URL } from "../redux" const liquidityRewardsKEEPETH = LiquidityRewardsFactory.create( SUPPORTED_LIQUIDITY_POOLS.KEEP_ETH @@ -28,19 +29,21 @@ const useLiquidityRewardsAPY = () => { setIsFetching(true) Promise.all([ - liquidityRewardsKEEPETH.calculateAPY(), - liquidityRewardsTBTCSaddle.calculateAPY(), - liquidityRewardsTBTCETH.calculateAPY(), - liquidityRewardsKEEP.calculateAPY(), + fetch(`${API_URL}/calculate-apy?pool=KEEP_ETH`).then((res) => res.json()), + fetch(`${API_URL}/calculate-apy?pool=TBTC_SADDLE`).then((res) => + res.json() + ), + fetch(`${API_URL}/calculate-apy?pool=TBTC_ETH`).then((res) => res.json()), + fetch(`${API_URL}/calculate-apy?pool=KEEP`).then((res) => res.json()), ]) .then(([apyKEEPETH, apyTBTCSaddle, apyTBTCETH, apyKEEP]) => { if (shouldSetState) { setLiquidityRewardsAPYs( [ - { value: apyKEEPETH, pool: "KEEP/ETH" }, - { value: apyTBTCSaddle, pool: "TBTC/SADDLE" }, - { value: apyTBTCETH, pool: "TBTC/ETH" }, - { value: apyKEEP, pool: "KEEP" }, + { value: apyKEEPETH.data, pool: "KEEP/ETH" }, + { value: apyTBTCSaddle.data, pool: "TBTC/SADDLE" }, + { value: apyTBTCETH.data, pool: "TBTC/ETH" }, + { value: apyKEEP.data, pool: "KEEP" }, ].sort((a, b) => b.value - a.value) ) setIsFetching(false) diff --git a/src/redux.js b/src/redux.js index fbe0bb4a..0ca40ba8 100644 --- a/src/redux.js +++ b/src/redux.js @@ -73,7 +73,7 @@ export const reducers = { ajaxRequestStates: ajaxRequestStates, } -const API_URL = "https://backend.keep.network" +export const API_URL = "https://backend.keep.network" const stripQuery = () => { window.history.pushState(null, "", window.location.href.split("?")[0])