1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
Matthias Kretschmann 92b7063b3d
ENS integration, the right way (#1410)
* prototype getting ENS names the right decentralized way

* get all profile metadata with ENS

* refactor account display in context of top sales list

* support almost all default text records

* refactor text record fetching

* more web3 calls reduction

* package cleanup

* add Publisher component test, mock out ens utils

* remove mock to run @utils/ens directly

* add Avatar stories

* cleanup

* rebase fixes

* profile loading tweaks

* fixes

* merge cleanup

* remove @ensdomains/ensjs

* fetch ENS data from proxy

* update avatar tests

* tweak error catching for all axios fetches

* test tweaks

* api path fix

* fetching fixes

* account switching tweaks

* remove unused methods

* add ENS fetching tests

* jest timeout tweak

* update readme
2022-09-22 19:18:32 +01:00

54 lines
1.6 KiB
TypeScript

import React, { FormEvent } from 'react'
import Caret from '@images/caret.svg'
import { accountTruncate } from '@utils/web3'
import Loader from '@shared/atoms/Loader'
import styles from './Account.module.css'
import { useWeb3 } from '@context/Web3'
import Avatar from '@shared/atoms/Avatar'
// Forward ref for Tippy.js
// eslint-disable-next-line
const Account = React.forwardRef((props, ref: any) => {
const { accountId, accountEns, accountEnsAvatar, web3Modal, connect } =
useWeb3()
async function handleActivation(e: FormEvent<HTMLButtonElement>) {
// prevent accidentially submitting a form the button might be in
e.preventDefault()
await connect()
}
return !accountId && web3Modal?.cachedProvider ? (
// Improve user experience for cached provider when connecting takes some time
<button className={styles.button} onClick={(e) => e.preventDefault()}>
<Loader />
</button>
) : accountId ? (
<button
className={styles.button}
aria-label="Account"
ref={ref}
onClick={(e) => e.preventDefault()}
>
<Avatar accountId={accountId} src={accountEnsAvatar} />
<span className={styles.address} title={accountId}>
{accountTruncate(accountEns || accountId)}
</span>
<Caret aria-hidden="true" className={styles.caret} />
</button>
) : (
<button
className={`${styles.button} ${styles.initial}`}
onClick={(e) => handleActivation(e)}
// Need the `ref` here although we do not want
// the Tippy to show in this state.
ref={ref}
>
Connect <span>Wallet</span>
</button>
)
})
export default Account