Compare commits

...

6 Commits

Author SHA1 Message Date
e7f6de4a29
feat(ide): add discord.xml file
This commit includes the creation of a new discord.xml file under the .idea directory. This config file brings in new settings for the DiscordProject related to its 'show' and 'description' options.
2024-06-18 21:33:43 +02:00
b9d47ba401
style(footer): adjust div spacing in footer component
This commit properly adjusts the spacing in an empty div within the footer section of the React component for adherence to standardized code formatting. Proper spacing contributes to code readability and maintainability.
2024-06-18 21:33:17 +02:00
d54d05403b
feat(auth-form): enhance user registration and login process
This commit introduces some improvements to the user registration and login processes. It standardizes the update interval in the user data upon registration, fixes the missing 'toString' call for 'access_token' and improves code readability by correcting indents and adding extra spaces. Additionally, this commit refactors the redirection logic after successful login or registration, making it more robust and reliable.
2024-06-18 21:32:49 +02:00
1898d554f9
feat(interfaces): add new API interfaces and update existing ones
New interfaces were added to enhance functionality for trade and offer creation requests. Renamed IApiAllTrades interface to IApiAllTradesRes for consistency. Interfaces were also added to manage referral codes and rankings.
2024-06-18 21:22:49 +02:00
50225f1c17
feat(account-info): import and use getWallet from account handler
The 'getWallet' function has been imported from the account handler service and is now used in account-info component. This addition ensures to fetch information when the component renders.
2024-06-18 21:22:34 +02:00
00be94c5a8
feat(account.handler): add new API methods
This commit adds several new async functions to fetch wallet, user trades and all trades in `account.handler.ts`. This provides an interface for interacting with multiple new endpoints. Additionally, several import statements have been updated to reflect the changes.
2024-06-18 21:22:12 +02:00
6 changed files with 166 additions and 45 deletions

7
.idea/discord.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="APPLICATION" />
<option name="description" value="" />
</component>
</project>

View File

