Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non fractal price data formatter #6348

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/components/Discover/TrendingTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ButtonPressAnimation } from '../animations';
import { useFarcasterAccountForWallets } from '@/hooks/useFarcasterAccountForWallets';
import { ImgixImage } from '../images';
import { useRemoteConfig } from '@/model/remoteConfig';
import { useAccountSettings } from '@/hooks';

const t = i18n.l.trending_tokens;

Expand Down Expand Up @@ -91,6 +92,7 @@ function FilterButton({ icon, label, onPress }: { onPress?: VoidFunction; label:
}

function useTrendingTokensData() {
const { nativeCurrency } = useAccountSettings();
const remoteConfig = useRemoteConfig();
const { chainId, category, timeframe, sort } = useTrendingTokensStore(state => ({
chainId: state.chainId,
Expand All @@ -109,6 +111,7 @@ function useTrendingTokensData() {
sortDirection: SortDirection.Desc,
limit: remoteConfig.trending_tokens_limit,
walletAddress: walletAddress,
currency: nativeCurrency,
});
}

Expand Down Expand Up @@ -569,16 +572,21 @@ function SortFilter() {
);
}

function TrendingTokensLoader() {
const { trending_tokens_limit } = useRemoteConfig();

return (
<View style={{ flex: 1 }}>
{Array.from({ length: trending_tokens_limit }).map((_, index) => (
<TrendingTokenLoadingRow key={index} />
))}
</View>
);
}
Comment on lines +575 to +585
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should show the correct amount of loading rows instead of the previously hardcoded 10


function TrendingTokenData() {
const { data: trendingTokens, isLoading } = useTrendingTokensData();
if (isLoading)
return (
<View style={{ flex: 1 }}>
{Array.from({ length: 10 }).map((_, index) => (
<TrendingTokenLoadingRow key={index} />
))}
</View>
);
if (isLoading) return <TrendingTokensLoader />;

return (
<FlatList
Expand Down
9 changes: 6 additions & 3 deletions src/helpers/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@ export function formatCurrency(
value: string | number,
{ valueIfNaN = '', currency = store.getState().settings.nativeCurrency }: CurrencyFormatterOptions = {}
): string {
const decimals = supportedNativeCurrencies[currency].decimals;
const numericString = typeof value === 'number' ? toDecimalString(value) : String(value);
if (isNaN(+numericString)) return valueIfNaN;

const currencySymbol = supportedNativeCurrencies[currency].symbol;

const [whole, fraction = '00'] = numericString.split('.');
const [whole, fraction = ''] = numericString.split('.');
if (fraction === '') {
const formattedWhole = formatNumber(numericString, { decimals, useOrderSuffix: true });
return `${currencySymbol}${formattedWhole}`;
}

const formattedWhole = formatNumber(whole, { decimals: 0, useOrderSuffix: true });
const formattedFraction = formatFraction(fraction);

// if it ends with a non-numeric character, it's in compact notation like '1.2K'
if (isNaN(+formattedWhole[formattedWhole.length - 1])) return `${currencySymbol}${formattedWhole}`;

Expand Down
Loading