Skip to content
Closed
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
278 changes: 186 additions & 92 deletions backend/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@nestjs/cli": "^11.0.0",
"@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.0.1",
"@prisma/config": "^7.8.0",
"@types/dotenv": "^6.1.1",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
Expand Down Expand Up @@ -131,4 +132,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}
2 changes: 1 addition & 1 deletion backend/prisma.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from 'prisma/config';
import { defineConfig } from '@prisma/config';

export default defineConfig({
datasource: {
Expand Down
3 changes: 3 additions & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ model Merchant {
id String @id @default(uuid())
name String
stellarPublicKey String @unique @map("stellar_public_key")
businessEmail String? @map("business_email")
preferredAsset String? @map("preferred_asset")
payoutWallet String? @map("payout_wallet")
webhookUrl String? @map("webhook_url")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Expand Down
2 changes: 2 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { WebhooksModule } from "./webhooks/webhooks.module";
import { CustomThrottlerModule } from "./throttler/throttler.module";
import { BackfillModule } from "./backfill/backfill.module";
import { AdminAnalyticsModule } from "./admin-analytics/admin-analytics.module";
import { MerchantModule } from "./merchant/merchant.module";

/**
* Root application module
Expand Down Expand Up @@ -103,6 +104,7 @@ import { AdminAnalyticsModule } from "./admin-analytics/admin-analytics.module";
WebhooksModule,
BackfillModule,
AdminAnalyticsModule,
MerchantModule,
],
})
export class AppModule {}
31 changes: 31 additions & 0 deletions backend/src/common/validators/is-stellar-public-key.validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
registerDecorator,
ValidationOptions,
ValidatorConstraint,
ValidatorConstraintInterface,
} from 'class-validator';
import { StrKey } from '@stellar/stellar-sdk';

@ValidatorConstraint({ name: 'isStellarPublicKey', async: false })
export class IsStellarPublicKeyConstraint implements ValidatorConstraintInterface {
validate(publicKey: any) {
if (typeof publicKey !== 'string') return false;
return StrKey.isValidEd25519PublicKey(publicKey);
}

defaultMessage() {
return 'payoutWallet must be a valid Stellar public key (starting with G)';
}
}

export function IsStellarPublicKey(validationOptions?: ValidationOptions) {
return function (object: Object, propertyName: string) {
registerDecorator({
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [],
validator: IsStellarPublicKeyConstraint,
});
};
}
20 changes: 20 additions & 0 deletions backend/src/merchant/dtos/update-merchant-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IsEmail, IsOptional, IsString } from 'class-validator';
import { IsStellarPublicKey } from '../../common/validators/is-stellar-public-key.validator';

export class UpdateMerchantProfileDto {
@IsString()
@IsOptional()
name?: string;

@IsEmail()
@IsOptional()
businessEmail?: string;

@IsString()
@IsOptional()
preferredAsset?: string;

@IsStellarPublicKey()
@IsOptional()
payoutWallet?: string;
}
26 changes: 26 additions & 0 deletions backend/src/merchant/merchant.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,43 @@ import {
Patch,
Delete,
UseGuards,
Param,
Body,
} from "@nestjs/common";

import { JwtAuthGuard } from "../auth/guard/auth.guard";
import { MerchantMembershipGuard } from "../common/guards/merchant-membership.guard";
import { MerchantRolesGuard } from "../common/guards/merchant-roles.guard";
import { Roles } from "../common/decorators/roles.decorator";
import { MerchantRole } from "../common/enums/merchant-role.enum";
import { MerchantService } from "./merchant.service";
import { UpdateMerchantProfileDto } from "./dtos/update-merchant-profile.dto";

@UseGuards(JwtAuthGuard, MerchantMembershipGuard, MerchantRolesGuard)
@Controller("merchants")
export class MerchantController {
constructor(private readonly merchantService: MerchantService) {}

@Get(":merchantId/profile")
@Roles(
MerchantRole.OWNER,
MerchantRole.ADMIN,
MerchantRole.OPERATOR,
MerchantRole.VIEWER,
)
getProfile(@Param("merchantId") merchantId: string) {
return this.merchantService.getProfile(merchantId);
}

@Patch(":merchantId/profile")
@Roles(MerchantRole.OWNER, MerchantRole.ADMIN)
updateProfile(
@Param("merchantId") merchantId: string,
@Body() data: UpdateMerchantProfileDto,
) {
return this.merchantService.updateProfile(merchantId, data);
}

@Get(":merchantId/export")
@Roles(MerchantRole.OWNER, MerchantRole.ADMIN)
exportMerchantData() {
Expand Down
12 changes: 12 additions & 0 deletions backend/src/merchant/merchant.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { MerchantController } from './merchant.controller';
import { MerchantService } from './merchant.service';
import { PrismaModule } from '../prisma/prisma.module';

@Module({
imports: [PrismaModule],
controllers: [MerchantController],
providers: [MerchantService],
exports: [MerchantService],
})
export class MerchantModule {}
46 changes: 44 additions & 2 deletions backend/src/merchant/merchant.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
import { Injectable } from "@nestjs/common";
import { Injectable, NotFoundException } from "@nestjs/common";
import { PrismaService } from "../prisma/prisma.service";
import { UpdateMerchantProfileDto } from "./dtos/update-merchant-profile.dto";

@Injectable()
export class MerchantService {}
export class MerchantService {
constructor(private prisma: PrismaService) {}

async getProfile(merchantId: string) {
const merchant = await this.prisma.merchant.findUnique({
where: { id: merchantId },
select: {
id: true,
name: true,
stellarPublicKey: true,
businessEmail: true,
preferredAsset: true,
payoutWallet: true,
webhookUrl: true,
createdAt: true,
updatedAt: true,
},
});

if (!merchant) {
throw new NotFoundException('Merchant not found');
}

return merchant;
}

async updateProfile(merchantId: string, data: UpdateMerchantProfileDto) {
const merchant = await this.prisma.merchant.findUnique({
where: { id: merchantId },
});

if (!merchant) {
throw new NotFoundException('Merchant not found');
}

return this.prisma.merchant.update({
where: { id: merchantId },
data,
});
}
}
13 changes: 13 additions & 0 deletions legacy/webapp/app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ReactNode } from "react"
import { MerchantDashboardShell } from "@/components/merchant-dashboard-shell"

export default function DashboardLayout({ children }: { children: ReactNode }) {
return (
<MerchantDashboardShell
title="Dashboard"
description="Welcome back! Here's your invoice overview."
>
{children}
</MerchantDashboardShell>
)
}
13 changes: 13 additions & 0 deletions legacy/webapp/app/invoices/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ReactNode } from "react"
import { MerchantDashboardShell } from "@/components/merchant-dashboard-shell"

export default function InvoicesLayout({ children }: { children: ReactNode }) {
return (
<MerchantDashboardShell
title="Invoices"
description="Create, review, and manage all merchant invoices."
>
{children}
</MerchantDashboardShell>
)
}
13 changes: 13 additions & 0 deletions legacy/webapp/app/settings/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ReactNode } from "react"
import { MerchantDashboardShell } from "@/components/merchant-dashboard-shell"

export default function SettingsLayout({ children }: { children: ReactNode }) {
return (
<MerchantDashboardShell
title="Settings"
description="Manage wallet, profile, and dashboard preferences."
>
{children}
</MerchantDashboardShell>
)
}
73 changes: 73 additions & 0 deletions legacy/webapp/app/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"use client"

import Link from "next/link"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { useEvmWallet } from "@/hooks/use-evm-wallet"
import { useAuthStore } from "@/hooks/use-auth-store"
import { ShieldCheck, LogOut, Wallet, ArrowRight } from "lucide-react"

export default function SettingsPage() {
const { address, connected, displayAddress, disconnect } = useEvmWallet()
const { user } = useAuthStore()

return (
<div className="space-y-6 pb-8">
<Card className="border-border bg-background shadow-sm">
<CardHeader>
<CardTitle className="flex items-center gap-2 text-foreground">
<ShieldCheck className="h-5 w-5 text-primary" />
Account Settings
</CardTitle>
<CardDescription className="text-muted-foreground">
Wallet access and dashboard preferences for the deployed legacy app.
</CardDescription>
</CardHeader>
<CardContent className="grid gap-4 sm:grid-cols-2">
<div className="rounded-2xl border border-border bg-muted/40 p-4">
<p className="text-xs uppercase tracking-[0.24em] text-muted-foreground">Wallet</p>
<p className="mt-2 text-sm font-medium text-foreground">
{connected ? displayAddress : "Not connected"}
</p>
<p className="mt-1 text-xs text-muted-foreground">
{address ? "Connected via your EVM wallet" : "Connect a wallet to authenticate"}
</p>
</div>
<div className="rounded-2xl border border-border bg-muted/40 p-4">
<p className="text-xs uppercase tracking-[0.24em] text-muted-foreground">Session</p>
<p className="mt-2 text-sm font-medium text-foreground">
{user?.walletAddress || "No active session"}
</p>
<p className="mt-1 text-xs text-muted-foreground">
Session data is stored locally for the legacy frontend.
</p>
</div>
</CardContent>
</Card>

<Card className="border-border bg-background shadow-sm">
<CardHeader>
<CardTitle className="flex items-center gap-2 text-foreground">
<Wallet className="h-5 w-5 text-primary" />
Quick Actions
</CardTitle>
<CardDescription className="text-muted-foreground">
Jump to common merchant tasks.
</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-3 sm:flex-row">
<Button asChild className="bg-primary text-primary-foreground hover:bg-primary/90">
<Link href="/invoices">
<ArrowRight className="mr-2 h-4 w-4" />
View Invoices
</Link>
</Button>
<Button variant="outline" onClick={() => void disconnect()}>
<LogOut className="mr-2 h-4 w-4" />
Sign Out
</Button>
</CardContent>
</Card>
</div>
)
}
Loading
Loading