@moonpay/platform-sdk-react-native 1.9.0 → 1.11.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.d.cts CHANGED
@@ -28,7 +28,7 @@ import * as GooglePaySdk from '@moonpay/platform-protocol/sdks/google-pay';
28
28
  export { Event as GooglePayEvent, SetupError as SetupGooglePayError } from '@moonpay/platform-protocol/sdks/google-pay';
29
29
  import * as WidgetSdk from '@moonpay/platform-protocol/sdks/widget';
30
30
  export { SetupError as SetupWidgetError, Event as WidgetEvent } from '@moonpay/platform-protocol/sdks/widget';
31
- import { FrameTransport, FrameOptions, ThemeOptions, ListAssetsParams, ListTransactionsParams } from '@moonpay/platform-sdk-core';
31
+ import { FrameTransport, FrameOptions, PresentationMode, ThemeOptions, ListAssetsParams, ListTransactionsParams } from '@moonpay/platform-sdk-core';
32
32
  export { ListAssetsParams, ThemeOptions } from '@moonpay/platform-sdk-core';
33
33
  import { GetPaymentMethodsError, GetQuoteError, GetAssetsError, GetTransactionsError, DevPlatformApiError, GetCustomerError, SubmitCustomerKycError, GetCustomerUploadUrlError, SubmitCustomerFilesError, CreateIdentityError, GetIdentityError, UpdateIdentityError, VerifyIdentityError, GetIdentityUploadUrlError, SubmitIdentityFilesError } from '@moonpay/platform-protocol/api/errors';
34
34
  import { UpdateIdentityRequestBody, IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentityFilesRequestBody, CreateIdentityRequestBody, Identity, IdentityVerificationResponse } from '@moonpay/platform-protocol/api/identity';
@@ -73,6 +73,8 @@ declare class WebViewTransport implements RNFrameTransport {
73
73
  }
74
74
 
75
75
  interface SetupAddCardOptions {
76
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
77
+ presentation?: PresentationMode;
76
78
  /** Callback for add-card frame lifecycle events. */
77
79
  onEvent?: (event: AddCardSdk.Event) => void;
78
80
  }
@@ -85,6 +87,8 @@ interface SetupApplePayOptions {
85
87
  quote: string;
86
88
  /** Partner-assigned identifier for this transaction attempt. */
87
89
  externalTransactionId?: string;
90
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
91
+ presentation?: PresentationMode;
88
92
  /** Callback for Apple Pay lifecycle events. */
89
93
  onEvent?: (event: ApplePaySdk.Event) => void;
90
94
  }
@@ -95,6 +99,8 @@ interface ApplePayFrame {
95
99
  }
96
100
 
97
101
  interface SetupAuthOptions {
102
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
103
+ presentation?: PresentationMode;
98
104
  /** Callback for auth frame lifecycle events. */
99
105
  onEvent?: (event: AuthSdk.Event) => void;
100
106
  }
@@ -121,6 +127,8 @@ interface SetupBuyButtonOptions {
121
127
  quote: string;
122
128
  /** Partner-assigned identifier for this transaction attempt. */
123
129
  externalTransactionId?: string;
130
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
131
+ presentation?: PresentationMode;
124
132
  /** Callback for buy-button frame lifecycle events. */
125
133
  onEvent?: (event: BuyButtonSdk.Event) => void;
126
134
  }
