|
@ -1,16 +1,24 @@ |
|
|
Vue.component(VueQrcode.name, VueQrcode); |
|
|
Vue.component(VueQrcode.name, VueQrcode) |
|
|
|
|
|
|
|
|
var locationPath = [window.location.protocol, '//', window.location.host, window.location.pathname].join(''); |
|
|
var locationPath = [ |
|
|
|
|
|
window.location.protocol, |
|
|
|
|
|
'//', |
|
|
|
|
|
window.location.host, |
|
|
|
|
|
window.location.pathname |
|
|
|
|
|
].join('') |
|
|
|
|
|
|
|
|
var mapWithdrawLink = function (obj) { |
|
|
var mapWithdrawLink = function (obj) { |
|
|
obj._data = _.clone(obj); |
|
|
obj._data = _.clone(obj) |
|
|
obj.date = Quasar.utils.date.formatDate(new Date(obj.time * 1000), 'YYYY-MM-DD HH:mm'); |
|
|
obj.date = Quasar.utils.date.formatDate( |
|
|
obj.min_fsat = new Intl.NumberFormat(LOCALE).format(obj.min_withdrawable); |
|
|
new Date(obj.time * 1000), |
|
|
obj.max_fsat = new Intl.NumberFormat(LOCALE).format(obj.max_withdrawable); |
|
|
'YYYY-MM-DD HH:mm' |
|
|
obj.uses_left = obj.uses - obj.used; |
|
|
) |
|
|
obj.print_url = [locationPath, 'print/', obj.id].join(''); |
|
|
obj.min_fsat = new Intl.NumberFormat(LOCALE).format(obj.min_withdrawable) |
|
|
obj.withdraw_url = [locationPath, obj.id].join(''); |
|
|
obj.max_fsat = new Intl.NumberFormat(LOCALE).format(obj.max_withdrawable) |
|
|
return obj; |
|
|
obj.uses_left = obj.uses - obj.used |
|
|
|
|
|
obj.print_url = [locationPath, 'print/', obj.id].join('') |
|
|
|
|
|
obj.withdraw_url = [locationPath, obj.id].join('') |
|
|
|
|
|
return obj |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
new Vue({ |
|
|
new Vue({ |
|
@ -24,8 +32,18 @@ new Vue({ |
|
|
columns: [ |
|
|
columns: [ |
|
|
{name: 'id', align: 'left', label: 'ID', field: 'id'}, |
|
|
{name: 'id', align: 'left', label: 'ID', field: 'id'}, |
|
|
{name: 'title', align: 'left', label: 'Title', field: 'title'}, |
|
|
{name: 'title', align: 'left', label: 'Title', field: 'title'}, |
|
|
{name: 'wait_time', align: 'right', label: 'Wait', field: 'wait_time'}, |
|
|
{ |
|
|
{name: 'uses_left', align: 'right', label: 'Uses left', field: 'uses_left'}, |
|
|
name: 'wait_time', |
|
|
|
|
|
align: 'right', |
|
|
|
|
|
label: 'Wait', |
|
|
|
|
|
field: 'wait_time' |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'uses_left', |
|
|
|
|
|
align: 'right', |
|
|
|
|
|
label: 'Uses left', |
|
|
|
|
|
field: 'uses_left' |
|
|
|
|
|
}, |
|
|
{name: 'min', align: 'right', label: 'Min (sat)', field: 'min_fsat'}, |
|
|
{name: 'min', align: 'right', label: 'Min (sat)', field: 'min_fsat'}, |
|
|
{name: 'max', align: 'right', label: 'Max (sat)', field: 'max_fsat'} |
|
|
{name: 'max', align: 'right', label: 'Max (sat)', field: 'max_fsat'} |
|
|
], |
|
|
], |
|
@ -45,118 +63,146 @@ new Vue({ |
|
|
show: false, |
|
|
show: false, |
|
|
data: null |
|
|
data: null |
|
|
} |
|
|
} |
|
|
}; |
|
|
} |
|
|
}, |
|
|
}, |
|
|
computed: { |
|
|
computed: { |
|
|
sortedWithdrawLinks: function () { |
|
|
sortedWithdrawLinks: function () { |
|
|
return this.withdrawLinks.sort(function (a, b) { |
|
|
return this.withdrawLinks.sort(function (a, b) { |
|
|
return b.uses_left - a.uses_left; |
|
|
return b.uses_left - a.uses_left |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
getWithdrawLinks: function () { |
|
|
getWithdrawLinks: function () { |
|
|
var self = this; |
|
|
var self = this |
|
|
|
|
|
|
|
|
LNbits.api.request( |
|
|
LNbits.api |
|
|
|
|
|
.request( |
|
|
'GET', |
|
|
'GET', |
|
|
'/withdraw/api/v1/links?all_wallets', |
|
|
'/withdraw/api/v1/links?all_wallets', |
|
|
this.g.user.wallets[0].inkey |
|
|
this.g.user.wallets[0].inkey |
|
|
).then(function (response) { |
|
|
) |
|
|
|
|
|
.then(function (response) { |
|
|
self.withdrawLinks = response.data.map(function (obj) { |
|
|
self.withdrawLinks = response.data.map(function (obj) { |
|
|
return mapWithdrawLink(obj); |
|
|
return mapWithdrawLink(obj) |
|
|
}); |
|
|
}) |
|
|
}).catch(function (error) { |
|
|
}) |
|
|
clearInterval(self.checker); |
|
|
.catch(function (error) { |
|
|
LNbits.utils.notifyApiError(error); |
|
|
clearInterval(self.checker) |
|
|
}); |
|
|
LNbits.utils.notifyApiError(error) |
|
|
|
|
|
}) |
|
|
}, |
|
|
}, |
|
|
closeFormDialog: function () { |
|
|
closeFormDialog: function () { |
|
|
this.formDialog.data = { |
|
|
this.formDialog.data = { |
|
|
is_unique: false |
|
|
is_unique: false |
|
|
}; |
|
|
} |
|
|
}, |
|
|
}, |
|
|
openQrCodeDialog: function (linkId) { |
|
|
openQrCodeDialog: function (linkId) { |
|
|
var link = _.findWhere(this.withdrawLinks, {id: linkId}); |
|
|
var link = _.findWhere(this.withdrawLinks, {id: linkId}) |
|
|
this.qrCodeDialog.data = _.clone(link); |
|
|
this.qrCodeDialog.data = _.clone(link) |
|
|
this.qrCodeDialog.show = true; |
|
|
this.qrCodeDialog.show = true |
|
|
}, |
|
|
}, |
|
|
openUpdateDialog: function (linkId) { |
|
|
openUpdateDialog: function (linkId) { |
|
|
var link = _.findWhere(this.withdrawLinks, {id: linkId}); |
|
|
var link = _.findWhere(this.withdrawLinks, {id: linkId}) |
|
|
this.formDialog.data = _.clone(link._data); |
|
|
this.formDialog.data = _.clone(link._data) |
|
|
this.formDialog.show = true; |
|
|
this.formDialog.show = true |
|
|
}, |
|
|
}, |
|
|
sendFormData: function () { |
|
|
sendFormData: function () { |
|
|
var wallet = _.findWhere(this.g.user.wallets, {id: this.formDialog.data.wallet}); |
|
|
var wallet = _.findWhere(this.g.user.wallets, { |
|
|
var data = _.omit(this.formDialog.data, 'wallet'); |
|
|
id: this.formDialog.data.wallet |
|
|
|
|
|
}) |
|
|
|
|
|
var data = _.omit(this.formDialog.data, 'wallet') |
|
|
|
|
|
|
|
|
data.wait_time = data.wait_time * { |
|
|
data.wait_time = |
|
|
'seconds': 1, |
|
|
data.wait_time * |
|
|
'minutes': 60, |
|
|
{ |
|
|
'hours': 3600 |
|
|
seconds: 1, |
|
|
}[this.formDialog.secondMultiplier]; |
|
|
minutes: 60, |
|
|
|
|
|
hours: 3600 |
|
|
|
|
|
}[this.formDialog.secondMultiplier] |
|
|
|
|
|
|
|
|
if (data.id) { this.updateWithdrawLink(wallet, data); } |
|
|
if (data.id) { |
|
|
else { this.createWithdrawLink(wallet, data); } |
|
|
this.updateWithdrawLink(wallet, data) |
|
|
|
|
|
} else { |
|
|
|
|
|
this.createWithdrawLink(wallet, data) |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
updateWithdrawLink: function (wallet, data) { |
|
|
updateWithdrawLink: function (wallet, data) { |
|
|
var self = this; |
|
|
var self = this |
|
|
|
|
|
|
|
|
LNbits.api.request( |
|
|
LNbits.api |
|
|
|
|
|
.request( |
|
|
'PUT', |
|
|
'PUT', |
|
|
'/withdraw/api/v1/links/' + data.id, |
|
|
'/withdraw/api/v1/links/' + data.id, |
|
|
wallet.adminkey, |
|
|
wallet.adminkey, |
|
|
_.pick(data, 'title', 'min_withdrawable', 'max_withdrawable', 'uses', 'wait_time', 'is_unique') |
|
|
_.pick( |
|
|
).then(function (response) { |
|
|
data, |
|
|
self.withdrawLinks = _.reject(self.withdrawLinks, function (obj) { return obj.id == data.id; }); |
|
|
'title', |
|
|
self.withdrawLinks.push(mapWithdrawLink(response.data)); |
|
|
'min_withdrawable', |
|
|
self.formDialog.show = false; |
|
|
'max_withdrawable', |
|
|
}).catch(function (error) { |
|
|
'uses', |
|
|
LNbits.utils.notifyApiError(error); |
|
|
'wait_time', |
|
|
}); |
|
|
'is_unique' |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
.then(function (response) { |
|
|
|
|
|
self.withdrawLinks = _.reject(self.withdrawLinks, function (obj) { |
|
|
|
|
|
return obj.id == data.id |
|
|
|
|
|
}) |
|
|
|
|
|
self.withdrawLinks.push(mapWithdrawLink(response.data)) |
|
|
|
|
|
self.formDialog.show = false |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(function (error) { |
|
|
|
|
|
LNbits.utils.notifyApiError(error) |
|
|
|
|
|
}) |
|
|
}, |
|
|
}, |
|
|
createWithdrawLink: function (wallet, data) { |
|
|
createWithdrawLink: function (wallet, data) { |
|
|
var self = this; |
|
|
var self = this |
|
|
|
|
|
|
|
|
LNbits.api.request( |
|
|
LNbits.api |
|
|
'POST', |
|
|
.request('POST', '/withdraw/api/v1/links', wallet.adminkey, data) |
|
|
'/withdraw/api/v1/links', |
|
|
.then(function (response) { |
|
|
wallet.adminkey, |
|
|
self.withdrawLinks.push(mapWithdrawLink(response.data)) |
|
|
data |
|
|
self.formDialog.show = false |
|
|
).then(function (response) { |
|
|
}) |
|
|
self.withdrawLinks.push(mapWithdrawLink(response.data)); |
|
|
.catch(function (error) { |
|
|
self.formDialog.show = false; |
|
|
LNbits.utils.notifyApiError(error) |
|
|
}).catch(function (error) { |
|
|
}) |
|
|
LNbits.utils.notifyApiError(error); |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
}, |
|
|
deleteWithdrawLink: function (linkId) { |
|
|
deleteWithdrawLink: function (linkId) { |
|
|
var self = this; |
|
|
var self = this |
|
|
var link = _.findWhere(this.withdrawLinks, {id: linkId}); |
|
|
var link = _.findWhere(this.withdrawLinks, {id: linkId}) |
|
|
|
|
|
|
|
|
LNbits.utils.confirmDialog( |
|
|
LNbits.utils |
|
|
'Are you sure you want to delete this withdraw link?' |
|
|
.confirmDialog('Are you sure you want to delete this withdraw link?') |
|
|
).onOk(function () { |
|
|
.onOk(function () { |
|
|
LNbits.api.request( |
|
|
LNbits.api |
|
|
|
|
|
.request( |
|
|
'DELETE', |
|
|
'DELETE', |
|
|
'/withdraw/api/v1/links/' + linkId, |
|
|
'/withdraw/api/v1/links/' + linkId, |
|
|
_.findWhere(self.g.user.wallets, {id: link.wallet}).adminkey |
|
|
_.findWhere(self.g.user.wallets, {id: link.wallet}).adminkey |
|
|
).then(function (response) { |
|
|
) |
|
|
self.withdrawLinks = _.reject(self.withdrawLinks, function (obj) { return obj.id == linkId; }); |
|
|
.then(function (response) { |
|
|
}).catch(function (error) { |
|
|
self.withdrawLinks = _.reject(self.withdrawLinks, function (obj) { |
|
|
LNbits.utils.notifyApiError(error); |
|
|
return obj.id == linkId |
|
|
}); |
|
|
}) |
|
|
}); |
|
|
}) |
|
|
|
|
|
.catch(function (error) { |
|
|
|
|
|
LNbits.utils.notifyApiError(error) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
}, |
|
|
}, |
|
|
exportCSV: function () { |
|
|
exportCSV: function () { |
|
|
LNbits.utils.exportCSV(this.paywallsTable.columns, this.paywalls); |
|
|
LNbits.utils.exportCSV(this.paywallsTable.columns, this.paywalls) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
created: function () { |
|
|
created: function () { |
|
|
if (this.g.user.wallets.length) { |
|
|
if (this.g.user.wallets.length) { |
|
|
var getWithdrawLinks = this.getWithdrawLinks; |
|
|
var getWithdrawLinks = this.getWithdrawLinks |
|
|
getWithdrawLinks(); |
|
|
getWithdrawLinks() |
|
|
this.checker = setInterval(function () { getWithdrawLinks(); }, 20000); |
|
|
this.checker = setInterval(function () { |
|
|
|
|
|
getWithdrawLinks() |
|
|
|
|
|
}, 20000) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}) |
|
|