@moonpay/platform-sdk-react-native 1.0.3 → 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.cjs CHANGED
@@ -416,7 +416,7 @@ var connectionResetSpec = {
416
416
  };
417
417
 
418
418
  // src/frame-view.tsx
419
- var import_react3 = require("react");
419
+ var import_react4 = require("react");
420
420
  var import_react_native3 = require("react-native");
421
421
 
422
422
  // src/frame-component.tsx
@@ -617,8 +617,7 @@ function createFrameSession(spec, ctx, props, overrides = {}) {
617
617
 
618
618
  // src/provider.tsx
619
619
  var import_platform_sdk_core3 = require("@moonpay/platform-sdk-core");
620
- var import_react2 = require("react");
621
- var import_react_native2 = require("react-native");
620
+ var import_react3 = require("react");
622
621
 
623
622
  // src/methods/add-card.ts
624
623
  var import_result = require("@moonpay/platform-protocol/result");
@@ -907,23 +906,157 @@ function createMountSession(specCtx, host) {
907
906
  };
908
907
  }
909
908
 
910
- // src/provider.tsx
909
+ // src/VisibleFrameSlotSheet.tsx
910
+ var import_react2 = require("react");
911
+ var import_react_native2 = require("react-native");
911
912
  var import_jsx_runtime2 = require("react/jsx-runtime");
