This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:deriv-com/smarttrader into niloo/WE…
…BREL-1602/server-time
- Loading branch information
Showing
11 changed files
with
178 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useMemo } from 'react'; | ||
import useQuery from './useQuery'; | ||
import useLogin from './useLogin'; | ||
|
||
const useActiveSymbols = () => { | ||
const { isLoggedIn, isAuthorized } = useLogin(); | ||
const { data: activeSymbols, ...rest } = useQuery('active_symbols', { | ||
payload: { active_symbols: 'brief' }, | ||
options: { enabled: isLoggedIn ? isAuthorized : true }, | ||
}); | ||
|
||
const modifiedActiveSymbols = useMemo( | ||
() => ({ ...activeSymbols?.active_symbols }), | ||
[activeSymbols?.active_symbols] | ||
); | ||
|
||
return { | ||
data: modifiedActiveSymbols, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useActiveSymbols; |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useCallback, useEffect, useRef, useState } from 'react'; | ||
import useAPI from './useAPI'; | ||
import type { | ||
TSocketAcceptableProps, | ||
TSocketError, | ||
TSocketRequestPayload, | ||
TSocketResponseData, | ||
TSocketSubscribableEndpointNames, | ||
} from '../types'; | ||
|
||
const useSubscription = <T extends TSocketSubscribableEndpointNames>(name: T) => { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [isSubscribed, setIsSubscribed] = useState(false); | ||
const [error, setError] = useState<TSocketError<T>>(); | ||
const [data, setData] = useState<TSocketResponseData<T>>(); | ||
const subscriber = useRef<{ unsubscribe?: VoidFunction }>(); | ||
const { subscribe: _subscribe } = useAPI(); | ||
|
||
const subscribe = useCallback( | ||
(...props: TSocketAcceptableProps<T>) => { | ||
const prop = props?.[0]; | ||
const payload = prop && 'payload' in prop ? (prop.payload as TSocketRequestPayload<T>) : undefined; | ||
|
||
setIsLoading(true); | ||
setIsSubscribed(true); | ||
|
||
try { | ||
subscriber.current = _subscribe(name, payload).subscribe( | ||
async response => { | ||
setData(await response); | ||
setIsLoading(false); | ||
}, | ||
async response => { | ||
setError((await response).error as unknown as TSocketError<T>); | ||
setIsLoading(false); | ||
} | ||
); | ||
} catch (e) { | ||
setError(e as TSocketError<T>); | ||
} | ||
}, | ||
[_subscribe, name] | ||
); | ||
|
||
const unsubscribe = useCallback(() => { | ||
subscriber.current?.unsubscribe?.(); | ||
setIsSubscribed(false); | ||
}, []); | ||
|
||
useEffect(() => { | ||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, [unsubscribe]); | ||
|
||
return { | ||
subscribe, | ||
unsubscribe, | ||
isLoading, | ||
isSubscribed, | ||
error, | ||
data, | ||
}; | ||
}; | ||
|
||
export default useSubscription; |
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,37 @@ | ||
import { useCallback } from 'react'; | ||
import useSubscription from './useSubscription'; | ||
|
||
import { TSocketRequestPayload } from 'Api/types'; | ||
|
||
type TTicksHistoryPayload = TSocketRequestPayload<'ticks_history'>['payload']; | ||
|
||
const useTicksHistory = () => { | ||
const { subscribe: _subscribe, unsubscribe, data, ...rest } = useSubscription('ticks_history'); | ||
|
||
const subscribe = useCallback( | ||
(symbol: TTicksHistoryPayload['ticks_history'], granularity: TTicksHistoryPayload['granularity']) => { | ||
const style: TTicksHistoryPayload['style'] = granularity ? 'candles' : 'ticks'; | ||
|
||
return _subscribe({ | ||
payload: { | ||
adjust_start_time: 1, | ||
ticks_history: symbol, | ||
end: 'latest', | ||
count: 1000, | ||
granularity: granularity || undefined, | ||
style, | ||
}, | ||
}); | ||
}, | ||
[_subscribe] | ||
); | ||
|
||
return { | ||
subscribe, | ||
unsubscribe, | ||
data, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useTicksHistory; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Fragment, PropsWithChildren } from 'react'; | ||
import Header from './header'; | ||
import Footer from './footer'; | ||
|
||
const Layout = ({ children }: PropsWithChildren) => { | ||
return ( | ||
<Fragment> | ||
<Header /> | ||
{children} | ||
<Footer /> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
export default Layout; |
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 was deleted.
Oops, something went wrong.