added error for too long messages
This commit is contained in:
parent
a9b5a904d8
commit
ce6f2008f3
|
@ -59,19 +59,11 @@ func (lnd *LND) Connect() error {
|
||||||
func (lnd *LND) GetInvoice(message string, amount int64, expiry int64) (invoice string, err error) {
|
func (lnd *LND) GetInvoice(message string, amount int64, expiry int64) (invoice string, err error) {
|
||||||
var response *lnrpc.AddInvoiceResponse
|
var response *lnrpc.AddInvoiceResponse
|
||||||
|
|
||||||
if message != "" {
|
response, err = lnd.client.AddInvoice(lnd.ctx, &lnrpc.Invoice{
|
||||||
response, err = lnd.client.AddInvoice(lnd.ctx, &lnrpc.Invoice{
|
Memo: message,
|
||||||
Memo: message,
|
Value: amount,
|
||||||
Value: amount,
|
Expiry: expiry,
|
||||||
Expiry: expiry,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
} else {
|
|
||||||
response, err = lnd.client.AddInvoice(lnd.ctx, &lnrpc.Invoice{
|
|
||||||
Value: amount,
|
|
||||||
Expiry: expiry,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -1,4 +1,21 @@
|
||||||
/* TODO: add light theme */
|
/* 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 {
|
.lightningTipInput {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
@ -47,23 +64,6 @@
|
||||||
border: 0;
|
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 {
|
#lightningTipLogo {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 0.6em;
|
margin-bottom: 0.6em;
|
||||||
|
|
|
@ -40,11 +40,12 @@ window.onload = function () {
|
||||||
|
|
||||||
button.style.height = (button.clientHeight + 1) + "px";
|
button.style.height = (button.clientHeight + 1) + "px";
|
||||||
button.style.width = (button.clientWidth + 1) + "px";
|
button.style.width = (button.clientWidth + 1) + "px";
|
||||||
|
|
||||||
|
resizeInput(document.getElementById("lightningTipMessage"))
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: show invoice even if JavaScript is disabled
|
// TODO: show invoice even if JavaScript is disabled
|
||||||
// TODO: fix scaling on phones
|
// TODO: fix scaling on phones
|
||||||
// TODO: optimize creating bigger QR codes
|
|
||||||
// TODO: show price in dollar?
|
// TODO: show price in dollar?
|
||||||
function getInvoice() {
|
function getInvoice() {
|
||||||
if (running === false) {
|
if (running === false) {
|
||||||
|
@ -320,6 +321,6 @@ function resizeInput(element) {
|
||||||
|
|
||||||
// Change the size only if
|
// Change the size only if
|
||||||
if (element.clientHeight !== element.scrollHeight) {
|
if (element.clientHeight !== element.scrollHeight) {
|
||||||
element.style.height = (element.scrollHeight) + "px";
|
element.style.height = element.scrollHeight + "px";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,6 @@ func getInvoiceHandler(writer http.ResponseWriter, request *http.Request) {
|
||||||
if body.Amount != 0 {
|
if body.Amount != 0 {
|
||||||
invoice, err := backend.GetInvoice(body.Message, body.Amount, cfg.TipExpiry)
|
invoice, err := backend.GetInvoice(body.Message, body.Amount, cfg.TipExpiry)
|
||||||
|
|
||||||
// TODO: handle too long messages better
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logMessage := "Created invoice with amount of " + strconv.FormatInt(body.Amount, 10) + " satoshis"
|
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 {
|
} else {
|
||||||
errorMessage = "Failed to create invoice"
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue