Skip to content

Commit adf3c70

Browse files
authored
Merge pull request #45 from deriv-com/farabi/add-server-time
Farabi/add server time
2 parents 426c227 + 3c4d5b6 commit adf3c70

File tree

7 files changed

+58
-10
lines changed

7 files changed

+58
-10
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { useEffect } from "react";
2+
import { useServerTimeStore } from "@/stores/serverTimeStore";
3+
4+
export const ServerTime: React.FC = () => {
5+
const { serverTime, setServerTime } = useServerTimeStore();
6+
7+
useEffect(() => {
8+
const updateTime = () => {
9+
setServerTime(new Date());
10+
};
11+
12+
// Update immediately and then every second
13+
updateTime();
14+
const interval = setInterval(updateTime, 1000);
15+
16+
return () => clearInterval(interval);
17+
}, [setServerTime]);
18+
19+
return (
20+
<div className="text-xs text-gray-700 flex justify-between items-center py-2 px-2">
21+
<div>
22+
{serverTime.getDate().toString().padStart(2, '0')} {' '}
23+
{serverTime.toLocaleString('default', { month: 'short' })} {' '}
24+
{serverTime.getFullYear()}
25+
</div>
26+
<div>
27+
{serverTime.toTimeString().split(' ')[0]} GMT
28+
</div>
29+
</div>
30+
);
31+
};

src/components/ServerTime/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ServerTime } from "./ServerTime";

src/screens/ContractDetailsPage/ContractDetailsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ const MobileContractDetailsPage: React.FC = () => {
4343

4444
{/* Close Button */}
4545
<div className="fixed bottom-0 left-0 right-0 z-[60]">
46-
<div className="mx-2 text-center">
46+
<div className="mx-2 mb-2 text-center">
4747
<button
4848
onClick={() => navigate(-1)}
49-
className="text-white bg-black max-w-[500px] mx-auto w-full p-3 px-8 text-center rounded-xl shadow-md"
49+
className="text-white bg-black max-w-[500px] mx-auto w-full p-3 px-8 text-center rounded-xl shadow-md"
5050
>
5151
Close
5252
</button>

src/screens/TradePage/TradePage.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const TradePage: React.FC = () => {
3535
<div
3636
className={`flex ${
3737
isLandscape ? "flex-row relative" : "flex-col"
38-
} flex-1 h-[100dvh]`}
38+
} flex-1 h-[100%]`}
3939
data-testid="trade-page"
4040
>
4141
<div
@@ -68,9 +68,11 @@ export const TradePage: React.FC = () => {
6868
</Suspense>
6969
</div>
7070

71-
<Suspense fallback={<div>Loading...</div>}>
72-
<DurationOptions />
73-
</Suspense>
71+
{!isLandscape && (
72+
<Suspense fallback={<div>Loading...</div>}>
73+
<DurationOptions />
74+
</Suspense>
75+
)}
7476
</div>
7577
</div>
7678

src/screens/TradePage/__tests__/TradePage.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ describe('TradePage', () => {
168168
expect(tradePage.className).toContain('flex');
169169
expect(tradePage.className).toContain('flex-col');
170170
expect(tradePage.className).toContain('flex-1');
171-
expect(tradePage.className).toContain('h-[100dvh]');
171+
expect(tradePage.className).toContain('h-[100%]');
172172
});
173173

174174
it('renders in landscape mode', async () => {
@@ -185,7 +185,6 @@ describe('TradePage', () => {
185185

186186
// Balance display should be visible in landscape mode
187187
expect(screen.getByTestId('bottom-sheet')).toBeInTheDocument();
188-
expect(screen.getByTestId('duration-options')).toBeInTheDocument();
189188
expect(screen.getByTestId('market-selector')).toBeInTheDocument();
190189

191190
// // Check for MarketInfo with selected market
@@ -197,7 +196,7 @@ describe('TradePage', () => {
197196
expect(tradePage.className).toContain('flex-row');
198197
expect(tradePage.className).toContain('relative');
199198
expect(tradePage.className).toContain('flex-1');
200-
expect(tradePage.className).toContain('h-[100dvh]');
199+
expect(tradePage.className).toContain('h-[100%]');
201200
});
202201

203202
it('shows "Select Market" when no market is selected', () => {

src/screens/TradePage/components/TradeFormController.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Suspense, lazy, useEffect, useState } from "react"
2+
import { ServerTime } from "@/components/ServerTime"
23
import { TradeButton } from "@/components/TradeButton"
34
import { ResponsiveTradeParamLayout } from "@/components/ui/responsive-trade-param-layout"
45
import { MobileTradeFieldCard } from "@/components/ui/mobile-trade-field-card"
@@ -199,7 +200,7 @@ export const TradeFormController: React.FC<TradeFormControllerProps> = ({
199200
</div>
200201
{isLandscape ? (
201202
// Desktop layout
202-
<div className="flex-1">
203+
<div className="flex-1 flex flex-col">
203204
<div
204205
className="flex flex-col gap-0"
205206
onMouseDown={() => {
@@ -299,6 +300,9 @@ export const TradeFormController: React.FC<TradeFormControllerProps> = ({
299300
</Suspense>
300301
))}
301302
</div>
303+
<div className="mt-auto">
304+
<ServerTime />
305+
</div>
302306
</div>
303307
) : (
304308
// Mobile layout

src/stores/serverTimeStore.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { create } from 'zustand';
2+
3+
interface ServerTimeStore {
4+
serverTime: Date;
5+
setServerTime: (time: Date) => void;
6+
}
7+
8+
export const useServerTimeStore = create<ServerTimeStore>((set) => ({
9+
serverTime: new Date(),
10+
setServerTime: (time: Date) => set({ serverTime: time }),
11+
}));

0 commit comments

Comments
 (0)