added error for too long messages

This commit is contained in:
michael1011 2018-04-01 17:21:55 +02:00
parent a9b5a904d8
commit ce6f2008f3
No known key found for this signature in database
GPG Key ID: 84D249BA71685D46
4 changed files with 32 additions and 33 deletions

View File

@ -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

View File

@ -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;

View File

@ -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";
}
}

View File

@ -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"
}
}
}