Skip to content

Commit a61fd10

Browse files
authored
Merge pull request #162 from nada-deriv/nada/FEQ-2419/country-list
Nada/FEQ-2419/fix: removed usecountrylist hook
2 parents 8689ff3 + d97c431 commit a61fd10

File tree

9 files changed

+50
-69
lines changed

9 files changed

+50
-69
lines changed

src/components/CopyAdForm/CopyAdForm.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Controller, FormProvider, NonUndefined, useForm } from 'react-hook-form';
22
import { TCountryListItem, TCurrency, THooks } from 'types';
33
import { RATE_TYPE } from '@/constants';
4-
import { api, useFloatingRate } from '@/hooks';
4+
import { useFloatingRate } from '@/hooks';
55
import { AdFormInput } from '@/pages/my-ads/components/AdFormInput';
66
import { formatTime, getValidationRules, restrictDecimalPlace } from '@/utils';
7+
import { useP2PCountryList } from '@deriv-com/api-hooks';
78
import { Localize, useTranslations } from '@deriv-com/translations';
89
import { InlineMessage, Text, useDevice } from '@deriv-com/ui';
910
import { FloatingRate } from '../FloatingRate';
@@ -62,7 +63,9 @@ const CopyAdForm = ({ formValues, isModalOpen, onClickCancel, onFormSubmit, ...r
6263
mode: 'all',
6364
});
6465

65-
const { data: countryList = {} as TCountryListItem } = api.countryList.useGet();
66+
const { data: countryList = {} as TCountryListItem } = useP2PCountryList({
67+
refetchOnWindowFocus: false,
68+
});
6669
const {
6770
control,
6871
formState: { isValid },

src/components/CopyAdForm/__tests__/CopyAdForm.spec.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ jest.mock('@/hooks/custom-hooks', () => {
6161
};
6262
});
6363

