@moonpay/platform-sdk-react-native 1.0.3 → 1.2.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/README.md +2 -0
- package/dist/index.cjs +228 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -10
- package/dist/index.d.ts +9 -10
- package/dist/index.js +247 -61
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -24,10 +24,11 @@ import * as GooglePaySdk from '@moonpay/platform-protocol/sdks/google-pay';
|
|
|
24
24
|
export { Event as GooglePayEvent, SetupError as SetupGooglePayError } from '@moonpay/platform-protocol/sdks/google-pay';
|
|
25
25
|
import * as WidgetSdk from '@moonpay/platform-protocol/sdks/widget';
|
|
26
26
|
export { SetupError as SetupWidgetError, Event as WidgetEvent } from '@moonpay/platform-protocol/sdks/widget';
|
|
27
|
+
import { FrameTransport, FrameOptions, ThemeOptions, ListTransactionsParams } from '@moonpay/platform-sdk-core';
|
|
28
|
+
export { ThemeOptions } from '@moonpay/platform-sdk-core';
|
|
27
29
|
import { GetPaymentMethodsError, GetQuoteError, GetTransactionsError, DevPlatformApiError, CreateIdentityError, GetIdentityError, UpdateIdentityError, VerifyIdentityError, GetIdentityUploadUrlError, SubmitIdentityFilesError } from '@moonpay/platform-protocol/api/errors';
|
|
28
30
|
import { CreateIdentityRequestBody, Identity, UpdateIdentityRequestBody, IdentityVerificationResponse, IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentityFilesRequestBody } from '@moonpay/platform-protocol/api/identity';
|
|
29
31
|
import { ResetConnectionError } from '@moonpay/platform-protocol/sdks/reset';
|
|
30
|
-
import { FrameTransport, FrameOptions, ListTransactionsParams } from '@moonpay/platform-sdk-core';
|
|
31
32
|
import { ViewStyle } from 'react-native';
|
|
32
33
|
import { ProtocolMessage } from '@moonpay/platform-protocol/protocol';
|
|
33
34
|
import { RefObject, ReactNode } from 'react';
|
|
@@ -132,10 +133,8 @@ interface ChallengeFrame {
|
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
interface ConnectOptions {
|
|
135
|
-
/** Theme
|
|
136
|
-
theme?:
|
|
137
|
-
appearance?: 'light' | 'dark';
|
|
138
|
-
};
|
|
136
|
+
/** Theme for this connect frame. Overrides the provider-level `theme`. */
|
|
137
|
+
theme?: ThemeOptions;
|
|
139
138
|
/** Callback for connect lifecycle events. */
|
|
140
139
|
onEvent?: (event: ConnectSdk.Event) => void;
|
|
141
140
|
}
|
|
@@ -306,10 +305,8 @@ interface MoonPayChallengeProps {
|
|
|
306
305
|
declare function MoonPayChallenge({ url, onEvent, style }: MoonPayChallengeProps): JSX.Element;
|
|
307
306
|
|
|
308
307
|
interface MoonPayConnectProps {
|
|
309
|
-
/** Theme
|
|
310
|
-
theme?:
|
|
311
|
-
appearance?: 'light' | 'dark';
|
|
312
|
-
};
|
|
308
|
+
/** Theme for this connect frame. Overrides the provider-level `theme`. Mount-time only. */
|
|
309
|
+
theme?: ThemeOptions;
|
|
313
310
|
/** Callback for connect lifecycle events. */
|
|
314
311
|
onEvent?: (event: ConnectSdk.Event) => void;
|
|
315
312
|
/** Container style. Defaults to flex: 1. */
|
|
@@ -398,9 +395,11 @@ interface MoonPayProviderProps {
|
|
|
398
395
|
sessionToken: string;
|
|
399
396
|
apiBaseUrl?: string;
|
|
400
397
|
frameBaseUrl?: string;
|
|
398
|
+
/** Theme applied to every visible MoonPay frame (connect, widget, Apple/Google Pay, …). */
|
|
399
|
+
theme?: ThemeOptions;
|
|
401
400
|
children: ReactNode;
|
|
402
401
|
}
|
|
403
|
-
declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, children, }: MoonPayProviderProps): JSX.Element;
|
|
402
|
+
declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
404
403
|
declare function useMoonPay(): {
|
|
405
404
|
client: RNClient;
|
|
406
405
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -24,10 +24,11 @@ import * as GooglePaySdk from '@moonpay/platform-protocol/sdks/google-pay';
|
|
|
24
24
|
export { Event as GooglePayEvent, SetupError as SetupGooglePayError } from '@moonpay/platform-protocol/sdks/google-pay';
|
|
25
25
|
import * as WidgetSdk from '@moonpay/platform-protocol/sdks/widget';
|
|
26
26
|
export { SetupError as SetupWidgetError, Event as WidgetEvent } from '@moonpay/platform-protocol/sdks/widget';
|
|
27
|
+
import { FrameTransport, FrameOptions, ThemeOptions, ListTransactionsParams } from '@moonpay/platform-sdk-core';
|
|
28
|
+
export { ThemeOptions } from '@moonpay/platform-sdk-core';
|
|
27
29
|
import { GetPaymentMethodsError, GetQuoteError, GetTransactionsError, DevPlatformApiError, CreateIdentityError, GetIdentityError, UpdateIdentityError, VerifyIdentityError, GetIdentityUploadUrlError, SubmitIdentityFilesError } from '@moonpay/platform-protocol/api/errors';
|
|
28
30
|
import { CreateIdentityRequestBody, Identity, UpdateIdentityRequestBody, IdentityVerificationResponse, IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentityFilesRequestBody } from '@moonpay/platform-protocol/api/identity';
|
|
29
31
|
import { ResetConnectionError } from '@moonpay/platform-protocol/sdks/reset';
|
|
30
|
-
import { FrameTransport, FrameOptions, ListTransactionsParams } from '@moonpay/platform-sdk-core';
|
|
31
32
|
import { ViewStyle } from 'react-native';
|
|
32
33
|
import { ProtocolMessage } from '@moonpay/platform-protocol/protocol';
|
|
33
34
|
import { RefObject, ReactNode } from 'react';
|
|
@@ -132,10 +133,8 @@ interface ChallengeFrame {
|
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
interface ConnectOptions {
|
|
135
|
-
/** Theme
|
|
136
|
-
theme?:
|
|
137
|
-
appearance?: 'light' | 'dark';
|
|
138
|
-
};
|
|
136
|
+
/** Theme for this connect frame. Overrides the provider-level `theme`. */
|
|
137
|
+
theme?: ThemeOptions;
|
|
139
138
|
/** Callback for connect lifecycle events. */
|
|
140
139
|
onEvent?: (event: ConnectSdk.Event) => void;
|
|
141
140
|
}
|
|
@@ -306,10 +305,8 @@ interface MoonPayChallengeProps {
|
|
|
306
305
|
declare function MoonPayChallenge({ url, onEvent, style }: MoonPayChallengeProps): JSX.Element;
|
|
307
306
|
|
|
308
307
|
interface MoonPayConnectProps {
|
|
309
|
-
/** Theme
|
|
310
|
-
theme?:
|
|
311
|
-
appearance?: 'light' | 'dark';
|
|
312
|
-
};
|
|
308
|
+
/** Theme for this connect frame. Overrides the provider-level `theme`. Mount-time only. */
|
|
309
|
+
theme?: ThemeOptions;
|
|
313
310
|
/** Callback for connect lifecycle events. */
|
|
314
311
|
onEvent?: (event: ConnectSdk.Event) => void;
|
|
315
312
|
/** Container style. Defaults to flex: 1. */
|
|
@@ -398,9 +395,11 @@ interface MoonPayProviderProps {
|
|
|
398
395
|
sessionToken: string;
|
|
399
396
|
apiBaseUrl?: string;
|
|
400
397
|
frameBaseUrl?: string;
|
|
398
|
+
/** Theme applied to every visible MoonPay frame (connect, widget, Apple/Google Pay, …). */
|
|
399
|
+
theme?: ThemeOptions;
|
|
401
400
|
children: ReactNode;
|
|
402
401
|
}
|
|
403
|
-
declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, children, }: MoonPayProviderProps): JSX.Element;
|
|
402
|
+
declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
404
403
|
declare function useMoonPay(): {
|
|
405
404
|
client: RNClient;
|
|
406
405
|
};
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,11 @@ import {
|
|
|
6
6
|
ConnectionErrorCode,
|
|
7
7
|
ConnectionStatus
|
|
8
8
|
} from "@moonpay/platform-protocol/models/connection";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
decryptCredentials,
|
|
11
|
+
FRAME_PATHS,
|
|
12
|
+
themeParams
|
|
13
|
+
} from "@moonpay/platform-sdk-core";
|
|
10
14
|
function createQuoteCommands(send, channelId) {
|
|
11
15
|
return {
|
|
12
16
|
setQuote: (signature) => send({
|
|
@@ -174,7 +178,9 @@ var connectSpec = {
|
|
|
174
178
|
buildParams: (ctx, props, publicKey) => ({
|
|
175
179
|
sessionToken: ctx.sessionToken,
|
|
176
180
|
publicKey,
|
|
177
|
-
|
|
181
|
+
// Per-call override; `applyThemeParam` in the engine fills the client
|
|
182
|
+
// default for connect (and every other visible frame) when this is absent.
|
|
183
|
+
...themeParams(props.theme)
|
|
178
184
|
}),
|
|
179
185
|
onMessageEffect: applyCredentialsOnComplete,
|
|
180
186
|
mapMessage: (msg) => {
|
|
@@ -370,8 +376,8 @@ var connectionResetSpec = {
|
|
|
370
376
|
};
|
|
371
377
|
|
|
372
378
|
// src/frame-view.tsx
|
|
373
|
-
import { useEffect as
|
|
374
|
-
import { View as
|
|
379
|
+
import { useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "react";
|
|
380
|
+
import { View as View3 } from "react-native";
|
|
375
381
|
|
|
376
382
|
// src/frame-component.tsx
|
|
377
383
|
import { useEffect, useRef } from "react";
|
|
@@ -408,6 +414,7 @@ function MoonPayFrame({ transport, hidden, style }) {
|
|
|
408
414
|
|
|
409
415
|
// src/frame-engine.ts
|
|
410
416
|
import {
|
|
417
|
+
applyThemeParam,
|
|
411
418
|
buildFrameUrl,
|
|
412
419
|
createFrameOrchestrator,
|
|
413
420
|
generateKeyPair
|
|
@@ -479,11 +486,12 @@ function createFrameSession(spec, ctx, props, overrides = {}) {
|
|
|
479
486
|
const generated = `${spec.channelPrefix}-${Date.now()}`;
|
|
480
487
|
const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
|
|
481
488
|
const keyPair = spec.needsKeyPair ? generateKeyPair() : void 0;
|
|
482
|
-
const
|
|
489
|
+
const builtUrl = spec.buildUrl ? spec.buildUrl(ctx, props, channelId, keyPair?.publicKey) : buildFrameUrl(
|
|
483
490
|
spec.path,
|
|
484
491
|
{ ...spec.buildParams?.(ctx, props, keyPair?.publicKey), channelId },
|
|
485
492
|
{ frameBaseUrl: ctx.frameBaseUrl }
|
|
486
493
|
);
|
|
494
|
+
const url = spec.hidden ? builtUrl : applyThemeParam(builtUrl, ctx.theme);
|
|
487
495
|
const transport = (overrides.createTransport ?? (() => new WebViewTransport()))();
|
|
488
496
|
let resolvedHandle = null;
|
|
489
497
|
let rejectDisposed;
|
|
@@ -577,13 +585,12 @@ function createFrameSession(spec, ctx, props, overrides = {}) {
|
|
|
577
585
|
import { createClientCore } from "@moonpay/platform-sdk-core";
|
|
578
586
|
import {
|
|
579
587
|
createContext,
|
|
580
|
-
useCallback,
|
|
588
|
+
useCallback as useCallback2,
|
|
581
589
|
useContext,
|
|
582
|
-
useMemo,
|
|
583
|
-
useRef as
|
|
584
|
-
useState
|
|
590
|
+
useMemo as useMemo2,
|
|
591
|
+
useRef as useRef3,
|
|
592
|
+
useState as useState2
|
|
585
593
|
} from "react";
|
|
586
|
-
import { Modal } from "react-native";
|
|
587
594
|
|
|
588
595
|
// src/methods/add-card.ts
|
|
589
596
|
import { err, ok } from "@moonpay/platform-protocol/result";
|
|
@@ -872,23 +879,200 @@ function createMountSession(specCtx, host) {
|
|
|
872
879
|
};
|
|
873
880
|
}
|
|
874
881
|
|
|
875
|
-
// src/
|
|
882
|
+
// src/VisibleFrameSlotSheet.tsx
|
|
883
|
+
import { useCallback, useEffect as useEffect2, useMemo, useRef as useRef2, useState } from "react";
|
|
884
|
+
import {
|
|
885
|
+
ActivityIndicator,
|
|
886
|
+
Animated,
|
|
887
|
+
Easing,
|
|
888
|
+
Modal,
|
|
889
|
+
PanResponder,
|
|
890
|
+
Platform,
|
|
891
|
+
Pressable,
|
|
892
|
+
StyleSheet,
|
|
893
|
+
useWindowDimensions,
|
|
894
|
+
View as View2
|
|
895
|
+
} from "react-native";
|
|
876
896
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
897
|
+
function animateSheet(value, toValue, onDone) {
|
|
898
|
+
const animation = Platform.OS === "android" ? Animated.timing(value, {
|
|
899
|
+
toValue,
|
|
900
|
+
duration: 250,
|
|
901
|
+
easing: Easing.out(Easing.exp),
|
|
902
|
+
useNativeDriver: true
|
|
903
|
+
}) : Animated.spring(value, {
|
|
904
|
+
toValue,
|
|
905
|
+
damping: 500,
|
|
906
|
+
stiffness: 1e3,
|
|
907
|
+
mass: 3,
|
|
908
|
+
overshootClamping: true,
|
|
909
|
+
restDisplacementThreshold: 10,
|
|
910
|
+
restSpeedThreshold: 10,
|
|
911
|
+
useNativeDriver: true
|
|
912
|
+
});
|
|
913
|
+
animation.start(onDone);
|
|
914
|
+
}
|
|
915
|
+
function VisibleFrameSlotSheet({
|
|
916
|
+
slot,
|
|
917
|
+
onClose
|
|
918
|
+
}) {
|
|
919
|
+
const { height } = useWindowDimensions();
|
|
920
|
+
const sheetHeight = Math.round(height * 0.9);
|
|
921
|
+
const translateY = useRef2(new Animated.Value(sheetHeight)).current;
|
|
922
|
+
const [frameReady, setFrameReady] = useState(false);
|
|
923
|
+
const onCloseRef = useRef2(onClose);
|
|
924
|
+
onCloseRef.current = onClose;
|
|
925
|
+
const closingRef = useRef2(false);
|
|
926
|
+
const close = useCallback(() => {
|
|
927
|
+
if (closingRef.current)
|
|
928
|
+
return;
|
|
929
|
+
closingRef.current = true;
|
|
930
|
+
animateSheet(translateY, sheetHeight, ({ finished }) => {
|
|
931
|
+
if (finished)
|
|
932
|
+
onCloseRef.current();
|
|
933
|
+
});
|
|
934
|
+
}, [translateY, sheetHeight]);
|
|
935
|
+
const panResponder = useMemo(
|
|
936
|
+
() => PanResponder.create({
|
|
937
|
+
// Claim the gesture only for a clearly downward drag — never on a tap
|
|
938
|
+
// (so the handle's onPress still fires) or a mostly-horizontal swipe.
|
|
939
|
+
onMoveShouldSetPanResponder: (_evt, { dy, dx }) => dy > 5 && dy > Math.abs(dx),
|
|
940
|
+
onPanResponderGrant: () => {
|
|
941
|
+
translateY.stopAnimation(() => {
|
|
942
|
+
translateY.extractOffset();
|
|
943
|
+
});
|
|
944
|
+
},
|
|
945
|
+
// Track the finger downward; clamp upward travel to the open position.
|
|
946
|
+
onPanResponderMove: (_evt, { dy }) => {
|
|
947
|
+
translateY.setValue(Math.max(0, dy));
|
|
948
|
+
},
|
|
949
|
+
onPanResponderRelease: (_evt, { dy, vy }) => {
|
|
950
|
+
translateY.flattenOffset();
|
|
951
|
+
const draggedPastThreshold = dy > sheetHeight * 0.35;
|
|
952
|
+
const flungDownFast = vy > 0.5;
|
|
953
|
+
if (draggedPastThreshold || flungDownFast) {
|
|
954
|
+
close();
|
|
955
|
+
} else {
|
|
956
|
+
animateSheet(translateY, 0);
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
// Another responder stole the gesture: settle to a known state.
|
|
960
|
+
onPanResponderTerminate: () => {
|
|
961
|
+
translateY.flattenOffset();
|
|
962
|
+
animateSheet(translateY, 0);
|
|
963
|
+
}
|
|
964
|
+
}),
|
|
965
|
+
[translateY, sheetHeight, close]
|
|
966
|
+
);
|
|
967
|
+
useEffect2(() => {
|
|
968
|
+
animateSheet(translateY, 0);
|
|
969
|
+
}, [translateY]);
|
|
970
|
+
useEffect2(() => {
|
|
971
|
+
const unsubscribe = slot.transport.onMessage((msg) => {
|
|
972
|
+
if (msg.kind === "ready")
|
|
973
|
+
setFrameReady(true);
|
|
974
|
+
else if (msg.kind === "complete" || msg.kind === "error")
|
|
975
|
+
close();
|
|
976
|
+
});
|
|
977
|
+
return unsubscribe;
|
|
978
|
+
}, [slot.transport, close]);
|
|
979
|
+
const backdropOpacity = translateY.interpolate({
|
|
980
|
+
inputRange: [0, sheetHeight],
|
|
981
|
+
outputRange: [1, 0],
|
|
982
|
+
extrapolate: "clamp"
|
|
983
|
+
});
|
|
984
|
+
return /* @__PURE__ */ jsx2(Modal, { visible: true, transparent: true, animationType: "none", onRequestClose: close, children: /* @__PURE__ */ jsxs(View2, { style: styles.root, children: [
|
|
985
|
+
/* @__PURE__ */ jsx2(Animated.View, { style: [styles.backdrop, { opacity: backdropOpacity }], children: /* @__PURE__ */ jsx2(
|
|
986
|
+
Pressable,
|
|
987
|
+
{
|
|
988
|
+
style: StyleSheet.absoluteFill,
|
|
989
|
+
accessibilityRole: "button",
|
|
990
|
+
accessibilityLabel: "Close",
|
|
991
|
+
onPress: close
|
|
992
|
+
}
|
|
993
|
+
) }),
|
|
994
|
+
/* @__PURE__ */ jsxs(Animated.View, { style: [styles.sheet, { height: sheetHeight, transform: [{ translateY }] }], children: [
|
|
995
|
+
/* @__PURE__ */ jsx2(MoonPayFrame, { transport: slot.transport }),
|
|
996
|
+
!frameReady && /* @__PURE__ */ jsx2(View2, { style: styles.loading, children: /* @__PURE__ */ jsx2(ActivityIndicator, { size: "large", color: "#000" }) }),
|
|
997
|
+
/* @__PURE__ */ jsx2(View2, { style: styles.handleArea, ...panResponder.panHandlers, children: /* @__PURE__ */ jsx2(
|
|
998
|
+
Pressable,
|
|
999
|
+
{
|
|
1000
|
+
onPress: close,
|
|
1001
|
+
accessibilityRole: "button",
|
|
1002
|
+
accessibilityLabel: "Close",
|
|
1003
|
+
hitSlop: 12,
|
|
1004
|
+
children: /* @__PURE__ */ jsx2(View2, { style: styles.handleBar })
|
|
1005
|
+
}
|
|
1006
|
+
) })
|
|
1007
|
+
] })
|
|
1008
|
+
] }) });
|
|
1009
|
+
}
|
|
1010
|
+
var styles = StyleSheet.create({
|
|
1011
|
+
root: {
|
|
1012
|
+
flex: 1,
|
|
1013
|
+
justifyContent: "flex-end"
|
|
1014
|
+
},
|
|
1015
|
+
// Dimmed backdrop covering the whole screen; fades with the sheet position.
|
|
1016
|
+
backdrop: {
|
|
1017
|
+
...StyleSheet.absoluteFillObject,
|
|
1018
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)"
|
|
1019
|
+
},
|
|
1020
|
+
// Bottom sheet: ~90% of the screen (height applied inline), rounded top
|
|
1021
|
+
// corners. The 10% gap keeps the frame clear of the status bar / notch
|
|
1022
|
+
// without depending on react-native-safe-area-context.
|
|
1023
|
+
sheet: {
|
|
1024
|
+
backgroundColor: "#fff",
|
|
1025
|
+
borderTopLeftRadius: 24,
|
|
1026
|
+
borderTopRightRadius: 24,
|
|
1027
|
+
overflow: "hidden"
|
|
1028
|
+
},
|
|
1029
|
+
// Opaque cover with a centered spinner, shown until the frame is ready.
|
|
1030
|
+
loading: {
|
|
1031
|
+
...StyleSheet.absoluteFillObject,
|
|
1032
|
+
backgroundColor: "#fff",
|
|
1033
|
+
alignItems: "center",
|
|
1034
|
+
justifyContent: "center"
|
|
1035
|
+
},
|
|
1036
|
+
// Drag-to-dismiss strip pinned across the top of the sheet, floating over the
|
|
1037
|
+
// frame. Tall enough to be an easy grab target without eating much of the UI.
|
|
1038
|
+
handleArea: {
|
|
1039
|
+
position: "absolute",
|
|
1040
|
+
top: 0,
|
|
1041
|
+
left: 0,
|
|
1042
|
+
right: 0,
|
|
1043
|
+
height: 28,
|
|
1044
|
+
alignItems: "center",
|
|
1045
|
+
justifyContent: "center",
|
|
1046
|
+
zIndex: 1,
|
|
1047
|
+
elevation: 2
|
|
1048
|
+
},
|
|
1049
|
+
// The visible pill.
|
|
1050
|
+
handleBar: {
|
|
1051
|
+
width: 36,
|
|
1052
|
+
height: 5,
|
|
1053
|
+
borderRadius: 3,
|
|
1054
|
+
backgroundColor: "rgba(0, 0, 0, 0.2)"
|
|
1055
|
+
}
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
// src/provider.tsx
|
|
1059
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
877
1060
|
var MoonPayContext = createContext(null);
|
|
878
1061
|
function MoonPayProvider({
|
|
879
1062
|
sessionToken,
|
|
880
1063
|
apiBaseUrl,
|
|
881
1064
|
frameBaseUrl,
|
|
1065
|
+
theme,
|
|
882
1066
|
children
|
|
883
1067
|
}) {
|
|
884
|
-
const [frameSlots, setFrameSlots] =
|
|
885
|
-
const addSlot =
|
|
1068
|
+
const [frameSlots, setFrameSlots] = useState2([]);
|
|
1069
|
+
const addSlot = useCallback2((slot) => {
|
|
886
1070
|
setFrameSlots((prev) => [...prev, slot]);
|
|
887
1071
|
}, []);
|
|
888
|
-
const removeSlot =
|
|
1072
|
+
const removeSlot = useCallback2((id) => {
|
|
889
1073
|
setFrameSlots((prev) => prev.filter((s) => s.id !== id));
|
|
890
1074
|
}, []);
|
|
891
|
-
const coreRef =
|
|
1075
|
+
const coreRef = useRef3(null);
|
|
892
1076
|
if (!coreRef.current) {
|
|
893
1077
|
coreRef.current = createClientCore({
|
|
894
1078
|
apiBaseUrl,
|
|
@@ -897,26 +1081,24 @@ function MoonPayProvider({
|
|
|
897
1081
|
});
|
|
898
1082
|
}
|
|
899
1083
|
const core = coreRef.current;
|
|
900
|
-
const client =
|
|
901
|
-
const specCtx = { sessionToken, core, frameBaseUrl };
|
|
1084
|
+
const client = useMemo2(() => {
|
|
1085
|
+
const specCtx = { sessionToken, core, frameBaseUrl, theme };
|
|
902
1086
|
return createRNClient({
|
|
903
1087
|
mountSession: createMountSession(specCtx, { addSlot, removeSlot }),
|
|
904
1088
|
core
|
|
905
1089
|
});
|
|
906
|
-
}, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);
|
|
907
|
-
return /* @__PURE__ */
|
|
1090
|
+
}, [sessionToken, frameBaseUrl, core, addSlot, removeSlot, theme?.appearance]);
|
|
1091
|
+
return /* @__PURE__ */ jsxs2(MoonPayContext.Provider, { value: { client, sessionToken, core, frameBaseUrl, theme }, children: [
|
|
908
1092
|
children,
|
|
909
|
-
frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */
|
|
910
|
-
frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */
|
|
911
|
-
|
|
1093
|
+
frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ jsx3(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
|
|
1094
|
+
frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ jsx3(
|
|
1095
|
+
VisibleFrameSlotSheet,
|
|
912
1096
|
{
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
onRequestClose: () => {
|
|
1097
|
+
slot,
|
|
1098
|
+
onClose: () => {
|
|
916
1099
|
slot.dispose();
|
|
917
1100
|
removeSlot(slot.id);
|
|
918
|
-
}
|
|
919
|
-
children: /* @__PURE__ */ jsx2(MoonPayFrame, { transport: slot.transport })
|
|
1101
|
+
}
|
|
920
1102
|
},
|
|
921
1103
|
slot.id
|
|
922
1104
|
))
|
|
@@ -934,7 +1116,7 @@ function useMoonPay() {
|
|
|
934
1116
|
}
|
|
935
1117
|
|
|
936
1118
|
// src/frame-view.tsx
|
|
937
|
-
import { jsx as
|
|
1119
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
938
1120
|
function applyReactiveProps(spec, keys, props, applied, handle) {
|
|
939
1121
|
for (const key of keys) {
|
|
940
1122
|
const next = props[key];
|
|
@@ -951,12 +1133,12 @@ function MoonPayFrameView({
|
|
|
951
1133
|
defaultStyle,
|
|
952
1134
|
onEvent
|
|
953
1135
|
}) {
|
|
954
|
-
const { sessionToken, core, frameBaseUrl } = useMoonPayContext();
|
|
955
|
-
const [transport, setTransport] =
|
|
956
|
-
const handleRef =
|
|
957
|
-
const onEventRef =
|
|
1136
|
+
const { sessionToken, core, frameBaseUrl, theme } = useMoonPayContext();
|
|
1137
|
+
const [transport, setTransport] = useState3(null);
|
|
1138
|
+
const handleRef = useRef4(null);
|
|
1139
|
+
const onEventRef = useRef4(onEvent);
|
|
958
1140
|
onEventRef.current = onEvent;
|
|
959
|
-
const propsRef =
|
|
1141
|
+
const propsRef = useRef4(props);
|
|
960
1142
|
propsRef.current = props;
|
|
961
1143
|
const reactiveKeys = Object.keys(spec.reactiveProps ?? {});
|
|
962
1144
|
const mountProps = {};
|
|
@@ -967,8 +1149,8 @@ function MoonPayFrameView({
|
|
|
967
1149
|
}
|
|
968
1150
|
const mountKey = JSON.stringify(mountProps);
|
|
969
1151
|
const liveKey = JSON.stringify(liveProps);
|
|
970
|
-
const appliedRef =
|
|
971
|
-
|
|
1152
|
+
const appliedRef = useRef4({});
|
|
1153
|
+
useEffect3(() => {
|
|
972
1154
|
let disposed = false;
|
|
973
1155
|
let session;
|
|
974
1156
|
const applied = {};
|
|
@@ -977,7 +1159,11 @@ function MoonPayFrameView({
|
|
|
977
1159
|
}
|
|
978
1160
|
appliedRef.current = applied;
|
|
979
1161
|
try {
|
|
980
|
-
session = createFrameSession(
|
|
1162
|
+
session = createFrameSession(
|
|
1163
|
+
spec,
|
|
1164
|
+
{ sessionToken, core, frameBaseUrl, theme },
|
|
1165
|
+
propsRef.current
|
|
1166
|
+
);
|
|
981
1167
|
} catch (e) {
|
|
982
1168
|
onEventRef.current?.(
|
|
983
1169
|
spec.errorEvent(e instanceof Error ? e.message : "Failed to create frame")
|
|
@@ -1007,23 +1193,23 @@ function MoonPayFrameView({
|
|
|
1007
1193
|
setTransport(null);
|
|
1008
1194
|
};
|
|
1009
1195
|
}, [mountKey, spec, sessionToken, core, frameBaseUrl]);
|
|
1010
|
-
|
|
1196
|
+
useEffect3(() => {
|
|
1011
1197
|
const handle = handleRef.current;
|
|
1012
1198
|
if (!handle)
|
|
1013
1199
|
return;
|
|
1014
1200
|
applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
|
|
1015
1201
|
}, [liveKey]);
|
|
1016
1202
|
if (spec.hidden) {
|
|
1017
|
-
return transport ? /* @__PURE__ */
|
|
1203
|
+
return transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport, hidden: true }) : null;
|
|
1018
1204
|
}
|
|
1019
1205
|
const resolvedStyle = { ...defaultStyle, ...style };
|
|
1020
|
-
return /* @__PURE__ */
|
|
1206
|
+
return /* @__PURE__ */ jsx4(View3, { style: resolvedStyle, children: transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport }) : null });
|
|
1021
1207
|
}
|
|
1022
1208
|
|
|
1023
1209
|
// src/components/add-card.tsx
|
|
1024
|
-
import { jsx as
|
|
1210
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1025
1211
|
function MoonPayAddCard({ onEvent, style }) {
|
|
1026
|
-
return /* @__PURE__ */
|
|
1212
|
+
return /* @__PURE__ */ jsx5(
|
|
1027
1213
|
MoonPayFrameView,
|
|
1028
1214
|
{
|
|
1029
1215
|
spec: addCardSpec,
|
|
@@ -1036,13 +1222,13 @@ function MoonPayAddCard({ onEvent, style }) {
|
|
|
1036
1222
|
}
|
|
1037
1223
|
|
|
1038
1224
|
// src/components/apple-pay-button.tsx
|
|
1039
|
-
import { jsx as
|
|
1225
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
1040
1226
|
function MoonPayApplePayButton({
|
|
1041
1227
|
quote,
|
|
1042
1228
|
onEvent,
|
|
1043
1229
|
style
|
|
1044
1230
|
}) {
|
|
1045
|
-
return /* @__PURE__ */
|
|
1231
|
+
return /* @__PURE__ */ jsx6(
|
|
1046
1232
|
MoonPayFrameView,
|
|
1047
1233
|
{
|
|
1048
1234
|
spec: applePaySpec,
|
|
@@ -1055,9 +1241,9 @@ function MoonPayApplePayButton({
|
|
|
1055
1241
|
}
|
|
1056
1242
|
|
|
1057
1243
|
// src/components/auth.tsx
|
|
1058
|
-
import { jsx as
|
|
1244
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1059
1245
|
function MoonPayAuth({ onEvent, style }) {
|
|
1060
|
-
return /* @__PURE__ */
|
|
1246
|
+
return /* @__PURE__ */ jsx7(
|
|
1061
1247
|
MoonPayFrameView,
|
|
1062
1248
|
{
|
|
1063
1249
|
spec: authSpec,
|
|
@@ -1070,9 +1256,9 @@ function MoonPayAuth({ onEvent, style }) {
|
|
|
1070
1256
|
}
|
|
1071
1257
|
|
|
1072
1258
|
// src/components/buy-button.tsx
|
|
1073
|
-
import { jsx as
|
|
1259
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1074
1260
|
function MoonPayBuyButton({ quote, onEvent, style }) {
|
|
1075
|
-
return /* @__PURE__ */
|
|
1261
|
+
return /* @__PURE__ */ jsx8(
|
|
1076
1262
|
MoonPayFrameView,
|
|
1077
1263
|
{
|
|
1078
1264
|
spec: buyButtonSpec,
|
|
@@ -1085,13 +1271,13 @@ function MoonPayBuyButton({ quote, onEvent, style }) {
|
|
|
1085
1271
|
}
|
|
1086
1272
|
|
|
1087
1273
|
// src/components/buy-frame.tsx
|
|
1088
|
-
import { jsx as
|
|
1274
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1089
1275
|
function MoonPayBuyFrame({
|
|
1090
1276
|
quote,
|
|
1091
1277
|
externalTransactionId,
|
|
1092
1278
|
onEvent
|
|
1093
1279
|
}) {
|
|
1094
|
-
return /* @__PURE__ */
|
|
1280
|
+
return /* @__PURE__ */ jsx9(
|
|
1095
1281
|
MoonPayFrameView,
|
|
1096
1282
|
{
|
|
1097
1283
|
spec: buySpec,
|
|
@@ -1103,9 +1289,9 @@ function MoonPayBuyFrame({
|
|
|
1103
1289
|
}
|
|
1104
1290
|
|
|
1105
1291
|
// src/components/challenge.tsx
|
|
1106
|
-
import { jsx as
|
|
1292
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1107
1293
|
function MoonPayChallenge({ url, onEvent, style }) {
|
|
1108
|
-
return /* @__PURE__ */
|
|
1294
|
+
return /* @__PURE__ */ jsx10(
|
|
1109
1295
|
MoonPayFrameView,
|
|
1110
1296
|
{
|
|
1111
1297
|
spec: challengeSpec,
|
|
@@ -1118,9 +1304,9 @@ function MoonPayChallenge({ url, onEvent, style }) {
|
|
|
1118
1304
|
}
|
|
1119
1305
|
|
|
1120
1306
|
// src/components/connect.tsx
|
|
1121
|
-
import { jsx as
|
|
1307
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1122
1308
|
function MoonPayConnect({ theme, onEvent, style }) {
|
|
1123
|
-
return /* @__PURE__ */
|
|
1309
|
+
return /* @__PURE__ */ jsx11(
|
|
1124
1310
|
MoonPayFrameView,
|
|
1125
1311
|
{
|
|
1126
1312
|
spec: connectSpec,
|
|
@@ -1133,12 +1319,12 @@ function MoonPayConnect({ theme, onEvent, style }) {
|
|
|
1133
1319
|
}
|
|
1134
1320
|
|
|
1135
1321
|
// src/components/connection-check.tsx
|
|
1136
|
-
import { jsx as
|
|
1322
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
1137
1323
|
function MoonPayConnectionCheck({
|
|
1138
1324
|
skipKyc,
|
|
1139
1325
|
onEvent
|
|
1140
1326
|
}) {
|
|
1141
|
-
return /* @__PURE__ */
|
|
1327
|
+
return /* @__PURE__ */ jsx12(
|
|
1142
1328
|
MoonPayFrameView,
|
|
1143
1329
|
{
|
|
1144
1330
|
spec: connectionCheckSpec,
|
|
@@ -1150,20 +1336,20 @@ function MoonPayConnectionCheck({
|
|
|
1150
1336
|
}
|
|
1151
1337
|
|
|
1152
1338
|
// src/components/connection-reset.tsx
|
|
1153
|
-
import { jsx as
|
|
1339
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
1154
1340
|
function MoonPayConnectionReset({ onEvent }) {
|
|
1155
|
-
return /* @__PURE__ */
|
|
1341
|
+
return /* @__PURE__ */ jsx13(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
|
|
1156
1342
|
}
|
|
1157
1343
|
|
|
1158
1344
|
// src/components/google-pay-button.tsx
|
|
1159
|
-
import { jsx as
|
|
1345
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
1160
1346
|
function MoonPayGooglePayButton({
|
|
1161
1347
|
quote,
|
|
1162
1348
|
externalTransactionId,
|
|
1163
1349
|
onEvent,
|
|
1164
1350
|
style
|
|
1165
1351
|
}) {
|
|
1166
|
-
return /* @__PURE__ */
|
|
1352
|
+
return /* @__PURE__ */ jsx14(
|
|
1167
1353
|
MoonPayFrameView,
|
|
1168
1354
|
{
|
|
1169
1355
|
spec: googlePaySpec,
|
|
@@ -1176,9 +1362,9 @@ function MoonPayGooglePayButton({
|
|
|
1176
1362
|
}
|
|
1177
1363
|
|
|
1178
1364
|
// src/components/widget.tsx
|
|
1179
|
-
import { jsx as
|
|
1365
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
1180
1366
|
function MoonPayWidget({ quote, onEvent, style }) {
|
|
1181
|
-
return /* @__PURE__ */
|
|
1367
|
+
return /* @__PURE__ */ jsx15(
|
|
1182
1368
|
MoonPayFrameView,
|
|
1183
1369
|
{
|
|
1184
1370
|
spec: widgetSpec,
|