Add fields checking for instant payment (#129)

This commit is contained in:
Ildar Galeev 2022-08-05 16:04:26 +03:00 committed by GitHub
parent 571710ded0
commit 84ae285e44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,8 +36,23 @@ const Container = styled.div`
justify-content: space-between;
`;
const isInstantPayment = (form: ServiceProviderMetadataField[], contactInfo: ServiceProviderContactInfo) =>
isNil(form) && isNil(contactInfo);
const isContactInfoRequired = (
contactInfo: ServiceProviderContactInfo,
emailFieldVisible: boolean,
phoneNumberFieldVisible: boolean
): boolean => {
if (isNil(contactInfo)) {
return false;
}
return emailFieldVisible || phoneNumberFieldVisible;
};
const isInstantPayment = (
form: ServiceProviderMetadataField[],
contactInfo: ServiceProviderContactInfo,
emailFieldVisible: boolean,
phoneNumberFieldVisible: boolean
) => isNil(form) && !isContactInfoRequired(contactInfo, emailFieldVisible, phoneNumberFieldVisible);
const PaymentTerminalFormRef: React.FC<InjectedFormProps> = ({ submitFailed, initialize, handleSubmit }) => {
const initConfig = useAppSelector(getInitConfigSelector);
@ -55,7 +70,7 @@ const PaymentTerminalFormRef: React.FC<InjectedFormProps> = ({ submitFailed, ini
useEffect(() => {
dispatch(setViewInfoError(false));
if (!isInstantPayment(form, contactInfo)) {
if (!isInstantPayment(form, contactInfo, email.visible, phoneNumber.visible)) {
switch (paymentStatus) {
case PaymentStatus.pristine:
initialize({
@ -119,7 +134,7 @@ const PaymentTerminalFormRef: React.FC<InjectedFormProps> = ({ submitFailed, ini
</FormGroup>
)}
</div>
{!isInstantPayment(form, contactInfo) && <PayButton />}
{!isInstantPayment(form, contactInfo, email.visible, phoneNumber.visible) && <PayButton />}
</Container>
</form>
);