From 3ad04cd19177fbfb235a9e019602db9f4fe3f893 Mon Sep 17 00:00:00 2001 From: Varun Date: Wed, 6 Apr 2022 21:17:56 -0400 Subject: [PATCH] Added button + function for removing non-ens addresses --- packages/react-app/src/views/HostRoom.jsx | 45 ++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/react-app/src/views/HostRoom.jsx b/packages/react-app/src/views/HostRoom.jsx index 05b651be..b0c7ee01 100644 --- a/packages/react-app/src/views/HostRoom.jsx +++ b/packages/react-app/src/views/HostRoom.jsx @@ -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, @@ -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; @@ -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]); }; @@ -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 = ( @@ -490,6 +522,17 @@ export default function HostRoom({ okText="Submit" confirmLoading={addressImportLoading} /> +
+ +