mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-02-20 00:33:07 +01:00
chore(suite-native): Trading: Fix circular dep
This commit is contained in:
committed by
Jiří Bažant
parent
42415ff332
commit
5c65aaabe9
@@ -39,10 +39,11 @@ export const BuyTradeableAssetPicker = () => {
|
|||||||
setSelectedValue(asset);
|
setSelectedValue(asset);
|
||||||
if (shouldFocusInput) {
|
if (shouldFocusInput) {
|
||||||
setShouldFocusInput(false);
|
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(() => {
|
setTimeout(() => {
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
}, 0);
|
}, 300);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[shouldFocusInput, setSelectedValue],
|
[shouldFocusInput, setSelectedValue],
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { Keyboard } from 'react-native';
|
|
||||||
|
|
||||||
import { NetworkSymbol } from '@suite-common/wallet-config';
|
import { NetworkSymbol } from '@suite-common/wallet-config';
|
||||||
import { BottomSheetSectionList, ItemRenderConfig } from '@suite-native/trading-atoms';
|
import { BottomSheetSectionList, ItemRenderConfig } from '@suite-native/trading-atoms';
|
||||||
@@ -44,10 +43,8 @@ export const TradeableAssetSheet = memo(
|
|||||||
testID,
|
testID,
|
||||||
}: TradeableAssetsSheetProps) => {
|
}: TradeableAssetsSheetProps) => {
|
||||||
const onAssetSelectCallback = (asset: TradeableAsset) => {
|
const onAssetSelectCallback = (asset: TradeableAsset) => {
|
||||||
// has to be before onAssetSelect callback call to allow focusing another input from it
|
|
||||||
Keyboard.dismiss();
|
|
||||||
onAssetSelect(asset);
|
|
||||||
onClose();
|
onClose();
|
||||||
|
onAssetSelect(asset);
|
||||||
};
|
};
|
||||||
|
|
||||||
const listData = useFavouriteAssetsSectionList(assets);
|
const listData = useFavouriteAssetsSectionList(assets);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { Keyboard } from 'react-native';
|
|
||||||
|
|
||||||
import { fireEvent, renderWithStoreProviderAsync, screen } from '@suite-native/test-utils';
|
import { fireEvent, renderWithStoreProviderAsync, screen } from '@suite-native/test-utils';
|
||||||
import { adaAsset, btcAsset, usdcAsset } from '@suite-native/trading-fixtures';
|
import { adaAsset, btcAsset, usdcAsset } from '@suite-native/trading-fixtures';
|
||||||
import { TradeableAsset } from '@suite-native/trading-types';
|
import { TradeableAsset } from '@suite-native/trading-types';
|
||||||
@@ -27,10 +25,9 @@ describe('TradeableAssetSheet', () => {
|
|||||||
screen.unmount();
|
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 closeMock = jest.fn();
|
||||||
const selectMock = jest.fn();
|
const selectMock = jest.fn();
|
||||||
const keyboardDismissSpy = jest.spyOn(Keyboard, 'dismiss');
|
|
||||||
|
|
||||||
const { getByText } = await renderTradeableAssetsSheet({
|
const { getByText } = await renderTradeableAssetsSheet({
|
||||||
onClose: closeMock,
|
onClose: closeMock,
|
||||||
@@ -39,7 +36,6 @@ describe('TradeableAssetSheet', () => {
|
|||||||
|
|
||||||
fireEvent.press(getByText('BTC'));
|
fireEvent.press(getByText('BTC'));
|
||||||
|
|
||||||
expect(keyboardDismissSpy).toHaveBeenCalledTimes(1);
|
|
||||||
expect(selectMock).toHaveBeenCalledTimes(1);
|
expect(selectMock).toHaveBeenCalledTimes(1);
|
||||||
expect(closeMock).toHaveBeenCalledTimes(1);
|
expect(closeMock).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ describe('useBottomSheetControls', () => {
|
|||||||
expect(result.current.isSheetVisible).toBe(true);
|
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 { result } = renderHookWithBasicProvider(() => useBottomSheetControls());
|
||||||
const keyboardDismissSpy = jest.spyOn(Keyboard, 'dismiss');
|
const keyboardDismissSpy = jest.spyOn(Keyboard, 'dismiss');
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ describe('useBottomSheetControls', () => {
|
|||||||
result.current.hideSheet();
|
result.current.hideSheet();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(keyboardDismissSpy).toHaveBeenCalledTimes(1);
|
expect(keyboardDismissSpy).toHaveBeenCalledTimes(2);
|
||||||
expect(result.current.isSheetVisible).toBe(false);
|
expect(result.current.isSheetVisible).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export const useBottomSheetControls = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const hideSheet = useCallback(() => {
|
const hideSheet = useCallback(() => {
|
||||||
|
Keyboard.dismiss();
|
||||||
setIsSheetVisible(false);
|
setIsSheetVisible(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user