Skip to content

Commit

Permalink
fix address comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
aquiladev committed Nov 23, 2023
1 parent 9c8b99f commit f62e3d9
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 77 deletions.
4 changes: 3 additions & 1 deletion src/components/Domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
173 changes: 99 additions & 74 deletions src/components/Lookup.js
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -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",
},
}));

Expand All @@ -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]);
Expand All @@ -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;
}
Expand All @@ -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 (
<Container style={{ paddingTop: '3rem' }}>
<Container style={{ paddingTop: "3rem" }}>
<Paper className={classes.root}>
<InputBase
error={!!error}
className={classes.input}
onKeyPress={keyPress}
onChange={handleChange}
placeholder='Search domain (.crypto, .wallet, .bitcoin, .x, .888, .nft, .dao, .blockchain)'
inputProps={{ 'aria-label': 'search domain (.crypto, .wallet, .bitcoin, .x, .888, .nft, .dao, .blockchain)' }}
placeholder="Search domain (.crypto, .wallet, .bitcoin, .x, .888, .nft, .dao, .blockchain)"
inputProps={{
"aria-label":
"search domain (.crypto, .wallet, .bitcoin, .x, .888, .nft, .dao, .blockchain)",
}}
defaultValue={domainName}
value={domainName}
/>
<IconButton
className={classes.iconButton}
onClick={search}
aria-label='search'>
aria-label="search"
>
<SearchIcon />
</IconButton>
</Paper>
{error && <Alert severity='error'>{error}</Alert>}
{!fetched &&
{error && <Alert severity="error">{error}</Alert>}
{!fetched && (
<div className={classes.loader}>
<CircularProgress color='inherit' />
<CircularProgress color="inherit" />
</div>
}
{fetched && domain &&
)}
{fetched && domain && (
<div style={{ marginTop: 20 }}>
<DomainList
chainId={chainId}
isFetching={!fetched}
domains={[domain]}
onEventsLoad={loadDomainEvents} />
onEventsLoad={loadDomainEvents}
/>
</div>
}
)}
</Container>
);
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/services/udRegistry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const BASE_URL = "https://api.unstoppabledomains.com";
// const BASE_URL = 'http://localhost:8080';

export const getAvailability = async (name) => {
if (!name) {
Expand Down

0 comments on commit f62e3d9

Please sign in to comment.