From e9c0c3977a58daa5337e3860426fd0efee4a3776 Mon Sep 17 00:00:00 2001 From: randalllionelkharkrang Date: Tue, 14 Oct 2025 14:28:47 +0530 Subject: [PATCH 01/11] Added mock runtime with tests for orderbook --- pallets/orderbook/src/engine.rs | 2 ++ runtime/src/configs/mod.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pallets/orderbook/src/engine.rs b/pallets/orderbook/src/engine.rs index b0b781e..870b3df 100644 --- a/pallets/orderbook/src/engine.rs +++ b/pallets/orderbook/src/engine.rs @@ -44,6 +44,8 @@ pub fn match_pending_internal( orders_map.insert(order_id, order.clone()); + orders_map.insert(order_id, order.clone()); + if order.status != OrderStatus::Filled { add_order_to_book(&order, &mut bid_book, &mut ask_book); } diff --git a/runtime/src/configs/mod.rs b/runtime/src/configs/mod.rs index 362a7e9..63f6482 100644 --- a/runtime/src/configs/mod.rs +++ b/runtime/src/configs/mod.rs @@ -186,3 +186,18 @@ impl pallet_orderbook::Config for Runtime { type MaxUserOrders = MaxUserOrders; type WeightInfo = pallet_orderbook::weights::SubstrateWeight; } + +parameter_types! { + pub const MaxPendingOrders: u32 = 1000; // Max 100 pending orders per block in tests + pub const MaxCancellationOrders: u32 = 50; // Max 50 cancellations per block in tests + pub const MaxOrders: u32 = 10000; // Max 1000 orders per price level in tests + pub const MaxUserOrders: u32 = 1000; // Max 100 orders per user in tests +} + +impl pallet_orderbook::Config for Test { + type RuntimeEvent = RuntimeEvent; + type MaxPendingOrders = MaxPendingOrders; + type MaxCancellationOrders = MaxCancellationOrders; + type MaxOrders = MaxOrders; + type MaxUserOrders = MaxUserOrders; +} From ac481412f72f09856bd6a6663d15664fb4eb1582 Mon Sep 17 00:00:00 2001 From: randalllionelkharkrang Date: Wed, 15 Oct 2025 10:59:17 +0530 Subject: [PATCH 02/11] latest commit before benchmark --- runtime/src/configs/mod.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/runtime/src/configs/mod.rs b/runtime/src/configs/mod.rs index 63f6482..362a7e9 100644 --- a/runtime/src/configs/mod.rs +++ b/runtime/src/configs/mod.rs @@ -186,18 +186,3 @@ impl pallet_orderbook::Config for Runtime { type MaxUserOrders = MaxUserOrders; type WeightInfo = pallet_orderbook::weights::SubstrateWeight; } - -parameter_types! { - pub const MaxPendingOrders: u32 = 1000; // Max 100 pending orders per block in tests - pub const MaxCancellationOrders: u32 = 50; // Max 50 cancellations per block in tests - pub const MaxOrders: u32 = 10000; // Max 1000 orders per price level in tests - pub const MaxUserOrders: u32 = 1000; // Max 100 orders per user in tests -} - -impl pallet_orderbook::Config for Test { - type RuntimeEvent = RuntimeEvent; - type MaxPendingOrders = MaxPendingOrders; - type MaxCancellationOrders = MaxCancellationOrders; - type MaxOrders = MaxOrders; - type MaxUserOrders = MaxUserOrders; -} From 38b335dfaaa862faebea4feedd5d10965b9629e2 Mon Sep 17 00:00:00 2001 From: randalllionelkharkrang Date: Thu, 16 Oct 2025 12:06:04 +0530 Subject: [PATCH 03/11] Added benchmarks for orderbook dex, along with cargo fmt. build successfull --- pallets/orderbook/src/engine.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/pallets/orderbook/src/engine.rs b/pallets/orderbook/src/engine.rs index 870b3df..b0b781e 100644 --- a/pallets/orderbook/src/engine.rs +++ b/pallets/orderbook/src/engine.rs @@ -44,8 +44,6 @@ pub fn match_pending_internal( orders_map.insert(order_id, order.clone()); - orders_map.insert(order_id, order.clone()); - if order.status != OrderStatus::Filled { add_order_to_book(&order, &mut bid_book, &mut ask_book); } From b9adff98a99a664487bb72c5bd9aad588004ce95 Mon Sep 17 00:00:00 2001 From: gil7788 Date: Tue, 21 Oct 2025 10:57:25 +0300 Subject: [PATCH 04/11] Init Frontend --- frontend/.dockerignore | 36 + frontend/.gitignore | 27 + frontend/Dockerfile | 31 + frontend/README.docker.md | 62 + frontend/app/globals.css | 126 + frontend/app/layout.tsx | 28 + frontend/app/page.tsx | 9 + frontend/components.json | 21 + frontend/components/account-tabs.tsx | 178 + frontend/components/market-stats.tsx | 95 + frontend/components/order-book.tsx | 196 + frontend/components/providers.tsx | 30 + frontend/components/theme-provider.tsx | 7 + frontend/components/theme-toggle.tsx | 22 + frontend/components/trading-dashboard.tsx | 151 + frontend/components/trading-form.tsx | 207 + frontend/components/trading-view-chart.tsx | 55 + frontend/components/ui/accordion.tsx | 66 + frontend/components/ui/alert-dialog.tsx | 157 + frontend/components/ui/alert.tsx | 66 + frontend/components/ui/aspect-ratio.tsx | 11 + frontend/components/ui/avatar.tsx | 53 + frontend/components/ui/badge.tsx | 46 + frontend/components/ui/breadcrumb.tsx | 109 + frontend/components/ui/button-group.tsx | 83 + frontend/components/ui/button.tsx | 60 + frontend/components/ui/calendar.tsx | 213 + frontend/components/ui/card.tsx | 92 + frontend/components/ui/carousel.tsx | 241 + frontend/components/ui/chart.tsx | 353 + frontend/components/ui/checkbox.tsx | 32 + frontend/components/ui/collapsible.tsx | 33 + frontend/components/ui/command.tsx | 184 + frontend/components/ui/context-menu.tsx | 252 + frontend/components/ui/dialog.tsx | 143 + frontend/components/ui/drawer.tsx | 135 + frontend/components/ui/dropdown-menu.tsx | 257 + frontend/components/ui/empty.tsx | 104 + frontend/components/ui/field.tsx | 244 + frontend/components/ui/form.tsx | 167 + frontend/components/ui/hover-card.tsx | 44 + frontend/components/ui/input-group.tsx | 169 + frontend/components/ui/input-otp.tsx | 77 + frontend/components/ui/input.tsx | 21 + frontend/components/ui/item.tsx | 193 + frontend/components/ui/kbd.tsx | 28 + frontend/components/ui/label.tsx | 24 + frontend/components/ui/menubar.tsx | 276 + frontend/components/ui/navigation-menu.tsx | 166 + frontend/components/ui/pagination.tsx | 127 + frontend/components/ui/popover.tsx | 48 + frontend/components/ui/progress.tsx | 31 + frontend/components/ui/radio-group.tsx | 45 + frontend/components/ui/resizable.tsx | 56 + frontend/components/ui/scroll-area.tsx | 58 + frontend/components/ui/select.tsx | 185 + frontend/components/ui/separator.tsx | 28 + frontend/components/ui/sheet.tsx | 139 + frontend/components/ui/sidebar.tsx | 726 +++ frontend/components/ui/skeleton.tsx | 13 + frontend/components/ui/slider.tsx | 63 + frontend/components/ui/sonner.tsx | 25 + frontend/components/ui/spinner.tsx | 16 + frontend/components/ui/switch.tsx | 31 + frontend/components/ui/table.tsx | 116 + frontend/components/ui/tabs.tsx | 66 + frontend/components/ui/textarea.tsx | 18 + frontend/components/ui/toast.tsx | 129 + frontend/components/ui/toaster.tsx | 35 + frontend/components/ui/toggle-group.tsx | 73 + frontend/components/ui/toggle.tsx | 47 + frontend/components/ui/tooltip.tsx | 61 + frontend/components/ui/use-mobile.tsx | 19 + frontend/components/ui/use-toast.ts | 191 + frontend/components/wallet-connect.tsx | 93 + frontend/docker-compose.yml | 9 + frontend/hooks/use-balances.ts | 46 + frontend/hooks/use-market-stats.ts | 44 + frontend/hooks/use-mobile.ts | 19 + frontend/hooks/use-open-orders.ts | 55 + frontend/hooks/use-order-book.ts | 77 + frontend/hooks/use-positions.ts | 60 + frontend/hooks/use-toast.ts | 191 + frontend/hooks/use-trades.ts | 49 + frontend/instrumentation.ts | 43 + frontend/lib/env.ts | 50 + frontend/lib/utils.ts | 6 + frontend/lib/wagmi-config.ts | 17 + frontend/next.config.mjs | 30 + frontend/package.json | 76 + frontend/pnpm-lock.yaml | 6861 ++++++++++++++++++++ frontend/postcss.config.mjs | 8 + frontend/public/placeholder-logo.png | Bin 0 -> 568 bytes frontend/public/placeholder-logo.svg | 1 + frontend/public/placeholder-user.jpg | Bin 0 -> 1635 bytes frontend/public/placeholder.jpg | Bin 0 -> 1064 bytes frontend/public/placeholder.svg | 1 + frontend/styles/globals.css | 125 + frontend/tsconfig.json | 27 + 99 files changed, 15614 insertions(+) create mode 100644 frontend/.dockerignore create mode 100644 frontend/.gitignore create mode 100644 frontend/Dockerfile create mode 100644 frontend/README.docker.md create mode 100644 frontend/app/globals.css create mode 100644 frontend/app/layout.tsx create mode 100644 frontend/app/page.tsx create mode 100644 frontend/components.json create mode 100644 frontend/components/account-tabs.tsx create mode 100644 frontend/components/market-stats.tsx create mode 100644 frontend/components/order-book.tsx create mode 100644 frontend/components/providers.tsx create mode 100644 frontend/components/theme-provider.tsx create mode 100644 frontend/components/theme-toggle.tsx create mode 100644 frontend/components/trading-dashboard.tsx create mode 100644 frontend/components/trading-form.tsx create mode 100644 frontend/components/trading-view-chart.tsx create mode 100644 frontend/components/ui/accordion.tsx create mode 100644 frontend/components/ui/alert-dialog.tsx create mode 100644 frontend/components/ui/alert.tsx create mode 100644 frontend/components/ui/aspect-ratio.tsx create mode 100644 frontend/components/ui/avatar.tsx create mode 100644 frontend/components/ui/badge.tsx create mode 100644 frontend/components/ui/breadcrumb.tsx create mode 100644 frontend/components/ui/button-group.tsx create mode 100644 frontend/components/ui/button.tsx create mode 100644 frontend/components/ui/calendar.tsx create mode 100644 frontend/components/ui/card.tsx create mode 100644 frontend/components/ui/carousel.tsx create mode 100644 frontend/components/ui/chart.tsx create mode 100644 frontend/components/ui/checkbox.tsx create mode 100644 frontend/components/ui/collapsible.tsx create mode 100644 frontend/components/ui/command.tsx create mode 100644 frontend/components/ui/context-menu.tsx create mode 100644 frontend/components/ui/dialog.tsx create mode 100644 frontend/components/ui/drawer.tsx create mode 100644 frontend/components/ui/dropdown-menu.tsx create mode 100644 frontend/components/ui/empty.tsx create mode 100644 frontend/components/ui/field.tsx create mode 100644 frontend/components/ui/form.tsx create mode 100644 frontend/components/ui/hover-card.tsx create mode 100644 frontend/components/ui/input-group.tsx create mode 100644 frontend/components/ui/input-otp.tsx create mode 100644 frontend/components/ui/input.tsx create mode 100644 frontend/components/ui/item.tsx create mode 100644 frontend/components/ui/kbd.tsx create mode 100644 frontend/components/ui/label.tsx create mode 100644 frontend/components/ui/menubar.tsx create mode 100644 frontend/components/ui/navigation-menu.tsx create mode 100644 frontend/components/ui/pagination.tsx create mode 100644 frontend/components/ui/popover.tsx create mode 100644 frontend/components/ui/progress.tsx create mode 100644 frontend/components/ui/radio-group.tsx create mode 100644 frontend/components/ui/resizable.tsx create mode 100644 frontend/components/ui/scroll-area.tsx create mode 100644 frontend/components/ui/select.tsx create mode 100644 frontend/components/ui/separator.tsx create mode 100644 frontend/components/ui/sheet.tsx create mode 100644 frontend/components/ui/sidebar.tsx create mode 100644 frontend/components/ui/skeleton.tsx create mode 100644 frontend/components/ui/slider.tsx create mode 100644 frontend/components/ui/sonner.tsx create mode 100644 frontend/components/ui/spinner.tsx create mode 100644 frontend/components/ui/switch.tsx create mode 100644 frontend/components/ui/table.tsx create mode 100644 frontend/components/ui/tabs.tsx create mode 100644 frontend/components/ui/textarea.tsx create mode 100644 frontend/components/ui/toast.tsx create mode 100644 frontend/components/ui/toaster.tsx create mode 100644 frontend/components/ui/toggle-group.tsx create mode 100644 frontend/components/ui/toggle.tsx create mode 100644 frontend/components/ui/tooltip.tsx create mode 100644 frontend/components/ui/use-mobile.tsx create mode 100644 frontend/components/ui/use-toast.ts create mode 100644 frontend/components/wallet-connect.tsx create mode 100644 frontend/docker-compose.yml create mode 100644 frontend/hooks/use-balances.ts create mode 100644 frontend/hooks/use-market-stats.ts create mode 100644 frontend/hooks/use-mobile.ts create mode 100644 frontend/hooks/use-open-orders.ts create mode 100644 frontend/hooks/use-order-book.ts create mode 100644 frontend/hooks/use-positions.ts create mode 100644 frontend/hooks/use-toast.ts create mode 100644 frontend/hooks/use-trades.ts create mode 100644 frontend/instrumentation.ts create mode 100644 frontend/lib/env.ts create mode 100644 frontend/lib/utils.ts create mode 100644 frontend/lib/wagmi-config.ts create mode 100644 frontend/next.config.mjs create mode 100644 frontend/package.json create mode 100644 frontend/pnpm-lock.yaml create mode 100644 frontend/postcss.config.mjs create mode 100644 frontend/public/placeholder-logo.png create mode 100644 frontend/public/placeholder-logo.svg create mode 100644 frontend/public/placeholder-user.jpg create mode 100644 frontend/public/placeholder.jpg create mode 100644 frontend/public/placeholder.svg create mode 100644 frontend/styles/globals.css create mode 100644 frontend/tsconfig.json diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..f217141 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,36 @@ +# Dependencies +node_modules +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Next.js +.next +out +build + +# Environment files +.env*.local +.env + +# Git +.git +.gitignore + +# IDE +.vscode +.idea +*.swp +*.swo + +# OS +.DS_Store +Thumbs.db + +# Testing +coverage +.nyc_output + +# Misc +*.log +.cache diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 0000000..f650315 --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1,27 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules + +# next.js +/.next/ +/out/ + +# production +/build + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# env files +.env* + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..5e3e030 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,31 @@ +# ----- base ----- +FROM node:20-alpine AS base +WORKDIR /app +RUN apk add --no-cache libc6-compat && corepack enable + +# Only lockfile + manifest first for better caching +COPY package.json pnpm-lock.yaml ./ +RUN corepack prepare pnpm@9 --activate && pnpm fetch + +# ----- build ----- +FROM base AS build +COPY . . +# If you removed the workspace file, this installs just this app +RUN pnpm install --no-frozen-lockfile +RUN pnpm build + +# ----- runtime ----- +FROM node:20-alpine AS runtime +WORKDIR /app +RUN addgroup -S nextjs && adduser -S nextjs -G nextjs + +# Copy minimal runtime artifacts +COPY --from=build /app/.next ./.next +COPY --from=build /app/public ./public +COPY --from=build /app/package.json . +COPY --from=build /app/node_modules ./node_modules +COPY --from=build /app/next.config.mjs ./next.config.mjs + +EXPOSE 3000 +USER nextjs +CMD ["node", "node_modules/next/dist/bin/next", "start", "-p", "3000"] diff --git a/frontend/README.docker.md b/frontend/README.docker.md new file mode 100644 index 0000000..2fee2c2 --- /dev/null +++ b/frontend/README.docker.md @@ -0,0 +1,62 @@ +# Docker Setup for Orbex + +## Prerequisites +- Docker installed on your system +- Docker Compose installed + +## Environment Variables + +The application requires the following environment variables: +- `NODE_ENV`: Set to `prod` for production +- `SERVER_URL`: API server URL (default: http://localhost:3000) +- `NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID`: Your WalletConnect project ID + +## Quick Start + +### 1. Build and run with Docker Compose + +\`\`\`bash +docker-compose up --build +\`\`\` + +The application will be available at http://localhost:3000 + +### 2. Run in detached mode + +\`\`\`bash +docker-compose up -d +\`\`\` + +### 3. Stop the application + +\`\`\`bash +docker-compose down +\`\`\` + +## Manual Docker Commands + +### Build the image + +\`\`\`bash +docker build -t orbex-web-app . +\`\`\` + +### Run the container + +\`\`\`bash +docker run -p 3000:3000 \ + -e NODE_ENV=prod \ + -e SERVER_URL=http://localhost:3000 \ + -e NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your-project-id \ + orbex-web-app +\`\`\` + +## Development + +To override environment variables, create a `.env` file or modify the `docker-compose.yml` file. + +## Troubleshooting + +- If port 3000 is already in use, modify the port mapping in `docker-compose.yml` +- Check logs: `docker-compose logs -f` +- Rebuild after code changes: `docker-compose up --build` diff --git a/frontend/app/globals.css b/frontend/app/globals.css new file mode 100644 index 0000000..29a1e34 --- /dev/null +++ b/frontend/app/globals.css @@ -0,0 +1,126 @@ +@import "tailwindcss"; +@import "tw-animate-css"; + +@custom-variant dark (&:is(.dark *)); + +:root { + --background: hsl(0 0% 100%); + --foreground: hsl(215 25% 18%); + --card: hsl(0 0% 100%); + --card-foreground: oklch(0.145 0 0); + --popover: hsl(0 0% 100%); + --popover-foreground: oklch(0.145 0 0); + --primary: hsl(215 45% 32%); + --primary-foreground: oklch(1 0 0); + --secondary: hsl(215 15% 93%); + --secondary-foreground: oklch(0.145 0 0); + --muted: hsl(215 15% 93%); + --muted-foreground: oklch(0.5 0 0); + --accent: hsl(215 25% 85%); + --accent-foreground: oklch(1 0 0); + --destructive: hsl(0 84.2% 60.2%); + --destructive-foreground: oklch(1 0 0); + --border: hsl(215 18% 88%); + --input: hsl(215 18% 88%); + --ring: hsl(215 45% 32%); + --chart-1: hsl(215 45% 32%); + --chart-2: hsl(220 38% 45%); + --chart-3: hsl(210 32% 58%); + --chart-4: hsl(205 25% 68%); + --chart-5: hsl(218 52% 22%); + --radius: 0.5rem; + --sidebar: hsl(215 12% 97%); + --sidebar-foreground: oklch(0.145 0 0); + --sidebar-primary: oklch(0.205 0 0); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.97 0 0); + --sidebar-accent-foreground: oklch(0.205 0 0); + --sidebar-border: oklch(0.922 0 0); + --sidebar-ring: oklch(0.708 0 0); +} + +.dark { + --background: hsl(222.2 84% 4.9%); + --foreground: hsl(210 40% 98%); + --card: hsl(222.2 84% 4.9%); + --card-foreground: oklch(0.98 0 0); + --popover: hsl(222.2 84% 4.9%); + --popover-foreground: oklch(0.98 0 0); + --primary: hsl(210 40% 98%); + --primary-foreground: oklch(0.12 0 0); + --secondary: hsl(217.2 32.6% 17.5%); + --secondary-foreground: oklch(0.98 0 0); + --muted: hsl(217.2 32.6% 17.5%); + --muted-foreground: oklch(0.65 0 0); + --accent: hsl(217.2 32.6% 17.5%); + --accent-foreground: oklch(0.98 0 0); + --destructive: hsl(0 62.8% 30.6%); + --destructive-foreground: oklch(1 0 0); + --border: hsl(217.2 32.6% 17.5%); + --input: hsl(217.2 32.6% 17.5%); + --ring: hsl(212.7 26.8% 83.9%); + --chart-1: hsl(220 70% 50%); + --chart-2: hsl(160 60% 45%); + --chart-3: hsl(30 80% 55%); + --chart-4: hsl(280 65% 60%); + --chart-5: hsl(340 75% 55%); + --sidebar: hsl(240 5.9% 10%); + --sidebar-foreground: oklch(0.985 0 0); + --sidebar-primary: oklch(0.488 0.243 264.376); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.269 0 0); + --sidebar-accent-foreground: oklch(0.985 0 0); + --sidebar-border: oklch(0.269 0 0); + --sidebar-ring: oklch(0.439 0 0); +} + +@theme inline { + /* optional: --font-sans, --font-serif, --font-mono if they are applied in the layout.tsx */ + --font-sans: "Geist", "Geist Fallback"; + --font-mono: "Geist Mono", "Geist Mono Fallback"; + --color-background: var(--background); + --color-foreground: var(--foreground); + --color-card: var(--card); + --color-card-foreground: var(--card-foreground); + --color-popover: var(--popover); + --color-popover-foreground: var(--popover-foreground); + --color-primary: var(--primary); + --color-primary-foreground: var(--primary-foreground); + --color-secondary: var(--secondary); + --color-secondary-foreground: var(--secondary-foreground); + --color-muted: var(--muted); + --color-muted-foreground: var(--muted-foreground); + --color-accent: var(--accent); + --color-accent-foreground: var(--accent-foreground); + --color-destructive: var(--destructive); + --color-destructive-foreground: var(--destructive-foreground); + --color-border: var(--border); + --color-input: var(--input); + --color-ring: var(--ring); + --color-chart-1: var(--chart-1); + --color-chart-2: var(--chart-2); + --color-chart-3: var(--chart-3); + --color-chart-4: var(--chart-4); + --color-chart-5: var(--chart-5); + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); + --color-sidebar: var(--sidebar); + --color-sidebar-foreground: var(--sidebar-foreground); + --color-sidebar-primary: var(--sidebar-primary); + --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); + --color-sidebar-accent: var(--sidebar-accent); + --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); + --color-sidebar-border: var(--sidebar-border); + --color-sidebar-ring: var(--sidebar-ring); +} + +@layer base { + * { + @apply border-border outline-ring/50; + } + body { + @apply bg-background text-foreground; + } +} diff --git a/frontend/app/layout.tsx b/frontend/app/layout.tsx new file mode 100644 index 0000000..095acf2 --- /dev/null +++ b/frontend/app/layout.tsx @@ -0,0 +1,28 @@ +import type React from 'react' +import type { Metadata } from 'next' +import { Geist, Geist_Mono } from 'next/font/google' +import './globals.css' +import { ThemeProvider } from '@/components/theme-provider' + +// ✅ import the client component directly +import { Providers } from '@/components/providers' + +const geistSans = Geist({ variable: '--font-geist-sans', subsets: ['latin'] }) +const geistMono = Geist_Mono({ variable: '--font-geist-mono', subsets: ['latin'] }) + +export const metadata: Metadata = { + title: 'Orbex', + description: 'Modern crypto trading platform', +} + +export default function RootLayout({ children }: { children: React.ReactNode }) { + return ( + + + + {children} + + + + ) +} diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx new file mode 100644 index 0000000..8d4dc0d --- /dev/null +++ b/frontend/app/page.tsx @@ -0,0 +1,9 @@ +import { TradingDashboard } from "@/components/trading-dashboard" + +export default function Home() { + return ( +
+ +
+ ) +} diff --git a/frontend/components.json b/frontend/components.json new file mode 100644 index 0000000..4ee62ee --- /dev/null +++ b/frontend/components.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://ui.shadcn.com/schema.json", + "style": "new-york", + "rsc": true, + "tsx": true, + "tailwind": { + "config": "", + "css": "app/globals.css", + "baseColor": "neutral", + "cssVariables": true, + "prefix": "" + }, + "aliases": { + "components": "@/components", + "utils": "@/lib/utils", + "ui": "@/components/ui", + "lib": "@/lib", + "hooks": "@/hooks" + }, + "iconLibrary": "lucide" +} diff --git a/frontend/components/account-tabs.tsx b/frontend/components/account-tabs.tsx new file mode 100644 index 0000000..db8a58a --- /dev/null +++ b/frontend/components/account-tabs.tsx @@ -0,0 +1,178 @@ +"use client" + +import { useState } from "react" +import { useBalances } from "@/hooks/use-balances" +import { usePositions } from "@/hooks/use-positions" +import { useOpenOrders } from "@/hooks/use-open-orders" +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" +import { Card, CardContent } from "@/components/ui/card" + +export function AccountTabs() { + const [activeTab, setActiveTab] = useState("balances") + + const balances = useBalances() + const positions = usePositions() + const openOrders = useOpenOrders() + + return ( + + + + + + Balances + + + Positions + + + Open Orders + + + TWAP + + + Trade History + + + Funding History + + + Order History + + + + +
+ + + + + + + + + + + {balances.map((balance) => ( + + + + + + + ))} + +
AssetAmountAvailableValue
{balance.asset}{balance.amount}{balance.available}{balance.value}
+
+
+ + +
+ + + + + + + + + + + + + {positions.map((position, idx) => ( + + + + + + + + + ))} + +
PairSideSizeEntry PriceMark PricePnL
{position.pair} + + {position.side} + + {position.size}{position.entryPrice}{position.markPrice} + {position.pnl} ({position.pnlPercent}) +
+
+
+ + +
+ + + + + + + + + + + + + + {openOrders.map((order, idx) => ( + + + + + + + + + + ))} + +
PairTypeSidePriceAmountFilledTotal
{order.pair}{order.type} + {order.side} + {order.price}{order.amount}{order.filled}{order.total}
+
+
+ + +
No TWAP orders
+
+ + +
No trade history
+
+ + +
No funding history
+
+ + +
No order history
+
+
+
+
+ ) +} diff --git a/frontend/components/market-stats.tsx b/frontend/components/market-stats.tsx new file mode 100644 index 0000000..0b249c4 --- /dev/null +++ b/frontend/components/market-stats.tsx @@ -0,0 +1,95 @@ +"use client" + +import { Card, CardContent } from "@/components/ui/card" +import { TrendingUp, TrendingDown } from "lucide-react" + +interface MarketStatsProps { + selectedPair: string +} + +export function MarketStats({ selectedPair }: MarketStatsProps) { + // Mock data - in production, fetch from API + const stats = { + "BTC/USD": { + price: "67,234.50", + change: "+2.34", + changePercent: "+3.61%", + high24h: "68,450.00", + low24h: "65,120.00", + volume24h: "28.5B", + isPositive: true, + }, + "ETH/USD": { + price: "3,456.78", + change: "-45.23", + changePercent: "-1.29%", + high24h: "3,520.00", + low24h: "3,401.00", + volume24h: "12.3B", + isPositive: false, + }, + "SOL/USD": { + price: "142.56", + change: "+8.92", + changePercent: "+6.68%", + high24h: "145.00", + low24h: "135.20", + volume24h: "2.1B", + isPositive: true, + }, + } + + const currentStats = stats[selectedPair as keyof typeof stats] + + return ( +
+ + +
+

Price

+
+

${currentStats.price}

+
+ {currentStats.isPositive ? : } + {currentStats.changePercent} +
+
+
+
+
+ + + +
+

24h Change

+

+ ${currentStats.change} +

+
+
+
+ + + +
+

24h High

+

${currentStats.high24h}

+
+
+
+ + + +
+

24h Volume

+

${currentStats.volume24h}

+
+
+
+
+ ) +} diff --git a/frontend/components/order-book.tsx b/frontend/components/order-book.tsx new file mode 100644 index 0000000..122f300 --- /dev/null +++ b/frontend/components/order-book.tsx @@ -0,0 +1,196 @@ +"use client" + +import { useState, useEffect, useRef } from "react" +import { useOrderBook } from "@/hooks/use-order-book" +import { useTrades } from "@/hooks/use-trades" +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" + +function OrderBookRow({ + price, + size, + total, + sizeNum, + maxSize, + type, + priceGrouping, +}: { + price: string + size: string + total: string + sizeNum: number + maxSize: number + type: "ask" | "bid" + priceGrouping: number +}) { + const [flash, setFlash] = useState(false) + const prevSizeRef = useRef(sizeNum) + + useEffect(() => { + // Detect size changes and trigger flash animation + if (prevSizeRef.current !== sizeNum) { + setFlash(true) + const timer = setTimeout(() => setFlash(false), 300) + prevSizeRef.current = sizeNum + return () => clearTimeout(timer) + } + }, [sizeNum]) + + // Calculate heatmap intensity (0-1) + const intensity = maxSize > 0 ? sizeNum / maxSize : 0 + + const bgGradient = + type === "ask" + ? `linear-gradient(to right, transparent ${100 - intensity * 100}%, rgba(239, 68, 68, ${intensity * 0.3}) ${100 - intensity * 100}%)` + : `linear-gradient(to right, transparent ${100 - intensity * 100}%, rgba(34, 197, 94, ${intensity * 0.3}) ${100 - intensity * 100}%)` + + const formatPrice = (priceStr: string, grouping: number): string => { + const priceNum = Number(priceStr) + + if (grouping >= 1) { + // Round up to nearest multiple of grouping + const rounded = Math.ceil(priceNum / grouping) * grouping + return rounded.toFixed(0) + } else { + // For decimal groupings, use decimal places + const decimals = Math.max(0, -Math.log10(grouping)) + return priceNum.toFixed(decimals) + } + } + + const formattedPrice = formatPrice(price, priceGrouping) + + return ( +
+
{formattedPrice}
+
{size}
+
{total}
+
+ ) +} + +export function OrderBook() { + const [activeTab, setActiveTab] = useState<"orderbook" | "trades">("orderbook") + const [priceGrouping, setPriceGrouping] = useState(0.01) + + const { asks, bids, spread, spreadPercent, maxSize } = useOrderBook() + const trades = useTrades() + + return ( +
+
+ + +
+ + {activeTab === "orderbook" ? ( + <> +
+ +
+ +
+
Price
+
+ Size ETH +
+
Total
+
+ +
+
+ {asks.map((ask, i) => ( + + ))} +
+ +
+
+ {spread} + Spread + {spreadPercent}% +
+
+ +
+ {bids.map((bid, i) => ( + + ))} +
+
+ + ) : ( + <> +
+
Price
+
Size
+
Time
+
+ +
+ {trades.map((trade, i) => ( +
+
{trade.price}
+
{trade.size}
+
{trade.time}
+
+ ))} +
+ + )} +
+ ) +} diff --git a/frontend/components/providers.tsx b/frontend/components/providers.tsx new file mode 100644 index 0000000..9e4aabd --- /dev/null +++ b/frontend/components/providers.tsx @@ -0,0 +1,30 @@ +'use client' + +import type React from 'react' +import { useMemo, useState } from 'react' + +import { WagmiProvider, createConfig, http } from 'wagmi' +import { mainnet } from 'wagmi/chains' +// IMPORTANT: use injected() instead of metaMask() to avoid pulling @metamask/sdk +import { injected } from 'wagmi/connectors' +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' + +export function Providers({ children }: { children: React.ReactNode }) { + const [queryClient] = useState(() => new QueryClient()) + + // Create config on the client; injected() does not touch indexedDB/RN storage. + const config = useMemo(() => { + return createConfig({ + chains: [mainnet], + transports: { [mainnet.id]: http() }, + connectors: [injected()], + // Do NOT enable any persistence layer that uses indexedDB on module load. + }) + }, []) + + return ( + + {children} + + ) +} diff --git a/frontend/components/theme-provider.tsx b/frontend/components/theme-provider.tsx new file mode 100644 index 0000000..1cd216d --- /dev/null +++ b/frontend/components/theme-provider.tsx @@ -0,0 +1,7 @@ +"use client" +import { ThemeProvider as NextThemesProvider } from "next-themes" +import type { ThemeProviderProps } from "next-themes" + +export function ThemeProvider({ children, ...props }: ThemeProviderProps) { + return {children} +} diff --git a/frontend/components/theme-toggle.tsx b/frontend/components/theme-toggle.tsx new file mode 100644 index 0000000..1ed9cbf --- /dev/null +++ b/frontend/components/theme-toggle.tsx @@ -0,0 +1,22 @@ +"use client" +import { Moon, Sun } from "lucide-react" +import { useTheme } from "next-themes" + +import { Button } from "@/components/ui/button" + +export function ThemeToggle() { + const { theme, setTheme } = useTheme() + + return ( + + ) +} diff --git a/frontend/components/trading-dashboard.tsx b/frontend/components/trading-dashboard.tsx new file mode 100644 index 0000000..a8ebfbc --- /dev/null +++ b/frontend/components/trading-dashboard.tsx @@ -0,0 +1,151 @@ +"use client" + +import { useState } from "react" +import { Button } from "@/components/ui/button" +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" +import { TradingViewChart } from "@/components/trading-view-chart" +import { WalletConnect } from "@/components/wallet-connect" +import { OrderBook } from "@/components/order-book" +import { TradingForm } from "@/components/trading-form" +import { AccountTabs } from "@/components/account-tabs" +import { ThemeToggle } from "@/components/theme-toggle" +import { Activity, TrendingUp, TrendingDown } from "lucide-react" + +export function TradingDashboard() { + const [selectedPair, setSelectedPair] = useState("BTC/USD") + + const stats = { + "BTC/USD": { + price: "67,234.50", + change: "+2.34", + changePercent: "+3.61%", + high24h: "68,450.00", + low24h: "65,120.00", + volume24h: "28.5B", + isPositive: true, + }, + "ETH/USD": { + price: "3,456.78", + change: "-45.23", + changePercent: "-1.29%", + high24h: "3,520.00", + low24h: "3,401.00", + volume24h: "12.3B", + isPositive: false, + }, + "SOL/USD": { + price: "142.56", + change: "+8.92", + changePercent: "+6.68%", + high24h: "145.00", + low24h: "135.20", + volume24h: "2.1B", + isPositive: true, + }, + } + + const currentStats = stats[selectedPair as keyof typeof stats] + + return ( +
+ {/* Header */} +
+
+
+
+ +

