UNPKG

@mono.co/connect-react-native

Version:

Easily add mono connect widget to your react-native app and get access to users' financial data.

32 lines (31 loc) 1.05 kB
import React from 'react'; import MonoConnect from './mono-connect'; const REAUTH_SCOPE = 'reauth'; export const MonoContext = React.createContext({ init: () => null, reauthorise: () => null, }); function MonoProvider(props) { var _a; const [openWidget, setOpenWidget] = React.useState(false); const [accountId, setAccountId] = React.useState(null); function init() { setAccountId(null); setOpenWidget(true); } function reauthorise(accountId) { setAccountId(accountId); setOpenWidget(true); } const payload = Object.assign({ openWidget, setOpenWidget }, props); if (accountId) { payload['accountId'] = accountId; payload.scope = (_a = props === null || props === void 0 ? void 0 : props.scope) !== null && _a !== void 0 ? _a : REAUTH_SCOPE; } return (<MonoContext.Provider value={{ init, reauthorise, scope: payload.scope }}> <MonoConnect {...payload}/> {props.children} </MonoContext.Provider>); } export default MonoProvider;