Compare commits
6 Commits
faba9fa3cb
...
e7f6de4a29
Author | SHA1 | Date | |
---|---|---|---|
e7f6de4a29 | |||
b9d47ba401 | |||
d54d05403b | |||
1898d554f9 | |||
50225f1c17 | |||
00be94c5a8 |
7
.idea/discord.xml
generated
Normal file
7
.idea/discord.xml
generated
Normal 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>
|
@ -14,7 +14,7 @@ import { Label } from "@/components/ui/label";
|
|||||||
import type { IUserData } from "@/interfaces/userdata.interface";
|
import type { IUserData } from "@/interfaces/userdata.interface";
|
||||||
|
|
||||||
import { CopyButton } from "@/components/ui/copy-button";
|
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 { Bitcoin, Fingerprint, Key, Landmark, Unplug, User, Wallet } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
@ -28,6 +28,9 @@ export function AccountInfo({
|
|||||||
setUserData: React.Dispatch<React.SetStateAction<IUserData | undefined>>;
|
setUserData: React.Dispatch<React.SetStateAction<IUserData | undefined>>;
|
||||||
isDisconnected: boolean;
|
isDisconnected: boolean;
|
||||||
}) {
|
}) {
|
||||||
|
getWallet().then(() => {
|
||||||
|
console.log("pong !");
|
||||||
|
});
|
||||||
if (isDisconnected) {
|
if (isDisconnected) {
|
||||||
return (
|
return (
|
||||||
<div className={"flex flex-col justify-center items-center h-10 p-2 text-xs mt-2"}>
|
<div className={"flex flex-col justify-center items-center h-10 p-2 text-xs mt-2"}>
|
||||||
|
@ -1,21 +1,25 @@
|
|||||||
"use client";
|
"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 AutoForm, { AutoFormSubmit } from "@/components/auto-form";
|
||||||
import {UserDataContext} from "@/components/providers/userdata-provider";
|
import { UserDataContext } from "@/components/providers/userdata-provider";
|
||||||
import type {IApiLoginReq, IApiLoginRes, IApiRegisterReq, IApiRegisterRes} from "@/interfaces/api.interface";
|
import { ToastBox, toastType } from "@/components/ui/toast-box";
|
||||||
import type {IUserData} from "@/interfaces/userdata.interface";
|
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 ApiRequest from "@/services/apiRequest";
|
||||||
import {EReturnState, type IStandardisedReturn} from "@/services/general.interface";
|
import { useLocalStorage } from "@/services/localStorage";
|
||||||
import {useLocalStorage} from "@/services/localStorage";
|
import { Bug, RefreshCw } from "lucide-react";
|
||||||
import {Bug, RefreshCw} from "lucide-react";
|
|
||||||
import Link from "next/link";
|
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 * as z from "zod";
|
||||||
import {ToastBox, toastType} from "@/components/ui/toast-box";
|
|
||||||
import {useToast} from "@/components/ui/use-toast";
|
|
||||||
|
|
||||||
|
|
||||||
const loginSchema = z.object({
|
const loginSchema = z.object({
|
||||||
email: z
|
email: z
|
||||||
@ -62,7 +66,7 @@ export function AuthForms() {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [sub, setSub] = useLocalStorage<string | undefined>("sub", "");
|
const [sub, setSub] = useLocalStorage<string | undefined>("sub", "");
|
||||||
const userContext = useContext(UserDataContext);
|
const userContext = useContext(UserDataContext);
|
||||||
const { toast } = useToast()
|
const { toast } = useToast();
|
||||||
|
|
||||||
async function doRegister(
|
async function doRegister(
|
||||||
registerData: IApiRegisterReq,
|
registerData: IApiRegisterReq,
|
||||||
@ -76,8 +80,15 @@ export function AuthForms() {
|
|||||||
>("auth/signup", registerData);
|
>("auth/signup", registerData);
|
||||||
console.trace(ReqRes.data);
|
console.trace(ReqRes.data);
|
||||||
if (ReqRes.data.user) {
|
if (ReqRes.data.user) {
|
||||||
userDataSetter(ReqRes.data.user);
|
userDataSetter({
|
||||||
setSub(ReqRes.data.access_token);
|
...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");
|
console.debug(ReqRes.data.message || "Not additional message from request");
|
||||||
return {
|
return {
|
||||||
@ -147,19 +158,19 @@ export function AuthForms() {
|
|||||||
toast({
|
toast({
|
||||||
description: res.message || "An unexpected error occurred..",
|
description: res.message || "An unexpected error occurred..",
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
})
|
});
|
||||||
setIsLoading(false)
|
setIsLoading(false);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
//toast.custom(<ToastBox message={"Login successful ! \n You will be redirected."} type={toastType.success}/>)
|
//toast.custom(<ToastBox message={"Login successful ! \n You will be redirected."} type={toastType.success}/>)
|
||||||
toast({
|
toast({
|
||||||
description: "Login successful ! \n You will be redirected."
|
description: "Login successful ! \n You will be redirected.",
|
||||||
})
|
});
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
setIsLoading(false)
|
setIsLoading(false);
|
||||||
location.href = "/"
|
location.href = "/";
|
||||||
console.log('Moving to home.')
|
console.log("Moving to home.");
|
||||||
}, 3_000)
|
}, 3_000);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
fieldConfig={{
|
fieldConfig={{
|
||||||
@ -193,15 +204,15 @@ export function AuthForms() {
|
|||||||
).then((res) => {
|
).then((res) => {
|
||||||
if (res.state !== EReturnState.done) {
|
if (res.state !== EReturnState.done) {
|
||||||
//toast.custom(<ToastBox message={res.message || "An unexpected error occurred.."} type={toastType.error}/>)
|
//toast.custom(<ToastBox message={res.message || "An unexpected error occurred.."} type={toastType.error}/>)
|
||||||
setIsLoading(false)
|
setIsLoading(false);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
//toast.custom(<ToastBox message={"Register successful ! \n You will be redirected."} type={toastType.success}/>)
|
//toast.custom(<ToastBox message={"Register successful ! \n You will be redirected."} type={toastType.success}/>)
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
setIsLoading(false)
|
setIsLoading(false);
|
||||||
//location.href = "/"
|
//location.href = "/"
|
||||||
console.log('Moving to home.')
|
console.log("Moving to home.");
|
||||||
}, 5_000)
|
}, 5_000);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
fieldConfig={{
|
fieldConfig={{
|
||||||
|
@ -49,7 +49,7 @@ export function Footer() {
|
|||||||
<h3 className={"text-nowrap text-center"}>Support Center</h3>
|
<h3 className={"text-nowrap text-center"}>Support Center</h3>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div/>
|
<div />
|
||||||
</footer>
|
</footer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,15 @@ export interface IApiLoginReq {
|
|||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IApiTradeCreateRq {
|
||||||
|
id_offer: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IApiOfferCreateReq {
|
||||||
|
id_crypto: string;
|
||||||
|
amount: number;
|
||||||
|
}
|
||||||
|
|
||||||
// ----- Response -----
|
// ----- Response -----
|
||||||
|
|
||||||
export interface IAbstractApiResponse {
|
export interface IAbstractApiResponse {
|
||||||
@ -43,4 +52,12 @@ export interface IApiUserAssetsRes extends IAbstractApiResponse {
|
|||||||
UserHasCrypto?: IUserWalletCryptos[];
|
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 {}
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type {
|
import type { IApiAllTradesRes, IApiUserAssetsRes } from "@/interfaces/api.interface";
|
||||||
IApiLoginReq,
|
import { IUserWalletCryptos } from "@/interfaces/crypto.interface";
|
||||||
IApiLoginRes,
|
import { EReturnState, type IStandardisedReturn } from "@/interfaces/general.interface";
|
||||||
IApiRegisterReq,
|
import type { IUserData, IUserWallet } from "@/interfaces/userdata.interface";
|
||||||
IApiRegisterRes,
|
|
||||||
} from "@/interfaces/api.interface";
|
|
||||||
import type { IUserData } from "@/interfaces/userdata.interface";
|
|
||||||
import ApiRequest from "@/services/apiRequest";
|
import ApiRequest from "@/services/apiRequest";
|
||||||
import { EReturnState, IStandardisedReturn } from "@/services/general.interface";
|
|
||||||
import { useLocalStorage } from "@/services/localStorage";
|
|
||||||
import type { Dispatch, SetStateAction } from "react";
|
import type { Dispatch, SetStateAction } from "react";
|
||||||
|
|
||||||
//TODO Run disconnect task
|
//TODO Run disconnect task
|
||||||
@ -21,9 +16,97 @@ export function doDisconnect() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
console.log(
|
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;
|
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() {}
|
Loading…
x
Reference in New Issue
Block a user