chore(suite-native): Trading: Fix circular dep

This commit is contained in:
Jirka Bažant
2026-02-02 17:00:21 +01:00
committed by Jiří Bažant
parent 42415ff332
commit 5c65aaabe9
5 changed files with 8 additions and 13 deletions

View File

@@ -39,10 +39,11 @@ export const BuyTradeableAssetPicker = () => {
setSelectedValue(asset);
if (shouldFocusInput) {
setShouldFocusInput(false);
// CryptoAmountInput is rendered disabled allow changes to propagate.
// CryptoAmountInput is rendered disabled allow changes to propagate and
// allow bottom-sheet to hide first.
setTimeout(() => {
inputRef.current?.focus();
}, 0);
}, 300);
}
},
[shouldFocusInput, setSelectedValue],

View File

@@ -1,5 +1,4 @@
import { memo, useCallback } from 'react';
import { Keyboard } from 'react-native';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { BottomSheetSectionList, ItemRenderConfig } from '@suite-native/trading-atoms';
@@ -44,10 +43,8 @@ export const TradeableAssetSheet = memo(
testID,
}: TradeableAssetsSheetProps) => {
const onAssetSelectCallback = (asset: TradeableAsset) => {
// has to be before onAssetSelect callback call to allow focusing another input from it
Keyboard.dismiss();
onAssetSelect(asset);
onClose();
onAssetSelect(asset);
};
const listData = useFavouriteAssetsSectionList(assets);

View File

@@ -1,5 +1,3 @@
import { Keyboard } from 'react-native';
import { fireEvent, renderWithStoreProviderAsync, screen } from '@suite-native/test-utils';
import { adaAsset, btcAsset, usdcAsset } from '@suite-native/trading-fixtures';
import { TradeableAsset } from '@suite-native/trading-types';
@@ -27,10 +25,9 @@ describe('TradeableAssetSheet', () => {
screen.unmount();
});
it('should call Keyboard.dismiss, onAssetSelect and onClose when an item is pressed', async () => {
it('should call onAssetSelect and onClose when an item is pressed', async () => {
const closeMock = jest.fn();
const selectMock = jest.fn();
const keyboardDismissSpy = jest.spyOn(Keyboard, 'dismiss');
const { getByText } = await renderTradeableAssetsSheet({
onClose: closeMock,
@@ -39,7 +36,6 @@ describe('TradeableAssetSheet', () => {
fireEvent.press(getByText('BTC'));
expect(keyboardDismissSpy).toHaveBeenCalledTimes(1);
expect(selectMock).toHaveBeenCalledTimes(1);
expect(closeMock).toHaveBeenCalledTimes(1);
});

View File

@@ -28,7 +28,7 @@ describe('useBottomSheetControls', () => {
expect(result.current.isSheetVisible).toBe(true);
});
it('should be false after hideTradeableAssetsSheet call and Keyboard.dismiss should be called one time', () => {
it('should be false after hideTradeableAssetsSheet call and Keyboard.dismiss should be called two times', () => {
const { result } = renderHookWithBasicProvider(() => useBottomSheetControls());
const keyboardDismissSpy = jest.spyOn(Keyboard, 'dismiss');
@@ -37,7 +37,7 @@ describe('useBottomSheetControls', () => {
result.current.hideSheet();
});
expect(keyboardDismissSpy).toHaveBeenCalledTimes(1);
expect(keyboardDismissSpy).toHaveBeenCalledTimes(2);
expect(result.current.isSheetVisible).toBe(false);
});
});

View File

@@ -12,6 +12,7 @@ export const useBottomSheetControls = () => {
}, []);
const hideSheet = useCallback(() => {
Keyboard.dismiss();
setIsSheetVisible(false);
}, []);