@moonpay/platform-sdk-react-native 0.3.0 → 1.0.1
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 +370 -0
- package/dist/index.cjs +1068 -653
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +276 -82
- package/dist/index.d.ts +276 -82
- package/dist/index.js +1066 -665
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
package/dist/index.cjs
CHANGED
|
@@ -30,12 +30,394 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
ConnectionStatus: () => import_connection2.ConnectionStatus,
|
|
34
|
+
MoonPayAddCard: () => MoonPayAddCard,
|
|
35
|
+
MoonPayApplePayButton: () => MoonPayApplePayButton,
|
|
36
|
+
MoonPayAuth: () => MoonPayAuth,
|
|
37
|
+
MoonPayBuyButton: () => MoonPayBuyButton,
|
|
38
|
+
MoonPayBuyFrame: () => MoonPayBuyFrame,
|
|
39
|
+
MoonPayChallenge: () => MoonPayChallenge,
|
|
40
|
+
MoonPayConnect: () => MoonPayConnect,
|
|
41
|
+
MoonPayConnectionCheck: () => MoonPayConnectionCheck,
|
|
42
|
+
MoonPayConnectionReset: () => MoonPayConnectionReset,
|
|
33
43
|
MoonPayFrame: () => MoonPayFrame,
|
|
44
|
+
MoonPayGooglePayButton: () => MoonPayGooglePayButton,
|
|
34
45
|
MoonPayProvider: () => MoonPayProvider,
|
|
46
|
+
MoonPayWidget: () => MoonPayWidget,
|
|
35
47
|
WebViewTransport: () => WebViewTransport,
|
|
36
48
|
useMoonPay: () => useMoonPay
|
|
37
49
|
});
|
|
38
50
|
module.exports = __toCommonJS(src_exports);
|
|
51
|
+
var import_connection2 = require("@moonpay/platform-protocol/models/connection");
|
|
52
|
+
|
|
53
|
+
// src/frame-specs.ts
|
|
54
|
+
var import_connection = require("@moonpay/platform-protocol/models/connection");
|
|
55
|
+
var import_platform_sdk_core = require("@moonpay/platform-sdk-core");
|
|
56
|
+
function createQuoteCommands(send, channelId) {
|
|
57
|
+
return {
|
|
58
|
+
setQuote: (signature) => send({
|
|
59
|
+
version: 2,
|
|
60
|
+
meta: { channelId },
|
|
61
|
+
kind: "setQuote",
|
|
62
|
+
payload: { quote: { signature } }
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var applePaySpec = {
|
|
67
|
+
channelPrefix: "applepay",
|
|
68
|
+
path: import_platform_sdk_core.FRAME_PATHS.applePay,
|
|
69
|
+
hidden: false,
|
|
70
|
+
buildParams: (ctx, props) => ({
|
|
71
|
+
clientToken: ctx.core.context.clientToken,
|
|
72
|
+
signature: props.quote
|
|
73
|
+
}),
|
|
74
|
+
createCommands: createQuoteCommands,
|
|
75
|
+
reactiveProps: {
|
|
76
|
+
quote: (commands, quote) => commands.setQuote(quote)
|
|
77
|
+
},
|
|
78
|
+
mapMessage: (msg, commands) => {
|
|
79
|
+
switch (msg.kind) {
|
|
80
|
+
case "ready":
|
|
81
|
+
return { kind: "ready" };
|
|
82
|
+
case "complete":
|
|
83
|
+
return { kind: "complete", payload: msg.payload };
|
|
84
|
+
case "challenge":
|
|
85
|
+
return {
|
|
86
|
+
kind: "challenge",
|
|
87
|
+
payload: msg.payload
|
|
88
|
+
};
|
|
89
|
+
case "error": {
|
|
90
|
+
const payload = msg.payload;
|
|
91
|
+
if (payload.code === "quoteExpired") {
|
|
92
|
+
return { kind: "quoteExpired", payload: { setQuote: commands.setQuote } };
|
|
93
|
+
}
|
|
94
|
+
if (payload.code === "applePayUnavailable") {
|
|
95
|
+
return { kind: "unsupported" };
|
|
96
|
+
}
|
|
97
|
+
const kind = payload.code === "generic" ? "genericError" : payload.code;
|
|
98
|
+
return { kind: "error", payload: { kind, message: payload.message } };
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
errorEvent: (message) => ({ kind: "error", payload: { kind: "genericError", message } })
|
|
105
|
+
};
|
|
106
|
+
var googlePaySpec = {
|
|
107
|
+
channelPrefix: "googlepay",
|
|
108
|
+
path: import_platform_sdk_core.FRAME_PATHS.googlePay,
|
|
109
|
+
hidden: false,
|
|
110
|
+
buildParams: (ctx, props) => ({
|
|
111
|
+
clientToken: ctx.core.context.clientToken,
|
|
112
|
+
signature: props.quote,
|
|
113
|
+
...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
|
|
114
|
+
}),
|
|
115
|
+
createCommands: createQuoteCommands,
|
|
116
|
+
reactiveProps: {
|
|
117
|
+
quote: (commands, quote) => commands.setQuote(quote)
|
|
118
|
+
},
|
|
119
|
+
mapMessage: (msg, commands) => {
|
|
120
|
+
switch (msg.kind) {
|
|
121
|
+
case "ready":
|
|
122
|
+
return { kind: "ready" };
|
|
123
|
+
case "complete":
|
|
124
|
+
return { kind: "complete", payload: msg.payload };
|
|
125
|
+
case "challenge":
|
|
126
|
+
return {
|
|
127
|
+
kind: "challenge",
|
|
128
|
+
payload: msg.payload
|
|
129
|
+
};
|
|
130
|
+
case "error": {
|
|
131
|
+
const payload = msg.payload;
|
|
132
|
+
if (payload.code === "quoteExpired") {
|
|
133
|
+
return { kind: "quoteExpired", payload: { setQuote: commands.setQuote } };
|
|
134
|
+
}
|
|
135
|
+
if (payload.code === "googlePayUnavailable") {
|
|
136
|
+
return { kind: "unsupported" };
|
|
137
|
+
}
|
|
138
|
+
const kind = payload.code === "generic" ? "genericError" : payload.code;
|
|
139
|
+
return { kind: "error", payload: { kind, message: payload.message } };
|
|
140
|
+
}
|
|
141
|
+
default:
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
errorEvent: (message) => ({ kind: "error", payload: { kind: "genericError", message } })
|
|
146
|
+
};
|
|
147
|
+
var buyButtonSpec = {
|
|
148
|
+
channelPrefix: "buy-button",
|
|
149
|
+
path: import_platform_sdk_core.FRAME_PATHS.buyButton,
|
|
150
|
+
hidden: false,
|
|
151
|
+
buildParams: (ctx, props) => ({
|
|
152
|
+
clientToken: ctx.core.context.clientToken,
|
|
153
|
+
signature: props.quote
|
|
154
|
+
}),
|
|
155
|
+
createCommands: createQuoteCommands,
|
|
156
|
+
reactiveProps: {
|
|
157
|
+
quote: (commands, quote) => commands.setQuote(quote)
|
|
158
|
+
},
|
|
159
|
+
mapMessage: (msg) => {
|
|
160
|
+
switch (msg.kind) {
|
|
161
|
+
case "complete":
|
|
162
|
+
return { kind: "complete", payload: msg.payload };
|
|
163
|
+
case "challenge":
|
|
164
|
+
return {
|
|
165
|
+
kind: "challenge",
|
|
166
|
+
payload: msg.payload
|
|
167
|
+
};
|
|
168
|
+
case "error":
|
|
169
|
+
return { kind: "error", payload: msg.payload };
|
|
170
|
+
default:
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
errorEvent: (message) => ({
|
|
175
|
+
kind: "error",
|
|
176
|
+
payload: { code: "generic", message }
|
|
177
|
+
})
|
|
178
|
+
};
|
|
179
|
+
function applyCredentialsOnComplete(msg, ctx) {
|
|
180
|
+
if (msg.kind !== "complete" || !ctx.privateKey)
|
|
181
|
+
return;
|
|
182
|
+
const connection = msg.payload;
|
|
183
|
+
if (connection.status !== import_connection.ConnectionStatus.active && connection.status !== import_connection.ConnectionStatus.connectionRequired) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (!connection.credentials)
|
|
187
|
+
return;
|
|
188
|
+
const creds = (0, import_platform_sdk_core.decryptCredentials)(connection.credentials, ctx.privateKey);
|
|
189
|
+
ctx.core.context.setAccessToken(creds.accessToken);
|
|
190
|
+
ctx.core.context.setClientToken(creds.clientToken);
|
|
191
|
+
}
|
|
192
|
+
var connectionCheckSpec = {
|
|
193
|
+
channelPrefix: "check",
|
|
194
|
+
path: import_platform_sdk_core.FRAME_PATHS.checkConnection,
|
|
195
|
+
hidden: true,
|
|
196
|
+
needsKeyPair: true,
|
|
197
|
+
handshakeTimeout: 1e4,
|
|
198
|
+
buildParams: (ctx, props, publicKey) => ({
|
|
199
|
+
sessionToken: ctx.sessionToken,
|
|
200
|
+
publicKey,
|
|
201
|
+
...props.skipKyc && { skipKyc: true }
|
|
202
|
+
}),
|
|
203
|
+
onMessageEffect: applyCredentialsOnComplete,
|
|
204
|
+
mapMessage: (msg) => {
|
|
205
|
+
if (msg.kind === "complete") {
|
|
206
|
+
return { kind: "complete", payload: msg.payload };
|
|
207
|
+
}
|
|
208
|
+
if (msg.kind === "error") {
|
|
209
|
+
return { kind: "error", payload: msg.payload };
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
},
|
|
213
|
+
errorEvent: (message) => ({ kind: "error", payload: { message } })
|
|
214
|
+
};
|
|
215
|
+
var connectSpec = {
|
|
216
|
+
channelPrefix: "connect",
|
|
217
|
+
path: import_platform_sdk_core.FRAME_PATHS.connect,
|
|
218
|
+
hidden: false,
|
|
219
|
+
needsKeyPair: true,
|
|
220
|
+
buildParams: (ctx, props, publicKey) => ({
|
|
221
|
+
sessionToken: ctx.sessionToken,
|
|
222
|
+
publicKey,
|
|
223
|
+
...props.theme?.appearance && { appearance: props.theme.appearance }
|
|
224
|
+
}),
|
|
225
|
+
onMessageEffect: applyCredentialsOnComplete,
|
|
226
|
+
mapMessage: (msg) => {
|
|
227
|
+
switch (msg.kind) {
|
|
228
|
+
case "ready":
|
|
229
|
+
return { kind: "ready" };
|
|
230
|
+
case "error":
|
|
231
|
+
return { kind: "error", payload: msg.payload };
|
|
232
|
+
case "complete":
|
|
233
|
+
return { kind: "complete", payload: msg.payload };
|
|
234
|
+
default:
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
errorEvent: (message) => ({
|
|
239
|
+
kind: "error",
|
|
240
|
+
payload: { code: import_connection.ConnectionErrorCode.connectionFailedGeneric, message }
|
|
241
|
+
})
|
|
242
|
+
};
|
|
243
|
+
var authSpec = {
|
|
244
|
+
channelPrefix: "auth",
|
|
245
|
+
path: import_platform_sdk_core.FRAME_PATHS.auth,
|
|
246
|
+
hidden: false,
|
|
247
|
+
needsKeyPair: true,
|
|
248
|
+
buildParams: (ctx, _props, publicKey) => {
|
|
249
|
+
const clientToken = ctx.core.context.clientToken;
|
|
250
|
+
if (!clientToken) {
|
|
251
|
+
throw new Error(
|
|
252
|
+
'No clientToken in context \u2014 call getConnection() first and ensure it resolved with status "connectionRequired".'
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
return { clientToken, publicKey };
|
|
256
|
+
},
|
|
257
|
+
onMessageEffect: applyCredentialsOnComplete,
|
|
258
|
+
mapMessage: (msg) => {
|
|
259
|
+
switch (msg.kind) {
|
|
260
|
+
case "ready":
|
|
261
|
+
return { kind: "ready" };
|
|
262
|
+
case "error":
|
|
263
|
+
return { kind: "error", payload: msg.payload };
|
|
264
|
+
case "complete": {
|
|
265
|
+
const connection = msg.payload;
|
|
266
|
+
if (connection.status === import_connection.ConnectionStatus.active || connection.status === import_connection.ConnectionStatus.termsAcceptanceRequired) {
|
|
267
|
+
return { kind: "complete", payload: msg.payload };
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
default:
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
errorEvent: (message) => ({
|
|
276
|
+
kind: "error",
|
|
277
|
+
payload: { code: import_connection.ConnectionErrorCode.connectionFailedGeneric, message }
|
|
278
|
+
})
|
|
279
|
+
};
|
|
280
|
+
var widgetSpec = {
|
|
281
|
+
channelPrefix: "widget",
|
|
282
|
+
path: import_platform_sdk_core.FRAME_PATHS.widget,
|
|
283
|
+
hidden: false,
|
|
284
|
+
buildParams: (ctx, props) => ({
|
|
285
|
+
flow: "buy",
|
|
286
|
+
clientToken: ctx.core.context.clientToken,
|
|
287
|
+
quoteSignature: props.quote
|
|
288
|
+
}),
|
|
289
|
+
mapMessage: (msg) => {
|
|
290
|
+
switch (msg.kind) {
|
|
291
|
+
case "ready":
|
|
292
|
+
return { kind: "ready" };
|
|
293
|
+
case "transactionCreated":
|
|
294
|
+
return {
|
|
295
|
+
kind: "transactionCreated",
|
|
296
|
+
payload: msg.payload
|
|
297
|
+
};
|
|
298
|
+
case "complete":
|
|
299
|
+
return { kind: "complete", payload: msg.payload };
|
|
300
|
+
case "error":
|
|
301
|
+
return { kind: "error", payload: msg.payload };
|
|
302
|
+
case "close":
|
|
303
|
+
return { kind: "close" };
|
|
304
|
+
default:
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
errorEvent: (message) => ({
|
|
309
|
+
kind: "error",
|
|
310
|
+
payload: { code: "generic", message }
|
|
311
|
+
})
|
|
312
|
+
};
|
|
313
|
+
var buySpec = {
|
|
314
|
+
channelPrefix: "buy",
|
|
315
|
+
path: import_platform_sdk_core.FRAME_PATHS.buy,
|
|
316
|
+
hidden: true,
|
|
317
|
+
buildParams: (ctx, props) => ({
|
|
318
|
+
clientToken: ctx.core.context.clientToken,
|
|
319
|
+
signature: props.quote,
|
|
320
|
+
...props.externalTransactionId && { externalTransactionId: props.externalTransactionId }
|
|
321
|
+
}),
|
|
322
|
+
createCommands: createQuoteCommands,
|
|
323
|
+
reactiveProps: {
|
|
324
|
+
quote: (commands, quote) => commands.setQuote(quote)
|
|
325
|
+
},
|
|
326
|
+
mapMessage: (msg) => {
|
|
327
|
+
switch (msg.kind) {
|
|
328
|
+
case "ready":
|
|
329
|
+
return { kind: "ready" };
|
|
330
|
+
case "complete":
|
|
331
|
+
return { kind: "complete", payload: msg.payload };
|
|
332
|
+
case "challenge":
|
|
333
|
+
return { kind: "challenge", payload: msg.payload };
|
|
334
|
+
case "error":
|
|
335
|
+
return { kind: "error", payload: msg.payload };
|
|
336
|
+
default:
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
errorEvent: (message) => ({
|
|
341
|
+
kind: "error",
|
|
342
|
+
payload: { code: "generic", message }
|
|
343
|
+
})
|
|
344
|
+
};
|
|
345
|
+
var addCardSpec = {
|
|
346
|
+
channelPrefix: "add-card",
|
|
347
|
+
path: import_platform_sdk_core.FRAME_PATHS.addCard,
|
|
348
|
+
hidden: false,
|
|
349
|
+
buildParams: (ctx) => ({ clientToken: ctx.core.context.clientToken }),
|
|
350
|
+
mapMessage: (msg) => {
|
|
351
|
+
switch (msg.kind) {
|
|
352
|
+
case "ready":
|
|
353
|
+
return { kind: "ready" };
|
|
354
|
+
case "complete":
|
|
355
|
+
return {
|
|
356
|
+
kind: "complete",
|
|
357
|
+
payload: msg.payload
|
|
358
|
+
};
|
|
359
|
+
case "error":
|
|
360
|
+
return { kind: "error", payload: msg.payload };
|
|
361
|
+
default:
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
errorEvent: (message) => ({
|
|
366
|
+
kind: "error",
|
|
367
|
+
payload: { code: "generic", message }
|
|
368
|
+
})
|
|
369
|
+
};
|
|
370
|
+
var challengeSpec = {
|
|
371
|
+
channelPrefix: "challenge",
|
|
372
|
+
path: import_platform_sdk_core.FRAME_PATHS.challenge,
|
|
373
|
+
// documentation only — buildUrl below wins
|
|
374
|
+
hidden: false,
|
|
375
|
+
resolveChannelId: (props, generated) => new URL(props.url).searchParams.get("channelId") || generated,
|
|
376
|
+
buildUrl: (_ctx, props, channelId) => {
|
|
377
|
+
const url = new URL(props.url);
|
|
378
|
+
url.searchParams.set("channelId", channelId);
|
|
379
|
+
return url.toString();
|
|
380
|
+
},
|
|
381
|
+
mapMessage: (msg) => {
|
|
382
|
+
switch (msg.kind) {
|
|
383
|
+
case "ready":
|
|
384
|
+
return { kind: "ready" };
|
|
385
|
+
case "complete":
|
|
386
|
+
return { kind: "complete", payload: msg.payload };
|
|
387
|
+
case "cancelled":
|
|
388
|
+
return { kind: "cancelled", payload: msg.payload };
|
|
389
|
+
case "error":
|
|
390
|
+
return { kind: "error", payload: msg.payload };
|
|
391
|
+
default:
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
errorEvent: (message) => ({
|
|
396
|
+
kind: "error",
|
|
397
|
+
payload: { code: "generic", message }
|
|
398
|
+
})
|
|
399
|
+
};
|
|
400
|
+
var connectionResetSpec = {
|
|
401
|
+
channelPrefix: "reset",
|
|
402
|
+
path: import_platform_sdk_core.FRAME_PATHS.reset,
|
|
403
|
+
hidden: true,
|
|
404
|
+
handshakeTimeout: 5e3,
|
|
405
|
+
buildParams: (ctx) => ({ sessionToken: ctx.sessionToken }),
|
|
406
|
+
mapMessage: (msg) => {
|
|
407
|
+
if (msg.kind === "complete")
|
|
408
|
+
return { kind: "complete" };
|
|
409
|
+
if (msg.kind === "error") {
|
|
410
|
+
const payload = msg.payload;
|
|
411
|
+
return { kind: "error", payload: { message: payload?.message ?? "Reset failed" } };
|
|
412
|
+
}
|
|
413
|
+
return null;
|
|
414
|
+
},
|
|
415
|
+
errorEvent: (message) => ({ kind: "error", payload: { message } })
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
// src/frame-view.tsx
|
|
419
|
+
var import_react3 = require("react");
|
|
420
|
+
var import_react_native3 = require("react-native");
|
|
39
421
|
|
|
40
422
|
// src/frame-component.tsx
|
|
41
423
|
var import_react = require("react");
|
|
@@ -70,10 +452,8 @@ function MoonPayFrame({ transport, hidden, style }) {
|
|
|
70
452
|
) });
|
|
71
453
|
}
|
|
72
454
|
|
|
73
|
-
// src/
|
|
74
|
-
var
|
|
75
|
-
var import_platform_sdk_core = require("@moonpay/platform-sdk-core");
|
|
76
|
-
var import_react2 = require("react");
|
|
455
|
+
// src/frame-engine.ts
|
|
456
|
+
var import_platform_sdk_core2 = require("@moonpay/platform-sdk-core");
|
|
77
457
|
|
|
78
458
|
// src/webview-transport.ts
|
|
79
459
|
var WebViewTransport = class {
|
|
@@ -134,10 +514,406 @@ var WebViewTransport = class {
|
|
|
134
514
|
}
|
|
135
515
|
};
|
|
136
516
|
|
|
517
|
+
// src/frame-engine.ts
|
|
518
|
+
var FrameSessionDisposedError = class extends Error {
|
|
519
|
+
constructor() {
|
|
520
|
+
super("Frame session disposed");
|
|
521
|
+
this.name = "FrameSessionDisposedError";
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
function createFrameSession(spec, ctx, props, overrides = {}) {
|
|
525
|
+
const generated = `${spec.channelPrefix}-${Date.now()}`;
|
|
526
|
+
const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
|
|
527
|
+
const keyPair = spec.needsKeyPair ? (0, import_platform_sdk_core2.generateKeyPair)() : void 0;
|
|
528
|
+
const url = spec.buildUrl ? spec.buildUrl(ctx, props, channelId, keyPair?.publicKey) : (0, import_platform_sdk_core2.buildFrameUrl)(
|
|
529
|
+
spec.path,
|
|
530
|
+
{ ...spec.buildParams?.(ctx, props, keyPair?.publicKey), channelId },
|
|
531
|
+
{ frameBaseUrl: ctx.frameBaseUrl }
|
|
532
|
+
);
|
|
533
|
+
const transport = (overrides.createTransport ?? (() => new WebViewTransport()))();
|
|
534
|
+
let resolvedHandle = null;
|
|
535
|
+
let rejectDisposed;
|
|
536
|
+
const disposedBeforeReady = new Promise((_, reject) => {
|
|
537
|
+
rejectDisposed = reject;
|
|
538
|
+
});
|
|
539
|
+
const handleReady = (0, import_platform_sdk_core2.createFrameOrchestrator)({
|
|
540
|
+
transport,
|
|
541
|
+
channelId,
|
|
542
|
+
url,
|
|
543
|
+
container: null,
|
|
544
|
+
hidden: spec.hidden,
|
|
545
|
+
handshakeTimeout: overrides.handshakeTimeout ?? spec.handshakeTimeout ?? 15e3
|
|
546
|
+
}).then((handle) => {
|
|
547
|
+
const send = (msg) => handle.sendMessage(msg);
|
|
548
|
+
const commands = spec.createCommands?.(send, channelId);
|
|
549
|
+
const eventHandlers = [];
|
|
550
|
+
const disposeHandlers = [];
|
|
551
|
+
let disposeNotified = false;
|
|
552
|
+
const notifyDisposed = () => {
|
|
553
|
+
if (disposeNotified)
|
|
554
|
+
return;
|
|
555
|
+
disposeNotified = true;
|
|
556
|
+
for (const handler of [...disposeHandlers]) {
|
|
557
|
+
handler();
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
handle.onMessage((msg) => {
|
|
561
|
+
let event;
|
|
562
|
+
try {
|
|
563
|
+
spec.onMessageEffect?.(msg, { ...ctx, privateKey: keyPair?.privateKey });
|
|
564
|
+
event = spec.mapMessage(msg, commands);
|
|
565
|
+
} catch (e) {
|
|
566
|
+
event = spec.errorEvent(e instanceof Error ? e.message : "Failed to process frame message");
|
|
567
|
+
}
|
|
568
|
+
if (event !== null) {
|
|
569
|
+
for (const handler of [...eventHandlers]) {
|
|
570
|
+
handler(event);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
const sessionHandle = {
|
|
575
|
+
onEvent(handler) {
|
|
576
|
+
eventHandlers.push(handler);
|
|
577
|
+
return () => {
|
|
578
|
+
const idx = eventHandlers.indexOf(handler);
|
|
579
|
+
if (idx >= 0)
|
|
580
|
+
eventHandlers.splice(idx, 1);
|
|
581
|
+
};
|
|
582
|
+
},
|
|
583
|
+
onMessage: (handler) => handle.onMessage(handler),
|
|
584
|
+
onDispose(handler) {
|
|
585
|
+
disposeHandlers.push(handler);
|
|
586
|
+
return () => {
|
|
587
|
+
const idx = disposeHandlers.indexOf(handler);
|
|
588
|
+
if (idx >= 0)
|
|
589
|
+
disposeHandlers.splice(idx, 1);
|
|
590
|
+
};
|
|
591
|
+
},
|
|
592
|
+
sendMessage: send,
|
|
593
|
+
commands,
|
|
594
|
+
dispose: () => {
|
|
595
|
+
handle.dispose();
|
|
596
|
+
notifyDisposed();
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
resolvedHandle = sessionHandle;
|
|
600
|
+
return sessionHandle;
|
|
601
|
+
});
|
|
602
|
+
const ready = Promise.race([handleReady, disposedBeforeReady]);
|
|
603
|
+
ready.catch(() => {
|
|
604
|
+
});
|
|
605
|
+
return {
|
|
606
|
+
transport,
|
|
607
|
+
channelId,
|
|
608
|
+
url,
|
|
609
|
+
hidden: spec.hidden,
|
|
610
|
+
ready,
|
|
611
|
+
dispose: () => {
|
|
612
|
+
if (resolvedHandle) {
|
|
613
|
+
resolvedHandle.dispose();
|
|
614
|
+
} else {
|
|
615
|
+
transport.dispose();
|
|
616
|
+
rejectDisposed?.(new FrameSessionDisposedError());
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/provider.tsx
|
|
623
|
+
var import_platform_sdk_core3 = require("@moonpay/platform-sdk-core");
|
|
624
|
+
var import_react2 = require("react");
|
|
625
|
+
var import_react_native2 = require("react-native");
|
|
626
|
+
|
|
627
|
+
// src/methods/add-card.ts
|
|
628
|
+
var import_result = require("@moonpay/platform-protocol/result");
|
|
629
|
+
async function setupAddCard(deps, opts) {
|
|
630
|
+
try {
|
|
631
|
+
const { handle, dispose } = await deps.mountSession(addCardSpec, {});
|
|
632
|
+
handle.onEvent((event) => opts.onEvent?.(event));
|
|
633
|
+
return (0, import_result.ok)({ dispose });
|
|
634
|
+
} catch (e) {
|
|
635
|
+
return (0, import_result.err)({
|
|
636
|
+
kind: "genericError",
|
|
637
|
+
message: e instanceof Error ? e.message : "Add card setup failed"
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// src/methods/apple-pay.ts
|
|
643
|
+
var import_result2 = require("@moonpay/platform-protocol/result");
|
|
644
|
+
async function setupApplePay(deps, opts) {
|
|
645
|
+
try {
|
|
646
|
+
const { handle, dispose } = await deps.mountSession(applePaySpec, { quote: opts.quote });
|
|
647
|
+
handle.onEvent((event) => opts.onEvent?.(event));
|
|
648
|
+
return (0, import_result2.ok)({ setQuote: handle.commands.setQuote, dispose });
|
|
649
|
+
} catch (e) {
|
|
650
|
+
return (0, import_result2.err)({
|
|
651
|
+
kind: "genericError",
|
|
652
|
+
message: e instanceof Error ? e.message : "Apple Pay setup failed"
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/methods/auth.ts
|
|
658
|
+
var import_result3 = require("@moonpay/platform-protocol/result");
|
|
659
|
+
async function setupAuth(deps, opts) {
|
|
660
|
+
if (!deps.core.context.clientToken) {
|
|
661
|
+
return (0, import_result3.err)({
|
|
662
|
+
kind: "configurationError",
|
|
663
|
+
message: 'No clientToken in context \u2014 call getConnection() first and ensure it resolved with status "connectionRequired".'
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
try {
|
|
667
|
+
const { handle, dispose } = await deps.mountSession(authSpec, {});
|
|
668
|
+
return await new Promise((resolve) => {
|
|
669
|
+
handle.onEvent((event) => {
|
|
670
|
+
opts.onEvent?.(event);
|
|
671
|
+
if (event.kind === "error") {
|
|
672
|
+
resolve((0, import_result3.err)({ kind: "genericError", message: "Auth frame error" }));
|
|
673
|
+
dispose();
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
handle.onMessage((msg) => {
|
|
677
|
+
if (msg.kind === "complete") {
|
|
678
|
+
resolve((0, import_result3.ok)({ dispose }));
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
handle.onDispose(() => {
|
|
682
|
+
resolve((0, import_result3.err)({ kind: "genericError", message: "Auth flow dismissed" }));
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
} catch (e) {
|
|
686
|
+
if (e instanceof FrameSessionDisposedError) {
|
|
687
|
+
return (0, import_result3.err)({ kind: "genericError", message: "Auth flow dismissed" });
|
|
688
|
+
}
|
|
689
|
+
return (0, import_result3.err)({
|
|
690
|
+
kind: "genericError",
|
|
691
|
+
message: e instanceof Error ? e.message : "Auth setup failed"
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// src/methods/buy.ts
|
|
697
|
+
var import_result4 = require("@moonpay/platform-protocol/result");
|
|
698
|
+
async function setupBuy(deps, opts) {
|
|
699
|
+
try {
|
|
700
|
+
const { handle, dispose } = await deps.mountSession(buySpec, {
|
|
701
|
+
quote: opts.quote,
|
|
702
|
+
externalTransactionId: opts.externalTransactionId
|
|
703
|
+
});
|
|
704
|
+
handle.onEvent((event) => opts.onEvent?.(event));
|
|
705
|
+
return (0, import_result4.ok)({ setQuote: handle.commands.setQuote, dispose });
|
|
706
|
+
} catch (e) {
|
|
707
|
+
return (0, import_result4.err)({
|
|
708
|
+
kind: "genericError",
|
|
709
|
+
message: e instanceof Error ? e.message : "Buy setup failed"
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// src/methods/buy-button.ts
|
|
715
|
+
var import_result5 = require("@moonpay/platform-protocol/result");
|
|
716
|
+
async function setupBuyButton(deps, opts) {
|
|
717
|
+
try {
|
|
718
|
+
const { handle, dispose } = await deps.mountSession(buyButtonSpec, { quote: opts.quote });
|
|
719
|
+
handle.onEvent((event) => opts.onEvent?.(event));
|
|
720
|
+
return (0, import_result5.ok)({ setQuote: handle.commands.setQuote, dispose });
|
|
721
|
+
} catch (e) {
|
|
722
|
+
return (0, import_result5.err)({
|
|
723
|
+
kind: "genericError",
|
|
724
|
+
message: e instanceof Error ? e.message : "Buy button setup failed"
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/methods/challenge.ts
|
|
730
|
+
var import_result6 = require("@moonpay/platform-protocol/result");
|
|
731
|
+
async function setupChallenge(deps, opts) {
|
|
732
|
+
try {
|
|
733
|
+
const { handle, dispose } = await deps.mountSession(challengeSpec, { url: opts.url });
|
|
734
|
+
handle.onEvent((event) => opts.onEvent?.(event));
|
|
735
|
+
return (0, import_result6.ok)({ dispose });
|
|
736
|
+
} catch (e) {
|
|
737
|
+
if (e instanceof TypeError) {
|
|
738
|
+
return (0, import_result6.err)({ kind: "configurationError", message: "Invalid challenge URL" });
|
|
739
|
+
}
|
|
740
|
+
return (0, import_result6.err)({
|
|
741
|
+
kind: "genericError",
|
|
742
|
+
message: e instanceof Error ? e.message : "Challenge setup failed"
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// src/methods/connect.ts
|
|
748
|
+
var import_result7 = require("@moonpay/platform-protocol/result");
|
|
749
|
+
async function connect(deps, opts) {
|
|
750
|
+
try {
|
|
751
|
+
const { handle, dispose } = await deps.mountSession(connectSpec, { theme: opts.theme });
|
|
752
|
+
return await new Promise((resolve) => {
|
|
753
|
+
handle.onEvent((event) => {
|
|
754
|
+
opts.onEvent?.(event);
|
|
755
|
+
if (event.kind === "error") {
|
|
756
|
+
resolve((0, import_result7.err)({ message: "Connection error" }));
|
|
757
|
+
dispose();
|
|
758
|
+
} else if (event.kind === "complete") {
|
|
759
|
+
resolve((0, import_result7.ok)({ dispose }));
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
handle.onDispose(() => {
|
|
763
|
+
resolve((0, import_result7.err)({ message: "Connect flow dismissed" }));
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
} catch (e) {
|
|
767
|
+
if (e instanceof FrameSessionDisposedError) {
|
|
768
|
+
return (0, import_result7.err)({ message: "Connect flow dismissed" });
|
|
769
|
+
}
|
|
770
|
+
return (0, import_result7.err)({
|
|
771
|
+
message: e instanceof Error ? e.message : "Connect failed"
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// src/methods/connection-check.ts
|
|
777
|
+
var import_result8 = require("@moonpay/platform-protocol/result");
|
|
778
|
+
async function getConnection(deps, options = {}) {
|
|
779
|
+
try {
|
|
780
|
+
const { handle, dispose } = await deps.mountSession(connectionCheckSpec, options);
|
|
781
|
+
return await new Promise((resolve) => {
|
|
782
|
+
const timeout = setTimeout(() => {
|
|
783
|
+
dispose();
|
|
784
|
+
resolve((0, import_result8.err)({ message: "Get connection timed out" }));
|
|
785
|
+
}, 1e4);
|
|
786
|
+
handle.onEvent((event) => {
|
|
787
|
+
clearTimeout(timeout);
|
|
788
|
+
dispose();
|
|
789
|
+
if (event.kind === "error") {
|
|
790
|
+
resolve((0, import_result8.err)({ message: event.payload.message }));
|
|
791
|
+
} else {
|
|
792
|
+
resolve((0, import_result8.ok)(event.payload));
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
});
|
|
796
|
+
} catch (e) {
|
|
797
|
+
return (0, import_result8.err)({
|
|
798
|
+
message: e instanceof Error ? e.message : "Failed to check connection"
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// src/methods/connection-reset.ts
|
|
804
|
+
var import_result9 = require("@moonpay/platform-protocol/result");
|
|
805
|
+
async function resetConnection(deps) {
|
|
806
|
+
try {
|
|
807
|
+
const { handle, dispose } = await deps.mountSession(connectionResetSpec, {});
|
|
808
|
+
return await new Promise((resolve) => {
|
|
809
|
+
const timeout = setTimeout(() => {
|
|
810
|
+
dispose();
|
|
811
|
+
resolve((0, import_result9.ok)(void 0));
|
|
812
|
+
}, 5e3);
|
|
813
|
+
handle.onEvent(() => {
|
|
814
|
+
clearTimeout(timeout);
|
|
815
|
+
dispose();
|
|
816
|
+
resolve((0, import_result9.ok)(void 0));
|
|
817
|
+
});
|
|
818
|
+
});
|
|
819
|
+
} catch {
|
|
820
|
+
return (0, import_result9.ok)(void 0);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// src/methods/google-pay.ts
|
|
825
|
+
var import_result10 = require("@moonpay/platform-protocol/result");
|
|
826
|
+
async function setupGooglePay(deps, opts) {
|
|
827
|
+
try {
|
|
828
|
+
const { handle, dispose } = await deps.mountSession(googlePaySpec, {
|
|
829
|
+
quote: opts.quote,
|
|
830
|
+
externalTransactionId: opts.externalTransactionId
|
|
831
|
+
});
|
|
832
|
+
handle.onEvent((event) => opts.onEvent?.(event));
|
|
833
|
+
return (0, import_result10.ok)({ setQuote: handle.commands.setQuote, dispose });
|
|
834
|
+
} catch (e) {
|
|
835
|
+
return (0, import_result10.err)({
|
|
836
|
+
kind: "genericError",
|
|
837
|
+
message: e instanceof Error ? e.message : "Google Pay setup failed"
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// src/methods/widget.ts
|
|
843
|
+
var import_result11 = require("@moonpay/platform-protocol/result");
|
|
844
|
+
async function setupWidget(deps, opts) {
|
|
845
|
+
try {
|
|
846
|
+
const { handle, dispose } = await deps.mountSession(widgetSpec, { quote: opts.quote });
|
|
847
|
+
handle.onEvent((event) => opts.onEvent?.(event));
|
|
848
|
+
return (0, import_result11.ok)({ dispose });
|
|
849
|
+
} catch (e) {
|
|
850
|
+
return (0, import_result11.err)({
|
|
851
|
+
kind: "genericError",
|
|
852
|
+
message: e instanceof Error ? e.message : "Widget setup failed"
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// src/client.ts
|
|
858
|
+
function createRNClient(deps) {
|
|
859
|
+
const { core } = deps;
|
|
860
|
+
return {
|
|
861
|
+
getConnection: (options) => getConnection(deps, options ?? {}),
|
|
862
|
+
connect: (opts) => connect(deps, opts),
|
|
863
|
+
setupAuth: (opts) => setupAuth(deps, opts),
|
|
864
|
+
getPaymentMethods: () => core.getPaymentMethods(),
|
|
865
|
+
getQuote: (params) => core.getQuote(params),
|
|
866
|
+
listTransactions: (params) => core.listTransactions(params),
|
|
867
|
+
getTransaction: (id) => core.getTransaction(id),
|
|
868
|
+
setupWidget: (opts) => setupWidget(deps, opts),
|
|
869
|
+
setupApplePay: (opts) => setupApplePay(deps, opts),
|
|
870
|
+
setupBuy: (opts) => setupBuy(deps, opts),
|
|
871
|
+
setupBuyButton: (opts) => setupBuyButton(deps, opts),
|
|
872
|
+
setupGooglePay: (opts) => setupGooglePay(deps, opts),
|
|
873
|
+
deletePaymentMethod: (id) => core.deletePaymentMethod(id),
|
|
874
|
+
resetConnection: () => resetConnection(deps),
|
|
875
|
+
setupChallenge: (opts) => setupChallenge(deps, opts),
|
|
876
|
+
setupAddCard: (opts) => setupAddCard(deps, opts),
|
|
877
|
+
createIdentity: (body) => core.createIdentity(body),
|
|
878
|
+
getIdentity: (id) => core.getIdentity(id),
|
|
879
|
+
updateIdentity: (id, body) => core.updateIdentity(id, body),
|
|
880
|
+
verifyIdentity: (id) => core.verifyIdentity(id),
|
|
881
|
+
getIdentityUploadUrl: (id, body) => core.getIdentityUploadUrl(id, body),
|
|
882
|
+
submitIdentityFiles: (id, body) => core.submitIdentityFiles(id, body)
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// src/methods/mount-session.ts
|
|
887
|
+
var slotCounter = 0;
|
|
888
|
+
function createMountSession(specCtx, host) {
|
|
889
|
+
return async function mountSession(spec, props) {
|
|
890
|
+
const session = createFrameSession(spec, specCtx, props);
|
|
891
|
+
const slotId = `slot-${++slotCounter}`;
|
|
892
|
+
host.addSlot({
|
|
893
|
+
id: slotId,
|
|
894
|
+
transport: session.transport,
|
|
895
|
+
hidden: session.hidden,
|
|
896
|
+
dispose: () => session.dispose()
|
|
897
|
+
});
|
|
898
|
+
try {
|
|
899
|
+
const handle = await session.ready;
|
|
900
|
+
return {
|
|
901
|
+
handle,
|
|
902
|
+
dispose: () => {
|
|
903
|
+
handle.dispose();
|
|
904
|
+
host.removeSlot(slotId);
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
} catch (e) {
|
|
908
|
+
host.removeSlot(slotId);
|
|
909
|
+
throw e;
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
|
|
137
914
|
// src/provider.tsx
|
|
138
915
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
139
916
|
var MoonPayContext = (0, import_react2.createContext)(null);
|
|
140
|
-
var slotCounter = 0;
|
|
141
917
|
function MoonPayProvider({
|
|
142
918
|
sessionToken,
|
|
143
919
|
apiBaseUrl,
|
|
@@ -153,7 +929,7 @@ function MoonPayProvider({
|
|
|
153
929
|
}, []);
|
|
154
930
|
const coreRef = (0, import_react2.useRef)(null);
|
|
155
931
|
if (!coreRef.current) {
|
|
156
|
-
coreRef.current = (0,
|
|
932
|
+
coreRef.current = (0, import_platform_sdk_core3.createClientCore)({
|
|
157
933
|
apiBaseUrl,
|
|
158
934
|
frameBaseUrl,
|
|
159
935
|
createTransport: () => new WebViewTransport()
|
|
@@ -161,674 +937,313 @@ function MoonPayProvider({
|
|
|
161
937
|
}
|
|
162
938
|
const core = coreRef.current;
|
|
163
939
|
const client = (0, import_react2.useMemo)(() => {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
182
|
-
return { promise, transport };
|
|
183
|
-
}
|
|
184
|
-
async function getConnection(options = {}) {
|
|
185
|
-
const { privateKey, publicKey } = (0, import_platform_sdk_core.generateKeyPair)();
|
|
186
|
-
const channelId = `check-${Date.now()}`;
|
|
187
|
-
const url = (0, import_platform_sdk_core.buildFrameUrl)(
|
|
188
|
-
import_platform_sdk_core.FRAME_PATHS.checkConnection,
|
|
189
|
-
{
|
|
190
|
-
sessionToken,
|
|
191
|
-
channelId,
|
|
192
|
-
publicKey,
|
|
193
|
-
...options.skipKyc && { skipKyc: true }
|
|
940
|
+
const specCtx = { sessionToken, core, frameBaseUrl };
|
|
941
|
+
return createRNClient({
|
|
942
|
+
mountSession: createMountSession(specCtx, { addSlot, removeSlot }),
|
|
943
|
+
core
|
|
944
|
+
});
|
|
945
|
+
}, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);
|
|
946
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(MoonPayContext.Provider, { value: { client, sessionToken, core, frameBaseUrl }, children: [
|
|
947
|
+
children,
|
|
948
|
+
frameSlots.filter((slot) => slot.hidden).map((slot) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonPayFrame, { transport: slot.transport, hidden: true }, slot.id)),
|
|
949
|
+
frameSlots.filter((slot) => !slot.hidden).map((slot) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
950
|
+
import_react_native2.Modal,
|
|
951
|
+
{
|
|
952
|
+
visible: true,
|
|
953
|
+
animationType: "slide",
|
|
954
|
+
onRequestClose: () => {
|
|
955
|
+
slot.dispose();
|
|
956
|
+
removeSlot(slot.id);
|
|
194
957
|
},
|
|
195
|
-
{
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (msg.kind === "complete") {
|
|
221
|
-
clearTimeout(timeout);
|
|
222
|
-
handle.dispose();
|
|
223
|
-
removeSlot(slotId);
|
|
224
|
-
const connection = msg.payload;
|
|
225
|
-
if (connection.status === import_platform_protocol.ConnectionStatus.active) {
|
|
226
|
-
const creds = (0, import_platform_sdk_core.decryptCredentials)(connection.credentials, privateKey);
|
|
227
|
-
core.context.setAccessToken(creds.accessToken);
|
|
228
|
-
core.context.setClientToken(creds.clientToken);
|
|
229
|
-
}
|
|
230
|
-
resolve((0, import_platform_protocol.ok)(connection));
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
} catch (e) {
|
|
235
|
-
return (0, import_platform_protocol.err)({
|
|
236
|
-
message: e instanceof Error ? e.message : "Failed to check connection"
|
|
237
|
-
});
|
|
238
|
-
}
|
|
958
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonPayFrame, { transport: slot.transport })
|
|
959
|
+
},
|
|
960
|
+
slot.id
|
|
961
|
+
))
|
|
962
|
+
] });
|
|
963
|
+
}
|
|
964
|
+
function useMoonPayContext() {
|
|
965
|
+
const ctx = (0, import_react2.useContext)(MoonPayContext);
|
|
966
|
+
if (!ctx) {
|
|
967
|
+
throw new Error("useMoonPay must be used within a <MoonPayProvider>");
|
|
968
|
+
}
|
|
969
|
+
return ctx;
|
|
970
|
+
}
|
|
971
|
+
function useMoonPay() {
|
|
972
|
+
return useMoonPayContext();
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// src/frame-view.tsx
|
|
976
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
977
|
+
function applyReactiveProps(spec, keys, props, applied, handle) {
|
|
978
|
+
for (const key of keys) {
|
|
979
|
+
const next = props[key];
|
|
980
|
+
if (next !== void 0 && next !== applied[key]) {
|
|
981
|
+
spec.reactiveProps?.[key]?.(handle.commands, next);
|
|
982
|
+
applied[key] = next;
|
|
239
983
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
function MoonPayFrameView({
|
|
987
|
+
spec,
|
|
988
|
+
props,
|
|
989
|
+
style,
|
|
990
|
+
defaultStyle,
|
|
991
|
+
onEvent
|
|
992
|
+
}) {
|
|
993
|
+
const { sessionToken, core, frameBaseUrl } = useMoonPayContext();
|
|
994
|
+
const [transport, setTransport] = (0, import_react3.useState)(null);
|
|
995
|
+
const handleRef = (0, import_react3.useRef)(null);
|
|
996
|
+
const onEventRef = (0, import_react3.useRef)(onEvent);
|
|
997
|
+
onEventRef.current = onEvent;
|
|
998
|
+
const propsRef = (0, import_react3.useRef)(props);
|
|
999
|
+
propsRef.current = props;
|
|
1000
|
+
const reactiveKeys = Object.keys(spec.reactiveProps ?? {});
|
|
1001
|
+
const mountProps = {};
|
|
1002
|
+
const liveProps = {};
|
|
1003
|
+
for (const [key, value] of Object.entries(props)) {
|
|
1004
|
+
const k = key;
|
|
1005
|
+
(reactiveKeys.includes(k) ? liveProps : mountProps)[k] = value;
|
|
1006
|
+
}
|
|
1007
|
+
const mountKey = JSON.stringify(mountProps);
|
|
1008
|
+
const liveKey = JSON.stringify(liveProps);
|
|
1009
|
+
const appliedRef = (0, import_react3.useRef)({});
|
|
1010
|
+
(0, import_react3.useEffect)(() => {
|
|
1011
|
+
let disposed = false;
|
|
1012
|
+
let session;
|
|
1013
|
+
const applied = {};
|
|
1014
|
+
for (const key of reactiveKeys) {
|
|
1015
|
+
applied[key] = propsRef.current[key];
|
|
1016
|
+
}
|
|
1017
|
+
appliedRef.current = applied;
|
|
1018
|
+
try {
|
|
1019
|
+
session = createFrameSession(spec, { sessionToken, core, frameBaseUrl }, propsRef.current);
|
|
1020
|
+
} catch (e) {
|
|
1021
|
+
onEventRef.current?.(
|
|
1022
|
+
spec.errorEvent(e instanceof Error ? e.message : "Failed to create frame")
|
|
252
1023
|
);
|
|
253
|
-
|
|
254
|
-
const { promise } = createManagedFrame({ url, channelId, hidden: false });
|
|
255
|
-
const { handle, slotId } = await promise;
|
|
256
|
-
return new Promise((resolve) => {
|
|
257
|
-
handle.onMessage((msg) => {
|
|
258
|
-
if (msg.kind === "ready") {
|
|
259
|
-
opts.onEvent?.({ kind: "ready" });
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
if (msg.kind === "error") {
|
|
263
|
-
const payload = msg.payload;
|
|
264
|
-
opts.onEvent?.({ kind: "error", payload });
|
|
265
|
-
handle.dispose();
|
|
266
|
-
removeSlot(slotId);
|
|
267
|
-
resolve((0, import_platform_protocol.err)({ message: "Connection error" }));
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if (msg.kind === "complete") {
|
|
271
|
-
const connection = msg.payload;
|
|
272
|
-
if (connection.status === import_platform_protocol.ConnectionStatus.active) {
|
|
273
|
-
const creds = (0, import_platform_sdk_core.decryptCredentials)(connection.credentials, privateKey);
|
|
274
|
-
core.context.setAccessToken(creds.accessToken);
|
|
275
|
-
core.context.setClientToken(creds.clientToken);
|
|
276
|
-
}
|
|
277
|
-
opts.onEvent?.({ kind: "complete", payload: connection });
|
|
278
|
-
resolve(
|
|
279
|
-
(0, import_platform_protocol.ok)({
|
|
280
|
-
dispose: () => {
|
|
281
|
-
handle.dispose();
|
|
282
|
-
removeSlot(slotId);
|
|
283
|
-
}
|
|
284
|
-
})
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
} catch (e) {
|
|
290
|
-
return (0, import_platform_protocol.err)({
|
|
291
|
-
message: e instanceof Error ? e.message : "Connect failed"
|
|
292
|
-
});
|
|
293
|
-
}
|
|
1024
|
+
return;
|
|
294
1025
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
message: 'No clientToken in context \u2014 call getConnection() first and ensure it resolved with status "connectionRequired".'
|
|
301
|
-
});
|
|
1026
|
+
setTransport(session.transport);
|
|
1027
|
+
session.ready.then((handle) => {
|
|
1028
|
+
if (disposed) {
|
|
1029
|
+
handle.dispose();
|
|
1030
|
+
return;
|
|
302
1031
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const { promise } = createManagedFrame({ url, channelId, hidden: false });
|
|
312
|
-
const { handle, slotId } = await promise;
|
|
313
|
-
return new Promise((resolve) => {
|
|
314
|
-
handle.onMessage((msg) => {
|
|
315
|
-
if (msg.kind === "ready") {
|
|
316
|
-
opts.onEvent?.({ kind: "ready" });
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
if (msg.kind === "error") {
|
|
320
|
-
const payload = msg.payload;
|
|
321
|
-
opts.onEvent?.({ kind: "error", payload });
|
|
322
|
-
handle.dispose();
|
|
323
|
-
removeSlot(slotId);
|
|
324
|
-
resolve((0, import_platform_protocol.err)({ kind: "genericError", message: "Auth frame error" }));
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
if (msg.kind === "complete") {
|
|
328
|
-
const connection = msg.payload;
|
|
329
|
-
if (connection.status === import_platform_protocol.ConnectionStatus.active) {
|
|
330
|
-
const creds = (0, import_platform_sdk_core.decryptCredentials)(connection.credentials, privateKey);
|
|
331
|
-
core.context.setAccessToken(creds.accessToken);
|
|
332
|
-
core.context.setClientToken(creds.clientToken);
|
|
333
|
-
}
|
|
334
|
-
if (connection.status === import_platform_protocol.ConnectionStatus.active || connection.status === import_platform_protocol.ConnectionStatus.termsAcceptanceRequired) {
|
|
335
|
-
opts.onEvent?.({ kind: "complete", payload: connection });
|
|
336
|
-
}
|
|
337
|
-
resolve(
|
|
338
|
-
(0, import_platform_protocol.ok)({
|
|
339
|
-
dispose: () => {
|
|
340
|
-
handle.dispose();
|
|
341
|
-
removeSlot(slotId);
|
|
342
|
-
}
|
|
343
|
-
})
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
} catch (e) {
|
|
349
|
-
return (0, import_platform_protocol.err)({
|
|
350
|
-
kind: "genericError",
|
|
351
|
-
message: e instanceof Error ? e.message : "Auth setup failed"
|
|
352
|
-
});
|
|
1032
|
+
handleRef.current = handle;
|
|
1033
|
+
handle.onEvent((event) => onEventRef.current?.(event));
|
|
1034
|
+
applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
|
|
1035
|
+
}).catch((e) => {
|
|
1036
|
+
if (!disposed) {
|
|
1037
|
+
onEventRef.current?.(
|
|
1038
|
+
spec.errorEvent(e instanceof Error ? e.message : "Frame handshake failed")
|
|
1039
|
+
);
|
|
353
1040
|
}
|
|
1041
|
+
});
|
|
1042
|
+
return () => {
|
|
1043
|
+
disposed = true;
|
|
1044
|
+
handleRef.current = null;
|
|
1045
|
+
session.dispose();
|
|
1046
|
+
setTransport(null);
|
|
1047
|
+
};
|
|
1048
|
+
}, [mountKey, spec, sessionToken, core, frameBaseUrl]);
|
|
1049
|
+
(0, import_react3.useEffect)(() => {
|
|
1050
|
+
const handle = handleRef.current;
|
|
1051
|
+
if (!handle)
|
|
1052
|
+
return;
|
|
1053
|
+
applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
|
|
1054
|
+
}, [liveKey]);
|
|
1055
|
+
if (spec.hidden) {
|
|
1056
|
+
return transport ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MoonPayFrame, { transport, hidden: true }) : null;
|
|
1057
|
+
}
|
|
1058
|
+
const resolvedStyle = { ...defaultStyle, ...style };
|
|
1059
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native3.View, { style: resolvedStyle, children: transport ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MoonPayFrame, { transport }) : null });
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// src/components/add-card.tsx
|
|
1063
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1064
|
+
function MoonPayAddCard({ onEvent, style }) {
|
|
1065
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1066
|
+
MoonPayFrameView,
|
|
1067
|
+
{
|
|
1068
|
+
spec: addCardSpec,
|
|
1069
|
+
props: {},
|
|
1070
|
+
style,
|
|
1071
|
+
defaultStyle: { flex: 1 },
|
|
1072
|
+
onEvent
|
|
354
1073
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
opts.onEvent?.({ kind: "ready" });
|
|
374
|
-
break;
|
|
375
|
-
case "transactionCreated":
|
|
376
|
-
opts.onEvent?.({
|
|
377
|
-
kind: "transactionCreated",
|
|
378
|
-
payload: msg.payload
|
|
379
|
-
});
|
|
380
|
-
break;
|
|
381
|
-
case "complete":
|
|
382
|
-
opts.onEvent?.({
|
|
383
|
-
kind: "complete",
|
|
384
|
-
payload: msg.payload
|
|
385
|
-
});
|
|
386
|
-
break;
|
|
387
|
-
case "error": {
|
|
388
|
-
const payload = msg.payload;
|
|
389
|
-
opts.onEvent?.({
|
|
390
|
-
kind: "error",
|
|
391
|
-
payload: { code: payload.code, message: payload.message }
|
|
392
|
-
});
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
case "close":
|
|
396
|
-
opts.onEvent?.({ kind: "close" });
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
return (0, import_platform_protocol.ok)({
|
|
401
|
-
dispose: () => {
|
|
402
|
-
handle.dispose();
|
|
403
|
-
removeSlot(slotId);
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
} catch (e) {
|
|
407
|
-
return (0, import_platform_protocol.err)({
|
|
408
|
-
kind: "genericError",
|
|
409
|
-
message: e instanceof Error ? e.message : "Widget setup failed"
|
|
410
|
-
});
|
|
411
|
-
}
|
|
1074
|
+
);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// src/components/apple-pay-button.tsx
|
|
1078
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1079
|
+
function MoonPayApplePayButton({
|
|
1080
|
+
quote,
|
|
1081
|
+
onEvent,
|
|
1082
|
+
style
|
|
1083
|
+
}) {
|
|
1084
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1085
|
+
MoonPayFrameView,
|
|
1086
|
+
{
|
|
1087
|
+
spec: applePaySpec,
|
|
1088
|
+
props: { quote },
|
|
1089
|
+
style,
|
|
1090
|
+
defaultStyle: { height: 48 },
|
|
1091
|
+
onEvent
|
|
412
1092
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const setQuote = (signature) => {
|
|
428
|
-
handle.sendMessage({
|
|
429
|
-
version: 2,
|
|
430
|
-
meta: { channelId },
|
|
431
|
-
kind: "setQuote",
|
|
432
|
-
payload: { quote: { signature } }
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
handle.onMessage((msg) => {
|
|
436
|
-
switch (msg.kind) {
|
|
437
|
-
case "ready":
|
|
438
|
-
opts.onEvent?.({ kind: "ready" });
|
|
439
|
-
break;
|
|
440
|
-
case "complete":
|
|
441
|
-
opts.onEvent?.({
|
|
442
|
-
kind: "complete",
|
|
443
|
-
payload: msg.payload
|
|
444
|
-
});
|
|
445
|
-
break;
|
|
446
|
-
case "error": {
|
|
447
|
-
const payload = msg.payload;
|
|
448
|
-
if (payload.code === "quoteExpired") {
|
|
449
|
-
opts.onEvent?.({ kind: "quoteExpired", payload: { setQuote } });
|
|
450
|
-
} else if (payload.code === "applePayUnavailable") {
|
|
451
|
-
opts.onEvent?.({ kind: "unsupported" });
|
|
452
|
-
} else {
|
|
453
|
-
const kind = payload.code === "generic" ? "genericError" : payload.code;
|
|
454
|
-
opts.onEvent?.({
|
|
455
|
-
kind: "error",
|
|
456
|
-
payload: { kind, message: payload.message }
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
break;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
return (0, import_platform_protocol.ok)({
|
|
464
|
-
setQuote,
|
|
465
|
-
dispose: () => {
|
|
466
|
-
handle.dispose();
|
|
467
|
-
removeSlot(slotId);
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
} catch (e) {
|
|
471
|
-
return (0, import_platform_protocol.err)({
|
|
472
|
-
kind: "genericError",
|
|
473
|
-
message: e instanceof Error ? e.message : "Apple Pay setup failed"
|
|
474
|
-
});
|
|
475
|
-
}
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
// src/components/auth.tsx
|
|
1097
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1098
|
+
function MoonPayAuth({ onEvent, style }) {
|
|
1099
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1100
|
+
MoonPayFrameView,
|
|
1101
|
+
{
|
|
1102
|
+
spec: authSpec,
|
|
1103
|
+
props: {},
|
|
1104
|
+
style,
|
|
1105
|
+
defaultStyle: { flex: 1 },
|
|
1106
|
+
onEvent
|
|
476
1107
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
const { handle, slotId } = await promise;
|
|
492
|
-
const setQuote = (signature) => {
|
|
493
|
-
handle.sendMessage({
|
|
494
|
-
version: 2,
|
|
495
|
-
meta: { channelId },
|
|
496
|
-
kind: "setQuote",
|
|
497
|
-
payload: { quote: { signature } }
|
|
498
|
-
});
|
|
499
|
-
};
|
|
500
|
-
handle.onMessage((msg) => {
|
|
501
|
-
switch (msg.kind) {
|
|
502
|
-
case "ready":
|
|
503
|
-
opts.onEvent?.({ kind: "ready" });
|
|
504
|
-
break;
|
|
505
|
-
case "complete":
|
|
506
|
-
opts.onEvent?.({
|
|
507
|
-
kind: "complete",
|
|
508
|
-
payload: msg.payload
|
|
509
|
-
});
|
|
510
|
-
break;
|
|
511
|
-
case "challenge":
|
|
512
|
-
opts.onEvent?.({
|
|
513
|
-
kind: "challenge",
|
|
514
|
-
payload: msg.payload
|
|
515
|
-
});
|
|
516
|
-
break;
|
|
517
|
-
case "error":
|
|
518
|
-
opts.onEvent?.({
|
|
519
|
-
kind: "error",
|
|
520
|
-
payload: msg.payload
|
|
521
|
-
});
|
|
522
|
-
break;
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
return (0, import_platform_protocol.ok)({
|
|
526
|
-
setQuote,
|
|
527
|
-
dispose: () => {
|
|
528
|
-
handle.dispose();
|
|
529
|
-
removeSlot(slotId);
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
} catch (e) {
|
|
533
|
-
return (0, import_platform_protocol.err)({
|
|
534
|
-
kind: "genericError",
|
|
535
|
-
message: e instanceof Error ? e.message : "Buy setup failed"
|
|
536
|
-
});
|
|
537
|
-
}
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// src/components/buy-button.tsx
|
|
1112
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1113
|
+
function MoonPayBuyButton({ quote, onEvent, style }) {
|
|
1114
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1115
|
+
MoonPayFrameView,
|
|
1116
|
+
{
|
|
1117
|
+
spec: buyButtonSpec,
|
|
1118
|
+
props: { quote },
|
|
1119
|
+
style,
|
|
1120
|
+
defaultStyle: { height: 48 },
|
|
1121
|
+
onEvent
|
|
538
1122
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
meta: { channelId },
|
|
557
|
-
kind: "setQuote",
|
|
558
|
-
payload: { quote: { signature } }
|
|
559
|
-
});
|
|
560
|
-
};
|
|
561
|
-
handle.onMessage((msg) => {
|
|
562
|
-
switch (msg.kind) {
|
|
563
|
-
case "complete":
|
|
564
|
-
opts.onEvent?.({
|
|
565
|
-
kind: "complete",
|
|
566
|
-
payload: msg.payload
|
|
567
|
-
});
|
|
568
|
-
break;
|
|
569
|
-
case "challenge":
|
|
570
|
-
opts.onEvent?.({
|
|
571
|
-
kind: "challenge",
|
|
572
|
-
payload: msg.payload
|
|
573
|
-
});
|
|
574
|
-
break;
|
|
575
|
-
case "error":
|
|
576
|
-
opts.onEvent?.({
|
|
577
|
-
kind: "error",
|
|
578
|
-
payload: msg.payload
|
|
579
|
-
});
|
|
580
|
-
break;
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
return (0, import_platform_protocol.ok)({
|
|
584
|
-
setQuote,
|
|
585
|
-
dispose: () => {
|
|
586
|
-
handle.dispose();
|
|
587
|
-
removeSlot(slotId);
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
} catch (e) {
|
|
591
|
-
return (0, import_platform_protocol.err)({
|
|
592
|
-
kind: "genericError",
|
|
593
|
-
message: e instanceof Error ? e.message : "Buy button setup failed"
|
|
594
|
-
});
|
|
595
|
-
}
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// src/components/buy-frame.tsx
|
|
1127
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1128
|
+
function MoonPayBuyFrame({
|
|
1129
|
+
quote,
|
|
1130
|
+
externalTransactionId,
|
|
1131
|
+
onEvent
|
|
1132
|
+
}) {
|
|
1133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1134
|
+
MoonPayFrameView,
|
|
1135
|
+
{
|
|
1136
|
+
spec: buySpec,
|
|
1137
|
+
props: { quote, externalTransactionId },
|
|
1138
|
+
defaultStyle: {},
|
|
1139
|
+
onEvent
|
|
596
1140
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
const { handle, slotId } = await promise;
|
|
612
|
-
const setQuote = (signature) => {
|
|
613
|
-
handle.sendMessage({
|
|
614
|
-
version: 2,
|
|
615
|
-
meta: { channelId },
|
|
616
|
-
kind: "setQuote",
|
|
617
|
-
payload: { quote: { signature } }
|
|
618
|
-
});
|
|
619
|
-
};
|
|
620
|
-
handle.onMessage((msg) => {
|
|
621
|
-
switch (msg.kind) {
|
|
622
|
-
case "ready":
|
|
623
|
-
opts.onEvent?.({ kind: "ready" });
|
|
624
|
-
break;
|
|
625
|
-
case "complete":
|
|
626
|
-
opts.onEvent?.({
|
|
627
|
-
kind: "complete",
|
|
628
|
-
payload: msg.payload
|
|
629
|
-
});
|
|
630
|
-
break;
|
|
631
|
-
case "challenge":
|
|
632
|
-
opts.onEvent?.({
|
|
633
|
-
kind: "challenge",
|
|
634
|
-
payload: msg.payload
|
|
635
|
-
});
|
|
636
|
-
break;
|
|
637
|
-
case "error": {
|
|
638
|
-
const payload = msg.payload;
|
|
639
|
-
if (payload.code === "quoteExpired") {
|
|
640
|
-
opts.onEvent?.({ kind: "quoteExpired", payload: { setQuote } });
|
|
641
|
-
} else if (payload.code === "googlePayUnavailable") {
|
|
642
|
-
opts.onEvent?.({ kind: "unsupported" });
|
|
643
|
-
} else {
|
|
644
|
-
const kind = payload.code === "generic" ? "genericError" : payload.code;
|
|
645
|
-
opts.onEvent?.({
|
|
646
|
-
kind: "error",
|
|
647
|
-
payload: { kind, message: payload.message }
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
return (0, import_platform_protocol.ok)({
|
|
655
|
-
setQuote,
|
|
656
|
-
dispose: () => {
|
|
657
|
-
handle.dispose();
|
|
658
|
-
removeSlot(slotId);
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
} catch (e) {
|
|
662
|
-
return (0, import_platform_protocol.err)({
|
|
663
|
-
kind: "genericError",
|
|
664
|
-
message: e instanceof Error ? e.message : "Google Pay setup failed"
|
|
665
|
-
});
|
|
666
|
-
}
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// src/components/challenge.tsx
|
|
1145
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1146
|
+
function MoonPayChallenge({ url, onEvent, style }) {
|
|
1147
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1148
|
+
MoonPayFrameView,
|
|
1149
|
+
{
|
|
1150
|
+
spec: challengeSpec,
|
|
1151
|
+
props: { url },
|
|
1152
|
+
style,
|
|
1153
|
+
defaultStyle: { flex: 1 },
|
|
1154
|
+
onEvent
|
|
667
1155
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
removeSlot(slotId);
|
|
683
|
-
resolve((0, import_platform_protocol.ok)(void 0));
|
|
684
|
-
}, 5e3);
|
|
685
|
-
handle.onMessage((msg) => {
|
|
686
|
-
if (msg.kind === "complete" || msg.kind === "error") {
|
|
687
|
-
clearTimeout(timeout);
|
|
688
|
-
handle.dispose();
|
|
689
|
-
removeSlot(slotId);
|
|
690
|
-
resolve((0, import_platform_protocol.ok)(void 0));
|
|
691
|
-
}
|
|
692
|
-
});
|
|
693
|
-
});
|
|
694
|
-
} catch {
|
|
695
|
-
return (0, import_platform_protocol.ok)(void 0);
|
|
696
|
-
}
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
// src/components/connect.tsx
|
|
1160
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1161
|
+
function MoonPayConnect({ theme, onEvent, style }) {
|
|
1162
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1163
|
+
MoonPayFrameView,
|
|
1164
|
+
{
|
|
1165
|
+
spec: connectSpec,
|
|
1166
|
+
props: { theme },
|
|
1167
|
+
style,
|
|
1168
|
+
defaultStyle: { flex: 1 },
|
|
1169
|
+
onEvent
|
|
697
1170
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
hidden: false
|
|
715
|
-
});
|
|
716
|
-
const { handle, slotId } = await promise;
|
|
717
|
-
handle.onMessage((msg) => {
|
|
718
|
-
switch (msg.kind) {
|
|
719
|
-
case "ready":
|
|
720
|
-
opts.onEvent?.({ kind: "ready" });
|
|
721
|
-
break;
|
|
722
|
-
case "complete":
|
|
723
|
-
opts.onEvent?.({
|
|
724
|
-
kind: "complete",
|
|
725
|
-
payload: msg.payload
|
|
726
|
-
});
|
|
727
|
-
break;
|
|
728
|
-
case "cancelled":
|
|
729
|
-
opts.onEvent?.({
|
|
730
|
-
kind: "cancelled",
|
|
731
|
-
payload: msg.payload
|
|
732
|
-
});
|
|
733
|
-
break;
|
|
734
|
-
case "error":
|
|
735
|
-
opts.onEvent?.({
|
|
736
|
-
kind: "error",
|
|
737
|
-
payload: msg.payload
|
|
738
|
-
});
|
|
739
|
-
break;
|
|
740
|
-
}
|
|
741
|
-
});
|
|
742
|
-
return (0, import_platform_protocol.ok)({
|
|
743
|
-
dispose: () => {
|
|
744
|
-
handle.dispose();
|
|
745
|
-
removeSlot(slotId);
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
} catch (e) {
|
|
749
|
-
return (0, import_platform_protocol.err)({
|
|
750
|
-
kind: "genericError",
|
|
751
|
-
message: e instanceof Error ? e.message : "Challenge setup failed"
|
|
752
|
-
});
|
|
753
|
-
}
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
// src/components/connection-check.tsx
|
|
1175
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1176
|
+
function MoonPayConnectionCheck({
|
|
1177
|
+
skipKyc,
|
|
1178
|
+
onEvent
|
|
1179
|
+
}) {
|
|
1180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1181
|
+
MoonPayFrameView,
|
|
1182
|
+
{
|
|
1183
|
+
spec: connectionCheckSpec,
|
|
1184
|
+
props: { skipKyc },
|
|
1185
|
+
defaultStyle: {},
|
|
1186
|
+
onEvent
|
|
754
1187
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
handle.dispose();
|
|
781
|
-
removeSlot(slotId);
|
|
782
|
-
}
|
|
783
|
-
});
|
|
784
|
-
} catch (e) {
|
|
785
|
-
return (0, import_platform_protocol.err)({
|
|
786
|
-
kind: "genericError",
|
|
787
|
-
message: e instanceof Error ? e.message : "Add card setup failed"
|
|
788
|
-
});
|
|
789
|
-
}
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// src/components/connection-reset.tsx
|
|
1192
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1193
|
+
function MoonPayConnectionReset({ onEvent }) {
|
|
1194
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
// src/components/google-pay-button.tsx
|
|
1198
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1199
|
+
function MoonPayGooglePayButton({
|
|
1200
|
+
quote,
|
|
1201
|
+
externalTransactionId,
|
|
1202
|
+
onEvent,
|
|
1203
|
+
style
|
|
1204
|
+
}) {
|
|
1205
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1206
|
+
MoonPayFrameView,
|
|
1207
|
+
{
|
|
1208
|
+
spec: googlePaySpec,
|
|
1209
|
+
props: { quote, externalTransactionId },
|
|
1210
|
+
style,
|
|
1211
|
+
defaultStyle: { height: 48 },
|
|
1212
|
+
onEvent
|
|
790
1213
|
}
|
|
791
|
-
|
|
792
|
-
getConnection,
|
|
793
|
-
connect,
|
|
794
|
-
setupAuth,
|
|
795
|
-
getPaymentMethods: () => core.getPaymentMethods(),
|
|
796
|
-
getQuote: (params) => core.getQuote(params),
|
|
797
|
-
listTransactions: (params) => core.listTransactions(params),
|
|
798
|
-
getTransaction: (id) => core.getTransaction(id),
|
|
799
|
-
setupWidget,
|
|
800
|
-
setupApplePay,
|
|
801
|
-
setupBuy,
|
|
802
|
-
setupBuyButton,
|
|
803
|
-
setupGooglePay,
|
|
804
|
-
deletePaymentMethod: (id) => core.deletePaymentMethod(id),
|
|
805
|
-
resetConnection,
|
|
806
|
-
setupChallenge,
|
|
807
|
-
setupAddCard,
|
|
808
|
-
createIdentity: (body) => core.createIdentity(body),
|
|
809
|
-
getIdentity: (id) => core.getIdentity(id),
|
|
810
|
-
updateIdentity: (id, body) => core.updateIdentity(id, body),
|
|
811
|
-
verifyIdentity: (id) => core.verifyIdentity(id),
|
|
812
|
-
getIdentityUploadUrl: (id, body) => core.getIdentityUploadUrl(id, body),
|
|
813
|
-
submitIdentityFiles: (id, body) => core.submitIdentityFiles(id, body)
|
|
814
|
-
};
|
|
815
|
-
}, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);
|
|
816
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(MoonPayContext.Provider, { value: { client }, children: [
|
|
817
|
-
children,
|
|
818
|
-
frameSlots.map((slot) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonPayFrame, { transport: slot.transport, hidden: slot.hidden }, slot.id))
|
|
819
|
-
] });
|
|
1214
|
+
);
|
|
820
1215
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
1216
|
+
|
|
1217
|
+
// src/components/widget.tsx
|
|
1218
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1219
|
+
function MoonPayWidget({ quote, onEvent, style }) {
|
|
1220
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1221
|
+
MoonPayFrameView,
|
|
1222
|
+
{
|
|
1223
|
+
spec: widgetSpec,
|
|
1224
|
+
props: { quote },
|
|
1225
|
+
style,
|
|
1226
|
+
defaultStyle: { flex: 1 },
|
|
1227
|
+
onEvent
|
|
1228
|
+
}
|
|
1229
|
+
);
|
|
827
1230
|
}
|
|
828
1231
|
// Annotate the CommonJS export names for ESM import in node:
|
|
829
1232
|
0 && (module.exports = {
|
|
1233
|
+
ConnectionStatus,
|
|
1234
|
+
MoonPayAddCard,
|
|
1235
|
+
MoonPayApplePayButton,
|
|
1236
|
+
MoonPayAuth,
|
|
1237
|
+
MoonPayBuyButton,
|
|
1238
|
+
MoonPayBuyFrame,
|
|
1239
|
+
MoonPayChallenge,
|
|
1240
|
+
MoonPayConnect,
|
|
1241
|
+
MoonPayConnectionCheck,
|
|
1242
|
+
MoonPayConnectionReset,
|
|
830
1243
|
MoonPayFrame,
|
|
1244
|
+
MoonPayGooglePayButton,
|
|
831
1245
|
MoonPayProvider,
|
|
1246
|
+
MoonPayWidget,
|
|
832
1247
|
WebViewTransport,
|
|
833
1248
|
useMoonPay
|
|
834
1249
|
});
|