From 4f6c676ee8e883a9d6cd4d0c4e93e21e97129a50 Mon Sep 17 00:00:00 2001 From: Nada Date: Fri, 26 Apr 2024 15:17:24 +0400 Subject: [PATCH] fix: rest of the errors fixed --- .../AdvertsTableRow/AdvertsTableRow.tsx | 6 ++--- src/components/BuySellForm/BuySellForm.tsx | 26 +++++++++---------- .../PaymentMethodCard/PaymentMethodCard.tsx | 4 +-- .../PaymentMethodCardBody.tsx | 10 ++++--- .../__tests__/PaymentMethodCard.spec.tsx | 1 + .../PaymentMethodFormAutocomplete.tsx | 11 ++++++-- .../p2p-advertiser/useAdvertiserList.ts | 3 ++- src/hooks/custom-hooks/useSendbird.ts | 2 +- .../components/SortDropdown/SortDropdown.tsx | 2 +- .../AdPaymentDetailsSection.spec.tsx | 4 +-- .../AdTypeSection/AdTypeSection.tsx | 4 +-- .../__tests__/AdTypeSection.spec.tsx | 5 ++-- .../AdWizard/__tests__/AdWizard.spec.tsx | 7 +++-- .../BuyPaymentMethodsList.tsx | 2 +- .../SellAdPaymentSelection.tsx | 4 +-- .../screens/CreateEditAd/CreateEditAd.tsx | 9 ++++--- .../screens/MyAds/MyAdsTable/MyAdsTable.tsx | 3 ++- .../screens/PaymentMethods/PaymentMethods.tsx | 3 ++- .../PaymentMethodsList/PaymentMethodsList.tsx | 2 +- .../PaymentMethodsListContent.tsx | 10 +++---- .../PaymentMethodsListContent.spec.tsx | 4 +-- .../__tests__/OrdersTable.spec.tsx | 25 +++++++++--------- .../__tests__/OrderTableRow.spec.tsx | 12 ++++----- types.ts | 16 +++++++++--- 24 files changed, 101 insertions(+), 74 deletions(-) diff --git a/src/components/AdvertsTableRow/AdvertsTableRow.tsx b/src/components/AdvertsTableRow/AdvertsTableRow.tsx index c7f5d1f5..bbd247ac 100644 --- a/src/components/AdvertsTableRow/AdvertsTableRow.tsx +++ b/src/components/AdvertsTableRow/AdvertsTableRow.tsx @@ -1,7 +1,7 @@ import { Fragment, memo, useEffect, useRef, useState } from 'react'; import clsx from 'clsx'; import { useHistory } from 'react-router-dom'; -import { TAdvertsTableRowRenderer, TCurrency, TExchangeRate } from 'types'; +import { TAdvertiserPaymentMethod, TAdvertsTableRowRenderer, TCurrency, TExchangeRate, TPaymentMethod } from 'types'; import { Badge, BuySellForm, PaymentMethodLabel, StarRating, UserAvatar } from '@/components'; import { ADVERTISER_URL, BUY_SELL } from '@/constants'; import { api } from '@/hooks'; @@ -180,14 +180,14 @@ const AdvertsTableRow = memo((props: TAdvertsTableRowRenderer) => { setIsModalOpen(false)} - paymentMethods={paymentMethods} + paymentMethods={paymentMethods as TPaymentMethod[]} /> )} diff --git a/src/components/BuySellForm/BuySellForm.tsx b/src/components/BuySellForm/BuySellForm.tsx index 0e4b2bde..bc7068d3 100644 --- a/src/components/BuySellForm/BuySellForm.tsx +++ b/src/components/BuySellForm/BuySellForm.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'; import { Control, Controller, FieldValues, useForm } from 'react-hook-form'; import { useHistory } from 'react-router-dom'; -import { TAdvertType, TCurrency, THooks } from 'types'; +import { TAdvertType, TCurrency, THooks, TPaymentMethod } from 'types'; import { BUY_SELL, ORDERS_URL, RATE_TYPE, VALID_SYMBOLS_PATTERN } from '@/constants'; import { api } from '@/hooks'; import { @@ -98,7 +98,7 @@ const BuySellForm = ({ const shouldDisableField = !isBuy && (parseFloat(balanceAvailable.toString()) === 0 || - parseFloat(balanceAvailable.toString()) < min_order_amount_limit); + parseFloat(balanceAvailable.toString()) < (min_order_amount_limit ?? 1)); const { control, @@ -118,7 +118,7 @@ const BuySellForm = ({ //TODO: error handling after implementation of exchange rate const rateValue = rate_type === RATE_TYPE.FIXED ? null : effectiveRate; const payload: TPayload = { - advert_id: id, + advert_id: id as string, amount: Number(getValues('amount')), }; if (rateValue) { @@ -138,7 +138,7 @@ const BuySellForm = ({ }; const calculatedRate = removeTrailingZeros(roundOffDecimal(effectiveRate, setDecimalPlaces(effectiveRate, 6))); - const initialAmount = removeTrailingZeros((min_order_amount_limit * Number(calculatedRate)).toString()); + const initialAmount = removeTrailingZeros((min_order_amount_limit ?? 1 * Number(calculatedRate)).toString()); const onSelectPaymentMethodCard = (paymentMethodId: number) => { if (selectedPaymentMethods.includes(paymentMethodId)) { @@ -158,7 +158,7 @@ const BuySellForm = ({ return (
)} - {isBuy && payment_method_names?.length > 0 && ( + {isBuy && payment_method_names && payment_method_names?.length > 0 && ( )} } @@ -206,9 +206,9 @@ const BuySellForm = ({ isBuy, advertiserBuyLimit, advertiserSellLimit, - max_order_amount_limit_display + max_order_amount_limit_display ?? '0' )} - minLimit={min_order_amount_limit_display} + minLimit={min_order_amount_limit_display ?? '0'} /> {isBuy && !payment_method_names?.length && ( & { onDeletePaymentMethod?: () => void; onEditPaymentMethod?: () => void; onSelectPaymentMethodCard?: (paymentMethodId: number) => void; - paymentMethod: TPaymentMethod & { isAvailable?: boolean }; + paymentMethod: (TAdvertiserPaymentMethod | TPaymentMethod) & { isAvailable?: boolean }; selectedPaymentMethodIds?: number[]; shouldShowPaymentMethodDisplayName?: boolean; }; diff --git a/src/components/PaymentMethodCard/PaymentMethodCardBody/PaymentMethodCardBody.tsx b/src/components/PaymentMethodCard/PaymentMethodCardBody/PaymentMethodCardBody.tsx index 6bf93f2d..014632b4 100644 --- a/src/components/PaymentMethodCard/PaymentMethodCardBody/PaymentMethodCardBody.tsx +++ b/src/components/PaymentMethodCard/PaymentMethodCardBody/PaymentMethodCardBody.tsx @@ -1,9 +1,9 @@ -import { THooks } from 'types'; +import { TAccount, TBankName, THooks, TName } from 'types'; import { Text } from '@deriv-com/ui'; import './PaymentMethodCardBody.scss'; type TPaymentMethodCardBodyProps = { - paymentMethod: THooks.AdvertiserPaymentMethods.Get[number]; + paymentMethod: THooks.AdvertiserPaymentMethods.Get[number] | THooks.PaymentMethods.Get[number]; shouldShowPaymentMethodDisplayName?: boolean; }; @@ -17,8 +17,10 @@ const PaymentMethodCardBody = ({ return (
{isBankOrOther && !shouldShowPaymentMethodDisplayName ? null : {displayName}} - {paymentMethod.fields?.bank_name?.value ?? paymentMethod.fields?.name?.value} - {paymentMethod.fields?.account?.value} + + {(paymentMethod.fields?.bank_name as TBankName)?.value ?? (paymentMethod.fields?.name as TName)?.value} + + {(paymentMethod.fields?.account as TAccount)?.value}
); }; diff --git a/src/components/PaymentMethodCard/__tests__/PaymentMethodCard.spec.tsx b/src/components/PaymentMethodCard/__tests__/PaymentMethodCard.spec.tsx index 03056037..95988768 100644 --- a/src/components/PaymentMethodCard/__tests__/PaymentMethodCard.spec.tsx +++ b/src/components/PaymentMethodCard/__tests__/PaymentMethodCard.spec.tsx @@ -11,6 +11,7 @@ const mockProps = { onEditPaymentMethod: jest.fn(), onSelectPaymentMethodCard: jest.fn(), paymentMethod: { + display_name: 'bank', fields: {}, id: 'test', is_enabled: 0 as 0 | 1, diff --git a/src/components/PaymentMethodForm/PaymentMethodFormAutocomplete/PaymentMethodFormAutocomplete.tsx b/src/components/PaymentMethodForm/PaymentMethodFormAutocomplete/PaymentMethodFormAutocomplete.tsx index 1f0d4993..239b7143 100644 --- a/src/components/PaymentMethodForm/PaymentMethodFormAutocomplete/PaymentMethodFormAutocomplete.tsx +++ b/src/components/PaymentMethodForm/PaymentMethodFormAutocomplete/PaymentMethodFormAutocomplete.tsx @@ -1,4 +1,4 @@ -import { TFormState, THooks, TSelectedPaymentMethod } from 'types'; +import { TFormState, THooks, TPaymentMethod, TSelectedPaymentMethod } from 'types'; import { Dropdown } from '@/components'; import { Button, Input, Text } from '@deriv-com/ui'; import CloseCircle from '../../../public/ic-close-circle.svg?react'; @@ -45,6 +45,13 @@ const PaymentMethodFormAutocomplete = ({ /> ); } + + const getValue = () => { + if (selectedPaymentMethod) { + return (selectedPaymentMethod as TPaymentMethod)?.display_name; + } + return ''; + }; return ( <>
diff --git a/src/hooks/api/advertiser/p2p-advertiser/useAdvertiserList.ts b/src/hooks/api/advertiser/p2p-advertiser/useAdvertiserList.ts index 8a081543..cfbca857 100644 --- a/src/hooks/api/advertiser/p2p-advertiser/useAdvertiserList.ts +++ b/src/hooks/api/advertiser/p2p-advertiser/useAdvertiserList.ts @@ -5,8 +5,9 @@ type THookPayload = Parameters[number]; //TODO: fix the types when updated from api-hooks type ExtendedPayload = THookPayload & { - is_blocked?: boolean; + is_blocked?: number; advertiser_name?: string; + trade_partners: number; }; /** * This custom hook returns the available advertisers who have had or currently have trades with the current advertiser. diff --git a/src/hooks/custom-hooks/useSendbird.ts b/src/hooks/custom-hooks/useSendbird.ts index b0e654dd..fd2b8ea3 100644 --- a/src/hooks/custom-hooks/useSendbird.ts +++ b/src/hooks/custom-hooks/useSendbird.ts @@ -119,7 +119,7 @@ const useSendbird = (orderId: string) => { sendbirdApiRef.current.groupChannel.addGroupChannelHandler( 'P2P_SENDBIRD_GROUP_CHANNEL_HANDLER', new GroupChannelHandler({ - onMessageReceived: (messageReceivedChannel: BaseChannel, _receivedMessage: BaseMessage) => + onMessageReceived: (_messageReceivedChannel: BaseChannel, _receivedMessage: BaseMessage) => setReceivedMessage(_receivedMessage), }) ); diff --git a/src/pages/buy-sell/components/SortDropdown/SortDropdown.tsx b/src/pages/buy-sell/components/SortDropdown/SortDropdown.tsx index e209bb56..28455911 100644 --- a/src/pages/buy-sell/components/SortDropdown/SortDropdown.tsx +++ b/src/pages/buy-sell/components/SortDropdown/SortDropdown.tsx @@ -34,7 +34,7 @@ const SortDropdown = ({ list, onSelect, setIsFilterModalOpen, value }: TSortDrop label='Sort by' list={list as unknown as MutableOption[]} name='Sort by' - onSelect={(value: string) => onSelect(value as TSortByValues)} + onSelect={value => onSelect(value as TSortByValues)} value={value} />
diff --git a/src/pages/my-ads/components/AdPaymentDetailsSection/__tests__/AdPaymentDetailsSection.spec.tsx b/src/pages/my-ads/components/AdPaymentDetailsSection/__tests__/AdPaymentDetailsSection.spec.tsx index 3d62f923..8eadd455 100644 --- a/src/pages/my-ads/components/AdPaymentDetailsSection/__tests__/AdPaymentDetailsSection.spec.tsx +++ b/src/pages/my-ads/components/AdPaymentDetailsSection/__tests__/AdPaymentDetailsSection.spec.tsx @@ -68,8 +68,8 @@ jest.mock('../../OrderTimeSelection', () => ({ })); const mockProps = { currency: 'USD' as TCurrency, - getCurrentStep: () => jest.fn(), - getTotalSteps: () => jest.fn(), + getCurrentStep: jest.fn(() => 1), + getTotalSteps: jest.fn(() => 4), goToNextStep: jest.fn(), goToPreviousStep: jest.fn(), localCurrency: 'IDR' as TCurrency, diff --git a/src/pages/my-ads/components/AdTypeSection/AdTypeSection.tsx b/src/pages/my-ads/components/AdTypeSection/AdTypeSection.tsx index 1bc3ed7b..f6af0f6b 100644 --- a/src/pages/my-ads/components/AdTypeSection/AdTypeSection.tsx +++ b/src/pages/my-ads/components/AdTypeSection/AdTypeSection.tsx @@ -12,12 +12,12 @@ import { AdFormTextArea } from '../AdFormTextArea'; import './AdTypeSection.scss'; type TAdTypeSectionProps = { - currency: string; + currency: TCurrency; getCurrentStep: () => number; getTotalSteps: () => number; goToNextStep: MouseEventHandler; goToPreviousStep: () => void; - localCurrency?: string; + localCurrency?: TCurrency; onCancel: () => void; rateType: string; }; diff --git a/src/pages/my-ads/components/AdTypeSection/__tests__/AdTypeSection.spec.tsx b/src/pages/my-ads/components/AdTypeSection/__tests__/AdTypeSection.spec.tsx index 4082f728..df48ab8b 100644 --- a/src/pages/my-ads/components/AdTypeSection/__tests__/AdTypeSection.spec.tsx +++ b/src/pages/my-ads/components/AdTypeSection/__tests__/AdTypeSection.spec.tsx @@ -1,3 +1,4 @@ +import { TCurrency } from 'types'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import AdTypeSection from '../AdTypeSection'; @@ -50,12 +51,12 @@ jest.mock('@/hooks', () => ({ })); const mockProps = { - currency: 'usd', + currency: 'usd' as TCurrency, getCurrentStep: jest.fn(() => 1), getTotalSteps: jest.fn(), goToNextStep: jest.fn(), goToPreviousStep: jest.fn(), - localCurrency: 'usd', + localCurrency: 'usd' as TCurrency, onCancel: jest.fn(), rateType: 'float', }; diff --git a/src/pages/my-ads/components/AdWizard/__tests__/AdWizard.spec.tsx b/src/pages/my-ads/components/AdWizard/__tests__/AdWizard.spec.tsx index 434d92df..17d891c5 100644 --- a/src/pages/my-ads/components/AdWizard/__tests__/AdWizard.spec.tsx +++ b/src/pages/my-ads/components/AdWizard/__tests__/AdWizard.spec.tsx @@ -1,3 +1,4 @@ +import { TCurrency } from 'types'; import { useDevice } from '@deriv-com/ui'; import { render, screen } from '@testing-library/react'; import AdWizard from '../AdWizard'; @@ -25,10 +26,12 @@ jest.mock('../../AdProgressBar', () => ({ })); const mockProps = { - currency: 'usd', - localCurrency: 'usd', + currency: 'usd' as TCurrency, + localCurrency: 'usd' as TCurrency, rateType: 'float', steps: [{ header: { title: 'step 1' } }, { header: { title: 'step 2' } }, { header: { title: 'step 3' } }], + onCancel: jest.fn(), + countryList: {}, }; describe('AdWizard', () => { diff --git a/src/pages/my-ads/components/BuyPaymentMethodsList/BuyPaymentMethodsList.tsx b/src/pages/my-ads/components/BuyPaymentMethodsList/BuyPaymentMethodsList.tsx index 650a918a..e2ba94c7 100644 --- a/src/pages/my-ads/components/BuyPaymentMethodsList/BuyPaymentMethodsList.tsx +++ b/src/pages/my-ads/components/BuyPaymentMethodsList/BuyPaymentMethodsList.tsx @@ -17,7 +17,7 @@ const BuyPaymentMethodsList = ({ list, onSelectPaymentMethod }: TBuyPaymentMetho isFullWidth list={list} name='payment-method-list' - onSelect={onSelectPaymentMethod} + onSelect={value => onSelectPaymentMethod(value as string)} placeholder='Add' value='' variant='prompt' diff --git a/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.tsx b/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.tsx index 2f54f64b..6e6d4aec 100644 --- a/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.tsx +++ b/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.tsx @@ -1,4 +1,4 @@ -import { TPaymentMethod } from 'types'; +import { TAdvertiserPaymentMethod } from 'types'; import { PaymentMethodCard } from '@/components'; import { api } from '@/hooks'; import { useIsAdvertiser } from '@/hooks/custom-hooks'; @@ -16,7 +16,7 @@ const SellAdPaymentSelection = ({ onSelectPaymentMethod, selectedPaymentMethodId return (
- {advertiserPaymentMethods?.map((paymentMethod: TPaymentMethod) => { + {advertiserPaymentMethods?.map((paymentMethod: TAdvertiserPaymentMethod) => { const isDisabled = selectedPaymentMethodIds.length >= 3 && !selectedPaymentMethodIds.includes(Number(paymentMethod.id)); diff --git a/src/pages/my-ads/screens/CreateEditAd/CreateEditAd.tsx b/src/pages/my-ads/screens/CreateEditAd/CreateEditAd.tsx index 6750b03f..a53e234a 100644 --- a/src/pages/my-ads/screens/CreateEditAd/CreateEditAd.tsx +++ b/src/pages/my-ads/screens/CreateEditAd/CreateEditAd.tsx @@ -183,9 +183,10 @@ const CreateEditAd = () => { setValue('payment-method', Object.keys(advertInfo.payment_method_details ?? {}).map(Number)); } else { const paymentMethodNames = advertInfo?.payment_method_names; - const paymentMethodKeys = paymentMethodNames?.map( - name => paymentMethodList.find(method => method.display_name === name)?.id - ); + const paymentMethodKeys = + paymentMethodNames?.map( + name => paymentMethodList.find(method => method.display_name === name)?.id + ) ?? []; setValue('payment-method', paymentMethodKeys); } }, @@ -212,7 +213,7 @@ const CreateEditAd = () => { [0] & { +export type TMyAdsTableRowRendererProps = NonUndefined[0] & { balanceAvailable: number; dailyBuyLimit: string; dailySellLimit: string; diff --git a/src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx b/src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx index b4a890f5..d9f44bc6 100644 --- a/src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx +++ b/src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx @@ -15,7 +15,8 @@ import { PaymentMethodsList } from './PaymentMethodsList'; * **/ const PaymentMethods = () => { const isAdvertiser = useIsAdvertiser(); - const { data: p2pAdvertiserPaymentMethods, isLoading } = api.advertiserPaymentMethods.useGet(isAdvertiser); + const { data: p2pAdvertiserPaymentMethods, isPending: isLoading } = + api.advertiserPaymentMethods.useGet(isAdvertiser); const [formState, dispatch] = useReducer(advertiserPaymentMethodsReducer, {}); const handleAddPaymentMethod = (selectedPaymentMethod?: TSelectedPaymentMethod) => { diff --git a/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/PaymentMethodsList.tsx b/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/PaymentMethodsList.tsx index 661cff01..495a135b 100644 --- a/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/PaymentMethodsList.tsx +++ b/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/PaymentMethodsList.tsx @@ -12,7 +12,7 @@ type TPaymentMethodsListProps = { onDelete: (selectedPaymentMethod?: TSelectedPaymentMethod) => void; onEdit: (selectedPaymentMethod?: TSelectedPaymentMethod) => void; onResetFormState: () => void; - p2pAdvertiserPaymentMethods: THooks.AdvertiserPaymentMethods.Get; + p2pAdvertiserPaymentMethods?: THooks.AdvertiserPaymentMethods.Get; }; /** diff --git a/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/PaymentMethodsListContent/PaymentMethodsListContent.tsx b/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/PaymentMethodsListContent/PaymentMethodsListContent.tsx index 1a179eab..f457354f 100644 --- a/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/PaymentMethodsListContent/PaymentMethodsListContent.tsx +++ b/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/PaymentMethodsListContent/PaymentMethodsListContent.tsx @@ -1,5 +1,5 @@ import { useEffect, useMemo, useState } from 'react'; -import { TFormState, THooks, TSelectedPaymentMethod } from 'types'; +import { TBankName, TFormState, THooks, TName, TSelectedPaymentMethod } from 'types'; import { PaymentMethodCard } from '@/components'; import { PaymentMethodErrorModal, PaymentMethodModal } from '@/components/Modals'; import { PAYMENT_METHOD_CATEGORIES } from '@/constants'; @@ -24,7 +24,7 @@ type TPaymentMethodsListContentProps = { onDelete: (selectedPaymentMethod?: TSelectedPaymentMethod) => void; onEdit: (selectedPaymentMethod?: TSelectedPaymentMethod) => void; onResetFormState: () => void; - p2pAdvertiserPaymentMethods: THooks.AdvertiserPaymentMethods.Get; + p2pAdvertiserPaymentMethods?: THooks.AdvertiserPaymentMethods.Get; }; /** @@ -54,7 +54,7 @@ const PaymentMethodsListContent = ({ const { actionType, selectedPaymentMethod } = formState; const groupedPaymentMethods = useMemo(() => { const groups: TPaymentMethodsGroup = {}; - const sortedPaymentMethods = sortPaymentMethods(p2pAdvertiserPaymentMethods); + const sortedPaymentMethods = sortPaymentMethods(p2pAdvertiserPaymentMethods ?? []); sortedPaymentMethods?.forEach(advertiserPaymentMethod => { if (groups[advertiserPaymentMethod.type]) { groups[advertiserPaymentMethod.type]?.paymentMethods?.push(advertiserPaymentMethod); @@ -141,8 +141,8 @@ const PaymentMethodsListContent = ({ primaryButtonLabel='No' secondaryButtonLabel='Yes, remove' title={`Delete ${ - selectedPaymentMethod?.fields?.bank_name?.value ?? - selectedPaymentMethod?.fields?.name?.value ?? + (selectedPaymentMethod?.fields?.bank_name as TBankName)?.value ?? + (selectedPaymentMethod?.fields?.name as TName)?.value ?? selectedPaymentMethod?.display_name }?`} /> diff --git a/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/__test__/PaymentMethodsListContent.spec.tsx b/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/__test__/PaymentMethodsListContent.spec.tsx index a578dcb2..8943bf5c 100644 --- a/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/__test__/PaymentMethodsListContent.spec.tsx +++ b/src/pages/my-profile/screens/PaymentMethods/PaymentMethodsList/__test__/PaymentMethodsListContent.spec.tsx @@ -1,5 +1,5 @@ import { ComponentProps } from 'react'; -import { THooks } from 'types'; +import { THooks, TSocketError } from 'types'; import { PaymentMethodErrorModal, PaymentMethodModal } from '@/components/Modals'; import { api } from '@/hooks'; import { render, screen } from '@testing-library/react'; @@ -64,7 +64,7 @@ const mockUseDeleteResponse: ReturnType Promise.resolve({}), + mutateAsync: () => Promise.resolve({} as TSocketError<'p2p_advertiser_payment_methods'>), reset: () => undefined, status: 'success', variables: undefined, diff --git a/src/pages/orders/screens/Orders/OrdersTable/__tests__/OrdersTable.spec.tsx b/src/pages/orders/screens/Orders/OrdersTable/__tests__/OrdersTable.spec.tsx index 0a5d27c1..4e2f3334 100644 --- a/src/pages/orders/screens/Orders/OrdersTable/__tests__/OrdersTable.spec.tsx +++ b/src/pages/orders/screens/Orders/OrdersTable/__tests__/OrdersTable.spec.tsx @@ -1,3 +1,5 @@ +import { TOrderStatus } from 'types'; +import { mockAdvertValues } from '@/__mocks__/mock-data'; import { useDevice } from '@deriv-com/ui'; import { render, screen } from '@testing-library/react'; import OrdersTable from '../OrdersTable'; @@ -21,14 +23,7 @@ const mockProps = { const mockData = [ { account_currency: 'USD', - advert_details: { - block_trade: undefined, - description: '1', - id: '344', - is_block_trade: false, - payment_method: 'bank_transfer', - type: 'sell' as 'buy' | 'sell', - }, + advert_details: mockAdvertValues, advertiser_details: { first_name: 'QA script', has_not_been_recommended: true, @@ -65,16 +60,22 @@ const mockData = [ is_incoming: false, is_reviewable: false, is_seen: true, - is_verification_pending: 0, + is_verification_pending: false, local_currency: 'IDR', payment_info: '', price: 1, price_display: '1.00', rate: 1, rate_display: '1.00', - review_details: null, - status: 'refunded', - type: 'buy', + review_details: { + is_recommended: false, + has_not_been_recommended: false, + created_time: 1234567, + rating: 3, + recommended: null, + }, + status: 'refunded' as TOrderStatus, + type: 'buy' as 'buy' | 'sell', }, ]; diff --git a/src/pages/orders/screens/Orders/OrdersTableRow/__tests__/OrderTableRow.spec.tsx b/src/pages/orders/screens/Orders/OrdersTableRow/__tests__/OrderTableRow.spec.tsx index 91714ec4..08c6fd11 100644 --- a/src/pages/orders/screens/Orders/OrdersTableRow/__tests__/OrderTableRow.spec.tsx +++ b/src/pages/orders/screens/Orders/OrdersTableRow/__tests__/OrderTableRow.spec.tsx @@ -1,4 +1,4 @@ -import { THooks } from 'types'; +import { THooks, TOrderStatus } from 'types'; import { useDevice } from '@deriv-com/ui'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; @@ -56,8 +56,8 @@ const mockProps = { client_details: { first_name: 'QA script', id: '60', - is_online: 1, - is_recommended: null, + is_online: true, + is_recommended: undefined, last_name: 'userzShta', last_online_time: 1709818032, loginid: 'CR90000300', @@ -72,15 +72,15 @@ const mockProps = { }, expiry_time: 1709816002, id: '8', - is_incoming: 1, - is_reviewable: 1, + is_incoming: true, + is_reviewable: true, local_currency: 'IDR', payment_info: 'Transfer to account 000-1111', price: 1350, price_display: '1350.00', rate: 13500, rate_display: '13500.00', - status: 'completed', + status: 'completed' as TOrderStatus, type: 'buy' as 'buy' | 'sell', is_seen: false, review_details: undefined, diff --git a/types.ts b/types.ts index 2bdec890..bb585b75 100644 --- a/types.ts +++ b/types.ts @@ -18,7 +18,7 @@ export type TAccumulatedPaymentMethods = Record< string, (THooks.AdvertiserPaymentMethods.Get | THooks.PaymentMethods.Get)[number] >; -export type TPaymentMethod = THooks.AdvertiserPaymentMethods.Get[number] | THooks.PaymentMethods.Get[number]; +export type TPaymentMethod = THooks.PaymentMethods.Get[number]; export type TAdvertiserStats = ReturnType['data']; @@ -29,13 +29,13 @@ export type TSelectedPaymentMethod = Partial<{ method: THooks.AdvertiserPaymentMethods.Get[number]['method']; }>; -export type TAdvertsTableRowRenderer = Partial; +export type TAdvertsTableRowRenderer = THooks.Advert.GetList[number]; export type NonUndefinedValues = { [K in keyof T]-?: Exclude; }; -export type TAdvertType = NonUndefinedValues; +export type TAdvertType = THooks.Advert.Get; export type TCurrencyListItem = { display_name: string; @@ -137,7 +137,7 @@ export type DeepPartial = T extends string | number | bigint | boolean | null export type TFormState = { actionType?: 'ADD' | 'DELETE' | 'EDIT' | 'RESET'; isVisible?: boolean; - selectedPaymentMethod?: DeepPartial>; + selectedPaymentMethod?: DeepPartial>; title?: string; }; @@ -203,3 +203,11 @@ export type TWalletType = 'other' | 'bank' | 'ewallet'; export type TPaymentFieldType = 'text' | 'memo'; export type TType01 = 0 | 1; + +export type TOrderStatus = THooks.Order.Get['status']; + +export type TAdvertiserPaymentMethod = THooks.AdvertiserPaymentMethods.Get[number]; + +export type TBankName = THooks.AdvertiserPaymentMethods.Get[number]['fields']['bank_name']; +export type TName = THooks.AdvertiserPaymentMethods.Get[number]['fields']['name']; +export type TAccount = THooks.AdvertiserPaymentMethods.Get[number]['fields']['account'];