Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updation of OnRampTransaction #13

Open
wants to merge 2 commits into
base: migration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 44 additions & 46 deletions apps/bank-webhook/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,52 @@ import express from "express";
import db from "@repo/db/client";
const app = express();

app.use(express.json())
app.use(express.json());

app.post("/hdfcWebhook", async (req, res) => {
//TODO: Add zod validation here?
//TODO: HDFC bank should ideally send us a secret so we know this is sent by them
const paymentInformation: {
token: string;
userId: string;
amount: string
} = {
token: req.body.token,
userId: req.body.user_identifier,
amount: req.body.amount
};
//TODO: Add zod validation here?
//TODO: HDFC bank should ideally send us a secret so we know this is sent by them
const paymentInformation: {
token: string;
userId: string;
amount: string;
} = {
token: req.body.token,
userId: req.body.user_identifier,
amount: req.body.amount,
};

try {
await db.$transaction([
db.balance.updateMany({
where: {
userId: Number(paymentInformation.userId)
},
data: {
amount: {
// You can also get this from your DB
increment: Number(paymentInformation.amount)
}
}
}),
db.onRampTransaction.updateMany({
where: {
token: paymentInformation.token
},
data: {
status: "Success",
}
})
]);
try {
await db.$transaction([
db.balance.updateMany({
where: {
userId: Number(paymentInformation.userId),
},
data: {
amount: {
increment: Number(paymentInformation.amount),
},
},
}),
db.onRampTransaction.updateMany({
where: {
token: paymentInformation.token,
},
data: {
status: "Success",
},
}),
]);

res.json({
message: "Captured"
})
} catch(e) {
console.error(e);
res.status(411).json({
message: "Error while processing webhook"
})
}
res.json({
message: "Captured",
});
} catch (e) {
console.error(e);
res.status(411).json({
message: "Error while processing webhook",
});
}
});

})

app.listen(3003);
app.listen(3003);
101 changes: 83 additions & 18 deletions apps/user-app/app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,98 @@ export default function Layout({
}): JSX.Element {
return (
<div className="flex">
<div className="w-72 border-r border-slate-300 min-h-screen mr-4 pt-28">
<div>
<SidebarItem href={"/dashboard"} icon={<HomeIcon />} title="Home" />
<SidebarItem href={"/transfer"} icon={<TransferIcon />} title="Transfer" />
<SidebarItem href={"/transactions"} icon={<TransactionsIcon />} title="Transactions" />
</div>
<div className="w-72 border-r border-slate-300 min-h-screen mr-4 pt-28">
<div>
<SidebarItem href={"/dashboard"} icon={<HomeIcon />} title="Home" />
<SidebarItem
href={"/transfer"}
icon={<TransferIcon />}
title="Transfer"
/>
<SidebarItem
href={"/transactions"}
icon={<TransactionsIcon />}
title="Transactions"
/>
<SidebarItem href={"/p2p"} icon={<P2PTr />} title="P2P " />
</div>
{children}
</div>
{children}
</div>
);
}

// Icons Fetched from https://heroicons.com/
function HomeIcon() {
return <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" className="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="m2.25 12 8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25" />
</svg>
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
className="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m2.25 12 8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25"
/>
</svg>
);
}
function TransferIcon() {
return <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" className="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M7.5 21 3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5" />
</svg>
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
className="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M7.5 21 3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5"
/>
</svg>
);
}

function TransactionsIcon() {
return <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" className="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
</svg>

}
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
className="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
</svg>
);
}
function P2PTr() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
className="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m4.5 19.5 15-15m0 0H8.25m11.25 0v11.25"
/>
</svg>
);
}
38 changes: 38 additions & 0 deletions apps/user-app/app/(dashboard)/p2p/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use server";
import { getServerSession } from "next-auth";
import { SendCard } from "../../../components/card-stack";
import { authOptions } from "../../lib/auth";
import prisma from "@repo/db/client";
import P2PTransaction from "../../../components/p2pTransactions";
async function getp2pTransaction() {
const session = await getServerSession(authOptions);
const txns = await prisma.p2pTransfer.findMany({
where: {
fromUserId: Number(session?.user?.id),
},
});
return txns.map((t) => ({
time: t.timestamp,
amount: t.amount,
toUserId: t.toUserId,
}));
}
export default async function () {
const transactions = await getp2pTransaction();

return (
<div className="w-screen">
<div className="text-4xl text-[#6a51a6] pt-8 mb-8 font-bold">
Transfer
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 p-4">
<div>
<SendCard />
</div>
<div>
<P2PTransaction transactions={transactions} />
</div>
</div>
</div>
);
}
80 changes: 41 additions & 39 deletions apps/user-app/app/(dashboard)/transfer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,53 @@ import { getServerSession } from "next-auth";
import { authOptions } from "../../lib/auth";

async function getBalance() {
const session = await getServerSession(authOptions);
const balance = await prisma.balance.findFirst({
where: {
userId: Number(session?.user?.id)
}
});
return {
amount: balance?.amount || 0,
locked: balance?.locked || 0
}
const session = await getServerSession(authOptions);
const balance = await prisma.balance.findFirst({
where: {
userId: Number(session?.user?.id),
},
});
return {
amount: balance?.amount || 0,
locked: balance?.locked || 0,
};
}

async function getOnRampTransactions() {
const session = await getServerSession(authOptions);
const txns = await prisma.onRampTransaction.findMany({
where: {
userId: Number(session?.user?.id)
}
});
return txns.map(t => ({
time: t.startTime,
amount: t.amount,
status: t.status,
provider: t.provider
}))
const session = await getServerSession(authOptions);
const txns = await prisma.onRampTransaction.findMany({
where: {
userId: Number(session?.user?.id),
},
});
return txns.map((t) => ({
time: t.startTime,
amount: t.amount,
status: t.status,
provider: t.provider,
}));
}

export default async function() {
const balance = await getBalance();
const transactions = await getOnRampTransactions();
export default async function () {
const balance = await getBalance();
const transactions = await getOnRampTransactions();

return <div className="w-screen">
<div className="text-4xl text-[#6a51a6] pt-8 mb-8 font-bold">
Transfer
return (
<div className="w-screen">
<div className="text-4xl text-[#6a51a6] pt-8 mb-8 font-bold">
Transfer
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 p-4">
<div>
<AddMoney />
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 p-4">
<div>
<AddMoney />
</div>
<div>
<BalanceCard amount={balance.amount} locked={balance.locked} />
<div className="pt-4">
<OnRampTransactions transactions={transactions} />
</div>
</div>
<div>
<BalanceCard amount={balance.amount} locked={balance.locked} />
<div className="pt-4">
<OnRampTransactions transactions={transactions} />
</div>
</div>
</div>
</div>
}
);
}
30 changes: 30 additions & 0 deletions apps/user-app/app/lib/newTransactions/createOnRampTransactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use server";

import { getServerSession } from "next-auth";
import prisma from "@repo/db/client";
import { authOptions } from "../auth";

export default async function createOnRampTransactions(
amount: number,
provider: string
) {
const session = await getServerSession(authOptions);
const userId = session?.user?.id;
if (!userId) {
message: "User not logged in";
}
const token = (Math.random() * 1000).toString();
await prisma.onRampTransaction.create({
data: {
provider,
status: "Processing",
userId: Number(session?.user?.id),
token: token,
amount: amount * 10,
startTime: new Date(),
},
});
return {
msg: "Done",
};
}
Loading