Skip to content

Commit

Permalink
rename Token price to value and associated files, fixed display in ac…
Browse files Browse the repository at this point in the history
…tivities
  • Loading branch information
bthaile committed Feb 7, 2025
1 parent ccf00b8 commit ded3c00
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';

import { formatPrice } from './formatPrice';
import { formatPrice } from './formatTokenValue';

describe('formatPrice', () => {
it('should handle zero', () => {
Expand Down
File renamed without changes.
12 changes: 9 additions & 3 deletions src/ui/views/Staking/TransferList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import activity from 'ui/FRWAssets/svg/activity.svg';
import { useWallet } from 'ui/utils';

import IconExec from '../../../components/iconfont/IconExec';
import { TokenPrice } from '../TokenDetail/TokenValue';

dayjs.extend(relativeTime);

Expand Down Expand Up @@ -103,9 +104,14 @@ const TransferList = ({ setCount }) => {
color: isReceive && isFT ? 'success.main' : 'text.primary',
}}
>
{props.type === 1
? (isReceive ? '+' : '-') + `${props.amount}`
: `${props.token.split('.')[2]}`}
{props.type === 1 ? (
<TokenPrice
value={`${props.amount}`.replace(/^-/, '')}
prefix={isReceive ? '+' : '-'}
/>
) : (
`${props.token.split('.')[2]}`
)}
</Typography>
) : (
<Skeleton variant="text" width={35} height={15} />
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/TokenDetail/TokenInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { addDotSeparators } from 'ui/utils/number';

import IconChevronRight from '../../../components/iconfont/IconChevronRight';

import { TokenPrice } from './TokenPrice';
import { TokenPrice } from './TokenValue';

// import tips from 'ui/FRWAssets/svg/tips.svg';

Expand Down Expand Up @@ -224,7 +224,7 @@ const TokenInfoCard = ({
<Typography variant="body1" color="text.secondary" sx={{ fontSize: '16px' }}>
<Box component="span" sx={{ marginRight: '0.25rem' }}>
<TokenPrice
price={balance * price}
value={balance * price}
prefix="$"
postFix={chrome.i18n.getMessage('USD')}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import React from 'react';

import { formatPrice } from '@/shared/utils/formatPrice';
import { formatPrice } from '@/shared/utils/formatTokenValue';

interface TokenPriceProps {
price: number | string;
value: number | string;
className?: string;
showPrefix?: boolean;
prefix?: string;
postFix?: string;
}

export const TokenPrice: React.FC<TokenPriceProps> = ({
price,
value,
className = '',
prefix = '$',
postFix = '',
}) => {
if (price === 0 || price === null || price === undefined || typeof price === 'string') {
if (value === 0 || value === null || value === undefined) {
return <span className={className}>{''}</span>;
}

const { formattedPrice } = formatPrice(price);
// convert value to number if it's a string
const valueNumber = typeof value === 'string' ? parseFloat(value) : value;

const { formattedPrice } = formatPrice(valueNumber);
const { leadingPart, zeroPart, endingPart } = formattedPrice;

return (
Expand Down
7 changes: 3 additions & 4 deletions src/ui/views/Wallet/Coinlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useHistory } from 'react-router-dom';
import { formatLargeNumber } from 'ui/utils/number';

import IconCreate from '../../../components/iconfont/IconCreate';
import { TokenPrice } from '../TokenDetail/TokenPrice';
import { TokenPrice } from '../TokenDetail/TokenValue';

const CoinList = ({ data, ableFt, isActive, childType, coinLoading }) => {
// const wallet = useWallet();
Expand Down Expand Up @@ -54,7 +54,6 @@ const CoinList = ({ data, ableFt, isActive, childType, coinLoading }) => {
variant="body1"
sx={{ fontSize: 12, fontWeight: '500', textAlign: 'end', color: 'text.secondary' }}
>
{props.change === null || props.change === 0 ? '' : '$'}
{props.secondary === null || props.secondary === 0 ? '' : props.secondary}
</Typography>
) : (
Expand Down Expand Up @@ -111,7 +110,7 @@ const CoinList = ({ data, ableFt, isActive, childType, coinLoading }) => {
}}
>
{props.change === null ? '-' : ''}
<TokenPrice price={props.price} prefix="$" />
<TokenPrice value={props.price} prefix="$" />
</Typography>
{props.change !== 0 && (
<Typography
Expand Down Expand Up @@ -192,7 +191,7 @@ const CoinList = ({ data, ableFt, isActive, childType, coinLoading }) => {
secondaryAction={
<EndListItemText
primary={parseFloat(coin.balance).toFixed(3)}
secondary={<TokenPrice price={coin.balance * coin.price} />}
secondary={<TokenPrice value={coin.balance * coin.price} prefix="$" />}
unit={coin.unit}
change={parseFloat(coin.change24h.toFixed(2))}
/>
Expand Down
14 changes: 11 additions & 3 deletions src/ui/views/Wallet/TransferList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import React, { useCallback, useEffect, useState } from 'react';
import { formatString } from '@/shared/utils/address';
import activity from 'ui/FRWAssets/svg/activity.svg';
import { useWallet } from 'ui/utils';

import { TokenPrice } from '../TokenDetail/TokenValue';
// import IconExec from '../../../components/iconfont/IconExec';
// import ExpandLessRoundedIcon from '@mui/icons-material/ExpandLessRounded';
dayjs.extend(relativeTime);
Expand Down Expand Up @@ -87,6 +89,7 @@ const TransferList = ({ setCount }) => {
const EndListItemText = (props) => {
const isReceive = props.txType === 2;
const isFT = props.type === 1;
const isContractCall = props.type === 1 && props.token === '';

const calculateMaxWidth = () => {
const textLength =
Expand All @@ -113,9 +116,14 @@ const TransferList = ({ setCount }) => {
textOverflow: 'ellipsis',
}}
>
{props.type === 1
? (isReceive ? '+' : '-') + `${props.amount}`.replace(/^-/, '')
: `${props.token}`}
{props.type === 1 ? (
<TokenPrice
value={`${props.amount}`.replace(/^-/, '')}
prefix={!isContractCall ? (isReceive ? '+' : '-') : ''}
/>
) : (
`${props.token}`
)}
</Typography>
) : (
<Skeleton variant="text" width={35} height={15} />
Expand Down

0 comments on commit ded3c00

Please sign in to comment.