Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions app/components/UI/Bridge/Views/BridgeView/BridgeView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
renderScreen,
DeepPartial,
} from '../../../../../util/test/renderWithProvider';
import { fireEvent, waitFor } from '@testing-library/react-native';
import { fireEvent, waitFor, act } from '@testing-library/react-native';
import Routes from '../../../../../constants/navigation/Routes';
import {
setDestToken,
Expand Down Expand Up @@ -1018,6 +1018,7 @@ describe('BridgeView', () => {
it('should navigate to blockaid modal on validation error for Solana swap', async () => {
// Mock validation result with validation error
mockValidateBridgeTx.mockResolvedValue({
status: 'ERROR',
result: {
validation: {
reason: 'Transaction may result in loss of funds',
Expand Down Expand Up @@ -1074,7 +1075,9 @@ describe('BridgeView', () => {

// Find and press the continue button
const continueButton = getByText(strings('bridge.confirm_swap'));
fireEvent.press(continueButton);
await act(async () => {
fireEvent.press(continueButton);
});

await waitFor(() => {
expect(mockValidateBridgeTx).toHaveBeenCalledWith({
Expand All @@ -1096,6 +1099,7 @@ describe('BridgeView', () => {
it('should navigate to blockaid modal on simulation error for Solana to EVM bridge', async () => {
// Mock validation result with simulation error
mockValidateBridgeTx.mockResolvedValue({
status: 'ERROR',
result: {
validation: {
reason: null,
Expand Down Expand Up @@ -1155,7 +1159,9 @@ describe('BridgeView', () => {

// Find and press the continue button
const continueButton = getByText(strings('bridge.confirm_bridge'));
fireEvent.press(continueButton);
await act(async () => {
fireEvent.press(continueButton);
});

await waitFor(() => {
expect(mockValidateBridgeTx).toHaveBeenCalledWith({
Expand All @@ -1177,6 +1183,7 @@ describe('BridgeView', () => {
it('should prioritize validation error over simulation error', async () => {
// Mock validation result with both validation and simulation errors
mockValidateBridgeTx.mockResolvedValue({
status: 'ERROR',
result: {
validation: {
reason: 'Transaction may result in loss of funds',
Expand Down Expand Up @@ -1233,7 +1240,9 @@ describe('BridgeView', () => {

// Find and press the continue button
const continueButton = getByText(strings('bridge.confirm_swap'));
fireEvent.press(continueButton);
await act(async () => {
fireEvent.press(continueButton);
});

await waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith(Routes.BRIDGE.MODALS.ROOT, {
Expand All @@ -1249,6 +1258,7 @@ describe('BridgeView', () => {
it('should proceed with transaction when no validation errors', async () => {
// Mock validation result with no errors
mockValidateBridgeTx.mockResolvedValue({
status: 'SUCCESS',
result: {
validation: {
reason: null,
Expand Down Expand Up @@ -1305,7 +1315,9 @@ describe('BridgeView', () => {

// Find and press the continue button
const continueButton = getByText(strings('bridge.confirm_swap'));
fireEvent.press(continueButton);
await act(async () => {
fireEvent.press(continueButton);
});

await waitFor(() => {
expect(mockValidateBridgeTx).toHaveBeenCalledWith({
Expand Down Expand Up @@ -1373,7 +1385,9 @@ describe('BridgeView', () => {

// Find and press the continue button
const continueButton = getByText(strings('bridge.confirm_bridge'));
fireEvent.press(continueButton);
await act(async () => {
fireEvent.press(continueButton);
});

await waitFor(() => {
expect(mockSubmitBridgeTx).toHaveBeenCalledWith({
Expand Down
15 changes: 8 additions & 7 deletions app/components/UI/Bridge/Views/BridgeView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,21 @@ const BridgeView = () => {
const validationResult = await validateBridgeTx({
quoteResponse: activeQuote,
});
if (
validationResult.error ||
validationResult.result.validation.reason
) {
if (validationResult.status === 'ERROR') {
displayValidationError = true;
const isValidationError =
!!validationResult.result.validation.reason;
const { error_details } = validationResult;
const fallbackErrorMessage = isValidationError
? validationResult.result.validation.reason
: validationResult.error;
navigation.navigate(Routes.BRIDGE.MODALS.ROOT, {
screen: Routes.BRIDGE.MODALS.BLOCKAID_MODAL,
params: {
errorType: isValidationError ? 'validation' : 'simulation',
errorMessage: isValidationError
? validationResult.result.validation.reason
: validationResult.error,
errorMessage: error_details?.message
? `The ${error_details.message}.`
: fallbackErrorMessage,
},
});
return;
Expand Down
Loading