Skip to content

Commit

Permalink
Change notices logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inpsyde-maticluznar committed Dec 20, 2024
1 parent da0a810 commit eeb0c63
Showing 1 changed file with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ const SimulationBlock = () => {
return new Promise( ( resolve ) => setTimeout( resolve, ms ) );
};
const startSimulation = async ( maxRetries ) => {
const simulationStartNoticeId =
'paypal-webhook-simulation-start-notice';
const statusCheckNoticeId = 'paypal-webhook-status-check-notice';
const webhookInfoNoticeId = 'paypal-webhook-simulation-info-notice';
const triggerWebhookInfoNotice = () => {
createInfoNotice(
__(
'Waiting for the webhook to arrive…',
'woocommerce-paypal-payments'
),
{
id: webhookInfoNoticeId,
}
);
};

const stopSimulation = () => {
removeNotice( statusCheckNoticeId );
removeNotice( simulationStartNoticeId );
removeNotice( webhookInfoNoticeId );
setSimulating( false );
};

setSimulating( true );

createInfoNotice(
__(
'Waiting for the webhook to arrive…',
'woocommerce-paypal-payments'
),
{
id: simulationStartNoticeId,
}
);
triggerWebhookInfoNotice();

try {
await startWebhookSimulation();
Expand Down Expand Up @@ -84,24 +84,22 @@ const SimulationBlock = () => {
stopSimulation();
return;
}
removeNotice( statusCheckNoticeId );
createInfoNotice(
__(
'Webhook status check: ',
'woocommerce-paypal-payments'
) +
( i + 1 ) +
' / ' +
maxRetries,
{
id: statusCheckNoticeId,
}
);
removeNotice( webhookInfoNoticeId );
triggerWebhookInfoNotice();
} catch ( error ) {
console.error( error );
}
}
stopSimulation();
createErrorNotice(
__(
'Looks like the webhook cannot be received. Check that your website is accessible from the internet.',
'woocommerce-paypal-payments'
),
{
icon: '❌',
}
);
};

return (
Expand Down

0 comments on commit eeb0c63

Please sign in to comment.