64-
jest.mock('@/hooks', () => ({
65-
...jest.requireActual('@/hooks'),
66-
api: {
67-
countryList: {
68-
useGet: jest.fn(() => ({ data: mockCountryList })),
69-
},
70-
},
64+
jest.mock('@deriv-com/api-hooks', () => ({
65+
...jest.requireActual('@deriv-com/api-hooks'),
66+
useP2PCountryList: jest.fn(() => ({
67+
data: mockCountryList,
68+
})),
7169
}));
7270

7371
describe('CopyAdForm', () => {

src/hooks/api/country/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/hooks/api/country/p2p-country-list/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/hooks/api/country/p2p-country-list/useCountryList.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/hooks/api/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from './advert';
33
export * from './advertiser';
44
export * from './chat';
55
export * from './counterparty';
6-
export * from './country';
76
export * from './order';
87
export * from './order-dispute';
98
export * from './order-review';

src/pages/my-ads/screens/CreateEditAd/CreateEditAd.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AdCancelCreateEditModal, AdCreateEditErrorModal, AdCreateEditSuccessMod
66
import { MY_ADS_URL, RATE_TYPE } from '@/constants';
77
import { api } from '@/hooks';
88
import { useFloatingRate, useModalManager, useQueryString } from '@/hooks/custom-hooks';
9+
import { useP2PCountryList } from '@deriv-com/api-hooks';
910
import { Loader } from '@deriv-com/ui';
1011
import { LocalStorageConstants, LocalStorageUtils } from '@deriv-com/utils';
1112
import { AdWizard } from '../../components';
@@ -46,7 +47,9 @@ const CreateEditAd = () => {
4647
const { data: advertInfo, isLoading } = api.advert.useGet({ id: advertId ?? undefined }, !!advertId, false);
4748
const isEdit = !!advertId;
4849
const { hideModal, isModalOpenFor, showModal } = useModalManager({ shouldReinitializeModals: false });
49-
const { data: countryList = {} as TCountryListItem } = api.countryList.useGet();
50+
const { data: countryList = {} as TCountryListItem } = useP2PCountryList({
51+
refetchOnWindowFocus: false,
52+
});
5053
const { data: paymentMethodList = [] } = api.paymentMethods.useGet();
5154
const { floatRateOffsetLimitString, rateType } = useFloatingRate();
5255
const { data: activeAccount } = api.account.useActiveAccount();

src/pages/my-ads/screens/CreateEditAd/__tests__/CreateEditAd.spec.tsx

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,38 +82,6 @@ jest.mock('@/hooks', () => ({
8282
},
8383
})),
8484
},
85-
countryList: {
86-
useGet: () => ({
87-
data: {
88-
af: {
89-
country_name: 'Afghanistan',
90-
cross_border_ads_enabled: 1,
91-
fixed_rate_adverts: 'enabled',
92-
float_rate_adverts: 'disabled',
93-
float_rate_offset_limit: 10,
94-
local_currency: 'AFN',
95-
payment_methods: {
96-
alipay: {
97-
display_name: 'Alipay',
98-
fields: {
99-
account: {
100-
display_name: 'Alipay ID',
101-
required: 1,
102-
type: 'text',
103-
},
104-
instructions: {
105-
display_name: 'Instructions',
106-
required: 0,
107-
type: 'memo',
108-
},
109-
},
110-
type: 'ewallet',
111-
},
112-
},
113-
},
114-
},
115-
}),
116-
},
11785
paymentMethods: {
11886
useGet: () => ({
11987
data: [
@@ -184,6 +152,40 @@ jest.mock('@/hooks', () => ({
184152
},
185153
}));
186154

155+
jest.mock('@deriv-com/api-hooks', () => ({
156+
...jest.requireActual('@deriv-com/api-hooks'),
157+
useP2PCountryList: jest.fn(() => ({
158+
data: {
159+
af: {
160+
country_name: 'Afghanistan',
161+
cross_border_ads_enabled: 1,
162+
fixed_rate_adverts: 'enabled',
163+
float_rate_adverts: 'disabled',
164+
float_rate_offset_limit: 10,
165+
local_currency: 'AFN',
166+
payment_methods: {
167+
alipay: {
168+
display_name: 'Alipay',
169+
fields: {
170+
account: {
171+
display_name: 'Alipay ID',
172+
required: 1,
173+
type: 'text',
174+
},
175+
instructions: {
176+
display_name: 'Instructions',
177+
required: 0,
178+
type: 'memo',
179+
},
180+
},
181+
type: 'ewallet',
182+
},
183+
},
184+
},
185+
},
186+
})),
187+
}));
188+
187189
jest.mock('@/hooks/custom-hooks', () => {
188190
const modalManager = {
189191
hideModal: jest.fn(),

types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AD_CONDITION_TYPES, ERROR_CODES } from '@/constants';
44
import { api } from '@/hooks';
55
import { useSendbirdServiceToken } from '@/hooks/api/account';
66
import { useAdvertiserStats, useSendbird } from '@/hooks/custom-hooks';
7-
import { useExchangeRates } from '@deriv-com/api-hooks';
7+
import { useExchangeRates, useP2PCountryList } from '@deriv-com/api-hooks';
88
import { useTranslations } from '@deriv-com/translations';
99
import { Text } from '@deriv-com/ui';
1010
import { CurrencyConstants } from '@deriv-com/utils';
@@ -93,7 +93,7 @@ export namespace THooks {
9393
export type Get = NonNullable<ReturnType<typeof api.settings.useSettings>['data']>;
9494
}
9595
export namespace Country {
96-
export type Get = NonNullable<ReturnType<typeof api.countryList.useGet>['data']>;
96+
export type Get = NonNullable<ReturnType<typeof useP2PCountryList>['data']>;
9797
}
9898
}
9999
export type TOrders = NonNullable<ReturnType<typeof api.order.useGetList>['data']>;

0 commit comments

Comments
 (0)