Orbex

+
+ +
+
+ + +
+
+
+ + {/* Main Content */} +
+ {/* Middle Section - Chart, Order Book, and Trading Form */} +
+ {/* Left Section - Chart and Order Book */} +
+ {/* Chart and Order Book Row */} +
+ {/* Trading Chart */} +
+
+
+ +
+ ${currentStats.price} +
+ {currentStats.isPositive ? ( + + ) : ( + + )} + {currentStats.changePercent} +
+
+
+
+ + +
+
+
+ +
+
+ + {/* Order Book */} +
+ +
+
+ +
+ +
+
+ + {/* Right Column - Trading Form */} +
+ +
+
+
+
+ ) +} diff --git a/frontend/components/trading-form.tsx b/frontend/components/trading-form.tsx new file mode 100644 index 0000000..2bb2df0 --- /dev/null +++ b/frontend/components/trading-form.tsx @@ -0,0 +1,207 @@ +"use client" + +import { useState } from "react" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" +import { Slider } from "@/components/ui/slider" +import { useToast } from "@/hooks/use-toast" + +interface TradingFormProps { + selectedPair: string +} + +export function TradingForm({ selectedPair }: TradingFormProps) { + const [buyAmount, setBuyAmount] = useState("") + const [buyPrice, setBuyPrice] = useState("") + const [sellAmount, setSellAmount] = useState("") + const [sellPrice, setSellPrice] = useState("") + const [buyPercentage, setBuyPercentage] = useState([0]) + const [sellPercentage, setSellPercentage] = useState([0]) + const { toast } = useToast() + + const handleBuy = () => { + toast({ + title: "Buy Order Placed", + description: `Buying ${buyAmount} ${selectedPair.split("/")[0]} at $${buyPrice}`, + }) + setBuyAmount("") + setBuyPrice("") + setBuyPercentage([0]) + } + + const handleSell = () => { + toast({ + title: "Sell Order Placed", + description: `Selling ${sellAmount} ${selectedPair.split("/")[0]} at $${sellPrice}`, + }) + setSellAmount("") + setSellPrice("") + setSellPercentage([0]) + } + + return ( +
+
+
Trade
+
+
+ + + + Buy + + + Sell + + + + +
+ + setBuyPrice(e.target.value)} + className="bg-background text-foreground" + /> +
+ +
+ + setBuyAmount(e.target.value)} + className="bg-background text-foreground" + /> +
+ +
+
+ + {buyPercentage[0]}% +
+ +
+ 0% + 25% + 50% + 75% + 100% +
+
+ +
+
+ Available Balance: + 10,000.00 USD +
+
+ Total: + + {buyAmount && buyPrice + ? (Number.parseFloat(buyAmount) * Number.parseFloat(buyPrice)).toFixed(2) + : "0.00"}{" "} + USD + +
+
+ + +
+ + +
+ + setSellPrice(e.target.value)} + className="bg-background text-foreground" + /> +
+ +
+ + setSellAmount(e.target.value)} + className="bg-background text-foreground" + /> +
+ +
+
+ + {sellPercentage[0]}% +
+ +
+ 0% + 25% + 50% + 75% + 100% +
+
+ +
+
+ Available Balance: + 0.5234 {selectedPair.split("/")[0]} +
+
+ Total: + + {sellAmount && sellPrice + ? (Number.parseFloat(sellAmount) * Number.parseFloat(sellPrice)).toFixed(2) + : "0.00"}{" "} + USD + +
+
+ + +
+
+
+
+ ) +} diff --git a/frontend/components/trading-view-chart.tsx b/frontend/components/trading-view-chart.tsx new file mode 100644 index 0000000..d511679 --- /dev/null +++ b/frontend/components/trading-view-chart.tsx @@ -0,0 +1,55 @@ +"use client" + +import { useEffect, useRef, memo } from "react" + +interface TradingViewChartProps { + symbol: string +} + +export const TradingViewChart = memo(function TradingViewChart({ symbol }: TradingViewChartProps) { + const container = useRef(null) + + useEffect(() => { + if (!container.current) return + + // Clear previous widget + container.current.innerHTML = "" + + const script = document.createElement("script") + script.src = "https://s3.tradingview.com/external-embedding/embed-widget-advanced-chart.js" + script.type = "text/javascript" + script.async = true + script.innerHTML = JSON.stringify({ + autosize: true, + symbol: symbol.replace("/", ""), + interval: "D", + timezone: "Etc/UTC", + theme: "dark", + style: "1", + locale: "en", + enable_publishing: false, + backgroundColor: "rgba(22, 22, 22, 1)", + gridColor: "rgba(42, 42, 42, 1)", + hide_top_toolbar: false, + hide_legend: false, + save_image: false, + container_id: "tradingview_chart", + height: "600", + width: "100%", + }) + + container.current.appendChild(script) + + return () => { + if (container.current) { + container.current.innerHTML = "" + } + } + }, [symbol]) + + return ( +
+
+
+ ) +}) diff --git a/frontend/components/ui/accordion.tsx b/frontend/components/ui/accordion.tsx new file mode 100644 index 0000000..e538a33 --- /dev/null +++ b/frontend/components/ui/accordion.tsx @@ -0,0 +1,66 @@ +'use client' + +import * as React from 'react' +import * as AccordionPrimitive from '@radix-ui/react-accordion' +import { ChevronDownIcon } from 'lucide-react' + +import { cn } from '@/lib/utils' + +function Accordion({ + ...props +}: React.ComponentProps) { + return +} + +function AccordionItem({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AccordionTrigger({ + className, + children, + ...props +}: React.ComponentProps) { + return ( + + svg]:rotate-180', + className, + )} + {...props} + > + {children} + + + + ) +} + +function AccordionContent({ + className, + children, + ...props +}: React.ComponentProps) { + return ( + +
{children}
+
+ ) +} + +export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } diff --git a/frontend/components/ui/alert-dialog.tsx b/frontend/components/ui/alert-dialog.tsx new file mode 100644 index 0000000..9704452 --- /dev/null +++ b/frontend/components/ui/alert-dialog.tsx @@ -0,0 +1,157 @@ +'use client' + +import * as React from 'react' +import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog' + +import { cn } from '@/lib/utils' +import { buttonVariants } from '@/components/ui/button' + +function AlertDialog({ + ...props +}: React.ComponentProps) { + return +} + +function AlertDialogTrigger({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogPortal({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogOverlay({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogContent({ + className, + ...props +}: React.ComponentProps) { + return ( + + + + + ) +} + +function AlertDialogHeader({ + className, + ...props +}: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +function AlertDialogFooter({ + className, + ...props +}: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +function AlertDialogTitle({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogDescription({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogAction({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogCancel({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { + AlertDialog, + AlertDialogPortal, + AlertDialogOverlay, + AlertDialogTrigger, + AlertDialogContent, + AlertDialogHeader, + AlertDialogFooter, + AlertDialogTitle, + AlertDialogDescription, + AlertDialogAction, + AlertDialogCancel, +} diff --git a/frontend/components/ui/alert.tsx b/frontend/components/ui/alert.tsx new file mode 100644 index 0000000..e6751ab --- /dev/null +++ b/frontend/components/ui/alert.tsx @@ -0,0 +1,66 @@ +import * as React from 'react' +import { cva, type VariantProps } from 'class-variance-authority' + +import { cn } from '@/lib/utils' + +const alertVariants = cva( + 'relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current', + { + variants: { + variant: { + default: 'bg-card text-card-foreground', + destructive: + 'text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90', + }, + }, + defaultVariants: { + variant: 'default', + }, + }, +) + +function Alert({ + className, + variant, + ...props +}: React.ComponentProps<'div'> & VariantProps) { + return ( +
+ ) +} + +function AlertTitle({ className, ...props }: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +function AlertDescription({ + className, + ...props +}: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +export { Alert, AlertTitle, AlertDescription } diff --git a/frontend/components/ui/aspect-ratio.tsx b/frontend/components/ui/aspect-ratio.tsx new file mode 100644 index 0000000..40bb120 --- /dev/null +++ b/frontend/components/ui/aspect-ratio.tsx @@ -0,0 +1,11 @@ +'use client' + +import * as AspectRatioPrimitive from '@radix-ui/react-aspect-ratio' + +function AspectRatio({ + ...props +}: React.ComponentProps) { + return +} + +export { AspectRatio } diff --git a/frontend/components/ui/avatar.tsx b/frontend/components/ui/avatar.tsx new file mode 100644 index 0000000..aa98465 --- /dev/null +++ b/frontend/components/ui/avatar.tsx @@ -0,0 +1,53 @@ +'use client' + +import * as React from 'react' +import * as AvatarPrimitive from '@radix-ui/react-avatar' + +import { cn } from '@/lib/utils' + +function Avatar({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AvatarImage({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AvatarFallback({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { Avatar, AvatarImage, AvatarFallback } diff --git a/frontend/components/ui/badge.tsx b/frontend/components/ui/badge.tsx new file mode 100644 index 0000000..fc4126b --- /dev/null +++ b/frontend/components/ui/badge.tsx @@ -0,0 +1,46 @@ +import * as React from 'react' +import { Slot } from '@radix-ui/react-slot' +import { cva, type VariantProps } from 'class-variance-authority' + +import { cn } from '@/lib/utils' + +const badgeVariants = cva( + 'inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden', + { + variants: { + variant: { + default: + 'border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90', + secondary: + 'border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90', + destructive: + 'border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60', + outline: + 'text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground', + }, + }, + defaultVariants: { + variant: 'default', + }, + }, +) + +function Badge({ + className, + variant, + asChild = false, + ...props +}: React.ComponentProps<'span'> & + VariantProps & { asChild?: boolean }) { + const Comp = asChild ? Slot : 'span' + + return ( + + ) +} + +export { Badge, badgeVariants } diff --git a/frontend/components/ui/breadcrumb.tsx b/frontend/components/ui/breadcrumb.tsx new file mode 100644 index 0000000..1750ff2 --- /dev/null +++ b/frontend/components/ui/breadcrumb.tsx @@ -0,0 +1,109 @@ +import * as React from 'react' +import { Slot } from '@radix-ui/react-slot' +import { ChevronRight, MoreHorizontal } from 'lucide-react' + +import { cn } from '@/lib/utils' + +function Breadcrumb({ ...props }: React.ComponentProps<'nav'>) { + return