diff --git a/views/assets/lntip.css b/assets/lntip.css
similarity index 100%
rename from views/assets/lntip.css
rename to assets/lntip.css
diff --git a/views/assets/lntip.js b/assets/lntip.js
similarity index 93%
rename from views/assets/lntip.js
rename to assets/lntip.js
index 96459e8..379d44f 100644
--- a/views/assets/lntip.js
+++ b/assets/lntip.js
@@ -13,14 +13,14 @@ LnTip = function (amount, memo, host) {
}
LnTip.prototype.loadStylesheet = function () {
- if (this.styleLoaded) { return }
+ if (document.getElementById('lntip-style')) { return; }
var head = document.getElementsByTagName('head')[0];
var css = document.createElement('link');
+ css.id = "lntip-style";
css.rel = "stylesheet";
css.type = "text/css";
css.href = `${this.host}/static/lntip.css`;
head.appendChild(css);
- this.styleLoaded = true;
}
LnTip.prototype.closePopup = function () {
@@ -31,8 +31,8 @@ LnTip.prototype.closePopup = function () {
}
LnTip.prototype.openPopup = function (content) {
- this.closePopup();
this.loadStylesheet();
+ this.closePopup();
this.popup = new jPopup({
content: content,
shouldSetHash: false
@@ -69,14 +69,18 @@ LnTip.prototype.stopWatchingPayment = function () {
}
LnTip.prototype.payWithWebln = function () {
+ console.log(this.invoice)
if (!webln.isEnabled) {
webln.enable().then((weblnResponse) => {
- return webln.sendPayment({ paymentRequest: invoice.PaymentRequest })
+ console.log(this.invoice.PaymentRequest)
+ return webln.sendPayment({ paymentRequest: this.invoice.PaymentRequest })
}).catch((e) => {
+ console.log(e);
this.requestPayment();
})
} else {
- return webln.sendPayment({ paymentRequest: invoice.PaymentRequest })
+ console.log(this.invoice.PaymentRequest)
+ return webln.sendPayment({ paymentRequest: this.invoice.PaymentRequest })
}
}
diff --git a/examples/tipping.html b/examples/tipping.html
new file mode 100644
index 0000000..d5a6b83
--- /dev/null
+++ b/examples/tipping.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+ Tip me
+
+
diff --git a/invoices.go b/invoices.go
index 3a0d7c7..8389706 100644
--- a/invoices.go
+++ b/invoices.go
@@ -5,9 +5,6 @@ import (
"github.com/bumi/lntip/ln"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
- "html/template"
- "io"
- "io/ioutil"
"log"
"net/http"
"os"
@@ -16,65 +13,19 @@ import (
var stdOutLogger = log.New(os.Stdout, "", log.LstdFlags)
-type TemplateRenderer struct {
- templates *template.Template
-}
-
-func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
- // Add global methods if data is a map
- if viewContext, isMap := data.(map[string]interface{}); isMap {
- viewContext["reverse"] = c.Echo().Reverse
- }
-
- return t.templates.ExecuteTemplate(w, name, data)
-}
-
func main() {
- var indexView = `
-
-
-
-
-
-
-
-
- hallo
-
-`
-
address := flag.String("address", "localhost:10009", "The host and port of the ln gRPC server")
certFile := flag.String("cert", "tls.cert", "Path to the lnd tls.cert file")
macaroonFile := flag.String("macaroon", "invoice.macaroon", "Path to the lnd macaroon file")
- viewPath := flag.String("template", "", "Path of a custom HTML template file")
flag.Parse()
- if *viewPath != "" {
- content, err := ioutil.ReadFile(*viewPath)
- if err != nil {
- panic(err)
- }
- indexView = string(content)
- }
-
e := echo.New()
- e.Static("/static", "views/assets")
+ e.Static("/static", "assets")
e.Use(middleware.CORS())
e.Use(middleware.Recover())
- renderer := &TemplateRenderer{
- templates: template.Must(template.New("index").Parse(indexView)),
- }
- e.Renderer = renderer
- lndOptions := ln.LNDoptions{
+ lndOptions := ln.LNDoptions{
Address: *address,
CertFile: *certFile,
MacaroonFile: *macaroonFile,
@@ -101,9 +52,5 @@ func main() {
return c.JSON(http.StatusOK, invoice)
})
- e.GET("/", func(c echo.Context) error {
- return c.Render(http.StatusOK, "index", map[string]interface{}{})
- })
-
e.Logger.Fatal(e.Start(":1323"))
}
diff --git a/ln/lnd.go b/ln/lnd.go
index 13d76a3..2989ae8 100644
--- a/ln/lnd.go
+++ b/ln/lnd.go
@@ -18,6 +18,7 @@ import (
var stdOutLogger = log.New(os.Stdout, "", log.LstdFlags)
+// thanks https://github.com/philippgille/ln-paywall/
// Invoice is a Lightning Network invoice and contains the typical invoice string and the payment hash.
type Invoice struct {
ImplDepID string
@@ -40,7 +41,7 @@ func (c LNDclient) GenerateInvoice(amount int64, memo string) (Invoice, error) {
Memo: memo,
Value: amount,
}
- stdOutLogger.Println("Creating invoice for a new API request")
+ stdOutLogger.Printf("Creating invoice: %s", memo)
res, err := c.lndClient.AddInvoice(c.ctx, &invoice)
if err != nil {
return result, err
@@ -62,7 +63,7 @@ func (c LNDclient) CheckInvoice(id string) (bool, error) {
return false, err
}
- stdOutLogger.Printf("Checking invoice for hash %v\n", id)
+ stdOutLogger.Printf("Lookup invoice with hash %v\n", id)
// Get the invoice for that hash
paymentHash := lnrpc.PaymentHash{
@@ -82,19 +83,9 @@ func (c LNDclient) CheckInvoice(id string) (bool, error) {
return true, nil
}
-func (c LNDclient) GetURIs() (bool, error) {
- req := &lnrpc.GetInfoRequest{}
- info, err := c.lndClient.GetInfo(c.ctx, req)
- stdOutLogger.Println(info.Uris)
- return true, err
-}
-
-
-// NewLNDclient creates a new LNDclient instance.
func NewLNDclient(lndOptions LNDoptions) (LNDclient, error) {
result := LNDclient{}
- // Set up a connection to the server.
creds, err := credentials.NewClientTLSFromFile(lndOptions.CertFile, "")
if err != nil {
return result, err
diff --git a/views/index.html b/views/index.html
deleted file mode 100644
index d6b0f4e..0000000
--- a/views/index.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-