Powered by Coinflow
Payments · Documentation
Operational

React Native Redirect Example

React Native mobile apps will require a redirect to the web browser to create a users bank account. The following code example will provide an implementation where you can redirect to a web browser to add a bank account and then redirect the user back to your mobile app.

Use solana in the path segment even if you aren’t using a Solana wallet — this is a URL routing convention from our session-key endpoint, not a chain requirement.

export default function HomeScreen() {
  const [isLinking, setIsLinking] = useState(false);

  const handleRedirect = () => {
    const deepLinkUrl = 'exp://10.0.0.19:8081';

    const session_key = "USER_SESSION_KEY" // replace with a session key generated here: /api-reference/api-reference/authentication/get-session-key
    const pathSegment = "solana"; // fixed URL routing convention — not a chain selector
    const coinflowUrl = `https://sandbox.coinflow.cash/${pathSegment}/withdraw/YOUR_MERCHANT_ID?sessionKey=${session_key}&bankAccountLinkRedirect=${encodeURIComponent(deepLinkUrl)}`

    console.log('coinflow url', coinflowUrl);

    // open url in browswer
    Linking.openURL(coinflowUrl).catch((error) => {
      console.error('error opening url', error);
      setIsLinking(false);
    });
  };

  useEffect(() => {
    handleRedirect();
  }, []);

  return null;
}