@mono.co/prove-react-native
Version:
The Mono Prove SDK is a quick and secure way to onboard your users from within your React Native app.
107 lines (106 loc) • 3.37 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _react = _interopRequireDefault(require("react"));
var _utils = require("./utils.js");
var _reactNativeWebview = _interopRequireDefault(require("react-native-webview"));
var _error = _interopRequireDefault(require("./error.js"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const INJECTED_JAVASCRIPT = `window.MonoClientInterface = window.ReactNativeWebView;`;
const MonoProve = props => {
const {
sessionId,
onClose,
onSuccess,
onEvent,
openWidget,
setOpenWidget,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
children,
...otherConfig
} = props;
const prove_url = _react.default.useMemo(() => {
const qs = {
reference: otherConfig?.reference,
...otherConfig
};
return (0, _utils.createUrl)(sessionId, qs);
}, [otherConfig, sessionId]);
function handleMessage(message) {
const response = JSON.parse(message);
const eventData = response.data;
switch (response.type) {
case 'mono.prove.widget_opened':
if (onEvent) onEvent('OPENED', eventData);
break;
case 'mono.prove.error_occurred':
if (onEvent) onEvent('ERROR', eventData);
break;
case 'mono.prove.identity_verified':
onSuccess();
if (onEvent) onEvent('IDENTITY_VERIFIED', eventData);
setOpenWidget(false);
break;
case 'mono.prove.widget.closed':
setOpenWidget(false);
onClose();
break;
}
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Modal, {
visible: openWidget,
animationType: "slide",
transparent: false,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.SafeAreaView, {
style: styles.container,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeWebview.default, {
javaScriptEnabled: true,
startInLoadingState: true,
allowsInlineMediaPlayback: true,
mediaPlaybackRequiresUserAction: false,
mediaCapturePermissionGrantType: "grant",
style: styles.webViewContainer,
injectedJavaScript: INJECTED_JAVASCRIPT,
source: {
uri: prove_url
},
onMessage: e => handleMessage(e.nativeEvent.data),
renderLoading: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: styles.loaderContainer,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
size: "large",
color: "#182CD1"
})
}),
renderError: e => /*#__PURE__*/(0, _jsxRuntime.jsx)(_error.default, {
name: e,
setOpenWidget: setOpenWidget
})
})
})
});
};
const styles = _reactNative.StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'rgba(0,0,0, 0.6)'
},
webViewContainer: {
flex: 1,
borderTopLeftRadius: 10,
borderTopRightRadius: 10
},
loaderContainer: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
height: '100%'
}
});
var _default = exports.default = MonoProve;
//# sourceMappingURL=mono-prove.js.map