mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-19 12:01:12 +02:00
animation queue working
This commit is contained in:
@@ -23,7 +23,7 @@ async def m001_initial(db):
|
||||
lnurl_title TEXT,
|
||||
show_message INTEGER,
|
||||
show_ack INTEGER,
|
||||
show_price INTEGER,
|
||||
show_price TEXT,
|
||||
amount_made INTEGER,
|
||||
fullscreen_cam INTEGER,
|
||||
iframe_url TEXT,
|
||||
|
@@ -25,7 +25,7 @@ class Copilots(NamedTuple):
|
||||
lnurl_title: str
|
||||
show_message: int
|
||||
show_ack: int
|
||||
show_price: int
|
||||
show_price: str
|
||||
amount_made: int
|
||||
timestamp: int
|
||||
fullscreen_cam: int
|
||||
|
@@ -135,6 +135,11 @@
|
||||
console.log('Something went wrong!')
|
||||
})
|
||||
},
|
||||
pushAnim(content){
|
||||
document.getElementById('animations').style.width = content[0]
|
||||
document.getElementById('animations').src = content[1]
|
||||
setTimeout(function(){ document.getElementById('animations').src = '' }, 5000)
|
||||
},
|
||||
launch(){
|
||||
self = this
|
||||
console.log("poo")
|
||||
@@ -152,7 +157,6 @@
|
||||
LNbits.utils.notifyApiError(err)
|
||||
})
|
||||
},
|
||||
|
||||
},
|
||||
mounted() {
|
||||
this.initCamera()
|
||||
@@ -160,7 +164,21 @@
|
||||
created: function () {
|
||||
self = this
|
||||
self.copilot = JSON.parse(localStorage.getItem('copilot'))
|
||||
|
||||
console.log(localStorage.getItem('inkey'))
|
||||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/copilot/api/v1/copilot/' +
|
||||
self.copilot.id,
|
||||
localStorage.getItem('inkey')
|
||||
)
|
||||
.then(function (response) {
|
||||
self.copilot = response.data
|
||||
})
|
||||
.catch(err => {
|
||||
LNbits.utils.notifyApiError(err)
|
||||
})
|
||||
|
||||
this.connectionBitStamp = new WebSocket('wss://ws.bitstamp.net')
|
||||
|
||||
const obj = JSON.stringify({
|
||||
@@ -170,14 +188,49 @@
|
||||
|
||||
this.connectionBitStamp.onmessage = function (e) {
|
||||
console.log(JSON.parse(e.data).data.price)
|
||||
self.price = String(
|
||||
new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'USD'
|
||||
}).format(JSON.parse(e.data).data.price)
|
||||
)
|
||||
console.log(self.copilot)
|
||||
if(self.copilot.show_price){
|
||||
if(self.copilot.show_price == "btcusd"){
|
||||
self.price = String(
|
||||
new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'USD'
|
||||
}).format(JSON.parse(e.data).data.price)
|
||||
)
|
||||
}
|
||||
else if(self.copilot.show_price == "btceur"){
|
||||
self.price = String(
|
||||
new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'EUR'
|
||||
}).format(JSON.parse(e.data).data.price)
|
||||
)
|
||||
}
|
||||
else if(self.copilot.show_price == "btcgbp"){
|
||||
self.price = String(
|
||||
new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'GBP'
|
||||
}).format(JSON.parse(e.data).data.price)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
this.connectionBitStamp.onopen = () => this.connectionBitStamp.send(obj)
|
||||
|
||||
const fetch = (data) => new Promise(resolve => setTimeout(resolve, 5000, this.pushAnim(data)))
|
||||
|
||||
const addTask = (() => {
|
||||
let pending = Promise.resolve();
|
||||
const run = async (data) => {
|
||||
try {
|
||||
await pending;
|
||||
} finally {
|
||||
return fetch(data);
|
||||
}
|
||||
}
|
||||
return (data) => (pending = run(data))
|
||||
})();
|
||||
|
||||
if (location.protocol !== 'http:') {
|
||||
localUrl = 'wss://' +
|
||||
@@ -195,58 +248,24 @@
|
||||
this.connection = new WebSocket(localUrl)
|
||||
this.connection.onmessage = function (e) {
|
||||
console.log(e.data)
|
||||
|
||||
res = e.data.split('-')
|
||||
if (res[0] != this.oldRes) {
|
||||
this.oldRes = res[0]
|
||||
if (res[0] == 'rocket') {
|
||||
document.getElementById('animations').style.width = '40%'
|
||||
document.getElementById('animations').src =
|
||||
'/copilot/static/rocket.gif'
|
||||
setTimeout(function () {
|
||||
document.getElementById('animations').src = ''
|
||||
}, 5000)
|
||||
addTask(['40%', '/copilot/static/rocket.gif'])
|
||||
}
|
||||
if (res[0] == 'face') {
|
||||
document.getElementById('animations').style.width = '35%'
|
||||
document.getElementById('animations').src =
|
||||
'/copilot/static/face.gif'
|
||||
setTimeout(function () {
|
||||
document.getElementById('animations').src = ''
|
||||
}, 5000)
|
||||
addTask(['35%', '/copilot/static/face.gif'])
|
||||
}
|
||||
if (res[0] == 'bitcoin') {
|
||||
document.getElementById('animations').style.width = '30%'
|
||||
document.getElementById('animations').src =
|
||||
'/copilot/static/bitcoin.gif'
|
||||
setTimeout(function () {
|
||||
document.getElementById('animations').src = ''
|
||||
}, 5000)
|
||||
addTask(['30%', '/copilot/static/bitcoin.gif'])
|
||||
}
|
||||
if (res[0] == 'confetti') {
|
||||
document.getElementById('animations').style.width = '100%'
|
||||
document.getElementById('animations').style.height = '100%'
|
||||
document.getElementById('animations').src =
|
||||
'/copilot/static/confetti.gif'
|
||||
setTimeout(function () {
|
||||
document.getElementById('animations').src = ''
|
||||
document.getElementById('animations').style.height = ''
|
||||
}, 5000)
|
||||
addTask(['100%', '/copilot/static/confetti.gif'])
|
||||
}
|
||||
if (res[0] == 'martijn') {
|
||||
document.getElementById('animations').style.width = '40%'
|
||||
document.getElementById('animations').src =
|
||||
'/copilot/static/martijn.gif'
|
||||
setTimeout(function () {
|
||||
document.getElementById('animations').src = ''
|
||||
}, 5000)
|
||||
addTask(['40%', '/copilot/static/martijn.gif'])
|
||||
}
|
||||
if (res[0] == 'rick') {
|
||||
this.animQueue.push({size: '40%', location: '/copilot/static/rick.gif'})
|
||||
}
|
||||
if(self.queue == false){
|
||||
for()
|
||||
|
||||
addTask(['40%', '/copilot/static/rick.gif'])
|
||||
}
|
||||
if (res[0] == 'true') {
|
||||
document.getElementById('videoCamera').style.width = '20%'
|
||||
@@ -260,8 +279,6 @@
|
||||
if (res[1] != 'none') {
|
||||
showNotif(res[1])
|
||||
}
|
||||
this.oldRes = ''
|
||||
}
|
||||
}
|
||||
this.connection.onopen = () => this.launch
|
||||
}
|
||||
|
@@ -323,13 +323,15 @@
|
||||
</div>
|
||||
|
||||
<div class="q-gutter-sm">
|
||||
<div class="row">
|
||||
<q-checkbox
|
||||
v-model="formDialogCopilot.data.show_price"
|
||||
left-label
|
||||
label="Show bitcoin price"
|
||||
></q-checkbox>
|
||||
</div>
|
||||
<q-select
|
||||
filled
|
||||
dense
|
||||
style="width:50%"
|
||||
v-model.trim="formDialogCopilot.data.show_price"
|
||||
:options="currencyOptions"
|
||||
label="Show price"
|
||||
/>
|
||||
|
||||
</div>
|
||||
<div class="q-gutter-sm">
|
||||
<div class="row">
|
||||
@@ -453,7 +455,8 @@
|
||||
show: false,
|
||||
data: null
|
||||
},
|
||||
options: ['bitcoin', 'confetti', 'rocket', 'face', 'martijn', 'rick']
|
||||
options: ['bitcoin', 'confetti', 'rocket', 'face', 'martijn', 'rick'],
|
||||
currencyOptions: ['btcusd', 'btceur', 'btcgbp']
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -512,6 +515,7 @@
|
||||
)
|
||||
.then(function (response) {
|
||||
localStorage.setItem('copilot', JSON.stringify(response.data))
|
||||
localStorage.setItem('inkey', self.g.user.wallets[0].inkey)
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
|
Reference in New Issue
Block a user