From d9858ecae89220e69fd8cfa9a28dd4b458e12f74 Mon Sep 17 00:00:00 2001 From: Mathis Date: Fri, 14 Jun 2024 10:06:57 +0200 Subject: [PATCH] refactor: Update account-related components and services Enhanced account-related components and services to include wallet and asset information. Introduced `refreshUserData` function in account handler service to fetch and update user assets. Revised local storage service to include encoding and decoding functionality for secure storage. On the components side, `account-info` and `account-dialog` components have been updated to reflect the new functionalities and data fields. User interface for account information has been improved including details for cryptos and identity information. --- src/components/account-dialog.tsx | 53 ++++++++++++--- src/components/account-info.tsx | 69 ++++++++++++++++--- src/services/account.handler.ts | 49 ++++++++++++-- src/services/localStorage.ts | 109 ++++++++++++++++++------------ 4 files changed, 216 insertions(+), 64 deletions(-) diff --git a/src/components/account-dialog.tsx b/src/components/account-dialog.tsx index 7add37e..a3a320e 100644 --- a/src/components/account-dialog.tsx +++ b/src/components/account-dialog.tsx @@ -4,7 +4,13 @@ import { AccountInfo } from "@/components/account-info"; import { UserDataContext } from "@/components/providers/userdata-provider"; import { Skeleton } from "@/components/ui/skeleton"; import type { IUserData } from "@/interfaces/userdata.interface"; -import {Dispatch, SetStateAction, useContext, useEffect, useState} from "react"; +import { + type Dispatch, + type SetStateAction, + useContext, + useEffect, + useState, +} from "react"; export function AccountDialog() { const userContext = useContext(UserDataContext); @@ -12,18 +18,44 @@ export function AccountDialog() { if (!userContext?.userData) { userContext?.setUserData({ - age: 0, + firstName: "Mathis", + lastName: "Herriot", + age: 23, city: "Chambéry", created_at: "jaj", dollarAvailables: 34, email: "mherriot@tutanota.com", - id: "", - isActive: false, - lastName: "Herriot", + id: "098807e1-6681-407a-a2b4-e6b7e5ec1919", + isActive: true, pseudo: "Avnyr", - roleId: "", + roleId: "092fb1eb-4ce4-4e3e-9df1-d00d467c6a43", updated_at: "", - firstName: "Mathis", + wallet: { + uat: Date.now(), + update_interval: 30_000, + owned_cryptos: [ + { + id: "1c237bcc-d2fa-4c4b-9a3a-f0efb4569e1e", + name: "Spectral", + value: 1.61051, + image: + "https://images.unsplash.com/photo-1640833906651-6bd1af7aeea3?w=800&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTh8fGNyeXB0b3xlbnwwfHwwfHx8MA%3D%3D", + quantity: 999, + created_at: "2024-06-08T22:42:14.113Z", + updated_at: "2024-06-11T12:48:07.001Z", + }, + { + id: "6c0edc95-a968-4c2f-9169-33acfdc73575", + name: "SOL", + value: 30.91268053287073, + image: + "https://images.unsplash.com/photo-1523961131990-5ea7c61b2107?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Nnx8Y3J5cHRvfGVufDB8fDB8fHww", + quantity: 998, + created_at: "2024-06-07T09:30:31.282Z", + updated_at: "2024-06-08T23:44:54.242Z", + }, + ], + }, }); } @@ -39,7 +71,12 @@ export function AccountDialog() { return (
- >} /> + > + } + />
); } diff --git a/src/components/account-info.tsx b/src/components/account-info.tsx index c314f1b..493cd55 100644 --- a/src/components/account-info.tsx +++ b/src/components/account-info.tsx @@ -13,8 +13,11 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import type { IUserData } from "@/interfaces/userdata.interface"; -import { Landmark, Unplug, User, Wallet } from "lucide-react"; +import { CopyButton } from "@/components/ui/copy-button"; +import {Bitcoin, Fingerprint, Landmark, RefreshCw, Unplug, User, Wallet} from "lucide-react"; import type React from "react"; +import {useState} from "react"; +import {refreshUserData} from "@/services/account.handler"; export function AccountInfo({ userData, @@ -23,6 +26,14 @@ export function AccountInfo({ userData: IUserData; setUserData: React.Dispatch>; }) { + + const [refreshOngoing, setRefreshOngoing] = useState(false) + + function doingRefresh() { + setRefreshOngoing(true); + refreshUserData().then(()=>setRefreshOngoing(false)) + } + return ( @@ -33,19 +44,59 @@ export function AccountInfo({ - {`Your account - ${userData.firstName} ${userData.lastName}`} - {userData.city} + {`${userData.firstName} ${userData.lastName}`} + Your personal account data.
-
-
- -

{userData.dollarAvailables} $

+
+
+
+ +

+ {userData.dollarAvailables} $ +

+
+
+ +

+ You dont have cryptos. +

+
+
+
+
+ +

Your identity

+
+
+

{userData.id}

+ +
-
- + + {!refreshOngoing && }