0ae70899e5
* tidy: refactor text * feat: added unstyled select * tidy: useToggle * tidy: useToggle * MP-2344: first unstyled version of Select * fix: fixed the build * MP-2344: progress on the Select * MP-2344: almost finished the Select * env: update wallet-connector * fix: relative imports * env: started adding osmo-test-5 contracts * refactor: rename stargate.ts to d.ts * env: adjusted tsconfig.json * feat: updated modals to use the dialog element * env: added mainnet config * env: enabled osmosis-1 * tidy: refactor * fix: fixed decimals * fix: fixed the NaN issue for ETH * fix: fixed price calculations for large decimals * feat: finished conversion to <dialog> * fix: fixed some logic issues * fix: layout fix * fix: fixed token slider and input * tidy: format * fix: added currentAccount hook * Mp 2345 withdraw from credit account flow (#180) * MP-2345: created the barebone for withdraw * MP-2351: changed the AccountHealth logic * MP-2345: enabled withdraw function * MP-2351: added animation to Accordion * fix: adjusted according to feedback * fix: reduced complexity * tidy: format * env: enabled osmo-test-5 support * feat: added USDC.n * env: updated dependencies * fix: hotfixed react-draggable * fix: fixed vault info
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { Coin } from '@cosmjs/stargate'
|
|
|
|
import { FormattedNumber } from 'components/FormattedNumber'
|
|
import useStore from 'store'
|
|
import { getMarketAssets } from 'utils/assets'
|
|
import { BN } from 'utils/helpers'
|
|
|
|
interface Props {
|
|
coin: Coin
|
|
className?: string
|
|
isApproximation?: boolean
|
|
}
|
|
|
|
export default function DisplayCurrency(props: Props) {
|
|
const displayCurrency = useStore((s) => s.displayCurrency)
|
|
const prices = useStore((s) => s.prices)
|
|
|
|
function convertToDisplayAmount(coin: Coin) {
|
|
const price = prices.find((price) => price.denom === coin.denom)
|
|
const asset = getMarketAssets().find((asset) => asset.denom === coin.denom)
|
|
const displayPrice = prices.find((price) => price.denom === displayCurrency.denom)
|
|
|
|
if (!price || !asset || !displayPrice) return '0'
|
|
|
|
return BN(coin.amount)
|
|
.shiftedBy(-1 * asset.decimals)
|
|
.times(price.amount)
|
|
.div(displayPrice.amount)
|
|
.toNumber()
|
|
}
|
|
|
|
return (
|
|
<FormattedNumber
|
|
className={props.className}
|
|
amount={convertToDisplayAmount(props.coin)}
|
|
options={{
|
|
minDecimals: 0,
|
|
maxDecimals: 2,
|
|
abbreviated: true,
|
|
prefix: `${props.isApproximation ? '~ ' : ''}${
|
|
displayCurrency.prefix ? displayCurrency.prefix : ''
|
|
}`,
|
|
suffix: displayCurrency.symbol ? ` ${displayCurrency.symbol}` : '',
|
|
}}
|
|
/>
|
|
)
|
|
}
|