2024-09-24 11:06:27 +02:00
|
|
|
window.app = Vue.createApp({
|
2020-03-04 23:11:15 +01:00
|
|
|
el: '#vue',
|
2024-09-24 11:06:27 +02:00
|
|
|
mixins: [window.windowMixin],
|
2020-09-02 19:19:18 -03:00
|
|
|
data: function () {
|
2020-03-04 23:11:15 +01:00
|
|
|
return {
|
2024-05-14 13:06:44 +02:00
|
|
|
updatePayments: false,
|
2024-02-20 12:32:49 +01:00
|
|
|
origin: window.location.origin,
|
2020-09-02 12:44:54 -03:00
|
|
|
user: LNbits.map.user(window.user),
|
2020-03-04 23:11:15 +01:00
|
|
|
receive: {
|
|
|
|
show: false,
|
|
|
|
status: 'pending',
|
|
|
|
paymentReq: null,
|
2020-10-15 00:18:56 -03:00
|
|
|
paymentHash: null,
|
2020-10-11 22:19:27 -03:00
|
|
|
minMax: [0, 2100000000000000],
|
|
|
|
lnurl: null,
|
2021-06-11 16:48:13 +01:00
|
|
|
units: ['sat'],
|
|
|
|
unit: 'sat',
|
2020-03-04 23:11:15 +01:00
|
|
|
data: {
|
|
|
|
amount: null,
|
|
|
|
memo: ''
|
|
|
|
}
|
|
|
|
},
|
2020-10-11 22:19:27 -03:00
|
|
|
parse: {
|
2020-03-04 23:11:15 +01:00
|
|
|
show: false,
|
|
|
|
invoice: null,
|
2020-10-11 22:19:27 -03:00
|
|
|
lnurlpay: null,
|
2020-11-10 00:25:46 -03:00
|
|
|
lnurlauth: null,
|
2020-03-04 23:11:15 +01:00
|
|
|
data: {
|
2020-10-11 22:19:27 -03:00
|
|
|
request: '',
|
2020-10-13 15:18:34 -03:00
|
|
|
amount: 0,
|
2023-11-30 09:36:10 +01:00
|
|
|
comment: '',
|
|
|
|
unit: 'sat'
|
2020-10-11 22:19:27 -03:00
|
|
|
},
|
|
|
|
paymentChecker: null,
|
2023-08-03 20:38:05 +02:00
|
|
|
copy: {
|
|
|
|
show: false
|
|
|
|
},
|
2020-10-11 22:19:27 -03:00
|
|
|
camera: {
|
|
|
|
show: false,
|
|
|
|
camera: 'auto'
|
2020-03-04 23:11:15 +01:00
|
|
|
}
|
|
|
|
},
|
2020-04-21 15:29:23 +02:00
|
|
|
disclaimerDialog: {
|
|
|
|
show: false,
|
|
|
|
location: window.location
|
2020-09-29 20:04:02 -03:00
|
|
|
},
|
2024-05-14 17:56:57 +02:00
|
|
|
balance: parseInt(wallet.balance_msat / 1000),
|
2023-12-06 16:54:58 +00:00
|
|
|
fiatBalance: 0,
|
2023-12-22 16:32:01 +00:00
|
|
|
mobileSimple: false,
|
2022-01-31 16:47:58 +00:00
|
|
|
credit: 0,
|
2023-08-28 12:00:59 +02:00
|
|
|
update: {
|
|
|
|
name: null,
|
|
|
|
currency: null
|
2024-07-31 07:51:17 +01:00
|
|
|
},
|
|
|
|
inkeyHidden: true,
|
|
|
|
adminkeyHidden: true
|
2020-05-03 13:55:17 -03:00
|
|
|
}
|
2020-03-04 23:11:15 +01:00
|
|
|
},
|
|
|
|
computed: {
|
2020-09-29 20:04:02 -03:00
|
|
|
formattedBalance: function () {
|
2022-02-02 17:28:00 +00:00
|
|
|
if (LNBITS_DENOMINATION != 'sats') {
|
|
|
|
return this.balance / 100
|
|
|
|
} else {
|
|
|
|
return LNbits.utils.formatSat(this.balance || this.g.wallet.sat)
|
|
|
|
}
|
2020-09-29 20:04:02 -03:00
|
|
|
},
|
2023-12-06 16:54:58 +00:00
|
|
|
formattedFiatBalance() {
|
|
|
|
if (this.fiatBalance) {
|
|
|
|
return LNbits.utils.formatCurrency(
|
|
|
|
this.fiatBalance.toFixed(2),
|
|
|
|
this.g.wallet.currency
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
canPay: function () {
|
2020-10-11 22:19:27 -03:00
|
|
|
if (!this.parse.invoice) return false
|
|
|
|
return this.parse.invoice.sat <= this.balance
|
2020-03-04 23:11:15 +01:00
|
|
|
}
|
|
|
|
},
|
2023-11-30 09:36:10 +01:00
|
|
|
methods: {
|
2020-10-11 22:19:27 -03:00
|
|
|
msatoshiFormat: function (value) {
|
|
|
|
return LNbits.utils.formatSat(value / 1000)
|
2023-11-30 09:36:10 +01:00
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
closeCamera: function () {
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.camera.show = false
|
2020-03-10 23:12:22 +01:00
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
showCamera: function () {
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.camera.show = true
|
2020-03-10 23:12:22 +01:00
|
|
|
},
|
2022-08-21 22:07:18 +01:00
|
|
|
focusInput(el) {
|
|
|
|
this.$nextTick(() => this.$refs[el].focus())
|
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
showReceiveDialog: function () {
|
2020-10-11 22:19:27 -03:00
|
|
|
this.receive.show = true
|
|
|
|
this.receive.status = 'pending'
|
|
|
|
this.receive.paymentReq = null
|
2020-10-15 00:18:56 -03:00
|
|
|
this.receive.paymentHash = null
|
2020-10-11 22:19:27 -03:00
|
|
|
this.receive.data.amount = null
|
|
|
|
this.receive.data.memo = null
|
2021-06-11 16:48:13 +01:00
|
|
|
this.receive.unit = 'sat'
|
2020-10-11 22:19:27 -03:00
|
|
|
this.receive.minMax = [0, 2100000000000000]
|
|
|
|
this.receive.lnurl = null
|
2022-08-21 22:07:18 +01:00
|
|
|
this.focusInput('setAmount')
|
2020-03-04 23:11:15 +01:00
|
|
|
},
|
2020-10-11 22:19:27 -03:00
|
|
|
showParseDialog: function () {
|
|
|
|
this.parse.show = true
|
|
|
|
this.parse.invoice = null
|
|
|
|
this.parse.lnurlpay = null
|
2020-11-10 00:25:46 -03:00
|
|
|
this.parse.lnurlauth = null
|
2023-08-03 20:38:05 +02:00
|
|
|
this.parse.copy.show =
|
|
|
|
window.isSecureContext && navigator.clipboard?.readText !== undefined
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.data.request = ''
|
2020-10-13 15:18:34 -03:00
|
|
|
this.parse.data.comment = ''
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.data.paymentChecker = null
|
|
|
|
this.parse.camera.show = false
|
2023-09-25 11:59:04 +02:00
|
|
|
this.focusInput('textArea')
|
2020-03-04 23:11:15 +01:00
|
|
|
},
|
2020-10-11 22:19:27 -03:00
|
|
|
closeParseDialog: function () {
|
|
|
|
setTimeout(() => {
|
2020-10-15 00:18:56 -03:00
|
|
|
clearInterval(this.parse.paymentChecker)
|
2020-10-13 13:57:26 -03:00
|
|
|
}, 10000)
|
2020-03-10 23:12:22 +01:00
|
|
|
},
|
2020-10-15 00:18:56 -03:00
|
|
|
onPaymentReceived: function (paymentHash) {
|
2024-05-14 13:06:44 +02:00
|
|
|
this.updatePayments = !this.updatePayments
|
2020-10-15 00:18:56 -03:00
|
|
|
if (this.receive.paymentHash === paymentHash) {
|
|
|
|
this.receive.show = false
|
|
|
|
this.receive.paymentHash = null
|
|
|
|
}
|
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
createInvoice: function () {
|
2020-05-03 13:55:17 -03:00
|
|
|
this.receive.status = 'loading'
|
2022-02-02 17:28:00 +00:00
|
|
|
if (LNBITS_DENOMINATION != 'sats') {
|
|
|
|
this.receive.data.amount = this.receive.data.amount * 100
|
|
|
|
}
|
2020-05-03 13:55:17 -03:00
|
|
|
LNbits.api
|
|
|
|
.createInvoice(
|
|
|
|
this.g.wallet,
|
|
|
|
this.receive.data.amount,
|
2020-10-12 18:15:27 -03:00
|
|
|
this.receive.data.memo,
|
2021-06-11 16:48:13 +01:00
|
|
|
this.receive.unit,
|
2020-10-12 18:15:27 -03:00
|
|
|
this.receive.lnurl && this.receive.lnurl.callback
|
2020-05-03 13:55:17 -03:00
|
|
|
)
|
2020-10-11 22:19:27 -03:00
|
|
|
.then(response => {
|
|
|
|
this.receive.status = 'success'
|
|
|
|
this.receive.paymentReq = response.data.payment_request
|
2020-10-15 00:18:56 -03:00
|
|
|
this.receive.paymentHash = response.data.payment_hash
|
2020-10-11 22:19:27 -03:00
|
|
|
|
2020-10-12 18:15:27 -03:00
|
|
|
if (response.data.lnurl_response !== null) {
|
|
|
|
if (response.data.lnurl_response === false) {
|
|
|
|
response.data.lnurl_response = `Unable to connect`
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof response.data.lnurl_response === 'string') {
|
|
|
|
// failure
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2020-10-12 18:15:27 -03:00
|
|
|
timeout: 5000,
|
2020-10-15 00:18:56 -03:00
|
|
|
type: 'warning',
|
2020-10-12 18:15:27 -03:00
|
|
|
message: `${this.receive.lnurl.domain} lnurl-withdraw call failed.`,
|
|
|
|
caption: response.data.lnurl_response
|
|
|
|
})
|
|
|
|
return
|
|
|
|
} else if (response.data.lnurl_response === true) {
|
|
|
|
// success
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2020-10-12 18:15:27 -03:00
|
|
|
timeout: 5000,
|
|
|
|
message: `Invoice sent to ${this.receive.lnurl.domain}!`,
|
|
|
|
spinner: true
|
|
|
|
})
|
|
|
|
}
|
2020-10-11 22:19:27 -03:00
|
|
|
}
|
2020-05-03 13:55:17 -03:00
|
|
|
})
|
2024-05-14 13:06:44 +02:00
|
|
|
.then(() => {
|
|
|
|
this.updatePayments = !this.updatePayments
|
|
|
|
})
|
2020-10-11 22:19:27 -03:00
|
|
|
.catch(err => {
|
|
|
|
LNbits.utils.notifyApiError(err)
|
|
|
|
this.receive.status = 'pending'
|
2020-05-03 13:55:17 -03:00
|
|
|
})
|
2020-03-04 23:11:15 +01:00
|
|
|
},
|
2022-10-24 12:32:20 +02:00
|
|
|
onInitQR: async function (promise) {
|
|
|
|
try {
|
|
|
|
await promise
|
|
|
|
} catch (error) {
|
|
|
|
let mapping = {
|
|
|
|
NotAllowedError: 'ERROR: you need to grant camera access permission',
|
|
|
|
NotFoundError: 'ERROR: no camera on this device',
|
|
|
|
NotSupportedError:
|
|
|
|
'ERROR: secure context required (HTTPS, localhost)',
|
|
|
|
NotReadableError: 'ERROR: is the camera already in use?',
|
|
|
|
OverconstrainedError: 'ERROR: installed cameras are not suitable',
|
|
|
|
StreamApiNotSupportedError:
|
|
|
|
'ERROR: Stream API is not supported in this browser',
|
|
|
|
InsecureContextError:
|
|
|
|
'ERROR: Camera access is only permitted in secure context. Use HTTPS or localhost rather than HTTP.'
|
|
|
|
}
|
|
|
|
let valid_error = Object.keys(mapping).filter(key => {
|
|
|
|
return error.name === key
|
|
|
|
})
|
|
|
|
let camera_error = valid_error
|
|
|
|
? mapping[valid_error]
|
|
|
|
: `ERROR: Camera error (${error.name})`
|
|
|
|
this.parse.camera.show = false
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2022-10-24 12:32:20 +02:00
|
|
|
message: camera_error,
|
|
|
|
type: 'negative'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-09-03 15:05:55 +01:00
|
|
|
lnurlScan() {
|
|
|
|
LNbits.api
|
|
|
|
.request(
|
|
|
|
'GET',
|
|
|
|
'/api/v1/lnurlscan/' + this.parse.data.request,
|
|
|
|
this.g.wallet.adminkey
|
|
|
|
)
|
|
|
|
.catch(err => {
|
|
|
|
LNbits.utils.notifyApiError(err)
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
let data = response.data
|
|
|
|
|
|
|
|
if (data.status === 'ERROR') {
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2024-09-03 15:05:55 +01:00
|
|
|
timeout: 5000,
|
|
|
|
type: 'warning',
|
|
|
|
message: `${data.domain} lnurl call failed.`,
|
|
|
|
caption: data.reason
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.kind === 'pay') {
|
|
|
|
this.parse.lnurlpay = Object.freeze(data)
|
|
|
|
this.parse.data.amount = data.minSendable / 1000
|
|
|
|
} else if (data.kind === 'auth') {
|
|
|
|
this.parse.lnurlauth = Object.freeze(data)
|
|
|
|
} else if (data.kind === 'withdraw') {
|
|
|
|
this.parse.show = false
|
|
|
|
this.receive.show = true
|
|
|
|
this.receive.status = 'pending'
|
|
|
|
this.receive.paymentReq = null
|
|
|
|
this.receive.paymentHash = null
|
|
|
|
this.receive.data.amount = data.maxWithdrawable / 1000
|
|
|
|
this.receive.data.memo = data.defaultDescription
|
|
|
|
this.receive.minMax = [
|
|
|
|
data.minWithdrawable / 1000,
|
|
|
|
data.maxWithdrawable / 1000
|
|
|
|
]
|
|
|
|
this.receive.lnurl = {
|
|
|
|
domain: data.domain,
|
|
|
|
callback: data.callback,
|
|
|
|
fixed: data.fixed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
decodeQR: function (res) {
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.data.request = res
|
2020-09-20 23:58:02 -03:00
|
|
|
this.decodeRequest()
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.camera.show = false
|
2020-09-20 23:58:02 -03:00
|
|
|
},
|
|
|
|
decodeRequest: function () {
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.show = true
|
2024-09-03 15:05:55 +01:00
|
|
|
this.parse.data.request = this.parse.data.request.trim().toLowerCase()
|
|
|
|
let req = this.parse.data.request
|
2024-08-30 12:48:24 +01:00
|
|
|
if (req.startsWith('lightning:')) {
|
|
|
|
this.parse.data.request = req.slice(10)
|
|
|
|
} else if (req.startsWith('lnurl:')) {
|
|
|
|
this.parse.data.request = req.slice(6)
|
|
|
|
} else if (req.includes('lightning=lnurl1')) {
|
|
|
|
this.parse.data.request = req.split('lightning=')[1].split('&')[0]
|
2020-09-20 23:58:02 -03:00
|
|
|
}
|
2024-09-03 11:03:09 +01:00
|
|
|
req = this.parse.data.request
|
2024-08-30 12:48:24 +01:00
|
|
|
if (req.startsWith('lnurl1') || req.match(/[\w.+-~_]+@[\w.+-~_]/)) {
|
2024-09-03 15:05:55 +01:00
|
|
|
this.lnurlScan()
|
2020-09-20 23:58:02 -03:00
|
|
|
return
|
2020-04-27 23:13:42 +02:00
|
|
|
}
|
|
|
|
|
2023-04-18 17:02:49 +01:00
|
|
|
// BIP-21 support
|
|
|
|
if (this.parse.data.request.toLowerCase().includes('lightning')) {
|
2023-04-18 15:39:53 +01:00
|
|
|
this.parse.data.request = this.parse.data.request.split('lightning=')[1]
|
2023-04-18 17:02:49 +01:00
|
|
|
|
2023-04-18 15:39:53 +01:00
|
|
|
// fail safe to check there's nothing after the lightning= part
|
2023-04-18 17:02:49 +01:00
|
|
|
if (this.parse.data.request.includes('&')) {
|
2023-04-18 15:39:53 +01:00
|
|
|
this.parse.data.request = this.parse.data.request.split('&')[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:55:17 -03:00
|
|
|
let invoice
|
2020-03-04 23:11:15 +01:00
|
|
|
try {
|
2020-10-12 23:17:50 -03:00
|
|
|
invoice = decode(this.parse.data.request)
|
2020-03-07 22:27:00 +01:00
|
|
|
} catch (error) {
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2020-03-07 22:27:00 +01:00
|
|
|
timeout: 3000,
|
|
|
|
type: 'warning',
|
|
|
|
message: error + '.',
|
2020-10-12 18:15:27 -03:00
|
|
|
caption: '400 BAD REQUEST'
|
2020-05-03 13:55:17 -03:00
|
|
|
})
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.show = false
|
2020-05-03 13:55:17 -03:00
|
|
|
return
|
2020-03-04 23:11:15 +01:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:13:42 +02:00
|
|
|
let cleanInvoice = {
|
2020-03-04 23:11:15 +01:00
|
|
|
msat: invoice.human_readable_part.amount,
|
|
|
|
sat: invoice.human_readable_part.amount / 1000,
|
|
|
|
fsat: LNbits.utils.formatSat(invoice.human_readable_part.amount / 1000)
|
2020-05-03 13:55:17 -03:00
|
|
|
}
|
2020-03-04 23:11:15 +01:00
|
|
|
|
2020-10-11 22:19:27 -03:00
|
|
|
_.each(invoice.data.tags, tag => {
|
2020-03-04 23:11:15 +01:00
|
|
|
if (_.isObject(tag) && _.has(tag, 'description')) {
|
2020-09-02 12:44:54 -03:00
|
|
|
if (tag.description === 'payment_hash') {
|
2020-05-03 13:55:17 -03:00
|
|
|
cleanInvoice.hash = tag.value
|
2020-09-02 12:44:54 -03:00
|
|
|
} else if (tag.description === 'description') {
|
2020-05-03 13:55:17 -03:00
|
|
|
cleanInvoice.description = tag.value
|
2020-09-02 12:44:54 -03:00
|
|
|
} else if (tag.description === 'expiry') {
|
2020-05-03 13:55:17 -03:00
|
|
|
var expireDate = new Date(
|
|
|
|
(invoice.data.time_stamp + tag.value) * 1000
|
|
|
|
)
|
2024-09-24 16:18:56 +02:00
|
|
|
cleanInvoice.expireDate = Quasar.date.formatDate(
|
2020-05-03 13:55:17 -03:00
|
|
|
expireDate,
|
|
|
|
'YYYY-MM-DDTHH:mm:ss.SSSZ'
|
|
|
|
)
|
|
|
|
cleanInvoice.expired = false // TODO
|
2020-03-04 23:11:15 +01:00
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:55:17 -03:00
|
|
|
})
|
2020-03-04 23:11:15 +01:00
|
|
|
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.invoice = Object.freeze(cleanInvoice)
|
2020-03-04 23:11:15 +01:00
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
payInvoice: function () {
|
2024-09-24 16:18:56 +02:00
|
|
|
let dismissPaymentMsg = Quasar.Notify.create({
|
2020-10-11 22:19:27 -03:00
|
|
|
timeout: 0,
|
2023-04-05 12:51:05 +02:00
|
|
|
message: this.$t('processing_payment')
|
2020-10-11 22:19:27 -03:00
|
|
|
})
|
2020-03-07 22:27:00 +01:00
|
|
|
|
2020-10-11 22:19:27 -03:00
|
|
|
LNbits.api
|
2020-10-12 23:17:50 -03:00
|
|
|
.payInvoice(this.g.wallet, this.parse.data.request)
|
2020-10-11 22:19:27 -03:00
|
|
|
.then(response => {
|
2020-10-15 12:32:28 -03:00
|
|
|
clearInterval(this.parse.paymentChecker)
|
|
|
|
setTimeout(() => {
|
|
|
|
clearInterval(this.parse.paymentChecker)
|
|
|
|
}, 40000)
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.paymentChecker = setInterval(() => {
|
|
|
|
LNbits.api
|
|
|
|
.getPayment(this.g.wallet, response.data.payment_hash)
|
|
|
|
.then(res => {
|
|
|
|
if (res.data.paid) {
|
|
|
|
dismissPaymentMsg()
|
2024-05-14 18:22:14 +02:00
|
|
|
clearInterval(this.parse.paymentChecker)
|
|
|
|
this.updatePayments = !this.updatePayments
|
|
|
|
this.parse.show = false
|
2020-10-11 22:19:27 -03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}, 2000)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
dismissPaymentMsg()
|
|
|
|
LNbits.utils.notifyApiError(err)
|
2024-05-14 18:22:14 +02:00
|
|
|
this.updatePayments = !this.updatePayments
|
|
|
|
this.parse.show = false
|
2020-10-11 22:19:27 -03:00
|
|
|
})
|
|
|
|
},
|
|
|
|
payLnurl: function () {
|
2024-09-24 16:18:56 +02:00
|
|
|
let dismissPaymentMsg = Quasar.Notify.create({
|
2020-03-07 22:27:00 +01:00
|
|
|
timeout: 0,
|
2020-10-12 18:15:27 -03:00
|
|
|
message: 'Processing payment...'
|
2020-05-03 13:55:17 -03:00
|
|
|
})
|
2020-03-07 22:27:00 +01:00
|
|
|
|
2020-05-03 13:55:17 -03:00
|
|
|
LNbits.api
|
2020-10-12 18:15:27 -03:00
|
|
|
.payLnurl(
|
|
|
|
this.g.wallet,
|
|
|
|
this.parse.lnurlpay.callback,
|
|
|
|
this.parse.lnurlpay.description_hash,
|
|
|
|
this.parse.data.amount * 1000,
|
2020-10-13 15:18:34 -03:00
|
|
|
this.parse.lnurlpay.description.slice(0, 120),
|
2023-11-30 09:36:10 +01:00
|
|
|
this.parse.data.comment,
|
|
|
|
this.parse.data.unit
|
2020-10-12 18:15:27 -03:00
|
|
|
)
|
2020-10-11 22:19:27 -03:00
|
|
|
.then(response => {
|
2020-10-12 18:15:27 -03:00
|
|
|
this.parse.show = false
|
|
|
|
|
2020-10-15 12:32:28 -03:00
|
|
|
clearInterval(this.parse.paymentChecker)
|
|
|
|
setTimeout(() => {
|
|
|
|
clearInterval(this.parse.paymentChecker)
|
|
|
|
}, 40000)
|
2020-10-11 22:19:27 -03:00
|
|
|
this.parse.paymentChecker = setInterval(() => {
|
2020-05-03 13:55:17 -03:00
|
|
|
LNbits.api
|
2020-10-11 22:19:27 -03:00
|
|
|
.getPayment(this.g.wallet, response.data.payment_hash)
|
|
|
|
.then(res => {
|
2020-05-03 13:55:17 -03:00
|
|
|
if (res.data.paid) {
|
|
|
|
dismissPaymentMsg()
|
2020-10-12 18:15:27 -03:00
|
|
|
clearInterval(this.parse.paymentChecker)
|
|
|
|
// show lnurlpay success action
|
|
|
|
if (response.data.success_action) {
|
|
|
|
switch (response.data.success_action.tag) {
|
|
|
|
case 'url':
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2020-10-13 13:57:26 -03:00
|
|
|
message: `<a target="_blank" style="color: inherit" href="${response.data.success_action.url}">${response.data.success_action.url}</a>`,
|
2020-10-12 18:15:27 -03:00
|
|
|
caption: response.data.success_action.description,
|
|
|
|
html: true,
|
2020-10-15 00:18:56 -03:00
|
|
|
type: 'positive',
|
2020-10-12 18:15:27 -03:00
|
|
|
timeout: 0,
|
|
|
|
closeBtn: true
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'message':
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2020-10-12 18:15:27 -03:00
|
|
|
message: response.data.success_action.message,
|
2020-10-15 00:18:56 -03:00
|
|
|
type: 'positive',
|
2020-10-12 18:15:27 -03:00
|
|
|
timeout: 0,
|
|
|
|
closeBtn: true
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 'aes':
|
2020-10-13 13:57:26 -03:00
|
|
|
LNbits.api
|
|
|
|
.getPayment(this.g.wallet, response.data.payment_hash)
|
2020-10-15 00:18:56 -03:00
|
|
|
.then(({data: payment}) =>
|
|
|
|
decryptLnurlPayAES(
|
|
|
|
response.data.success_action,
|
|
|
|
payment.preimage
|
|
|
|
)
|
2020-10-13 13:57:26 -03:00
|
|
|
)
|
|
|
|
.then(value => {
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2020-10-13 13:57:26 -03:00
|
|
|
message: value,
|
|
|
|
caption: response.data.success_action.description,
|
|
|
|
html: true,
|
2020-10-15 00:18:56 -03:00
|
|
|
type: 'positive',
|
2020-10-13 13:57:26 -03:00
|
|
|
timeout: 0,
|
|
|
|
closeBtn: true
|
|
|
|
})
|
|
|
|
})
|
2020-10-12 18:15:27 -03:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:55:17 -03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}, 2000)
|
|
|
|
})
|
2020-10-11 22:19:27 -03:00
|
|
|
.catch(err => {
|
2020-05-03 13:55:17 -03:00
|
|
|
dismissPaymentMsg()
|
2020-10-11 22:19:27 -03:00
|
|
|
LNbits.utils.notifyApiError(err)
|
2020-05-03 13:55:17 -03:00
|
|
|
})
|
2020-03-04 23:11:15 +01:00
|
|
|
},
|
2020-11-10 00:25:46 -03:00
|
|
|
authLnurl: function () {
|
2024-09-24 16:18:56 +02:00
|
|
|
let dismissAuthMsg = Quasar.Notify.create({
|
2020-11-10 00:25:46 -03:00
|
|
|
timeout: 10,
|
|
|
|
message: 'Performing authentication...'
|
|
|
|
})
|
|
|
|
|
|
|
|
LNbits.api
|
|
|
|
.authLnurl(this.g.wallet, this.parse.lnurlauth.callback)
|
2023-09-25 15:06:00 +02:00
|
|
|
.then(_ => {
|
2020-11-10 00:25:46 -03:00
|
|
|
dismissAuthMsg()
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2020-11-10 00:25:46 -03:00
|
|
|
message: `Authentication successful.`,
|
|
|
|
type: 'positive',
|
|
|
|
timeout: 3500
|
|
|
|
})
|
|
|
|
this.parse.show = false
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
dismissAuthMsg()
|
2020-11-10 23:01:55 -03:00
|
|
|
if (err.response.data.reason) {
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2020-11-10 23:01:55 -03:00
|
|
|
message: `Authentication failed. ${this.parse.lnurlauth.domain} says:`,
|
|
|
|
caption: err.response.data.reason,
|
|
|
|
type: 'warning',
|
|
|
|
timeout: 5000
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
LNbits.utils.notifyApiError(err)
|
|
|
|
}
|
2020-11-10 00:25:46 -03:00
|
|
|
})
|
|
|
|
},
|
2023-08-28 12:00:59 +02:00
|
|
|
updateWallet: function (data) {
|
2021-08-06 11:15:07 +01:00
|
|
|
LNbits.api
|
2023-08-28 12:00:59 +02:00
|
|
|
.request('PATCH', '/api/v1/wallet', this.g.wallet.adminkey, data)
|
2023-09-25 15:06:00 +02:00
|
|
|
.then(_ => {
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2023-08-28 12:00:59 +02:00
|
|
|
message: `Wallet updated.`,
|
2021-10-22 00:41:30 +01:00
|
|
|
type: 'positive',
|
|
|
|
timeout: 3500
|
|
|
|
})
|
2023-09-25 15:06:00 +02:00
|
|
|
window.location.reload()
|
2021-10-22 00:41:30 +01:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
LNbits.utils.notifyApiError(err)
|
2021-08-06 11:15:07 +01:00
|
|
|
})
|
|
|
|
},
|
2023-09-25 15:06:00 +02:00
|
|
|
deleteWallet: function () {
|
2020-05-03 13:55:17 -03:00
|
|
|
LNbits.utils
|
|
|
|
.confirmDialog('Are you sure you want to delete this wallet?')
|
2020-10-11 22:19:27 -03:00
|
|
|
.onOk(() => {
|
2023-09-25 15:06:00 +02:00
|
|
|
LNbits.api
|
|
|
|
.deleteWallet(this.g.wallet)
|
|
|
|
.then(_ => {
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2023-09-25 15:06:00 +02:00
|
|
|
timeout: 3000,
|
|
|
|
message: `Wallet deleted!`,
|
|
|
|
spinner: true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
LNbits.utils.notifyApiError(err)
|
|
|
|
})
|
2020-05-03 13:55:17 -03:00
|
|
|
})
|
2020-03-04 23:11:15 +01:00
|
|
|
},
|
2020-09-29 20:04:02 -03:00
|
|
|
fetchBalance: function () {
|
2020-10-11 22:19:27 -03:00
|
|
|
LNbits.api.getWallet(this.g.wallet).then(response => {
|
2023-11-06 07:49:47 +01:00
|
|
|
this.balance = Math.floor(response.data.balance / 1000)
|
2024-09-24 11:06:27 +02:00
|
|
|
document.dispatchEvent(
|
|
|
|
new CustomEvent('updateWalletBalance', {
|
|
|
|
detail: [this.g.wallet.id, this.balance]
|
|
|
|
})
|
|
|
|
)
|
2020-09-29 20:04:02 -03:00
|
|
|
})
|
2023-12-06 16:54:58 +00:00
|
|
|
if (this.g.wallet.currency) {
|
|
|
|
this.updateFiatBalance()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateFiatBalance() {
|
|
|
|
if (!this.g.wallet.currency) return 0
|
|
|
|
LNbits.api
|
|
|
|
.request('POST', `/api/v1/conversion`, null, {
|
|
|
|
amount: this.balance || this.g.wallet.sat,
|
|
|
|
to: this.g.wallet.currency
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
this.fiatBalance = response.data[this.g.wallet.currency]
|
|
|
|
})
|
|
|
|
.catch(e => console.error(e))
|
|
|
|
},
|
2024-01-30 07:48:59 +01:00
|
|
|
updateBalanceCallback: function (res) {
|
2024-05-16 15:31:24 +02:00
|
|
|
if (res.success && wallet.id === res.wallet_id) {
|
|
|
|
this.balance += res.credit
|
|
|
|
}
|
2024-01-30 07:48:59 +01:00
|
|
|
},
|
2023-08-02 13:42:23 +02:00
|
|
|
pasteToTextArea: function () {
|
2023-09-25 11:59:04 +02:00
|
|
|
this.$refs.textArea.focus() // Set cursor to textarea
|
2023-08-02 13:42:23 +02:00
|
|
|
navigator.clipboard.readText().then(text => {
|
2024-07-09 14:57:03 +02:00
|
|
|
this.parse.data.request = text.trim()
|
2023-08-02 13:42:23 +02:00
|
|
|
})
|
2020-04-01 22:18:46 +02:00
|
|
|
}
|
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
created: function () {
|
2023-12-11 19:40:22 +00:00
|
|
|
let urlParams = new URLSearchParams(window.location.search)
|
|
|
|
if (urlParams.has('lightning') || urlParams.has('lnurl')) {
|
|
|
|
this.parse.data.request =
|
|
|
|
urlParams.get('lightning') || urlParams.get('lnurl')
|
|
|
|
this.decodeRequest()
|
|
|
|
this.parse.show = true
|
|
|
|
}
|
2023-12-22 16:32:01 +00:00
|
|
|
if (this.$q.screen.lt.md) {
|
|
|
|
this.mobileSimple = true
|
|
|
|
}
|
2023-08-28 12:00:59 +02:00
|
|
|
this.update.name = this.g.wallet.name
|
|
|
|
this.update.currency = this.g.wallet.currency
|
2024-03-22 12:59:49 +01:00
|
|
|
this.receive.units = ['sat', ...window.currencies]
|
2024-05-23 07:47:56 +02:00
|
|
|
this.updateFiatBalance()
|
2020-04-23 21:25:46 +02:00
|
|
|
},
|
2024-05-14 13:06:44 +02:00
|
|
|
watch: {
|
|
|
|
updatePayments: function () {
|
|
|
|
this.fetchBalance()
|
|
|
|
}
|
|
|
|
},
|
2020-09-02 19:19:18 -03:00
|
|
|
mounted: function () {
|
2020-10-15 00:18:56 -03:00
|
|
|
// show disclaimer
|
2022-05-17 12:16:41 +01:00
|
|
|
if (!this.$q.localStorage.getItem('lnbits.disclaimerShown')) {
|
2020-05-03 13:55:17 -03:00
|
|
|
this.disclaimerDialog.show = true
|
|
|
|
this.$q.localStorage.set('lnbits.disclaimerShown', true)
|
2020-04-21 23:47:16 +02:00
|
|
|
}
|
2020-10-15 00:18:56 -03:00
|
|
|
// listen to incoming payments
|
2024-05-14 13:06:44 +02:00
|
|
|
LNbits.events.onInvoicePaid(this.g.wallet, payment => {
|
2020-10-15 00:18:56 -03:00
|
|
|
this.onPaymentReceived(payment.payment_hash)
|
2024-05-14 13:06:44 +02:00
|
|
|
})
|
2024-02-12 10:48:07 +00:00
|
|
|
eventReactionWebocket(wallet.id)
|
2020-03-04 23:11:15 +01:00
|
|
|
}
|
2020-05-03 13:55:17 -03:00
|
|
|
})
|
2022-07-04 11:01:08 -06:00
|
|
|
|
|
|
|
if (navigator.serviceWorker != null) {
|
2022-07-05 16:16:46 -06:00
|
|
|
navigator.serviceWorker
|
|
|
|
.register('/service-worker.js')
|
|
|
|
.then(function (registration) {
|
|
|
|
console.log('Registered events at scope: ', registration.scope)
|
|
|
|
})
|
|
|
|
}
|