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.
Merge pull request #67 from shaheer-deriv/shaheer/WALL-1892
feat: 🪝 added hook for checking the presence of given status in mt5_login_list
- Loading branch information
Showing
6 changed files
with
76 additions
and
34 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
27 changes: 27 additions & 0 deletions
27
packages/hooks/src/__tests__/useIsMt5LoginListStatusPresent.spec.tsx
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,27 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import useIsMt5LoginListStatusPresent from '../useIsMt5LoginListStatusPresent'; | ||
|
||
const mock_login_id = 'MOCK_LOGIN_ID'; | ||
jest.mock('@deriv/api', () => ({ | ||
...jest.requireActual('@deriv/api'), | ||
useMT5AccountsList: jest.fn(() => ({ | ||
data: [{ login: mock_login_id, landing_company_short: 'MOCK_LANDING_COMPANY_SHORT_CODE' }], | ||
})), | ||
})); | ||
|
||
describe('useIsMt5LoginListStatusPresent', () => { | ||
it('should return true when the given status is present for the given login id', () => { | ||
const { result } = renderHook(() => useIsMt5LoginListStatusPresent('landing_company_short', mock_login_id)); | ||
expect(result.current).toBeTruthy(); | ||
}); | ||
|
||
it('should return false when the given status is not present for the given login id', () => { | ||
const { result } = renderHook(() => useIsMt5LoginListStatusPresent('balance', mock_login_id)); | ||
expect(result.current).toBeFalsy(); | ||
}); | ||
|
||
it('should return false when the given login id is empty', () => { | ||
const { result } = renderHook(() => useIsMt5LoginListStatusPresent('account_type', '')); | ||
expect(result.current).toBeFalsy(); | ||
}); | ||
}); |
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,21 @@ | ||
import React from 'react'; | ||
import { useMT5AccountsList } from '@deriv/api'; | ||
import { useStore } from '@deriv/stores'; | ||
|
||
// TODO: Remove this todo once 'open_order_position_status' flag is available in BE response and in type TSocketResponseData<"mt5_login_list"> | ||
type DetailsOfEachMT5LoginId = ReturnType<typeof useStore>['client']['mt5_login_list'][number]; | ||
type TStatus = keyof DetailsOfEachMT5LoginId; | ||
|
||
/** | ||
* A custom hook to check if the given status flag is present in the mt5_login_list of given account login id | ||
*/ | ||
const useIsMt5LoginListStatusPresent = (status: TStatus, account_login_id: string) => { | ||
const { data: mt5_login_list } = useMT5AccountsList(); | ||
|
||
return React.useMemo( | ||
() => !!mt5_login_list?.find(account => account?.login === account_login_id)?.[status], | ||
[account_login_id, mt5_login_list, status] | ||
); | ||
}; | ||
|
||
export default useIsMt5LoginListStatusPresent; |