Skip to main content
Use this function to enable or disable features related to Lemon 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 to communicate with the Lemon App, and they return an error message if no React Native WebView is detected.

Usage

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

// Check if running in Lemon's App WebView environment
const isLemon = await isLemonWebView();

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

Parameters

This function takes no parameters.

Returns

Promise<boolean>
Promise<boolean>
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:
  1. First checks if the app is in a React Native WebView.
  2. If it is, it sends a message to the native Lemon app requesting confirmation.
  3. Waits for a response with a 1-second timeout.
  4. Returns true only if the native app confirms, false otherwise.

Complete Example

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

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

  useEffect(() => {
    const checkEnvironment = async () => {
      const lemonWebView = await isLemonWebView();
      setIsInLemonApp(lemonWebView);
    };

    checkEnvironment();
  }, []);

  return (
    <div>
      <h2>Mini App Status</h2>
      <p>
        Lemon Environment: {isInLemonApp ? 'Available' : 'Not Available'}
      </p>

      {!isInLemonApp && (
        <p>
          Open this app in the Lemon app to use all features.
        </p>
      )}
    </div>
  );
};

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.
If you are currently using isWebView, update your code as follows:
// Before (deprecated)
import { isWebView } from '@lemoncash/mini-app-sdk';
const inWebView = isWebView(); // synchronous

// After (recommended)
import { isLemonWebView } from '@lemoncash/mini-app-sdk';
const inLemonApp = await isLemonWebView(); // async
Key differences:
  • isLemonWebView is async and returns a Promise<boolean>, while isWebView was synchronous.
  • isLemonWebView confirms 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.