diff --git a/src/api/address-resolver/HardcodedAddressResolver.ts b/src/api/address-resolver/HardcodedAddressResolver.ts new file mode 100644 index 0000000..42d1102 --- /dev/null +++ b/src/api/address-resolver/HardcodedAddressResolver.ts @@ -0,0 +1,22 @@ +import { BaseProvider } from "@ethersproject/providers"; +import { IAddressResolver } from "./address-resolver"; + +type HardcodedAddressMap = Record; + +export class HardcodedAddressResolver implements IAddressResolver { + async resolveAddress( + provider: BaseProvider, + address: string + ): Promise { + try { + const addressMap: HardcodedAddressMap = await import( + `./hardcoded-addresses/${provider.network.chainId}.json` + ); + + return addressMap[address]; + } catch (err) { + // Ignore on purpose + return undefined; + } + } +} diff --git a/src/api/address-resolver/hardcoded-addresses/1.json b/src/api/address-resolver/hardcoded-addresses/1.json new file mode 100644 index 0000000..7ae2f9b --- /dev/null +++ b/src/api/address-resolver/hardcoded-addresses/1.json @@ -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" +} \ No newline at end of file diff --git a/src/api/address-resolver/index.ts b/src/api/address-resolver/index.ts index dc72a9f..f1514be 100644 --- a/src/api/address-resolver/index.ts +++ b/src/api/address-resolver/index.ts @@ -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>; // 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> = _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 ( diff --git a/src/components/PlainString.tsx b/src/components/PlainString.tsx new file mode 100644 index 0000000..5b891bf --- /dev/null +++ b/src/components/PlainString.tsx @@ -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 = ({ + address, + name, + linkable, + dontOverrideColors, +}) => { + if (linkable) { + return ( + + {name} + + ); + } + + return ( + + {name} + + ); +}; + +export const plainStringRenderer: ResolvedAddressRenderer = ( + address, + resolvedAddress, + linkable, + dontOverrideColors +) => ( + +); + +export default PlainString;