@moonpay/platform-sdk-react-native 1.15.2 → 1.17.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.js CHANGED
@@ -51,6 +51,11 @@ var applePaySpec = {
51
51
  kind: "challenge",
52
52
  payload: msg.payload
53
53
  };
54
+ case "cancelled":
55
+ return {
56
+ kind: "cancelled",
57
+ payload: msg.payload
58
+ };
54
59
  case "error": {
55
60
  const payload = msg.payload;
56
61
  if (payload.code === "quoteExpired") {
@@ -95,6 +100,11 @@ var googlePaySpec = {
95
100
  kind: "challenge",
96
101
  payload: msg.payload
97
102
  };
103
+ case "cancelled":
104
+ return {
105
+ kind: "cancelled",
106
+ payload: msg.payload
107
+ };
98
108
  case "error": {
99
109
  const payload = msg.payload;
100
110
  if (payload.code === "quoteExpired") {
@@ -452,7 +462,13 @@ import { useEffect, useRef } from "react";
452
462
  import { View } from "react-native";
453
463
  import WebView from "react-native-webview";
454
464
  import { jsx } from "react/jsx-runtime";
455
- function MoonPayFrame({ transport, hidden, style }) {
465
+ var DEFAULT_ORIGIN_WHITELIST = ["https://*", "http://*", "about:srcdoc"];
466
+ function MoonPayFrame({
467
+ transport,
468
+ hidden,
469
+ style,
470
+ webViewProps
471
+ }) {
456
472
  const webViewRef = useRef(null);
457
473
  useEffect(() => {
458
474
  transport.attachWebView(webViewRef);
@@ -468,13 +484,15 @@ function MoonPayFrame({ transport, hidden, style }) {
468
484
  return /* @__PURE__ */ jsx(View, { style: containerStyle, children: /* @__PURE__ */ jsx(
469
485
  WebView,
470
486
  {
471
- ref: webViewRef,
472
- source: { uri: url },
473
- onMessage: handleMessage,
487
+ originWhitelist: DEFAULT_ORIGIN_WHITELIST,
474
488
  allowsInlineMediaPlayback: true,
475
489
  javaScriptEnabled: true,
476
490
  domStorageEnabled: true,
477
- style: { flex: 1 }
491
+ style: { flex: 1 },
492
+ ...webViewProps,
493
+ ref: webViewRef,
494
+ source: { uri: url },
495
+ onMessage: handleMessage
478
496
  }
479
497
  ) });
480
498
  }
@@ -484,7 +502,8 @@ import {
484
502
  applyThemeParam,
485
503
  buildFrameUrl,
486
504
  createFrameOrchestrator,
487
- generateKeyPair
505
+ generateKeyPair,
506
+ isSecureRandomAvailable
488
507
  } from "@moonpay/platform-sdk-core";
489
508
 
490
509
  // src/webview-transport.ts
@@ -547,6 +566,7 @@ var WebViewTransport = class {
547
566
  };
548
567
 
549
568
  // src/frame-engine.ts
569
+ var CRYPTO_UNAVAILABLE_MESSAGE = "MoonPay SDK: crypto.getRandomValues is unavailable. React Native (Hermes) has no Web Crypto. Install and register a Web Crypto getRandomValues polyfill on the global before using the SDK \u2014 Expo: expo-crypto; bare React Native: react-native-get-random-values. See https://dev.moonpay.com/platform/sdk-reference/react-native/overview.";
550
570
  var FrameSessionDisposedError = class extends Error {
551
571
  constructor() {
552
572
  super("Frame session disposed");
@@ -556,7 +576,11 @@ var FrameSessionDisposedError = class extends Error {
556
576
  function createFrameSession(spec, ctx, props, overrides = {}) {
557
577
  const generated = `${spec.channelPrefix}-${Date.now()}`;
558
578
  const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
559
- const keyPair = spec.needsKeyPair ? generateKeyPair() : void 0;
579
+ let keyPair;
580
+ if (spec.needsKeyPair) {
581
+ if (!isSecureRandomAvailable()) throw new Error(CRYPTO_UNAVAILABLE_MESSAGE);
582
+ keyPair = generateKeyPair();
583
+ }
560
584
  const builtUrl = spec.buildUrl ? spec.buildUrl(ctx, props, channelId, keyPair?.publicKey) : buildFrameUrl(
561
585
  spec.path,
562
586
  { ...spec.buildParams?.(ctx, props, keyPair?.publicKey), channelId },
@@ -1306,7 +1330,8 @@ function MoonPayFrameView({
1306
1330
  props,
1307
1331
  style,
1308
1332
  defaultStyle,
1309
- onEvent
1333
+ onEvent,
1334
+ webViewProps
1310
1335
  }) {
1311
1336
  const { sessionToken, core, frameBaseUrl, theme } = useMoonPayContext();
1312
1337
  const [transport, setTransport] = useState3(null);
@@ -1374,15 +1399,15 @@ function MoonPayFrameView({
1374
1399
  applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
1375
1400
  }, [liveKey]);
1376
1401
  if (spec.hidden) {
1377
- return transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport, hidden: true }) : null;
1402
+ return transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport, hidden: true, webViewProps }) : null;
1378
1403
  }
1379
1404
  const resolvedStyle = { ...defaultStyle, ...style };
1380
- return /* @__PURE__ */ jsx4(View3, { style: resolvedStyle, children: transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport }) : null });
1405
+ return /* @__PURE__ */ jsx4(View3, { style: resolvedStyle, children: transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport, webViewProps }) : null });
1381
1406
  }
1382
1407
 
1383
1408
  // src/components/add-card.tsx
1384
1409
  import { jsx as jsx5 } from "react/jsx-runtime";
1385
- function MoonPayAddCard({ onEvent, style }) {
1410
+ function MoonPayAddCard({ onEvent, style, webViewProps }) {
1386
1411
  return /* @__PURE__ */ jsx5(
1387
1412
  MoonPayFrameView,
1388
1413
  {
@@ -1390,7 +1415,8 @@ function MoonPayAddCard({ onEvent, style }) {
1390
1415
  props: {},
1391
1416
  style,
1392
1417
  defaultStyle: { flex: 1 },
1393
- onEvent
1418
+ onEvent,
1419
+ webViewProps
1394
1420
  }
1395
1421
  );
1396
1422
  }
@@ -1401,7 +1427,8 @@ function MoonPayApplePayButton({
1401
1427
  quote,
1402
1428
  externalTransactionId,
1403
1429
  onEvent,
1404
- style
1430
+ style,
1431
+ webViewProps
1405
1432
  }) {
1406
1433
  return /* @__PURE__ */ jsx6(
1407
1434
  MoonPayFrameView,
@@ -1410,14 +1437,15 @@ function MoonPayApplePayButton({
1410
1437
  props: { quote, externalTransactionId },
1411
1438
  style,
1412
1439
  defaultStyle: { height: 48 },
1413
- onEvent
1440
+ onEvent,
1441
+ webViewProps
1414
1442
  }
1415
1443
  );
1416
1444
  }
1417
1445
 
1418
1446
  // src/components/auth.tsx
1419
1447
  import { jsx as jsx7 } from "react/jsx-runtime";
1420
- function MoonPayAuth({ onEvent, style }) {
1448
+ function MoonPayAuth({ onEvent, style, webViewProps }) {
1421
1449
  return /* @__PURE__ */ jsx7(
1422
1450
  MoonPayFrameView,
1423
1451
  {
@@ -1425,7 +1453,8 @@ function MoonPayAuth({ onEvent, style }) {
1425
1453
  props: {},
1426
1454
  style,
1427
1455
  defaultStyle: { flex: 1 },
1428
- onEvent
1456
+ onEvent,
1457
+ webViewProps
1429
1458
  }
1430
1459
  );
1431
1460
  }
@@ -1436,7 +1465,8 @@ function MoonPayBuyButton({
1436
1465
  quote,
1437
1466
  externalTransactionId,
1438
1467
  onEvent,
1439
- style
1468
+ style,
1469
+ webViewProps
1440
1470
  }) {
1441
1471
  return /* @__PURE__ */ jsx8(
1442
1472
  MoonPayFrameView,
@@ -1445,7 +1475,8 @@ function MoonPayBuyButton({
1445
1475
  props: { quote, externalTransactionId },
1446
1476
  style,
1447
1477
  defaultStyle: { height: 48 },
1448
- onEvent
1478
+ onEvent,
1479
+ webViewProps
1449
1480
  }
1450
1481
  );
1451
1482
  }
@@ -1455,7 +1486,8 @@ import { jsx as jsx9 } from "react/jsx-runtime";
1455
1486
  function MoonPayBuyFrame({
1456
1487
  quote,
1457
1488
  externalTransactionId,
1458
- onEvent
1489
+ onEvent,
1490
+ webViewProps
1459
1491
  }) {
1460
1492
  return /* @__PURE__ */ jsx9(
1461
1493
  MoonPayFrameView,
@@ -1463,14 +1495,20 @@ function MoonPayBuyFrame({
1463
1495
  spec: buySpec,
1464
1496
  props: { quote, externalTransactionId },
1465
1497
  defaultStyle: {},
1466
- onEvent
1498
+ onEvent,
1499
+ webViewProps
1467
1500
  }
1468
1501
  );
1469
1502
  }
1470
1503
 
1471
1504
  // src/components/challenge.tsx
1472
1505
  import { jsx as jsx10 } from "react/jsx-runtime";
1473
- function MoonPayChallenge({ url, onEvent, style }) {
1506
+ function MoonPayChallenge({
1507
+ url,
1508
+ onEvent,
1509
+ style,
1510
+ webViewProps
1511
+ }) {
1474
1512
  return /* @__PURE__ */ jsx10(
1475
1513
  MoonPayFrameView,
1476
1514
  {
@@ -1478,14 +1516,20 @@ function MoonPayChallenge({ url, onEvent, style }) {
1478
1516
  props: { url },
1479
1517
  style,
1480
1518
  defaultStyle: { flex: 1 },
1481
- onEvent
1519
+ onEvent,
1520
+ webViewProps
1482
1521
  }
1483
1522
  );
1484
1523
  }
1485
1524
 
1486
1525
  // src/components/connect.tsx
1487
1526
  import { jsx as jsx11 } from "react/jsx-runtime";
1488
- function MoonPayConnect({ theme, onEvent, style }) {
1527
+ function MoonPayConnect({
1528
+ theme,
1529
+ onEvent,
1530
+ style,
1531
+ webViewProps
1532
+ }) {
1489
1533
  return /* @__PURE__ */ jsx11(
1490
1534
  MoonPayFrameView,
1491
1535
  {
@@ -1493,7 +1537,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
1493
1537
  props: { theme },
1494
1538
  style,
1495
1539
  defaultStyle: { flex: 1 },
1496
- onEvent
1540
+ onEvent,
1541
+ webViewProps
1497
1542
  }
1498
1543
  );
1499
1544
  }
@@ -1502,7 +1547,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
1502
1547
  import { jsx as jsx12 } from "react/jsx-runtime";
1503
1548
  function MoonPayConnectionCheck({
1504
1549
  skipKyc,
1505
- onEvent
1550
+ onEvent,
1551
+ webViewProps
1506
1552
  }) {
1507
1553
  return /* @__PURE__ */ jsx12(
1508
1554
  MoonPayFrameView,
@@ -1510,20 +1556,37 @@ function MoonPayConnectionCheck({
1510
1556
  spec: connectionCheckSpec,
1511
1557
  props: { skipKyc },
1512
1558
  defaultStyle: {},
1513
- onEvent
1559
+ onEvent,
1560
+ webViewProps
1514
1561
  }
1515
1562
  );
1516
1563
  }
1517
1564
 
1518
1565
  // src/components/connection-reset.tsx
1519
1566
  import { jsx as jsx13 } from "react/jsx-runtime";
1520
- function MoonPayConnectionReset({ onEvent }) {
1521
- return /* @__PURE__ */ jsx13(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
1567
+ function MoonPayConnectionReset({
1568
+ onEvent,
1569
+ webViewProps
1570
+ }) {
1571
+ return /* @__PURE__ */ jsx13(
1572
+ MoonPayFrameView,
1573
+ {
1574
+ spec: connectionResetSpec,
1575
+ props: {},
1576
+ defaultStyle: {},
1577
+ onEvent,
1578
+ webViewProps
1579
+ }
1580
+ );
1522
1581
  }
1523
1582
 
1524
1583
  // src/components/customer-export.tsx
1525
1584
  import { jsx as jsx14 } from "react/jsx-runtime";
1526
- function MoonPayCustomerExport({ onEvent, style }) {
1585
+ function MoonPayCustomerExport({
1586
+ onEvent,
1587
+ style,
1588
+ webViewProps
1589
+ }) {
1527
1590
  return /* @__PURE__ */ jsx14(
1528
1591
  MoonPayFrameView,
1529
1592
  {
@@ -1531,7 +1594,8 @@ function MoonPayCustomerExport({ onEvent, style }) {
1531
1594
  props: {},
1532
1595
  style,
1533
1596
  defaultStyle: { flex: 1 },
1534
- onEvent
1597
+ onEvent,
1598
+ webViewProps
1535
1599
  }
1536
1600
  );
1537
1601
  }
@@ -1542,7 +1606,8 @@ function MoonPayGooglePayButton({
1542
1606
  quote,
1543
1607
  externalTransactionId,
1544
1608
  onEvent,
1545
- style
1609
+ style,
1610
+ webViewProps
1546
1611
  }) {
1547
1612
  return /* @__PURE__ */ jsx15(
1548
1613
  MoonPayFrameView,
@@ -1551,7 +1616,8 @@ function MoonPayGooglePayButton({
1551
1616
  props: { quote, externalTransactionId },
1552
1617
  style,
1553
1618
  defaultStyle: { height: 48 },
1554
- onEvent
1619
+ onEvent,
1620
+ webViewProps
1555
1621
  }
1556
1622
  );
1557
1623
  }
@@ -1562,7 +1628,8 @@ function MoonPayWidget({
1562
1628
  quote,
1563
1629
  externalTransactionId,
1564
1630
  onEvent,
1565
- style
1631
+ style,
1632
+ webViewProps
1566
1633
  }) {
1567
1634
  return /* @__PURE__ */ jsx16(
1568
1635
  MoonPayFrameView,
@@ -1571,7 +1638,8 @@ function MoonPayWidget({
1571
1638
  props: { quote, externalTransactionId },
1572
1639
  style,
1573
1640
  defaultStyle: { flex: 1 },
1574
- onEvent
1641
+ onEvent,
1642
+ webViewProps
1575
1643
  }
1576
1644
  );
1577
1645
  }