-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thisyahlen/chore: add useTradingPlatformAccounts to deriv api package (…
- Loading branch information
1 parent
89b151f
commit 4a9119a
Showing
3 changed files
with
260 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
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,48 @@ | ||
import { useMemo } from 'react'; | ||
import useFetch from '../useFetch'; | ||
|
||
/** A custom hook that gets the list of created other CFD accounts. */ | ||
const useTradingPlatformAccounts = () => { | ||
const { data: derivez_accounts, ...derivez_rest } = useFetch('trading_platform_accounts', { | ||
payload: { platform: 'derivez' }, | ||
}); | ||
const { data: dxtrade_accounts, ...dxtrade_rest } = useFetch('trading_platform_accounts', { | ||
payload: { platform: 'dxtrade' }, | ||
}); | ||
|
||
/** Adding neccesary properties to derivez accounts */ | ||
const modified_derivez_accounts = useMemo( | ||
() => | ||
derivez_accounts?.trading_platform_accounts?.map(account => ({ | ||
...account, | ||
loginid: account.login, | ||
})), | ||
[derivez_accounts?.trading_platform_accounts] | ||
); | ||
|
||
/** Adding neccesary properties to dxtrade accounts */ | ||
const modified_dxtrade_accounts = useMemo( | ||
() => | ||
dxtrade_accounts?.trading_platform_accounts?.map(account => ({ | ||
...account, | ||
loginid: account.account_id, | ||
})), | ||
[dxtrade_accounts?.trading_platform_accounts] | ||
); | ||
|
||
const data = useMemo( | ||
() => ({ | ||
dxtrade_accounts: modified_dxtrade_accounts || [], | ||
derivez_accounts: modified_derivez_accounts || [], | ||
}), | ||
[modified_dxtrade_accounts, modified_derivez_accounts] | ||
); | ||
|
||
return { | ||
/** List of all created other CFD accounts */ | ||
data, | ||
...{ ...derivez_rest, ...dxtrade_rest }, | ||
}; | ||
}; | ||
|
||
export default useTradingPlatformAccounts; |
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
4a9119a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
deriv-app – ./
binary.sx
deriv-app-git-master.binary.sx
deriv-app.binary.sx
deriv-app.vercel.app