1 import { useCallback } from 'react';
3 import useSettingsLink from '@proton/components/components/link/useSettingsLink';
4 import { type Currency } from '@proton/payments';
5 import { getAppHref } from '@proton/shared/lib/apps/helper';
6 import { APPS } from '@proton/shared/lib/constants';
7 import { isElectronApp } from '@proton/shared/lib/helpers/desktop';
9 import { openLinkInBrowser } from '../../desktop/openExternalLink';
10 import { useHasInboxDesktopInAppPayments } from '../../desktop/useHasInboxDesktopInAppPayments';
11 import getOfferRedirectionParams from '../helpers/getOfferRedirectionParams';
12 import type { Deal, Offer } from '../interface';
14 const useSelectDeal = (callback?: () => void) => {
15 const goToSettingsLink = useSettingsLink();
16 const hasInboxDesktopInAppPayments = useHasInboxDesktopInAppPayments();
18 const handleOnSelectDeal = useCallback(
19 (offer: Offer, deal: Deal, currency: Currency) => {
20 const urlSearchParams = getOfferRedirectionParams({ offer, deal, currency });
23 const url = `/dashboard?${urlSearchParams.toString()}`;
24 if (isElectronApp && !hasInboxDesktopInAppPayments) {
25 openLinkInBrowser(getAppHref(url, APPS.PROTONACCOUNT));
28 goToSettingsLink(url);
34 return handleOnSelectDeal;
37 export default useSelectDeal;