@@ -133,6 +141,8 @@ interface BuyButtonFrame {
133
141
  interface SetupChallengeOptions {
134
142
  /** Full challenge URL received from a frame's `challenge` event. */
135
143
  url: string;
144
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
145
+ presentation?: PresentationMode;
136
146
  /** Callback for challenge frame lifecycle events. */
137
147
  onEvent?: (event: ChallengeSdk.Event) => void;
138
148
  }
@@ -143,6 +153,8 @@ interface ChallengeFrame {
143
153
  interface ConnectOptions {
144
154
  /** Theme for this connect frame. Overrides the provider-level `theme`. */
145
155
  theme?: ThemeOptions;
156
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
157
+ presentation?: PresentationMode;
146
158
  /** Callback for connect lifecycle events. */
147
159
  onEvent?: (event: ConnectSdk.Event) => void;
148
160
  }
@@ -160,6 +172,8 @@ interface GetConnectionOptions {
160
172
  }
161
173
 
162
174
  interface SetupCustomerExportOptions {
175
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
176
+ presentation?: PresentationMode;
163
177
  /** Callback for customer-export frame lifecycle events. */
164
178
  onEvent?: (event: CustomerExportSdk.Event) => void;
165
179
  }
@@ -172,6 +186,8 @@ interface SetupGooglePayOptions {
172
186
  quote: string;
173
187
  /** Partner-assigned identifier for this transaction attempt. */
174
188
  externalTransactionId?: string;
189
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
190
+ presentation?: PresentationMode;
175
191
  /** Callback for Google Pay lifecycle events. */
176
192
  onEvent?: (event: GooglePaySdk.Event) => void;
177
193
  }
@@ -186,6 +202,8 @@ interface SetupWidgetOptions {
186
202
  quote: string;
187
203
  /** Partner-assigned identifier for this transaction attempt. */
188
204
  externalTransactionId?: string;
205
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
206
+ presentation?: PresentationMode;
189
207
  /** Callback for widget lifecycle events. */
190
208
  onEvent?: (event: WidgetSdk.Event) => void;
191
209
  }
@@ -460,16 +478,25 @@ interface MoonPayFrameProps {
460
478
  declare function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null;
461
479
 
462
480
  interface MoonPayProviderProps {
463
- sessionToken: string;
481
+ /**
482
+ * Session token from your server (via `createSession`). Optional — omit it and
483
+ * call `initialize(sessionToken)` from `useMoonPay()` once you've fetched it.
484
+ * When provided, this prop takes precedence over an imperatively-set token.
485
+ */
486
+ sessionToken?: string;
464
487
  apiBaseUrl?: string;
465
488
  frameBaseUrl?: string;
466
489
  /** Theme applied to every visible MoonPay frame (connect, widget, Apple/Google Pay, …). */
467
490
  theme?: ThemeOptions;
468
491
  children: ReactNode;
469
492
  }
470
- declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
493
+ declare function MoonPayProvider({ sessionToken: sessionTokenProp, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
471
494
  declare function useMoonPay(): {
472
495
  client: RNClient;
496
+ /** Set or replace the session token after mount. */
497
+ initialize: (sessionToken: string) => void;
498
+ /** True once a session token (via prop or `initialize()`) is available. */
499
+ isInitialized: boolean;
473
500
  };
474
501
 
475
502
  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
@@ -28,7 +28,7 @@ import * as GooglePaySdk from '@moonpay/platform-protocol/sdks/google-pay';
28
28
  export { Event as GooglePayEvent, SetupError as SetupGooglePayError } from '@moonpay/platform-protocol/sdks/google-pay';
29
29
  import * as WidgetSdk from '@moonpay/platform-protocol/sdks/widget';
30
30
  export { SetupError as SetupWidgetError, Event as WidgetEvent } from '@moonpay/platform-protocol/sdks/widget';
31
- import { FrameTransport, FrameOptions, ThemeOptions, ListAssetsParams, ListTransactionsParams } from '@moonpay/platform-sdk-core';
31
+ import { FrameTransport, FrameOptions, PresentationMode, ThemeOptions, ListAssetsParams, ListTransactionsParams } from '@moonpay/platform-sdk-core';
32
32
  export { ListAssetsParams, ThemeOptions } from '@moonpay/platform-sdk-core';
33
33
  import { GetPaymentMethodsError, GetQuoteError, GetAssetsError, GetTransactionsError, DevPlatformApiError, GetCustomerError, SubmitCustomerKycError, GetCustomerUploadUrlError, SubmitCustomerFilesError, CreateIdentityError, GetIdentityError, UpdateIdentityError, VerifyIdentityError, GetIdentityUploadUrlError, SubmitIdentityFilesError } from '@moonpay/platform-protocol/api/errors';
34
34
  import { UpdateIdentityRequestBody, IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentityFilesRequestBody, CreateIdentityRequestBody, Identity, IdentityVerificationResponse } from '@moonpay/platform-protocol/api/identity';
@@ -73,6 +73,8 @@ declare class WebViewTransport implements RNFrameTransport {
73
73
  }
74
74
 
75
75
  interface SetupAddCardOptions {
76
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
77
+ presentation?: PresentationMode;
76
78
  /** Callback for add-card frame lifecycle events. */
77
79
  onEvent?: (event: AddCardSdk.Event) => void;
78
80
  }
@@ -85,6 +87,8 @@ interface SetupApplePayOptions {
85
87
  quote: string;
86
88
  /** Partner-assigned identifier for this transaction attempt. */
87
89
  externalTransactionId?: string;
90
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
91
+ presentation?: PresentationMode;
88
92
  /** Callback for Apple Pay lifecycle events. */
89
93
  onEvent?: (event: ApplePaySdk.Event) => void;
90
94
  }
@@ -95,6 +99,8 @@ interface ApplePayFrame {
95
99
  }
96
100
 
97
101
  interface SetupAuthOptions {
102
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
103
+ presentation?: PresentationMode;
98
104
  /** Callback for auth frame lifecycle events. */
99
105
  onEvent?: (event: AuthSdk.Event) => void;
100
106
  }
@@ -121,6 +127,8 @@ interface SetupBuyButtonOptions {
121
127
  quote: string;
122
128
  /** Partner-assigned identifier for this transaction attempt. */
123
129
  externalTransactionId?: string;
130
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
131
+ presentation?: PresentationMode;
124
132
  /** Callback for buy-button frame lifecycle events. */
125
133
  onEvent?: (event: BuyButtonSdk.Event) => void;
126
134
  }
@@ -133,6 +141,8 @@ interface BuyButtonFrame {
133
141
  interface SetupChallengeOptions {
134
142
  /** Full challenge URL received from a frame's `challenge` event. */
135
143
  url: string;
144
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
145
+ presentation?: PresentationMode;
136
146
  /** Callback for challenge frame lifecycle events. */
137
147
  onEvent?: (event: ChallengeSdk.Event) => void;
138
148
  }
@@ -143,6 +153,8 @@ interface ChallengeFrame {
143
153
  interface ConnectOptions {
144
154
  /** Theme for this connect frame. Overrides the provider-level `theme`. */
145
155
  theme?: ThemeOptions;
156
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
157
+ presentation?: PresentationMode;
146
158
  /** Callback for connect lifecycle events. */
147
159
  onEvent?: (event: ConnectSdk.Event) => void;
148
160
  }
@@ -160,6 +172,8 @@ interface GetConnectionOptions {
160
172
  }
161
173
 
162
174
  interface SetupCustomerExportOptions {
175
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
176
+ presentation?: PresentationMode;
163
177
  /** Callback for customer-export frame lifecycle events. */
164
178
  onEvent?: (event: CustomerExportSdk.Event) => void;
165
179
  }
@@ -172,6 +186,8 @@ interface SetupGooglePayOptions {
172
186
  quote: string;
173
187
  /** Partner-assigned identifier for this transaction attempt. */
174
188
  externalTransactionId?: string;
189
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
190
+ presentation?: PresentationMode;
175
191
  /** Callback for Google Pay lifecycle events. */
176
192
  onEvent?: (event: GooglePaySdk.Event) => void;
177
193
  }
@@ -186,6 +202,8 @@ interface SetupWidgetOptions {
186
202
  quote: string;
187
203
  /** Partner-assigned identifier for this transaction attempt. */
188
204
  externalTransactionId?: string;
205
+ /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
206
+ presentation?: PresentationMode;
189
207
  /** Callback for widget lifecycle events. */
190
208
  onEvent?: (event: WidgetSdk.Event) => void;
191
209
  }
@@ -460,16 +478,25 @@ interface MoonPayFrameProps {
460
478
  declare function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null;
461
479
 
462
480
  interface MoonPayProviderProps {
463
- sessionToken: string;
481
+ /**
482
+ * Session token from your server (via `createSession`). Optional — omit it and
483
+ * call `initialize(sessionToken)` from `useMoonPay()` once you've fetched it.
484
+ * When provided, this prop takes precedence over an imperatively-set token.
485
+ */
486
+ sessionToken?: string;
464
487
  apiBaseUrl?: string;
465
488
  frameBaseUrl?: string;
466
489
  /** Theme applied to every visible MoonPay frame (connect, widget, Apple/Google Pay, …). */
467
490
  theme?: ThemeOptions;
468
491
  children: ReactNode;
469
492
  }
470
- declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
493
+ declare function MoonPayProvider({ sessionToken: sessionTokenProp, apiBaseUrl, frameBaseUrl, theme, children, }: MoonPayProviderProps): JSX.Element;
471
494
  declare function useMoonPay(): {
472
495
  client: RNClient;
496
+ /** Set or replace the session token after mount. */
497
+ initialize: (sessionToken: string) => void;
498
+ /** True once a session token (via prop or `initialize()`) is available. */
499
+ isInitialized: boolean;
473
500
  };
474
501
 
475
502
  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
@@ -7,8 +7,10 @@ import {
7
7
  ConnectionStatus
8
8
  } from "@moonpay/platform-protocol/models/connection";
9
9
  import {
10
+ applyPresentationParam,
10
11
  decryptCredentials,
11
12
  FRAME_PATHS,
13
+ presentationParams,
12
14
  themeParams
13
15
  } from "@moonpay/platform-sdk-core";
14
16
  function createQuoteCommands(send, channelId) {
@@ -28,7 +30,8 @@ var applePaySpec = {
28
30
  buildParams: (ctx, props) => ({
29
31
  clientToken: ctx.core.context.clientToken,
30
32
  signature: props.quote,
31
- ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
33
+ ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId },
34
+ ...presentationParams(props.presentation)
32
35
  }),
33
36
  createCommands: createQuoteCommands,
34
37
  reactiveProps: {
@@ -71,7 +74,8 @@ var googlePaySpec = {
71
74
  buildParams: (ctx, props) => ({
72
75
  clientToken: ctx.core.context.clientToken,
73
76
  signature: props.quote,
74
- ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
77
+ ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId },
78
+ ...presentationParams(props.presentation)
75
79
  }),
76
80
  createCommands: createQuoteCommands,
77
81
  reactiveProps: {
@@ -114,7 +118,8 @@ var buyButtonSpec = {
114
118
  buildParams: (ctx, props) => ({
115
119
  clientToken: ctx.core.context.clientToken,
116
120
  signature: props.quote,
117
- ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
121
+ ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId },
122
+ ...presentationParams(props.presentation)
118
123
  }),
119
124
  createCommands: createQuoteCommands,
120
125
  reactiveProps: {
@@ -155,6 +160,14 @@ function applyCredentialsOnComplete(msg, ctx) {
155
160
  ctx.core.context.setAccessToken(creds.accessToken);
156
161
  ctx.core.context.setClientToken(creds.clientToken);
157
162
  }
163
+ function requireSessionToken(ctx) {
164
+ if (!ctx.sessionToken) {
165
+ throw new Error(
166
+ "No session token \u2014 pass sessionToken to <MoonPayProvider> or call initialize() from useMoonPay() before starting a connection."
167
+ );
168
+ }
169
+ return ctx.sessionToken;
170
+ }
158
171
  var connectionCheckSpec = {
159
172
  channelPrefix: "check",
160
173
  path: FRAME_PATHS.checkConnection,
@@ -162,7 +175,7 @@ var connectionCheckSpec = {
162
175
  needsKeyPair: true,
163
176
  handshakeTimeout: 1e4,
164
177
  buildParams: (ctx, props, publicKey) => ({
165
- sessionToken: ctx.sessionToken,
178
+ sessionToken: requireSessionToken(ctx),
166
179
  publicKey,
167
180
  ...props.skipKyc && { skipKyc: true }
168
181
  }),
@@ -183,13 +196,22 @@ var connectSpec = {
183
196
  path: FRAME_PATHS.connect,
184
197
  hidden: false,
185
198
  needsKeyPair: true,
186
- buildParams: (ctx, props, publicKey) => ({
187
- sessionToken: ctx.sessionToken,
188
- publicKey,
189
- // Per-call override; `applyThemeParam` in the engine fills the client
190
- // default for connect (and every other visible frame) when this is absent.
191
- ...themeParams(props.theme)
192
- }),
199
+ buildParams: (ctx, props, publicKey) => {
200
+ const clientToken = ctx.core.context.clientToken;
201
+ if (!clientToken) {
202
+ throw new Error(
203
+ 'No clientToken in context \u2014 call getConnection() first and ensure it resolved with status "connectionRequired".'
204
+ );
205
+ }
206
+ return {
207
+ clientToken,
208
+ publicKey,
209
+ // Per-call override; `applyThemeParam` in the engine fills the client
210
+ // default for connect (and every other visible frame) when this is absent.
211
+ ...themeParams(props.theme),
212
+ ...presentationParams(props.presentation)
213
+ };
214
+ },
193
215
  onMessageEffect: applyCredentialsOnComplete,
194
216
  mapMessage: (msg) => {
195
217
  switch (msg.kind) {
@@ -213,14 +235,14 @@ var authSpec = {
213
235
  path: FRAME_PATHS.auth,
214
236
  hidden: false,
215
237
  needsKeyPair: true,
216
- buildParams: (ctx, _props, publicKey) => {
238
+ buildParams: (ctx, props, publicKey) => {
217
239
  const clientToken = ctx.core.context.clientToken;
218
240
  if (!clientToken) {
219
241
  throw new Error(
220
242
  'No clientToken in context \u2014 call getConnection() first and ensure it resolved with status "connectionRequired".'
221
243
  );
222
244
  }
223
- return { clientToken, publicKey };
245
+ return { clientToken, publicKey, ...presentationParams(props.presentation) };
224
246
  },
225
247
  onMessageEffect: applyCredentialsOnComplete,
226
248
  mapMessage: (msg) => {
@@ -253,7 +275,8 @@ var widgetSpec = {
253
275
  flow: "buy",
254
276
  clientToken: ctx.core.context.clientToken,
255
277
  quoteSignature: props.quote,
256
- ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
278
+ ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId },
279
+ ...presentationParams(props.presentation)
257
280
  }),
258
281
  mapMessage: (msg) => {
259
282
  switch (msg.kind) {
@@ -315,7 +338,10 @@ var addCardSpec = {
315
338
  channelPrefix: "add-card",
316
339
  path: FRAME_PATHS.addCard,
317
340
  hidden: false,
318
- buildParams: (ctx) => ({ clientToken: ctx.core.context.clientToken }),
341
+ buildParams: (ctx, props) => ({
342
+ clientToken: ctx.core.context.clientToken,
343
+ ...presentationParams(props.presentation)
344
+ }),
319
345
  mapMessage: (msg) => {
320
346
  switch (msg.kind) {
321
347
  case "ready":
@@ -340,7 +366,10 @@ var customerExportSpec = {
340
366
  channelPrefix: "customer-export",
341
367
  path: FRAME_PATHS.customerExport,
342
368
  hidden: false,
343
- buildParams: (ctx) => ({ clientToken: ctx.core.context.clientToken }),
369
+ buildParams: (ctx, props) => ({
370
+ clientToken: ctx.core.context.clientToken,
371
+ ...presentationParams(props.presentation)
372
+ }),
344
373
  mapMessage: (msg) => {
345
374
  switch (msg.kind) {
346
375
  case "ready":
@@ -372,7 +401,7 @@ var challengeSpec = {
372
401
  buildUrl: (_ctx, props, channelId) => {
373
402
  const url = new URL(props.url);
374
403
  url.searchParams.set("channelId", channelId);
375
- return url.toString();
404
+ return applyPresentationParam(url.toString(), props.presentation);
376
405
  },
377
406
  mapMessage: (msg) => {
378
407
  switch (msg.kind) {
@@ -398,7 +427,7 @@ var connectionResetSpec = {
398
427
  path: FRAME_PATHS.reset,
399
428
  hidden: true,
400
429
  handshakeTimeout: 5e3,
401
- buildParams: (ctx) => ({ sessionToken: ctx.sessionToken }),
430
+ buildParams: (ctx) => ({ sessionToken: requireSessionToken(ctx) }),
402
431
  mapMessage: (msg) => {
403
432
  if (msg.kind === "complete") return { kind: "complete" };
404
433
  if (msg.kind === "error") {
@@ -631,7 +660,9 @@ import {
631
660
  import { err, ok } from "@moonpay/platform-protocol/result";
632
661
  async function setupAddCard(deps, opts) {
633
662
  try {
634
- const { handle, dispose } = await deps.mountSession(addCardSpec, {});
663
+ const { handle, dispose } = await deps.mountSession(addCardSpec, {
664
+ presentation: opts.presentation
665
+ });
635
666
  handle.onEvent((event) => opts.onEvent?.(event));
636
667
  return ok({ dispose });
637
668
  } catch (e) {
@@ -648,7 +679,8 @@ async function setupApplePay(deps, opts) {
648
679
  try {
649
680
  const { handle, dispose } = await deps.mountSession(applePaySpec, {
650
681
  quote: opts.quote,
651
- externalTransactionId: opts.externalTransactionId
682
+ externalTransactionId: opts.externalTransactionId,
683
+ presentation: opts.presentation
652
684
  });
653
685
  handle.onEvent((event) => opts.onEvent?.(event));
654
686
  return ok2({ setQuote: handle.commands.setQuote, dispose });
@@ -670,7 +702,9 @@ async function setupAuth(deps, opts) {
670
702
  });
671
703
  }
672
704
  try {
673
- const { handle, dispose } = await deps.mountSession(authSpec, {});
705
+ const { handle, dispose } = await deps.mountSession(authSpec, {
706
+ presentation: opts.presentation
707
+ });
674
708
  return await new Promise((resolve) => {
675
709
  handle.onEvent((event) => {
676
710
  opts.onEvent?.(event);
@@ -723,7 +757,8 @@ async function setupBuyButton(deps, opts) {
723
757
  try {
724
758
  const { handle, dispose } = await deps.mountSession(buyButtonSpec, {
725
759
  quote: opts.quote,
726
- externalTransactionId: opts.externalTransactionId
760
+ externalTransactionId: opts.externalTransactionId,
761
+ presentation: opts.presentation
727
762
  });
728
763
  handle.onEvent((event) => opts.onEvent?.(event));
729
764
  return ok5({ setQuote: handle.commands.setQuote, dispose });
@@ -746,7 +781,10 @@ async function setupChallenge(deps, opts) {
746
781
  });
747
782
  }
748
783
  try {
749
- const { handle, dispose } = await deps.mountSession(challengeSpec, { url: opts.url });
784
+ const { handle, dispose } = await deps.mountSession(challengeSpec, {
785
+ url: opts.url,
786
+ presentation: opts.presentation
787
+ });
750
788
  handle.onEvent((event) => opts.onEvent?.(event));
751
789
  return ok6({ dispose });
752
790
  } catch (e) {
@@ -761,7 +799,10 @@ async function setupChallenge(deps, opts) {
761
799
  import { err as err7, ok as ok7 } from "@moonpay/platform-protocol/result";
762
800
  async function connect(deps, opts) {
763
801
  try {
764
- const { handle, dispose } = await deps.mountSession(connectSpec, { theme: opts.theme });
802
+ const { handle, dispose } = await deps.mountSession(connectSpec, {
803
+ theme: opts.theme,
804
+ presentation: opts.presentation
805
+ });
765
806
  return await new Promise((resolve) => {
766
807
  handle.onEvent((event) => {
767
808
  opts.onEvent?.(event);
@@ -838,7 +879,9 @@ async function resetConnection(deps) {
838
879
  import { err as err9, ok as ok10 } from "@moonpay/platform-protocol/result";
839
880
  async function setupCustomerExport(deps, opts) {
840
881
  try {
841
- const { handle, dispose } = await deps.mountSession(customerExportSpec, {});
882
+ const { handle, dispose } = await deps.mountSession(customerExportSpec, {
883
+ presentation: opts.presentation
884
+ });
842
885
  handle.onEvent((event) => opts.onEvent?.(event));
843
886
  return ok10({ dispose });
844
887
  } catch (e) {
@@ -855,7 +898,8 @@ async function setupGooglePay(deps, opts) {
855
898
  try {
856
899
  const { handle, dispose } = await deps.mountSession(googlePaySpec, {
857
900
  quote: opts.quote,
858
- externalTransactionId: opts.externalTransactionId
901
+ externalTransactionId: opts.externalTransactionId,
902
+ presentation: opts.presentation
859
903
  });
860
904
  handle.onEvent((event) => opts.onEvent?.(event));
861
905
  return ok11({ setQuote: handle.commands.setQuote, dispose });
@@ -873,7 +917,8 @@ async function setupWidget(deps, opts) {
873
917
  try {
874
918
  const { handle, dispose } = await deps.mountSession(widgetSpec, {
875
919
  quote: opts.quote,
876
- externalTransactionId: opts.externalTransactionId
920
+ externalTransactionId: opts.externalTransactionId,
921
+ presentation: opts.presentation
877
922
  });
878
923
  handle.onEvent((event) => opts.onEvent?.(event));
879
924
  return ok12({ dispose });
@@ -1166,13 +1211,15 @@ var styles = StyleSheet.create({
1166
1211
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1167
1212
  var MoonPayContext = createContext(null);
1168
1213
  function MoonPayProvider({
1169
- sessionToken,
1214
+ sessionToken: sessionTokenProp,
1170
1215
  apiBaseUrl,
1171
1216
  frameBaseUrl,
1172
1217
  theme,
1173
1218
  children
1174
1219
  }) {
1175
1220
  const [frameSlots, setFrameSlots] = useState2([]);
1221
+ const [internalToken, setInternalToken] = useState2(void 0);
1222
+ const sessionToken = sessionTokenProp ?? internalToken;
1176
1223
  const addSlot = useCallback2((slot) => {
1177
1224
  setFrameSlots((prev) => [...prev, slot]);
1178
1225
  }, []);
@@ -1188,6 +1235,14 @@ function MoonPayProvider({
1188
1235
  });
1189
1236
  }
1190
1237
  const core = coreRef.current;
1238
+ const initialize = useCallback2(
1239
+ (token) => {
1240
+ core.context.setAccessToken("");
1241
+ core.context.setClientToken("");
1242
+ setInternalToken(token);
1243
+ },
1244
+ [core]
1245
+ );
1191
1246
  const client = useMemo2(() => {
1192
1247
  const specCtx = { sessionToken, core, frameBaseUrl, theme };
1193
1248
  return createRNClient({
@@ -1195,21 +1250,28 @@ function MoonPayProvider({
1195
1250
  core
1196
1251
  });
1197
1252
  }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot, theme?.appearance]);
1198
- return /* @__PURE__ */ jsxs2(MoonPayContext.Provider, { value: { client, sessionToken, core, frameBaseUrl, theme }, children: [
1199
- children,
1200
- frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ jsx3(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
1201
- frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ jsx3(
1202
- VisibleFrameSlotSheet,
1203
- {
1204
- slot,
1205
- onClose: () => {
1206
- slot.dispose();
1207
- removeSlot(slot.id);
1208
- }
1209
- },
1210
- slot.id
1211
- ))
1212
- ] });
1253
+ const isInitialized = sessionToken !== void 0;
1254
+ return /* @__PURE__ */ jsxs2(
1255
+ MoonPayContext.Provider,
1256
+ {
1257
+ value: { client, sessionToken, core, frameBaseUrl, theme, initialize, isInitialized },
1258
+ children: [
1259
+ children,
1260
+ frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ jsx3(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
1261
+ frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ jsx3(
1262
+ VisibleFrameSlotSheet,
1263
+ {
1264
+ slot,
1265
+ onClose: () => {
1266
+ slot.dispose();
1267
+ removeSlot(slot.id);
1268
+ }
1269
+ },
1270
+ slot.id
1271
+ ))
1272
+ ]
1273
+ }
1274
+ );
1213
1275
  }
1214
1276
  function useMoonPayContext() {
1215
1277
  const ctx = useContext(MoonPayContext);
@@ -1219,7 +1281,8 @@ function useMoonPayContext() {
1219
1281
  return ctx;
1220
1282
  }
1221
1283
  function useMoonPay() {
1222
- return useMoonPayContext();
1284
+ const { client, initialize, isInitialized } = useMoonPayContext();
1285
+ return { client, initialize, isInitialized };
1223
1286
  }
1224
1287
 
1225
1288
  // src/frame-view.tsx