Skip to content

Commit

Permalink
feat(trading): update l2 icons
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive authored and tomasklim committed Feb 4, 2025
1 parent 683cc27 commit 8a6e468
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
39 changes: 36 additions & 3 deletions packages/components/src/components/AssetLogo/AssetLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';

import styled from 'styled-components';

import { getNetwork, getNetworkByCoingeckoId, isNetworkSymbol } from '@suite-common/wallet-config';
import { getAssetLogoUrl } from '@trezor/asset-utils';
import { Elevation, borders, mapElevationToBackground, mapElevationToBorder } from '@trezor/theme';

Expand Down Expand Up @@ -59,6 +60,29 @@ const ElevatedLogo = (props: LogoProps) => {
return <Logo {...props} $elevation={elevation} />;
};

export const getCoingeckoIdAndContractAddressIncludesNativeTokens = (
coingeckoId: string,
contractAddress: string | undefined,
) => {
const mainNetworkSymbol = getNetworkByCoingeckoId(coingeckoId)?.displaySymbol.toLowerCase();

if (
contractAddress === '0x0000000000000000000000000000000000000000' &&
mainNetworkSymbol &&
isNetworkSymbol(mainNetworkSymbol)
) {
return {
coingeckoId: getNetwork(mainNetworkSymbol).tradeCryptoId ?? coingeckoId,
contractAddress: undefined,
};
}

return {
coingeckoId,
contractAddress,
};
};

export const AssetLogo = ({
size,
coingeckoId,
Expand All @@ -71,9 +95,18 @@ export const AssetLogo = ({
}: AssetLogoProps) => {
const [isLoading, setIsLoading] = useState(true);
const [isPlaceholder, setIsPlaceholder] = useState(!shouldTryToFetch);

const logoUrl = getAssetLogoUrl({ coingeckoId, contractAddress });
const logoUrl2x = getAssetLogoUrl({ coingeckoId, contractAddress, quality: '@2x' });
const { coingeckoId: coingeckoIdLogo, contractAddress: contractAddressLogo } =
getCoingeckoIdAndContractAddressIncludesNativeTokens(coingeckoId, contractAddress);

const logoUrl = getAssetLogoUrl({
coingeckoId: coingeckoIdLogo,
contractAddress: contractAddressLogo,
});
const logoUrl2x = getAssetLogoUrl({
coingeckoId: coingeckoIdLogo,
contractAddress: contractAddressLogo,
quality: '@2x',
});

const frameProps = pickAndPrepareFrameProps(rest, allowedAssetLogoFrameProps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const AssetItem = ({
const getCoinLogo = () =>
isCoinSymbol(symbol) ? <CoinLogo size={24} symbol={symbol} /> : null;
const displaySymbol = getDisplaySymbol(ticker, contractAddress);
const nativeContractAddress = '0x0000000000000000000000000000000000000000';

return (
<ClickableContainer
Expand All @@ -62,7 +61,7 @@ export const AssetItem = ({
}
>
<Row data-testid={dataTestId} gap={spacings.sm}>
{coingeckoId && !coingeckoId.includes(nativeContractAddress) ? (
{coingeckoId ? (
<AssetLogo
size={24}
coingeckoId={coingeckoId}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import styled from 'styled-components';

import { cryptoIdToNetwork, isCryptoIdForNativeToken, parseCryptoId } from '@suite-common/trading';
import { parseCryptoId } from '@suite-common/trading';
import { AssetLogo } from '@trezor/components';
import { CoinLogo } from '@trezor/product-components';

import { TradingCoinLogoProps } from 'src/types/trading/trading';

Expand All @@ -15,11 +14,6 @@ export const TradingCoinLogo = ({
className,
}: TradingCoinLogoProps) => {
const { networkId, contractAddress } = parseCryptoId(cryptoId);
const network = cryptoIdToNetwork(cryptoId);

if (isCryptoIdForNativeToken(cryptoId) && network) {
return <CoinLogo size={size} symbol={network.symbol} />;
}

return (
<Wrapper className={className}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,13 @@ export const TradingFormInputCryptoSelect = <
if (!network) return null;

const { symbol } = network;
const isNativeToken = isCryptoIdForNativeToken(option.value);
// for native tokens (eg. base) to use tradeCryptoId
const coingeckoId = isNativeToken ? network.tradeCryptoId : option.coingeckoId;

return {
...option,
ticker: option.ticker || option.label,
symbol,
contractAddress: option.contractAddress ?? null,
coingeckoId,
coingeckoId: option.coingeckoId,
};
})
.filter(option => option !== null),
Expand Down

0 comments on commit 8a6e468

Please sign in to comment.