Skip to content

Commit

Permalink
fix: 🐛 fix query parameter (#13141)
Browse files Browse the repository at this point in the history
  • Loading branch information
heorhi-deriv authored Jan 26, 2024
1 parent 77d3fdf commit 05db48d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const TransactionStatusSuccess: React.FC<TTransactionStatusSuccess> = ({ transac
isFullWidth
onClick={() => {
// should navigate to transactions page with "Pending transactions" toggle on and filter set to `transactionType`
history.push('/wallets/cashier/transactions?showPending');
history.push('/wallets/cashier/transactions', {
showPending: true,
transactionType: 'withdrawal',
});
}}
size='sm'
variant='outlined'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ describe('TransactionStatusSuccess', () => {
expect(screen.getByText('View more')).toBeInTheDocument();

fireEvent.click(screen.getByText('View more'));
expect(pushMock).toHaveBeenCalledWith('/wallets/cashier/transactions?showPending');
expect(pushMock).toHaveBeenCalledWith('/wallets/cashier/transactions', {
showPending: true,
transactionType: 'withdrawal',
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useMemo, useState } from 'react';
import classNames from 'classnames';
import { useHistory } from 'react-router-dom';
import { useActiveWalletAccount, useCurrencyConfig } from '@deriv/api';
import { ToggleSwitch, WalletDropdown, WalletText } from '../../../../components';
import useDevice from '../../../../hooks/useDevice';
Expand All @@ -10,6 +11,10 @@ import './Transactions.scss';
type TTransactionsPendingFilter = React.ComponentProps<typeof TransactionsPending>['filter'];
type TTransactionCompletedFilter = React.ComponentProps<typeof TransactionsCompleted>['filter'];
type TFilterValue = TTransactionCompletedFilter | TTransactionsPendingFilter;
type THistoryState = {
showPending?: boolean;
transactionType?: string;
};

const filtersMapper: Record<string, Record<string, TFilterValue>> = {
completed: {
Expand All @@ -32,11 +37,11 @@ const Transactions = () => {
const { isLoading } = useCurrencyConfig();
const { isMobile } = useDevice();

const queryParams = new URLSearchParams(location.search);
const showPending = queryParams.get('showPending');
const { location } = useHistory();
const state: THistoryState = location.state;

const [isPendingActive, setIsPendingActive] = useState(showPending === 'true');
const [filterValue, setFilterValue] = useState('all');
const [isPendingActive, setIsPendingActive] = useState(Boolean(state?.showPending));
const [filterValue, setFilterValue] = useState(state?.transactionType ?? 'all');

const filterOptionsList = useMemo(
() =>
Expand Down
12 changes: 10 additions & 2 deletions packages/wallets/src/routes/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ type TRoutes = `${typeof prefix}${
| '/cashier'
| '/cashier/deposit'
| '/cashier/reset-balance'
| '/cashier/transaction'
| '/cashier/transactions'
| '/cashier/transfer'
| '/cashier/withdraw'
| '/compare-account'}`;

declare module 'react-router-dom' {
export function useHistory(): { push: (path: TRoutes | string) => void };
export function useHistory(): {
location: {
hash: string;
pathname: string;
search: string;
state: Record<string, unknown>;
};
push: (path: TRoutes | string, state?: Record<string, unknown>) => void;
};

export function useRouteMatch(path: TRoutes): boolean;
}
Expand Down

1 comment on commit 05db48d

@vercel
Copy link

@vercel vercel bot commented on 05db48d Jan 26, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

deriv-app – ./

deriv-app.vercel.app
binary.sx
deriv-app-git-master.binary.sx
deriv-app.binary.sx

Please sign in to comment.