From 93f517e50ff17a3646df599d405d97ad0f362346 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 13:25:11 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20the=20manual=20connection?=
=?UTF-8?q?=20confirmation=20logic?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/common/hooks.js | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/hooks.js b/modules/ppcp-settings/resources/js/data/common/hooks.js
index cd13e02e6..a584c4e99 100644
--- a/modules/ppcp-settings/resources/js/data/common/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/common/hooks.js
@@ -145,18 +145,27 @@ export const useWebhooks = () => {
export const useMerchantInfo = () => {
const { isReady, merchant, features } = useHooks();
- const { refreshMerchantData } = useDispatch( STORE_NAME );
+ const { refreshMerchantData, setMerchant } = useDispatch( STORE_NAME );
const verifyLoginStatus = useCallback( async () => {
const result = await refreshMerchantData();
- if ( ! result.success ) {
+ if ( ! result.success || ! result.merchant ) {
throw new Error( result?.message || result?.error?.message );
}
+ const newMerchant = result.merchant;
+
// Verify if the server state is "connected" and we have a merchant ID.
- return merchant?.isConnected && merchant?.id;
- }, [ refreshMerchantData, merchant ] );
+ if ( newMerchant?.isConnected && newMerchant?.id ) {
+ // Update the verified merchant details in Redux.
+ setMerchant( newMerchant );
+
+ return true;
+ }
+
+ return false;
+ }, [ refreshMerchantData, setMerchant ] );
return {
isReady,