@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/README.md +24 -1
- package/dist/index.cjs +91 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -16
- package/dist/index.d.ts +58 -16
- package/dist/index.js +93 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,7 +23,30 @@ Peer dependencies:
|
|
|
23
23
|
- `react-native` >= 0.73 (Hermes supported)
|
|
24
24
|
- `react-native-webview` >= 13
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
### Crypto polyfill (required on React Native)
|
|
27
|
+
|
|
28
|
+
The SDK's crypto layer is pure JavaScript (`@noble` libraries), but key exchange needs a cryptographically-secure `crypto.getRandomValues`. React Native (Hermes) has no Web Crypto API, so you must install a polyfill and register it **before** the SDK runs — at your app entry, or a `polyfills.ts` you import first. Without it, the first `getConnection()` fails with a clear error telling you to add one.
|
|
29
|
+
|
|
30
|
+
**Expo** — `expo-crypto` provides a Web-Crypto-compatible `getRandomValues` but does not auto-install it on the global (works in Expo Go):
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// polyfills.ts — imported first, before the MoonPay SDK
|
|
34
|
+
import * as Crypto from 'expo-crypto';
|
|
35
|
+
|
|
36
|
+
if (typeof globalThis.crypto?.getRandomValues !== 'function') {
|
|
37
|
+
globalThis.crypto = {
|
|
38
|
+
...globalThis.crypto,
|
|
39
|
+
getRandomValues: (array) => Crypto.getRandomValues(array),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Bare React Native** — `react-native-get-random-values` installs the global on import:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// index.js — first import, before the app
|
|
48
|
+
import 'react-native-get-random-values';
|
|
49
|
+
```
|
|
27
50
|
|
|
28
51
|
## Quick start
|
|
29
52
|
|
package/dist/index.cjs
CHANGED
|
@@ -502,7 +502,13 @@ var import_react = require("react");
|
|
|
502
502
|
var import_react_native = require("react-native");
|
|
503
503
|
var import_react_native_webview = __toESM(require("react-native-webview"), 1);
|
|
504
504
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
505
|
-
|
|
505
|
+
var DEFAULT_ORIGIN_WHITELIST = ["https://*", "http://*", "about:srcdoc"];
|
|
506
|
+
function MoonPayFrame({
|
|
507
|
+
transport,
|
|
508
|
+
hidden,
|
|
509
|
+
style,
|
|
510
|
+
webViewProps
|
|
511
|
+
}) {
|
|
506
512
|
const webViewRef = (0, import_react.useRef)(null);
|
|
507
513
|
(0, import_react.useEffect)(() => {
|
|
508
514
|
transport.attachWebView(webViewRef);
|
|
@@ -518,13 +524,15 @@ function MoonPayFrame({ transport, hidden, style }) {
|
|
|
518
524
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: containerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
519
525
|
import_react_native_webview.default,
|
|
520
526
|
{
|
|
521
|
-
|
|
522
|
-
source: { uri: url },
|
|
523
|
-
onMessage: handleMessage,
|
|
527
|
+
originWhitelist: DEFAULT_ORIGIN_WHITELIST,
|
|
524
528
|
allowsInlineMediaPlayback: true,
|
|
525
529
|
javaScriptEnabled: true,
|
|
526
530
|
domStorageEnabled: true,
|
|
527
|
-
style: { flex: 1 }
|
|
531
|
+
style: { flex: 1 },
|
|
532
|
+
...webViewProps,
|
|
533
|
+
ref: webViewRef,
|
|
534
|
+
source: { uri: url },
|
|
535
|
+
onMessage: handleMessage
|
|
528
536
|
}
|
|
529
537
|
) });
|
|
530
538
|
}
|
|
@@ -590,6 +598,7 @@ var WebViewTransport = class {
|
|
|
590
598
|
};
|
|
591
599
|
|
|
592
600
|
// src/frame-engine.ts
|
|
601
|
+
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.";
|
|
593
602
|
var FrameSessionDisposedError = class extends Error {
|
|
594
603
|
constructor() {
|
|
595
604
|
super("Frame session disposed");
|
|
@@ -599,7 +608,11 @@ var FrameSessionDisposedError = class extends Error {
|
|
|
599
608
|
function createFrameSession(spec, ctx, props, overrides = {}) {
|
|
600
609
|
const generated = `${spec.channelPrefix}-${Date.now()}`;
|
|
601
610
|
const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
|
|
602
|
-
|
|
611
|
+
let keyPair;
|
|
612
|
+
if (spec.needsKeyPair) {
|
|
613
|
+
if (!(0, import_platform_sdk_core3.isSecureRandomAvailable)()) throw new Error(CRYPTO_UNAVAILABLE_MESSAGE);
|
|
614
|
+
keyPair = (0, import_platform_sdk_core3.generateKeyPair)();
|
|
615
|
+
}
|
|
603
616
|
const builtUrl = spec.buildUrl ? spec.buildUrl(ctx, props, channelId, keyPair?.publicKey) : (0, import_platform_sdk_core3.buildFrameUrl)(
|
|
604
617
|
spec.path,
|
|
605
618
|
{ ...spec.buildParams?.(ctx, props, keyPair?.publicKey), channelId },
|
|
@@ -977,6 +990,7 @@ function createRNClient(deps) {
|
|
|
977
990
|
getConnection: (options) => getConnection(deps, options ?? {}),
|
|
978
991
|
connect: (opts) => connect(deps, opts),
|
|
979
992
|
setupAuth: (opts) => setupAuth(deps, opts),
|
|
993
|
+
getCredentials: () => core.getCredentials(),
|
|
980
994
|
getPaymentMethods: () => core.getPaymentMethods(),
|
|
981
995
|
getQuote: (params) => core.getQuote(params),
|
|
982
996
|
getAssets: (params) => core.getAssets(params),
|
|
@@ -1331,7 +1345,8 @@ function MoonPayFrameView({
|
|
|
1331
1345
|
props,
|
|
1332
1346
|
style,
|
|
1333
1347
|
defaultStyle,
|
|
1334
|
-
onEvent
|
|
1348
|
+
onEvent,
|
|
1349
|
+
webViewProps
|
|
1335
1350
|
}) {
|
|
1336
1351
|
const { sessionToken, core, frameBaseUrl, theme } = useMoonPayContext();
|
|
1337
1352
|
const [transport, setTransport] = (0, import_react4.useState)(null);
|
|
@@ -1399,15 +1414,15 @@ function MoonPayFrameView({
|
|
|
1399
1414
|
applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
|
|
1400
1415
|
}, [liveKey]);
|
|
1401
1416
|
if (spec.hidden) {
|
|
1402
|
-
return transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport, hidden: true }) : null;
|
|
1417
|
+
return transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport, hidden: true, webViewProps }) : null;
|
|
1403
1418
|
}
|
|
1404
1419
|
const resolvedStyle = { ...defaultStyle, ...style };
|
|
1405
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: resolvedStyle, children: transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport }) : null });
|
|
1420
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: resolvedStyle, children: transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport, webViewProps }) : null });
|
|
1406
1421
|
}
|
|
1407
1422
|
|
|
1408
1423
|
// src/components/add-card.tsx
|
|
1409
1424
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1410
|
-
function MoonPayAddCard({ onEvent, style }) {
|
|
1425
|
+
function MoonPayAddCard({ onEvent, style, webViewProps }) {
|
|
1411
1426
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1412
1427
|
MoonPayFrameView,
|
|
1413
1428
|
{
|
|
@@ -1415,7 +1430,8 @@ function MoonPayAddCard({ onEvent, style }) {
|
|
|
1415
1430
|
props: {},
|
|
1416
1431
|
style,
|
|
1417
1432
|
defaultStyle: { flex: 1 },
|
|
1418
|
-
onEvent
|
|
1433
|
+
onEvent,
|
|
1434
|
+
webViewProps
|
|
1419
1435
|
}
|
|
1420
1436
|
);
|
|
1421
1437
|
}
|
|
@@ -1426,7 +1442,8 @@ function MoonPayApplePayButton({
|
|
|
1426
1442
|
quote,
|
|
1427
1443
|
externalTransactionId,
|
|
1428
1444
|
onEvent,
|
|
1429
|
-
style
|
|
1445
|
+
style,
|
|
1446
|
+
webViewProps
|
|
1430
1447
|
}) {
|
|
1431
1448
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1432
1449
|
MoonPayFrameView,
|
|
@@ -1435,14 +1452,15 @@ function MoonPayApplePayButton({
|
|
|
1435
1452
|
props: { quote, externalTransactionId },
|
|
1436
1453
|
style,
|
|
1437
1454
|
defaultStyle: { height: 48 },
|
|
1438
|
-
onEvent
|
|
1455
|
+
onEvent,
|
|
1456
|
+
webViewProps
|
|
1439
1457
|
}
|
|
1440
1458
|
);
|
|
1441
1459
|
}
|
|
1442
1460
|
|
|
1443
1461
|
// src/components/auth.tsx
|
|
1444
1462
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1445
|
-
function MoonPayAuth({ onEvent, style }) {
|
|
1463
|
+
function MoonPayAuth({ onEvent, style, webViewProps }) {
|
|
1446
1464
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1447
1465
|
MoonPayFrameView,
|
|
1448
1466
|
{
|
|
@@ -1450,7 +1468,8 @@ function MoonPayAuth({ onEvent, style }) {
|
|
|
1450
1468
|
props: {},
|
|
1451
1469
|
style,
|
|
1452
1470
|
defaultStyle: { flex: 1 },
|
|
1453
|
-
onEvent
|
|
1471
|
+
onEvent,
|
|
1472
|
+
webViewProps
|
|
1454
1473
|
}
|
|
1455
1474
|
);
|
|
1456
1475
|
}
|
|
@@ -1461,7 +1480,8 @@ function MoonPayBuyButton({
|
|
|
1461
1480
|
quote,
|
|
1462
1481
|
externalTransactionId,
|
|
1463
1482
|
onEvent,
|
|
1464
|
-
style
|
|
1483
|
+
style,
|
|
1484
|
+
webViewProps
|
|
1465
1485
|
}) {
|
|
1466
1486
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1467
1487
|
MoonPayFrameView,
|
|
@@ -1470,7 +1490,8 @@ function MoonPayBuyButton({
|
|
|
1470
1490
|
props: { quote, externalTransactionId },
|
|
1471
1491
|
style,
|
|
1472
1492
|
defaultStyle: { height: 48 },
|
|
1473
|
-
onEvent
|
|
1493
|
+
onEvent,
|
|
1494
|
+
webViewProps
|
|
1474
1495
|
}
|
|
1475
1496
|
);
|
|
1476
1497
|
}
|
|
@@ -1480,7 +1501,8 @@ var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
|
1480
1501
|
function MoonPayBuyFrame({
|
|
1481
1502
|
quote,
|
|
1482
1503
|
externalTransactionId,
|
|
1483
|
-
onEvent
|
|
1504
|
+
onEvent,
|
|
1505
|
+
webViewProps
|
|
1484
1506
|
}) {
|
|
1485
1507
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1486
1508
|
MoonPayFrameView,
|
|
@@ -1488,14 +1510,20 @@ function MoonPayBuyFrame({
|
|
|
1488
1510
|
spec: buySpec,
|
|
1489
1511
|
props: { quote, externalTransactionId },
|
|
1490
1512
|
defaultStyle: {},
|
|
1491
|
-
onEvent
|
|
1513
|
+
onEvent,
|
|
1514
|
+
webViewProps
|
|
1492
1515
|
}
|
|
1493
1516
|
);
|
|
1494
1517
|
}
|
|
1495
1518
|
|
|
1496
1519
|
// src/components/challenge.tsx
|
|
1497
1520
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1498
|
-
function MoonPayChallenge({
|
|
1521
|
+
function MoonPayChallenge({
|
|
1522
|
+
url,
|
|
1523
|
+
onEvent,
|
|
1524
|
+
style,
|
|
1525
|
+
webViewProps
|
|
1526
|
+
}) {
|
|
1499
1527
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1500
1528
|
MoonPayFrameView,
|
|
1501
1529
|
{
|
|
@@ -1503,14 +1531,20 @@ function MoonPayChallenge({ url, onEvent, style }) {
|
|
|
1503
1531
|
props: { url },
|
|
1504
1532
|
style,
|
|
1505
1533
|
defaultStyle: { flex: 1 },
|
|
1506
|
-
onEvent
|
|
1534
|
+
onEvent,
|
|
1535
|
+
webViewProps
|
|
1507
1536
|
}
|
|
1508
1537
|
);
|
|
1509
1538
|
}
|
|
1510
1539
|
|
|
1511
1540
|
// src/components/connect.tsx
|
|
1512
1541
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1513
|
-
function MoonPayConnect({
|
|
1542
|
+
function MoonPayConnect({
|
|
1543
|
+
theme,
|
|
1544
|
+
onEvent,
|
|
1545
|
+
style,
|
|
1546
|
+
webViewProps
|
|
1547
|
+
}) {
|
|
1514
1548
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1515
1549
|
MoonPayFrameView,
|
|
1516
1550
|
{
|
|
@@ -1518,7 +1552,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
|
|
|
1518
1552
|
props: { theme },
|
|
1519
1553
|
style,
|
|
1520
1554
|
defaultStyle: { flex: 1 },
|
|
1521
|
-
onEvent
|
|
1555
|
+
onEvent,
|
|
1556
|
+
webViewProps
|
|
1522
1557
|
}
|
|
1523
1558
|
);
|
|
1524
1559
|
}
|
|
@@ -1527,7 +1562,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
|
|
|
1527
1562
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1528
1563
|
function MoonPayConnectionCheck({
|
|
1529
1564
|
skipKyc,
|
|
1530
|
-
onEvent
|
|
1565
|
+
onEvent,
|
|
1566
|
+
webViewProps
|
|
1531
1567
|
}) {
|
|
1532
1568
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1533
1569
|
MoonPayFrameView,
|
|
@@ -1535,20 +1571,37 @@ function MoonPayConnectionCheck({
|
|
|
1535
1571
|
spec: connectionCheckSpec,
|
|
1536
1572
|
props: { skipKyc },
|
|
1537
1573
|
defaultStyle: {},
|
|
1538
|
-
onEvent
|
|
1574
|
+
onEvent,
|
|
1575
|
+
webViewProps
|
|
1539
1576
|
}
|
|
1540
1577
|
);
|
|
1541
1578
|
}
|
|
1542
1579
|
|
|
1543
1580
|
// src/components/connection-reset.tsx
|
|
1544
1581
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1545
|
-
function MoonPayConnectionReset({
|
|
1546
|
-
|
|
1582
|
+
function MoonPayConnectionReset({
|
|
1583
|
+
onEvent,
|
|
1584
|
+
webViewProps
|
|
1585
|
+
}) {
|
|
1586
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1587
|
+
MoonPayFrameView,
|
|
1588
|
+
{
|
|
1589
|
+
spec: connectionResetSpec,
|
|
1590
|
+
props: {},
|
|
1591
|
+
defaultStyle: {},
|
|
1592
|
+
onEvent,
|
|
1593
|
+
webViewProps
|
|
1594
|
+
}
|
|
1595
|
+
);
|
|
1547
1596
|
}
|
|
1548
1597
|
|
|
1549
1598
|
// src/components/customer-export.tsx
|
|
1550
1599
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1551
|
-
function MoonPayCustomerExport({
|
|
1600
|
+
function MoonPayCustomerExport({
|
|
1601
|
+
onEvent,
|
|
1602
|
+
style,
|
|
1603
|
+
webViewProps
|
|
1604
|
+
}) {
|
|
1552
1605
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1553
1606
|
MoonPayFrameView,
|
|
1554
1607
|
{
|
|
@@ -1556,7 +1609,8 @@ function MoonPayCustomerExport({ onEvent, style }) {
|
|
|
1556
1609
|
props: {},
|
|
1557
1610
|
style,
|
|
1558
1611
|
defaultStyle: { flex: 1 },
|
|
1559
|
-
onEvent
|
|
1612
|
+
onEvent,
|
|
1613
|
+
webViewProps
|
|
1560
1614
|
}
|
|
1561
1615
|
);
|
|
1562
1616
|
}
|
|
@@ -1567,7 +1621,8 @@ function MoonPayGooglePayButton({
|
|
|
1567
1621
|
quote,
|
|
1568
1622
|
externalTransactionId,
|
|
1569
1623
|
onEvent,
|
|
1570
|
-
style
|
|
1624
|
+
style,
|
|
1625
|
+
webViewProps
|
|
1571
1626
|
}) {
|
|
1572
1627
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1573
1628
|
MoonPayFrameView,
|
|
@@ -1576,7 +1631,8 @@ function MoonPayGooglePayButton({
|
|
|
1576
1631
|
props: { quote, externalTransactionId },
|
|
1577
1632
|
style,
|
|
1578
1633
|
defaultStyle: { height: 48 },
|
|
1579
|
-
onEvent
|
|
1634
|
+
onEvent,
|
|
1635
|
+
webViewProps
|
|
1580
1636
|
}
|
|
1581
1637
|
);
|
|
1582
1638
|
}
|
|
@@ -1587,7 +1643,8 @@ function MoonPayWidget({
|
|
|
1587
1643
|
quote,
|
|
1588
1644
|
externalTransactionId,
|
|
1589
1645
|
onEvent,
|
|
1590
|
-
style
|
|
1646
|
+
style,
|
|
1647
|
+
webViewProps
|
|
1591
1648
|
}) {
|
|
1592
1649
|
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1593
1650
|
MoonPayFrameView,
|
|
@@ -1596,7 +1653,8 @@ function MoonPayWidget({
|
|
|
1596
1653
|
props: { quote, externalTransactionId },
|
|
1597
1654
|
style,
|
|
1598
1655
|
defaultStyle: { flex: 1 },
|
|
1599
|
-
onEvent
|
|
1656
|
+
onEvent,
|
|
1657
|
+
webViewProps
|
|
1600
1658
|
}
|
|
1601
1659
|
);
|
|
1602
1660
|
}
|