Merge branch 'feature/hardcoded-addresses' into develop
This commit is contained in:
commit
7d58cc96f3
|
@ -0,0 +1,22 @@
|
|||
import { BaseProvider } from "@ethersproject/providers";
|
||||
import { IAddressResolver } from "./address-resolver";
|
||||
|
||||
type HardcodedAddressMap = Record<string, string | undefined>;
|
||||
|
||||
export class HardcodedAddressResolver implements IAddressResolver<string> {
|
||||
async resolveAddress(
|
||||
provider: BaseProvider,
|
||||
address: string
|
||||
): Promise<string | undefined> {
|
||||
try {
|
||||
const addressMap: HardcodedAddressMap = await import(
|
||||
`./hardcoded-addresses/${provider.network.chainId}.json`
|
||||
);
|
||||
|
||||
return addressMap[address];
|
||||
} catch (err) {
|
||||
// Ignore on purpose
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"0x7d655c57f71464B6f83811C55D84009Cd9f5221C": "Gitcoin: Bulk Checkout",
|
||||
"0x722122dF12D4e14e13Ac3b6895a86e84145b6967": "Tornado Cash: Proxy",
|
||||
"0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95": "Uniswap V1: Factory",
|
||||
"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f": "Uniswap V2: Factory",
|
||||
"0xf164fC0Ec4E93095b804a4795bBe1e041497b92a": "Uniswap V2: Router 1",
|
||||
"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D": "Uniswap V2: Router 2",
|
||||
"0x1F98431c8aD98523631AE4a59f267346ea31F984": "Uniswap V3: Router"
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { BaseProvider } from "@ethersproject/providers";
|
||||
import { ensRenderer } from "../../components/ENSName";
|
||||
import { plainStringRenderer } from "../../components/PlainString";
|
||||
import { tokenRenderer } from "../../components/TokenName";
|
||||
import { IAddressResolver, ResolvedAddressRenderer } from "./address-resolver";
|
||||
import {
|
||||
|
@ -8,16 +9,19 @@ import {
|
|||
} from "./CompositeAddressResolver";
|
||||
import { ENSAddressResolver } from "./ENSAddressResolver";
|
||||
import { ERCTokenResolver } from "./ERCTokenResolver";
|
||||
import { HardcodedAddressResolver } from "./HardcodedAddressResolver";
|
||||
|
||||
export type ResolvedAddresses = Record<string, SelectedResolvedName<any>>;
|
||||
|
||||
// Create and configure the main resolver
|
||||
export const ensResolver = new ENSAddressResolver();
|
||||
export const ercTokenResolver = new ERCTokenResolver();
|
||||
export const hardcodedResolver = new HardcodedAddressResolver();
|
||||
|
||||
const _mainResolver = new CompositeAddressResolver();
|
||||
_mainResolver.addResolver(ensResolver);
|
||||
_mainResolver.addResolver(ercTokenResolver);
|
||||
_mainResolver.addResolver(hardcodedResolver);
|
||||
|
||||
export const mainResolver: IAddressResolver<SelectedResolvedName<any>> =
|
||||
_mainResolver;
|
||||
|
@ -28,6 +32,7 @@ export const resolverRendererRegistry = new Map<
|
|||
>();
|
||||
resolverRendererRegistry.set(ensResolver, ensRenderer);
|
||||
resolverRendererRegistry.set(ercTokenResolver, tokenRenderer);
|
||||
resolverRendererRegistry.set(hardcodedResolver, plainStringRenderer);
|
||||
|
||||
// TODO: implement progressive resolving
|
||||
export const batchPopulate = async (
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
import React from "react";
|
||||
import { NavLink } from "react-router-dom";
|
||||
import { ResolvedAddressRenderer } from "../api/address-resolver/address-resolver";
|
||||
|
||||
type PlainStringProps = {
|
||||
address: string;
|
||||
name: string;
|
||||
linkable: boolean;
|
||||
dontOverrideColors: boolean | undefined;
|
||||
};
|
||||
|
||||
const PlainString: React.FC<PlainStringProps> = ({
|
||||
address,
|
||||
name,
|
||||
linkable,
|
||||
dontOverrideColors,
|
||||
}) => {
|
||||
if (linkable) {
|
||||
return (
|
||||
<NavLink
|
||||
className={`${
|
||||
dontOverrideColors ? "" : "text-link-blue hover:text-link-blue-hover"
|
||||
} truncate`}
|
||||
to={`/address/${address}`}
|
||||
title={name}
|
||||
>
|
||||
{name}
|
||||
</NavLink>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span className="text-gray-400 truncate" title={name}>
|
||||
{name}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export const plainStringRenderer: ResolvedAddressRenderer<string> = (
|
||||
address,
|
||||
resolvedAddress,
|
||||
linkable,
|
||||
dontOverrideColors
|
||||
) => (
|
||||
<PlainString
|
||||
address={address}
|
||||
name={resolvedAddress}
|
||||
linkable={linkable}
|
||||
dontOverrideColors={dontOverrideColors}
|
||||
/>
|
||||
);
|
||||
|
||||
export default PlainString;
|
Loading…
Reference in New Issue