From 212865110e1db065ab7d6c81c1b6195aca02de1b Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 20 Sep 2021 13:47:15 +0200 Subject: [PATCH] ENS names (#860) * prototype getting ENS names * get ENS name with subgraph * ENS name for publisher line * inject ENS name in profile page * refactor to cover all use cases for profile URLs * fixes for switching between own and other profiles * remove testing ENS libraries * more cleanup * any solves everything * build fix * more profile switching tweaks * link publisher line to ens name * another profile switching fix * show ENS link in meta line --- package-lock.json | 20 ------- package.json | 1 - src/components/atoms/Publisher/index.tsx | 25 ++++++--- src/components/molecules/Wallet/Account.tsx | 4 +- .../pages/Profile/Header/Account.tsx | 12 ++--- src/components/pages/Profile/Header/index.tsx | 28 +++++++--- src/models/Profile.ts | 1 + src/pages/profile/index.tsx | 52 +++++++++++++++--- src/providers/Profile.tsx | 32 ++++++----- src/providers/Web3.tsx | 53 +++++++++++-------- src/utils/ens.ts | 52 ++++++++++++++++++ 11 files changed, 196 insertions(+), 84 deletions(-) create mode 100644 src/utils/ens.ts diff --git a/package-lock.json b/package-lock.json index 94e78b378..153f41abd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,7 +86,6 @@ "@testing-library/jest-dom": "^5.12.0", "@testing-library/react": "^11.2.7", "@types/chart.js": "^2.9.32", - "@types/classnames": "^2.3.1", "@types/jest": "^26.0.23", "@types/loadable__component": "^5.13.1", "@types/lodash.debounce": "^4.0.3", @@ -10515,16 +10514,6 @@ "moment": "^2.10.2" } }, - "node_modules/@types/classnames": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/@types/classnames/-/classnames-2.3.1.tgz", - "integrity": "sha512-zeOWb0JGBoVmlQoznvqXbE0tEC/HONsnoUNH19Hc96NFsTAwTXbTqb8FMYkru1F/iqp7a18Ws3nWJvtA1sHD1A==", - "deprecated": "This is a stub types definition. classnames provides its own type definitions, so you do not need this installed.", - "dev": true, - "dependencies": { - "classnames": "*" - } - }, "node_modules/@types/clipboard": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/@types/clipboard/-/clipboard-2.0.7.tgz", @@ -67020,15 +67009,6 @@ "moment": "^2.10.2" } }, - "@types/classnames": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/@types/classnames/-/classnames-2.3.1.tgz", - "integrity": "sha512-zeOWb0JGBoVmlQoznvqXbE0tEC/HONsnoUNH19Hc96NFsTAwTXbTqb8FMYkru1F/iqp7a18Ws3nWJvtA1sHD1A==", - "dev": true, - "requires": { - "classnames": "*" - } - }, "@types/clipboard": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/@types/clipboard/-/clipboard-2.0.7.tgz", diff --git a/package.json b/package.json index 7bfab8799..318ef028c 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ "@testing-library/jest-dom": "^5.12.0", "@testing-library/react": "^11.2.7", "@types/chart.js": "^2.9.32", - "@types/classnames": "^2.3.1", "@types/jest": "^26.0.23", "@types/loadable__component": "^5.13.1", "@types/lodash.debounce": "^4.0.3", diff --git a/src/components/atoms/Publisher/index.tsx b/src/components/atoms/Publisher/index.tsx index 38934bf90..734fd1e02 100644 --- a/src/components/atoms/Publisher/index.tsx +++ b/src/components/atoms/Publisher/index.tsx @@ -8,6 +8,7 @@ import { accountTruncate } from '../../../utils/web3' import axios from 'axios' import Add from './Add' import { useWeb3 } from '../../../providers/Web3' +import { getEnsName } from '../../../utils/ens' const cx = classNames.bind(styles) @@ -20,27 +21,34 @@ export default function Publisher({ minimal?: boolean className?: string }): ReactElement { - const { networkId, accountId } = useWeb3() + const { accountId } = useWeb3() const [profile, setProfile] = useState() - const [name, setName] = useState() + const [name, setName] = useState(accountTruncate(account)) + const [accountEns, setAccountEns] = useState() const showAdd = account === accountId && !profile useEffect(() => { if (!account) return - setName(accountTruncate(account)) const source = axios.CancelToken.source() - async function get3Box() { + async function getExternalName() { + // ENS + const accountEns = await getEnsName(account) + if (accountEns) { + setAccountEns(accountEns) + setName(accountEns) + } + + // 3box const profile = await get3BoxProfile(account, source.token) if (!profile) return - setProfile(profile) const { name, emoji } = profile name && setName(`${emoji || ''} ${name}`) } - get3Box() + getExternalName() return () => { source.cancel() @@ -58,7 +66,10 @@ export default function Publisher({ name ) : ( <> - + {name} {showAdd && } diff --git a/src/components/molecules/Wallet/Account.tsx b/src/components/molecules/Wallet/Account.tsx index 22c2ad249..e95430306 100644 --- a/src/components/molecules/Wallet/Account.tsx +++ b/src/components/molecules/Wallet/Account.tsx @@ -9,7 +9,7 @@ import Blockies from '../../atoms/Blockies' // Forward ref for Tippy.js // eslint-disable-next-line const Account = React.forwardRef((props, ref: any) => { - const { accountId, web3Modal, connect } = useWeb3() + const { accountId, accountEns, web3Modal, connect } = useWeb3() async function handleActivation(e: FormEvent) { // prevent accidentially submitting a form the button might be in @@ -32,7 +32,7 @@ const Account = React.forwardRef((props, ref: any) => { > - {accountTruncate(accountId)} + {accountTruncate(accountEns || accountId)}