Merge branch 'feature/generalize-network-id' into develop

This commit is contained in:
Willian Mitsuda 2022-02-25 16:06:28 -03:00
commit b09449d38f
11 changed files with 101 additions and 54 deletions

View File

@ -10,7 +10,7 @@ RUN npm run build
FROM alpine:3.14.0 AS logobuilder FROM alpine:3.14.0 AS logobuilder
RUN apk add imagemagick parallel RUN apk add imagemagick parallel
WORKDIR /assets WORKDIR /assets
COPY trustwallet/blockchains/ethereum/assets /assets/ COPY trustwallet/blockchains/ethereum/assets /assets/1/
RUN find . -name logo.png | parallel magick convert {} -filter Lanczos -resize 32x32 {} RUN find . -name logo.png | parallel magick convert {} -filter Lanczos -resize 32x32 {}
FROM alpine:3.14.0 AS fourbytesbuilder FROM alpine:3.14.0 AS fourbytesbuilder

View File

@ -9,6 +9,7 @@ export interface IAddressResolver<T> {
} }
export type ResolvedAddressRenderer<T> = ( export type ResolvedAddressRenderer<T> = (
chainId: number,
address: string, address: string,
resolvedAddress: T, resolvedAddress: T,
linkable: boolean, linkable: boolean,

View File

@ -20,7 +20,7 @@ const AddressOrENSName: React.FC<AddressOrENSNameProps> = ({
const resolvedAddress = useResolvedAddress(provider, address); const resolvedAddress = useResolvedAddress(provider, address);
const linkable = address !== selectedAddress; const linkable = address !== selectedAddress;
if (!resolvedAddress) { if (!provider || !resolvedAddress) {
return ( return (
<PlainAddress <PlainAddress
address={address} address={address}
@ -42,7 +42,13 @@ const AddressOrENSName: React.FC<AddressOrENSNameProps> = ({
); );
} }
return renderer(address, resolvedName, linkable, !!dontOverrideColors); return renderer(
provider.network.chainId,
address,
resolvedName,
linkable,
!!dontOverrideColors
);
}; };
export default AddressOrENSName; export default AddressOrENSName;

View File

@ -59,6 +59,7 @@ const Content: React.FC<ContentProps> = ({ linkable, name }) => (
); );
export const ensRenderer: ResolvedAddressRenderer<string> = ( export const ensRenderer: ResolvedAddressRenderer<string> = (
chainId,
address, address,
resolvedAddress, resolvedAddress,
linkable, linkable,

View File

@ -37,6 +37,7 @@ const PlainString: React.FC<PlainStringProps> = ({
}; };
export const plainStringRenderer: ResolvedAddressRenderer<string> = ( export const plainStringRenderer: ResolvedAddressRenderer<string> = (
chainId,
address, address,
resolvedAddress, resolvedAddress,
linkable, linkable,

View File

@ -7,16 +7,17 @@ import { RuntimeContext } from "../useRuntime";
import { ChecksummedAddress } from "../types"; import { ChecksummedAddress } from "../types";
type TokenLogoProps = { type TokenLogoProps = {
chainId: number;
address: ChecksummedAddress; address: ChecksummedAddress;
name: string; name: string;
}; };
const TokenLogo: React.FC<TokenLogoProps> = ({ address, name }) => { const TokenLogo: React.FC<TokenLogoProps> = ({ chainId, address, name }) => {
const { config } = useContext(RuntimeContext); const { config } = useContext(RuntimeContext);
const srcList: string[] = []; const srcList: string[] = [];
if (config) { if (config) {
srcList.push(tokenLogoURL(config.assetsURLPrefix ?? "", address)); srcList.push(tokenLogoURL(config.assetsURLPrefix ?? "", chainId, address));
} }
const { src, isLoading } = useImage({ srcList, useSuspense: false }); const { src, isLoading } = useImage({ srcList, useSuspense: false });

View File

@ -5,6 +5,7 @@ import { ResolvedAddressRenderer } from "../api/address-resolver/address-resolve
import { TokenMeta } from "../types"; import { TokenMeta } from "../types";
type TokenNameProps = { type TokenNameProps = {
chainId: number;
address: string; address: string;
name: string; name: string;
symbol: string; symbol: string;
@ -13,6 +14,7 @@ type TokenNameProps = {
}; };
const TokenName: React.FC<TokenNameProps> = ({ const TokenName: React.FC<TokenNameProps> = ({
chainId,
address, address,
name, name,
symbol, symbol,
@ -29,6 +31,7 @@ const TokenName: React.FC<TokenNameProps> = ({
title={`${name} (${symbol}): ${address}`} title={`${name} (${symbol}): ${address}`}
> >
<Content <Content
chainId={chainId}
address={address} address={address}
linkable={true} linkable={true}
name={name} name={name}
@ -43,12 +46,19 @@ const TokenName: React.FC<TokenNameProps> = ({
className="flex items-baseline space-x-1 font-sans text-gray-700 truncate" className="flex items-baseline space-x-1 font-sans text-gray-700 truncate"
title={`${name} (${symbol}): ${address}`} title={`${name} (${symbol}): ${address}`}
> >
<Content address={address} linkable={false} name={name} symbol={symbol} /> <Content
chainId={chainId}
address={address}
linkable={false}
name={name}
symbol={symbol}
/>
</div> </div>
); );
}; };
type ContentProps = { type ContentProps = {
chainId: number;
address: string; address: string;
name: string; name: string;
symbol: string; symbol: string;
@ -56,6 +66,7 @@ type ContentProps = {
}; };
const Content: React.FC<ContentProps> = ({ const Content: React.FC<ContentProps> = ({
chainId,
address, address,
name, name,
symbol, symbol,
@ -65,7 +76,7 @@ const Content: React.FC<ContentProps> = ({
<div <div
className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`} className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`}
> >
<TokenLogo address={address} name={name} /> <TokenLogo chainId={chainId} address={address} name={name} />
</div> </div>
<span className="truncate"> <span className="truncate">
{name} ({symbol}) {name} ({symbol})
@ -74,12 +85,14 @@ const Content: React.FC<ContentProps> = ({
); );
export const tokenRenderer: ResolvedAddressRenderer<TokenMeta> = ( export const tokenRenderer: ResolvedAddressRenderer<TokenMeta> = (
chainId,
address, address,
tokenMeta, tokenMeta,
linkable, linkable,
dontOverrideColors dontOverrideColors
) => ( ) => (
<TokenName <TokenName
chainId={chainId}
address={address} address={address}
name={tokenMeta.name} name={tokenMeta.name}
symbol={tokenMeta.symbol} symbol={tokenMeta.symbol}

View File

@ -9,6 +9,7 @@ import {
} from "../api/address-resolver/UniswapV1Resolver"; } from "../api/address-resolver/UniswapV1Resolver";
type UniswapV1ExchangeNameProps = { type UniswapV1ExchangeNameProps = {
chainId: number;
address: string; address: string;
token: UniswapV1TokenMeta; token: UniswapV1TokenMeta;
linkable: boolean; linkable: boolean;
@ -16,6 +17,7 @@ type UniswapV1ExchangeNameProps = {
}; };
const UniswapV1ExchangeName: React.FC<UniswapV1ExchangeNameProps> = ({ const UniswapV1ExchangeName: React.FC<UniswapV1ExchangeNameProps> = ({
chainId,
address, address,
token, token,
linkable, linkable,
@ -32,10 +34,11 @@ const UniswapV1ExchangeName: React.FC<UniswapV1ExchangeNameProps> = ({
> >
<span>Uniswap V1 LP:</span> <span>Uniswap V1 LP:</span>
<Content <Content
linkable={true} chainId={chainId}
address={token.address} address={token.address}
name={token.name} name={token.name}
symbol={token.symbol} symbol={token.symbol}
linkable
/> />
</NavLink> </NavLink>
); );
@ -48,7 +51,7 @@ const UniswapV1ExchangeName: React.FC<UniswapV1ExchangeNameProps> = ({
> >
<span>Uniswap V1 LP:</span> <span>Uniswap V1 LP:</span>
<Content <Content
linkable={false} chainId={chainId}
address={token.address} address={token.address}
name={token.name} name={token.name}
symbol={token.symbol} symbol={token.symbol}
@ -58,13 +61,15 @@ const UniswapV1ExchangeName: React.FC<UniswapV1ExchangeNameProps> = ({
}; };
type ContentProps = { type ContentProps = {
linkable: boolean; chainId: number;
address: ChecksummedAddress; address: ChecksummedAddress;
name: string; name: string;
symbol: string; symbol: string;
linkable?: boolean;
}; };
const Content: React.FC<ContentProps> = ({ const Content: React.FC<ContentProps> = ({
chainId,
address, address,
name, name,
symbol, symbol,
@ -74,20 +79,22 @@ const Content: React.FC<ContentProps> = ({
<div <div
className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`} className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`}
> >
<TokenLogo address={address} name={name} /> <TokenLogo chainId={chainId} address={address} name={name} />
</div> </div>
<span>{symbol}</span> <span>{symbol}</span>
</> </>
); );
export const uniswapV1PairRenderer: ResolvedAddressRenderer<UniswapV1PairMeta> = export const uniswapV1PairRenderer: ResolvedAddressRenderer<
(address, tokenMeta, linkable, dontOverrideColors) => ( UniswapV1PairMeta
<UniswapV1ExchangeName > = (chainId, address, tokenMeta, linkable, dontOverrideColors) => (
address={address} <UniswapV1ExchangeName
token={tokenMeta.token} chainId={chainId}
linkable={linkable} address={address}
dontOverrideColors={dontOverrideColors} token={tokenMeta.token}
/> linkable={linkable}
); dontOverrideColors={dontOverrideColors}
/>
);
export default UniswapV1ExchangeName; export default UniswapV1ExchangeName;

View File

@ -9,6 +9,7 @@ import {
import { ChecksummedAddress } from "../types"; import { ChecksummedAddress } from "../types";
type UniswapV2PairNameProps = { type UniswapV2PairNameProps = {
chainId: number;
address: string; address: string;
token0: UniswapV2TokenMeta; token0: UniswapV2TokenMeta;
token1: UniswapV2TokenMeta; token1: UniswapV2TokenMeta;
@ -17,6 +18,7 @@ type UniswapV2PairNameProps = {
}; };
const UniswapV2PairName: React.FC<UniswapV2PairNameProps> = ({ const UniswapV2PairName: React.FC<UniswapV2PairNameProps> = ({
chainId,
address, address,
token0, token0,
token1, token1,
@ -34,17 +36,19 @@ const UniswapV2PairName: React.FC<UniswapV2PairNameProps> = ({
> >
<span>Uniswap V2 LP:</span> <span>Uniswap V2 LP:</span>
<Content <Content
linkable={true} chainId={chainId}
address={token0.address} address={token0.address}
name={token0.name} name={token0.name}
symbol={token0.symbol} symbol={token0.symbol}
linkable
/> />
<span>/</span> <span>/</span>
<Content <Content
linkable={true} chainId={chainId}
address={token1.address} address={token1.address}
name={token1.name} name={token1.name}
symbol={token1.symbol} symbol={token1.symbol}
linkable
/> />
</NavLink> </NavLink>
); );
@ -57,14 +61,14 @@ const UniswapV2PairName: React.FC<UniswapV2PairNameProps> = ({
> >
<span>Uniswap V2 LP:</span> <span>Uniswap V2 LP:</span>
<Content <Content
linkable={false} chainId={chainId}
address={token0.address} address={token0.address}
name={token0.name} name={token0.name}
symbol={token0.symbol} symbol={token0.symbol}
/> />
<span>/</span> <span>/</span>
<Content <Content
linkable={false} chainId={chainId}
address={token1.address} address={token1.address}
name={token1.name} name={token1.name}
symbol={token1.symbol} symbol={token1.symbol}
@ -74,13 +78,15 @@ const UniswapV2PairName: React.FC<UniswapV2PairNameProps> = ({
}; };
type ContentProps = { type ContentProps = {
linkable: boolean; chainId: number;
address: ChecksummedAddress; address: ChecksummedAddress;
name: string; name: string;
symbol: string; symbol: string;
linkable?: boolean;
}; };
const Content: React.FC<ContentProps> = ({ const Content: React.FC<ContentProps> = ({
chainId,
address, address,
name, name,
symbol, symbol,
@ -90,21 +96,23 @@ const Content: React.FC<ContentProps> = ({
<div <div
className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`} className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`}
> >
<TokenLogo address={address} name={name} /> <TokenLogo chainId={chainId} address={address} name={name} />
</div> </div>
<span>{symbol}</span> <span>{symbol}</span>
</> </>
); );
export const uniswapV2PairRenderer: ResolvedAddressRenderer<UniswapV2PairMeta> = export const uniswapV2PairRenderer: ResolvedAddressRenderer<
(address, tokenMeta, linkable, dontOverrideColors) => ( UniswapV2PairMeta
<UniswapV2PairName > = (chainId, address, tokenMeta, linkable, dontOverrideColors) => (
address={address} <UniswapV2PairName
token0={tokenMeta.token0} chainId={chainId}
token1={tokenMeta.token1} address={address}
linkable={linkable} token0={tokenMeta.token0}
dontOverrideColors={dontOverrideColors} token1={tokenMeta.token1}
/> linkable={linkable}
); dontOverrideColors={dontOverrideColors}
/>
);
export default UniswapV2PairName; export default UniswapV2PairName;

View File

@ -9,6 +9,7 @@ import {
import { ChecksummedAddress } from "../types"; import { ChecksummedAddress } from "../types";
type UniswapV3PoolNameProps = { type UniswapV3PoolNameProps = {
chainId: number;
address: string; address: string;
token0: UniswapV3TokenMeta; token0: UniswapV3TokenMeta;
token1: UniswapV3TokenMeta; token1: UniswapV3TokenMeta;
@ -18,6 +19,7 @@ type UniswapV3PoolNameProps = {
}; };
const UniswapV3PairName: React.FC<UniswapV3PoolNameProps> = ({ const UniswapV3PairName: React.FC<UniswapV3PoolNameProps> = ({
chainId,
address, address,
token0, token0,
token1, token1,
@ -38,17 +40,19 @@ const UniswapV3PairName: React.FC<UniswapV3PoolNameProps> = ({
> >
<span>Uniswap V3 LP:</span> <span>Uniswap V3 LP:</span>
<Content <Content
linkable={true} chainId={chainId}
address={token0.address} address={token0.address}
name={token0.name} name={token0.name}
symbol={token0.symbol} symbol={token0.symbol}
linkable
/> />
<span>/</span> <span>/</span>
<Content <Content
linkable={true} chainId={chainId}
address={token1.address} address={token1.address}
name={token1.name} name={token1.name}
symbol={token1.symbol} symbol={token1.symbol}
linkable
/> />
<span>/ {fee / 10000}%</span> <span>/ {fee / 10000}%</span>
</NavLink> </NavLink>
@ -64,14 +68,14 @@ const UniswapV3PairName: React.FC<UniswapV3PoolNameProps> = ({
> >
<span>Uniswap V3 LP:</span> <span>Uniswap V3 LP:</span>
<Content <Content
linkable={false} chainId={chainId}
address={token0.address} address={token0.address}
name={token0.name} name={token0.name}
symbol={token0.symbol} symbol={token0.symbol}
/> />
<span>/</span> <span>/</span>
<Content <Content
linkable={false} chainId={chainId}
address={token1.address} address={token1.address}
name={token1.name} name={token1.name}
symbol={token1.symbol} symbol={token1.symbol}
@ -82,13 +86,15 @@ const UniswapV3PairName: React.FC<UniswapV3PoolNameProps> = ({
}; };
type ContentProps = { type ContentProps = {
linkable: boolean; chainId: number;
address: ChecksummedAddress; address: ChecksummedAddress;
name: string; name: string;
symbol: string; symbol: string;
linkable?: boolean;
}; };
const Content: React.FC<ContentProps> = ({ const Content: React.FC<ContentProps> = ({
chainId,
address, address,
name, name,
symbol, symbol,
@ -98,22 +104,24 @@ const Content: React.FC<ContentProps> = ({
<div <div
className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`} className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`}
> >
<TokenLogo address={address} name={name} /> <TokenLogo chainId={chainId} address={address} name={name} />
</div> </div>
<span>{symbol}</span> <span>{symbol}</span>
</> </>
); );
export const uniswapV3PairRenderer: ResolvedAddressRenderer<UniswapV3PairMeta> = export const uniswapV3PairRenderer: ResolvedAddressRenderer<
(address, tokenMeta, linkable, dontOverrideColors) => ( UniswapV3PairMeta
<UniswapV3PairName > = (chainId, address, tokenMeta, linkable, dontOverrideColors) => (
address={address} <UniswapV3PairName
token0={tokenMeta.token0} chainId={chainId}
token1={tokenMeta.token1} address={address}
fee={tokenMeta.fee} token0={tokenMeta.token0}
linkable={linkable} token1={tokenMeta.token1}
dontOverrideColors={dontOverrideColors} fee={tokenMeta.fee}
/> linkable={linkable}
); dontOverrideColors={dontOverrideColors}
/>
);
export default UniswapV3PairName; export default UniswapV3PairName;

View File

@ -11,8 +11,9 @@ export const topic0URL = (assetsURLPrefix: string, topic0: string): string =>
export const tokenLogoURL = ( export const tokenLogoURL = (
assetsURLPrefix: string, assetsURLPrefix: string,
chainId: number,
address: string address: string
): string => `${assetsURLPrefix}/assets/${address}/logo.png`; ): string => `${assetsURLPrefix}/assets/${chainId}/${address}/logo.png`;
export const blockURL = (blockNum: BlockTag) => `/block/${blockNum}`; export const blockURL = (blockNum: BlockTag) => `/block/${blockNum}`;