1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

use locale value as Conversion prop

This commit is contained in:
ClaudiaHolhos 2022-06-03 16:29:36 +03:00
parent 20546dea3a
commit 6cbdb0d722
13 changed files with 48 additions and 40 deletions

View File

@ -3,6 +3,7 @@ import { ComponentStory, ComponentMeta } from '@storybook/react'
import AssetSelection, { import AssetSelection, {
AssetSelectionProps AssetSelectionProps
} from '@shared/FormFields/AssetSelection' } from '@shared/FormFields/AssetSelection'
import { assetSelectionAsset } from '../../../../../.storybook/__mockdata__'
export default { export default {
title: 'Component/@shared/FormFields/AssetSelection', title: 'Component/@shared/FormFields/AssetSelection',
@ -17,36 +18,19 @@ interface Props {
args: AssetSelectionProps args: AssetSelectionProps
} }
const assetsList = [
{
did: 'did:op:07baafad66d21e61789d2d71ee1684c2d7235f8efefc59bfabf4fd984bf5c09d',
name: 'Pool test',
price: '22.004619932610114622',
checked: true,
symbol: 'OCEAN-NFT'
},
{
did: 'did:op:3f0f273e030e38fa24d5c725bb73fc799cc424847e05bc064ff63813d30fae36',
name: 'Dynamic price test',
price: '11.103104637669568064',
checked: true,
symbol: 'PUCPOR-86'
}
]
export const Default: Props = Template.bind({}) export const Default: Props = Template.bind({})
Default.args = { Default.args = {
assets: assetsList assets: assetSelectionAsset
} }
export const Multiple: Props = Template.bind({}) export const Multiple: Props = Template.bind({})
Multiple.args = { Multiple.args = {
assets: assetsList, assets: assetSelectionAsset,
multiple: true multiple: true
} }
export const Disabled: Props = Template.bind({}) export const Disabled: Props = Template.bind({})
Disabled.args = { Disabled.args = {
assets: assetsList, assets: assetSelectionAsset,
disabled: true disabled: true
} }

View File

@ -6,6 +6,7 @@ import useNftFactory from '@hooks/contracts/useNftFactory'
import { NftFactory } from '@oceanprotocol/lib' import { NftFactory } from '@oceanprotocol/lib'
import Conversion from '@shared/Price/Conversion' import Conversion from '@shared/Price/Conversion'
import { generateNftCreateData, NftMetadata } from '@utils/nft' import { generateNftCreateData, NftMetadata } from '@utils/nft'
import { useUserPreferences } from '@context/UserPreferences'
const getEstGasFee = async ( const getEstGasFee = async (
address: string, address: string,
@ -37,6 +38,8 @@ export default function TxFee({
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { prices } = usePrices() const { prices } = usePrices()
const nftFactory = useNftFactory() const nftFactory = useNftFactory()
const { locale } = useUserPreferences()
const [gasFee, setGasFee] = useState('') const [gasFee, setGasFee] = useState('')
useEffect(() => { useEffect(() => {
@ -55,7 +58,7 @@ export default function TxFee({
return gasFee ? ( return gasFee ? (
<p> <p>
Gas fee estimation for this artwork Gas fee estimation for this artwork
<Conversion price={gasFee} /> <Conversion locale={locale} price={gasFee} />
</p> </p>
) : accountId ? ( ) : accountId ? (
<p> <p>

View File

@ -1,8 +1,7 @@
import React from 'react' import React from 'react'
import { ComponentStory, ComponentMeta } from '@storybook/react' import { ComponentStory, ComponentMeta } from '@storybook/react'
import Conversion, { ConversionProps } from '@shared/Price/Conversion' import Conversion, { ConversionProps } from '@shared/Price/Conversion'
import { usePrices } from '@context/Prices' import { locale } from '../../../../../.storybook/__mockdata__'
import { useUserPreferences } from '@context/UserPreferences'
export default { export default {
title: 'Component/@shared/Price/Conversion', title: 'Component/@shared/Price/Conversion',
@ -10,12 +9,6 @@ export default {
} as ComponentMeta<typeof Conversion> } as ComponentMeta<typeof Conversion>
const Template: ComponentStory<typeof Conversion> = (args: ConversionProps) => { const Template: ComponentStory<typeof Conversion> = (args: ConversionProps) => {
const { prices } = usePrices()
const { currency, locale } = useUserPreferences()
console.log('PRICES: ', prices)
if (!prices || !currency || !locale) return
return <Conversion {...args} /> return <Conversion {...args} />
} }
@ -25,11 +18,13 @@ interface Props {
export const Default: Props = Template.bind({}) export const Default: Props = Template.bind({})
Default.args = { Default.args = {
price: '11.12333' price: '11.12333',
locale
} }
export const HideApproximateSymbol: Props = Template.bind({}) export const HideApproximateSymbol: Props = Template.bind({})
HideApproximateSymbol.args = { HideApproximateSymbol.args = {
price: '11.12333', price: '11.12333',
locale,
hideApproximateSymbol: true hideApproximateSymbol: true
} }

View File

@ -11,15 +11,17 @@ export interface ConversionProps {
price: string // expects price in OCEAN, not wei price: string // expects price in OCEAN, not wei
className?: string className?: string
hideApproximateSymbol?: boolean hideApproximateSymbol?: boolean
locale: string
} }
export default function Conversion({ export default function Conversion({
price, price,
className, className,
hideApproximateSymbol hideApproximateSymbol,
locale
}: ConversionProps): ReactElement { }: ConversionProps): ReactElement {
const { prices } = usePrices() const { prices } = usePrices()
const { currency, locale } = useUserPreferences() const { currency } = useUserPreferences()
const [priceConverted, setPriceConverted] = useState('0.00') const [priceConverted, setPriceConverted] = useState('0.00')
// detect fiat, only have those kick in full @coingecko/cryptoformat formatting // detect fiat, only have those kick in full @coingecko/cryptoformat formatting
@ -56,7 +58,7 @@ export default function Conversion({
(match) => `<span>${match}</span>` (match) => `<span>${match}</span>`
) )
setPriceConverted(convertedFormattedHTMLstring) setPriceConverted(convertedFormattedHTMLstring)
}, [price, prices, currency, locale, isFiat]) }, [price, prices, currency, isFiat, locale])
return ( return (
<span <span

View File

@ -45,7 +45,7 @@ export default function PriceUnit({
<Badge label="pool" className={styles.badge} /> <Badge label="pool" className={styles.badge} />
)} )}
</div> </div>
{conversion && <Conversion price={price} />} {conversion && <Conversion price={price} locale={locale} />}
</> </>
)} )}
</div> </div>

View File

@ -35,7 +35,11 @@ export default function Token({
/> />
</div> </div>
{conversion && ( {conversion && (
<Conversion price={balance} className={`${styles.conversion}`} /> <Conversion
price={balance}
className={`${styles.conversion}`}
locale={locale}
/>
)} )}
</> </>
) )

View File

@ -28,6 +28,7 @@ export default function MarketStatsTooltip({
<Conversion <Conversion
price={totalValueLockedInOcean?.[chainId] || '0'} price={totalValueLockedInOcean?.[chainId] || '0'}
hideApproximateSymbol hideApproximateSymbol
locale={locale}
/>{' '} />{' '}
<abbr title="Total Value Locked">TVL</abbr> <abbr title="Total Value Locked">TVL</abbr>
{' | '} {' | '}

View File

@ -20,6 +20,7 @@ export default function MarketStatsTotal({
<Conversion <Conversion
price={`${total.totalValueLockedInOcean}`} price={`${total.totalValueLockedInOcean}`}
hideApproximateSymbol hideApproximateSymbol
locale={locale}
/>{' '} />{' '}
<abbr title="Total Value Locked">TVL</abbr> across{' '} <abbr title="Total Value Locked">TVL</abbr> across{' '}
<strong>{total.pools}</strong> asset pools that contain{' '} <strong>{total.pools}</strong> asset pools that contain{' '}

View File

@ -66,7 +66,7 @@ export default function Details(): ReactElement {
{formatCurrency(Number(value), '', locale, false, { {formatCurrency(Number(value), '', locale, false, {
significantFigures: 4 significantFigures: 4
})} })}
{key === 'ocean' && <Conversion price={value} />} {key === 'ocean' && <Conversion price={value} locale={locale} />}
</li> </li>
))} ))}

View File

@ -34,6 +34,7 @@ export default function Stats({
}): ReactElement { }): ReactElement {
const { chainIds } = useUserPreferences() const { chainIds } = useUserPreferences()
const { poolShares, assets, assetsTotal, sales } = useProfile() const { poolShares, assets, assetsTotal, sales } = useProfile()
const { locale } = useUserPreferences()
const [publisherTvl, setPublisherTvl] = useState('0') const [publisherTvl, setPublisherTvl] = useState('0')
const [totalTvl, setTotalTvl] = useState('0') const [totalTvl, setTotalTvl] = useState('0')
@ -90,11 +91,19 @@ export default function Stats({
<div className={styles.stats}> <div className={styles.stats}>
<NumberUnit <NumberUnit
label="Liquidity in Own Assets" label="Liquidity in Own Assets"
value={<Conversion price={publisherTvl} hideApproximateSymbol />} value={
<Conversion
price={publisherTvl}
hideApproximateSymbol
locale={locale}
/>
}
/> />
<NumberUnit <NumberUnit
label="Liquidity" label="Liquidity"
value={<Conversion price={totalTvl} hideApproximateSymbol />} value={
<Conversion price={totalTvl} hideApproximateSymbol locale={locale} />
}
/> />
<NumberUnit label={`Sale${sales === 1 ? '' : 's'}`} value={sales} /> <NumberUnit label={`Sale${sales === 1 ? '' : 's'}`} value={sales} />
<NumberUnit label="Published" value={assetsTotal} /> <NumberUnit label="Published" value={assetsTotal} />

View File

@ -5,6 +5,7 @@ import Token from '../../../@shared/Token'
import Decimal from 'decimal.js' import Decimal from 'decimal.js'
import { AssetPoolShare } from './index' import { AssetPoolShare } from './index'
import { calcSingleOutGivenPoolIn } from '@utils/pool' import { calcSingleOutGivenPoolIn } from '@utils/pool'
import { useUserPreferences } from '@context/UserPreferences'
export function Liquidity({ export function Liquidity({
row, row,
@ -14,6 +15,7 @@ export function Liquidity({
type: string type: string
}) { }) {
const [liquidity, setLiquidity] = useState('0') const [liquidity, setLiquidity] = useState('0')
const { locale } = useUserPreferences()
useEffect(() => { useEffect(() => {
let calculatedLiquidity = '0' let calculatedLiquidity = '0'
@ -43,6 +45,7 @@ export function Liquidity({
price={liquidity} price={liquidity}
className={styles.totalLiquidity} className={styles.totalLiquidity}
hideApproximateSymbol hideApproximateSymbol
locale={locale}
/> />
<Token <Token
symbol={row.poolShare.pool.baseToken.symbol} symbol={row.poolShare.pool.baseToken.symbol}

View File

@ -5,6 +5,7 @@ import Logo from '@images/logo.svg'
import Conversion from '@shared/Price/Conversion' import Conversion from '@shared/Price/Conversion'
import { useField } from 'formik' import { useField } from 'formik'
import Error from '@shared/FormInput/Error' import Error from '@shared/FormInput/Error'
import { useUserPreferences } from '@context/UserPreferences'
export default function Coin({ export default function Coin({
datatokenOptions, datatokenOptions,
@ -18,6 +19,7 @@ export default function Coin({
readOnly?: boolean readOnly?: boolean
}): ReactElement { }): ReactElement {
const [field, meta] = useField(`pricing.${name}`) const [field, meta] = useField(`pricing.${name}`)
const { locale } = useUserPreferences()
return ( return (
<div className={styles.coin}> <div className={styles.coin}>
@ -47,7 +49,7 @@ export default function Coin({
{...field} {...field}
/> />
{datatokenOptions?.symbol === 'OCEAN' && ( {datatokenOptions?.symbol === 'OCEAN' && (
<Conversion price={field.value} /> <Conversion price={field.value} locale={locale} />
)} )}
<div> <div>
<Error meta={meta} /> <Error meta={meta} />

View File

@ -48,7 +48,11 @@ export default function Price({
<div className={styles.datatoken}> <div className={styles.datatoken}>
<h4> <h4>
= <strong>1</strong> {dataTokenOptions.symbol}{' '} = <strong>1</strong> {dataTokenOptions.symbol}{' '}
<Conversion price={field.value} className={styles.conversion} /> <Conversion
price={field.value}
className={styles.conversion}
locale={locale}
/>
</h4> </h4>
</div> </div>
</div> </div>