-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thisyahlen/chore: update regulation edge cases if one of regulations …
…does not have an account (#13046) * chore: update regulation edge cases if one of regulations does not have an account * fix: demo real swither bug * chore: komen
- Loading branch information
1 parent
a2fecc3
commit 2380193
Showing
9 changed files
with
133 additions
and
58 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
27 changes: 21 additions & 6 deletions
27
packages/tradershub/src/components/CFDSection/CFDSection.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 |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import React from 'react'; | ||
import useRegulationFlags from '../../hooks/useRegulationFlags'; | ||
import { GetADerivAccountBanner } from '../GetADerivAccountBanner'; | ||
import { useUIContext } from '../UIProvider'; | ||
import { CFDContent } from './CFDContent'; | ||
import { CFDHeading } from './CFDHeading'; | ||
|
||
const CFDSection = () => ( | ||
<div className='overflow-y-scroll border-solid pt-800 lg:p-1200 rounded-1200 lg:border-xs lg:border-opacity-black-100'> | ||
<CFDHeading /> | ||
<CFDContent /> | ||
</div> | ||
); | ||
const CFDSection = () => { | ||
const { getUIState } = useUIContext(); | ||
const regulation = getUIState('regulation'); | ||
const accountType = getUIState('accountType'); | ||
const { isSuccess, noRealCRNonEUAccount, noRealMFEUAccount } = useRegulationFlags(regulation, accountType); | ||
|
||
return ( | ||
<div className='overflow-y-scroll border-solid pt-800 lg:p-1200 rounded-1200 lg:border-xs lg:border-opacity-black-100'> | ||
<CFDHeading /> | ||
{(noRealCRNonEUAccount || noRealMFEUAccount) && isSuccess && ( | ||
<div className='pt-1000'> | ||
<GetADerivAccountBanner /> | ||
</div> | ||
)} | ||
<CFDContent /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CFDSection; |
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
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 |
---|---|---|
@@ -1,37 +1,67 @@ | ||
import { useActiveTradingAccount, useIsEuRegion, useTradingAccountsList } from '@deriv/api'; | ||
import { useMemo } from 'react'; | ||
import { useActiveTradingAccount, useIsEuRegion, useLandingCompany, useTradingAccountsList } from '@deriv/api'; | ||
import { Regulation } from '../constants/constants'; | ||
|
||
/** | ||
* @description A custom hook that returns regulation flags based on the regulation passed in | ||
* @param regulation 'EU' | 'Non-EU' | ||
* @returns { isDemo: boolean, isEU: boolean, isEUReal: boolean, isNonEU: boolean, isNonEUReal: boolean } | ||
*/ | ||
const useRegulationFlags = (regulation?: string) => { | ||
const useRegulationFlags = (regulation?: string, accountType?: string) => { | ||
const { isEUCountry } = useIsEuRegion(); | ||
const { data: activeTradingAccount } = useActiveTradingAccount(); | ||
const { data: tradingAccountsList } = useTradingAccountsList(); | ||
|
||
const isEURegulation = regulation === Regulation.EU; | ||
const isNonEURegulation = regulation === Regulation.NonEU; | ||
|
||
const isEU = isEUCountry || isEURegulation; | ||
const isNonEU = !isEUCountry || isNonEURegulation; | ||
const isDemo = activeTradingAccount?.is_virtual ?? false; | ||
|
||
const isEUReal = isEU && !isDemo; | ||
const isNonEUReal = isNonEU && !isDemo; | ||
|
||
const noRealCRNonEU = isNonEU && !tradingAccountsList?.find(account => account.broker === 'CR'); | ||
const noRealMFEU = isEU && !tradingAccountsList?.find(account => account.broker === 'MF'); | ||
|
||
return { | ||
isEU, | ||
isEUReal, | ||
isNonEU, | ||
isNonEUReal, | ||
noRealCRNonEU, | ||
noRealMFEU, | ||
}; | ||
const { data: activeTradingAccount, isSuccess: activeTradingAccountSuccess } = useActiveTradingAccount(); | ||
const { data: tradingAccountsList, isSuccess: tradingAccountListSuccess } = useTradingAccountsList(); | ||
const { data: landingCompany, isSuccess: landingCompanySuccess } = useLandingCompany(); | ||
|
||
return useMemo(() => { | ||
const isHighRisk = | ||
landingCompany?.financial_company?.shortcode === 'svg' && | ||
landingCompany?.gaming_company?.shortcode === 'svg'; | ||
|
||
const isEURegulation = regulation === Regulation.EU; | ||
const isNonEURegulation = regulation === Regulation.NonEU; | ||
|
||
const isEU = isEUCountry || isEURegulation; | ||
const isNonEU = !isEUCountry || isNonEURegulation; | ||
|
||
const isRealAccount = !activeTradingAccount?.is_virtual || accountType === 'real'; | ||
|
||
const isEURealAccount = isEU && isRealAccount; | ||
const isNonEURealAccount = isNonEU && isRealAccount; | ||
|
||
const noRealCRNonEUAccount = | ||
isNonEU && !tradingAccountsList?.find(account => account.broker === 'CR') && isRealAccount; | ||
|
||
const noRealMFEUAccount = | ||
isEU && !tradingAccountsList?.find(account => account.broker === 'MF') && isRealAccount; | ||
|
||
const hasActiveDerivAccount = !(noRealCRNonEUAccount || noRealMFEUAccount); | ||
|
||
const isSuccess = activeTradingAccountSuccess && tradingAccountListSuccess && landingCompanySuccess; | ||
|
||
return { | ||
hasActiveDerivAccount, | ||
isEU, | ||
isEURealAccount, | ||
isHighRisk, | ||
isNonEU, | ||
isNonEURealAccount, | ||
isSuccess, | ||
noRealCRNonEUAccount, | ||
noRealMFEUAccount, | ||
}; | ||
}, [ | ||
landingCompany?.financial_company?.shortcode, | ||
landingCompany?.gaming_company?.shortcode, | ||
regulation, | ||
isEUCountry, | ||
activeTradingAccount?.is_virtual, | ||
accountType, | ||
tradingAccountsList, | ||
activeTradingAccountSuccess, | ||
tradingAccountListSuccess, | ||
landingCompanySuccess, | ||
]); | ||
}; | ||
|
||
export default useRegulationFlags; |
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
2380193
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 – ./
deriv-app.vercel.app
deriv-app.binary.sx
binary.sx
deriv-app-git-master.binary.sx