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

fixed onRamping transaction issue #23

Open
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions apps/bank-webhook/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ app.post("/hdfcWebhook", async (req, res) => {

try {
await db.$transaction([
db.balance.updateMany({
db.balance.update({
where: {
userId: Number(paymentInformation.userId)
},
Expand All @@ -30,7 +30,7 @@ app.post("/hdfcWebhook", async (req, res) => {
}
}
}),
db.onRampTransaction.updateMany({
db.onRampTransaction.update({
where: {
token: paymentInformation.token
},
Expand Down
2 changes: 0 additions & 2 deletions apps/user-app/.env.example

This file was deleted.

1 change: 1 addition & 0 deletions apps/user-app/app/(dashboard)/transfer/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use server"
import prisma from "@repo/db/client";
import { AddMoney } from "../../../components/AddMoneyCard";
import { BalanceCard } from "../../../components/BalanceCard";
Expand Down
29 changes: 29 additions & 0 deletions apps/user-app/app/lib/actions/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use server"
import prisma from "@repo/db/client";
import { getServerSession } from "next-auth";
import { authOptions } from "../auth";

export default async function transactions (amount:string,provider:string){
const TransactionAmount =Number(amount)
const time =new Date()
const isoString= time.toISOString()
const session = await getServerSession(authOptions)
if(!session.user.id || !session.user ){
return "Unauthorised request"
}
const transactionToken = (Math.random()+10*18).toString()
const transaction = await prisma.onRampTransaction.create({
data:{
userId:Number(session.user.id),
token:transactionToken,
amount:TransactionAmount,
status:"Processing",
provider:provider,
startTime:isoString
}
})
if(transaction){
return true
}

}
6 changes: 3 additions & 3 deletions apps/user-app/app/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import db from "@repo/db/client";
import CredentialsProvider from "next-auth/providers/credentials"
import bcrypt from "bcrypt";
import bcrypt from 'bcryptjs'

export const authOptions = {
providers: [
Expand All @@ -13,15 +13,15 @@ export const authOptions = {
// TODO: User credentials type from next-aut
async authorize(credentials: any) {
// Do zod validation, OTP validation here
const hashedPassword = await bcrypt.hash(credentials.password, 10);
const hashedPassword = bcrypt.hashSync(credentials.password, 10);
const existingUser = await db.user.findFirst({
where: {
number: credentials.phone
}
});

if (existingUser) {
const passwordValidation = await bcrypt.compare(credentials.password, existingUser.password);
const passwordValidation = bcrypt.compareSync(credentials.password, existingUser.password);
if (passwordValidation) {
return {
id: existingUser.id.toString(),
Expand Down
30 changes: 24 additions & 6 deletions apps/user-app/components/AddMoneyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Center } from "@repo/ui/center";
import { Select } from "@repo/ui/select";
import { useState } from "react";
import { TextInput } from "@repo/ui/textinput";
import transactions from "../app/lib/actions/transactions";


const SUPPORTED_BANKS = [{
name: "HDFC Bank",
Expand All @@ -15,24 +17,40 @@ const SUPPORTED_BANKS = [{
}];

export const AddMoney = () => {
const [redirectUrl, setRedirectUrl] = useState(SUPPORTED_BANKS[0]?.redirectUrl);
const [amount,setAmount] = useState<string>("")
const [redirectUrl, setRedirectUrl] = useState(SUPPORTED_BANKS[0]?.redirectUrl);
const [provider,setProvider] =useState("")








return <Card title="Add Money">
<div className="w-full">
<TextInput label={"Amount"} placeholder={"Amount"} onChange={() => {

}} />
<TextInput label={"Amount"} type="number" placeholder={"Amount"} onChange={(e) => {
setAmount(e.target.value+"00")
}} />
<div className="py-4 text-left">
Bank
</div>
<Select onSelect={(value) => {
setProvider(value)

setRedirectUrl(SUPPORTED_BANKS.find(x => x.name === value)?.redirectUrl || "")
}} options={SUPPORTED_BANKS.map(x => ({
key: x.name,
value: x.name
}))} />
<div className="flex justify-center pt-4">
<Button onClick={() => {
window.location.href = redirectUrl || "";
<Button onClick={async()=>{

await transactions(amount,provider)
if(typeof redirectUrl ==="string"){
window.location.href =redirectUrl
}
}}>
Add Money
</Button>
Expand Down
2 changes: 1 addition & 1 deletion apps/user-app/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
5 changes: 3 additions & 2 deletions apps/user-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"dependencies": {
"@repo/store": "*",
"@repo/ui": "*",
"@types/bcrypt": "^5.0.2",
"bcrypt": "^5.1.1",
"next": "^14.1.1",
"next-auth": "^4.24.7",
"react": "^18.2.0",
Expand All @@ -22,11 +20,14 @@
"@next/eslint-plugin-next": "^14.1.1",
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@types/bcrypt": "^5.0.2",
"@types/bcryptjs": "^2.4.6",
"@types/eslint": "^8.56.5",
"@types/node": "^20.11.24",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"autoprefixer": "^10.4.19",
"bcryptjs": "^2.4.3",
"eslint": "^8.57.0",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.1",
Expand Down
Loading