Skip to content

Commit

Permalink
fix merge conflict with dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
bthaile committed Feb 7, 2025
1 parent 8d91d71 commit 2b84363
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 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.
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
15 changes: 12 additions & 3 deletions src/ui/views/Wallet/TransferList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { useTransferList } from '@/ui/hooks/useTransferListHook';
import { useProfileStore } from '@/ui/stores/profileStore';
import { useTransferListStore } from '@/ui/stores/transferListStore';
import activity from 'ui/FRWAssets/svg/activity.svg';
import { useWallet } from 'ui/utils';

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

dayjs.extend(relativeTime);

Expand Down Expand Up @@ -56,6 +59,7 @@ const TransferList = () => {
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 Down Expand Up @@ -83,9 +87,14 @@ const TransferList = () => {
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 2b84363

Please sign in to comment.