diff --git a/api/lightning/node.py b/api/lightning/node.py index a9bec2e4..8ca8e20c 100644 --- a/api/lightning/node.py +++ b/api/lightning/node.py @@ -255,6 +255,7 @@ class LNNode: 5 Insufficient local balance. """ failure_reason = cls.payment_failure_context[response.failure_reason] + lnpayment.failure_reason = response.failure_reason lnpayment.status = LNPayment.Status.FAILRO lnpayment.save() return False, failure_reason @@ -262,6 +263,7 @@ class LNNode: if response.status == 2: # STATUS 'SUCCEEDED' lnpayment.status = LNPayment.Status.SUCCED lnpayment.fee = float(response.fee_msat)/1000 + lnpayment.preimage = response.payment_preimage lnpayment.save() return True, None diff --git a/api/models.py b/api/models.py index dad72bef..7115ec9b 100644 --- a/api/models.py +++ b/api/models.py @@ -75,6 +75,14 @@ class LNPayment(models.Model): SUCCED = 8, "Succeeded" FAILRO = 9, "Routing failed" + class FailureReason(models.IntegerChoices): + NOTYETF = 0, "Payment isn't failed (yet)" + TIMEOUT = 1, "There are more routes to try, but the payment timeout was exceeded." + NOROUTE = 2, "All possible routes were tried and failed permanently. Or there were no routes to the destination at all." + NONRECO = 3, "A non-recoverable error has occurred." + INCORRE = 4, "Payment details are incorrect (unknown hash, invalid amount or invalid final CLTV delta)." + NOBALAN = 5, "Insufficient unlocked balance in RoboSats' node." + # payment use details type = models.PositiveSmallIntegerField(choices=Types.choices, null=False, @@ -85,6 +93,9 @@ class LNPayment(models.Model): status = models.PositiveSmallIntegerField(choices=Status.choices, null=False, default=Status.INVGEN) + failure_reason = models.PositiveSmallIntegerField(choices=FailureReason.choices, + null=True, + default=None) # payment info payment_hash = models.CharField(max_length=100, diff --git a/api/tasks.py b/api/tasks.py index b1975b17..d1576f1b 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -115,6 +115,7 @@ def follow_send_payment(hash): lnpayment.status = LNPayment.Status.FAILRO lnpayment.last_routing_time = timezone.now() lnpayment.routing_attempts += 1 + lnpayment.failure_reason = response.failure_reason lnpayment.in_flight = False if lnpayment.routing_attempts > 2: lnpayment.status = LNPayment.Status.EXPIRE @@ -140,6 +141,7 @@ def follow_send_payment(hash): print("SUCCEEDED") lnpayment.status = LNPayment.Status.SUCCED lnpayment.fee = float(response.fee_msat)/1000 + lnpayment.preimage = response.payment_preimage lnpayment.save() order.status = Order.Status.SUC order.expires_at = timezone.now() + timedelta( diff --git a/api/views.py b/api/views.py index ac2103df..7b0a05cc 100644 --- a/api/views.py +++ b/api/views.py @@ -379,6 +379,8 @@ class OrderView(viewsets.ViewSet): data["retries"] = order.payout.routing_attempts data["next_retry_time"] = order.payout.last_routing_time + timedelta( minutes=RETRY_TIME) + if order.payout.failure_reason: + data["failure_reason"] = LNPayment.FailureReason(order.payout.failure_reason).label if order.payout.status == LNPayment.Status.EXPIRE: data["invoice_expired"] = True diff --git a/frontend/src/components/TradeBox.js b/frontend/src/components/TradeBox.js index 38f1a6f1..18d5c56c 100644 --- a/frontend/src/components/TradeBox.js +++ b/frontend/src/components/TradeBox.js @@ -1158,6 +1158,20 @@ handleRatingRobosatsChange=(e)=>{ ); } }; + + failureReason=()=>{ + const { t } = this.props; + return( + + + {"Failure reason:"} + + + {t(this.props.data.failure_reason)} + + + ) + } showRoutingFailed=()=>{ const { t } = this.props; @@ -1172,10 +1186,11 @@ handleRatingRobosatsChange=(e)=>{ {t("Your invoice has expired or more than 3 payment attempts have been made.")} - {t("Check the list of compatible wallets")} + {this.props.data.failure_reason ? this.failureReason():null} + {this.compatibleWalletsButton()} @@ -1214,6 +1229,9 @@ handleRatingRobosatsChange=(e)=>{ {t("Lightning Routing Failed")} + + {this.props.data.failure_reason ? this.failureReason():null} + {t("RoboSats will try to pay your invoice 3 times every 5 minutes. If it keeps failing, you will be able to submit a new invoice. Check whether you have enough inbound liquidity. Remember that lightning nodes must be online in order to receive payments.")}