Add onProgress message type (#344)

This commit is contained in:
Ildar Galeev 2024-09-24 23:10:52 +07:00 committed by GitHub
parent 5111cbfdd2
commit ba95f7b434
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 4 deletions

View File

@ -1,4 +1,4 @@
export const sendPostMessage = (message: 'onSuccess' | 'onError' | 'onBack') => {
window.top.postMessage(message);
export const sendPostMessage = (message: 'onSuccess' | 'onError' | 'onBack' | 'onProgress') => {
window.top.postMessage(message, '*');
console.info(`${message} message sent`);
};

View File

@ -12,6 +12,9 @@ const handlePaymentStatusChanged = (condition: PaymentStatusChanged) => {
case 'failed':
sendPostMessage('onError');
break;
case 'pending':
sendPostMessage('onProgress');
break;
}
};
@ -36,6 +39,11 @@ export function usePostMessage(conditions: PaymentCondition[]) {
case 'invoiceStatusChanged':
handleInvoiceStatusChanged(lastCondition);
break;
case 'paymentStatusUnknown':
case 'interactionCompleted':
case 'paymentStarted':
sendPostMessage('onProgress');
break;
}
}, [conditions]);
}

View File

@ -8,7 +8,7 @@ import {
PaymentModelContext,
ViewModelContext,
} from 'checkout/contexts';
import { isNil, last } from 'checkout/utils';
import { isNil, last, sendPostMessage } from 'checkout/utils';
import { ResultIcon } from './ResultIcon';
import { getPaymentFormViewId, getResultInfo, isExternalIdEmpty, isInstantPayment } from './utils';
@ -79,7 +79,10 @@ export function PaymentResultView() {
colorScheme="brand"
size="lg"
variant="link"
onClick={() => window.open(initContext.redirectUrl, '_self')}
onClick={() => {
sendPostMessage('onBack');
window.open(initContext.redirectUrl, '_self');
}}
>
{l['form.button.back.to.website']}
</Button>