mango-v4-ui/components/shared/BankAmountWithValue.tsx

49 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-01-28 17:13:36 -08:00
import { Bank } from '@blockworks-foundation/mango-v4'
import Decimal from 'decimal.js'
import FormatNumericValue from './FormatNumericValue'
const BankAmountWithValue = ({
amount = 0,
bank,
2023-11-27 03:33:33 -08:00
decimals,
2023-01-28 17:13:36 -08:00
fixDecimals = true,
stacked,
value,
2023-11-02 17:27:20 -07:00
isPrivate,
2023-01-28 17:13:36 -08:00
}: {
amount: Decimal | number | string
bank: Bank
2023-11-27 03:33:33 -08:00
decimals?: number
2023-01-28 17:13:36 -08:00
fixDecimals?: boolean
stacked?: boolean
value?: number
2023-11-02 17:27:20 -07:00
isPrivate?: boolean
2023-01-28 17:13:36 -08:00
}) => {
return (
<p className={`font-mono text-th-fgd-2 ${stacked ? 'text-right' : ''}`}>
<>
<FormatNumericValue
value={amount}
2023-11-27 03:33:33 -08:00
decimals={
decimals
? decimals
: amount && fixDecimals
? bank.mintDecimals
: undefined
}
2023-01-28 17:13:36 -08:00
/>{' '}
<span className={`text-th-fgd-4 ${stacked ? 'block' : ''}`}>
<FormatNumericValue
value={value ? value : Number(amount) * bank.uiPrice}
2023-11-27 03:33:33 -08:00
decimals={decimals || fixDecimals ? 2 : undefined}
2023-01-28 17:13:36 -08:00
isUsd={true}
2023-11-02 17:27:20 -07:00
isPrivate={isPrivate}
2023-01-28 17:13:36 -08:00
/>
</span>
</>
</p>
)
}
export default BankAmountWithValue