Skip to content

Commit 98f253c

Browse files
fix: dont show stale quotes when returning to review screen
1 parent c0f594c commit 98f253c

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

app/components/UI/Bridge/Views/BatchSellReview/BatchSellReview.test.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { BridgeToken } from '../../types';
66
import { BatchSellReview } from './BatchSellReview';
77
import { BatchSellReviewSelectorsIDs } from './BatchSellReview.testIds';
88
import Routes from '../../../../../constants/navigation/Routes';
9+
import Engine from '../../../../../core/Engine';
910

1011
const mockNavigate = jest.fn();
1112
const mockDispatch = jest.fn();
@@ -95,6 +96,17 @@ jest.mock('@react-navigation/native', () => ({
9596
}),
9697
}));
9798

99+
jest.mock('../../../../../core/Engine', () => ({
100+
__esModule: true,
101+
default: {
102+
context: {
103+
BridgeController: {
104+
resetState: jest.fn(),
105+
},
106+
},
107+
},
108+
}));
109+
98110
jest.mock('../../../../../core/redux/slices/bridge', () => ({
99111
resetBridgeState: jest.fn(() => ({
100112
type: 'bridge/resetBridgeState',
@@ -392,12 +404,13 @@ describe('BatchSellReview', () => {
392404
expect(mockCancelBatchSellQuoteParams).toHaveBeenCalled();
393405
});
394406

395-
it('leaves bridge state intact on unmount', () => {
407+
it('resets controller quote state but leaves Redux bridge state intact on unmount', () => {
396408
const { unmount } = render(<BatchSellReview />);
397409

398410
mockDispatch.mockClear();
399411
unmount();
400412

413+
expect(Engine.context.BridgeController.resetState).toHaveBeenCalledTimes(1);
401414
expect(mockDispatch).not.toHaveBeenCalledWith({
402415
type: 'bridge/resetBridgeState',
403416
});

app/components/UI/Bridge/Views/BatchSellReview/BatchSellReview.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
setBatchSellTokenSlippages,
4242
} from '../../../../../core/redux/slices/bridge';
4343
import { RootState } from '../../../../../reducers';
44+
import Engine from '../../../../../core/Engine';
4445
import { BridgeToken } from '../../types';
4546
import { getBridgeTokenAssetId } from '../../utils/tokenUtils';
4647
import { getBatchSellSlippage } from '../../components/SlippageModal/utils';
@@ -154,6 +155,14 @@ export function BatchSellReview() {
154155
};
155156
}, [hasValidBatchSellInputs, updateBatchSellQuoteParams]);
156157

158+
useEffect(
159+
() => () => {
160+
// Clear controller quote state so returning to review does not show stale quotes.
161+
Engine.context.BridgeController?.resetState?.();
162+
},
163+
[],
164+
);
165+
157166
useEffect(() => {
158167
const nextSourceTokenAmounts = selectedTokens.reduce<
159168
Record<string, string | undefined>

0 commit comments

Comments
 (0)