Skip to content

Commit

Permalink
feat: update profile
Browse files Browse the repository at this point in the history
  • Loading branch information
wfnuser committed Jul 18, 2024
1 parent 299e111 commit b811860
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion src/pages/profile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
import { useState, useEffect } from 'react'
import Cookies from 'js-cookie'
import { NetworkType, SDK } from 'youbet-sdk'
import { SkeletonCard } from '@/components/skeleton-card'

const sdk = new SDK({
networkType: NetworkType.Testnet, // or NetworkType.Mainnet
})

function SkeletonTasks() {
return (
<>
<SkeletonCard />
<SkeletonCard />
<SkeletonCard />
<SkeletonCard />
<SkeletonCard />
<SkeletonCard />
</>
)
}

export default function Profile() {
return <h2>User Profile</h2>
const [username, setUsername] = useState('')
const [linkedAddress, setLinkedAddress] = useState('')
const [userPoints, setUserPoints] = useState('')
const [loading, setLoading] = useState(true)

useEffect(() => {
const fetchUserProfile = async () => {
try {
const github = Cookies.get('username')
setUsername(github || '')

const linkedAddressResponse = await fetch(`/api/get-linked-wallet?github=${github}`)
const linkedAddress = await linkedAddressResponse.text()
setLinkedAddress(linkedAddress)

if (linkedAddress !== '0x0000000000000000000000000000000000000000') {
const points = await sdk.client.getUserPoints(linkedAddress)
setUserPoints(points.toString())
}
} catch (error) {
console.error('Error fetching user profile:', error)
} finally {
setLoading(false)
}
}

fetchUserProfile()
}, [])

if (loading) {
return <SkeletonTasks />
}

return (
<div>
<h2>User Profile</h2>
<p>Username: {username}</p>
<p>Linked Address: {linkedAddress}</p>
<p>User Points: {userPoints}</p>
{/* 添加更多的用户信息显示 */}
</div>
)
}

0 comments on commit b811860

Please sign in to comment.