-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRamp.tsx
92 lines (87 loc) · 2.52 KB
/
Ramp.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { useMemo } from "react";
import { StyleSheet, Linking } from "react-native";
import { WebView } from "react-native-webview";
import { NavTheme } from "~/constants";
import { Toast, ToastType } from "~/lib/toast";
import { NobleAddress } from "~/lib/useAuth";
import { useColorScheme } from "~/lib/useColorScheme";
type RampProps = {
value: string;
receiver: NobleAddress;
email: string;
product: "BUY" | "SELL";
};
export const Ramp = ({ value, receiver, email, product }: RampProps) => {
const { colorScheme } = useColorScheme();
const uri = useMemo(() => {
const colors = NavTheme[colorScheme];
const baseUrl = new URL("https://sandbox--kado.netlify.app/");
const searchParams = new URLSearchParams({
apiKey: "YOUR_WIDGET_ID",
isMobileWebview: "true",
onPayCurrency: "USD",
onPayAmount: value,
onToAddress: receiver,
network: "NOBLE",
onRevCurrency: "USDC",
email,
mode: "minimal",
product,
theme: colorScheme,
primaryColor: colors.colors.primary,
secondaryColor: colors.colors.secondary,
successColor: colors.colors.success,
warningColor: colors.colors.border,
errorColor: colors.colors.notification,
fiatMethodList: "card, debit_only",
});
return baseUrl.href + "?" + searchParams.toString();
}, [colorScheme]);
return (
<WebView
containerStyle={styles.modalContainer}
onMessage={(event) => {
const eventData = event?.nativeEvent?.data;
try {
const message = JSON.parse(eventData);
if (message && message?.type === "PLAID_NEW_ACH_LINK") {
const achLink = message?.payload?.link;
Linking.openURL(achLink);
}
} catch (error) {
Toast.show({
text1: "ACH Link Error",
type: ToastType.Error,
});
}
}}
allowUniversalAccessFromFileURLs
geolocationEnabled
javaScriptEnabled
allowsInlineMediaPlayback
mediaPlaybackRequiresUserAction={false}
originWhitelist={["*"]}
source={{ uri }}
allowsBackForwardNavigationGestures
onError={() => {
Toast.show({
text1: "Something went wrong",
type: ToastType.Error,
});
}}
style={styles.webview}
/>
);
};
const styles = StyleSheet.create({
modalContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "rgba(0, 0, 0, 0)",
},
webview: {
width: "100%",
height: "100%",
},
});