forked from deriv-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.
[DTRA]feat: added growthbook feature flag for dtrader-v2 (deriv-com#1…
…7160) * feat: added growthbook feature flag for dtrader-v2 * feat: enable dtrader v2 when feature flag is enabled * feat: dtrader-v2 added behind feature flag * fix: implement contract header inside dtrader v2 * fix: fixed failing test cases in contract-details * refactor: centeralised the logic for dtrader v2 in one place * fix: failing test case * fix: addressed review comments and removed loader from app.jsx * refactor: refactor dtrader-v2 hook * refactor: small change in useDtraderV2 flag
- Loading branch information
1 parent
595fdb0
commit 97d01e2
Showing
23 changed files
with
185 additions
and
91 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
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,54 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useDtraderV2Flag } from '..'; | ||
import useIsGrowthbookIsLoaded from '../useIsGrowthbookLoaded'; | ||
import { useDevice } from '@deriv-com/ui'; | ||
import { Analytics } from '@deriv-com/analytics'; | ||
|
||
jest.mock('@deriv-com/analytics', () => ({ | ||
Analytics: { | ||
getFeatureValue: jest.fn().mockReturnValue(true), | ||
}, | ||
})); | ||
|
||
jest.mock('@deriv-com/ui', () => ({ | ||
useDevice: jest.fn(() => ({ isMobile: true })), | ||
})); | ||
|
||
jest.mock('../useIsGrowthbookLoaded'); | ||
|
||
describe('useDtraderV2Flag', () => { | ||
const originalLocation = window.location; | ||
beforeAll(() => { | ||
const mockLocation = { | ||
...originalLocation, | ||
pathname: '/dtrader', | ||
}; | ||
|
||
Object.defineProperty(window, 'location', { | ||
value: mockLocation, | ||
writable: true, | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
Object.defineProperty(window, 'location', { | ||
value: originalLocation, | ||
writable: true, | ||
}); | ||
}); | ||
|
||
it('should initially set load_dtrader_module and dtrader_v2_enabled to false', () => { | ||
(useIsGrowthbookIsLoaded as jest.Mock).mockReturnValue({ isGBLoaded: false, isGBAvailable: true }); | ||
const { result } = renderHook(() => useDtraderV2Flag()); | ||
expect(result.current.load_dtrader_module).toBe(false); | ||
expect(result.current.dtrader_v2_enabled).toBe(false); | ||
}); | ||
|
||
it('should set load_dtrader_module and dtrader_v2_enabled to true when dtrader is enabled', () => { | ||
(useIsGrowthbookIsLoaded as jest.Mock).mockReturnValue({ isGBLoaded: true, isGBAvailable: true }); | ||
(useDevice as jest.Mock).mockReturnValueOnce({ isMobile: true }); | ||
(Analytics.getFeatureValue as jest.Mock).mockReturnValue(true); | ||
const { result } = renderHook(() => useDtraderV2Flag()); | ||
expect(result.current.dtrader_v2_enabled).toBe(true); | ||
}); | ||
}); |
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,28 @@ | ||
import { useState, useEffect } from 'react'; | ||
import useIsGrowthbookIsLoaded from './useIsGrowthbookLoaded'; | ||
import { isDTraderV2, routes } from '@deriv/shared'; | ||
import { useDevice } from '@deriv-com/ui'; | ||
import { Analytics } from '@deriv-com/analytics'; | ||
|
||
const useDtraderV2Flag = () => { | ||
const { isGBLoaded: is_growthbook_loaded, isGBAvailable: is_gb_available } = useIsGrowthbookIsLoaded(); | ||
const load_dtrader_module = is_growthbook_loaded || !is_gb_available; | ||
|
||
const is_dtrader_v2 = isDTraderV2(); | ||
const { isMobile: is_mobile } = useDevice(); | ||
const is_feature_flag_active = Boolean(Analytics?.getFeatureValue('dtrader_v2_enabled', false)); | ||
const is_trade_or_contract_path = | ||
location.pathname.startsWith(routes.trade) || location.pathname.startsWith('/contract/'); | ||
|
||
const [dtrader_v2_enabled, setDTraderV2Enabled] = useState(false); | ||
useEffect(() => { | ||
if (is_growthbook_loaded || isDTraderV2()) { | ||
setDTraderV2Enabled((is_dtrader_v2 || is_feature_flag_active) && is_mobile && is_trade_or_contract_path); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [is_mobile, is_growthbook_loaded]); | ||
|
||
return { dtrader_v2_enabled, load_dtrader_module }; | ||
}; | ||
|
||
export default useDtraderV2Flag; |
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
Oops, something went wrong.