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

feat: show tezos domain on profile #356

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
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
34 changes: 33 additions & 1 deletion src/pages/profile/profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ import Identicon from '@atoms/identicons'
import styles from '@style'
import { useDisplayStore } from '.'
import ParticipantList from '@components/collab/manage/ParticipantList'
import { useCallback, useEffect, useState } from 'react'

async function reverseRecord(address) {
const response = await fetch('https://api.tezos.domains/graphql', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is standardized across the code base but we should use axios since I'm not sure we polyfill fetch yet (for older browsers)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to axios with d04ad54

headers: {
'content-type': 'application/json',
},
method: 'POST',
mode: 'cors',
credentials: 'omit',
body: JSON.stringify({
query:
'query reverseRecord($address: String!) { reverseRecord(address: $address) { domain { name }}}',
variables: { address },
operationName: 'reverseRecord',
}),
})

const result = await response.json()
return result?.data?.reverseRecord?.domain?.name || ''
}

export default function Profile({ user }) {
const [isDiscordCopied, setDiscordCopied] = useClipboard(user.discord)
Expand All @@ -13,6 +34,17 @@ export default function Profile({ user }) {
})

const coreParticipants = useDisplayStore((st) => st.coreParticipants)
const [reverseDomain, setReverseDomain] = useState('')

const loadReverseDomain = useCallback(() => {
reverseRecord(user.address).then((domain) => {
setReverseDomain(domain)
})
}, [user.address])

useEffect(() => {
loadReverseDomain()
}, [loadReverseDomain])

return (
<div className={styles.container}>
Expand All @@ -34,7 +66,7 @@ export default function Profile({ user }) {
)}
<div style={{ display: 'flex', gap: '1em', alignItems: 'center' }}>
<Button href={`https://tzkt.io/${user.address}`}>
{walletPreview(user.address)}
{reverseDomain ? reverseDomain : walletPreview(user.address)}
</Button>
<Button className={styles.square} onClick={setAddressCopied} />
{isAddressCopied && 'Copied!'}
Expand Down
Loading