forked from burrowfdn/burrow-cash
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tokennetbalance farm display ui in stake modal (#92)
- Loading branch information
1 parent
c3e422b
commit 4c9c6c4
Showing
5 changed files
with
84 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { createSelector } from "@reduxjs/toolkit"; | ||
import { isEmpty } from "lodash"; | ||
import { RootState } from "../store"; | ||
import { getTokennetMarketAPY } from "../../hooks/useRewards"; | ||
import { AssetsState } from "../assetState"; | ||
|
||
export const getMarketRewardsData = createSelector( | ||
(state: RootState) => state.assets, | ||
(assets) => { | ||
const result = getMarketRewardsDataUtil(assets); | ||
return result; | ||
}, | ||
); | ||
|
||
export function getMarketRewardsDataUtil(assets: AssetsState) { | ||
const allFarms = assets?.allFarms; | ||
if (!allFarms || !assets?.data) return {}; | ||
const { tokenNetBalance } = allFarms; | ||
// filter ended farms | ||
const newTokenNetBalance = {}; | ||
Object.entries(tokenNetBalance || {}).forEach(([assetId, rewards]) => { | ||
const activeFarms = filterEndedFarms(rewards); | ||
if (!isEmpty(activeFarms)) { | ||
newTokenNetBalance[assetId] = activeFarms; | ||
} | ||
}); | ||
const tokenNetBalanceMarketFarmData = Object.entries(newTokenNetBalance).map(([assetId]) => { | ||
const asset = assets.data[assetId]; | ||
return { | ||
asset, | ||
marketAPY: getTokennetMarketAPY(asset, assets), | ||
}; | ||
}); | ||
// eslint-disable-next-line consistent-return | ||
return { | ||
tokenNetBalance: tokenNetBalanceMarketFarmData, | ||
booster_log_base: getBoosterLogBaseFromFarms(newTokenNetBalance), | ||
}; | ||
} | ||
function filterEndedFarms(rewards: any) { | ||
const newRewards = {}; | ||
Object.entries(rewards).forEach(([rewardId, rewardData]: any) => { | ||
if (rewardData.remaining_rewards !== "0") { | ||
newRewards[rewardId] = rewardData; | ||
} | ||
}); | ||
return newRewards; | ||
} | ||
function getBoosterLogBaseFromFarms(marketFarms) { | ||
const farms = Object.values(marketFarms)?.[0]; | ||
const farm = Object.values(farms || {})?.[0]; | ||
if (farm) { | ||
return farm.booster_log_base; | ||
} | ||
return ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters