Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added button + function for removing non-ens addresses #381

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion packages/react-app/src/views/HostRoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { ethers } from "ethers";
import { CSVLink } from "react-csv";
import copy from "copy-to-clipboard";
import * as storage from "../utils/storage";
import { useTokenImport } from "../hooks";
import { useTokenImport, useLookupAddress } from "../hooks";
//import useWindowSize from 'react-use/lib/useWindowSize'
import Confetti from "react-confetti";
import { NETWORK } from "../constants";
import axios from "axios";
import "./HostRoom.css";
import { useMemo } from "react";
import { utils } from "ethers";

export default function HostRoom({
appServer,
Expand Down Expand Up @@ -51,6 +52,7 @@ export default function HostRoom({
const [list, setList] = useState([]);
const [tokenImportLoading, setTokenImportLoading] = useState(false);
const [addressImportLoading, setAddressImportLoading] = useState(false);
const [ensFilterLoading, setEnsFilterLoading] = useState(false);

const { readContracts, writeContracts } = contracts;
const numericalAmount = amount[0] === "." ? "0" + amount : amount;
Expand Down Expand Up @@ -377,6 +379,7 @@ export default function HostRoom({
const updatedAddressesList = [...blocklist];
updatedAddressesList.splice(index, 1);
setBlocklist([...updatedAddressesList]);
localStorage.setItem(room + "blocklist", JSON.stringify([...updatedAddressesList]));
setAddresses([...addresses, addressChanged]);
};

Expand Down Expand Up @@ -406,6 +409,35 @@ export default function HostRoom({
});
};

const filterEns = async () => {
setEnsFilterLoading(true);
let blocklistAdded = [];


for (let i = 0; i < addresses.length; i++) {
const addr = addresses[i];
const reportedName = await mainnetProvider.lookupAddress(addr);

//const resolvedAddress = await mainnetProvider.resolveName(reportedName);

if (!reportedName) {
//updatedAddressList.splice(i, 1);
blocklistAdded.push(addr);
}
}
const updatedAddressList = addresses.filter(addr => !blocklistAdded.includes(addr));

setAddresses([...updatedAddressList]);
setBlocklist([...blocklist, ...blocklistAdded]);
localStorage.setItem(room + "blocklist", JSON.stringify([...blocklist, ...blocklistAdded]));
setEnsFilterLoading(false);

return notification.success({
message: "Non-ENS Names successfully filtered out",
placement: "topRight",
});
};

const exportMenu = (
<Menu>
<Menu.Item key="export_csv">
Expand Down Expand Up @@ -490,6 +522,17 @@ export default function HostRoom({
okText="Submit"
confirmLoading={addressImportLoading}
/>
<div style={{ width: "100%", display: "flex", justifyContent: "flex-end" }}>
<Button
size="small"
loading={ensFilterLoading}
onClick={async () => {
await filterEns();
}}
>
Remove Non-ENS Addresses
</Button>
</div>
<div style={{ width: "100%", display: "flex", justifyContent: "flex-end" }}>
<a
href="#"
Expand Down