912
- var MoonPayContext = (0, import_react2.createContext)(null);
913
+ function animateSheet(value, toValue, onDone) {
914
+ const animation = import_react_native2.Platform.OS === "android" ? import_react_native2.Animated.timing(value, {
915
+ toValue,
916
+ duration: 250,
917
+ easing: import_react_native2.Easing.out(import_react_native2.Easing.exp),
918
+ useNativeDriver: true
919
+ }) : import_react_native2.Animated.spring(value, {
920
+ toValue,
921
+ damping: 500,
922
+ stiffness: 1e3,
923
+ mass: 3,
924
+ overshootClamping: true,
925
+ restDisplacementThreshold: 10,
926
+ restSpeedThreshold: 10,
927
+ useNativeDriver: true
928
+ });
929
+ animation.start(onDone);
930
+ }
931
+ function VisibleFrameSlotSheet({
932
+ slot,
933
+ onClose
934
+ }) {
935
+ const { height } = (0, import_react_native2.useWindowDimensions)();
936
+ const sheetHeight = Math.round(height * 0.9);
937
+ const translateY = (0, import_react2.useRef)(new import_react_native2.Animated.Value(sheetHeight)).current;
938
+ const [frameReady, setFrameReady] = (0, import_react2.useState)(false);
939
+ const onCloseRef = (0, import_react2.useRef)(onClose);
940
+ onCloseRef.current = onClose;
941
+ const closingRef = (0, import_react2.useRef)(false);
942
+ const close = (0, import_react2.useCallback)(() => {
943
+ if (closingRef.current)
944
+ return;
945
+ closingRef.current = true;
946
+ animateSheet(translateY, sheetHeight, ({ finished }) => {
947
+ if (finished)
948
+ onCloseRef.current();
949
+ });
950
+ }, [translateY, sheetHeight]);
951
+ (0, import_react2.useEffect)(() => {
952
+ animateSheet(translateY, 0);
953
+ }, [translateY]);
954
+ (0, import_react2.useEffect)(() => {
955
+ const unsubscribe = slot.transport.onMessage((msg) => {
956
+ if (msg.kind === "ready")
957
+ setFrameReady(true);
958
+ else if (msg.kind === "complete" || msg.kind === "error")
959
+ close();
960
+ });
961
+ return unsubscribe;
962
+ }, [slot.transport, close]);
963
+ const backdropOpacity = translateY.interpolate({
964
+ inputRange: [0, sheetHeight],
965
+ outputRange: [1, 0],
966
+ extrapolate: "clamp"
967
+ });
968
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Modal, { visible: true, transparent: true, animationType: "none", onRequestClose: close, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.root, children: [
969
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Animated.View, { style: [styles.backdrop, { opacity: backdropOpacity }], children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
970
+ import_react_native2.Pressable,
971
+ {
972
+ style: import_react_native2.StyleSheet.absoluteFill,
973
+ accessibilityRole: "button",
974
+ accessibilityLabel: "Close",
975
+ onPress: close
976
+ }
977
+ ) }),
978
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.Animated.View, { style: [styles.sheet, { height: sheetHeight, transform: [{ translateY }] }], children: [
979
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonPayFrame, { transport: slot.transport }),
980
+ !frameReady && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles.loading, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.ActivityIndicator, { size: "large", color: "#000" }) }),
981
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
982
+ import_react_native2.Pressable,
983
+ {
984
+ onPress: close,
985
+ accessibilityRole: "button",
986
+ accessibilityLabel: "Close",
987
+ hitSlop: 8,
988
+ style: styles.closeButton,
989
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles.closeButtonText, children: "\u2715" })
990
+ }
991
+ )
992
+ ] })
993
+ ] }) });
994
+ }
995
+ var styles = import_react_native2.StyleSheet.create({
996
+ root: {
997
+ flex: 1,
998
+ justifyContent: "flex-end"
999
+ },
1000
+ // Dimmed backdrop covering the whole screen; fades with the sheet position.
1001
+ backdrop: {
1002
+ ...import_react_native2.StyleSheet.absoluteFillObject,
1003
+ backgroundColor: "rgba(0, 0, 0, 0.5)"
1004
+ },
1005
+ // Bottom sheet: ~90% of the screen (height applied inline), rounded top
1006
+ // corners. The 10% gap keeps the frame clear of the status bar / notch
1007
+ // without depending on react-native-safe-area-context.
1008
+ sheet: {
1009
+ backgroundColor: "#fff",
1010
+ borderTopLeftRadius: 24,
1011
+ borderTopRightRadius: 24,
1012
+ overflow: "hidden"
1013
+ },
1014
+ // Opaque cover with a centered spinner, shown until the frame is ready.
1015
+ loading: {
1016
+ ...import_react_native2.StyleSheet.absoluteFillObject,
1017
+ backgroundColor: "#fff",
1018
+ alignItems: "center",
1019
+ justifyContent: "center"
1020
+ },
1021
+ // Floating X in the top-right corner, over the frame.
1022
+ closeButton: {
1023
+ position: "absolute",
1024
+ top: 12,
1025
+ right: 12,
1026
+ width: 32,
1027
+ height: 32,
1028
+ borderRadius: 16,
1029
+ backgroundColor: "rgba(0, 0, 0, 0.06)",
1030
+ alignItems: "center",
1031
+ justifyContent: "center",
1032
+ zIndex: 1,
1033
+ elevation: 2
1034
+ },
1035
+ closeButtonText: {
1036
+ fontSize: 17,
1037
+ lineHeight: 20,
1038
+ color: "#000",
1039
+ fontWeight: "500"
1040
+ }
1041
+ });
1042
+
1043
+ // src/provider.tsx
1044
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1045
+ var MoonPayContext = (0, import_react3.createContext)(null);
913
1046
  function MoonPayProvider({
914
1047
  sessionToken,
915
1048
  apiBaseUrl,
916
1049
  frameBaseUrl,
917
1050
  children
918
1051
  }) {
919
- const [frameSlots, setFrameSlots] = (0, import_react2.useState)([]);
920
- const addSlot = (0, import_react2.useCallback)((slot) => {
1052
+ const [frameSlots, setFrameSlots] = (0, import_react3.useState)([]);
1053
+ const addSlot = (0, import_react3.useCallback)((slot) => {
921
1054
  setFrameSlots((prev) => [...prev, slot]);
922
1055
  }, []);
923
- const removeSlot = (0, import_react2.useCallback)((id) => {
1056
+ const removeSlot = (0, import_react3.useCallback)((id) => {
924
1057
  setFrameSlots((prev) => prev.filter((s) => s.id !== id));
925
1058
  }, []);
926
- const coreRef = (0, import_react2.useRef)(null);
1059
+ const coreRef = (0, import_react3.useRef)(null);
927
1060
  if (!coreRef.current) {
928
1061
  coreRef.current = (0, import_platform_sdk_core3.createClientCore)({
929
1062
  apiBaseUrl,
@@ -932,33 +1065,31 @@ function MoonPayProvider({
932
1065
  });
933
1066
  }
934
1067
  const core = coreRef.current;
935
- const client = (0, import_react2.useMemo)(() => {
1068
+ const client = (0, import_react3.useMemo)(() => {
936
1069
  const specCtx = { sessionToken, core, frameBaseUrl };
937
1070
  return createRNClient({
938
1071
  mountSession: createMountSession(specCtx, { addSlot, removeSlot }),
939
1072
  core
940
1073
  });
941
1074
  }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);
942
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(MoonPayContext.Provider, { value: { client, sessionToken, core, frameBaseUrl }, children: [
1075
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(MoonPayContext.Provider, { value: { client, sessionToken, core, frameBaseUrl }, children: [
943
1076
  children,
944
- frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
945
- frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
946
- import_react_native2.Modal,
1077
+ frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
1078
+ frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1079
+ VisibleFrameSlotSheet,
947
1080
  {
948
- visible: true,
949
- animationType: "slide",
950
- onRequestClose: () => {
1081
+ slot,
1082
+ onClose: () => {
951
1083
  slot.dispose();
952
1084
  removeSlot(slot.id);
953
- },
954
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonPayFrame, { transport: slot.transport })
1085
+ }
955
1086
  },
956
1087
  slot.id
957
1088
  ))
958
1089
  ] });
959
1090
  }
960
1091
  function useMoonPayContext() {
961
- const ctx = (0, import_react2.useContext)(MoonPayContext);
1092
+ const ctx = (0, import_react3.useContext)(MoonPayContext);
962
1093
  if (!ctx) {
963
1094
  throw new Error("useMoonPay must be used within a <MoonPayProvider>");
964
1095
  }
@@ -969,7 +1100,7 @@ function useMoonPay() {
969
1100
  }
970
1101
 
971
1102
  // src/frame-view.tsx
972
- var import_jsx_runtime3 = require("react/jsx-runtime");
1103
+ var import_jsx_runtime4 = require("react/jsx-runtime");
973
1104
  function applyReactiveProps(spec, keys, props, applied, handle) {
974
1105
  for (const key of keys) {
975
1106
  const next = props[key];
@@ -987,11 +1118,11 @@ function MoonPayFrameView({
987
1118
  onEvent
988
1119
  }) {
989
1120
  const { sessionToken, core, frameBaseUrl } = useMoonPayContext();
990
- const [transport, setTransport] = (0, import_react3.useState)(null);
991
- const handleRef = (0, import_react3.useRef)(null);
992
- const onEventRef = (0, import_react3.useRef)(onEvent);
1121
+ const [transport, setTransport] = (0, import_react4.useState)(null);
1122
+ const handleRef = (0, import_react4.useRef)(null);
1123
+ const onEventRef = (0, import_react4.useRef)(onEvent);
993
1124
  onEventRef.current = onEvent;
994
- const propsRef = (0, import_react3.useRef)(props);
1125
+ const propsRef = (0, import_react4.useRef)(props);
995
1126
  propsRef.current = props;
996
1127
  const reactiveKeys = Object.keys(spec.reactiveProps ?? {});
997
1128
  const mountProps = {};
@@ -1002,8 +1133,8 @@ function MoonPayFrameView({
1002
1133
  }
1003
1134
  const mountKey = JSON.stringify(mountProps);
1004
1135
  const liveKey = JSON.stringify(liveProps);
1005
- const appliedRef = (0, import_react3.useRef)({});
1006
- (0, import_react3.useEffect)(() => {
1136
+ const appliedRef = (0, import_react4.useRef)({});
1137
+ (0, import_react4.useEffect)(() => {
1007
1138
  let disposed = false;
1008
1139
  let session;
1009
1140
  const applied = {};
@@ -1042,23 +1173,23 @@ function MoonPayFrameView({
1042
1173
  setTransport(null);
1043
1174
  };
1044
1175
  }, [mountKey, spec, sessionToken, core, frameBaseUrl]);
1045
- (0, import_react3.useEffect)(() => {
1176
+ (0, import_react4.useEffect)(() => {
1046
1177
  const handle = handleRef.current;
1047
1178
  if (!handle)
1048
1179
  return;
1049
1180
  applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
1050
1181
  }, [liveKey]);
1051
1182
  if (spec.hidden) {
1052
- return transport ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MoonPayFrame, { transport, hidden: true }) : null;
1183
+ return transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport, hidden: true }) : null;
1053
1184
  }
1054
1185
  const resolvedStyle = { ...defaultStyle, ...style };
1055
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native3.View, { style: resolvedStyle, children: transport ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MoonPayFrame, { transport }) : null });
1186
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: resolvedStyle, children: transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport }) : null });
1056
1187
  }
1057
1188
 
1058
1189
  // src/components/add-card.tsx
1059
- var import_jsx_runtime4 = require("react/jsx-runtime");
1190
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1060
1191
  function MoonPayAddCard({ onEvent, style }) {
1061
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1192
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1062
1193
  MoonPayFrameView,
1063
1194
  {
1064
1195
  spec: addCardSpec,
@@ -1071,13 +1202,13 @@ function MoonPayAddCard({ onEvent, style }) {
1071
1202
  }
1072
1203
 
1073
1204
  // src/components/apple-pay-button.tsx
1074
- var import_jsx_runtime5 = require("react/jsx-runtime");
1205
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1075
1206
  function MoonPayApplePayButton({
1076
1207
  quote,
1077
1208
  onEvent,
1078
1209
  style
1079
1210
  }) {
1080
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1211
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1081
1212
  MoonPayFrameView,
1082
1213
  {
1083
1214
  spec: applePaySpec,
@@ -1090,9 +1221,9 @@ function MoonPayApplePayButton({
1090
1221
  }
1091
1222
 
1092
1223
  // src/components/auth.tsx
1093
- var import_jsx_runtime6 = require("react/jsx-runtime");
1224
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1094
1225
  function MoonPayAuth({ onEvent, style }) {
1095
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1226
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1096
1227
  MoonPayFrameView,
1097
1228
  {
1098
1229
  spec: authSpec,
@@ -1105,9 +1236,9 @@ function MoonPayAuth({ onEvent, style }) {
1105
1236
  }
1106
1237
 
1107
1238
  // src/components/buy-button.tsx
1108
- var import_jsx_runtime7 = require("react/jsx-runtime");
1239
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1109
1240
  function MoonPayBuyButton({ quote, onEvent, style }) {
1110
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1241
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1111
1242
  MoonPayFrameView,
1112
1243
  {
1113
1244
  spec: buyButtonSpec,
@@ -1120,13 +1251,13 @@ function MoonPayBuyButton({ quote, onEvent, style }) {
1120
1251
  }
1121
1252
 
1122
1253
  // src/components/buy-frame.tsx
1123
- var import_jsx_runtime8 = require("react/jsx-runtime");
1254
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1124
1255
  function MoonPayBuyFrame({
1125
1256
  quote,
1126
1257
  externalTransactionId,
1127
1258
  onEvent
1128
1259
  }) {
1129
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1260
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1130
1261
  MoonPayFrameView,
1131
1262
  {
1132
1263
  spec: buySpec,
@@ -1138,9 +1269,9 @@ function MoonPayBuyFrame({
1138
1269
  }
1139
1270
 
1140
1271
  // src/components/challenge.tsx
1141
- var import_jsx_runtime9 = require("react/jsx-runtime");
1272
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1142
1273
  function MoonPayChallenge({ url, onEvent, style }) {
1143
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1274
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1144
1275
  MoonPayFrameView,
1145
1276
  {
1146
1277
  spec: challengeSpec,
@@ -1153,9 +1284,9 @@ function MoonPayChallenge({ url, onEvent, style }) {
1153
1284
  }
1154
1285
 
1155
1286
  // src/components/connect.tsx
1156
- var import_jsx_runtime10 = require("react/jsx-runtime");
1287
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1157
1288
  function MoonPayConnect({ theme, onEvent, style }) {
1158
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1289
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1159
1290
  MoonPayFrameView,
1160
1291
  {
1161
1292
  spec: connectSpec,
@@ -1168,12 +1299,12 @@ function MoonPayConnect({ theme, onEvent, style }) {
1168
1299
  }
1169
1300
 
1170
1301
  // src/components/connection-check.tsx
1171
- var import_jsx_runtime11 = require("react/jsx-runtime");
1302
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1172
1303
  function MoonPayConnectionCheck({
1173
1304
  skipKyc,
1174
1305
  onEvent
1175
1306
  }) {
1176
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1307
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1177
1308
  MoonPayFrameView,
1178
1309
  {
1179
1310
  spec: connectionCheckSpec,
@@ -1185,20 +1316,20 @@ function MoonPayConnectionCheck({
1185
1316
  }
1186
1317
 
1187
1318
  // src/components/connection-reset.tsx
1188
- var import_jsx_runtime12 = require("react/jsx-runtime");
1319
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1189
1320
  function MoonPayConnectionReset({ onEvent }) {
1190
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
1321
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
1191
1322
  }
1192
1323
 
1193
1324
  // src/components/google-pay-button.tsx
1194
- var import_jsx_runtime13 = require("react/jsx-runtime");
1325
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1195
1326
  function MoonPayGooglePayButton({
1196
1327
  quote,
1197
1328
  externalTransactionId,
1198
1329
  onEvent,
1199
1330
  style
1200
1331
  }) {
1201
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1332
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1202
1333
  MoonPayFrameView,
1203
1334
  {
1204
1335
  spec: googlePaySpec,
@@ -1211,9 +1342,9 @@ function MoonPayGooglePayButton({
1211
1342
  }
1212
1343
 
1213
1344
  // src/components/widget.tsx
1214
- var import_jsx_runtime14 = require("react/jsx-runtime");
1345
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1215
1346
  function MoonPayWidget({ quote, onEvent, style }) {
1216
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1347
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1217
1348
  MoonPayFrameView,
1218
1349
  {
1219
1350
  spec: widgetSpec,