Improves payment reactions (#2251)

* updated to select

* updating

* working

* bundle

* updated to select

* updating

* working

* bundle

* Make room for everything apart from sending

* Update lnbits/static/js/base.js

Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>

* prettier

* bundled

* fundle

* changed to window[]

* vlads suggestion

* added stars

* vlads suggestion

* fundle

---------

Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
This commit is contained in:
Arc
2024-02-12 10:48:07 +00:00
committed by GitHub
co-authored by Vlad Stan
parent 62dec118af
commit 98338ffb00
9 changed files with 423 additions and 790 deletions
+8 -3
View File
@@ -6,6 +6,12 @@ new Vue({
user: null,
hasUsername: false,
showUserId: false,
reactionOptions: [
'None',
'confettiBothSides',
'confettiFireworks',
'confettiStars'
],
tab: 'user',
passwordData: {
show: false,
@@ -27,9 +33,8 @@ new Vue({
this.$q.dark.toggle()
this.$q.localStorage.set('lnbits.darkMode', this.$q.dark.isActive)
},
toggleReactions: function () {
this.reactionToggle = !this.reactionToggle
this.$q.localStorage.set('lnbits.reactions', this.reactionToggle)
reactionChoiceFunc: function () {
this.$q.localStorage.set('lnbits.reactions', this.reactionChoice)
},
changeColor: function (newValue) {
document.body.setAttribute('data-theme', newValue)
+3 -8
View File
@@ -168,7 +168,6 @@ window.LNbits = {
let listener = ev => {
cb(JSON.parse(ev.data))
}
this.listenersCount = this.listenersCount || {[wallet.inkey]: 0}
this.listenersCount[wallet.inkey]++
@@ -444,7 +443,7 @@ window.windowMixin = {
data: function () {
return {
toggleSubs: true,
reactionToggle: true,
reactionChoice: 'confettiBothSides',
isUserAuthorized: false,
g: {
offline: !navigator.onLine,
@@ -524,12 +523,8 @@ window.windowMixin = {
} else {
this.$q.dark.set(true)
}
let reactions = this.$q.localStorage.getItem('lnbits.reactions')
if (reactions == null) {
this.$q.localStorage.set('lnbits.reactions', true)
reactions = true
}
this.reactionToggle = reactions
this.reactionChoice =
this.$q.localStorage.getItem('lnbits.reactions') || 'confettiBothSides'
this.g.allowedThemes = window.allowedThemes ?? ['bitcoin']
+53 -5
View File
@@ -1,5 +1,9 @@
function eventReactionWebocket(event_id, event_function) {
function eventReactionWebocket(event_id) {
localUrl = ''
reaction = localStorage.getItem('lnbits.reactions')
if (!reaction || reaction === 'None') {
return
}
if (location.protocol !== 'http:') {
localUrl = 'wss://' + location.host + '/api/v1/ws/' + event_id
} else {
@@ -7,10 +11,21 @@ function eventReactionWebocket(event_id, event_function) {
}
connection = new WebSocket(localUrl)
connection.onmessage = function (e) {
event_function()
try {
const parsedData = JSON.parse(e.data)
if (parsedData.payment.amount < 0) {
return
}
reaction = localStorage.getItem('lnbits.reactions')
if (reaction) {
window[reaction.split('|')[1]]()
}
} catch (e) {
console.log(e)
}
}
}
function eventReactionBothSidesConfetti() {
function confettiBothSides() {
document.getElementById('vue').disabled = true
var end = Date.now() + 2 * 1000
var colors = ['#FFD700', '#ffffff']
@@ -39,8 +54,8 @@ function eventReactionBothSidesConfetti() {
}
frame()
}
function eventReactionFireworksConfetti() {
var duration = 15 * 1000
function confettiFireworks() {
var duration = 3 * 1000
var animationEnd = Date.now() + duration
var defaults = {startVelocity: 30, spread: 360, ticks: 60, zIndex: 0}
@@ -70,6 +85,39 @@ function eventReactionFireworksConfetti() {
}, 250)
}
function confettiStars() {
var defaults = {
spread: 360,
ticks: 50,
gravity: 0,
decay: 0.94,
startVelocity: 30,
colors: ['FFE400', 'FFBD00', 'E89400', 'FFCA6C', 'FDFFB8']
}
function shoot() {
confetti({
...defaults,
particleCount: 40,
scalar: 1.2,
shapes: ['star']
})
confetti({
...defaults,
particleCount: 10,
scalar: 0.75,
shapes: ['circle']
})
}
setTimeout(shoot, 0)
setTimeout(shoot, 100)
setTimeout(shoot, 200)
setTimeout(shoot, 0)
setTimeout(shoot, 100)
setTimeout(shoot, 200)
}
!(function (t, e) {
!(function t(e, n, a, i) {
var o = !!(
+1 -1
View File
@@ -1,6 +1,6 @@
// update cache version every time there is a new deployment
// so the service worker reinitializes the cache
const CACHE_VERSION = 109
const CACHE_VERSION = 114
const CURRENT_CACHE = `lnbits-${CACHE_VERSION}-`
const getApiKey = request => {
+1 -4
View File
@@ -860,14 +860,11 @@ new Vue({
this.disclaimerDialog.show = true
this.$q.localStorage.set('lnbits.disclaimerShown', true)
}
// listen to incoming payments
if (this.reactionToggle) {
eventReactionWebocket(this.g.wallet.id, eventReactionBothSidesConfetti)
}
LNbits.events.onInvoicePaid(this.g.wallet, payment =>
this.onPaymentReceived(payment.payment_hash)
)
eventReactionWebocket(wallet.id)
}
})