* feat: added simulateTrade * MP-3330: added vault positions to the useUpdated Account * tidy: format * tidy: refactor * Health indicator change preview (#410) * fix: adjusted the AccountDetail width * feat: added health indicator updates * Update src/components/Account/AccountDetails.tsx Co-authored-by: Yusuf Seyrek <yusufseyrek@users.noreply.github.com> * fix: created a function for the back- and foregroundColors * fix: updated tailwind conf * fix: fixed the useHealthColorAndLabel function --------- Co-authored-by: Yusuf Seyrek <yusufseyrek@users.noreply.github.com> Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> * fix: added updatedAccount to AccountSummary (#414) Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> * fix: added a new way of calulating values to vaults * fix: refactored the displayCurrency * fix: fixed the subtitles, to not nest <p> tags * MP-3330: added comparison to the vault mechanics * fix: fixed tests * fix: updated the borrow slider percentage on vaults * fix: addressed change request * update displayValue stuff * fixed wrong display conversions * fix: fixed the display price and renamed getDepositsAndLendsAfterCoinSpent * fix test and update DisplayCurrency * tidy: refactor * tidy: rename method --------- Co-authored-by: Yusuf Seyrek <yusufseyrek@users.noreply.github.com> Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { BNCoin } from 'types/classes/BNCoin'
|
|
import { BN } from 'utils/helpers'
|
|
export function isNumber(value: unknown) {
|
|
if (typeof value === 'string' && value !== '') {
|
|
return !isNaN(Number(value))
|
|
}
|
|
|
|
if (typeof value === 'number') {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
export const convertAprToApy = (apr: number, numberOfCompoundingPeriods: number): number => {
|
|
return ((1 + apr / 100 / numberOfCompoundingPeriods) ** numberOfCompoundingPeriods - 1) * 100
|
|
}
|
|
|
|
export const convertApyToApr = (apy: number, numberOfCompoundingPeriods: number): number => {
|
|
const periodicRate = (1 + apy) ** (1 / numberOfCompoundingPeriods) - 1
|
|
return periodicRate * numberOfCompoundingPeriods
|
|
}
|
|
|
|
export const combineBNCoins = (coins: BNCoin[]): BNCoin[] => {
|
|
const combinedMap: { [key: string]: number } = {}
|
|
|
|
coins.forEach((coin) => {
|
|
if (combinedMap.hasOwnProperty(coin.denom)) {
|
|
combinedMap[coin.denom] += coin.amount.toNumber()
|
|
} else {
|
|
combinedMap[coin.denom] = coin.amount.toNumber()
|
|
}
|
|
})
|
|
|
|
const combinedArray: BNCoin[] = Object.keys(combinedMap).map(
|
|
(denom) =>
|
|
new BNCoin({
|
|
denom,
|
|
amount: BN(combinedMap[denom]).toString(),
|
|
}),
|
|
)
|
|
|
|
return combinedArray
|
|
}
|