stripe-terminal-react-native: DiscoverReaders won't work, busy with command "discoverReaders" :(

Describe the bug The hook discoverReaders won’t work. Everytime I just get the error Could not execute discoverReaders because the SDK is busy with another command: discoverReaders.. (simulated)

To Reproduce Steps to reproduce the behavior:

  1. Just run discoverReaders
  2. See Error

Expected behavior discoverReaders should discover or just simulate it.

Screenshots N/A

Stripe Terminal React Native SDK version

0.0.1-beta.11

Smartphone (please complete the following information):

  • Device: iPad Pro (12.9-inch) — Xcode Simulator
  • OS: iOS 16.2
  • Browser N/A
  • Version N/A

Additional context See Code:

...
const { discoverReaders, connectBluetoothReader, isInitialized, discoveredReaders } =
useStripeTerminal({
	didUpdateDiscoveredReaders: (readers) => {
		// After the SDK discovers a reader, your app can connect to it.
		// Here, we're automatically connecting to the first discovered reader.
		handleConnectBluetoothReader(readers[0].id);
	},
});

useEffect(() => {
	if (!isInitialized) {
		// Initialize Stripe Terminal, then connect to the reader
		initialize({
			logLevel: 'verbose',
		})
	}
}, [navigation, isLoading]);

useEffect(() => {
	if (isInitialized && isLoading === false) {
		console.log('Stripe Terminal initialized. Discovering readers...');
		setIsLoading(true);
		discoverReaders({
			discoveryMethod: 'bluetoothScan',
			simulated: true,
		});
	}
}, [isInitialized, isLoading]);
...

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 23 (3 by maintainers)

Most upvoted comments

I had a similar issue, the app would work the first time running discoverReaders but afterwards it would throw the same error, unless I restart the app which was annoying. To avoid this I had to cancel the current discovery session

This should not be required. Is it reproducible with the example app, or can you provide a sample code that exhibits the failure?

And Is there a way to add a timer to discoverReaders method so that it runs for a specified amount of time.

The native SDKs do support a timeout field. We’ll need to add/expose it to DiscoverReadersParams here: https://github.com/stripe/stripe-terminal-react-native/blob/9d7dee7a6821288da2de902640930f0e9c27a02c/src/types/index.ts#L24

And then thread it to the underlying Android/iOS calls here: https://github.com/stripe/stripe-terminal-react-native/blob/9d7dee7a6821288da2de902640930f0e9c27a02c/ios/StripeTerminalReactNative.swift#L180-L183 https://github.com/stripe/stripe-terminal-react-native/blob/9d7dee7a6821288da2de902640930f0e9c27a02c/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt#L184

Native docs: https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.models/-discovery-configuration/index.html https://stripe.dev/stripe-terminal-ios/docs/Classes/SCPDiscoveryConfiguration.html#/c:objc(cs)SCPDiscoveryConfiguration(py)timeout

Hi @rachelanordgren – thanks for calling this to our attention. It does appear to be missing in the implementation. The underlying native SDKs do support a timeout field, so we should be able to add it to the RN SDK.

Would you mind filing a separate Github issue, so we can track and address this request?

there is a screen where I am searching for the readers. And there is a cancel button on that screen which when clicked calls the cancelDiscovering method. And then this error popup comes attached.

This error dialog is generated by the example application. It is not created by the SDK. You can modify your application (which may be a fork of the example application) so that it does not display this alert. Search for “Discover readers error” and change the code where Alert.alert is called to match the behavior you desire.

Here’s where the alert dialog is created in the example application: https://github.com/stripe/stripe-terminal-react-native/blob/61f9dc2d9c5f488f012ea2a016808ce57e35effa/example-app/src/screens/DiscoverReadersScreen.tsx#L138