Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
diff --git a/dist/index.d.cts b/dist/index.d.cts
index e6741164a2d67dabbd6b74ee34a07c37cb41d8c9..6dd7a98e3143c45ba3b636be3f0acd615adb87ab 100644
--- a/dist/index.d.cts
+++ b/dist/index.d.cts
@@ -49,5 +49,5 @@ export { calculateBalanceChangeForAllWallets, calculateBalanceChangeForAccountGr
export type { AssetsByAccountGroup, AccountGroupAssets, Asset, AssetListState, } from "./selectors/token-selectors.cjs";
export { selectAssetsBySelectedAccountGroup, selectAllAssets, } from "./selectors/token-selectors.cjs";
export { createFormatters } from "./utils/formatters.cjs";
-export type { SortTrendingBy, TrendingAsset, TokenSearchItem, TokenAsset, TokenRwaData, TokenSecurityData, TokenSecurityFeature, TokenSecurityHolder, TokenSecurityMarket, TokenSecurityFees, TokenSecurityFinancialStats, TokenSecurityMetadata, } from "./token-service.cjs";
+export type { SortTrendingBy, TrendingAsset, TokenSearchItem, TokenAsset, TrendingTokensQueryParams, TokenRwaData, TokenSecurityData, TokenSecurityFeature, TokenSecurityHolder, TokenSecurityMarket, TokenSecurityFees, TokenSecurityFinancialStats, TokenSecurityMetadata, } from "./token-service.cjs";
//# sourceMappingURL=index.d.cts.map
\ No newline at end of file
diff --git a/dist/token-service.cjs b/dist/token-service.cjs
index e420ea7b8ba28eae8efcec239e2fbe54caaa3916..54991205703a6ed3e00b73f1547fa982c6553020 100644
--- a/dist/token-service.cjs
+++ b/dist/token-service.cjs
@@ -98,25 +98,13 @@ function getTokenAssetsURL(options) {
/**
* Get the trending tokens URL for the given networks and search query.
*
- * @param options - Options for getting trending tokens.
- * @param options.chainIds - Array of CAIP format chain IDs (e.g., ['eip155:1', 'eip155:137', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp']).
- * @param options.sort - The sort field.
- * @param options.minLiquidity - The minimum liquidity.
- * @param options.minVolume24hUsd - The minimum volume 24h in USD.
- * @param options.maxVolume24hUsd - The maximum volume 24h in USD.
- * @param options.minMarketCap - The minimum market cap.
- * @param options.maxMarketCap - The maximum market cap.
- * @param options.excludeLabels - Array of labels to exclude (e.g., ['stable_coin', 'blue_chip']).
- * @param options.includeRwaData - Optional flag to include RWA data in the results (defaults to false).
- * @param options.usePriceApiData - Optional flag to use price API data in the results (defaults to false).
- * @param options.includeTokenSecurityData - Optional flag to include token security data in the results (defaults to false).
+ * @param options - Options bag: `chainIds` (required) plus any query params.
* @returns The trending tokens URL.
*/
function getTrendingTokensURL(options) {
const encodedChainIds = options.chainIds
.map((id) => encodeURIComponent(id))
.join(',');
- // Add the rest of query params if they are defined
const queryParams = new URLSearchParams();
const { chainIds, excludeLabels, ...rest } = options;
Object.entries(rest).forEach(([key, value]) => {
@@ -201,38 +189,26 @@ exports.searchTokens = searchTokens;
/**
* Get the trending tokens for the given chains.
*
- * @param options - Options for getting trending tokens.
- * @param options.chainIds - The chains to get the trending tokens for.
- * @param options.sortBy - The sort by field.
- * @param options.minLiquidity - The minimum liquidity.
- * @param options.minVolume24hUsd - The minimum volume 24h in USD.
- * @param options.maxVolume24hUsd - The maximum volume 24h in USD.
- * @param options.minMarketCap - The minimum market cap.
- * @param options.maxMarketCap - The maximum market cap.
- * @param options.excludeLabels - Array of labels to exclude (e.g., ['stable_coin', 'blue_chip']).
- * @param options.includeRwaData - Optional flag to include RWA data in the results (defaults to true).
- * @param options.usePriceApiData - Optional flag to use price API data in the results (defaults to true).
- * @param options.includeTokenSecurityData - Optional flag to include token security data in the results (defaults to false).
+ * Accepts all known query parameters plus any additional ones via the
+ * index signature on {@link TrendingTokensQueryParams}. New API parameters
+ * can be passed without updating this function.
+ *
+ * @param options - Options bag: `chainIds` (required) plus any query params
+ * supported by the v3 trending endpoint.
* @returns The trending tokens.
* @throws Will throw if the request fails.
*/
-async function getTrendingTokens({ chainIds, sortBy, minLiquidity, minVolume24hUsd, maxVolume24hUsd, minMarketCap, maxMarketCap, excludeLabels, includeRwaData = true, usePriceApiData = true, includeTokenSecurityData, }) {
+async function getTrendingTokens(options) {
+ const { chainIds, ...rest } = options;
if (chainIds.length === 0) {
console.error('No chains provided');
return [];
}
const trendingTokensURL = getTrendingTokensURL({
chainIds,
- sort: sortBy,
- minLiquidity,
- minVolume24hUsd,
- maxVolume24hUsd,
- minMarketCap,
- maxMarketCap,
- excludeLabels,
- includeRwaData,
- usePriceApiData,
- includeTokenSecurityData,
+ includeRwaData: true,
+ usePriceApiData: true,
+ ...rest,
});
try {
const result = await (0, controller_utils_1.handleFetch)(trendingTokensURL);
diff --git a/dist/token-service.d.cts b/dist/token-service.d.cts
index 38521c00fd2e37c5976936ec55ace02ef803b663..c0e9eb61e4622747e8dabbcfededc30c360b33bd 100644
--- a/dist/token-service.d.cts
+++ b/dist/token-service.d.cts
@@ -5,6 +5,27 @@ export declare const TOKEN_METADATA_NO_SUPPORT_ERROR = "TokenService Error: Netw
* The sort by field for trending tokens.
*/
export type SortTrendingBy = 'm5_trending' | 'h1_trending' | 'h6_trending' | 'h24_trending';
+/**
+ * Shared query-parameter type for the v3 trending tokens endpoint.
+ *
+ * Known parameters are explicitly typed for autocomplete and documentation.
+ * The index signature allows new API parameters to pass through without
+ * requiring a core release — callers can add any additional key/value and
+ * it will be forwarded as a query parameter.
+ */
+export type TrendingTokensQueryParams = {
+ sort?: SortTrendingBy;
+ minLiquidity?: number;
+ minVolume24hUsd?: number;
+ maxVolume24hUsd?: number;
+ minMarketCap?: number;
+ maxMarketCap?: number;
+ excludeLabels?: string[];
+ includeRwaData?: boolean;
+ usePriceApiData?: boolean;
+ includeTokenSecurityData?: boolean;
+ [key: string]: string | number | boolean | string[] | undefined;
+};
/**
* Fetch the list of token metadata for a given network. This request is cancellable using the
* abort signal passed in.
@@ -138,34 +159,18 @@ export type TrendingAsset = {
/**
* Get the trending tokens for the given chains.
*
- * @param options - Options for getting trending tokens.
- * @param options.chainIds - The chains to get the trending tokens for.
- * @param options.sortBy - The sort by field.
- * @param options.minLiquidity - The minimum liquidity.
- * @param options.minVolume24hUsd - The minimum volume 24h in USD.
- * @param options.maxVolume24hUsd - The maximum volume 24h in USD.
- * @param options.minMarketCap - The minimum market cap.
- * @param options.maxMarketCap - The maximum market cap.
- * @param options.excludeLabels - Array of labels to exclude (e.g., ['stable_coin', 'blue_chip']).
- * @param options.includeRwaData - Optional flag to include RWA data in the results (defaults to true).
- * @param options.usePriceApiData - Optional flag to use price API data in the results (defaults to true).
- * @param options.includeTokenSecurityData - Optional flag to include token security data in the results (defaults to false).
+ * Accepts all known query parameters plus any additional ones via the
+ * index signature on {@link TrendingTokensQueryParams}. New API parameters
+ * can be passed without updating this function.
+ *
+ * @param options - Options bag: `chainIds` (required) plus any query params
+ * supported by the v3 trending endpoint.
* @returns The trending tokens.
* @throws Will throw if the request fails.
*/
-export declare function getTrendingTokens({ chainIds, sortBy, minLiquidity, minVolume24hUsd, maxVolume24hUsd, minMarketCap, maxMarketCap, excludeLabels, includeRwaData, usePriceApiData, includeTokenSecurityData, }: {
+export declare function getTrendingTokens(options: {
chainIds: CaipChainId[];
- sortBy?: SortTrendingBy;
- minLiquidity?: number;
- minVolume24hUsd?: number;
- maxVolume24hUsd?: number;
- minMarketCap?: number;
- maxMarketCap?: number;
- excludeLabels?: string[];
- includeRwaData?: boolean;
- usePriceApiData?: boolean;
- includeTokenSecurityData?: boolean;
-}): Promise<TrendingAsset[]>;
+} & TrendingTokensQueryParams): Promise<TrendingAsset[]>;
/**
* The token asset type returned by the /assets endpoint.
*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback, useMemo } from 'react';
import { TouchableOpacity, View } from 'react-native';
import { useSelector } from 'react-redux';
import Text, {
TextColor,
TextVariant,
Expand Down Expand Up @@ -33,6 +34,7 @@ import type { TrendingFilterContext } from '../TrendingTokensList/TrendingTokens
import { TokenDetailsSource } from '../../../TokenDetails/constants/constants';
import { useTrendingTokenPress } from '../../hooks/useTrendingTokenPress/useTrendingTokenPress';
import SecurityTrustInlineBadge from '../../../SecurityTrust/components/SecurityTrustInlineBadge/SecurityTrustInlineBadge';
import { selectCurrentCurrency } from '../../../../../selectors/currencyRateController';

/**
* Gets the text color for price percentage change
Expand Down Expand Up @@ -129,6 +131,7 @@ const TrendingTokenRowItem = ({
testIdInstanceKey,
}: TrendingTokenRowItemProps) => {
const { styles } = useStyles(styleSheet, {});
const currentCurrency = useSelector(selectCurrentCurrency) || 'USD';

const caipChainId = useMemo(
() => getCaipChainIdFromAssetId(token.assetId),
Expand Down Expand Up @@ -232,7 +235,7 @@ const TrendingTokenRowItem = ({
</View>
<View style={styles.rightContainer}>
<Text variant={TextVariant.BodyMDMedium} color={TextColor.Default}>
{formatPriceWithSubscriptNotation(token.price)}
{formatPriceWithSubscriptNotation(token.price, currentCurrency)}
</Text>
{parseFloat(token.price) === 0 ? (
<Text variant={TextVariant.BodySM} color={TextColor.Alternative}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useCallback, useMemo, useEffect, useState, useRef } from 'react';
import { useSelector } from 'react-redux';
import type { CaipChainId } from '@metamask/utils';
import {
getTrendingTokens,
SortTrendingBy,
TrendingTokensQueryParams,
} from '@metamask/assets-controllers';
import { useStableArray } from '../../../Perps/hooks/useStableArray';
import { TRENDING_NETWORKS_LIST } from '../../utils/trendingNetworksList';
import { NetworkToCaipChainId } from '../../../NetworkMultiSelector/NetworkMultiSelector.constants';
import { selectCurrentCurrency } from '../../../../../selectors/currencyRateController';

/**
* Baseline thresholds for multi-chain requests
Expand Down Expand Up @@ -140,25 +142,24 @@ interface FetchOptions {
* Hook for handling trending tokens request
* @returns {Object} An object containing the trending tokens results, loading state, error, and a function to trigger fetch
*/
export const useTrendingRequest = (options: {
chainIds?: CaipChainId[];
sortBy?: SortTrendingBy;
minLiquidity?: number;
minVolume24hUsd?: number;
maxVolume24hUsd?: number;
minMarketCap?: number;
maxMarketCap?: number;
}) => {
export const useTrendingRequest = (
options: {
chainIds?: CaipChainId[];
} & TrendingTokensQueryParams,
) => {
const {
chainIds: providedChainIds = [],
sortBy = 'h24_trending',
sort = 'h24_trending',
minLiquidity: providedMinLiquidity,
minVolume24hUsd: providedMinVolume24hUsd,
maxVolume24hUsd,
minMarketCap = 0,
maxMarketCap,
} = options;

// Get user's selected currency from Redux store (default to 'usd' if not set)
const currentCurrency = useSelector(selectCurrentCurrency) || 'usd';

// Use provided chainIds or default to trending networks
const chainIds = useMemo((): CaipChainId[] => {
if (providedChainIds.length > 0) {
Expand All @@ -168,13 +169,17 @@ export const useTrendingRequest = (options: {
}, [providedChainIds]);

// Calculate thresholds based on selected chains
const minLiquidity = useMemo(
() => providedMinLiquidity ?? getMinLiquidityForChains(chainIds),
const minLiquidity: number = useMemo(
() =>
(providedMinLiquidity as number | undefined) ??
getMinLiquidityForChains(chainIds),
[providedMinLiquidity, chainIds],
);

const minVolume24hUsd = useMemo(
() => providedMinVolume24hUsd ?? getMinVolume24hForChains(chainIds),
const minVolume24hUsd: number = useMemo(
() =>
(providedMinVolume24hUsd as number | undefined) ??
getMinVolume24hForChains(chainIds),
[providedMinVolume24hUsd, chainIds],
);

Expand Down Expand Up @@ -217,14 +222,15 @@ export const useTrendingRequest = (options: {
try {
const resultsToStore = await getTrendingTokens({
chainIds: stableChainIds,
sortBy,
sort,
minLiquidity,
minVolume24hUsd,
maxVolume24hUsd,
minMarketCap,
maxMarketCap,
maxVolume24hUsd: maxVolume24hUsd as number | undefined,
minMarketCap: minMarketCap as number | undefined,
maxMarketCap: maxMarketCap as number | undefined,
excludeLabels: ['stable_coin', 'blue_chip'],
includeTokenSecurityData: true,
vsCurrency: currentCurrency.toLowerCase(),
});
// Only update state if this is still the current request
if (currentRequestId === requestIdRef.current) {
Expand All @@ -246,12 +252,13 @@ export const useTrendingRequest = (options: {
},
[
stableChainIds,
sortBy,
sort,
minLiquidity,
minVolume24hUsd,
maxVolume24hUsd,
minMarketCap,
maxMarketCap,
currentCurrency,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jest.mock('../../../../hooks/useAddPopularNetwork');
jest.mock('../../../../../selectors/networkController', () => ({
selectNetworkConfigurationsByCaipChainId: jest.fn(),
}));
jest.mock('../../../../../selectors/currencyRateController', () => ({
selectCurrentCurrency: jest.fn(() => 'USD'),
}));
jest.mock('../../services/TrendingFeedSessionManager', () => ({
__esModule: true,
default: { getInstance: jest.fn() },
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@
"@metamask/keyring-api@npm:^21.4.0": "23.1.0",
"@metamask/keyring-api@npm:^21.6.0": "23.1.0",
"@metamask/keyring-api@npm:^22.0.0": "23.1.0",
"@metamask/bridge-status-controller@npm:^71.0.0": "patch:@metamask/bridge-status-controller@npm%3A71.1.0#~/.yarn/patches/@metamask-bridge-status-controller-npm-71.1.0-6140a0bdf3.patch"
"@metamask/bridge-status-controller@npm:^71.0.0": "patch:@metamask/bridge-status-controller@npm%3A71.1.0#~/.yarn/patches/@metamask-bridge-status-controller-npm-71.1.0-6140a0bdf3.patch",
"@metamask/assets-controllers@npm:^105.1.0": "patch:@metamask/assets-controllers@npm%3A105.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-105.1.0-76332163aa.patch",
"@metamask/assets-controllers@npm:^105.0.0": "patch:@metamask/assets-controllers@npm%3A105.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-105.1.0-76332163aa.patch"
},
"dependencies": {
"@braze/react-native-sdk": "patch:@braze/react-native-sdk@npm%3A19.1.0#~/.yarn/patches/@braze-react-native-sdk-npm-19.1.0-076-reactmoduleinfo.patch",
Expand All @@ -241,7 +243,7 @@
"@metamask/app-metadata-controller": "^2.0.0",
"@metamask/approval-controller": "^9.0.0",
"@metamask/assets-controller": "^6.2.1",
"@metamask/assets-controllers": "^105.0.0",
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A105.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-105.1.0-76332163aa.patch",
"@metamask/authenticated-user-storage": "^1.0.0",
"@metamask/base-controller": "^9.0.1",
"@metamask/bitcoin-wallet-snap": "^1.10.1",
Expand Down
Loading
Loading