forked from deriv-com/trade-rise-fall
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request deriv-com#11 from mayuran-deriv/mayuran/globalstor…
…e-and-price-validation Mayuran/globalstore and price validation
- Loading branch information
Showing
6 changed files
with
162 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,13 @@ | ||
import { useEffect, useState } from "react"; | ||
import { isBrowser } from "../common/utils"; | ||
import { Chart } from "../components/TradingComponents/Chart/Chart"; | ||
import { TradingPanel } from "../components/TradingComponents/TradingPanel/TradingPanel"; | ||
import { DurationTabValue, StakeTabValue } from "../components/TradingComponents/types"; | ||
import "@deriv/deriv-charts/dist/smartcharts.css"; | ||
import "./DerivTrading.scss"; | ||
|
||
export default function DerivTrading() { | ||
const [symbol, setSymbol] = useState<string>("1HZ10V"); | ||
const [chartStatus, setChartStatus] = useState<boolean>(true); | ||
const [showChart, setShowChart] = useState<boolean>(false); | ||
const [duration, setDuration] = useState(1); | ||
const [stake, setStake] = useState(50); | ||
const [allowEquals, setAllowEquals] = useState(false); | ||
const [selectedDurationTab, setSelectedDurationTab] = useState<DurationTabValue>('duration'); | ||
const [selectedStakeTab, setSelectedStakeTab] = useState<StakeTabValue>('stake'); | ||
|
||
useEffect(() => { | ||
setShowChart(isBrowser()); | ||
}, []); | ||
|
||
const handleDurationChange = (value: string) => { | ||
const numValue = parseInt(value); | ||
if (!isNaN(numValue)) { | ||
setDuration(Math.min(Math.max(numValue, 1), 1440)); | ||
} | ||
}; | ||
|
||
const handleStakeChange = (value: string) => { | ||
const numValue = parseFloat(value); | ||
if (!isNaN(numValue)) { | ||
setStake(numValue); | ||
} | ||
}; | ||
|
||
const handleCheckboxChange = (e: React.ChangeEvent<HTMLInputElement> | React.KeyboardEvent<HTMLSpanElement>) => { | ||
if (e.target instanceof HTMLInputElement) { | ||
setAllowEquals(e.target.checked); | ||
} | ||
}; | ||
|
||
import { observer } from "mobx-react-lite"; | ||
export default observer(function DerivTrading() { | ||
return ( | ||
<div className="trading-container"> | ||
<Chart | ||
symbol={symbol} | ||
chartStatus={chartStatus} | ||
showChart={showChart} | ||
onChartStatusChange={setChartStatus} | ||
onSymbolChange={setSymbol} | ||
/> | ||
|
||
<TradingPanel | ||
duration={duration} | ||
stake={stake} | ||
allowEquals={allowEquals} | ||
selectedDurationTab={selectedDurationTab} | ||
selectedStakeTab={selectedStakeTab} | ||
onDurationChange={handleDurationChange} | ||
onStakeChange={handleStakeChange} | ||
onAllowEqualsChange={handleCheckboxChange} | ||
onDurationTabChange={setSelectedDurationTab} | ||
onStakeTabChange={setSelectedStakeTab} | ||
onDurationIncrement={() => setDuration(Math.min(1440, duration + 1))} | ||
onDurationDecrement={() => setDuration(Math.max(1, duration - 1))} | ||
onStakeIncrement={() => setStake(stake + 1)} | ||
onStakeDecrement={() => setStake(Math.max(0, stake - 1))} | ||
/> | ||
<Chart /> | ||
<TradingPanel /> | ||
</div> | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { makeAutoObservable } from "mobx"; | ||
|
||
export class ChartStore { | ||
symbol: string = ""; | ||
chartStatus: boolean = false; | ||
showChart: boolean = false; | ||
|
||
constructor() { | ||
makeAutoObservable(this); | ||
} | ||
|
||
setSymbol = (symbol: string) => { | ||
this.symbol = symbol; | ||
}; | ||
|
||
setChartStatus = (status: boolean) => { | ||
this.chartStatus = status; | ||
}; | ||
|
||
setShowChart = (show: boolean) => { | ||
this.showChart = show; | ||
}; | ||
} | ||
|
||
export const chartStore = new ChartStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { makeAutoObservable } from "mobx"; | ||
|
||
export class TradingPanelStore { | ||
duration = 1; | ||
price = "0"; | ||
allowEquals = false; | ||
selectedDurationTab: "duration" | "endtime" = "duration"; | ||
selectedStakeTab: "stake" | "payout" = "stake"; | ||
|
||
constructor() { | ||
makeAutoObservable(this); | ||
} | ||
|
||
setDuration = (value: string) => { | ||
const numValue = parseInt(value); | ||
if (!isNaN(numValue)) { | ||
this.duration = Math.min(Math.max(numValue, 1), 1440); | ||
} | ||
}; | ||
|
||
setPrice = (value: string) => { | ||
const numValue = parseFloat(value); | ||
if (!isNaN(numValue)) { | ||
this.price = numValue.toString(); | ||
} | ||
}; | ||
|
||
setAllowEquals = (value: boolean) => { | ||
this.allowEquals = value; | ||
}; | ||
|
||
setSelectedDurationTab = (value: "duration" | "endtime") => { | ||
this.selectedDurationTab = value; | ||
}; | ||
|
||
setSelectedStakeTab = (value: "stake" | "payout") => { | ||
this.selectedStakeTab = value; | ||
}; | ||
} | ||
|
||
export const tradingPanelStore = new TradingPanelStore(); |