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.
hamid/WALL-250/withdraw-hooks-refactor (binary-com#8776)
* feat: add useaccountplatformdetails hook * feat: add useneedpoi hook * fix: fix failed test --------- Co-authored-by: Bahar <bahar@regentmarkets.com>
- Loading branch information
1 parent
711d3e0
commit 8623b8a
Showing
9 changed files
with
114 additions
and
16 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
35 changes: 35 additions & 0 deletions
35
packages/hooks/src/__tests__/useCurrentAccountDetails.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,35 @@ | ||
import * as React from 'react'; | ||
import { StoreProvider, mockStore } from '@deriv/stores'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import useCurrentAccountDetails from '../useCurrentAccountDetails'; | ||
|
||
describe('useCurrentAccountDetails', () => { | ||
test('should return the account info of the current loginid', async () => { | ||
const mockRootStore = mockStore({ | ||
client: { | ||
account_list: [ | ||
{ | ||
account: { | ||
balance: 10000, | ||
currency: 'USD', | ||
disabled: false, | ||
is_crypto: false, | ||
}, | ||
icon: 'icon', | ||
is_dark_mode_on: false, | ||
loginid: 'loginid', | ||
title: 'title', | ||
}, | ||
], | ||
loginid: 'loginid', | ||
}, | ||
}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mockRootStore}>{children}</StoreProvider> | ||
); | ||
const { result } = renderHook(() => useCurrentAccountDetails(), { wrapper }); | ||
|
||
expect(result.current).toStrictEqual(mockRootStore.client.account_list[0]); | ||
}); | ||
}); |
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,44 @@ | ||
import * as React from 'react'; | ||
import { StoreProvider, mockStore } from '@deriv/stores'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import useNeedPOI from '../useNeedPOI'; | ||
|
||
describe('useNeedPOI', () => { | ||
test('should be true if authentication?.needs_verification includes identity', async () => { | ||
const mockRootStore = mockStore({ | ||
client: { | ||
account_status: { | ||
authentication: { | ||
needs_verification: ['identity'], | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mockRootStore}>{children}</StoreProvider> | ||
); | ||
const { result } = renderHook(() => useNeedPOI(), { wrapper }); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
|
||
test("should be false if authentication?.needs_verification doesn't include identity", async () => { | ||
const mockRootStore = mockStore({ | ||
client: { | ||
account_status: { | ||
authentication: { | ||
needs_verification: [], | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mockRootStore}>{children}</StoreProvider> | ||
); | ||
const { result } = renderHook(() => useNeedPOI(), { wrapper }); | ||
|
||
expect(result.current).toBe(false); | ||
}); | ||
}); |
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,10 @@ | ||
import { useStore } from '@deriv/stores'; | ||
|
||
const useCurrentAccountDetails = () => { | ||
const { client } = useStore(); | ||
const { account_list, loginid } = client; | ||
|
||
return account_list.find(account => loginid === account.loginid); | ||
}; | ||
|
||
export default useCurrentAccountDetails; |
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,10 @@ | ||
import { useStore } from '@deriv/stores'; | ||
|
||
const useNeedPOI = () => { | ||
const { client } = useStore(); | ||
const authentication = client.account_status?.authentication; | ||
|
||
return authentication?.needs_verification.includes('identity'); | ||
}; | ||
|
||
export default useNeedPOI; |