Repository navigation
Expand file tree
/
Copy pathdigits-view.tsx
More file actions
244 lines (231 loc) · 8.18 KB
/
Copy pathdigits-view.tsx
File metadata and controls
244 lines (231 loc) · 8.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
'use client';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Footer } from '@/components/custom/footer';
import { Header } from '@/components/custom/header';
import { Skeleton } from '@/components/ui/skeleton';
import { CurrentTickDisplay } from './current-tick-display';
import { DigitStatsBar } from './digit-stats-bar';
import { TradeControls } from './trade-controls';
import { TradeTypeChips } from '@/components/custom/trade-type-chips';
import { SymbolSelector } from '@/components/custom/symbol-selector';
import { ThemeToggle } from '@/components/custom/theme-toggle';
import type {
AuthState,
DerivAccount,
ActiveSymbol,
Tick,
ProposalInfo,
DurationLimits,
BuyResult,
} from '@deriv/core';
import type { ContractMode, TradeType, DigitStats } from '../lib/types';
const DIGIT_TRADE_TYPE_OPTIONS: { value: TradeType; label: string }[] = [
{ value: 'matches-differs', label: 'Matches/Differs' },
{ value: 'over-under', label: 'Over/Under' },
{ value: 'even-odd', label: 'Even/Odd' },
];
export interface DigitsViewProps {
// Auth
authState: AuthState;
accounts: DerivAccount[];
activeAccount: DerivAccount | null;
onLogin: () => Promise<void>;
onSignUp: () => Promise<void>;
onLogout: () => void;
onSwitchAccount: (accountId: string) => Promise<void>;
// Connection / loading
isConnected: boolean;
isLoading: boolean;
error: string | null;
// Market data
symbols: ActiveSymbol[];
activeSymbol: ActiveSymbol | null;
selectSymbol: (symbol: string) => void;
currentTick: Tick | null;
lastDigit: number | null;
digitStats: DigitStats;
pipSize: number;
// Trade controls
tradeType: TradeType;
setTradeType: (type: TradeType) => void;
contractMode: ContractMode;
setContractMode: (mode: ContractMode) => void;
selectedDigit: number;
setSelectedDigit: (digit: number) => void;
stake: string;
setStake: (value: string) => void;
duration: number;
setDuration: (value: number) => void;
durationLimits: DurationLimits;
proposal: ProposalInfo | null;
isProposalLoading: boolean;
buyContract: () => Promise<void>;
isBuying: boolean;
buyResult: BuyResult | null;
buyError: string | null;
clearBuyResult: () => void;
// Branding (used by preview route; no-op in the real app)
logoSrc?: string;
appName?: string;
}
export function DigitsView({
authState,
accounts,
activeAccount,
onLogin,
onSignUp,
onLogout,
onSwitchAccount,
isConnected,
isLoading,
error,
symbols,
activeSymbol,
selectSymbol,
currentTick,
lastDigit,
digitStats,
pipSize,
tradeType,
setTradeType,
contractMode,
setContractMode,
selectedDigit,
setSelectedDigit,
stake,
setStake,
duration,
setDuration,
durationLimits,
proposal,
isProposalLoading,
buyContract,
isBuying,
buyResult,
buyError,
clearBuyResult,
logoSrc,
appName,
}: DigitsViewProps) {
if (error) {
return (
<main className="flex flex-col bg-background items-center justify-center px-4 min-h-dvh">
<Card className="max-w-md w-full">
<CardHeader>
<CardTitle className="text-destructive">Connection Error</CardTitle>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">{error}</p>
</CardContent>
</Card>
</main>
);
}
return (
<main className="flex flex-col bg-background max-lg:h-dvh max-lg:overflow-y-auto lg:overflow-visible">
<Header
authState={authState}
accounts={accounts}
activeAccount={activeAccount}
onLogin={onLogin}
onSignUp={onSignUp}
onLogout={onLogout}
onSwitchAccount={onSwitchAccount}
logoSrc={logoSrc}
appName={appName}
actions={<ThemeToggle />}
/>
{/* Spacer to push content below fixed header — taller when authenticated (account bar visible) */}
<div className={authState === 'authenticated' ? 'h-[76px] shrink-0' : 'h-[66px] shrink-0'} />
{/* Scrollable content area — sits between header and sticky buy bar on mobile */}
<div className="flex w-full max-w-7xl mx-auto flex-col px-3 py-2 sm:px-4 sm:py-4 gap-2 sm:gap-3 lg:flex-none lg:overflow-visible pb-10">
{isLoading ? (
<>
{/* Trade type chips skeleton */}
<div className="flex gap-2">
<Skeleton className="h-8 w-32 rounded-full" />
<Skeleton className="h-8 w-28 rounded-full" />
<Skeleton className="h-8 w-24 rounded-full" />
</div>
{/* Main card skeleton */}
<Skeleton className="w-full h-[420px] rounded-xl" />
</>
) : (
<>
<div className="shrink-0 overflow-x-auto pb-0.5 [-webkit-overflow-scrolling:touch] [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden">
<TradeTypeChips
value={tradeType}
options={DIGIT_TRADE_TYPE_OPTIONS}
onValueChange={setTradeType}
/>
</div>
<Card className="shrink-0 border shadow-sm mb-12">
<CardContent className="flex flex-col p-3 pt-3 sm:p-6 sm:pt-4 pb-2 sm:pb-6">
<div
className={`lg:grid lg:overflow-visible ${tradeType !== 'even-odd' ? 'lg:grid-cols-3' : 'lg:grid-cols-2'}`}
>
{/* Column 1: Symbol selector + tick display */}
<div className="flex flex-col pb-4 pt-1 sm:pb-6 sm:pt-2 lg:py-0 lg:pr-6">
<SymbolSelector
symbols={symbols}
activeSymbol={activeSymbol}
onSymbolChange={selectSymbol}
/>
<div className="flex items-center justify-center min-h-24 sm:min-h-32 lg:flex-1">
<CurrentTickDisplay
tick={currentTick}
lastDigit={lastDigit}
activeSymbol={activeSymbol}
pipSize={pipSize}
/>
</div>
</div>
{/* Columns 2+3 wrapper: stacked on mobile, transparent on desktop */}
<div className="max-lg:border-t max-lg:divide-y divide-border lg:contents">
{/* Column 2: Digit stats — hidden for Even/Odd */}
{tradeType !== 'even-odd' && (
<div className="py-4 sm:py-6 lg:py-0 lg:px-6 lg:border-l lg:border-border">
<DigitStatsBar
digitStats={digitStats}
selectedDigit={selectedDigit}
onDigitSelect={setSelectedDigit}
/>
</div>
)}
{/* Column 3: Trade controls */}
<div className="pt-4 sm:pt-6 lg:pt-0 lg:pl-6 lg:border-l lg:border-border">
<TradeControls
tradeType={tradeType}
contractMode={contractMode}
onContractModeChange={setContractMode}
selectedDigit={selectedDigit}
isConnected={isConnected}
stake={stake}
onStakeChange={setStake}
duration={duration}
onDurationChange={setDuration}
durationLimits={durationLimits}
proposal={proposal}
isProposalLoading={isProposalLoading}
onBuy={buyContract}
isBuying={isBuying}
buyResult={buyResult}
buyError={buyError}
onClearBuyResult={clearBuyResult}
isAuthenticated={authState === 'authenticated'}
/>
</div>
</div>
</div>
</CardContent>
</Card>
</>
)}
</div>
{/* Fixed footer */}
<div className="fixed bottom-0 left-0 right-0 py-2 text-center bg-background/80 backdrop-blur-sm">
<Footer />
</div>
</main>
);
}