- Your Bid
+ Amount
- {" "}
+
{bid.amount} {bid.currency}
diff --git a/src/app/component/my-positions/positions-cards.tsx b/src/app/component/my-positions/positions-cards.tsx
index a771e98..a8d51d0 100644
--- a/src/app/component/my-positions/positions-cards.tsx
+++ b/src/app/component/my-positions/positions-cards.tsx
@@ -1,33 +1,38 @@
-import React, { useEffect, useState } from "react";
-import Card, { CardProps } from "./_components/card";
+import React, { useCallback, useEffect, useState } from "react";
+import Card from "./_components/card";
import useAuth from "@/hooks/useAuth";
-import { LoanData, getMyLoan } from "@/services/api/my-position";
import { positionCardsData } from "@/data";
import Slider from "react-slick";
import useElementWidth from "@/hooks/useElementWidth";
-import { DateTime, Duration } from "luxon";
-import { getMarketLoans } from "@/services/api/market-loans";
+import { DateTime } from "luxon";
import { ILoanRequest } from "@/interfaces/loan-interface";
+import { getMyLoan, getMySuppliedLoan } from "@/services/api/my-position";
+import EmptyComponent from "../common/Empty";
interface PositionCardsProps {
- positionCardsData: CardProps[];
gridStyle?: string;
- isDashBoard?: boolean;
+ suppliedLoans?: boolean;
+ image?: string;
+ description?: string;
+ action?: string;
}
-export const PositionCards = ({ isDashBoard }: PositionCardsProps) => {
+export const PositionCards = ({ suppliedLoans, description, image, action }: PositionCardsProps) => {
const [sectionWidth, sectionRef] = useElementWidth();
const [slidesToShow, setSlidesToShow] = useState(3);
+ const { address } = useAuth();
+ const [loanData, setLoanData] = useState();
+ const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
if (sectionWidth) {
if (sectionWidth > 1800) {
setSlidesToShow(5);
- } else if (sectionWidth < 768 && sectionWidth > 350) {
+ } else if (sectionWidth < 650 && sectionWidth > 450) {
setSlidesToShow(2);
} else if (sectionWidth > 1200 && sectionWidth <= 1800) {
setSlidesToShow(4);
- } else if (sectionWidth > 768 && sectionWidth <= 1200) {
+ } else if (sectionWidth > 650 && sectionWidth <= 1200) {
setSlidesToShow(3);
} else {
setSlidesToShow(1);
@@ -44,12 +49,10 @@ export const PositionCards = ({ isDashBoard }: PositionCardsProps) => {
slidesToScroll: 1,
};
- const { address, logout, addressBalance } = useAuth();
- const [loanData, setLoanData] = useState();
- const [isLoading, setIsLoading] = useState(false);
-
- const handleGetMyLoanAPI = () => {
- if (!address) return;
+ const handleGetMyLoanAPI = useCallback(() => {
+ if (!address) {
+ return;
+ };
setIsLoading(true);
getMyLoan(address)
.then((data) => {
@@ -58,61 +61,59 @@ export const PositionCards = ({ isDashBoard }: PositionCardsProps) => {
}
})
.finally(() => setIsLoading(false));
- };
+ }, [address]);
+
- const handleGetMarketLoans = () => {
+ const handleGetMySuppliedLoansAPI = useCallback(() => {
+ if (!address) {
+ return;
+ };
setIsLoading(true);
- getMarketLoans()
- .then((data) => setLoanData(data?.slice(0, 3)))
+ getMySuppliedLoan(address)
+ .then((data) => {
+ if (data) {
+ setLoanData(data);
+ }
+ })
.finally(() => setIsLoading(false));
- };
+ }, [address]);
useEffect(() => {
- if (isDashBoard) {
- handleGetMarketLoans();
+ if (suppliedLoans) {
+ handleGetMySuppliedLoansAPI();
} else {
handleGetMyLoanAPI();
}
- }, []);
+ }, [suppliedLoans, handleGetMyLoanAPI, handleGetMySuppliedLoansAPI]);
if (isLoading) return Loading...
;
function calculateCountdown(date: string) {
const targetDate = DateTime.fromISO(date);
const now = DateTime.now();
- const diff = targetDate.diff(now, ["hours", "minutes", "seconds"]);
-
- const countdown = `${Math.floor(diff.hours)}h ${Math.floor(diff.minutes)}m ${Math.floor(diff.seconds)}s`;
+ const diff = targetDate.diff(now, ["days", "hours", "minutes", "seconds"]);
+ const countdown = `${Math.floor(diff.days)}d ${Math.floor(diff.hours)}h ${Math.floor(diff.minutes)}m ${Math.floor(diff.seconds)}s`;
return countdown;
}
return (
- {/* {positionCardsData &&
- positionCardsData.map((item, index) => (
-
-
-
- ))} */}
- {loanData &&
+ {loanData ?
loanData.map((item, index) => (
- ))}
+ ))
+ :
+
+ }
);
diff --git a/src/app/data/currency.ts b/src/app/data/currency.ts
new file mode 100644
index 0000000..e0a35aa
--- /dev/null
+++ b/src/app/data/currency.ts
@@ -0,0 +1,21 @@
+import { CurrencyOption } from "@/types/liquidation";
+
+export type Currency = CurrencyOption[];
+
+export const requestAmountOptions: Currency = [
+ { name: "USDT", value: "usdt", address: "", image: "/tokens/usdt.svg" },
+ { name: "BTC", value: "btc", address: "", image: "/tokens/btc.svg" },
+ { name: "USDC", value: "usdc", address: "", image: "/tokens/usdc.svg" },
+ { name: "ETH", value: "eth", address: "", image: "/tokens/eth.svg" },
+ { name: "LINK", value: "link", address: "", image: "/tokens/link.svg" },
+ { name: "MATIC", value: "matic", address: "", image: "/tokens/matic.svg" },
+];
+
+export const collateralAmountOptions: Currency = [
+ { name: "USDT", value: "usdt", address: "", image: "/tokens/usdt.svg" },
+ { name: "BTC", value: "btc", address: "", image: "/tokens/btc.svg" },
+ { name: "USDC", value: "usdc", address: "", image: "/tokens/usdc.svg" },
+ { name: "ETH", value: "eth", address: "", image: "/tokens/eth.svg" },
+ { name: "LINK", value: "link", address: "", image: "/tokens/link.svg" },
+ { name: "MATIC", value: "matic", address: "", image: "/tokens/matic.svg" },
+];
diff --git a/src/app/favicon.ico b/src/app/favicon.ico
index 718d6fe..05f5d3a 100644
Binary files a/src/app/favicon.ico and b/src/app/favicon.ico differ
diff --git a/src/constant/liquidation.ts b/src/constant/liquidation.ts
deleted file mode 100644
index 5485d68..0000000
--- a/src/constant/liquidation.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { CurrencyOption } from "../types/liquidation";
-
-export const collateralAmountOptions: CurrencyOption[] = [
- { name: "USDT", value: "usdt" },
- { name: "BTC", value: "btc" },
- { name: "USDC", value: "usdc" },
- { name: "ETH", value: "eth" },
- { name: "MATIC", value: "matic" },
- { name: "SOL", value: "sol" },
-];
diff --git a/src/constant/loan.ts b/src/constant/loan.ts
deleted file mode 100644
index 23003ce..0000000
--- a/src/constant/loan.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { CurrencyOption } from "@/types/liquidation";
-
-export const requestAmountOptions: CurrencyOption[] = [
- { name: "USDT", value: "usdt" },
- { name: "BTC", value: "btc" },
- { name: "USDC", value: "usdc" },
- { name: "ETH", value: "eth" },
- { name: "MATIC", value: "matic" },
- { name: "SOL", value: "sol" },
-];
-
-export const collateralAmountOptions: CurrencyOption[] = [
- { name: "USDT", value: "usdt" },
- { name: "BTC", value: "btc" },
- { name: "USDC", value: "usdc" },
- { name: "ETH", value: "eth" },
- { name: "MATIC", value: "matic" },
- { name: "SOL", value: "sol" },
-];
diff --git a/src/interfaces/loan-interface.ts b/src/interfaces/loan-interface.ts
index abf3d72..21d4454 100644
--- a/src/interfaces/loan-interface.ts
+++ b/src/interfaces/loan-interface.ts
@@ -1,23 +1,31 @@
export interface ILoanRequest {
- _id: string;
- userAddress: string;
- loanAmount: string;
- loanToken: string;
- collateralAmount: string;
- collateralToken: string;
- loanPeriod: Date;
- loanRequestPeriod: Date;
- healthFactor: string;
- interestRate: string;
- initialThreshold: string;
- liquidationThreshold: string;
- nftManager: string;
- nftVersion: string;
- creationDate: Date;
- borrowedStatus: string;
- investorAddress: string;
- updatedDate: Date;
- createdAt: Date;
- updatedAt: Date;
- name: string;
+ _id?: string;
+ userAddress: string;
+ loanAmount: string;
+ loanToken: string;
+ collateralAmount: string;
+ collateralToken: string;
+ loanPeriod: Date;
+ loanRequestPeriod: Date;
+ healthFactor: string;
+ interestRate: string;
+ initialThreshold: string;
+ liquidationThreshold: string;
+ nftManager: string;
+ nftVersion: string;
+ creationDate: Date;
+ loanStatus: string;
+ investorAddress: string;
+ updatedDate: Date;
+ createdAt?: Date;
+ updatedAt?: Date;
+ name: string;
+}
+
+export enum STATUS {
+ "pending" = "pending",
+ "borrowed" = "borrowed",
+ "expired" = "expired",
+ "liquidated" = "liquidated",
+ "refunded" = "refunded",
}
diff --git a/src/middleware.ts b/src/middleware.ts
index 93c0074..1c1dd78 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -1,15 +1,17 @@
-import createMiddleware from 'next-intl/middleware';
-
+import createMiddleware from "next-intl/middleware";
+
export default createMiddleware({
// A list of all locales that are supported
- locales: ['en', 'de', 'es'],
-
+ locales: ["en", "de", "es"],
+
// If this locale is matched, pathnames work without a prefix (e.g. `/about`)
- defaultLocale: 'en'
+ defaultLocale: "en",
});
-
+
+// createMiddleware(){}
+
export const config = {
// Skip all paths that should not be internationalized. This example skips
// certain folders and all pathnames with a dot (e.g. favicon.ico)
- matcher: ['/((?!api|_next|_vercel|.*\\..*).*)']
-};
\ No newline at end of file
+ matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"],
+};
diff --git a/src/models/loan-model.ts b/src/models/loan-model.ts
index df6efa2..36720a4 100644
--- a/src/models/loan-model.ts
+++ b/src/models/loan-model.ts
@@ -2,32 +2,37 @@ import { Document, Schema, model, models } from "mongoose";
import { ILoanRequest } from "@/interfaces/loan-interface";
const loanSchema = new Schema(
- {
- userAddress: { type: String, required: true },
- loanAmount: { type: String, required: true },
- loanToken: { type: String, required: true },
- collateralAmount: { type: String, required: true },
- collateralToken: { type: String, required: true },
- loanPeriod: { type: Date, required: true },
- loanRequestPeriod: { type: Date, required: true },
- healthFactor: { type: String, required: true },
- interestRate: { type: String, required: true },
- initialThreshold: { type: String, required: true },
- liquidationThreshold: { type: String, required: true },
- nftManager: { type: String, required: true },
- nftVersion: { type: String, required: true },
- creationDate: { type: Date, required: true },
- borrowedStatus: { type: String, default: "new", required: true },
- investorAddress: { type: String, required: false },
- updatedDate: { type: Date, required: false },
- name: { type: String, required: false },
- },
- {
- timestamps: true,
- }
+ {
+ userAddress: { type: String, required: true },
+ loanAmount: { type: String, required: true },
+ loanToken: { type: String, required: true },
+ collateralAmount: { type: String, required: true },
+ collateralToken: { type: String, required: true },
+ loanPeriod: { type: Date, required: true },
+ loanRequestPeriod: { type: Date, required: true },
+ healthFactor: { type: String, required: true },
+ interestRate: { type: String, required: true },
+ initialThreshold: { type: String, required: true },
+ liquidationThreshold: { type: String, required: true },
+ nftManager: { type: String, required: true },
+ nftVersion: { type: String, required: true },
+ creationDate: { type: Date, required: true },
+ loanStatus: {
+ type: String,
+ enum: ["pending", "borrowed", "expired", "liquidated", "refunded"],
+ default: "pending",
+ required: true,
+ },
+ investorAddress: { type: String, required: false },
+ updatedDate: { type: Date, required: false },
+ name: { type: String, required: false },
+ },
+ {
+ timestamps: true,
+ }
);
-// const LoanModel = model("LoanModel", loanSchema);
-const LoanModel = models.LoanModel || model("LoanModel", loanSchema);
+const LoanModel =
+ models.LoanModel || model("LoanModel", loanSchema);
export default LoanModel;
diff --git a/src/services/DTOs/LoanGet.ts b/src/services/DTOs/LoanGet.ts
index 23dd127..4e0d68a 100644
--- a/src/services/DTOs/LoanGet.ts
+++ b/src/services/DTOs/LoanGet.ts
@@ -1,9 +1,5 @@
-import { IsString, IsOptional, IsEnum } from 'class-validator';
-
-enum BorrowedStatus {
- Pending = 'pending',
- Borrowed = 'borrowed'
-}
+import { STATUS } from "@/interfaces/loan-interface";
+import { IsString, IsOptional, IsEnum } from "class-validator";
export class GetLoanDto {
@IsString()
@@ -18,7 +14,11 @@ export class GetLoanDto {
@IsOptional()
loanToken?: string;
- @IsEnum(BorrowedStatus)
+ @IsEnum(STATUS)
+ @IsOptional()
+ status?: STATUS;
+
+ @IsString()
@IsOptional()
- status?: BorrowedStatus;
+ loanName?: string;
}
diff --git a/src/services/DTOs/LoanRequest.ts b/src/services/DTOs/LoanRequest.ts
index 94895aa..071be2d 100644
--- a/src/services/DTOs/LoanRequest.ts
+++ b/src/services/DTOs/LoanRequest.ts
@@ -1,94 +1,94 @@
-import { IsNotEmpty, IsString, IsDateString, IsEnum, IsOptional } from "class-validator";
-import { ILoanRequest } from "@/interfaces/loan-interface";
-
-enum BorrowedStatus {
- new = "new",
- invested = "invested",
- closed = "closed",
-}
+import {
+ IsNotEmpty,
+ IsString,
+ IsDateString,
+ IsEnum,
+ IsOptional,
+} from "class-validator";
+import { ILoanRequest, STATUS } from "@/interfaces/loan-interface";
export class LoanRequestDto implements ILoanRequest {
- @IsNotEmpty({ message: "User address is required." })
- @IsString()
- userAddress: string;
+ @IsNotEmpty({ message: "User address is required." })
+ @IsString()
+ userAddress: string;
- @IsNotEmpty({ message: "Loan amount is required." })
- @IsString()
- loanAmount: string;
+ @IsNotEmpty({ message: "Loan amount is required." })
+ @IsString()
+ loanAmount: string;
- @IsNotEmpty({ message: "Loan token is required." })
- @IsString()
- loanToken: string;
+ @IsNotEmpty({ message: "Loan token is required." })
+ @IsString()
+ loanToken: string;
- @IsNotEmpty({ message: "Collateral amount is required." })
- @IsString()
- collateralAmount: string;
+ @IsNotEmpty({ message: "Collateral amount is required." })
+ @IsString()
+ collateralAmount: string;
- @IsNotEmpty({ message: "Collateral token is required." })
- @IsString()
- collateralToken: string;
+ @IsNotEmpty({ message: "Collateral token is required." })
+ @IsString()
+ collateralToken: string;
- @IsNotEmpty({ message: "Loan period is required." })
- @IsDateString()
- loanPeriod: Date;
+ @IsNotEmpty({ message: "Loan period is required." })
+ @IsDateString()
+ loanPeriod: Date;
- @IsNotEmpty({ message: "Loan request period is required." })
- @IsDateString()
- loanRequestPeriod: Date;
+ @IsNotEmpty({ message: "Loan request period is required." })
+ @IsDateString()
+ loanRequestPeriod: Date;
- @IsNotEmpty({ message: "Health factor is required." })
- @IsString()
- healthFactor: string;
+ @IsNotEmpty({ message: "Health factor is required." })
+ @IsString()
+ healthFactor: string;
- @IsNotEmpty({ message: "Interest rate is required." })
- @IsString()
- interestRate: string;
+ @IsNotEmpty({ message: "Interest rate is required." })
+ @IsString()
+ interestRate: string;
- @IsNotEmpty({ message: "Initial threshold is required." })
- @IsString()
- initialThreshold: string;
+ @IsNotEmpty({ message: "Initial threshold is required." })
+ @IsString()
+ initialThreshold: string;
- @IsNotEmpty({ message: "Liquidation threshold is required." })
- @IsString()
- liquidationThreshold: string;
+ @IsNotEmpty({ message: "Liquidation threshold is required." })
+ @IsString()
+ liquidationThreshold: string;
- @IsNotEmpty({ message: "NFT manager is required." })
- @IsString()
- nftManager: string;
+ @IsNotEmpty({ message: "NFT manager is required." })
+ @IsString()
+ nftManager: string;
- @IsNotEmpty({ message: "NFT version is required." })
- @IsString()
- nftVersion: string;
+ @IsNotEmpty({ message: "NFT version is required." })
+ @IsString()
+ nftVersion: string;
- @IsNotEmpty({ message: "Borrowed status is required." })
- @IsEnum(BorrowedStatus)
- borrowedStatus: BorrowedStatus;
+ @IsNotEmpty({ message: "Loan status is required." })
+ @IsEnum(STATUS)
+ loanStatus: STATUS;
- @IsNotEmpty({ message: "Investor Address is required." })
- @IsString()
- investorAddress: string;
+ @IsNotEmpty({ message: "Investor Address is required." })
+ @IsString()
+ investorAddress: string;
- @IsNotEmpty({ message: "Creation Date is required." })
- @IsDateString()
- creationDate: Date;
+ @IsNotEmpty({ message: "Creation Date is required." })
+ @IsDateString()
+ creationDate: Date;
- @IsNotEmpty({ message: "Updated date is required." })
- @IsDateString()
- updatedDate: Date;
+ @IsNotEmpty({ message: "Updated date is required." })
+ @IsDateString()
+ updatedDate: Date;
- @IsOptional()
- @IsString()
- _id: string;
+ @IsOptional()
+ @IsString()
+ _id?: string;
- @IsOptional()
- @IsDateString()
- createdAt: Date;
+ @IsOptional()
+ @IsDateString()
+ createdAt?: Date;
- @IsOptional()
- @IsDateString()
- updatedAt: Date;
+ @IsOptional()
+ @IsDateString()
+ updatedAt?: Date;
- @IsOptional()
- @IsString()
- name: string;
+ @IsOptional()
+ @IsString()
+ name: string;
}
diff --git a/src/services/api/dashboard.ts b/src/services/api/dashboard.ts
index 39e4124..16125b9 100644
--- a/src/services/api/dashboard.ts
+++ b/src/services/api/dashboard.ts
@@ -1,19 +1,20 @@
import { get } from "@/services/utils";
export type LoanData = {
- _id: string;
- userAddress: string;
- loanToken: string;
- collateralToken: string;
- collateralAmount: number;
- liquidationThreshold: number;
- initialThreshold: number;
- loanRepayDeadline: number;
- loanRequestDeadline: number;
- interestRate: number;
- createdAt: string;
- updatedAt: string;
- __v: number;
+ _id: string;
+ userAddress: string;
+ loanToken: string;
+ loanAmount: string;
+ collateralToken: string;
+ collateralAmount: number;
+ liquidationThreshold: number;
+ initialThreshold: number;
+ loanRepayDeadline: number;
+ loanRequestDeadline: number;
+ interestRate: number;
+ createdAt: string;
+ updatedAt: string;
+ __v: number;
};
type GetRecentLoanResponse = LoanData[];
@@ -27,7 +28,9 @@ type GetRecentLoanResponse = LoanData[];
// get("/getRecentLoan").then((data) => data.data?.data);
export const getRecentLoan = async (walletAddress: String) => {
- return get("/loan?borrowerID=" + walletAddress).then((data) => {
- return data.data;
- });
+ return get(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/loan?borrowerID=` + walletAddress
+ ).then((data) => {
+ return data.data;
+ });
};
diff --git a/src/services/api/getPrice.ts b/src/services/api/getPrice.ts
index 498e6ab..13ee45d 100644
--- a/src/services/api/getPrice.ts
+++ b/src/services/api/getPrice.ts
@@ -1,10 +1,14 @@
import { get } from "../utils";
interface Price {
- token: string;
- price: number;
+ token: string;
+ price: number;
}
export const getPriceApi = async (tokenPair: string) => {
- return (await get(`/get-price?tokenPair=${tokenPair}`)).data;
+ return (
+ await get(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/get-price?tokenPair=${tokenPair}`
+ )
+ ).data;
};
diff --git a/src/services/api/liquidation-loans.ts b/src/services/api/liquidation-loans.ts
index 64ab534..ba6ea43 100644
--- a/src/services/api/liquidation-loans.ts
+++ b/src/services/api/liquidation-loans.ts
@@ -2,5 +2,7 @@ import { get } from "@/services/utils";
import { ILoanRequest } from "@/interfaces/loan-interface";
export const getLiquidationLoans = async () => {
- return get("/liquidateable-loan").then((data) => data.data);
+ return get(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/liquidateable-loan`
+ ).then((data) => data.data);
};
diff --git a/src/services/api/loan-service.ts b/src/services/api/loan-service.ts
index e48f261..59b8807 100644
--- a/src/services/api/loan-service.ts
+++ b/src/services/api/loan-service.ts
@@ -1,20 +1,29 @@
-import { baseUrl } from "@/shared/constant";
+// import { baseUrl } from "@/shared/constant";
+import { LoanRequestDto } from "../DTOs/LoanRequest";
+import { post } from "../utils";
-const createNewLoan = async (loanData: any) => {
- try {
- const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/new-loan`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(loanData),
- });
- const newLoan = await response.json();
- return newLoan;
- } catch (error) {
- console.log("Failed creating new loan, api/loan: ", error);
- return { error };
- }
-};
+// const createNewLoan = async (loanData: any) => {
+// try {
+// const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/new-loan`, {
+// method: "POST",
+// headers: {
+// "Content-Type": "application/json",
+// },
+// body: JSON.stringify(loanData),
+// });
+// const newLoan = await response.json();
+// return newLoan;
+// } catch (error) {
+// console.log("Failed creating new loan, api/loan: ", error);
+// return { error };
+// }
+// };
+
+// export { createNewLoan };
-export { createNewLoan };
+export const createNewLoan = async (loanData: LoanRequestDto) => {
+ return await post(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/new-loan`,
+ JSON.stringify(loanData)
+ );
+};
diff --git a/src/services/api/market-loans.ts b/src/services/api/market-loans.ts
index 71c0706..38cb4ac 100644
--- a/src/services/api/market-loans.ts
+++ b/src/services/api/market-loans.ts
@@ -2,5 +2,13 @@ import { get } from "@/services/utils";
import { ILoanRequest } from "@/interfaces/loan-interface";
export const getMarketLoans = async () => {
- return get("/loan").then((data) => data.data);
+ return get(`${process.env.NEXT_PUBLIC_BASE_URL}/loan`).then(
+ (data) => data.data
+ );
+};
+
+export const getMarketLoan = async (loanName: String) => {
+ return get(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/loan?name=` + loanName
+ ).then((data) => data.data);
};
diff --git a/src/services/api/my-position.ts b/src/services/api/my-position.ts
index 235bf29..0d8d865 100644
--- a/src/services/api/my-position.ts
+++ b/src/services/api/my-position.ts
@@ -1,51 +1,25 @@
import { ILoanRequest } from "@/interfaces/loan-interface";
import { post, get } from "@/services/utils";
-// export type LoanData = {
-// liquidationThreshold: number;
-// initialThreshold: number;
-// loanRepayDeadline: number;
-// loanRequestDeadline: number;
-// _id: string;
-// userAddress: string;
-// loanAmount: number;
-// loanPeriod: number;
-// loanToken: string;
-// collateralAmount: number;
-// collateralToken: string;
-// healthFactor: number;
-// platformFee: number;
-// interestRate: number;
-// __v: number;
-// };
-export type LoanData = {
- _id: string;
- name: string;
- liquidationThreshold: string;
- initialThreshold: string;
- loanRepayDeadline: string;
- loanRequestDeadline: string;
- userAddress: string;
- loanAmount: string;
- loanPeriod: string;
- loanToken: string;
- collateralAmount: string;
- collateralToken: string;
- healthFactor: string;
- platformFee: string;
- interestRate: string;
- creationDate: string;
- updatedDate: string;
- __v: number;
-};
-
-// type GetMyLoanResponse = {
-// // success: true;
-// // status: 200;
-// data: LoanData[];
-// };
type GetMyLoanResponse = ILoanRequest[];
export const getMyLoan = async (walletAddress: String) => {
- return get("/loan?borrowerID=" + walletAddress).then((data) => data.data);
+ return get(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/loan?borrowerID=` + walletAddress
+ ).then((data) => data.data);
+};
+
+export const getMySuppliedLoan = async (walletAddress: String) => {
+ return get(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/loan?investorAddress=` + walletAddress
+ ).then((data) => data.data);
+};
+
+export const getMyLoansByStatus = async (
+ walletAddress: String,
+ status: String
+) => {
+ return get(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/loan?borrowerId=${walletAddress}&status=${status}`
+ ).then((data) => data.data);
};
diff --git a/src/services/api/user.ts b/src/services/api/user.ts
index edb19f5..5faa5b8 100644
--- a/src/services/api/user.ts
+++ b/src/services/api/user.ts
@@ -1,16 +1,14 @@
-const baseurl = process.env.PROD_BASE_URL;
-
const addNewUserWallet = async (signeeWalletAddress: string | undefined) => {
- try {
- const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/user`, {
- method: "POST",
- body: JSON.stringify({ signeeWalletAddress }),
- });
- const newUser = await response.json();
- return newUser;
- } catch (error) {
- console.log("Failed calling api/user endpoint: ", error);
- }
+ try {
+ const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/user`, {
+ method: "POST",
+ body: JSON.stringify({ signeeWalletAddress }),
+ });
+ const newUser = await response.json();
+ return newUser;
+ } catch (error) {
+ console.log("Failed calling api/user endpoint: ", error);
+ }
};
export { addNewUserWallet };
diff --git a/src/shared/constant.ts b/src/shared/constant.ts
index aebcc30..fda38d2 100644
--- a/src/shared/constant.ts
+++ b/src/shared/constant.ts
@@ -1 +1,10 @@
-export const baseUrl: string = 'http://localhost:3000'
\ No newline at end of file
+import { requestAmountOptions } from "@/app/data/currency";
+
+export const baseUrl: string = "http://localhost:3000";
+
+export const getImage = (token: string) => {
+ const selectedOption = requestAmountOptions.find(
+ (option) => option.name.toLowerCase() === token.toLowerCase()
+ );
+ return selectedOption ? selectedOption.image : "";
+};
diff --git a/src/types/input.ts b/src/types/input.ts
index 70dc3e3..813b45d 100644
--- a/src/types/input.ts
+++ b/src/types/input.ts
@@ -5,4 +5,5 @@ export type InputProps = {
className?: string;
value?: string | number | Date | any | null;
onChange?: (e: React.ChangeEvent) => void;
+ disabled?: boolean;
};
diff --git a/src/types/liquidation.ts b/src/types/liquidation.ts
index d8bc8c7..e54d102 100644
--- a/src/types/liquidation.ts
+++ b/src/types/liquidation.ts
@@ -1,12 +1,14 @@
import { ILoanRequest } from "@/interfaces/loan-interface";
export type LiquidationModalProps = {
- open: boolean;
- handleClose: () => void;
- data: ILoanRequest;
+ open: boolean;
+ handleClose: () => void;
+ data: ILoanRequest;
};
export type CurrencyOption = {
- name: string;
- value: string;
+ name: string;
+ value: string;
+ address: string;
+ image: string;
};
diff --git a/src/types/select.ts b/src/types/select.ts
index 5fcba24..87e0034 100644
--- a/src/types/select.ts
+++ b/src/types/select.ts
@@ -2,6 +2,6 @@ export type SelectProps = {
name: string;
id: string;
className?: string;
- options: { value: string; name: string }[];
+ options: { value: string; name?: string; image?: string }[];
onChange: (selectedValue: string) => void;
};
diff --git a/src/utils/config.ts b/src/utils/config.ts
index 8fa2e01..412f275 100644
--- a/src/utils/config.ts
+++ b/src/utils/config.ts
@@ -1,8 +1,8 @@
const config = {
- MONGODB_URI: process.env.NEXT_PUBLIC_TEST_MONGODB_URI,
- ORACLE_CONTRACT_ADDRESS: process.env.NEXT_PUBLIC_TEST_ORACLE_CONTRACT_ADDRESS,
- RPC_URL: process.env.NEXT_PUBLIC_TEST_RPC_URL,
- NETWORK_ID: process.env.NEXT_PUBLIC_NETWORK_ID,
+ MONGODB_URI: process.env.NEXT_PUBLIC_TEST_MONGODB_URI,
+ ORACLE_CONTRACT_ADDRESS: process.env.NEXT_PUBLIC_TEST_ORACLE_CONTRACT_ADDRESS,
+ RPC_URL: process.env.NEXT_PUBLIC_TEST_RPC_URL,
+ NETWORK_ID: process.env.NEXT_PUBLIC_NETWORK_ID,
};
export default config;
diff --git a/src/utils/helper.ts b/src/utils/helper.ts
index c2687ef..ddb7d39 100644
--- a/src/utils/helper.ts
+++ b/src/utils/helper.ts
@@ -47,3 +47,11 @@ export const calculateTPass = (startDate: any) => {
return { hours, minutes, seconds };
};
+
+export const truncateAddress = (address: string) => {
+ return (
+ address.slice(0, 5) +
+ "..." +
+ address.slice(address.length - 5, address.length)
+ );
+};
diff --git a/src/wagmi/WagmiWrapper.tsx b/src/wagmi/WagmiWrapper.tsx
index 72d7461..b913c2f 100644
--- a/src/wagmi/WagmiWrapper.tsx
+++ b/src/wagmi/WagmiWrapper.tsx
@@ -2,20 +2,36 @@
import React, { ReactNode } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { WagmiProvider } from "wagmi";
+import { cookieStorage, createStorage, WagmiProvider } from "wagmi";
// 2. Set up a React Query client.
const queryClient = new QueryClient();
import { http, createConfig } from "wagmi";
-import { base, mainnet, optimism } from "wagmi/chains";
+import { base, mainnet } from "wagmi/chains";
import { injected, metaMask, safe, walletConnect } from "wagmi/connectors";
const projectId = "18f45d4c6ab419ec257168ecbc48df46";
export const config = createConfig({
chains: [mainnet, base],
- connectors: [injected(), metaMask(), safe()],
+ connectors: [
+ injected(),
+ metaMask({
+ dappMetadata: {
+ name: "Koryntia",
+ url: 'https://app.koryntia.finance'
+ }
+ }),
+ safe(),
+ walletConnect({
+ projectId: projectId
+ })
+ ],
+ storage: createStorage({
+ storage: cookieStorage
+ }),
+ ssr: true,
transports: {
[mainnet.id]: http(),
[base.id]: http(),