Skip to content

Commit

Permalink
Merge pull request #45 from deriv-com/farabi/add-server-time
Browse files Browse the repository at this point in the history
Farabi/add server time
  • Loading branch information
farabi-deriv authored Feb 20, 2025
2 parents 426c227 + 3c4d5b6 commit adf3c70
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 10 deletions.
31 changes: 31 additions & 0 deletions src/components/ServerTime/ServerTime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useEffect } from "react";
import { useServerTimeStore } from "@/stores/serverTimeStore";

export const ServerTime: React.FC = () => {
const { serverTime, setServerTime } = useServerTimeStore();

useEffect(() => {
const updateTime = () => {
setServerTime(new Date());
};

// Update immediately and then every second
updateTime();
const interval = setInterval(updateTime, 1000);

return () => clearInterval(interval);
}, [setServerTime]);

return (
<div className="text-xs text-gray-700 flex justify-between items-center py-2 px-2">
<div>
{serverTime.getDate().toString().padStart(2, '0')} {' '}
{serverTime.toLocaleString('default', { month: 'short' })} {' '}
{serverTime.getFullYear()}
</div>
<div>
{serverTime.toTimeString().split(' ')[0]} GMT
</div>
</div>
);
};
1 change: 1 addition & 0 deletions src/components/ServerTime/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ServerTime } from "./ServerTime";
4 changes: 2 additions & 2 deletions src/screens/ContractDetailsPage/ContractDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const MobileContractDetailsPage: React.FC = () => {

{/* Close Button */}
<div className="fixed bottom-0 left-0 right-0 z-[60]">
<div className="mx-2 text-center">
<div className="mx-2 mb-2 text-center">
<button
onClick={() => navigate(-1)}
className="text-white bg-black max-w-[500px] mx-auto w-full p-3 px-8 text-center rounded-xl shadow-md"
className="text-white bg-black max-w-[500px] mx-auto w-full p-3 px-8 text-center rounded-xl shadow-md"
>
Close
</button>
Expand Down
10 changes: 6 additions & 4 deletions src/screens/TradePage/TradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const TradePage: React.FC = () => {
<div
className={`flex ${
isLandscape ? "flex-row relative" : "flex-col"
} flex-1 h-[100dvh]`}
} flex-1 h-[100%]`}
data-testid="trade-page"
>
<div
Expand Down Expand Up @@ -68,9 +68,11 @@ export const TradePage: React.FC = () => {
</Suspense>
</div>

<Suspense fallback={<div>Loading...</div>}>
<DurationOptions />
</Suspense>
{!isLandscape && (
<Suspense fallback={<div>Loading...</div>}>
<DurationOptions />
</Suspense>
)}
</div>
</div>

Expand Down
5 changes: 2 additions & 3 deletions src/screens/TradePage/__tests__/TradePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('TradePage', () => {
expect(tradePage.className).toContain('flex');
expect(tradePage.className).toContain('flex-col');
expect(tradePage.className).toContain('flex-1');
expect(tradePage.className).toContain('h-[100dvh]');
expect(tradePage.className).toContain('h-[100%]');
});

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

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

// // Check for MarketInfo with selected market
Expand All @@ -197,7 +196,7 @@ describe('TradePage', () => {
expect(tradePage.className).toContain('flex-row');
expect(tradePage.className).toContain('relative');
expect(tradePage.className).toContain('flex-1');
expect(tradePage.className).toContain('h-[100dvh]');
expect(tradePage.className).toContain('h-[100%]');
});

it('shows "Select Market" when no market is selected', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/screens/TradePage/components/TradeFormController.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Suspense, lazy, useEffect, useState } from "react"
import { ServerTime } from "@/components/ServerTime"
import { TradeButton } from "@/components/TradeButton"
import { ResponsiveTradeParamLayout } from "@/components/ui/responsive-trade-param-layout"
import { MobileTradeFieldCard } from "@/components/ui/mobile-trade-field-card"
Expand Down Expand Up @@ -199,7 +200,7 @@ export const TradeFormController: React.FC<TradeFormControllerProps> = ({
</div>
{isLandscape ? (
// Desktop layout
<div className="flex-1">
<div className="flex-1 flex flex-col">
<div
className="flex flex-col gap-0"
onMouseDown={() => {
Expand Down Expand Up @@ -299,6 +300,9 @@ export const TradeFormController: React.FC<TradeFormControllerProps> = ({
</Suspense>
))}
</div>
<div className="mt-auto">
<ServerTime />
</div>
</div>
) : (
// Mobile layout
Expand Down
11 changes: 11 additions & 0 deletions src/stores/serverTimeStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { create } from 'zustand';

interface ServerTimeStore {
serverTime: Date;
setServerTime: (time: Date) => void;
}

export const useServerTimeStore = create<ServerTimeStore>((set) => ({
serverTime: new Date(),
setServerTime: (time: Date) => set({ serverTime: time }),
}));

0 comments on commit adf3c70

Please sign in to comment.