@moonpay/platform-sdk-react-native 1.9.0 → 1.10.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 +47 -0
- package/dist/index.cjs +46 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +46 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -460,16 +460,25 @@ interface MoonPayFrameProps {
|
|
|
460
460
|
declare function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null;
|
|
461
461
|
|
|
462
462
|
interface MoonPayProviderProps {
|
|
463
|
-
|
|
463
|
+
/**
|
|
464
|
+
* Session token from your server (via `createSession`). Optional — omit it and
|
|
465
|
+
* call `initialize(sessionToken)` from `useMoonPay()` once you've fetched it.
|
|
466
|
+
* When provided, this prop takes precedence over an imperatively-set token.
|
|
467
|
+
*/
|
|
468
|
+
sessionToken?: string;
|
|
464
469
|
apiBaseUrl?: string;
|
|
465
470
|
frameBaseUrl?: string;
|
|
466
471
|
/** Theme applied to every visible MoonPay frame (connect, widget, Apple/Google Pay, …). */
|
|
467
472
|
theme?: ThemeOptions;
|
|
468
473
|
children: ReactNode;
|
|
469
474
|
}
|
|
470
|
-
declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
475
|
+
declare function MoonPayProvider({ sessionToken: sessionTokenProp, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
471
476
|
declare function useMoonPay(): {
|
|
472
477
|
client: RNClient;
|
|
478
|
+
/** Set or replace the session token after mount. */
|
|
479
|
+
initialize: (sessionToken: string) => void;
|
|
480
|
+
/** True once a session token (via prop or `initialize()`) is available. */
|
|
481
|
+
isInitialized: boolean;
|
|
473
482
|
};
|
|
474
483
|
|
|
475
484
|
export { type AddCardFrame, type ApplePayFrame, type AuthFrame, type BuyButtonFrame, type BuyFrame, type ChallengeFrame, type ConnectFrame, type ConnectOptions, type ConnectionCheckEvent, type ConnectionResetEvent, type CustomerExportFrame, type GetConnectionOptions, type GooglePayFrame, MoonPayAddCard, type MoonPayAddCardProps, MoonPayApplePayButton, type MoonPayApplePayButtonProps, MoonPayAuth, type MoonPayAuthProps, MoonPayBuyButton, type MoonPayBuyButtonProps, MoonPayBuyFrame, type MoonPayBuyFrameProps, MoonPayChallenge, type MoonPayChallengeProps, MoonPayConnect, type MoonPayConnectProps, MoonPayConnectionCheck, type MoonPayConnectionCheckProps, MoonPayConnectionReset, type MoonPayConnectionResetProps, MoonPayCustomerExport, type MoonPayCustomerExportProps, MoonPayFrame, type MoonPayFrameProps, MoonPayGooglePayButton, type MoonPayGooglePayButtonProps, MoonPayProvider, type MoonPayProviderProps, MoonPayWidget, type MoonPayWidgetProps, type RNClient, type SetupAddCardOptions, type SetupApplePayOptions, type SetupAuthOptions, type SetupBuyButtonOptions, type SetupBuyOptions, type SetupChallengeOptions, type SetupCustomerExportOptions, type SetupGooglePayOptions, type SetupWidgetOptions, WebViewTransport, type WidgetFrame, useMoonPay };
|
package/dist/index.d.ts
CHANGED
|
@@ -460,16 +460,25 @@ interface MoonPayFrameProps {
|
|
|
460
460
|
declare function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null;
|
|
461
461
|
|
|
462
462
|
interface MoonPayProviderProps {
|
|
463
|
-
|
|
463
|
+
/**
|
|
464
|
+
* Session token from your server (via `createSession`). Optional — omit it and
|
|
465
|
+
* call `initialize(sessionToken)` from `useMoonPay()` once you've fetched it.
|
|
466
|
+
* When provided, this prop takes precedence over an imperatively-set token.
|
|
467
|
+
*/
|
|
468
|
+
sessionToken?: string;
|
|
464
469
|
apiBaseUrl?: string;
|
|
465
470
|
frameBaseUrl?: string;
|
|
466
471
|
/** Theme applied to every visible MoonPay frame (connect, widget, Apple/Google Pay, …). */
|
|
467
472
|
theme?: ThemeOptions;
|
|
468
473
|
children: ReactNode;
|
|
469
474
|
}
|
|
470
|
-
declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
475
|
+
declare function MoonPayProvider({ sessionToken: sessionTokenProp, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
471
476
|
declare function useMoonPay(): {
|
|
472
477
|
client: RNClient;
|
|
478
|
+
/** Set or replace the session token after mount. */
|
|
479
|
+
initialize: (sessionToken: string) => void;
|
|
480
|
+
/** True once a session token (via prop or `initialize()`) is available. */
|
|
481
|
+
isInitialized: boolean;
|
|
473
482
|
};
|
|
474
483
|
|
|
475
484
|
export { type AddCardFrame, type ApplePayFrame, type AuthFrame, type BuyButtonFrame, type BuyFrame, type ChallengeFrame, type ConnectFrame, type ConnectOptions, type ConnectionCheckEvent, type ConnectionResetEvent, type CustomerExportFrame, type GetConnectionOptions, type GooglePayFrame, MoonPayAddCard, type MoonPayAddCardProps, MoonPayApplePayButton, type MoonPayApplePayButtonProps, MoonPayAuth, type MoonPayAuthProps, MoonPayBuyButton, type MoonPayBuyButtonProps, MoonPayBuyFrame, type MoonPayBuyFrameProps, MoonPayChallenge, type MoonPayChallengeProps, MoonPayConnect, type MoonPayConnectProps, MoonPayConnectionCheck, type MoonPayConnectionCheckProps, MoonPayConnectionReset, type MoonPayConnectionResetProps, MoonPayCustomerExport, type MoonPayCustomerExportProps, MoonPayFrame, type MoonPayFrameProps, MoonPayGooglePayButton, type MoonPayGooglePayButtonProps, MoonPayProvider, type MoonPayProviderProps, MoonPayWidget, type MoonPayWidgetProps, type RNClient, type SetupAddCardOptions, type SetupApplePayOptions, type SetupAuthOptions, type SetupBuyButtonOptions, type SetupBuyOptions, type SetupChallengeOptions, type SetupCustomerExportOptions, type SetupGooglePayOptions, type SetupWidgetOptions, WebViewTransport, type WidgetFrame, useMoonPay };
|
package/dist/index.js
CHANGED
|
@@ -155,6 +155,14 @@ function applyCredentialsOnComplete(msg, ctx) {
|
|
|
155
155
|
ctx.core.context.setAccessToken(creds.accessToken);
|
|
156
156
|
ctx.core.context.setClientToken(creds.clientToken);
|
|
157
157
|
}
|
|
158
|
+
function requireSessionToken(ctx) {
|
|
159
|
+
if (!ctx.sessionToken) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
"No session token \u2014 pass sessionToken to <MoonPayProvider> or call initialize() from useMoonPay() before starting a connection."
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return ctx.sessionToken;
|
|
165
|
+
}
|
|
158
166
|
var connectionCheckSpec = {
|
|
159
167
|
channelPrefix: "check",
|
|
160
168
|
path: FRAME_PATHS.checkConnection,
|
|
@@ -162,7 +170,7 @@ var connectionCheckSpec = {
|
|
|
162
170
|
needsKeyPair: true,
|
|
163
171
|
handshakeTimeout: 1e4,
|
|
164
172
|
buildParams: (ctx, props, publicKey) => ({
|
|
165
|
-
sessionToken: ctx
|
|
173
|
+
sessionToken: requireSessionToken(ctx),
|
|
166
174
|
publicKey,
|
|
167
175
|
...props.skipKyc && { skipKyc: true }
|
|
168
176
|
}),
|
|
@@ -184,7 +192,7 @@ var connectSpec = {
|
|
|
184
192
|
hidden: false,
|
|
185
193
|
needsKeyPair: true,
|
|
186
194
|
buildParams: (ctx, props, publicKey) => ({
|
|
187
|
-
sessionToken: ctx
|
|
195
|
+
sessionToken: requireSessionToken(ctx),
|
|
188
196
|
publicKey,
|
|
189
197
|
// Per-call override; `applyThemeParam` in the engine fills the client
|
|
190
198
|
// default for connect (and every other visible frame) when this is absent.
|
|
@@ -398,7 +406,7 @@ var connectionResetSpec = {
|
|
|
398
406
|
path: FRAME_PATHS.reset,
|
|
399
407
|
hidden: true,
|
|
400
408
|
handshakeTimeout: 5e3,
|
|
401
|
-
buildParams: (ctx) => ({ sessionToken: ctx
|
|
409
|
+
buildParams: (ctx) => ({ sessionToken: requireSessionToken(ctx) }),
|
|
402
410
|
mapMessage: (msg) => {
|
|
403
411
|
if (msg.kind === "complete") return { kind: "complete" };
|
|
404
412
|
if (msg.kind === "error") {
|
|
@@ -1166,13 +1174,15 @@ var styles = StyleSheet.create({
|
|
|
1166
1174
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1167
1175
|
var MoonPayContext = createContext(null);
|
|
1168
1176
|
function MoonPayProvider({
|
|
1169
|
-
sessionToken,
|
|
1177
|
+
sessionToken: sessionTokenProp,
|
|
1170
1178
|
apiBaseUrl,
|
|
1171
1179
|
frameBaseUrl,
|
|
1172
1180
|
theme,
|
|
1173
1181
|
children
|
|
1174
1182
|
}) {
|
|
1175
1183
|
const [frameSlots, setFrameSlots] = useState2([]);
|
|
1184
|
+
const [internalToken, setInternalToken] = useState2(void 0);
|
|
1185
|
+
const sessionToken = sessionTokenProp ?? internalToken;
|
|
1176
1186
|
const addSlot = useCallback2((slot) => {
|
|
1177
1187
|
setFrameSlots((prev) => [...prev, slot]);
|
|
1178
1188
|
}, []);
|
|
@@ -1188,6 +1198,14 @@ function MoonPayProvider({
|
|
|
1188
1198
|
});
|
|
1189
1199
|
}
|
|
1190
1200
|
const core = coreRef.current;
|
|
1201
|
+
const initialize = useCallback2(
|
|
1202
|
+
(token) => {
|
|
1203
|
+
core.context.setAccessToken("");
|
|
1204
|
+
core.context.setClientToken("");
|
|
1205
|
+
setInternalToken(token);
|
|
1206
|
+
},
|
|
1207
|
+
[core]
|
|
1208
|
+
);
|
|
1191
1209
|
const client = useMemo2(() => {
|
|
1192
1210
|
const specCtx = { sessionToken, core, frameBaseUrl, theme };
|
|
1193
1211
|
return createRNClient({
|
|
@@ -1195,21 +1213,28 @@ function MoonPayProvider({
|
|
|
1195
1213
|
core
|
|
1196
1214
|
});
|
|
1197
1215
|
}, [sessionToken, frameBaseUrl, core, addSlot, removeSlot, theme?.appearance]);
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1216
|
+
const isInitialized = sessionToken !== void 0;
|
|
1217
|
+
return /* @__PURE__ */ jsxs2(
|
|
1218
|
+
MoonPayContext.Provider,
|
|
1219
|
+
{
|
|
1220
|
+
value: { client, sessionToken, core, frameBaseUrl, theme, initialize, isInitialized },
|
|
1221
|
+
children: [
|
|
1222
|
+
children,
|
|
1223
|
+
frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ jsx3(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
|
|
1224
|
+
frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ jsx3(
|
|
1225
|
+
VisibleFrameSlotSheet,
|
|
1226
|
+
{
|
|
1227
|
+
slot,
|
|
1228
|
+
onClose: () => {
|
|
1229
|
+
slot.dispose();
|
|
1230
|
+
removeSlot(slot.id);
|
|
1231
|
+
}
|
|
1232
|
+
},
|
|
1233
|
+
slot.id
|
|
1234
|
+
))
|
|
1235
|
+
]
|
|
1236
|
+
}
|
|
1237
|
+
);
|
|
1213
1238
|
}
|
|
1214
1239
|
function useMoonPayContext() {
|
|
1215
1240
|
const ctx = useContext(MoonPayContext);
|
|
@@ -1219,7 +1244,8 @@ function useMoonPayContext() {
|
|
|
1219
1244
|
return ctx;
|
|
1220
1245
|
}
|
|
1221
1246
|
function useMoonPay() {
|
|
1222
|
-
|
|
1247
|
+
const { client, initialize, isInitialized } = useMoonPayContext();
|
|
1248
|
+
return { client, initialize, isInitialized };
|
|
1223
1249
|
}
|
|
1224
1250
|
|
|
1225
1251
|
// src/frame-view.tsx
|