Skip to content

Commit

Permalink
fix: pets in 3d (#10596)
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Aug 23, 2023
1 parent f9f922a commit d3a4515
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
8 changes: 1 addition & 7 deletions packages/plugins/Pets/src/SiteAdaptor/Animate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { useEffect, useState } from 'react'
import { makeStyles } from '@masknet/theme'
import { useValueRef } from '@masknet/shared-base-ui'
import { useEssay, useDefaultEssay, useCurrentVisitingUser } from '../hooks/index.js'
import { ModelNFT } from './ModelNFT.js'
import { NormalNFT } from './NormalNFT.js'
import { ImageType } from '../types.js'
import { PluginPetMessages } from '../messages.js'
import { petShowSettings } from '../settings.js'

Expand Down Expand Up @@ -56,11 +54,7 @@ function AnimatePic() {
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
key={visitor.userId}>
{showMeta.type === ImageType.GLB ? (
<ModelNFT start={start} showMeta={showMeta} />
) : (
<NormalNFT start={start} infoShow={infoShow} showMeta={showMeta} handleClose={handleClose} />
)}
<NormalNFT start={start} infoShow={infoShow} showMeta={showMeta} handleClose={handleClose} />
</div>
)
}
Expand Down
13 changes: 3 additions & 10 deletions packages/plugins/Pets/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import urlcat from 'urlcat'
import { resolveIPFS_URL } from '@masknet/web3-shared-base'
import { EMPTY_LIST, PluginID, MEDIA_VIEWER_URL } from '@masknet/shared-base'
import { EMPTY_LIST, PluginID } from '@masknet/shared-base'
import { ImageType } from './types.js'

export const PetsPluginID = PluginID.Pets
export const TWITTER = 'twitter.com'
export const MASK_TWITTER = 'realMaskNetwork'
export const DEFAULT_SET_WORD =
'Click the wallet icon on the left side of the page and set up your Non-Fungible Friend in "NFTs" tab!'
export const DEFAULT_PUNK_MASK_WORD =
"I'm CryptoPunk #6128... in 3D & with a body! Voyagers, welcome to the uncharted waters of WEB3!"
export const DEFAULT_PUNK_MASK_WORD = "I'm CryptoPunk #6128! Voyagers, welcome to the uncharted waters of WEB3!"
export const NFF_TWITTER = 'https://twitter.com/NonFFriend'

export const initMeta = {
Expand All @@ -33,11 +30,7 @@ export const initCollection = {
export const Punk3D = {
contract: '0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb',
tokenId: '6128',
url: urlcat(MEDIA_VIEWER_URL, {
/* cspell:disable-next-line */
url: resolveIPFS_URL('QmZjfo1zKTfQZjqs4CaZJ7pQDZHrUBaozre8Z71c7ZXGMc'),
type: 'model/gltf-binary',
}),
url: 'https://cdn.simplehash.com/assets/fbbba7e60c774884b98e49cb6d48975f4690dfd207ff5861e8db0d9a49b16bba.png',
}

export const GLB3DIcon = new URL('./assets/glb3D.png', import.meta.url).toString()
Expand Down
15 changes: 7 additions & 8 deletions packages/plugins/Pets/src/hooks/useEssay.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect, useState } from 'react'
import { useMemo } from 'react'
import { useAsync } from 'react-use'
import { Web3Storage } from '@masknet/web3-providers'
import { ImageType } from '../types.js'
import type { User, ShowMeta, EssayRSSNode } from '../types.js'
import { Punk3D, DEFAULT_SET_WORD, MASK_TWITTER, DEFAULT_PUNK_MASK_WORD, PunkIcon } from '../constants.js'
import { DEFAULT_SET_WORD, MASK_TWITTER, DEFAULT_PUNK_MASK_WORD, PunkIcon, Punk3D } from '../constants.js'
import { useUser } from './useUser.js'

export function useEssay(user: User, refresh?: number) {
Expand All @@ -22,22 +22,21 @@ export function useEssay(user: User, refresh?: number) {
}

export function useDefaultEssay(user: User) {
const [essayMeta, setEssayMeta] = useState<ShowMeta | undefined>(undefined)
const profileUser = useUser()
useEffect(() => {
const essayMeta = useMemo<ShowMeta | undefined>(() => {
if (user?.userId || user?.userId !== '$unknown') {
const isProfile = user.userId === profileUser?.userId
const isMASK = user.userId === MASK_TWITTER
setEssayMeta({
return {
image: isMASK ? Punk3D.url : isProfile ? PunkIcon : '',
word: isMASK ? DEFAULT_PUNK_MASK_WORD : DEFAULT_SET_WORD,
type: isMASK ? ImageType.GLB : ImageType.NORMAL,
type: ImageType.NORMAL,
contract: '',
tokenId: '',
chainId: undefined,
})
}
} else {
setEssayMeta(undefined)
return
}
}, [user, profileUser])
return essayMeta
Expand Down

0 comments on commit d3a4515

Please sign in to comment.