react-native-unit-components
Version:
Unit React Native components
79 lines • 2.9 kB
JavaScript
/* eslint-disable no-case-declarations */
import React, { useRef } from 'react';
import { UnitMessage } from '../../messages/webMessages/unitMessages';
import { WebComponent } from '../../webComponent/WebComponent';
import { getFundAccountPaymentParams, getFundAccountPaymentScript } from './UNFundAccountPaymentComponent.utils';
import { PresentationMode, WebComponentType } from '../../types/internal/webComponent.types';
import { withReduxStore } from '../../helpers/store/helpers';
import { SafeAreaView } from 'react-native';
import { RESPONSE_KEYS } from '../../messages/webMessages/onLoadMessage';
import { PaymentMessage } from '../../messages/webMessages/paymentsMessage';
import { UNBaseView } from '../../nativeComponents/UNBaseView';
const UNFundAccountPaymentComponent = props => {
const webRef = useRef(null);
const handleUnitOnLoad = response => {
if (!props.onLoad) {
return;
}
if (RESPONSE_KEYS.errors in response) {
props.onLoad(response);
return;
}
if (RESPONSE_KEYS.astraExternalCard in response) {
// AstraOnLoadResponse
props.onLoad(response[RESPONSE_KEYS.astraExternalCard]);
return;
}
if (RESPONSE_KEYS.accountCards in response) {
props.onLoad(response[RESPONSE_KEYS.accountCards]);
return;
}
console.error('On Load Error: unexpected response type');
return;
};
const handleMessage = message => {
switch (message.type) {
case UnitMessage.UNIT_ON_LOAD:
handleUnitOnLoad(message.details);
break;
case PaymentMessage.PAYMENT_CREATED:
const fundAccountPayment = message.details;
props.onPaymentCreated && props.onPaymentCreated(fundAccountPayment.data);
break;
case PaymentMessage.INITIAL_STAGE_BACK_BUTTON_CLICKED:
{
props.onInitialStageBackButtonClicked && props.onInitialStageBackButtonClicked();
break;
}
case PaymentMessage.FINAL_STAGE_DONE_BUTTON_CLICKED:
{
props.onFinalStageDoneButtonClicked && props.onFinalStageDoneButtonClicked();
break;
}
}
};
return /*#__PURE__*/React.createElement(SafeAreaView, {
style: {
flex: 1,
minHeight: 400
}
}, /*#__PURE__*/React.createElement(UNBaseView, {
style: {
flex: 1
},
onLoadError: handleUnitOnLoad
}, /*#__PURE__*/React.createElement(WebComponent, {
ref: webRef,
type: WebComponentType.fundAccountPayment,
presentationMode: PresentationMode.Inherit,
params: getFundAccountPaymentParams(props),
script: getFundAccountPaymentScript(),
theme: props.theme,
language: props.language,
onMessage: message => handleMessage(message),
isScrollable: true,
nestedScrollEnabled: true
})));
};
export default withReduxStore(UNFundAccountPaymentComponent);
//# sourceMappingURL=UNFundAccountPaymentComponent.js.map