diff --git a/src/components/account-info.tsx b/src/components/account-info.tsx index 17bf88b..b7e6ca0 100644 --- a/src/components/account-info.tsx +++ b/src/components/account-info.tsx @@ -11,13 +11,15 @@ import { } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; -import type { IUserData } from "@/interfaces/userdata.interface"; +import type {IUserData, IUserWallet} from "@/interfaces/userdata.interface"; import { CopyButton } from "@/components/ui/copy-button"; import { doDisconnect, getWallet } from "@/services/account.handler"; import { Bitcoin, Fingerprint, Key, Landmark, Unplug, User, Wallet } from "lucide-react"; import Link from "next/link"; import type React from "react"; +import {useEffect, useState} from "react"; +import {type ICryptoInUserWalletInfo, ICryptoInWalletInfo} from "@/interfaces/crypto.interface"; export function AccountInfo({ userData, @@ -28,9 +30,41 @@ export function AccountInfo({ setUserData: React.Dispatch>; isDisconnected: boolean; }) { - getWallet().then(() => { - console.log("pong !"); - }); + const [isLoaded,setIsLoaded] = useState(false) + + useEffect(() => { + if (!isLoaded) { + getWallet().then((res) => { + + const wallet: IUserWallet = { + uat: Date.now(), + update_interval: 30_000, + owned_cryptos: res.resolved?.UserHasCrypto?.map((el): ICryptoInUserWalletInfo => { + return { + id: el.Crypto.id, + name: el.Crypto.name, + value: el.Crypto.value, + image: el.Crypto.image, + quantity: el.Crypto.quantity, + owned_amount: el.amount, + created_at: el.Crypto.created_at, + updated_at: el.Crypto.updated_at + } + }) || [] + } + + delete res.resolved?.UserHasCrypto + //@ts-ignore + setUserData({ + ...userData, + ...res.resolved, + wallet: wallet + }) + console.log(userData) + setIsLoaded(true) + }); + } + }, [isLoaded]); if (isDisconnected) { return (
@@ -64,7 +98,7 @@ export function AccountInfo({ - + {`Your account - ${userData.firstName} ${userData.lastName}`} {userData.city} @@ -93,7 +127,7 @@ export function AccountInfo({ >

- You dont have cryptos. + {`You currently have ${userData.wallet.owned_cryptos.length} crypto(s)`}

@@ -116,13 +150,15 @@ export function AccountInfo({ -