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:
- Just run discoverReaders
- 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)
This should not be required. Is it reproducible with the example app, or can you provide a sample code that exhibits the failure?
The native SDKs do support a timeout field. We’ll need to add/expose it to
DiscoverReadersParamshere: https://github.com/stripe/stripe-terminal-react-native/blob/9d7dee7a6821288da2de902640930f0e9c27a02c/src/types/index.ts#L24And 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?
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.alertis 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