@moonpay/platform-sdk-react-native 1.16.0 → 1.18.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
@@ -462,7 +462,13 @@ import { useEffect, useRef } from "react";
462
462
  import { View } from "react-native";
463
463
  import WebView from "react-native-webview";
464
464
  import { jsx } from "react/jsx-runtime";
465
- 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
+ }) {
466
472
  const webViewRef = useRef(null);
467
473
  useEffect(() => {
468
474
  transport.attachWebView(webViewRef);
@@ -478,13 +484,15 @@ function MoonPayFrame({ transport, hidden, style }) {
478
484
  return /* @__PURE__ */ jsx(View, { style: containerStyle, children: /* @__PURE__ */ jsx(
479
485
  WebView,
480
486
  {
481
- ref: webViewRef,
482
- source: { uri: url },
483
- onMessage: handleMessage,
487
+ originWhitelist: DEFAULT_ORIGIN_WHITELIST,
484
488
  allowsInlineMediaPlayback: true,
485
489
  javaScriptEnabled: true,
486
490
  domStorageEnabled: true,
487
- style: { flex: 1 }
491
+ style: { flex: 1 },
492
+ ...webViewProps,
493
+ ref: webViewRef,
494
+ source: { uri: url },
495
+ onMessage: handleMessage
488
496
  }
489
497
  ) });
490
498
  }
@@ -494,7 +502,8 @@ import {
494
502
  applyThemeParam,
495
503
  buildFrameUrl,
496
504
  createFrameOrchestrator,
497
- generateKeyPair
505
+ generateKeyPair,
506
+ isSecureRandomAvailable
498
507
  } from "@moonpay/platform-sdk-core";
499
508
 
500
509
  // src/webview-transport.ts
@@ -557,6 +566,7 @@ var WebViewTransport = class {
557
566
  };
558
567
 
559
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.";
560
570
  var FrameSessionDisposedError = class extends Error {
561
571
  constructor() {
562
572
  super("Frame session disposed");
@@ -566,7 +576,11 @@ var FrameSessionDisposedError = class extends Error {
566
576
  function createFrameSession(spec, ctx, props, overrides = {}) {
567
577
  const generated = `${spec.channelPrefix}-${Date.now()}`;
568
578
  const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
569
- 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
+ }
570
584
  const builtUrl = spec.buildUrl ? spec.buildUrl(ctx, props, channelId, keyPair?.publicKey) : buildFrameUrl(
571
585
  spec.path,
572
586
  { ...spec.buildParams?.(ctx, props, keyPair?.publicKey), channelId },
@@ -951,6 +965,7 @@ function createRNClient(deps) {
951
965
  getConnection: (options) => getConnection(deps, options ?? {}),
952
966
  connect: (opts) => connect(deps, opts),
953
967
  setupAuth: (opts) => setupAuth(deps, opts),
968
+ getCredentials: () => core.getCredentials(),
954
969
  getPaymentMethods: () => core.getPaymentMethods(),
955
970
  getQuote: (params) => core.getQuote(params),
956
971
  getAssets: (params) => core.getAssets(params),
@@ -1316,7 +1331,8 @@ function MoonPayFrameView({
1316
1331
  props,
1317
1332
  style,
1318
1333
  defaultStyle,
1319
- onEvent
1334
+ onEvent,
1335
+ webViewProps
1320
1336
  }) {
1321
1337
  const { sessionToken, core, frameBaseUrl, theme } = useMoonPayContext();
1322
1338
  const [transport, setTransport] = useState3(null);
@@ -1384,15 +1400,15 @@ function MoonPayFrameView({
1384
1400
  applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
1385
1401
  }, [liveKey]);
1386
1402
  if (spec.hidden) {
1387
- return transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport, hidden: true }) : null;
1403
+ return transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport, hidden: true, webViewProps }) : null;
1388
1404
  }
1389
1405
  const resolvedStyle = { ...defaultStyle, ...style };
1390
- return /* @__PURE__ */ jsx4(View3, { style: resolvedStyle, children: transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport }) : null });
1406
+ return /* @__PURE__ */ jsx4(View3, { style: resolvedStyle, children: transport ? /* @__PURE__ */ jsx4(MoonPayFrame, { transport, webViewProps }) : null });
1391
1407
  }
1392
1408
 
1393
1409
  // src/components/add-card.tsx
1394
1410
  import { jsx as jsx5 } from "react/jsx-runtime";
1395
- function MoonPayAddCard({ onEvent, style }) {
1411
+ function MoonPayAddCard({ onEvent, style, webViewProps }) {
1396
1412
  return /* @__PURE__ */ jsx5(
1397
1413
  MoonPayFrameView,
1398
1414
  {
@@ -1400,7 +1416,8 @@ function MoonPayAddCard({ onEvent, style }) {
1400
1416
  props: {},
1401
1417
  style,
1402
1418
  defaultStyle: { flex: 1 },
1403
- onEvent
1419
+ onEvent,
1420
+ webViewProps
1404
1421
  }
1405
1422
  );
1406
1423
  }
@@ -1411,7 +1428,8 @@ function MoonPayApplePayButton({
1411
1428
  quote,
1412
1429
  externalTransactionId,
1413
1430
  onEvent,
1414
- style
1431
+ style,
1432
+ webViewProps
1415
1433
  }) {
1416
1434
  return /* @__PURE__ */ jsx6(
1417
1435
  MoonPayFrameView,
@@ -1420,14 +1438,15 @@ function MoonPayApplePayButton({
1420
1438
  props: { quote, externalTransactionId },
1421
1439
  style,
1422
1440
  defaultStyle: { height: 48 },
1423
- onEvent
1441
+ onEvent,
1442
+ webViewProps
1424
1443
  }
1425
1444
  );
1426
1445
  }
1427
1446
 
1428
1447
  // src/components/auth.tsx
1429
1448
  import { jsx as jsx7 } from "react/jsx-runtime";
1430
- function MoonPayAuth({ onEvent, style }) {
1449
+ function MoonPayAuth({ onEvent, style, webViewProps }) {
1431
1450
  return /* @__PURE__ */ jsx7(
1432
1451
  MoonPayFrameView,
1433
1452
  {
@@ -1435,7 +1454,8 @@ function MoonPayAuth({ onEvent, style }) {
1435
1454
  props: {},
1436
1455
  style,
1437
1456
  defaultStyle: { flex: 1 },
1438
- onEvent
1457
+ onEvent,
1458
+ webViewProps
1439
1459
  }
1440
1460
  );
1441
1461
  }
@@ -1446,7 +1466,8 @@ function MoonPayBuyButton({
1446
1466
  quote,
1447
1467
  externalTransactionId,
1448
1468
  onEvent,
1449
- style
1469
+ style,
1470
+ webViewProps
1450
1471
  }) {
1451
1472
  return /* @__PURE__ */ jsx8(
1452
1473
  MoonPayFrameView,
@@ -1455,7 +1476,8 @@ function MoonPayBuyButton({
1455
1476
  props: { quote, externalTransactionId },
1456
1477
  style,
1457
1478
  defaultStyle: { height: 48 },
1458
- onEvent
1479
+ onEvent,
1480
+ webViewProps
1459
1481
  }
1460
1482
  );
1461
1483
  }
@@ -1465,7 +1487,8 @@ import { jsx as jsx9 } from "react/jsx-runtime";
1465
1487
  function MoonPayBuyFrame({
1466
1488
  quote,
1467
1489
  externalTransactionId,
1468
- onEvent
1490
+ onEvent,
1491
+ webViewProps
1469
1492
  }) {
1470
1493
  return /* @__PURE__ */ jsx9(
1471
1494
  MoonPayFrameView,
@@ -1473,14 +1496,20 @@ function MoonPayBuyFrame({
1473
1496
  spec: buySpec,
1474
1497
  props: { quote, externalTransactionId },
1475
1498
  defaultStyle: {},
1476
- onEvent
1499
+ onEvent,
1500
+ webViewProps
1477
1501
  }
1478
1502
  );
1479
1503
  }
1480
1504
 
1481
1505
  // src/components/challenge.tsx
1482
1506
  import { jsx as jsx10 } from "react/jsx-runtime";
1483
- function MoonPayChallenge({ url, onEvent, style }) {
1507
+ function MoonPayChallenge({
1508
+ url,
1509
+ onEvent,
1510
+ style,
1511
+ webViewProps
1512
+ }) {
1484
1513
  return /* @__PURE__ */ jsx10(
1485
1514
  MoonPayFrameView,
1486
1515
  {
@@ -1488,14 +1517,20 @@ function MoonPayChallenge({ url, onEvent, style }) {
1488
1517
  props: { url },
1489
1518
  style,
1490
1519
  defaultStyle: { flex: 1 },
1491
- onEvent
1520
+ onEvent,
1521
+ webViewProps
1492
1522
  }
1493
1523
  );
1494
1524
  }
1495
1525
 
1496
1526
  // src/components/connect.tsx
1497
1527
  import { jsx as jsx11 } from "react/jsx-runtime";
1498
- function MoonPayConnect({ theme, onEvent, style }) {
1528
+ function MoonPayConnect({
1529
+ theme,
1530
+ onEvent,
1531
+ style,
1532
+ webViewProps
1533
+ }) {
1499
1534
  return /* @__PURE__ */ jsx11(
1500
1535
  MoonPayFrameView,
1501
1536
  {
@@ -1503,7 +1538,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
1503
1538
  props: { theme },
1504
1539
  style,
1505
1540
  defaultStyle: { flex: 1 },
1506
- onEvent
1541
+ onEvent,
1542
+ webViewProps
1507
1543
  }
1508
1544
  );
1509
1545
  }
@@ -1512,7 +1548,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
1512
1548
  import { jsx as jsx12 } from "react/jsx-runtime";
1513
1549
  function MoonPayConnectionCheck({
1514
1550
  skipKyc,
1515
- onEvent
1551
+ onEvent,
1552
+ webViewProps
1516
1553
  }) {
1517
1554
  return /* @__PURE__ */ jsx12(
1518
1555
  MoonPayFrameView,
@@ -1520,20 +1557,37 @@ function MoonPayConnectionCheck({
1520
1557
  spec: connectionCheckSpec,
1521
1558
  props: { skipKyc },
1522
1559
  defaultStyle: {},
1523
- onEvent
1560
+ onEvent,
1561
+ webViewProps
1524
1562
  }
1525
1563
  );
1526
1564
  }
1527
1565
 
1528
1566
  // src/components/connection-reset.tsx
1529
1567
  import { jsx as jsx13 } from "react/jsx-runtime";
1530
- function MoonPayConnectionReset({ onEvent }) {
1531
- return /* @__PURE__ */ jsx13(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
1568
+ function MoonPayConnectionReset({
1569
+ onEvent,
1570
+ webViewProps
1571
+ }) {
1572
+ return /* @__PURE__ */ jsx13(
1573
+ MoonPayFrameView,
1574
+ {
1575
+ spec: connectionResetSpec,
1576
+ props: {},
1577
+ defaultStyle: {},
1578
+ onEvent,
1579
+ webViewProps
1580
+ }
1581
+ );
1532
1582
  }
1533
1583
 
1534
1584
  // src/components/customer-export.tsx
1535
1585
  import { jsx as jsx14 } from "react/jsx-runtime";
1536
- function MoonPayCustomerExport({ onEvent, style }) {
1586
+ function MoonPayCustomerExport({
1587
+ onEvent,
1588
+ style,
1589
+ webViewProps
1590
+ }) {
1537
1591
  return /* @__PURE__ */ jsx14(
1538
1592
  MoonPayFrameView,
1539
1593
  {
@@ -1541,7 +1595,8 @@ function MoonPayCustomerExport({ onEvent, style }) {
1541
1595
  props: {},
1542
1596
  style,
1543
1597
  defaultStyle: { flex: 1 },
1544
- onEvent
1598
+ onEvent,
1599
+ webViewProps
1545
1600
  }
1546
1601
  );
1547
1602
  }
@@ -1552,7 +1607,8 @@ function MoonPayGooglePayButton({
1552
1607
  quote,
1553
1608
  externalTransactionId,
1554
1609
  onEvent,
1555
- style
1610
+ style,
1611
+ webViewProps
1556
1612
  }) {
1557
1613
  return /* @__PURE__ */ jsx15(
1558
1614
  MoonPayFrameView,
@@ -1561,7 +1617,8 @@ function MoonPayGooglePayButton({
1561
1617
  props: { quote, externalTransactionId },
1562
1618
  style,
1563
1619
  defaultStyle: { height: 48 },
1564
- onEvent
1620
+ onEvent,
1621
+ webViewProps
1565
1622
  }
1566
1623
  );
1567
1624
  }
@@ -1572,7 +1629,8 @@ function MoonPayWidget({
1572
1629
  quote,
1573
1630
  externalTransactionId,
1574
1631
  onEvent,
1575
- style
1632
+ style,
1633
+ webViewProps
1576
1634
  }) {
1577
1635
  return /* @__PURE__ */ jsx16(
1578
1636
  MoonPayFrameView,
@@ -1581,7 +1639,8 @@ function MoonPayWidget({
1581
1639
  props: { quote, externalTransactionId },
1582
1640
  style,
1583
1641
  defaultStyle: { flex: 1 },
1584
- onEvent
1642
+ onEvent,
1643
+ webViewProps
1585
1644
  }
1586
1645
  );
1587
1646
  }