-
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.
chore: add useTradingPlatformAccounts to deriv api package
- Loading branch information
1 parent
f6556e7
commit ef573b0
Showing
3 changed files
with
259 additions
and
0 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
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