From b811860ca2c4cb5c7d760a4ac981aa0c3be5a1da Mon Sep 17 00:00:00 2001 From: wfnuser Date: Thu, 18 Jul 2024 21:07:49 +0700 Subject: [PATCH] feat: update profile --- src/pages/profile/index.tsx | 65 ++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index 3278143..d3b985d 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -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 ( + <> + + + + + + + + ) +} + export default function Profile() { - return

User Profile

+ 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 + } + + return ( +
+

User Profile

+

Username: {username}

+

Linked Address: {linkedAddress}

+

User Points: {userPoints}

+ {/* 添加更多的用户信息显示 */} +
+ ) }