Fix is last condition is nil (#347)

This commit is contained in:
Ildar Galeev 2024-09-26 12:09:06 +07:00 committed by GitHub
parent 9afbafa386
commit 7355f9a41d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
import { useEffect } from 'react';
import { InvoiceStatusChanged, PaymentCondition, PaymentStatusChanged } from 'checkout/paymentCondition';
import { last, sendPostMessage } from 'checkout/utils';
import { isNil, last, sendPostMessage } from 'checkout/utils';
const handlePaymentStatusChanged = (condition: PaymentStatusChanged) => {
switch (condition.status) {
@ -29,6 +29,7 @@ const handleInvoiceStatusChanged = (condition: InvoiceStatusChanged) => {
export function usePostMessage(conditions: PaymentCondition[]) {
useEffect(() => {
const lastCondition = last(conditions);
if (isNil(lastCondition)) return;
switch (lastCondition.name) {
case 'paymentProcessFailed':
sendPostMessage('onError');