first commit of restructured project
This commit is contained in:
16
trahn-trade-frontend/README.md
Normal file
16
trahn-trade-frontend/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# React + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|
||||
29
trahn-trade-frontend/eslint.config.js
Normal file
29
trahn-trade-frontend/eslint.config.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{js,jsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
ecmaFeatures: { jsx: true },
|
||||
sourceType: 'module',
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
||||
},
|
||||
},
|
||||
])
|
||||
15
trahn-trade-frontend/index.html
Normal file
15
trahn-trade-frontend/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>TRAHN Grid Trader</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Space+Grotesk:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
30
trahn-trade-frontend/package.json
Normal file
30
trahn-trade-frontend/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.90.12",
|
||||
"firebase": "^12.7.0",
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"react-router-dom": "^7.10.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@types/react": "^19.2.5",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^5.1.1",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"globals": "^16.5.0",
|
||||
"vite": "^7.2.4"
|
||||
}
|
||||
}
|
||||
612
trahn-trade-frontend/src/App.css
Normal file
612
trahn-trade-frontend/src/App.css
Normal file
@@ -0,0 +1,612 @@
|
||||
:root {
|
||||
--bg-primary: #0d1117;
|
||||
--bg-secondary: #161b22;
|
||||
--bg-tertiary: #21262d;
|
||||
--text-primary: #e6edf3;
|
||||
--text-secondary: #8b949e;
|
||||
--text-muted: #484f58;
|
||||
--accent: #58a6ff;
|
||||
--green: #3fb950;
|
||||
--green-fill: rgba(63, 185, 80, 0.15);
|
||||
--red: #f85149;
|
||||
--red-fill: rgba(248, 81, 73, 0.15);
|
||||
--yellow: #f0c000;
|
||||
--orange: #db6d28;
|
||||
--border: #30363d;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
min-height: 100vh;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.ascii-logo {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 0.65rem;
|
||||
line-height: 1.1;
|
||||
color: var(--accent);
|
||||
margin: 0;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary);
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
/* Carousel Navigation */
|
||||
.carousel-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.nav-arrow {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-primary);
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.nav-arrow:hover:not(:disabled) {
|
||||
background: var(--bg-tertiary);
|
||||
border-color: var(--accent);
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.nav-arrow:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.date-display {
|
||||
text-align: center;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.date-label {
|
||||
display: block;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.date-status {
|
||||
display: block;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary);
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.date-status.live {
|
||||
color: var(--green);
|
||||
}
|
||||
|
||||
.date-status.live::before {
|
||||
content: '●';
|
||||
margin-right: 0.5rem;
|
||||
animation: pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.4; }
|
||||
}
|
||||
|
||||
/* Chart */
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
position: absolute;
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 0.75rem;
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s ease;
|
||||
z-index: 100;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tooltip.visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tooltip .price {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.tooltip .time {
|
||||
color: var(--text-secondary);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* Loading overlay */
|
||||
.loading-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: var(--bg-secondary);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
border-radius: 12px;
|
||||
color: var(--text-secondary);
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 3px solid var(--border);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* Stats */
|
||||
.stats {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.stat {
|
||||
flex: 1;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
display: block;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.stat-value.high { color: var(--green); }
|
||||
.stat-value.low { color: var(--red); }
|
||||
.stat-value.buy { color: var(--yellow); }
|
||||
.stat-value.sell { color: var(--orange); }
|
||||
|
||||
/* Day indicators */
|
||||
.day-indicators {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.day-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--border);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.day-dot:hover {
|
||||
background: var(--text-secondary);
|
||||
}
|
||||
|
||||
.day-dot.active {
|
||||
background: var(--accent);
|
||||
box-shadow: 0 0 8px var(--accent);
|
||||
}
|
||||
|
||||
/* Legend */
|
||||
.legend {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 2rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.legend-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.buy-dot {
|
||||
background: var(--yellow);
|
||||
box-shadow: 0 0 8px var(--yellow);
|
||||
}
|
||||
|
||||
.sell-dot {
|
||||
background: var(--orange);
|
||||
box-shadow: 0 0 8px var(--orange);
|
||||
}
|
||||
|
||||
/* Connection status */
|
||||
.connection-status {
|
||||
position: fixed;
|
||||
bottom: 1rem;
|
||||
right: 1rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.connection-status .status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--text-muted);
|
||||
}
|
||||
|
||||
.connection-status.connected .status-dot {
|
||||
background: var(--green);
|
||||
box-shadow: 0 0 6px var(--green);
|
||||
}
|
||||
|
||||
.connection-status.waiting .status-dot {
|
||||
background: var(--yellow);
|
||||
animation: pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
body {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.75rem;
|
||||
}
|
||||
|
||||
.stats {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.stat {
|
||||
flex: 1 1 45%;
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Grid Levels Display */
|
||||
.grid-levels {
|
||||
margin-top: 1.5rem;
|
||||
padding: 1rem;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.grid-levels-header {
|
||||
text-align: center;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 1rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.grid-levels-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.grid-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.grid-column-header {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
margin-bottom: 0.5rem;
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.grid-column-header.buy {
|
||||
color: var(--yellow);
|
||||
background: rgba(240, 192, 0, 0.1);
|
||||
}
|
||||
|
||||
.grid-column-header.sell {
|
||||
color: var(--orange);
|
||||
background: rgba(219, 109, 40, 0.1);
|
||||
}
|
||||
|
||||
.grid-level {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 0.8rem;
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 4px;
|
||||
min-width: 100px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.grid-level.buy {
|
||||
color: var(--yellow);
|
||||
background: rgba(240, 192, 0, 0.08);
|
||||
border: 1px solid rgba(240, 192, 0, 0.2);
|
||||
}
|
||||
|
||||
.grid-level.sell {
|
||||
color: var(--orange);
|
||||
background: rgba(219, 109, 40, 0.08);
|
||||
border: 1px solid rgba(219, 109, 40, 0.2);
|
||||
}
|
||||
|
||||
.grid-level.filled {
|
||||
opacity: 0.5;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
/* Auth Pages */
|
||||
.auth-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 2.5rem;
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.auth-card .ascii-logo {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.auth-card h2 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text-primary);
|
||||
font-size: 1rem;
|
||||
font-family: inherit;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
|
||||
}
|
||||
|
||||
.form-group input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.auth-btn {
|
||||
width: 100%;
|
||||
padding: 0.875rem 1.5rem;
|
||||
background: var(--accent);
|
||||
color: var(--bg-primary);
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s, transform 0.1s;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.auth-btn:hover:not(:disabled) {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.auth-btn:active:not(:disabled) {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.auth-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.auth-error {
|
||||
background: var(--red-fill);
|
||||
border: 1px solid var(--red);
|
||||
color: var(--red);
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 8px;
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.auth-success {
|
||||
background: var(--green-fill);
|
||||
border: 1px solid var(--green);
|
||||
color: var(--green);
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 8px;
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.auth-link {
|
||||
margin-top: 1.5rem;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.auth-link a {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.auth-link a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Waitlist Message */
|
||||
.waitlist-message {
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 1.5rem;
|
||||
margin: 1rem 0;
|
||||
text-align: left;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.waitlist-message p {
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.waitlist-message .thank-you {
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* Logout Button */
|
||||
.logout-btn {
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
padding: 0.5rem 1rem;
|
||||
background: transparent;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s, color 0.2s;
|
||||
}
|
||||
|
||||
.logout-btn:hover {
|
||||
border-color: var(--red);
|
||||
color: var(--red);
|
||||
}
|
||||
|
||||
header {
|
||||
position: relative;
|
||||
}
|
||||
80
trahn-trade-frontend/src/App.jsx
Normal file
80
trahn-trade-frontend/src/App.jsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { AuthProvider, useAuth } from './contexts/AuthContext';
|
||||
import { TradingDataProvider } from './contexts/TradingDataContext';
|
||||
import { ProtectedRoute } from './components/ProtectedRoute';
|
||||
import { Dashboard } from './pages/Dashboard';
|
||||
import { Login } from './pages/Login';
|
||||
import { Signup } from './pages/Signup';
|
||||
import './App.css';
|
||||
|
||||
// Create React Query client
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
refetchOnWindowFocus: false,
|
||||
retry: 3,
|
||||
retryDelay: 2000,
|
||||
staleTime: 30000,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Redirect authenticated users away from auth pages
|
||||
function PublicRoute({ children }) {
|
||||
const { currentUser } = useAuth();
|
||||
|
||||
if (currentUser) {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
function AppRoutes() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Dashboard />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/login"
|
||||
element={
|
||||
<PublicRoute>
|
||||
<Login />
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/signup"
|
||||
element={
|
||||
<PublicRoute>
|
||||
<Signup />
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
);
|
||||
}
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<Router>
|
||||
<AuthProvider>
|
||||
<TradingDataProvider>
|
||||
<AppRoutes />
|
||||
</TradingDataProvider>
|
||||
</AuthProvider>
|
||||
</Router>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
81
trahn-trade-frontend/src/api/tradingApi.js
Normal file
81
trahn-trade-frontend/src/api/tradingApi.js
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Trading API Client
|
||||
* Communicates with backend REST API
|
||||
*/
|
||||
|
||||
const API_BASE = 'http://localhost:3001/api';
|
||||
|
||||
export const tradingApi = {
|
||||
/**
|
||||
* Get current trading day prices
|
||||
*/
|
||||
getCurrentPrices: async () => {
|
||||
const response = await fetch(`${API_BASE}/prices/today`);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get current trading day trades
|
||||
*/
|
||||
getCurrentTrades: async () => {
|
||||
const response = await fetch(`${API_BASE}/trades/today`);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get current grid state
|
||||
*/
|
||||
getCurrentGrid: async () => {
|
||||
const response = await fetch(`${API_BASE}/grid/current`);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get latest support/resistance levels
|
||||
*/
|
||||
getLatestSR: async () => {
|
||||
const response = await fetch(`${API_BASE}/support-resistance/latest`);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get available trading days
|
||||
*/
|
||||
getAvailableDays: async () => {
|
||||
const response = await fetch(`${API_BASE}/prices/days`);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get historical prices for a specific day
|
||||
*/
|
||||
getPricesByDay: async (date) => {
|
||||
const response = await fetch(`${API_BASE}/prices/day/${date}`);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get historical trades for a specific day
|
||||
*/
|
||||
getTradesByDay: async (date) => {
|
||||
const response = await fetch(`${API_BASE}/trades/day/${date}`);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get trade statistics
|
||||
*/
|
||||
getTradeStats: async () => {
|
||||
const response = await fetch(`${API_BASE}/trades/stats`);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
},
|
||||
};
|
||||
|
||||
1
trahn-trade-frontend/src/assets/react.svg
Normal file
1
trahn-trade-frontend/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
26
trahn-trade-frontend/src/auth/firebase.js
Normal file
26
trahn-trade-frontend/src/auth/firebase.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { initializeApp } from 'firebase/app';
|
||||
import { getAuth } from 'firebase/auth';
|
||||
import { getFirestore, collection, addDoc, serverTimestamp } from 'firebase/firestore';
|
||||
import { firebaseConfig } from './secrets';
|
||||
|
||||
const app = initializeApp(firebaseConfig);
|
||||
export const auth = getAuth(app);
|
||||
export const db = getFirestore(app);
|
||||
|
||||
// Add email to waitlist collection
|
||||
export async function addToWaitlist(email) {
|
||||
try {
|
||||
await addDoc(collection(db, 'trahn-trade-signups'), {
|
||||
email: email,
|
||||
createdAt: serverTimestamp(),
|
||||
status: 'pending'
|
||||
});
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error adding to waitlist:', error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
export default app;
|
||||
|
||||
13
trahn-trade-frontend/src/auth/secrets.example.js
Normal file
13
trahn-trade-frontend/src/auth/secrets.example.js
Normal file
@@ -0,0 +1,13 @@
|
||||
// Firebase Configuration
|
||||
// Copy this file to secrets.js and fill in your Firebase project values
|
||||
// Get these from: Firebase Console → Project Settings → Your apps → Web app
|
||||
|
||||
export const firebaseConfig = {
|
||||
apiKey: "YOUR_API_KEY",
|
||||
authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
|
||||
projectId: "YOUR_PROJECT_ID",
|
||||
storageBucket: "YOUR_PROJECT_ID.firebasestorage.app",
|
||||
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
|
||||
appId: "YOUR_APP_ID"
|
||||
};
|
||||
|
||||
82
trahn-trade-frontend/src/components/CarouselNav.jsx
Normal file
82
trahn-trade-frontend/src/components/CarouselNav.jsx
Normal file
@@ -0,0 +1,82 @@
|
||||
export function CarouselNav({
|
||||
currentDay,
|
||||
availableDays,
|
||||
currentDayIndex,
|
||||
isLive,
|
||||
canGoPrev,
|
||||
canGoNext,
|
||||
onPrev,
|
||||
onNext,
|
||||
onNavigateTo
|
||||
}) {
|
||||
const formatDate = (day) => {
|
||||
if (!day) return 'No Data';
|
||||
const date = new Date(day + 'T12:00:00');
|
||||
return date.toLocaleDateString('en-US', {
|
||||
weekday: 'short',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="carousel-nav">
|
||||
<button
|
||||
className="nav-arrow"
|
||||
onClick={onPrev}
|
||||
disabled={!canGoPrev}
|
||||
title="Previous Day"
|
||||
>
|
||||
◀
|
||||
</button>
|
||||
|
||||
<div className="date-display">
|
||||
<span className="date-label">{formatDate(currentDay)}</span>
|
||||
<span className={`date-status ${isLive ? 'live' : ''}`}>
|
||||
{isLive ? 'LIVE' : '24h snapshot'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<button
|
||||
className="nav-arrow"
|
||||
onClick={onNext}
|
||||
disabled={!canGoNext}
|
||||
title="Next Day"
|
||||
>
|
||||
▶
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function DayIndicators({ availableDays, currentDayIndex, onNavigateTo }) {
|
||||
return (
|
||||
<div className="day-indicators">
|
||||
{availableDays.map((day, i) => (
|
||||
<div
|
||||
key={day}
|
||||
className={`day-dot ${i === currentDayIndex ? 'active' : ''}`}
|
||||
title={day}
|
||||
onClick={() => onNavigateTo(i)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ConnectionStatus({ status }) {
|
||||
const statusText = {
|
||||
connected: 'Live',
|
||||
waiting: 'Waiting for backend...',
|
||||
connecting: 'Connecting...',
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`connection-status ${status}`}>
|
||||
<span className="status-dot" />
|
||||
<span className="status-text">{statusText[status] || 'Unknown'}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
350
trahn-trade-frontend/src/components/Chart.jsx
Normal file
350
trahn-trade-frontend/src/components/Chart.jsx
Normal file
@@ -0,0 +1,350 @@
|
||||
import { useRef, useEffect, useState } from 'react';
|
||||
|
||||
const COLORS = {
|
||||
line: '#58a6ff',
|
||||
green: '#3fb950',
|
||||
greenFill: 'rgba(63, 185, 80, 0.12)',
|
||||
red: '#f85149',
|
||||
redFill: 'rgba(248, 81, 73, 0.12)',
|
||||
grid: '#21262d',
|
||||
text: '#8b949e',
|
||||
textMuted: '#484f58',
|
||||
baseline: '#30363d',
|
||||
buy: '#f0c000',
|
||||
sell: '#db6d28',
|
||||
bg: '#0d1117',
|
||||
};
|
||||
|
||||
const PADDING = { top: 20, right: 80, bottom: 40, left: 20 };
|
||||
|
||||
export function Chart({ prices, trades }) {
|
||||
const canvasRef = useRef(null);
|
||||
const containerRef = useRef(null);
|
||||
const [tooltip, setTooltip] = useState(null);
|
||||
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
|
||||
|
||||
// Handle resize
|
||||
useEffect(() => {
|
||||
const updateDimensions = () => {
|
||||
if (containerRef.current) {
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
setDimensions({ width: rect.width, height: rect.height });
|
||||
}
|
||||
};
|
||||
|
||||
updateDimensions();
|
||||
window.addEventListener('resize', updateDimensions);
|
||||
return () => window.removeEventListener('resize', updateDimensions);
|
||||
}, []);
|
||||
|
||||
// Draw chart
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas || dimensions.width === 0) return;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
|
||||
canvas.width = dimensions.width * dpr;
|
||||
canvas.height = dimensions.height * dpr;
|
||||
ctx.scale(dpr, dpr);
|
||||
|
||||
const width = dimensions.width;
|
||||
const height = dimensions.height;
|
||||
const chartWidth = width - PADDING.left - PADDING.right;
|
||||
const chartHeight = height - PADDING.top - PADDING.bottom;
|
||||
|
||||
// Clear
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
|
||||
if (!prices || prices.length === 0) {
|
||||
ctx.fillStyle = COLORS.textMuted;
|
||||
ctx.font = '14px JetBrains Mono, monospace';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillText('No data for this day', width / 2, height / 2);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate bounds
|
||||
const priceValues = prices.map(d => d.p || d.price);
|
||||
const times = prices.map(d => d.t || d.timestamp);
|
||||
|
||||
let minPrice = Math.min(...priceValues);
|
||||
let maxPrice = Math.max(...priceValues);
|
||||
const minTime = Math.min(...times);
|
||||
const maxTime = Math.max(...times);
|
||||
|
||||
const pricePadding = (maxPrice - minPrice) * 0.05 || 10;
|
||||
minPrice -= pricePadding;
|
||||
maxPrice += pricePadding;
|
||||
|
||||
const baselinePrice = priceValues[0];
|
||||
|
||||
// Coordinate converters
|
||||
const priceToY = (price) => {
|
||||
const range = maxPrice - minPrice;
|
||||
const normalized = (price - minPrice) / range;
|
||||
return PADDING.top + chartHeight * (1 - normalized);
|
||||
};
|
||||
|
||||
const timeToX = (timestamp) => {
|
||||
const range = maxTime - minTime;
|
||||
const normalized = (timestamp - minTime) / range;
|
||||
return PADDING.left + chartWidth * normalized;
|
||||
};
|
||||
|
||||
// Draw grid
|
||||
ctx.strokeStyle = COLORS.grid;
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
const priceStep = calculateNiceStep(maxPrice - minPrice, 5);
|
||||
const startPrice = Math.ceil(minPrice / priceStep) * priceStep;
|
||||
|
||||
for (let price = startPrice; price <= maxPrice; price += priceStep) {
|
||||
const y = priceToY(price);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(PADDING.left, y);
|
||||
ctx.lineTo(width - PADDING.right, y);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// Draw baseline
|
||||
const baselineY = priceToY(baselinePrice);
|
||||
ctx.strokeStyle = COLORS.baseline;
|
||||
ctx.setLineDash([4, 4]);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(PADDING.left, baselineY);
|
||||
ctx.lineTo(width - PADDING.right, baselineY);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
|
||||
// Draw gradient fill
|
||||
if (prices.length >= 2) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(timeToX(times[0]), baselineY);
|
||||
ctx.lineTo(timeToX(times[0]), priceToY(priceValues[0]));
|
||||
|
||||
for (let i = 1; i < prices.length; i++) {
|
||||
ctx.lineTo(timeToX(times[i]), priceToY(priceValues[i]));
|
||||
}
|
||||
|
||||
ctx.lineTo(timeToX(times[times.length - 1]), baselineY);
|
||||
ctx.closePath();
|
||||
|
||||
const gradient = ctx.createLinearGradient(0, PADDING.top, 0, height - PADDING.bottom);
|
||||
gradient.addColorStop(0, COLORS.greenFill);
|
||||
gradient.addColorStop(0.5, 'rgba(0,0,0,0)');
|
||||
gradient.addColorStop(1, COLORS.redFill);
|
||||
ctx.fillStyle = gradient;
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// Draw price line
|
||||
if (prices.length >= 2) {
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = COLORS.line;
|
||||
ctx.lineWidth = 2;
|
||||
ctx.lineJoin = 'round';
|
||||
ctx.lineCap = 'round';
|
||||
|
||||
ctx.moveTo(timeToX(times[0]), priceToY(priceValues[0]));
|
||||
for (let i = 1; i < prices.length; i++) {
|
||||
ctx.lineTo(timeToX(times[i]), priceToY(priceValues[i]));
|
||||
}
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// Draw Y axis labels
|
||||
ctx.fillStyle = COLORS.text;
|
||||
ctx.font = '11px JetBrains Mono, monospace';
|
||||
ctx.textAlign = 'left';
|
||||
|
||||
for (let price = startPrice; price <= maxPrice; price += priceStep) {
|
||||
const y = priceToY(price);
|
||||
ctx.fillText(formatPrice(price), width - PADDING.right + 8, y + 4);
|
||||
}
|
||||
|
||||
// Draw X axis labels
|
||||
ctx.textAlign = 'center';
|
||||
const hourMs = 60 * 60 * 1000;
|
||||
const rangeMs = maxTime - minTime;
|
||||
let stepMs = hourMs * 4;
|
||||
if (rangeMs < hourMs * 6) stepMs = hourMs;
|
||||
if (rangeMs < hourMs * 2) stepMs = hourMs / 2;
|
||||
|
||||
let current = Math.ceil(minTime / stepMs) * stepMs;
|
||||
while (current <= maxTime) {
|
||||
const x = timeToX(current);
|
||||
if (x >= PADDING.left && x <= width - PADDING.right) {
|
||||
const date = new Date(current);
|
||||
const label = date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false });
|
||||
ctx.fillText(label, x, height - PADDING.bottom + 20);
|
||||
}
|
||||
current += stepMs;
|
||||
}
|
||||
|
||||
// Draw trades
|
||||
for (const trade of (trades || [])) {
|
||||
const x = timeToX(trade.t || trade.timestamp);
|
||||
const y = priceToY(trade.price);
|
||||
|
||||
if (x < PADDING.left || x > width - PADDING.right) continue;
|
||||
|
||||
const color = trade.side === 'buy' ? COLORS.buy : COLORS.sell;
|
||||
const radius = 7;
|
||||
|
||||
// Glow
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, radius + 4, 0, Math.PI * 2);
|
||||
ctx.fillStyle = color + '33';
|
||||
ctx.fill();
|
||||
|
||||
// Outer
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, radius, 0, Math.PI * 2);
|
||||
ctx.fillStyle = color;
|
||||
ctx.fill();
|
||||
|
||||
// Inner
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, radius - 3, 0, Math.PI * 2);
|
||||
ctx.fillStyle = COLORS.bg;
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// Draw current price tag
|
||||
if (prices.length > 0) {
|
||||
const lastPrice = priceValues[priceValues.length - 1];
|
||||
const y = priceToY(lastPrice);
|
||||
const x = width - PADDING.right;
|
||||
|
||||
const isUp = lastPrice >= baselinePrice;
|
||||
const color = isUp ? COLORS.green : COLORS.red;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
roundRect(ctx, x + 4, y - 11, 70, 22, 4);
|
||||
ctx.fill();
|
||||
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.font = 'bold 11px JetBrains Mono, monospace';
|
||||
ctx.textAlign = 'left';
|
||||
ctx.fillText(formatPrice(lastPrice), x + 10, y + 4);
|
||||
}
|
||||
|
||||
}, [prices, trades, dimensions]);
|
||||
|
||||
// Mouse handling for tooltip
|
||||
const handleMouseMove = (e) => {
|
||||
if (!prices || prices.length === 0) {
|
||||
setTooltip(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const rect = canvasRef.current.getBoundingClientRect();
|
||||
const x = e.clientX - rect.left;
|
||||
const y = e.clientY - rect.top;
|
||||
|
||||
const width = dimensions.width;
|
||||
const height = dimensions.height;
|
||||
const chartWidth = width - PADDING.left - PADDING.right;
|
||||
|
||||
if (x < PADDING.left || x > width - PADDING.right ||
|
||||
y < PADDING.top || y > height - PADDING.bottom) {
|
||||
setTooltip(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const times = prices.map(d => d.t || d.timestamp);
|
||||
const minTime = Math.min(...times);
|
||||
const maxTime = Math.max(...times);
|
||||
|
||||
const normalized = (x - PADDING.left) / chartWidth;
|
||||
const timestamp = minTime + normalized * (maxTime - minTime);
|
||||
|
||||
let nearestPoint = null;
|
||||
let nearestDistance = Infinity;
|
||||
|
||||
for (const point of prices) {
|
||||
const t = point.t || point.timestamp;
|
||||
const distance = Math.abs(t - timestamp);
|
||||
if (distance < nearestDistance) {
|
||||
nearestDistance = distance;
|
||||
nearestPoint = point;
|
||||
}
|
||||
}
|
||||
|
||||
if (nearestPoint) {
|
||||
setTooltip({
|
||||
x: e.clientX - rect.left + 15,
|
||||
y: e.clientY - rect.top - 10,
|
||||
price: nearestPoint.p || nearestPoint.price,
|
||||
timestamp: nearestPoint.t || nearestPoint.timestamp,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="chart-container" ref={containerRef}>
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseLeave={() => setTooltip(null)}
|
||||
/>
|
||||
{tooltip && (
|
||||
<div
|
||||
className="tooltip visible"
|
||||
style={{ left: tooltip.x, top: tooltip.y }}
|
||||
>
|
||||
<div className="price">
|
||||
${tooltip.price.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
|
||||
</div>
|
||||
<div className="time">
|
||||
{new Date(tooltip.timestamp).toLocaleString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function calculateNiceStep(range, targetSteps) {
|
||||
const roughStep = range / targetSteps;
|
||||
const magnitude = Math.pow(10, Math.floor(Math.log10(roughStep)));
|
||||
const normalized = roughStep / magnitude;
|
||||
|
||||
let niceStep;
|
||||
if (normalized <= 1.5) niceStep = 1;
|
||||
else if (normalized <= 3) niceStep = 2;
|
||||
else if (normalized <= 7) niceStep = 5;
|
||||
else niceStep = 10;
|
||||
|
||||
return niceStep * magnitude;
|
||||
}
|
||||
|
||||
function formatPrice(price) {
|
||||
if (price >= 10000) {
|
||||
return '$' + (price / 1000).toFixed(1) + 'k';
|
||||
}
|
||||
return '$' + price.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
||||
}
|
||||
|
||||
function roundRect(ctx, x, y, width, height, radius) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x + radius, y);
|
||||
ctx.lineTo(x + width - radius, y);
|
||||
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
||||
ctx.lineTo(x + width, y + height - radius);
|
||||
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
||||
ctx.lineTo(x + radius, y + height);
|
||||
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
||||
ctx.lineTo(x, y + radius);
|
||||
ctx.quadraticCurveTo(x, y, x + radius, y);
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
13
trahn-trade-frontend/src/components/ProtectedRoute.jsx
Normal file
13
trahn-trade-frontend/src/components/ProtectedRoute.jsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Navigate } from 'react-router-dom';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
|
||||
export function ProtectedRoute({ children }) {
|
||||
const { currentUser } = useAuth();
|
||||
|
||||
if (!currentUser) {
|
||||
return <Navigate to="/signup" replace />;
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
48
trahn-trade-frontend/src/components/Stats.jsx
Normal file
48
trahn-trade-frontend/src/components/Stats.jsx
Normal file
@@ -0,0 +1,48 @@
|
||||
export function Stats({ prices, trades }) {
|
||||
if (!prices || prices.length === 0) {
|
||||
return (
|
||||
<div className="stats">
|
||||
<Stat label="Current Price" value="--" />
|
||||
<Stat label="24H High" value="--" className="high" />
|
||||
<Stat label="24H Low" value="--" className="low" />
|
||||
<Stat label="Buys" value="0" className="buy" />
|
||||
<Stat label="Sells" value="0" className="sell" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const priceValues = prices.map(d => d.p || d.price);
|
||||
const currentPrice = priceValues[priceValues.length - 1];
|
||||
const highPrice = Math.max(...priceValues);
|
||||
const lowPrice = Math.min(...priceValues);
|
||||
|
||||
const buyCount = (trades || []).filter(t => t.side === 'buy').length;
|
||||
const sellCount = (trades || []).filter(t => t.side === 'sell').length;
|
||||
|
||||
const formatPrice = (price) => {
|
||||
return '$' + price.toLocaleString('en-US', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="stats">
|
||||
<Stat label="Current Price" value={formatPrice(currentPrice)} />
|
||||
<Stat label="24H High" value={formatPrice(highPrice)} className="high" />
|
||||
<Stat label="24H Low" value={formatPrice(lowPrice)} className="low" />
|
||||
<Stat label="Buys" value={buyCount} className="buy" />
|
||||
<Stat label="Sells" value={sellCount} className="sell" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Stat({ label, value, className = '' }) {
|
||||
return (
|
||||
<div className="stat">
|
||||
<span className="stat-label">{label}</span>
|
||||
<span className={`stat-value ${className}`}>{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
54
trahn-trade-frontend/src/contexts/AuthContext.jsx
Normal file
54
trahn-trade-frontend/src/contexts/AuthContext.jsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import { createContext, useContext, useState, useEffect } from 'react';
|
||||
import {
|
||||
createUserWithEmailAndPassword,
|
||||
signInWithEmailAndPassword,
|
||||
signOut,
|
||||
onAuthStateChanged
|
||||
} from 'firebase/auth';
|
||||
import { auth } from '../auth/firebase';
|
||||
|
||||
const AuthContext = createContext();
|
||||
|
||||
export function useAuth() {
|
||||
return useContext(AuthContext);
|
||||
}
|
||||
|
||||
export function AuthProvider({ children }) {
|
||||
const [currentUser, setCurrentUser] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
function signup(email, password) {
|
||||
return createUserWithEmailAndPassword(auth, email, password);
|
||||
}
|
||||
|
||||
function login(email, password) {
|
||||
return signInWithEmailAndPassword(auth, email, password);
|
||||
}
|
||||
|
||||
function logout() {
|
||||
return signOut(auth);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = onAuthStateChanged(auth, (user) => {
|
||||
setCurrentUser(user);
|
||||
setLoading(false);
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
}, []);
|
||||
|
||||
const value = {
|
||||
currentUser,
|
||||
signup,
|
||||
login,
|
||||
logout
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={value}>
|
||||
{!loading && children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
125
trahn-trade-frontend/src/contexts/TradingDataContext.jsx
Normal file
125
trahn-trade-frontend/src/contexts/TradingDataContext.jsx
Normal file
@@ -0,0 +1,125 @@
|
||||
import { createContext, useContext, useReducer, useEffect } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { tradingApi } from '../api/tradingApi';
|
||||
|
||||
const TradingDataContext = createContext(undefined);
|
||||
|
||||
const initialState = {
|
||||
currentDay: null,
|
||||
availableDays: [],
|
||||
currentDayIndex: 0,
|
||||
prices: [],
|
||||
trades: [],
|
||||
grid: [],
|
||||
supportResistance: null,
|
||||
isLive: true,
|
||||
connectionStatus: 'connecting',
|
||||
};
|
||||
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case 'UPDATE_CURRENT_DAY':
|
||||
const dayIndex = action.availableDays.length > 0 ? action.availableDays.length - 1 : 0;
|
||||
return {
|
||||
...state,
|
||||
prices: action.prices || [],
|
||||
trades: action.trades || [],
|
||||
grid: action.grid || [],
|
||||
availableDays: action.availableDays || [],
|
||||
currentDay: action.currentDay,
|
||||
currentDayIndex: dayIndex,
|
||||
isLive: true,
|
||||
connectionStatus: 'connected',
|
||||
};
|
||||
|
||||
case 'LOAD_HISTORICAL_DAY':
|
||||
return {
|
||||
...state,
|
||||
prices: action.prices,
|
||||
trades: action.trades,
|
||||
currentDayIndex: action.index,
|
||||
isLive: false,
|
||||
};
|
||||
|
||||
case 'SET_CONNECTION_STATUS':
|
||||
return {
|
||||
...state,
|
||||
connectionStatus: action.status,
|
||||
};
|
||||
|
||||
case 'SWITCH_TO_LIVE':
|
||||
return {
|
||||
...state,
|
||||
isLive: true,
|
||||
currentDayIndex: state.availableDays.length - 1,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export function TradingDataProvider({ children }) {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
// React Query: Poll current day data every 1 minute
|
||||
const { data: currentData, error, isLoading } = useQuery({
|
||||
queryKey: ['currentDay'],
|
||||
queryFn: async () => {
|
||||
const [prices, trades, grid, days] = await Promise.all([
|
||||
tradingApi.getCurrentPrices(),
|
||||
tradingApi.getCurrentTrades(),
|
||||
tradingApi.getCurrentGrid(),
|
||||
tradingApi.getAvailableDays(),
|
||||
]);
|
||||
|
||||
return {
|
||||
prices,
|
||||
trades,
|
||||
grid: grid.grid || [],
|
||||
availableDays: days,
|
||||
currentDay: days[days.length - 1] || null,
|
||||
};
|
||||
},
|
||||
refetchInterval: 60000, // Poll every 1 minute
|
||||
staleTime: 30000, // Data fresh for 30 seconds
|
||||
retry: 3,
|
||||
retryDelay: 2000,
|
||||
});
|
||||
|
||||
// Update context when live data changes
|
||||
useEffect(() => {
|
||||
if (currentData) {
|
||||
dispatch({
|
||||
type: 'UPDATE_CURRENT_DAY',
|
||||
...currentData
|
||||
});
|
||||
}
|
||||
}, [currentData]);
|
||||
|
||||
// Handle connection status
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
dispatch({ type: 'SET_CONNECTION_STATUS', status: 'error' });
|
||||
} else if (isLoading) {
|
||||
dispatch({ type: 'SET_CONNECTION_STATUS', status: 'connecting' });
|
||||
} else {
|
||||
dispatch({ type: 'SET_CONNECTION_STATUS', status: 'connected' });
|
||||
}
|
||||
}, [error, isLoading]);
|
||||
|
||||
return (
|
||||
<TradingDataContext.Provider value={{ state, dispatch }}>
|
||||
{children}
|
||||
</TradingDataContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTradingData() {
|
||||
const context = useContext(TradingDataContext);
|
||||
if (!context) {
|
||||
throw new Error('useTradingData must be used within TradingDataProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
18
trahn-trade-frontend/src/hooks/useChartData.js
Normal file
18
trahn-trade-frontend/src/hooks/useChartData.js
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* DEPRECATED - Replaced by TradingDataContext + React Query
|
||||
*
|
||||
* This file is kept for reference but no longer used.
|
||||
* The new implementation:
|
||||
* - Uses React Query for polling
|
||||
* - Uses Context for state management
|
||||
* - Calls REST API instead of JSON files
|
||||
*
|
||||
* See:
|
||||
* - contexts/TradingDataContext.jsx
|
||||
* - hooks/useTradingData.js
|
||||
* - api/tradingApi.js
|
||||
*/
|
||||
|
||||
export function useChartData() {
|
||||
throw new Error('useChartData is deprecated. Use useTradingData from TradingDataContext instead.');
|
||||
}
|
||||
80
trahn-trade-frontend/src/hooks/useTradingData.js
Normal file
80
trahn-trade-frontend/src/hooks/useTradingData.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Custom hooks for trading data management
|
||||
* Handles carousel navigation and historical day loading
|
||||
*/
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useTradingData } from '../contexts/TradingDataContext';
|
||||
import { tradingApi } from '../api/tradingApi';
|
||||
|
||||
/**
|
||||
* Hook for loading historical day data (lazy load)
|
||||
*/
|
||||
export function useHistoricalDay(date, enabled = false) {
|
||||
return useQuery({
|
||||
queryKey: ['historicalDay', date],
|
||||
queryFn: async () => {
|
||||
const [prices, trades] = await Promise.all([
|
||||
tradingApi.getPricesByDay(date),
|
||||
tradingApi.getTradesByDay(date),
|
||||
]);
|
||||
return { prices, trades };
|
||||
},
|
||||
enabled: enabled && !!date,
|
||||
staleTime: Infinity, // Historical data never changes
|
||||
cacheTime: 600000, // Keep in cache for 10 minutes
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for carousel navigation
|
||||
*/
|
||||
export function useCarousel() {
|
||||
const { state, dispatch } = useTradingData();
|
||||
|
||||
const navigateTo = (index) => {
|
||||
if (index < 0 || index >= state.availableDays.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index === state.availableDays.length - 1) {
|
||||
// Navigate to live (current) day
|
||||
dispatch({ type: 'SWITCH_TO_LIVE' });
|
||||
} else {
|
||||
// Load historical day
|
||||
const date = state.availableDays[index];
|
||||
// Historical data will be loaded via useHistoricalDay in Dashboard
|
||||
dispatch({
|
||||
type: 'LOAD_HISTORICAL_DAY',
|
||||
prices: [],
|
||||
trades: [],
|
||||
index
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const navigatePrev = () => {
|
||||
if (state.currentDayIndex > 0) {
|
||||
navigateTo(state.currentDayIndex - 1);
|
||||
}
|
||||
};
|
||||
|
||||
const navigateNext = () => {
|
||||
if (state.currentDayIndex < state.availableDays.length - 1) {
|
||||
navigateTo(state.currentDayIndex + 1);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
currentDayIndex: state.currentDayIndex,
|
||||
availableDays: state.availableDays,
|
||||
currentDay: state.availableDays[state.currentDayIndex],
|
||||
canGoPrev: state.currentDayIndex > 0,
|
||||
canGoNext: state.currentDayIndex < state.availableDays.length - 1,
|
||||
navigatePrev,
|
||||
navigateNext,
|
||||
navigateTo,
|
||||
isLive: state.isLive,
|
||||
};
|
||||
}
|
||||
|
||||
1
trahn-trade-frontend/src/index.css
Normal file
1
trahn-trade-frontend/src/index.css
Normal file
@@ -0,0 +1 @@
|
||||
/* Reset handled in App.css */
|
||||
10
trahn-trade-frontend/src/main.jsx
Normal file
10
trahn-trade-frontend/src/main.jsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.jsx'
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
138
trahn-trade-frontend/src/pages/Dashboard.jsx
Normal file
138
trahn-trade-frontend/src/pages/Dashboard.jsx
Normal file
@@ -0,0 +1,138 @@
|
||||
import { Chart } from '../components/Chart';
|
||||
import { CarouselNav, DayIndicators, ConnectionStatus } from '../components/CarouselNav';
|
||||
import { Stats } from '../components/Stats';
|
||||
import { useTradingData } from '../contexts/TradingDataContext';
|
||||
import { useCarousel } from '../hooks/useTradingData';
|
||||
import { useHistoricalDay } from '../hooks/useTradingData';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function Dashboard() {
|
||||
const { logout } = useAuth();
|
||||
const { state, dispatch } = useTradingData();
|
||||
const carousel = useCarousel();
|
||||
|
||||
// Load historical day data when viewing past days
|
||||
const historicalDate = !state.isLive ? state.availableDays[state.currentDayIndex] : null;
|
||||
const { data: historicalData } = useHistoricalDay(historicalDate, !state.isLive);
|
||||
|
||||
// Update context with historical data when loaded
|
||||
useEffect(() => {
|
||||
if (historicalData && !state.isLive) {
|
||||
dispatch({
|
||||
type: 'LOAD_HISTORICAL_DAY',
|
||||
prices: historicalData.prices,
|
||||
trades: historicalData.trades,
|
||||
index: state.currentDayIndex,
|
||||
});
|
||||
}
|
||||
}, [historicalData, state.isLive, state.currentDayIndex, dispatch]);
|
||||
|
||||
const {
|
||||
prices,
|
||||
trades,
|
||||
grid,
|
||||
availableDays,
|
||||
currentDayIndex,
|
||||
isLive,
|
||||
connectionStatus,
|
||||
} = state;
|
||||
|
||||
const {
|
||||
navigatePrev,
|
||||
navigateNext,
|
||||
navigateTo,
|
||||
canGoPrev,
|
||||
canGoNext,
|
||||
} = carousel;
|
||||
|
||||
const currentDay = availableDays[currentDayIndex] || null;
|
||||
const loading = connectionStatus === 'connecting';
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
<header>
|
||||
<pre className="ascii-logo">{`
|
||||
████████╗██████╗ █████╗ ██╗ ██╗███╗ ██╗
|
||||
╚══██╔══╝██╔══██╗██╔══██╗██║ ██║████╗ ██║
|
||||
██║ ██████╔╝███████║███████║██╔██╗ ██║
|
||||
██║ ██╔══██╗██╔══██║██╔══██║██║╚██╗██║
|
||||
██║ ██║ ██║██║ ██║██║ ██║██║ ╚████║
|
||||
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝`}</pre>
|
||||
<button className="logout-btn" onClick={logout}>Logout</button>
|
||||
</header>
|
||||
|
||||
<CarouselNav
|
||||
currentDay={currentDay}
|
||||
availableDays={availableDays}
|
||||
currentDayIndex={currentDayIndex}
|
||||
isLive={isLive}
|
||||
canGoPrev={canGoPrev}
|
||||
canGoNext={canGoNext}
|
||||
onPrev={navigatePrev}
|
||||
onNext={navigateNext}
|
||||
onNavigateTo={navigateTo}
|
||||
/>
|
||||
|
||||
<div className="chart-wrapper">
|
||||
<Chart prices={prices} trades={trades} />
|
||||
{loading && (
|
||||
<div className="loading-overlay">
|
||||
<div className="spinner" />
|
||||
<span>Waiting for data...</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Stats prices={prices} trades={trades} />
|
||||
|
||||
<DayIndicators
|
||||
availableDays={availableDays}
|
||||
currentDayIndex={currentDayIndex}
|
||||
onNavigateTo={navigateTo}
|
||||
/>
|
||||
|
||||
<div className="legend">
|
||||
<span className="legend-item">
|
||||
<span className="dot buy-dot" /> Buy (USDC → ETH)
|
||||
</span>
|
||||
<span className="legend-item">
|
||||
<span className="dot sell-dot" /> Sell (ETH → USDC)
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{grid && grid.length > 0 && (
|
||||
<div className="grid-levels">
|
||||
<div className="grid-levels-header">Grid Levels</div>
|
||||
<div className="grid-levels-container">
|
||||
<div className="grid-column">
|
||||
<div className="grid-column-header buy">Buy Levels</div>
|
||||
{grid
|
||||
.filter(level => level.side === 'buy')
|
||||
.sort((a, b) => b.price - a.price)
|
||||
.map((level, idx) => (
|
||||
<div key={idx} className={`grid-level buy ${level.filled ? 'filled' : ''}`}>
|
||||
${level.price.toFixed(2)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid-column">
|
||||
<div className="grid-column-header sell">Sell Levels</div>
|
||||
{grid
|
||||
.filter(level => level.side === 'sell')
|
||||
.sort((a, b) => a.price - b.price)
|
||||
.map((level, idx) => (
|
||||
<div key={idx} className={`grid-level sell ${level.filled ? 'filled' : ''}`}>
|
||||
${level.price.toFixed(2)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ConnectionStatus status={connectionStatus} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
82
trahn-trade-frontend/src/pages/Login.jsx
Normal file
82
trahn-trade-frontend/src/pages/Login.jsx
Normal file
@@ -0,0 +1,82 @@
|
||||
import { useState } from 'react';
|
||||
import { useNavigate, Link, useLocation } from 'react-router-dom';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
|
||||
export function Login() {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { login } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const successMessage = location.state?.message;
|
||||
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
try {
|
||||
setError('');
|
||||
setLoading(true);
|
||||
await login(email, password);
|
||||
navigate('/');
|
||||
} catch (err) {
|
||||
setError(err.message || 'Failed to log in');
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="auth-container">
|
||||
<div className="auth-card">
|
||||
<pre className="ascii-logo">{`
|
||||
████████╗██████╗ █████╗ ██╗ ██╗███╗ ██╗
|
||||
╚══██╔══╝██╔══██╗██╔══██╗██║ ██║████╗ ██║
|
||||
██║ ██████╔╝███████║███████║██╔██╗ ██║
|
||||
██║ ██╔══██╗██╔══██║██╔══██║██║╚██╗██║
|
||||
██║ ██║ ██║██║ ██║██║ ██║██║ ╚████║
|
||||
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝`}</pre>
|
||||
|
||||
<h2>Welcome Back</h2>
|
||||
|
||||
{successMessage && <div className="auth-success">{successMessage}</div>}
|
||||
{error && <div className="auth-error">{error}</div>}
|
||||
|
||||
<form onSubmit={handleSubmit} className="auth-form">
|
||||
<div className="form-group">
|
||||
<label htmlFor="email">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
placeholder="you@example.com"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="password">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
placeholder="••••••••"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button type="submit" className="auth-btn" disabled={loading}>
|
||||
{loading ? 'Logging In...' : 'Log In'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p className="auth-link">
|
||||
Don't have an account? <Link to="/signup">Sign Up</Link>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
96
trahn-trade-frontend/src/pages/Signup.jsx
Normal file
96
trahn-trade-frontend/src/pages/Signup.jsx
Normal file
@@ -0,0 +1,96 @@
|
||||
import { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { addToWaitlist } from '../auth/firebase';
|
||||
//a comment
|
||||
|
||||
export function Signup() {
|
||||
const [email, setEmail] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
//
|
||||
//
|
||||
//
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!email) {
|
||||
return setError('Please enter your email address');
|
||||
}
|
||||
|
||||
try {
|
||||
setError('');
|
||||
setLoading(true);
|
||||
const result = await addToWaitlist(email);
|
||||
|
||||
if (result.success) {
|
||||
setSubmitted(true);
|
||||
} else {
|
||||
setError(result.error || 'Failed to join waitlist. Please try again.');
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Something went wrong. Please try again.');
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
// some spacing
|
||||
//more
|
||||
return (
|
||||
<div className="auth-container">
|
||||
<div className="auth-card">
|
||||
<pre className="ascii-logo">{`
|
||||
████████╗██████╗ █████╗ ██╗ ██╗███╗ ██╗
|
||||
╚══██╔══╝██╔══██╗██╔══██╗██║ ██║████╗ ██║
|
||||
██║ ██████╔╝███████║███████║██╔██╗ ██║
|
||||
██║ ██╔══██╗██╔══██║██╔══██║██║╚██╗██║
|
||||
██║ ██║ ██║██║ ██║██║ ██║██║ ╚████║
|
||||
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝`}</pre>
|
||||
|
||||
{submitted ? (
|
||||
<>
|
||||
<h2>Request Received</h2>
|
||||
<div className="waitlist-message">
|
||||
<p>
|
||||
A message has been sent requesting authorization for signup.
|
||||
You will receive a response to your email when granted, or
|
||||
further information regarding the waitlist.
|
||||
</p>
|
||||
<p className="thank-you">Thank you for your interest!</p>
|
||||
</div>
|
||||
<p className="auth-link">
|
||||
Already have an account? <Link to="/login">Log In</Link>
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<h2>Join Waitlist</h2>
|
||||
|
||||
{error && <div className="auth-error">{error}</div>}
|
||||
|
||||
<form onSubmit={handleSubmit} className="auth-form">
|
||||
<div className="form-group">
|
||||
<label htmlFor="email">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
placeholder="you@example.com"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button type="submit" className="auth-btn" disabled={loading}>
|
||||
{loading ? 'Submitting...' : 'Request Access'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p className="auth-link">
|
||||
Already have an account? <Link to="/login">Log In</Link>
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
15
trahn-trade-frontend/vite.config.js
Normal file
15
trahn-trade-frontend/vite.config.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 3000,
|
||||
// Serve the data folder
|
||||
fs: {
|
||||
allow: ['..'],
|
||||
},
|
||||
},
|
||||
// Make data folder accessible
|
||||
publicDir: 'public',
|
||||
})
|
||||
Reference in New Issue
Block a user