From ce6f2008f3ddfef7c020a00337557454a0cd6ce6 Mon Sep 17 00:00:00 2001 From: michael1011 Date: Sun, 1 Apr 2018 17:21:55 +0200 Subject: [PATCH] added error for too long messages --- backends/lnd.go | 18 +++++------------- frontend/lightningTip.css | 34 +++++++++++++++++----------------- frontend/lightningTip.js | 5 +++-- lightningtip.go | 8 +++++++- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/backends/lnd.go b/backends/lnd.go index d312817..15dce46 100644 --- a/backends/lnd.go +++ b/backends/lnd.go @@ -59,19 +59,11 @@ func (lnd *LND) Connect() error { func (lnd *LND) GetInvoice(message string, amount int64, expiry int64) (invoice string, err error) { var response *lnrpc.AddInvoiceResponse - if message != "" { - response, err = lnd.client.AddInvoice(lnd.ctx, &lnrpc.Invoice{ - Memo: message, - Value: amount, - Expiry: expiry, - }) - - } else { - response, err = lnd.client.AddInvoice(lnd.ctx, &lnrpc.Invoice{ - Value: amount, - Expiry: expiry, - }) - } + response, err = lnd.client.AddInvoice(lnd.ctx, &lnrpc.Invoice{ + Memo: message, + Value: amount, + Expiry: expiry, + }) if err != nil { return "", err diff --git a/frontend/lightningTip.css b/frontend/lightningTip.css index 00d956e..d634565 100644 --- a/frontend/lightningTip.css +++ b/frontend/lightningTip.css @@ -1,4 +1,21 @@ /* TODO: add light theme */ +#lightningTip { + width: 12em; + + padding: 1em; + + background-color: #212121; + + border-radius: 4px; + + color: #F5F5F5; + + font-size: 20px; + font-family: Arial, Helvetica, sans-serif; + + text-align: center; +} + .lightningTipInput { width: 100%; @@ -47,23 +64,6 @@ border: 0; } -#lightningTip { - width: 12em; - - padding: 1em; - - background-color: #212121; - - border-radius: 4px; - - color: #F5F5F5; - - font-size: 20px; - font-family: Arial, Helvetica, sans-serif; - - text-align: center; -} - #lightningTipLogo { margin-top: 0; margin-bottom: 0.6em; diff --git a/frontend/lightningTip.js b/frontend/lightningTip.js index 049e648..56297b6 100644 --- a/frontend/lightningTip.js +++ b/frontend/lightningTip.js @@ -40,11 +40,12 @@ window.onload = function () { button.style.height = (button.clientHeight + 1) + "px"; button.style.width = (button.clientWidth + 1) + "px"; + + resizeInput(document.getElementById("lightningTipMessage")) }; // TODO: show invoice even if JavaScript is disabled // TODO: fix scaling on phones -// TODO: optimize creating bigger QR codes // TODO: show price in dollar? function getInvoice() { if (running === false) { @@ -320,6 +321,6 @@ function resizeInput(element) { // Change the size only if if (element.clientHeight !== element.scrollHeight) { - element.style.height = (element.scrollHeight) + "px"; + element.style.height = element.scrollHeight + "px"; } } diff --git a/lightningtip.go b/lightningtip.go index f6436e6..eaecbe1 100644 --- a/lightningtip.go +++ b/lightningtip.go @@ -213,7 +213,6 @@ func getInvoiceHandler(writer http.ResponseWriter, request *http.Request) { if body.Amount != 0 { invoice, err := backend.GetInvoice(body.Message, body.Amount, cfg.TipExpiry) - // TODO: handle too long messages better if err == nil { logMessage := "Created invoice with amount of " + strconv.FormatInt(body.Amount, 10) + " satoshis" @@ -245,6 +244,13 @@ func getInvoiceHandler(writer http.ResponseWriter, request *http.Request) { } else { errorMessage = "Failed to create invoice" + + // This is way to hacky + // Maybe a cast to the gRPC error and get its error message directly + if fmt.Sprint(err)[:47] == "rpc error: code = Unknown desc = memo too large" { + errorMessage += ": message too long" + } + } }