Skip to content

Commit

Permalink
feat: Add link to pending transaction alert
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronfigueiredo committed Nov 29, 2024
1 parent 0120ce4 commit e168314
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ describe('Contract Interaction Confirmation Alerts', () => {
expect(
await screen.findByTestId('alert-modal__selected-alert'),
).toHaveTextContent(
'This transaction wont go through until a previous transaction is complete. Learn how to cancel or speed up a transaction.',
"This transaction won't go through until a previous transaction is complete. Learn how to cancel or speed up a transaction.",
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ReactNode } from 'react';
import {
BannerAlert,
Box,
Expand All @@ -21,7 +21,7 @@ import { AlertProvider } from '../alert-provider';
import { AlertSeverity } from '../../../../ducks/confirm-alerts/confirm-alerts';

export type GeneralAlertProps = {
description: string;
description: string | ReactNode;
details?: React.ReactNode | string[];
onClickSupportLink?: () => void;
provider?: SecurityProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface BannerBaseStyleUtilityProps extends StyleUtilityProps {
/**
* The description is the content area below BannerBase title
*/
description?: string;
description?: string | React.ReactNode;
/**
* Additional props to pass to the `Text` component used for the `description` text
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@ import {
TransactionStatus,
TransactionType,
} from '@metamask/transaction-controller';

import { getMockConfirmState } from '../../../../../../test/data/confirmations/helper';
import { useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
import { genUnapprovedContractInteractionConfirmation } from '../../../../../../test/data/confirmations/contract-interaction';
import { getMockConfirmState } from '../../../../../../test/data/confirmations/helper';
import { renderHookWithConfirmContextProvider } from '../../../../../../test/lib/confirmations/render-helpers';
import { Severity } from '../../../../../helpers/constants/design-system';
import { RowAlertKey } from '../../../../../components/app/confirm/info/row/constants';
import { Severity } from '../../../../../helpers/constants/design-system';
import {
getRedesignedTransactionsEnabled,
submittedPendingTransactionsSelector,
} from '../../../../../selectors';
import { PendingTransactionAlertMessage } from './PendingTransactionAlertMessage';
import { usePendingTransactionAlerts } from './usePendingTransactionAlerts';

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: jest.fn(),
}));

jest.mock('./PendingTransactionAlertMessage', () => ({
PendingTransactionAlertMessage: () => 'PendingTransactionAlertMessage',
}));

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: jest.fn().mockReturnValue({ id: 'mock-transaction-id' }),
}));

const ACCOUNT_ADDRESS = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc';
const TRANSACTION_ID_MOCK = '123-456';

Expand Down Expand Up @@ -63,8 +83,12 @@ function runHook({
}

describe('usePendingTransactionAlerts', () => {
const useSelectorMock = useSelector as jest.Mock;

beforeEach(() => {
jest.resetAllMocks();

(useParams as jest.Mock).mockReturnValue({ id: 'mock-transaction-id' });
});

it('returns no alerts if no confirmation', () => {
Expand Down Expand Up @@ -121,6 +145,20 @@ describe('usePendingTransactionAlerts', () => {
});

it('returns alert if submitted transaction', () => {
useSelectorMock.mockImplementation((selector) => {
if (selector === submittedPendingTransactionsSelector) {
return [
{ name: 'first transaction', id: '1' },
{ name: 'second transaction', id: '2' },
];
} else if (selector === getRedesignedTransactionsEnabled) {
return true;
} else if (selector.toString().includes('getUnapprovedTransaction')) {
return { type: TransactionType.contractInteraction };
}
return undefined;
});

const alerts = runHook({
currentConfirmation: CONFIRMATION_MOCK,
transactions: [TRANSACTION_META_MOCK],
Expand All @@ -130,8 +168,7 @@ describe('usePendingTransactionAlerts', () => {
{
field: RowAlertKey.Speed,
key: 'pendingTransactions',
message:
'This transaction won’t go through until a previous transaction is complete. Learn how to cancel or speed up a transaction.',
message: PendingTransactionAlertMessage(),
reason: 'Pending transaction',
severity: Severity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ export function usePendingTransactionAlerts(): Alert[] {

const isValidType = isCorrectDeveloperTransactionType(type);

// const hasPendingTransactions =
// isValidType && Boolean(pendingTransactions.length);

const hasPendingTransactions = true;
const hasPendingTransactions =
isValidType && Boolean(pendingTransactions.length);

return useMemo(() => {
if (!hasPendingTransactions) {
Expand Down

0 comments on commit e168314

Please sign in to comment.