mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
refactor state, make use of existing Profile model
This commit is contained in:
parent
b30fcf0c4b
commit
ed9930dfb3
@ -38,9 +38,11 @@ export default function Account({
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h3 className={styles.name}>{name || accountTruncate(accountId)}</h3>
|
<h3 className={styles.name}>{name || accountTruncate(accountId)}</h3>
|
||||||
|
{accountId && (
|
||||||
<code className={styles.accountId}>
|
<code className={styles.accountId}>
|
||||||
{accountId} <Copy text={accountId} />
|
{accountId} <Copy text={accountId} />
|
||||||
</code>
|
</code>
|
||||||
|
)}
|
||||||
<p>
|
<p>
|
||||||
{accountId &&
|
{accountId &&
|
||||||
chainIds.map((value) => (
|
chainIds.map((value) => (
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { ReactElement, useEffect, useState } from 'react'
|
import React, { ReactElement, useEffect, useState } from 'react'
|
||||||
import get3BoxProfile from '../../../utils/profile'
|
import get3BoxProfile from '../../../utils/profile'
|
||||||
import { ProfileLink } from '../../../models/Profile'
|
import { Profile } from '../../../models/Profile'
|
||||||
import { accountTruncate } from '../../../utils/web3'
|
import { accountTruncate } from '../../../utils/web3'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import PublisherLinks from './PublisherLinks'
|
import PublisherLinks from './PublisherLinks'
|
||||||
@ -14,15 +14,36 @@ const isDescriptionTextClamped = () => {
|
|||||||
if (el) return el.scrollHeight > el.clientHeight
|
if (el) return el.scrollHeight > el.clientHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clearedProfile: Profile = {
|
||||||
|
name: null,
|
||||||
|
image: null,
|
||||||
|
description: null,
|
||||||
|
links: null
|
||||||
|
}
|
||||||
|
|
||||||
|
const Link3Box = ({ accountId, text }: { accountId: string; text: string }) => {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={`https://www.3box.io/${accountId}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default function AccountHeader({
|
export default function AccountHeader({
|
||||||
accountId
|
accountId
|
||||||
}: {
|
}: {
|
||||||
accountId: string
|
accountId: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const [image, setImage] = useState<string>()
|
const [profile, setProfile] = useState<Profile>({
|
||||||
const [name, setName] = useState(accountTruncate(accountId))
|
name: accountTruncate(accountId),
|
||||||
const [description, setDescription] = useState<string>()
|
image: null,
|
||||||
const [links, setLinks] = useState<ProfileLink[]>()
|
description: null,
|
||||||
|
links: null
|
||||||
|
})
|
||||||
const [isShowMore, setIsShowMore] = useState(false)
|
const [isShowMore, setIsShowMore] = useState(false)
|
||||||
|
|
||||||
const toogleShowMore = () => {
|
const toogleShowMore = () => {
|
||||||
@ -31,28 +52,26 @@ export default function AccountHeader({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!accountId) {
|
if (!accountId) {
|
||||||
setName(null)
|
setProfile(clearedProfile)
|
||||||
setDescription(null)
|
|
||||||
setImage(null)
|
|
||||||
setLinks([])
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const source = axios.CancelToken.source()
|
const source = axios.CancelToken.source()
|
||||||
|
|
||||||
async function getInfoFrom3Box() {
|
async function getInfoFrom3Box() {
|
||||||
const profile = await get3BoxProfile(accountId, source.token)
|
const profile3Box = await get3BoxProfile(accountId, source.token)
|
||||||
if (profile) {
|
if (profile3Box) {
|
||||||
const { name, emoji, description, image, links } = profile
|
const { name, emoji, description, image, links } = profile3Box
|
||||||
setName(`${emoji || ''} ${name || accountTruncate(accountId)}`)
|
const newName = `${emoji || ''} ${name || accountTruncate(accountId)}`
|
||||||
setDescription(description || null)
|
const newProfile = {
|
||||||
setImage(image || null)
|
name: newName,
|
||||||
setLinks(links || [])
|
image,
|
||||||
|
description,
|
||||||
|
links
|
||||||
|
}
|
||||||
|
setProfile(newProfile)
|
||||||
} else {
|
} else {
|
||||||
setName(null)
|
setProfile(clearedProfile)
|
||||||
setDescription(null)
|
|
||||||
setImage(null)
|
|
||||||
setLinks([])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getInfoFrom3Box()
|
getInfoFrom3Box()
|
||||||
@ -65,44 +84,32 @@ export default function AccountHeader({
|
|||||||
return (
|
return (
|
||||||
<div className={styles.grid}>
|
<div className={styles.grid}>
|
||||||
<div>
|
<div>
|
||||||
<Account accountId={accountId} image={image} name={name} />
|
<Account
|
||||||
|
accountId={accountId}
|
||||||
|
image={profile.image}
|
||||||
|
name={profile.name}
|
||||||
|
/>
|
||||||
<Stats accountId={accountId} />
|
<Stats accountId={accountId} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Markdown
|
<Markdown text={profile.description} className={styles.description} />
|
||||||
text={
|
|
||||||
description ||
|
|
||||||
'No description found on [3box](https://3box.io/login).'
|
|
||||||
}
|
|
||||||
className={styles.description}
|
|
||||||
/>
|
|
||||||
{isDescriptionTextClamped() ? (
|
{isDescriptionTextClamped() ? (
|
||||||
<span className={styles.more} onClick={toogleShowMore}>
|
<span className={styles.more} onClick={toogleShowMore}>
|
||||||
<a
|
<Link3Box accountId={accountId} text="Read more on 3box" />
|
||||||
href={`https://www.3box.io/${accountId}`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
Read more on 3box
|
|
||||||
</a>
|
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
''
|
''
|
||||||
)}
|
)}
|
||||||
{links?.length > 0 && (
|
{profile.links?.length > 0 && (
|
||||||
<PublisherLinks links={links} className={styles.publisherLinks} />
|
<PublisherLinks
|
||||||
|
links={profile.links}
|
||||||
|
className={styles.publisherLinks}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.meta}>
|
<div className={styles.meta}>
|
||||||
Profile data from{' '}
|
Profile data from <Link3Box accountId={accountId} text="3Box Hub" />
|
||||||
<a
|
|
||||||
href={`https://www.3box.io/${accountId}`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
3Box Hub
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -92,12 +92,12 @@ export default function Stats({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.stats}>
|
<div className={styles.stats}>
|
||||||
<NumberUnit label="Published" value={numberOfAssets} />
|
|
||||||
<NumberUnit label="Sold" value={sold} />
|
|
||||||
<NumberUnit
|
<NumberUnit
|
||||||
label="Total Value Locked"
|
label="Total Value Locked"
|
||||||
value={<Conversion price={tvl?.price} hideApproximateSymbol />}
|
value={<Conversion price={tvl?.price} hideApproximateSymbol />}
|
||||||
/>
|
/>
|
||||||
|
<NumberUnit label="Sold" value={sold} />
|
||||||
|
<NumberUnit label="Published" value={numberOfAssets} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ export interface ProfileLink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Profile {
|
export interface Profile {
|
||||||
did: string
|
did?: string
|
||||||
name?: string
|
name?: string
|
||||||
description?: string
|
description?: string
|
||||||
emoji?: string
|
emoji?: string
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { Profile, ProfileLink, ResponseData3Box } from '../models/Profile'
|
import { Profile, ProfileLink, ResponseData3Box } from '../models/Profile'
|
||||||
import axios, { AxiosResponse, CancelToken } from 'axios'
|
import axios, { AxiosResponse, CancelToken } from 'axios'
|
||||||
import jwtDecode from 'jwt-decode'
|
import jwtDecode from 'jwt-decode'
|
||||||
import { Logger } from '@oceanprotocol/lib'
|
|
||||||
|
|
||||||
// https://docs.3box.io/api/rest-api
|
// https://docs.3box.io/api/rest-api
|
||||||
const apiUri = 'https://3box.oceanprotocol.com'
|
const apiUri = 'https://3box.oceanprotocol.com'
|
||||||
|
Loading…
Reference in New Issue
Block a user