Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ameerul / P2PS-4363 Banner on Buy/Sell page #401

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
14 changes: 14 additions & 0 deletions src/hooks/api/account/__tests__/useActiveAccount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('useActiveAccount', () => {
created_at: 1718953961,
currency: 'USD',
currency_type: 'fiat',
hasMigratedToWallets: false,
is_disabled: 0,
is_virtual: 0,
landing_company_name: 'name',
Expand All @@ -139,11 +140,24 @@ describe('useActiveAccount', () => {
created_at: 1718953961,
currency: 'USD',
currency_type: 'fiat',
hasMigratedToWallets: false,
is_disabled: 0,
is_virtual: 0,
landing_company_name: 'name',
linked_to: [],
loginid: 'CR00001',
});
});

it('should return hasMigratedToWallets as true if the account is linked to dwallet', () => {
// @ts-expect-error mockAccountList is not typed with platform
mockAccountList[0].linked_to = [{ platform: 'dwallet' }];
mockUseAccountList.mockReturnValue({ data: mockAccountList });
mockUseAuthData.mockReturnValue({ activeLoginid: 'CR00001' });
mockUseBalance.mockReturnValue({ data: mockBalanceData });

const { result } = renderHook(() => useActiveAccount());

expect(result.current.data?.hasMigratedToWallets).toBe(true);
});
});
1 change: 1 addition & 0 deletions src/hooks/api/account/useActiveAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const useActiveAccount = () => {
? {
...activeAccount,
balance: balanceData?.accounts?.[activeAccount?.loginid]?.balance ?? 0,
hasMigratedToWallets: activeAccount?.linked_to.some(item => item.platform === 'dwallet'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be temporary until we get the flag from BE.

}
: undefined;
}, [activeAccount, balanceData]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jest.mock('@deriv-com/ui', () => ({
jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
api: {
account: {
useActiveAccount: jest.fn().mockReturnValue({ data: { hasMigratedToWallets: false } }),
},
settings: {
useGetSettings: () => ({
data: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jest.mock('@/components/Modals', () => ({
jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
api: {
account: {
useActiveAccount: jest.fn().mockReturnValue({ data: { hasMigratedToWallets: false } }),
},
advert: {
useGetList: jest.fn(() => mockAdvertiserListData),
},
Expand Down
5 changes: 4 additions & 1 deletion src/pages/guide/components/GuideTooltip/GuideTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import clsx from 'clsx';
import { useHistory } from 'react-router-dom';
import { OnboardingTooltip } from '@/components';
import { GUIDE_URL } from '@/constants';
import { api } from '@/hooks';
import { useIsAdvertiser } from '@/hooks/custom-hooks';
import { getCurrentRoute } from '@/utils';
import { LabelPairedBookCircleQuestionLgRegularIcon } from '@deriv/quill-icons';
Expand All @@ -13,12 +14,14 @@ const GuideTooltip = () => {
const history = useHistory();
const currentRoute = getCurrentRoute();
const isAdvertiser = useIsAdvertiser();
const { data: activeAccountData } = api.account.useActiveAccount();

return (
<OnboardingTooltip
buttonText={<Localize i18n_default_text='Get Started' />}
className={clsx('guide-tooltip__icon', {
'guide-tooltip__icon--is-buy-sell': currentRoute === 'buy-sell' && isAdvertiser,
'guide-tooltip__icon--is-buy-sell':
currentRoute === 'buy-sell' && isAdvertiser && activeAccountData?.hasMigratedToWallets,
'guide-tooltip__icon--not-advertiser': !isAdvertiser,
})}
description={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { render, screen } from '@testing-library/react';
import GuideTooltip from '../GuideTooltip';

jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
api: {
...jest.requireActual('@/hooks/api'),
account: {
...jest.requireActual('@/hooks/api/account'),
useActiveAccount: jest.fn().mockReturnValue({ data: { hasMigratedToWallets: false } }),
},
},
}));

jest.mock('@/hooks/custom-hooks', () => ({
...jest.requireActual('@/hooks/custom-hooks'),
useIsAdvertiser: jest.fn().mockReturnValue(true),
Expand Down
5 changes: 3 additions & 2 deletions src/routes/AppContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ const AppContent = () => {
(queryString.modal === 'RadioGroupFilterModal' ||
queryString.modal === 'FundsModal' ||
!queryString.modal)) ||
isDesktop)
isDesktop) &&
activeAccountData?.hasMigratedToWallets
) {
setShowFundsBanner(true);
} else {
setShowFundsBanner(false);
}
}, [isAdvertiser, isBuySellPage, isDesktop, location, queryString]);
}, [activeAccountData?.hasMigratedToWallets, isAdvertiser, isBuySellPage, isDesktop, location, queryString]);

const getComponent = () => {
if ((isP2PSettingsLoading || isLoadingActiveAccount || !isFetched || !activeAccountData) && !isEndpointRoute) {
Expand Down
Loading