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.
thisyahlen/feat: use account list (binary-com#9768)
* feat: added use-authorize hook taken from sergei pr Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * chore: sorted imports for use-authorize Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * chore: moved default empty string in use-authorize * chore: incorporated code reviews * chore: add useAccountsList to deriv/api * fix: address comments * fix: comments * fix: comments * fix: comments * fix: remove duplicated --------- Co-authored-by: adrienne-rio <adrienne@deriv.com> Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com>
- Loading branch information
1 parent
28c010e
commit b7ed164
Showing
4 changed files
with
44 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as useAuthorize } from './useAuthorize'; | ||
export { default as useAccountsList } from './useAccountsList'; |
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,40 @@ | ||
import { useMemo } from 'react'; | ||
import useAuthorize from './useAuthorize'; | ||
|
||
/** A custom hook that returns the list of accounts of the logged in user. */ | ||
const useAccountsList = () => { | ||
const { data: authorize_data, ...rest } = useAuthorize(); | ||
|
||
// Add additional information to the authorize response. | ||
const modified_accounts = useMemo(() => { | ||
return authorize_data.account_list?.map(account => { | ||
return { | ||
...account, | ||
/** Creation time of the account. */ | ||
created_at: account.created_at ? new Date(account.created_at) : undefined, | ||
/** Date till client has excluded him/herself from the website, only present if client is self excluded. */ | ||
excluded_until: account.excluded_until ? new Date(account.excluded_until) : undefined, | ||
/** Indicating whether the wallet is the currently active account. */ | ||
is_active: account.loginid === authorize_data.loginid, | ||
/** indicating whether the account is a virtual-money account. */ | ||
is_virtual: Boolean(account.is_virtual), | ||
/** indicating whether the account is marked as disabled or not. */ | ||
is_disabled: Boolean(account.is_disabled), | ||
/** indicating whether the account is a trading account. */ | ||
is_trading: account.account_category === 'trading', | ||
/** indicating whether the account is a wallet account. */ | ||
is_wallet: account.account_category === 'wallet', | ||
/** The account ID of specified account. */ | ||
loginid: `${account.loginid}`, | ||
} as const; | ||
}); | ||
}, [authorize_data.account_list, authorize_data.loginid]); | ||
|
||
return { | ||
/** The list of accounts. */ | ||
data: modified_accounts, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useAccountsList; |
2 changes: 1 addition & 1 deletion
2
packages/api/src/useAuthorize.ts → packages/api/src/hooks/useAuthorize.ts
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