-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #320 from yieldprotocol/marcomariscal/issue308
issue308: update pool view to include strategy language instead of pool
- Loading branch information
Showing
7 changed files
with
106 additions
and
68 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 |
---|---|---|
@@ -1,4 +1,48 @@ | ||
import { useContext, useEffect, useState } from 'react'; | ||
import { ethers, BigNumber } from 'ethers'; | ||
import { UserContext } from '../../contexts/UserContext'; | ||
import { ChainContext } from '../../contexts/ChainContext'; | ||
import { IAsset, IStrategy } from '../../types'; | ||
import { cleanValue } from '../../utils/appUtils'; | ||
import { mulDecimal, divDecimal } from '../../utils/yieldMath'; | ||
|
||
export const usePoolHelpers = (input: string | undefined) => { | ||
const poolMax = input; | ||
return { poolMax }; | ||
/* STATE FROM CONTEXT */ | ||
const { | ||
userState: { selectedStrategyAddr, strategyMap, assetMap, activeAccount }, | ||
} = useContext(UserContext); | ||
|
||
const strategy: IStrategy | undefined = strategyMap?.get(selectedStrategyAddr); | ||
const strategyBase: IAsset | undefined = assetMap?.get(strategy?.baseId); | ||
|
||
/* LOCAL STATE */ | ||
const [poolPercentPreview, setPoolPercentPreview] = useState<string | undefined>(); | ||
const [poolTokenPreview, setPoolTokenPreview] = useState<string | undefined>(input); | ||
const [maxPool, setMaxPool] = useState<string | undefined>(); | ||
|
||
/* SET MAX VALUES */ | ||
useEffect(() => { | ||
if (activeAccount) { | ||
/* Checks asset selection and sets the max available value */ | ||
(async () => { | ||
const max = await strategyBase?.getBalance(activeAccount); | ||
if (max) setMaxPool(ethers.utils.formatUnits(max, strategyBase?.decimals).toString()); | ||
})(); | ||
} | ||
}, [input, activeAccount, strategyBase]); | ||
|
||
useEffect(() => { | ||
if (input && strategy) { | ||
// update the below to get an actual estimated token value based on the input | ||
const _poolTokenPreview = BigNumber.from(ethers.utils.parseUnits(input, strategyBase?.decimals)); | ||
const _poolPercentPreview = cleanValue( | ||
mulDecimal(divDecimal(_poolTokenPreview, strategy.strategyTotalSupply!), '100'), | ||
2 | ||
); | ||
|
||
setPoolPercentPreview(_poolPercentPreview); | ||
} | ||
}, [input, strategy, strategyBase]); | ||
|
||
return { maxPool, poolTokenPreview, poolPercentPreview }; | ||
}; |
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
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