react-native-tink-sdk
Version:
NPM package for wrapping Tink SDKs
72 lines • 3.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.showMoneyManager = exports.MoneyManagerFinanceOverview = exports.initTink = void 0;
const react_1 = require("react");
const react_native_1 = require("react-native");
const LINKING_ERROR = `The package 'react-native-tink-sdk' doesn't seem to be linked. Make sure: \n\n` +
react_native_1.Platform.select({ ios: '- You have run pod install\n', default: '' }) +
'- You rebuilt the app after installing the package\n';
const ReactNativeTink = react_native_1.NativeModules.ReactNativeTink
? react_native_1.NativeModules.ReactNativeTink
: new Proxy({}, {
get() {
throw new Error(LINKING_ERROR);
},
});
const tinkEventEmitter = react_native_1.Platform.OS === 'ios' ? new react_native_1.NativeEventEmitter(react_native_1.NativeModules.TinkEventEmitter) : react_native_1.DeviceEventEmitter;
/**
* This is the method for initializing Tink Money manager SDK. Should be called only once
* and is required only for Android.
*
* @param clientId - client ID retrieved from Tink Console.
*
*/
function initTink(clientId) {
return ReactNativeTink.initTink(clientId);
}
exports.initTink = initTink;
// Automatically resolves this to "MoneyManagerFinanceOverviewManager"
const MoneyManagerFinanceOverviewComponent = react_native_1.requireNativeComponent('MoneyManagerFinanceOverview');
function _userPressedBack(props) {
if (props.userPressedBack) {
props.userPressedBack();
}
}
// This is the view which contains the Money manager SDK screens.
const MoneyManagerFinanceOverview = (props) => {
const { style, clientId, userAccessToken, clientAccessToken, userId, idHint, redirectUri, userPressedBack } = props;
let nativeComponentref;
const onCreate = () => {
if (react_native_1.Platform.OS === 'android') {
const androidViewId = react_native_1.findNodeHandle(nativeComponentref);
react_native_1.UIManager.dispatchViewManagerCommand(androidViewId,
// @ts-ignore
react_native_1.UIManager.MoneyManagerFinanceOverview.Commands.create.toString(), [androidViewId]);
}
};
function cleanListeners() {
tinkEventEmitter.removeAllListeners('userPressedBack');
}
react_1.useEffect(() => {
onCreate();
cleanListeners();
if (userPressedBack) {
tinkEventEmitter.addListener('userPressedBack', () => _userPressedBack(props));
}
});
return (<MoneyManagerFinanceOverviewComponent style={style} clientId={clientId} clientAccessToken={clientAccessToken} userAccessToken={userAccessToken} userId={userId} idHint={idHint} redirectUri={redirectUri} ref={nativeRef => (nativeComponentref = nativeRef)}/>);
};
exports.MoneyManagerFinanceOverview = MoneyManagerFinanceOverview;
/**
* This is the method for opening money manager view
* and is required only for Android.
*
* @param clientId - client ID retrieved from Tink Console.
* @param accessToken - access token generated with all the required scopes.
*
*/
function showMoneyManager(clientId, userAccessToken, appAccessToken, userId, idHint, actorClientId, scope, redirectUri) {
return ReactNativeTink.launchFinanceOverview(clientId, userAccessToken, appAccessToken, userId, idHint, actorClientId, scope, redirectUri);
}
exports.showMoneyManager = showMoneyManager;
//# sourceMappingURL=index.js.map