authenticate, deposit, withdraw and callSmartContract verify that they are being executed in a React Native WebView environment before trying to communicate with the Lemon App, and they return an error message if no React Native WebView is detected.
Usage
Parameters
This function takes no parameters.Returns
Returns a
Promise that resolves to true if the application is running inside Lemon’s WebView environment, false otherwise.How It Works
The function uses a communication-based approach to verify the environment:- First checks if the app is in a React Native WebView.
- If it is, it sends a message to the native Lemon app requesting confirmation.
- Waits for a response with a 1-second timeout.
- Returns
trueonly if the native app confirms,falseotherwise.
Complete Example
Migration from old isWebView
isWebView has been replaced by isLemonWebView. The old isWebView function is deprecated and will become a private function in a future release. Please migrate to isLemonWebView.isWebView, update your code as follows:
isLemonWebViewis async and returns aPromise<boolean>, whileisWebViewwas synchronous.isLemonWebViewconfirms the host app is the Lemon App, not just any React Native WebView.
UX Tips
- Feature Gating: Use this function to conditionally enable/disable features based on the environment.
- User Experience: Provide clear feedback when features are not available in the current environment.
- Fallback Handling: Implement graceful fallbacks for non-Lemon’s App environments.