forked from binary-com/deriv-app
-
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.
Adrienne / integrated useSubscription hook for website status (binary…
…-com#8702) * Create codeql.yml * Create codeql-test.yml * chore: removed codeql workflows * chore: removed dccache * chore: added escapeHtml function to login * refactor: added website status store * chore: removed old changes * chore: added checks for loginid * chore: fixed an issue where website status is not subscribed properly and not after authorize * chore: removed observer * chore: removed duplicate if statement * chore: added dependencies * chore: moved unsubscribe outside * refactor: use without websocket hooks * chore: updated comments * chore: removed prettier changes * chore: fixed wrong type * chore: fixed wrong type * chore: incorporated code reviews * chore: undo prettier formatting * chore: undo prettier formatting * chore: removed comments * fix: fixed some issues with testing website-status store --------- Co-authored-by: Jim Daniels Wasswa <104334373+jim-deriv@users.noreply.github.com> Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>
- Loading branch information
1 parent
ba08c0f
commit 4f7c079
Showing
9 changed files
with
62 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useSubscription } from '@deriv/api'; | ||
import { observer } from 'mobx-react-lite'; | ||
import useStore from '../useStore'; | ||
import merge from 'lodash.merge'; | ||
|
||
const WebsiteStatusProvider = observer(({ children }: React.PropsWithChildren<unknown>) => { | ||
const { data, subscribe, unsubscribe } = useSubscription('website_status'); | ||
const { | ||
client: { is_authorize }, | ||
website_status: { update }, | ||
} = useStore(); | ||
|
||
useEffect(() => { | ||
if (data) { | ||
const { website_status } = data; | ||
if (website_status) update(prev => merge(prev, website_status)); | ||
} | ||
}, [update, data]); | ||
|
||
useEffect(() => { | ||
if (is_authorize) unsubscribe() | ||
subscribe() | ||
}, [is_authorize, subscribe, unsubscribe]); | ||
|
||
return <>{children}</>; | ||
}); | ||
|
||
export default WebsiteStatusProvider; |
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 +1,2 @@ | ||
export { default as ExchangeRatesProvider } from './ExchangeRatesProvider'; | ||
export { default as WebsiteStatusProvider } from './WebsiteStatusProvider'; |
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,8 @@ | ||
import type { ServerStatusResponse } from '@deriv/api-types'; | ||
import BaseStore from './BaseStore'; | ||
|
||
export default class WebsiteStatusStore extends BaseStore<ServerStatusResponse['website_status']> { | ||
constructor() { | ||
super('WebsiteStatusStore'); | ||
} | ||
} |
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,2 +1,3 @@ | ||
export { default as ExchangeRatesStore } from './ExchangeRatesStore'; | ||
export { default as FeatureFlagsStore } from './FeatureFlagsStore'; | ||
export { default as WebsiteStatusStore } from './WebsiteStatusStore'; |
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