From f588ffe5d34863d277d7d4d5ba97d647e7be7cee Mon Sep 17 00:00:00 2001 From: PhilReact Date: Wed, 8 Nov 2023 12:46:05 +0200 Subject: [PATCH 1/2] fix sponsorship list includes error --- .../sponsorship-list/sponsorship-list.src.js | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/plugins/plugins/core/sponsorship-list/sponsorship-list.src.js b/plugins/plugins/core/sponsorship-list/sponsorship-list.src.js index ebc74070..5bb599d9 100644 --- a/plugins/plugins/core/sponsorship-list/sponsorship-list.src.js +++ b/plugins/plugins/core/sponsorship-list/sponsorship-list.src.js @@ -721,23 +721,30 @@ class SponsorshipList extends LitElement { } const getTxnRequestResponse = (txnResponse) => { - if(txnResponse.extraData.rewardSharePrivateKey && (txnResponse.data.message.includes('multiple') || txnResponse.data.message.includes('SELF_SHARE_EXISTS'))) { - this.privateRewardShareKey = txnResponse.extraData.rewardSharePrivateKey - this.confirmRelationship(publicKeyValue, isCopy) - } else if (txnResponse.success === false && txnResponse?.message) { - this.errorMessage = txnResponse?.message - this.isLoadingCreateSponsorship = false - throw(txnResponse?.message) - } else if ( - txnResponse.success === true && - !txnResponse.data.error - ) { - this.privateRewardShareKey = txnResponse.extraData.rewardSharePrivateKey - this.confirmRelationship(publicKeyValue, isCopy) + + const extraData = txnResponse && txnResponse.extraData; + const data = txnResponse && txnResponse.data; + const dataMessage = data && data.message; + const extraDataPrivateKey = extraData && extraData.rewardSharePrivateKey; + const txnSuccess = txnResponse && txnResponse.success; + + if (extraDataPrivateKey && typeof dataMessage === 'string' && + (dataMessage.includes('multiple') || dataMessage.includes('SELF_SHARE_EXISTS'))) { + this.privateRewardShareKey = extraDataPrivateKey; + this.confirmRelationship(publicKeyValue, isCopy); + } else if (txnSuccess === false && txnResponse.message) { + this.errorMessage = txnResponse.message; + this.isLoadingCreateSponsorship = false; + throw new Error(txnResponse.message); + } else if (txnSuccess === true && !(data && data.error)) { + this.privateRewardShareKey = extraDataPrivateKey; + this.confirmRelationship(publicKeyValue, isCopy); } else { - this.errorMessage = txnResponse.data.message || txnResponse.message - this.isLoadingCreateSponsorship = false - throw(txnResponse.data.message || txnResponse.message) + // It's a good practice to provide a default error message + const defaultErrorMessage = 'An unknown error occurred.'; + this.errorMessage = dataMessage || txnResponse.message || defaultErrorMessage; + this.isLoadingCreateSponsorship = false; + throw new Error(dataMessage || txnResponse.message || defaultErrorMessage); } } validateReceiver() From 5b9ec54872463ecd81a209021eb3b8fe8f926c3f Mon Sep 17 00:00:00 2001 From: PhilReact Date: Wed, 8 Nov 2023 12:47:02 +0200 Subject: [PATCH 2/2] remove comment --- plugins/plugins/core/sponsorship-list/sponsorship-list.src.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/plugins/core/sponsorship-list/sponsorship-list.src.js b/plugins/plugins/core/sponsorship-list/sponsorship-list.src.js index 5bb599d9..bf552c27 100644 --- a/plugins/plugins/core/sponsorship-list/sponsorship-list.src.js +++ b/plugins/plugins/core/sponsorship-list/sponsorship-list.src.js @@ -740,7 +740,6 @@ class SponsorshipList extends LitElement { this.privateRewardShareKey = extraDataPrivateKey; this.confirmRelationship(publicKeyValue, isCopy); } else { - // It's a good practice to provide a default error message const defaultErrorMessage = 'An unknown error occurred.'; this.errorMessage = dataMessage || txnResponse.message || defaultErrorMessage; this.isLoadingCreateSponsorship = false;