Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/api-v2/src/hooks/useIsEuRegion.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useMemo } from 'react';

import useActiveWalletAccount from './useActiveWalletAccount';
import useLandingCompany from './useLandingCompany';

/** * A hook to determine if region is Eu using the useLandingCompany hook */
const useIsEuRegion = () => {
/** Retrieve landing company data*/
const { data: landing_company, ...rest } = useLandingCompany();
const { data: activeWallet } = useActiveWalletAccount();
const isMFAccount = activeWallet?.loginid?.startsWith('MF');

const isEuRegion = useMemo(() => {
if (!landing_company) return false;
if (!landing_company || !isMFAccount) return false;

/** Regular expressions for EU shortcodes and excluded residence */
const eu_shortcode_regex = /^maltainvest$/;
Expand All @@ -32,18 +36,18 @@ const useIsEuRegion = () => {
/** is region Eu based on residence */
const is_eu_based_on_residence = !shortcodes && is_residence_eu;

return is_financial_maltainvest || is_eu_based_on_shortcodes || is_eu_based_on_residence;
}, [landing_company]);
return isMFAccount && (is_financial_maltainvest || is_eu_based_on_shortcodes || is_eu_based_on_residence);
}, [isMFAccount, landing_company]);

// New method to test, if this works will remove the legacy method above
const isEUCountry = useMemo(() => {
if (!landing_company) return;
if (!landing_company || !isMFAccount) return;

const { gaming_company, financial_company } = landing_company;
const isEuRegion = !gaming_company && financial_company?.shortcode === 'maltainvest';
const isEuRegion = isMFAccount && !gaming_company && financial_company?.shortcode === 'maltainvest';

return isEuRegion;
}, [landing_company]);
}, [isMFAccount, landing_company]);

return {
/** A boolean flag indicating if the region is within the EU */
Expand Down
Loading