damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README | LICENSE

commit 7a40085aa45b9e7beb3642ec477c6237fb725893
parent e4d581b9cebaac9bcd7135275d6a2594bfd2d06d
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Wed, 31 Jan 2024 02:11:07 +0000

Let LN node communication have a few tries before displaying errors.

On staging it was observed that occasionally LN node communication fails
once or twice before succeeding. This commit allows such functions to
try a few times before showing the user that there was an error.

This is a preventative measure to avoid sensitive false positives.

Testing: Ran LN flow locally to verify no error messages are displayed.
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Link: 20240131021044.86169-4-daniel@daquino.me
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/components/sections/PurpleCheckout.tsx | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/components/sections/PurpleCheckout.tsx b/src/components/sections/PurpleCheckout.tsx @@ -37,6 +37,11 @@ export function PurpleCheckout() { const [waitingForInvoice, setWaitingForInvoice] = useState<boolean>(false) // Whether we are waiting for a response from the LN node about the invoice const [error, setError] = useState<string|null>(null) // An error message to display to the user + const [lnConnectionRetryCount, setLnConnectionRetryCount] = useState<number>(0) // The number of times we have tried to connect to the LN node + const lnConnectionRetryLimit = 5 // The maximum number of times we will try to connect to the LN node before displaying an error + const [lnWaitinvoiceRetryCount, setLnWaitinvoiceRetryCount] = useState<number>(0) // The number of times we have tried to check the invoice status + const lnWaitinvoiceRetryLimit = 5 // The maximum number of times we will try to check the invoice status before displaying an error + // MARK: - Functions const fetchProfile = async () => { @@ -133,7 +138,12 @@ export function PurpleCheckout() { } catch (e) { console.error(e) - setError("Failed to connect to the Lightning node. Please refresh this page, and try again in a few minutes. If the problem persists, please contact support.") + if (lnConnectionRetryCount >= lnConnectionRetryLimit) { + setError("Failed to connect to the Lightning node. Please refresh this page, and try again in a few minutes. If the problem persists, please contact support.") + } + else { + setLnConnectionRetryCount(lnConnectionRetryCount + 1) + } return } @@ -153,7 +163,12 @@ export function PurpleCheckout() { } catch (e) { setWaitingForInvoice(false) // Indicate that we are no longer waiting for a response from the LN node console.error(e) - setError("There was an error checking the lightning payment status. If you haven't paid yet, please wait a few minutes, refresh the page, and try again. If you have already paid, please copy the reference ID shown below and contact support.") + if (lnWaitinvoiceRetryCount >= lnWaitinvoiceRetryLimit) { + setError("There was an error checking the lightning payment status. If you haven't paid yet, please wait a few minutes, refresh the page, and try again. If you have already paid, please copy the reference ID shown below and contact support.") + } + else { + setLnWaitinvoiceRetryCount(lnWaitinvoiceRetryCount + 1) + } } }