@moonpay/platform-sdk-react-native 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -370,8 +370,8 @@ var connectionResetSpec = {
370
370
  };
371
371
 
372
372
  // src/frame-view.tsx
373
- import { useEffect as useEffect2, useRef as useRef3, useState as useState2 } from "react";
374
- import { View as View2 } from "react-native";
373
+ import { useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "react";
374
+ import { View as View3 } from "react-native";
375
375
 
376
376
  // src/frame-component.tsx
377
377
  import { useEffect, useRef } from "react";
@@ -450,11 +450,7 @@ var WebViewTransport = class {
450
450
  if (!this.webViewRef?.current) {
451
451
  throw new Error("Cannot send message: WebView not attached");
452
452
  }
453
- const js = `
454
- window.postMessage(${JSON.stringify(JSON.stringify(message))}, '*');
455
- true;
456
- `;
457
- this.webViewRef.current.injectJavaScript(js);
453
+ this.webViewRef.current.postMessage(JSON.stringify(message));
458
454
  }
459
455
  onMessage(handler) {
460
456
  this.handlers.push(handler);
@@ -581,13 +577,12 @@ function createFrameSession(spec, ctx, props, overrides = {}) {
581
577
  import { createClientCore } from "@moonpay/platform-sdk-core";
582
578
  import {
583
579
  createContext,
584
- useCallback,
580
+ useCallback as useCallback2,
585
581
  useContext,
586
582
  useMemo,
587
- useRef as useRef2,
588
- useState
583
+ useRef as useRef3,
584
+ useState as useState2
589
585
  } from "react";
590
- import { Modal } from "react-native";
591
586
 
592
587
  // src/methods/add-card.ts
593
588
  import { err, ok } from "@moonpay/platform-protocol/result";
@@ -876,8 +871,153 @@ function createMountSession(specCtx, host) {
876
871
  };
877
872
  }
878
873
 
879
- // src/provider.tsx
874
+ // src/VisibleFrameSlotSheet.tsx
875
+ import { useCallback, useEffect as useEffect2, useRef as useRef2, useState } from "react";
876
+ import {
877
+ ActivityIndicator,
878
+ Animated,
879
+ Easing,
880
+ Modal,
881
+ Platform,
882
+ Pressable,
883
+ StyleSheet,
884
+ Text,
885
+ useWindowDimensions,
886
+ View as View2
887
+ } from "react-native";
880
888
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
889
+ function animateSheet(value, toValue, onDone) {
890
+ const animation = Platform.OS === "android" ? Animated.timing(value, {
891
+ toValue,
892
+ duration: 250,
893
+ easing: Easing.out(Easing.exp),
894
+ useNativeDriver: true
895
+ }) : Animated.spring(value, {
896
+ toValue,
897
+ damping: 500,
898
+ stiffness: 1e3,
899
+ mass: 3,
900
+ overshootClamping: true,
901
+ restDisplacementThreshold: 10,
902
+ restSpeedThreshold: 10,
903
+ useNativeDriver: true
904
+ });
905
+ animation.start(onDone);
906
+ }
907
+ function VisibleFrameSlotSheet({
908
+ slot,
909
+ onClose
910
+ }) {
911
+ const { height } = useWindowDimensions();
912
+ const sheetHeight = Math.round(height * 0.9);
913
+ const translateY = useRef2(new Animated.Value(sheetHeight)).current;
914
+ const [frameReady, setFrameReady] = useState(false);
915
+ const onCloseRef = useRef2(onClose);
916
+ onCloseRef.current = onClose;
917
+ const closingRef = useRef2(false);
918
+ const close = useCallback(() => {
919
+ if (closingRef.current)
920
+ return;
921
+ closingRef.current = true;
922
+ animateSheet(translateY, sheetHeight, ({ finished }) => {
923
+ if (finished)
924
+ onCloseRef.current();
925
+ });
926
+ }, [translateY, sheetHeight]);
927
+ useEffect2(() => {
928
+ animateSheet(translateY, 0);
929
+ }, [translateY]);
930
+ useEffect2(() => {
931
+ const unsubscribe = slot.transport.onMessage((msg) => {
932
+ if (msg.kind === "ready")
933
+ setFrameReady(true);
934
+ else if (msg.kind === "complete" || msg.kind === "error")
935
+ close();
936
+ });
937
+ return unsubscribe;
938
+ }, [slot.transport, close]);
939
+ const backdropOpacity = translateY.interpolate({
940
+ inputRange: [0, sheetHeight],
941
+ outputRange: [1, 0],
942
+ extrapolate: "clamp"
943
+ });
944
+ return /* @__PURE__ */ jsx2(Modal, { visible: true, transparent: true, animationType: "none", onRequestClose: close, children: /* @__PURE__ */ jsxs(View2, { style: styles.root, children: [
945
+ /* @__PURE__ */ jsx2(Animated.View, { style: [styles.backdrop, { opacity: backdropOpacity }], children: /* @__PURE__ */ jsx2(
946
+ Pressable,
947
+ {
948
+ style: StyleSheet.absoluteFill,
949
+ accessibilityRole: "button",
950
+ accessibilityLabel: "Close",
951
+ onPress: close
952
+ }
953
+ ) }),
954
+ /* @__PURE__ */ jsxs(Animated.View, { style: [styles.sheet, { height: sheetHeight, transform: [{ translateY }] }], children: [
955
+ /* @__PURE__ */ jsx2(MoonPayFrame, { transport: slot.transport }),
956
+ !frameReady && /* @__PURE__ */ jsx2(View2, { style: styles.loading, children: /* @__PURE__ */ jsx2(ActivityIndicator, { size: "large", color: "#000" }) }),
957
+ /* @__PURE__ */ jsx2(
958
+ Pressable,
959
+ {
960
+ onPress: close,
961
+ accessibilityRole: "button",
962
+ accessibilityLabel: "Close",
963
+ hitSlop: 8,
964
+ style: styles.closeButton,
965
+ children: /* @__PURE__ */ jsx2(Text, { style: styles.closeButtonText, children: "\u2715" })
966
+ }
967
+ )
968
+ ] })
969
+ ] }) });
970
+ }
971
+ var styles = StyleSheet.create({
972
+ root: {
973
+ flex: 1,
974
+ justifyContent: "flex-end"
975
+ },
976
+ // Dimmed backdrop covering the whole screen; fades with the sheet position.
977
+ backdrop: {
978
+ ...StyleSheet.absoluteFillObject,
979
+ backgroundColor: "rgba(0, 0, 0, 0.5)"
980
+ },
981
+ // Bottom sheet: ~90% of the screen (height applied inline), rounded top
982
+ // corners. The 10% gap keeps the frame clear of the status bar / notch
983
+ // without depending on react-native-safe-area-context.
984
+ sheet: {
985
+ backgroundColor: "#fff",
986
+ borderTopLeftRadius: 24,
987
+ borderTopRightRadius: 24,
988
+ overflow: "hidden"
989
+ },
990
+ // Opaque cover with a centered spinner, shown until the frame is ready.
991
+ loading: {
992
+ ...StyleSheet.absoluteFillObject,
993
+ backgroundColor: "#fff",
994
+ alignItems: "center",
995
+ justifyContent: "center"
996
+ },
997
+ // Floating X in the top-right corner, over the frame.
998
+ closeButton: {
999
+ position: "absolute",
1000
+ top: 12,
1001
+ right: 12,
1002
+ width: 32,
1003
+ height: 32,
1004
+ borderRadius: 16,
1005
+ backgroundColor: "rgba(0, 0, 0, 0.06)",
1006
+ alignItems: "center",
1007
+ justifyContent: "center",
1008
+ zIndex: 1,
1009
+ elevation: 2
1010
+ },
1011
+ closeButtonText: {
1012
+ fontSize: 17,
1013
+ lineHeight: 20,
1014
+ color: "#000",
1015
+ fontWeight: "500"
1016
+ }
1017
+ });
1018
+
1019
+ // src/provider.tsx
1020
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
881
1021
  var MoonPayContext = createContext(null);
882
1022
  function MoonPayProvider({
883
1023
  sessionToken,
@@ -885,14 +1025,14 @@ function MoonPayProvider({
885
1025
  frameBaseUrl,
886
1026
  children
887
1027
  }) {
888
- const [frameSlots, setFrameSlots] = useState([]);
889
- const addSlot = useCallback((slot) => {
1028
+ const [frameSlots, setFrameSlots] = useState2([]);
1029
+ const addSlot = useCallback2((slot) => {
890
1030
  setFrameSlots((prev) => [...prev, slot]);
891
1031
  }, []);
892
- const removeSlot = useCallback((id) => {
1032
+ const removeSlot = useCallback2((id) => {
893
1033
  setFrameSlots((prev) => prev.filter((s) => s.id !== id));
894
1034
  }, []);
895
- const coreRef = useRef2(null);
1035
+ const coreRef = useRef3(null);
896
1036
  if (!coreRef.current) {
897
1037
  coreRef.current = createClientCore({
898
1038
  apiBaseUrl,
@@ -908,19 +1048,17 @@ function MoonPayProvider({
908
1048
  core
909
1049
  });
910
1050
  }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);
911
- return /* @__PURE__ */ jsxs(MoonPayContext.Provider, { value: { client, sessionToken, core, frameBaseUrl }, children: [
1051
+ return /* @__PURE__ */ jsxs2(MoonPayContext.Provider, { value: { client, sessionToken, core, frameBaseUrl }, children: [
912
1052
  children,
913
- frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ jsx2(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
914
- frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ jsx2(
915
- Modal,
1053
+ frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ jsx3(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
1054
+ frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ jsx3(
1055
+ VisibleFrameSlotSheet,
916
1056
  {
917
- visible: true,
918
- animationType: "slide",
919
- onRequestClose: () => {
1057
+ slot,
1058
+ onClose: () => {
920
1059
  slot.dispose();
921
1060
  removeSlot(slot.id);
922
- },
923
- children: /* @__PURE__ */ jsx2(MoonPayFrame, { transport: slot.transport })
1061
+ }
924
1062
  },
925
1063
  slot.id
926
1064
  ))
@@ -938,7 +1076,7 @@ function useMoonPay() {
938
1076
  }
939
1077
 
940
1078
  // src/frame-view.tsx
941
- import { jsx as jsx3 } from "react/jsx-runtime";
1079
+ import { jsx as jsx4 } from "react/jsx-runtime";
942
1080
  function applyReactiveProps(spec, keys, props, applied, handle) {
943
1081
  for (const key of keys) {
944
1082
  const next = props[key];
@@ -956,11 +1094,11 @@ function MoonPayFrameView({
956
1094
  onEvent
957
1095
  }) {
958
1096
  const { sessionToken, core, frameBaseUrl } = useMoonPayContext();
959
- const [transport, setTransport] = useState2(null);
960
- const handleRef = useRef3(null);
961
- const onEventRef = useRef3(onEvent);
1097
+ const [transport, setTransport] = useState3(null);
1098
+ const handleRef = useRef4(null);
1099
+ const onEventRef = useRef4(onEvent);
962
1100
  onEventRef.current = onEvent;
963
- const propsRef = useRef3(props);
1101
+ const propsRef = useRef4(props);
964
1102
  propsRef.current = props;
965
1103
  const reactiveKeys = Object.keys(spec.reactiveProps ?? {});
966
1104
  const mountProps = {};
@@ -971,8 +1109,8 @@ function MoonPayFrameView({
971
1109
  }
972
1110
  const mountKey = JSON.stringify(mountProps);
973
1111
  const liveKey = JSON.stringify(liveProps);
974
- const appliedRef = useRef3({});
975
- useEffect2(() => {
1112
+ const appliedRef = useRef4({});
1113
+ useEffect3(() => {
976
1114
  let disposed = false;
977
1115
  let session;
978
1116
  const applied = {};
@@ -1011,23 +1149,23 @@ function MoonPayFrameView({
1011
1149
  setTransport(null);
1012
1150
  };
1013
1151
  }, [mountKey, spec, sessionToken, core, frameBaseUrl]);
1014
- useEffect2(() => {
1152
+ useEffect3(() => {
1015
1153
  const handle = handleRef.current;
1016
1154
  if (!handle)
1017
1155
  return;
1018
1156
  applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
1019
1157
  }, [liveKey]);
1020
1158
  if (spec.hidden) {
1021
- return transport ? /* @__PURE__ */ jsx3(MoonPayFrame, { transport, hidden: true }) : null;
1159
+ return transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport, hidden: true }) : null;
1022
1160
  }
1023
1161
  const resolvedStyle = { ...defaultStyle, ...style };
1024
- return /* @__PURE__ */ jsx3(View2, { style: resolvedStyle, children: transport ? /* @__PURE__ */ jsx3(MoonPayFrame, { transport }) : null });
1162
+ return /* @__PURE__ */ jsx4(View3, { style: resolvedStyle, children: transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport }) : null });
1025
1163
  }
1026
1164
 
1027
1165
  // src/components/add-card.tsx
1028
- import { jsx as jsx4 } from "react/jsx-runtime";
1166
+ import { jsx as jsx5 } from "react/jsx-runtime";
1029
1167
  function MoonPayAddCard({ onEvent, style }) {
1030
- return /* @__PURE__ */ jsx4(
1168
+ return /* @__PURE__ */ jsx5(
1031
1169
  MoonPayFrameView,
1032
1170
  {
1033
1171
  spec: addCardSpec,
@@ -1040,13 +1178,13 @@ function MoonPayAddCard({ onEvent, style }) {
1040
1178
  }
1041
1179
 
1042
1180
  // src/components/apple-pay-button.tsx
1043
- import { jsx as jsx5 } from "react/jsx-runtime";
1181
+ import { jsx as jsx6 } from "react/jsx-runtime";
1044
1182
  function MoonPayApplePayButton({
1045
1183
  quote,
1046
1184
  onEvent,
1047
1185
  style
1048
1186
  }) {
1049
- return /* @__PURE__ */ jsx5(
1187
+ return /* @__PURE__ */ jsx6(
1050
1188
  MoonPayFrameView,
1051
1189
  {
1052
1190
  spec: applePaySpec,
@@ -1059,9 +1197,9 @@ function MoonPayApplePayButton({
1059
1197
  }
1060
1198
 
1061
1199
  // src/components/auth.tsx
1062
- import { jsx as jsx6 } from "react/jsx-runtime";
1200
+ import { jsx as jsx7 } from "react/jsx-runtime";
1063
1201
  function MoonPayAuth({ onEvent, style }) {
1064
- return /* @__PURE__ */ jsx6(
1202
+ return /* @__PURE__ */ jsx7(
1065
1203
  MoonPayFrameView,
1066
1204
  {
1067
1205
  spec: authSpec,
@@ -1074,9 +1212,9 @@ function MoonPayAuth({ onEvent, style }) {
1074
1212
  }
1075
1213
 
1076
1214
  // src/components/buy-button.tsx
1077
- import { jsx as jsx7 } from "react/jsx-runtime";
1215
+ import { jsx as jsx8 } from "react/jsx-runtime";
1078
1216
  function MoonPayBuyButton({ quote, onEvent, style }) {
1079
- return /* @__PURE__ */ jsx7(
1217
+ return /* @__PURE__ */ jsx8(
1080
1218
  MoonPayFrameView,
1081
1219
  {
1082
1220
  spec: buyButtonSpec,
@@ -1089,13 +1227,13 @@ function MoonPayBuyButton({ quote, onEvent, style }) {
1089
1227
  }
1090
1228
 
1091
1229
  // src/components/buy-frame.tsx
1092
- import { jsx as jsx8 } from "react/jsx-runtime";
1230
+ import { jsx as jsx9 } from "react/jsx-runtime";
1093
1231
  function MoonPayBuyFrame({
1094
1232
  quote,
1095
1233
  externalTransactionId,
1096
1234
  onEvent
1097
1235
  }) {
1098
- return /* @__PURE__ */ jsx8(
1236
+ return /* @__PURE__ */ jsx9(
1099
1237
  MoonPayFrameView,
1100
1238
  {
1101
1239
  spec: buySpec,
@@ -1107,9 +1245,9 @@ function MoonPayBuyFrame({
1107
1245
  }
1108
1246
 
1109
1247
  // src/components/challenge.tsx
1110
- import { jsx as jsx9 } from "react/jsx-runtime";
1248
+ import { jsx as jsx10 } from "react/jsx-runtime";
1111
1249
  function MoonPayChallenge({ url, onEvent, style }) {
1112
- return /* @__PURE__ */ jsx9(
1250
+ return /* @__PURE__ */ jsx10(
1113
1251
  MoonPayFrameView,
1114
1252
  {
1115
1253
  spec: challengeSpec,
@@ -1122,9 +1260,9 @@ function MoonPayChallenge({ url, onEvent, style }) {
1122
1260
  }
1123
1261
 
1124
1262
  // src/components/connect.tsx
1125
- import { jsx as jsx10 } from "react/jsx-runtime";
1263
+ import { jsx as jsx11 } from "react/jsx-runtime";
1126
1264
  function MoonPayConnect({ theme, onEvent, style }) {
1127
- return /* @__PURE__ */ jsx10(
1265
+ return /* @__PURE__ */ jsx11(
1128
1266
  MoonPayFrameView,
1129
1267
  {
1130
1268
  spec: connectSpec,
@@ -1137,12 +1275,12 @@ function MoonPayConnect({ theme, onEvent, style }) {
1137
1275
  }
1138
1276
 
1139
1277
  // src/components/connection-check.tsx
1140
- import { jsx as jsx11 } from "react/jsx-runtime";
1278
+ import { jsx as jsx12 } from "react/jsx-runtime";
1141
1279
  function MoonPayConnectionCheck({
1142
1280
  skipKyc,
1143
1281
  onEvent
1144
1282
  }) {
1145
- return /* @__PURE__ */ jsx11(
1283
+ return /* @__PURE__ */ jsx12(
1146
1284
  MoonPayFrameView,
1147
1285
  {
1148
1286
  spec: connectionCheckSpec,
@@ -1154,20 +1292,20 @@ function MoonPayConnectionCheck({
1154
1292
  }
1155
1293
 
1156
1294
  // src/components/connection-reset.tsx
1157
- import { jsx as jsx12 } from "react/jsx-runtime";
1295
+ import { jsx as jsx13 } from "react/jsx-runtime";
1158
1296
  function MoonPayConnectionReset({ onEvent }) {
1159
- return /* @__PURE__ */ jsx12(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
1297
+ return /* @__PURE__ */ jsx13(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
1160
1298
  }
1161
1299
 
1162
1300
  // src/components/google-pay-button.tsx
1163
- import { jsx as jsx13 } from "react/jsx-runtime";
1301
+ import { jsx as jsx14 } from "react/jsx-runtime";
1164
1302
  function MoonPayGooglePayButton({
1165
1303
  quote,
1166
1304
  externalTransactionId,
1167
1305
  onEvent,
1168
1306
  style
1169
1307
  }) {
1170
- return /* @__PURE__ */ jsx13(
1308
+ return /* @__PURE__ */ jsx14(
1171
1309
  MoonPayFrameView,
1172
1310
  {
1173
1311
  spec: googlePaySpec,
@@ -1180,9 +1318,9 @@ function MoonPayGooglePayButton({
1180
1318
  }
1181
1319
 
1182
1320
  // src/components/widget.tsx
1183
- import { jsx as jsx14 } from "react/jsx-runtime";
1321
+ import { jsx as jsx15 } from "react/jsx-runtime";
1184
1322
  function MoonPayWidget({ quote, onEvent, style }) {
1185
- return /* @__PURE__ */ jsx14(
1323
+ return /* @__PURE__ */ jsx15(
1186
1324
  MoonPayFrameView,
1187
1325
  {
1188
1326
  spec: widgetSpec,