From f62e3d988b40848a54e794447028b94152dacc61 Mon Sep 17 00:00:00 2001 From: Sergii Bomko <1164492+aquiladev@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:50:49 +0200 Subject: [PATCH] fix address comparison --- src/components/Domains.js | 4 +- src/components/Lookup.js | 173 +++++++++++++++++++++---------------- src/components/Search.js | 4 +- src/services/udRegistry.js | 1 - 4 files changed, 105 insertions(+), 77 deletions(-) diff --git a/src/components/Domains.js b/src/components/Domains.js index 10792e1..14eec55 100644 --- a/src/components/Domains.js +++ b/src/components/Domains.js @@ -148,7 +148,9 @@ const Domains = ({ library, account, chainId }) => { setTransferring(true); const registry = - unsRegistry.address === _domain.registry ? unsRegistry : cnsRegistry; + unsRegistry.address.toLowerCase() === _domain.registry + ? unsRegistry + : cnsRegistry; await registry["safeTransferFrom(address,address,uint256)"]( account, receiver, diff --git a/src/components/Lookup.js b/src/components/Lookup.js index 830d45f..2315b1c 100644 --- a/src/components/Lookup.js +++ b/src/components/Lookup.js @@ -1,31 +1,31 @@ -import React, { useEffect, useState } from 'react'; -import { useParams } from 'react-router-dom'; -import { makeStyles } from '@material-ui/core/styles'; -import { ethers } from 'ethers'; -import Container from '@material-ui/core/Container'; -import Paper from '@material-ui/core/Paper'; -import InputBase from '@material-ui/core/InputBase'; -import IconButton from '@material-ui/core/IconButton'; -import SearchIcon from '@material-ui/icons/Search'; -import Alert from '@material-ui/lab/Alert'; -import CircularProgress from '@material-ui/core/CircularProgress'; - -import NetworkConfig from 'uns/uns-config.json'; -import supportedKeys from 'uns/resolver-keys.json'; - -import cnsRegistryJson from 'uns/artifacts/CNSRegistry.json'; -import unsRegistryJson from 'uns/artifacts/UNSRegistry.json'; -import proxyReaderJson from 'uns/artifacts/ProxyReader.json'; - -import DomainList from './DomainList'; -import { createContract } from '../utils/contract'; +import React, { useEffect, useState } from "react"; +import { useParams } from "react-router-dom"; +import { makeStyles } from "@material-ui/core/styles"; +import { ethers } from "ethers"; +import Container from "@material-ui/core/Container"; +import Paper from "@material-ui/core/Paper"; +import InputBase from "@material-ui/core/InputBase"; +import IconButton from "@material-ui/core/IconButton"; +import SearchIcon from "@material-ui/icons/Search"; +import Alert from "@material-ui/lab/Alert"; +import CircularProgress from "@material-ui/core/CircularProgress"; + +import NetworkConfig from "uns/uns-config.json"; +import supportedKeys from "uns/resolver-keys.json"; + +import cnsRegistryJson from "uns/artifacts/CNSRegistry.json"; +import unsRegistryJson from "uns/artifacts/UNSRegistry.json"; +import proxyReaderJson from "uns/artifacts/ProxyReader.json"; + +import DomainList from "./DomainList"; +import { createContract } from "../utils/contract"; const useStyles = makeStyles((theme) => ({ root: { marginTop: 40, - padding: '2px 4px', - display: 'flex', - alignItems: 'center', + padding: "2px 4px", + display: "flex", + alignItems: "center", }, input: { marginLeft: theme.spacing(1), @@ -35,10 +35,10 @@ const useStyles = makeStyles((theme) => ({ padding: 10, }, loader: { - width: '100%', - display: 'flex', - flexDirection: 'column', - alignItems: 'center', + width: "100%", + display: "flex", + flexDirection: "column", + alignItems: "center", }, })); @@ -52,14 +52,29 @@ const Lookup = ({ library, chainId }) => { const [error, setError] = useState(undefined); const { contracts } = NetworkConfig.networks[chainId]; - const cnsRegistry = createContract(library, chainId, cnsRegistryJson.abi, contracts.CNSRegistry); - const unsRegistry = createContract(library, chainId, unsRegistryJson.abi, contracts.UNSRegistry); - const proxyReader = createContract(library, chainId, proxyReaderJson.abi, contracts.ProxyReader); + const cnsRegistry = createContract( + library, + chainId, + cnsRegistryJson.abi, + contracts.CNSRegistry + ); + const unsRegistry = createContract( + library, + chainId, + unsRegistryJson.abi, + contracts.UNSRegistry + ); + const proxyReader = createContract( + library, + chainId, + proxyReaderJson.abi, + contracts.ProxyReader + ); const _keys = Object.keys(supportedKeys.keys); useEffect(() => { - if(domainName) { + if (domainName) { search(); } }, [domainName]); @@ -71,7 +86,7 @@ const Lookup = ({ library, chainId }) => { return; } - if(ethers.utils.isHexString(domainName) && domainName.length === 66) { + if (ethers.utils.isHexString(domainName) && domainName.length === 66) { setDomainName(await fetchName(domainName)); return; } @@ -86,101 +101,111 @@ const Lookup = ({ library, chainId }) => { }; const fetchName = async (token) => { - const registry = await unsRegistry.exists(token) ? unsRegistry : cnsRegistry; + const registry = (await unsRegistry.exists(token)) + ? unsRegistry + : cnsRegistry; const events = await registry.source.fetchNewURIEvents([token]); - if(!events.length) { + if (!events.length) { throw new Error("Token not found"); } - return events.find(e => e.args.tokenId.toHexString() === token).args.uri; - } + return events.find((e) => e.args.tokenId.toHexString() === token).args.uri; + }; const loadData = async (tokenId, name) => { setFetched(false); - console.debug('Fetching state...'); + console.debug("Fetching state..."); const data = await proxyReader.callStatic.getData(_keys, tokenId); - console.debug('Fetched state', data); + console.debug("Fetched state", data); const records = {}; - _keys.forEach((k, i) => records[k] = data[2][i]); + _keys.forEach((k, i) => (records[k] = data[2][i])); const _domain = { id: tokenId, name, - registry: data.resolver === unsRegistry.address - ? unsRegistry.address - : cnsRegistry.address, - type: data.resolver === unsRegistry.address ? 'uns' : 'cns', + registry: + data.resolver === unsRegistry.address.toLowerCase() + ? unsRegistry.address + : cnsRegistry.address, + type: data.resolver === unsRegistry.address ? "uns" : "cns", owner: data.owner, resolver: data.resolver, - records - } + records, + }; - console.debug('Update state', _domain); + console.debug("Update state", _domain); setFetched(true); setDomain(_domain); - } + }; const loadDomainEvents = (domain) => { - console.debug('Loading DOMAIN events...'); - - const registry = unsRegistry.address === domain.registry ? unsRegistry : cnsRegistry; - return registry.source.fetchEvents(domain) - .then((domainEvents) => { - console.debug('Loaded DOMAIN events', domainEvents); - - return { - isFetched: true, - events: domainEvents || [] - }; - }); - } + console.debug("Loading DOMAIN events..."); + + const registry = + unsRegistry.address.toLowerCase() === domain.registry + ? unsRegistry + : cnsRegistry; + return registry.source.fetchEvents(domain).then((domainEvents) => { + console.debug("Loaded DOMAIN events", domainEvents); + + return { + isFetched: true, + events: domainEvents || [], + }; + }); + }; const handleChange = (e) => { setDomainName(e.target.value); - } + }; const keyPress = (e) => { if (e.charCode === 13) { search(); } - } + }; return ( - + + aria-label="search" + > - {error && {error}} - {!fetched && + {error && {error}} + {!fetched && (
- +
- } - {fetched && domain && + )} + {fetched && domain && (
+ onEventsLoad={loadDomainEvents} + />
- } + )}
); }; diff --git a/src/components/Search.js b/src/components/Search.js index 84ded2c..8f25f7f 100644 --- a/src/components/Search.js +++ b/src/components/Search.js @@ -116,7 +116,9 @@ const Search = ({ library, chainId }) => { console.debug("Loading DOMAIN events..."); const registry = - unsRegistry.address === domain.registry ? unsRegistry : cnsRegistry; + unsRegistry.address.toLowerCase() === domain.registry + ? unsRegistry + : cnsRegistry; return registry.source.fetchEvents(domain).then((domainEvents) => { console.debug("Loaded DOMAIN events", domainEvents); diff --git a/src/services/udRegistry.js b/src/services/udRegistry.js index 4f4bf70..56deddc 100644 --- a/src/services/udRegistry.js +++ b/src/services/udRegistry.js @@ -1,5 +1,4 @@ const BASE_URL = "https://api.unstoppabledomains.com"; -// const BASE_URL = 'http://localhost:8080'; export const getAvailability = async (name) => { if (!name) {