@ -14,7 +14,7 @@ import { Label } from "@/components/ui/label";
import type { IUserData } from "@/interfaces/userdata.interface";
import { CopyButton } from "@/components/ui/copy-button";
import { doDisconnect } from "@/services/account.handler";
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";
@ -28,6 +28,9 @@ export function AccountInfo({
setUserData: React.Dispatch<React.SetStateAction<IUserData | undefined>>;
isDisconnected: boolean;
}) {
getWallet().then(() => {
console.log("pong !");
});
if (isDisconnected) {
return (
<div className={"flex flex-col justify-center items-center h-10 p-2 text-xs mt-2"}>

View File

@ -1,21 +1,25 @@
"use client";
import {Tabs, TabsContent, TabsList, TabsTrigger} from "@/components/ui/tabs";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import AutoForm, {AutoFormSubmit} from "@/components/auto-form";
import {UserDataContext} from "@/components/providers/userdata-provider";
import type {IApiLoginReq, IApiLoginRes, IApiRegisterReq, IApiRegisterRes} from "@/interfaces/api.interface";
import type {IUserData} from "@/interfaces/userdata.interface";
import AutoForm, { AutoFormSubmit } from "@/components/auto-form";
import { UserDataContext } from "@/components/providers/userdata-provider";
import { ToastBox, toastType } from "@/components/ui/toast-box";
import { useToast } from "@/components/ui/use-toast";
import type {
IApiLoginReq,
IApiLoginRes,
IApiRegisterReq,
IApiRegisterRes,
} from "@/interfaces/api.interface";
import { EReturnState, type IStandardisedReturn } from "@/interfaces/general.interface";
import type { IUserData } from "@/interfaces/userdata.interface";
import ApiRequest from "@/services/apiRequest";
import {EReturnState, type IStandardisedReturn} from "@/services/general.interface";
import {useLocalStorage} from "@/services/localStorage";
import {Bug, RefreshCw} from "lucide-react";
import { useLocalStorage } from "@/services/localStorage";
import { Bug, RefreshCw } from "lucide-react";
import Link from "next/link";
import {type Dispatch, type SetStateAction, useContext, useState} from "react";
import { type Dispatch, type SetStateAction, useContext, useState } from "react";
import * as z from "zod";
import {ToastBox, toastType} from "@/components/ui/toast-box";
import {useToast} from "@/components/ui/use-toast";
const loginSchema = z.object({
email: z
@ -62,7 +66,7 @@ export function AuthForms() {
const [isLoading, setIsLoading] = useState(false);
const [sub, setSub] = useLocalStorage<string | undefined>("sub", "");
const userContext = useContext(UserDataContext);
const { toast } = useToast()
const { toast } = useToast();
async function doRegister(
registerData: IApiRegisterReq,
@ -76,8 +80,15 @@ export function AuthForms() {
>("auth/signup", registerData);
console.trace(ReqRes.data);
if (ReqRes.data.user) {
userDataSetter(ReqRes.data.user);
setSub(ReqRes.data.access_token);
userDataSetter({
...ReqRes.data.user,
wallet: {
uat: Date.now(),
update_interval: 30_000,
owned_cryptos: [],
},
});
setSub(ReqRes.data.access_token?.toString());
}
console.debug(ReqRes.data.message || "Not additional message from request");
return {
@ -147,19 +158,19 @@ export function AuthForms() {
toast({
description: res.message || "An unexpected error occurred..",
variant: "destructive",
})
setIsLoading(false)
return
});
setIsLoading(false);
return;
}
//toast.custom(<ToastBox message={"Login successful ! \n You will be redirected."} type={toastType.success}/>)
toast({
description: "Login successful ! \n You will be redirected."
})
setTimeout(()=>{
setIsLoading(false)
location.href = "/"
console.log('Moving to home.')
}, 3_000)
description: "Login successful ! \n You will be redirected.",
});
setTimeout(() => {
setIsLoading(false);
location.href = "/";
console.log("Moving to home.");
}, 3_000);
});
}}
fieldConfig={{
@ -193,15 +204,15 @@ export function AuthForms() {
).then((res) => {
if (res.state !== EReturnState.done) {
//toast.custom(<ToastBox message={res.message || "An unexpected error occurred.."} type={toastType.error}/>)
setIsLoading(false)
return
setIsLoading(false);
return;
}
//toast.custom(<ToastBox message={"Register successful ! \n You will be redirected."} type={toastType.success}/>)
setTimeout(()=>{
setIsLoading(false)
setTimeout(() => {
setIsLoading(false);
//location.href = "/"
console.log('Moving to home.')
}, 5_000)
console.log("Moving to home.");
}, 5_000);
});
}}
fieldConfig={{

View File

@ -49,7 +49,7 @@ export function Footer() {
<h3 className={"text-nowrap text-center"}>Support Center</h3>
</Link>
</div>
<div/>
<div />
</footer>
);
}

View File

@ -18,6 +18,15 @@ export interface IApiLoginReq {
password: string;
}
export interface IApiTradeCreateRq {
id_offer: string;
}
export interface IApiOfferCreateReq {
id_crypto: string;
amount: number;
}
// ----- Response -----
export interface IAbstractApiResponse {
@ -43,4 +52,12 @@ export interface IApiUserAssetsRes extends IAbstractApiResponse {
UserHasCrypto?: IUserWalletCryptos[];
}
export interface IApiAllTrades extends IAbstractApiResponse {}
export interface IApiAllTradesRes extends IAbstractApiResponse {}
export interface IAllRankRes extends IAbstractApiResponse {}
export interface IAllReferralCodeRes extends IAbstractApiResponse {}
export interface IReferralCodeUpdateRes extends IAbstractApiResponse {}
export interface IReferralCodeDeleteRes extends IAbstractApiResponse {}

View File

@ -1,15 +1,10 @@
"use client";
import type {
IApiLoginReq,
IApiLoginRes,
IApiRegisterReq,
IApiRegisterRes,
} from "@/interfaces/api.interface";
import type { IUserData } from "@/interfaces/userdata.interface";
import type { IApiAllTradesRes, IApiUserAssetsRes } from "@/interfaces/api.interface";
import { IUserWalletCryptos } from "@/interfaces/crypto.interface";
import { EReturnState, type IStandardisedReturn } from "@/interfaces/general.interface";
import type { IUserData, IUserWallet } from "@/interfaces/userdata.interface";
import ApiRequest from "@/services/apiRequest";
import { EReturnState, IStandardisedReturn } from "@/services/general.interface";
import { useLocalStorage } from "@/services/localStorage";
import type { Dispatch, SetStateAction } from "react";
//TODO Run disconnect task
@ -21,9 +16,97 @@ export function doDisconnect() {
return true;
}
console.log(
"Whut ? Why trying to remove an item from the localStorage when runner in SSR ?",
"Whut ? Why trying to remove an item from the localStorage when running in SSR ?",
);
return false;
}
//TODO Run update user data
export async function getWallet(): Promise<IStandardisedReturn<IApiUserAssetsRes>> {
try {
const ReqRes =
await ApiRequest.authenticated.get.json<IStandardisedReturn<IApiUserAssetsRes>>(
"user/my-assets",
);
console.log(ReqRes.data);
if (ReqRes.status !== 200) {
return {
state: EReturnState.clientError,
};
}
return {
state: EReturnState.done,
resolved: ReqRes.data,
};
} catch (err) {
return {
state: EReturnState.serverError,
};
}
}
export async function getUserTrades() {
try {
const ReqRes =
await ApiRequest.authenticated.get.json<IStandardisedReturn<IApiAllTradesRes>>(
"user/my-trades",
);
console.log(ReqRes.data);
if (ReqRes.status !== 200) {
return {
state: EReturnState.clientError,
};
}
return {
state: EReturnState.done,
resolved: ReqRes.data,
};
} catch (err) {
return {
state: EReturnState.serverError,
};
}
}
export async function getAlltrades() {
try {
const ReqRes =
await ApiRequest.authenticated.get.json<IStandardisedReturn<IApiAllTradesRes>>(
"trade/all",
);
console.log(ReqRes.data);
if (ReqRes.status !== 200) {
return {
state: EReturnState.clientError,
};
}
return {
state: EReturnState.done,
resolved: ReqRes.data,
};
} catch (err) {
return {
state: EReturnState.serverError,
};
}
}
export async function createTrade() {}
export async function getAllTrade() {}
export async function getUserTrade() {}
export async function getAllReferralCode() {}
export async function createReferralCode() {}
export async function getAllCryptos() {}
export async function getCryptoHistory(cryptoId: string) {}
export async function sellCrypto() {}
export async function buyCrypto() {}