@moonpay/platform-sdk-react-native 1.8.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 +86 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -5
- package/dist/index.d.ts +26 -5
- package/dist/index.js +86 -31
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -83,6 +83,8 @@ interface AddCardFrame {
|
|
|
83
83
|
interface SetupApplePayOptions {
|
|
84
84
|
/** Quote signature from getQuote(). */
|
|
85
85
|
quote: string;
|
|
86
|
+
/** Partner-assigned identifier for this transaction attempt. */
|
|
87
|
+
externalTransactionId?: string;
|
|
86
88
|
/** Callback for Apple Pay lifecycle events. */
|
|
87
89
|
onEvent?: (event: ApplePaySdk.Event) => void;
|
|
88
90
|
}
|
|
@@ -117,6 +119,8 @@ interface BuyFrame {
|
|
|
117
119
|
interface SetupBuyButtonOptions {
|
|
118
120
|
/** Quote signature from getQuote(). */
|
|
119
121
|
quote: string;
|
|
122
|
+
/** Partner-assigned identifier for this transaction attempt. */
|
|
123
|
+
externalTransactionId?: string;
|
|
120
124
|
/** Callback for buy-button frame lifecycle events. */
|
|
121
125
|
onEvent?: (event: BuyButtonSdk.Event) => void;
|
|
122
126
|
}
|
|
@@ -180,6 +184,8 @@ interface GooglePayFrame {
|
|
|
180
184
|
interface SetupWidgetOptions {
|
|
181
185
|
/** Quote signature from getQuote(). */
|
|
182
186
|
quote: string;
|
|
187
|
+
/** Partner-assigned identifier for this transaction attempt. */
|
|
188
|
+
externalTransactionId?: string;
|
|
183
189
|
/** Callback for widget lifecycle events. */
|
|
184
190
|
onEvent?: (event: WidgetSdk.Event) => void;
|
|
185
191
|
}
|
|
@@ -297,13 +303,15 @@ declare function MoonPayAddCard({ onEvent, style }: MoonPayAddCardProps): JSX.El
|
|
|
297
303
|
interface MoonPayApplePayButtonProps {
|
|
298
304
|
/** Quote signature from getQuote(). Reactive — updates are pushed via setQuote without remounting. */
|
|
299
305
|
quote: string;
|
|
306
|
+
/** Partner-assigned identifier for this transaction attempt. Mount-time only. */
|
|
307
|
+
externalTransactionId?: string;
|
|
300
308
|
/** Callback for Apple Pay lifecycle events. */
|
|
301
309
|
onEvent?: (event: ApplePaySdk.Event) => void;
|
|
302
310
|
/** Container style. Defaults to height 48. */
|
|
303
311
|
style?: ViewStyle;
|
|
304
312
|
}
|
|
305
313
|
/** Inline Apple Pay button. Render it wherever it should appear in your layout. */
|
|
306
|
-
declare function MoonPayApplePayButton({ quote, onEvent, style, }: MoonPayApplePayButtonProps): JSX.Element;
|
|
314
|
+
declare function MoonPayApplePayButton({ quote, externalTransactionId, onEvent, style, }: MoonPayApplePayButtonProps): JSX.Element;
|
|
307
315
|
|
|
308
316
|
interface MoonPayAuthProps {
|
|
309
317
|
/** Callback for auth lifecycle events. */
|
|
@@ -321,13 +329,15 @@ declare function MoonPayAuth({ onEvent, style }: MoonPayAuthProps): JSX.Element;
|
|
|
321
329
|
interface MoonPayBuyButtonProps {
|
|
322
330
|
/** Quote signature from getQuote(). Reactive — updates are pushed via setQuote without remounting. */
|
|
323
331
|
quote: string;
|
|
332
|
+
/** Partner-assigned identifier for this transaction attempt. Mount-time only. */
|
|
333
|
+
externalTransactionId?: string;
|
|
324
334
|
/** Callback for buy button lifecycle events. */
|
|
325
335
|
onEvent?: (event: BuyButtonSdk.Event) => void;
|
|
326
336
|
/** Container style. Defaults to height 48. */
|
|
327
337
|
style?: ViewStyle;
|
|
328
338
|
}
|
|
329
339
|
/** Inline card/buy button. Render it wherever it should appear in your layout. */
|
|
330
|
-
declare function MoonPayBuyButton({ quote, onEvent, style }: MoonPayBuyButtonProps): JSX.Element;
|
|
340
|
+
declare function MoonPayBuyButton({ quote, externalTransactionId, onEvent, style, }: MoonPayBuyButtonProps): JSX.Element;
|
|
331
341
|
|
|
332
342
|
interface MoonPayBuyFrameProps {
|
|
333
343
|
/** Quote signature from getQuote(). Reactive — updates are pushed via setQuote without remounting. */
|
|
@@ -425,13 +435,15 @@ declare function MoonPayGooglePayButton({ quote, externalTransactionId, onEvent,
|
|
|
425
435
|
interface MoonPayWidgetProps {
|
|
426
436
|
/** Quote signature from getQuote(). Mount-time only — changing it reloads the widget. */
|
|
427
437
|
quote: string;
|
|
438
|
+
/** Partner-assigned identifier for this transaction attempt. Mount-time only. */
|
|
439
|
+
externalTransactionId?: string;
|
|
428
440
|
/** Callback for widget lifecycle events. */
|
|
429
441
|
onEvent?: (event: WidgetSdk.Event) => void;
|
|
430
442
|
/** Container style. Defaults to flex: 1. */
|
|
431
443
|
style?: ViewStyle;
|
|
432
444
|
}
|
|
433
445
|
/** Inline widget frame. Render it wherever it should appear in your layout. */
|
|
434
|
-
declare function MoonPayWidget({ quote, onEvent, style }: MoonPayWidgetProps): JSX.Element;
|
|
446
|
+
declare function MoonPayWidget({ quote, externalTransactionId, onEvent, style, }: MoonPayWidgetProps): JSX.Element;
|
|
435
447
|
|
|
436
448
|
interface MoonPayFrameProps {
|
|
437
449
|
/** The transport instance managing this frame's communication. */
|
|
@@ -448,16 +460,25 @@ interface MoonPayFrameProps {
|
|
|
448
460
|
declare function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null;
|
|
449
461
|
|
|
450
462
|
interface MoonPayProviderProps {
|
|
451
|
-
|
|
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;
|
|
452
469
|
apiBaseUrl?: string;
|
|
453
470
|
frameBaseUrl?: string;
|
|
454
471
|
/** Theme applied to every visible MoonPay frame (connect, widget, Apple/Google Pay, …). */
|
|
455
472
|
theme?: ThemeOptions;
|
|
456
473
|
children: ReactNode;
|
|
457
474
|
}
|
|
458
|
-
declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
475
|
+
declare function MoonPayProvider({ sessionToken: sessionTokenProp, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
459
476
|
declare function useMoonPay(): {
|
|
460
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;
|
|
461
482
|
};
|
|
462
483
|
|
|
463
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
|
@@ -83,6 +83,8 @@ interface AddCardFrame {
|
|
|
83
83
|
interface SetupApplePayOptions {
|
|
84
84
|
/** Quote signature from getQuote(). */
|
|
85
85
|
quote: string;
|
|
86
|
+
/** Partner-assigned identifier for this transaction attempt. */
|
|
87
|
+
externalTransactionId?: string;
|
|
86
88
|
/** Callback for Apple Pay lifecycle events. */
|
|
87
89
|
onEvent?: (event: ApplePaySdk.Event) => void;
|
|
88
90
|
}
|
|
@@ -117,6 +119,8 @@ interface BuyFrame {
|
|
|
117
119
|
interface SetupBuyButtonOptions {
|
|
118
120
|
/** Quote signature from getQuote(). */
|
|
119
121
|
quote: string;
|
|
122
|
+
/** Partner-assigned identifier for this transaction attempt. */
|
|
123
|
+
externalTransactionId?: string;
|
|
120
124
|
/** Callback for buy-button frame lifecycle events. */
|
|
121
125
|
onEvent?: (event: BuyButtonSdk.Event) => void;
|
|
122
126
|
}
|
|
@@ -180,6 +184,8 @@ interface GooglePayFrame {
|
|
|
180
184
|
interface SetupWidgetOptions {
|
|
181
185
|
/** Quote signature from getQuote(). */
|
|
182
186
|
quote: string;
|
|
187
|
+
/** Partner-assigned identifier for this transaction attempt. */
|
|
188
|
+
externalTransactionId?: string;
|
|
183
189
|
/** Callback for widget lifecycle events. */
|
|
184
190
|
onEvent?: (event: WidgetSdk.Event) => void;
|
|
185
191
|
}
|
|
@@ -297,13 +303,15 @@ declare function MoonPayAddCard({ onEvent, style }: MoonPayAddCardProps): JSX.El
|
|
|
297
303
|
interface MoonPayApplePayButtonProps {
|
|
298
304
|
/** Quote signature from getQuote(). Reactive — updates are pushed via setQuote without remounting. */
|
|
299
305
|
quote: string;
|
|
306
|
+
/** Partner-assigned identifier for this transaction attempt. Mount-time only. */
|
|
307
|
+
externalTransactionId?: string;
|
|
300
308
|
/** Callback for Apple Pay lifecycle events. */
|
|
301
309
|
onEvent?: (event: ApplePaySdk.Event) => void;
|
|
302
310
|
/** Container style. Defaults to height 48. */
|
|
303
311
|
style?: ViewStyle;
|
|
304
312
|
}
|
|
305
313
|
/** Inline Apple Pay button. Render it wherever it should appear in your layout. */
|
|
306
|
-
declare function MoonPayApplePayButton({ quote, onEvent, style, }: MoonPayApplePayButtonProps): JSX.Element;
|
|
314
|
+
declare function MoonPayApplePayButton({ quote, externalTransactionId, onEvent, style, }: MoonPayApplePayButtonProps): JSX.Element;
|
|
307
315
|
|
|
308
316
|
interface MoonPayAuthProps {
|
|
309
317
|
/** Callback for auth lifecycle events. */
|
|
@@ -321,13 +329,15 @@ declare function MoonPayAuth({ onEvent, style }: MoonPayAuthProps): JSX.Element;
|
|
|
321
329
|
interface MoonPayBuyButtonProps {
|
|
322
330
|
/** Quote signature from getQuote(). Reactive — updates are pushed via setQuote without remounting. */
|
|
323
331
|
quote: string;
|
|
332
|
+
/** Partner-assigned identifier for this transaction attempt. Mount-time only. */
|
|
333
|
+
externalTransactionId?: string;
|
|
324
334
|
/** Callback for buy button lifecycle events. */
|
|
325
335
|
onEvent?: (event: BuyButtonSdk.Event) => void;
|
|
326
336
|
/** Container style. Defaults to height 48. */
|
|
327
337
|
style?: ViewStyle;
|
|
328
338
|
}
|
|
329
339
|
/** Inline card/buy button. Render it wherever it should appear in your layout. */
|
|
330
|
-
declare function MoonPayBuyButton({ quote, onEvent, style }: MoonPayBuyButtonProps): JSX.Element;
|
|
340
|
+
declare function MoonPayBuyButton({ quote, externalTransactionId, onEvent, style, }: MoonPayBuyButtonProps): JSX.Element;
|
|
331
341
|
|
|
332
342
|
interface MoonPayBuyFrameProps {
|
|
333
343
|
/** Quote signature from getQuote(). Reactive — updates are pushed via setQuote without remounting. */
|
|
@@ -425,13 +435,15 @@ declare function MoonPayGooglePayButton({ quote, externalTransactionId, onEvent,
|
|
|
425
435
|
interface MoonPayWidgetProps {
|
|
426
436
|
/** Quote signature from getQuote(). Mount-time only — changing it reloads the widget. */
|
|
427
437
|
quote: string;
|
|
438
|
+
/** Partner-assigned identifier for this transaction attempt. Mount-time only. */
|
|
439
|
+
externalTransactionId?: string;
|
|
428
440
|
/** Callback for widget lifecycle events. */
|
|
429
441
|
onEvent?: (event: WidgetSdk.Event) => void;
|
|
430
442
|
/** Container style. Defaults to flex: 1. */
|
|
431
443
|
style?: ViewStyle;
|
|
432
444
|
}
|
|
433
445
|
/** Inline widget frame. Render it wherever it should appear in your layout. */
|
|
434
|
-
declare function MoonPayWidget({ quote, onEvent, style }: MoonPayWidgetProps): JSX.Element;
|
|
446
|
+
declare function MoonPayWidget({ quote, externalTransactionId, onEvent, style, }: MoonPayWidgetProps): JSX.Element;
|
|
435
447
|
|
|
436
448
|
interface MoonPayFrameProps {
|
|
437
449
|
/** The transport instance managing this frame's communication. */
|
|
@@ -448,16 +460,25 @@ interface MoonPayFrameProps {
|
|
|
448
460
|
declare function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null;
|
|
449
461
|
|
|
450
462
|
interface MoonPayProviderProps {
|
|
451
|
-
|
|
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;
|
|
452
469
|
apiBaseUrl?: string;
|
|
453
470
|
frameBaseUrl?: string;
|
|
454
471
|
/** Theme applied to every visible MoonPay frame (connect, widget, Apple/Google Pay, …). */
|
|
455
472
|
theme?: ThemeOptions;
|
|
456
473
|
children: ReactNode;
|
|
457
474
|
}
|
|
458
|
-
declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
475
|
+
declare function MoonPayProvider({ sessionToken: sessionTokenProp, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
|
|
459
476
|
declare function useMoonPay(): {
|
|
460
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;
|
|
461
482
|
};
|
|
462
483
|
|
|
463
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
|
@@ -27,7 +27,8 @@ var applePaySpec = {
|
|
|
27
27
|
hidden: false,
|
|
28
28
|
buildParams: (ctx, props) => ({
|
|
29
29
|
clientToken: ctx.core.context.clientToken,
|
|
30
|
-
signature: props.quote
|
|
30
|
+
signature: props.quote,
|
|
31
|
+
...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
|
|
31
32
|
}),
|
|
32
33
|
createCommands: createQuoteCommands,
|
|
33
34
|
reactiveProps: {
|
|
@@ -37,6 +38,8 @@ var applePaySpec = {
|
|
|
37
38
|
switch (msg.kind) {
|
|
38
39
|
case "ready":
|
|
39
40
|
return { kind: "ready" };
|
|
41
|
+
case "buttonPressed":
|
|
42
|
+
return { kind: "buttonPressed" };
|
|
40
43
|
case "complete":
|
|
41
44
|
return { kind: "complete", payload: msg.payload };
|
|
42
45
|
case "challenge":
|
|
@@ -78,6 +81,8 @@ var googlePaySpec = {
|
|
|
78
81
|
switch (msg.kind) {
|
|
79
82
|
case "ready":
|
|
80
83
|
return { kind: "ready" };
|
|
84
|
+
case "buttonPressed":
|
|
85
|
+
return { kind: "buttonPressed" };
|
|
81
86
|
case "complete":
|
|
82
87
|
return { kind: "complete", payload: msg.payload };
|
|
83
88
|
case "challenge":
|
|
@@ -108,7 +113,8 @@ var buyButtonSpec = {
|
|
|
108
113
|
hidden: false,
|
|
109
114
|
buildParams: (ctx, props) => ({
|
|
110
115
|
clientToken: ctx.core.context.clientToken,
|
|
111
|
-
signature: props.quote
|
|
116
|
+
signature: props.quote,
|
|
117
|
+
...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
|
|
112
118
|
}),
|
|
113
119
|
createCommands: createQuoteCommands,
|
|
114
120
|
reactiveProps: {
|
|
@@ -118,6 +124,8 @@ var buyButtonSpec = {
|
|
|
118
124
|
switch (msg.kind) {
|
|
119
125
|
case "ready":
|
|
120
126
|
return { kind: "ready" };
|
|
127
|
+
case "buttonPressed":
|
|
128
|
+
return { kind: "buttonPressed" };
|
|
121
129
|
case "complete":
|
|
122
130
|
return { kind: "complete", payload: msg.payload };
|
|
123
131
|
case "challenge":
|
|
@@ -147,6 +155,14 @@ function applyCredentialsOnComplete(msg, ctx) {
|
|
|
147
155
|
ctx.core.context.setAccessToken(creds.accessToken);
|
|
148
156
|
ctx.core.context.setClientToken(creds.clientToken);
|
|
149
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
|
+
}
|
|
150
166
|
var connectionCheckSpec = {
|
|
151
167
|
channelPrefix: "check",
|
|
152
168
|
path: FRAME_PATHS.checkConnection,
|
|
@@ -154,7 +170,7 @@ var connectionCheckSpec = {
|
|
|
154
170
|
needsKeyPair: true,
|
|
155
171
|
handshakeTimeout: 1e4,
|
|
156
172
|
buildParams: (ctx, props, publicKey) => ({
|
|
157
|
-
sessionToken: ctx
|
|
173
|
+
sessionToken: requireSessionToken(ctx),
|
|
158
174
|
publicKey,
|
|
159
175
|
...props.skipKyc && { skipKyc: true }
|
|
160
176
|
}),
|
|
@@ -176,7 +192,7 @@ var connectSpec = {
|
|
|
176
192
|
hidden: false,
|
|
177
193
|
needsKeyPair: true,
|
|
178
194
|
buildParams: (ctx, props, publicKey) => ({
|
|
179
|
-
sessionToken: ctx
|
|
195
|
+
sessionToken: requireSessionToken(ctx),
|
|
180
196
|
publicKey,
|
|
181
197
|
// Per-call override; `applyThemeParam` in the engine fills the client
|
|
182
198
|
// default for connect (and every other visible frame) when this is absent.
|
|
@@ -244,7 +260,8 @@ var widgetSpec = {
|
|
|
244
260
|
buildParams: (ctx, props) => ({
|
|
245
261
|
flow: "buy",
|
|
246
262
|
clientToken: ctx.core.context.clientToken,
|
|
247
|
-
quoteSignature: props.quote
|
|
263
|
+
quoteSignature: props.quote,
|
|
264
|
+
...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
|
|
248
265
|
}),
|
|
249
266
|
mapMessage: (msg) => {
|
|
250
267
|
switch (msg.kind) {
|
|
@@ -389,7 +406,7 @@ var connectionResetSpec = {
|
|
|
389
406
|
path: FRAME_PATHS.reset,
|
|
390
407
|
hidden: true,
|
|
391
408
|
handshakeTimeout: 5e3,
|
|
392
|
-
buildParams: (ctx) => ({ sessionToken: ctx
|
|
409
|
+
buildParams: (ctx) => ({ sessionToken: requireSessionToken(ctx) }),
|
|
393
410
|
mapMessage: (msg) => {
|
|
394
411
|
if (msg.kind === "complete") return { kind: "complete" };
|
|
395
412
|
if (msg.kind === "error") {
|
|
@@ -637,7 +654,10 @@ async function setupAddCard(deps, opts) {
|
|
|
637
654
|
import { err as err2, ok as ok2 } from "@moonpay/platform-protocol/result";
|
|
638
655
|
async function setupApplePay(deps, opts) {
|
|
639
656
|
try {
|
|
640
|
-
const { handle, dispose } = await deps.mountSession(applePaySpec, {
|
|
657
|
+
const { handle, dispose } = await deps.mountSession(applePaySpec, {
|
|
658
|
+
quote: opts.quote,
|
|
659
|
+
externalTransactionId: opts.externalTransactionId
|
|
660
|
+
});
|
|
641
661
|
handle.onEvent((event) => opts.onEvent?.(event));
|
|
642
662
|
return ok2({ setQuote: handle.commands.setQuote, dispose });
|
|
643
663
|
} catch (e) {
|
|
@@ -709,7 +729,10 @@ async function setupBuy(deps, opts) {
|
|
|
709
729
|
import { err as err5, ok as ok5 } from "@moonpay/platform-protocol/result";
|
|
710
730
|
async function setupBuyButton(deps, opts) {
|
|
711
731
|
try {
|
|
712
|
-
const { handle, dispose } = await deps.mountSession(buyButtonSpec, {
|
|
732
|
+
const { handle, dispose } = await deps.mountSession(buyButtonSpec, {
|
|
733
|
+
quote: opts.quote,
|
|
734
|
+
externalTransactionId: opts.externalTransactionId
|
|
735
|
+
});
|
|
713
736
|
handle.onEvent((event) => opts.onEvent?.(event));
|
|
714
737
|
return ok5({ setQuote: handle.commands.setQuote, dispose });
|
|
715
738
|
} catch (e) {
|
|
@@ -856,7 +879,10 @@ async function setupGooglePay(deps, opts) {
|
|
|
856
879
|
import { err as err11, ok as ok12 } from "@moonpay/platform-protocol/result";
|
|
857
880
|
async function setupWidget(deps, opts) {
|
|
858
881
|
try {
|
|
859
|
-
const { handle, dispose } = await deps.mountSession(widgetSpec, {
|
|
882
|
+
const { handle, dispose } = await deps.mountSession(widgetSpec, {
|
|
883
|
+
quote: opts.quote,
|
|
884
|
+
externalTransactionId: opts.externalTransactionId
|
|
885
|
+
});
|
|
860
886
|
handle.onEvent((event) => opts.onEvent?.(event));
|
|
861
887
|
return ok12({ dispose });
|
|
862
888
|
} catch (e) {
|
|
@@ -1148,13 +1174,15 @@ var styles = StyleSheet.create({
|
|
|
1148
1174
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1149
1175
|
var MoonPayContext = createContext(null);
|
|
1150
1176
|
function MoonPayProvider({
|
|
1151
|
-
sessionToken,
|
|
1177
|
+
sessionToken: sessionTokenProp,
|
|
1152
1178
|
apiBaseUrl,
|
|
1153
1179
|
frameBaseUrl,
|
|
1154
1180
|
theme,
|
|
1155
1181
|
children
|
|
1156
1182
|
}) {
|
|
1157
1183
|
const [frameSlots, setFrameSlots] = useState2([]);
|
|
1184
|
+
const [internalToken, setInternalToken] = useState2(void 0);
|
|
1185
|
+
const sessionToken = sessionTokenProp ?? internalToken;
|
|
1158
1186
|
const addSlot = useCallback2((slot) => {
|
|
1159
1187
|
setFrameSlots((prev) => [...prev, slot]);
|
|
1160
1188
|
}, []);
|
|
@@ -1170,6 +1198,14 @@ function MoonPayProvider({
|
|
|
1170
1198
|
});
|
|
1171
1199
|
}
|
|
1172
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
|
+
);
|
|
1173
1209
|
const client = useMemo2(() => {
|
|
1174
1210
|
const specCtx = { sessionToken, core, frameBaseUrl, theme };
|
|
1175
1211
|
return createRNClient({
|
|
@@ -1177,21 +1213,28 @@ function MoonPayProvider({
|
|
|
1177
1213
|
core
|
|
1178
1214
|
});
|
|
1179
1215
|
}, [sessionToken, frameBaseUrl, core, addSlot, removeSlot, theme?.appearance]);
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
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
|
+
);
|
|
1195
1238
|
}
|
|
1196
1239
|
function useMoonPayContext() {
|
|
1197
1240
|
const ctx = useContext(MoonPayContext);
|
|
@@ -1201,7 +1244,8 @@ function useMoonPayContext() {
|
|
|
1201
1244
|
return ctx;
|
|
1202
1245
|
}
|
|
1203
1246
|
function useMoonPay() {
|
|
1204
|
-
|
|
1247
|
+
const { client, initialize, isInitialized } = useMoonPayContext();
|
|
1248
|
+
return { client, initialize, isInitialized };
|
|
1205
1249
|
}
|
|
1206
1250
|
|
|
1207
1251
|
// src/frame-view.tsx
|
|
@@ -1313,6 +1357,7 @@ function MoonPayAddCard({ onEvent, style }) {
|
|
|
1313
1357
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
1314
1358
|
function MoonPayApplePayButton({
|
|
1315
1359
|
quote,
|
|
1360
|
+
externalTransactionId,
|
|
1316
1361
|
onEvent,
|
|
1317
1362
|
style
|
|
1318
1363
|
}) {
|
|
@@ -1320,7 +1365,7 @@ function MoonPayApplePayButton({
|
|
|
1320
1365
|
MoonPayFrameView,
|
|
1321
1366
|
{
|
|
1322
1367
|
spec: applePaySpec,
|
|
1323
|
-
props: { quote },
|
|
1368
|
+
props: { quote, externalTransactionId },
|
|
1324
1369
|
style,
|
|
1325
1370
|
defaultStyle: { height: 48 },
|
|
1326
1371
|
onEvent
|
|
@@ -1345,12 +1390,17 @@ function MoonPayAuth({ onEvent, style }) {
|
|
|
1345
1390
|
|
|
1346
1391
|
// src/components/buy-button.tsx
|
|
1347
1392
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1348
|
-
function MoonPayBuyButton({
|
|
1393
|
+
function MoonPayBuyButton({
|
|
1394
|
+
quote,
|
|
1395
|
+
externalTransactionId,
|
|
1396
|
+
onEvent,
|
|
1397
|
+
style
|
|
1398
|
+
}) {
|
|
1349
1399
|
return /* @__PURE__ */ jsx8(
|
|
1350
1400
|
MoonPayFrameView,
|
|
1351
1401
|
{
|
|
1352
1402
|
spec: buyButtonSpec,
|
|
1353
|
-
props: { quote },
|
|
1403
|
+
props: { quote, externalTransactionId },
|
|
1354
1404
|
style,
|
|
1355
1405
|
defaultStyle: { height: 48 },
|
|
1356
1406
|
onEvent
|
|
@@ -1466,12 +1516,17 @@ function MoonPayGooglePayButton({
|
|
|
1466
1516
|
|
|
1467
1517
|
// src/components/widget.tsx
|
|
1468
1518
|
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
1469
|
-
function MoonPayWidget({
|
|
1519
|
+
function MoonPayWidget({
|
|
1520
|
+
quote,
|
|
1521
|
+
externalTransactionId,
|
|
1522
|
+
onEvent,
|
|
1523
|
+
style
|
|
1524
|
+
}) {
|
|
1470
1525
|
return /* @__PURE__ */ jsx16(
|
|
1471
1526
|
MoonPayFrameView,
|
|
1472
1527
|
{
|
|
1473
1528
|
spec: widgetSpec,
|
|
1474
|
-
props: { quote },
|
|
1529
|
+
props: { quote, externalTransactionId },
|
|
1475
1530
|
style,
|
|
1476
1531
|
defaultStyle: { flex: 1 },
|
|
1477
1532
|
onEvent
|