Skip to main content
Use this function to enable or disable features related to Lemon Cash Mini Apps. For safety, all methods: authenticate, deposit, withdraw and callSmartContract verify that they are being executed in a React Native WebView environment before trying before trying to communicate with the Lemon Cash App, and they return an error message if no React Native WebView is detected.

Usage

import { isWebView } from '@lemoncash/mini-app-sdk';

// Check if running in WebView environment
if (isWebView()) {
  console.log('✅ Running inside React Native WebView');
  // Safe to use SDK functions like authenticate, deposit, etc.
} else {
  console.log('❌ Not running in React Native WebView environment');
  // SDK functions will throw errors
}

Parameters

This function takes no parameters.

Returns

boolean
boolean
Returns true if the application is running inside a React Native WebView environment, false otherwise.

Detection Methods

The function uses multiple detection strategies to ensure accurate React Native WebView identification:

1. ReactNativeWebView Object

Checks if window.ReactNativeWebView is available, which is the primary indicator of a React Native WebView environment.

2. User Agent String

Looks for 'ReactNativeWebView' in the browser’s user agent string.

3. CSS Class Detection

Checks if the document root element has the 'ReactNativeWebView' CSS class.

4. SSR Safety

Returns false when window is undefined (server-side rendering scenarios).

Complete Example

import { isWebView } from '@lemoncash/mini-app-sdk';

export const MiniApp = () => {
  const [isInWebView, setIsInWebView] = useState<boolean>(false);

  useEffect(() => {
    // Check WebView environment on component mount
    const webViewStatus = isWebView();
    setIsInWebView(webViewStatus);
  }, []);

  return (
    <div>
      <h2>Mini App Status</h2>
      <p>
        WebView Environment: {isInWebView ? '✅ Available' : '❌ Not Available'}
      </p>
      
      {!isInWebView && (
        <p>
          Open this app in the Lemon Cash app to use all features.
        </p>
      )}
    </div>
  );
};

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-WebView environments.