connect-transfer-react-native-sdk
Version:
Connect Transfer React Native SDK for Mastercard Open Banking Connect
209 lines (208 loc) • 9.18 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useTransferEventResponse = exports.useTransferEventCommonData = exports.getUserEventMappingForPDS = exports.getTransferProductType = exports.getCommonUserEventMapping = void 0;
var _reactRedux = require("react-redux");
var _transactReactNative = require("@atomicfi/transact-react-native");
var _constants = require("../constants");
// @ts-ignore
const getTransferProductType = product => {
if (product === 'deposit') {
return _transactReactNative.Product.DEPOSIT;
}
return null;
};
exports.getTransferProductType = getTransferProductType;
const useTransferEventCommonData = () => {
const queryParams = (0, _reactRedux.useSelector)(state => state.user.queryParamsObject);
if (Object.keys(queryParams).length === 0 || !queryParams.hasOwnProperty('customerId') && !queryParams.hasOwnProperty('partnerId')) {
return {};
}
const commonData = {
[]: queryParams[_constants.TransferEventDataName.CUSTOMER_ID],
[]: queryParams[_constants.TransferEventDataName.PARTNER_ID],
[]: queryParams[_constants.TransferEventDataName.TIMESTAMP],
[]: queryParams[_constants.TransferEventDataName.TTL],
[]: queryParams[_constants.TransferEventDataName.TYPE],
[]: queryParams.signature
};
if (queryParams?.experience?.id) {
commonData[_constants.TransferEventDataName.EXPERIENCE] = queryParams.experience.id;
}
return commonData;
};
exports.useTransferEventCommonData = useTransferEventCommonData;
const useTransferEventResponse = () => {
const commonData = useTransferEventCommonData();
const isEmpty = !commonData || Object.keys(commonData).length === 0;
const getResponseForInitializeTransfer = () => {
if (isEmpty) return;
return {
...commonData,
[]: _constants.TransferActionEvents.INITIALIZE_TRANSFER
};
};
const getResponseForTermsAndConditionsAccepted = () => {
if (isEmpty) return;
return {
...commonData,
[]: _constants.TransferActionEvents.TERMS_ACCEPTED
};
};
const getResponseForInitializeDepositSwitch = productType => {
if (isEmpty) return;
return {
...commonData,
[]: _constants.UserEvents.INITIALIZE_DEPOSIT_SWITCH,
...(productType && {
[]: productType
})
};
};
const getResponseForError = errorCode => ({
...commonData,
[]: _constants.TransferActionEvents.ERROR,
[]: _constants.RedirectReason.ERROR,
[]: errorCode || _constants.TransferActionCodes.API_OR_ATOMIC_ERROR
});
const getResponseForClose = (reason, errorCode) => {
if (isEmpty) return;
const isExitReason = reason === _constants.RedirectReason.UNKNOWN || reason === _constants.RedirectReason.EXIT;
return {
...commonData,
[]: _constants.TransferActionEvents.END,
[]: isExitReason ? _constants.RedirectReason.EXIT : reason,
[]: isExitReason ? _constants.TransferActionCodes.USER_INITIATED_EXIT : errorCode || _constants.TransferActionCodes.API_OR_ATOMIC_ERROR
};
};
const getResponseForFinish = responseData => {
if (isEmpty) return;
const {
taskId,
...otherResponseData
} = responseData;
return {
...commonData,
[]: _constants.TransferActionEvents.END,
[]: _constants.RedirectReason.COMPLETE,
[]: _constants.TransferActionCodes.SUCCESS,
...otherResponseData,
switchId: taskId
};
};
return {
getResponseForInitializeTransfer,
getResponseForTermsAndConditionsAccepted,
getResponseForInitializeDepositSwitch,
getResponseForError,
getResponseForClose,
getResponseForFinish
};
};
exports.useTransferEventResponse = useTransferEventResponse;
const getUserEventMappingForPDS = (interactionResponse, commonData) => {
const {
name: eventName,
value
} = interactionResponse;
const commonResponse = commonData;
switch (eventName) {
case _constants.AtomicEvents.SEARCH_BY_COMPANY:
return {
...commonResponse,
[]: _constants.UserEvents.SEARCH_PAYROLL_PROVIDER,
[]: value?.query
};
case _constants.AtomicEvents.SELECTED_COMPANY_FROM_SEARCH_BY_COMPANY_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.SELECT_PAYROLL_PROVIDER,
[]: value?.company
};
case _constants.AtomicEvents.SELECTED_COMPANY_FROM_SEARCH_BY_FRANCHISE_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.SELECTED_COMPANY_THROUGH_FRANCHISE_PAGE,
[]: value?.company
};
case _constants.AtomicEvents.SELECTED_COMPANY_FROM_TYPEAHEAD_SEARCH_BY_CONFIGURABLE_CONNECTOR_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.SELECTED_COMPANY_THROUGH_PAYROLL_PROVIDER,
[]: value?.company
};
default:
return getCommonUserEventMapping(interactionResponse, commonData);
}
};
exports.getUserEventMappingForPDS = getUserEventMappingForPDS;
const getCommonUserEventMapping = (interactionResponse, commonData) => {
const {
name: eventName,
value
} = interactionResponse;
const commonResponse = commonData;
switch (eventName) {
case _constants.AtomicEvents.CLICKED_CONTINUE_FROM_FORM_ON_LOGIN_PAGE:
case _constants.AtomicEvents.CLICKED_CONTINUE_FROM_FORM_ON_INTERRUPT_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.SUBMIT_CREDENTIALS,
[]: value?.input
};
case _constants.AtomicEvents.CLICKED_EXTERNAL_LOGIN_RECOVERY_LINK_FROM_LOGIN_HELP_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.EXTERNAL_LINK,
[]: value?.button
};
case _constants.AtomicEvents.CLICKED_CONTINUE_FROM_PERCENTAGE_DEPOSIT_AMOUNT_PAGE:
case _constants.AtomicEvents.CLICKED_CONTINUE_FROM_FIXED_DEPOSIT_AMOUNT_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.CHANGE_DEFAULT_ALLOCATION,
[]: value?.distributionType,
...(value?.distributionAmount !== undefined && {
[]: value?.distributionAmount
})
};
case _constants.AtomicEvents.CLICKED_DISTRIBUTION_TYPE_FROM_SELECT_FROM_DEPOSIT_OPTIONS_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.CHANGE_DEFAULT_ALLOCATION,
[]: value?.depositOption
};
case _constants.AtomicEvents.CLICKED_BUTTON_TO_START_AUTHENTICATION:
return {
...commonResponse,
[]: _constants.UserEvents.SUBMIT_ALLOCATION,
[]: value?.distributionType,
...(value?.distributionAmount !== undefined && {
[]: value?.distributionAmount
})
};
case _constants.AtomicEvents.VIEWED_TASK_COMPLETED_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.TASK_COMPLETED,
[]: value?.state
};
case _constants.AtomicEvents.VIEWED_ACCESS_UNAUTHORIZED_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.UNAUTHORIZED,
[]: false
};
case _constants.AtomicEvents.VIEWED_EXPIRED_TOKEN_PAGE:
return {
...commonResponse,
[]: _constants.UserEvents.UNAUTHORIZED,
[]: true
};
default:
break;
}
};
exports.getCommonUserEventMapping = getCommonUserEventMapping;
//# sourceMappingURL=transferEventHandlers.js.map