import { View, Button, Text, useEffect } from "react-native";
import { useMoonPaySdk } from "@moonpay/react-native-moonpay-sdk";
const YourComponent = () => {
const { openWithInAppBrowser, generateUrlForSigning, updateSignature } =
useMoonPaySdk({
sdkConfig: {
flow: "buy",
environment: "sandbox",
params: {
apiKey: "pk_test_key",
},
},
browserOpener: {
open: (url) => {
// Use any in-app browser or standalone browser here
// Example with custom browser implementation
},
},
});
useEffect(() => {
// The URL for signature should be sent to your backend, which should then
// sign it with your API secret and return the signature.
// Once you have the signature, you can update the SDK with it and show the widget.
fetch("/sign-url", {
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <token>",
},
method: "POST",
body: JSON.stringify({
url: generateUrlForSigning(),
}),
})
.then((res) => res.json())
.then((data) => {
const signature = data.signature;
updateSignature(signature);
});
}, []);
return (
<View>
<Button onPress={() => openWithInAppBrowser()}>
<Text>Open in InApp browser</Text>
</Button>
</View>
);
};