mirror of
https://github.com/bumi/lntip
synced 2025-06-16 09:45:35 +00:00
Merge pull request #5 from bumi/configurable-urls
Make URLs configurable
This commit is contained in:
commit
a0dd7420de
@ -57,12 +57,33 @@ class LnMe {
|
||||
} else {
|
||||
this.baseURL = `${document.location.protocol}//${document.location.host}`;
|
||||
}
|
||||
if (options.watchPaymentUrl) {
|
||||
this.watchPaymentUrl = options.watchPaymentUrl.bind(this);
|
||||
}
|
||||
if (options.createInvoiceUrl) {
|
||||
this.createInvoiceUrl = options.createInvoiceUrl.bind(this);
|
||||
}
|
||||
if (options.newAddressUrl) {
|
||||
this.newAddressUrl = options.newAddressUrl.bind(this);
|
||||
}
|
||||
this.value = parseInt(options.value || 0);
|
||||
this.memo = options.memo || '';
|
||||
this.target = options.target;
|
||||
this.loadStylesheet(); // load it early that styles are ready when the popup is opened
|
||||
}
|
||||
|
||||
watchPaymentUrl() {
|
||||
return `${this.baseURL}/v1/invoice/${this.invoice.payment_hash}`;
|
||||
}
|
||||
|
||||
createInvoiceUrl() {
|
||||
return `${this.baseURL}/v1/invoices`;
|
||||
}
|
||||
|
||||
newAddressUrl() {
|
||||
return `${this.baseURL}/v1/newaddress`;
|
||||
}
|
||||
|
||||
loadStylesheet() {
|
||||
if (document.getElementById('lnme-style')) { return; }
|
||||
// get the CSS file from the same source as the JS widget file
|
||||
@ -81,7 +102,7 @@ class LnMe {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.paymentWatcher = window.setInterval(() => {
|
||||
this._fetch(`${this.baseURL}/v1/invoice/${this.invoice.payment_hash}`)
|
||||
this._fetch(this.watchPaymentUrl())
|
||||
.then((invoice) => {
|
||||
if (invoice.settled) {
|
||||
this.invoice.settled = true;
|
||||
@ -147,7 +168,7 @@ class LnMe {
|
||||
body: JSON.stringify({ memo: this.memo, value: this.value })
|
||||
};
|
||||
return this._fetch(
|
||||
`${this.baseURL}/v1/invoices`,
|
||||
this.createInvoiceUrl(),
|
||||
args
|
||||
).then((invoice) => {
|
||||
this.invoice = invoice;
|
||||
@ -161,7 +182,7 @@ class LnMe {
|
||||
mode: 'cors',
|
||||
header: { 'Content-Type': 'application/json' }
|
||||
};
|
||||
return this._fetch(`${this.baseURL}/v1/newaddress`, args)
|
||||
return this._fetch(this.newAddressUrl(), args)
|
||||
.then(address => {
|
||||
this.address = address;
|
||||
return address;
|
||||
|
Loading…
x
Reference in New Issue
Block a user