Working
This commit is contained in:
parent
08dad16611
commit
911aabd7d7
4 changed files with 31 additions and 54 deletions
|
|
@ -20,8 +20,8 @@ class MyExtension(BaseModel):
|
||||||
lnurlpay: str = ""
|
lnurlpay: str = ""
|
||||||
lnurlwithdraw: str = ""
|
lnurlwithdraw: str = ""
|
||||||
|
|
||||||
|
|
||||||
class CreatePayment(BaseModel):
|
class CreatePayment(BaseModel):
|
||||||
myextension_id: str
|
myextension_id: str
|
||||||
amount: int
|
amount: int
|
||||||
memo: str
|
memo: str
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,12 +63,6 @@ window.app = Vue.createApp({
|
||||||
LNbits.utils.notifyApiError(err)
|
LNbits.utils.notifyApiError(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async openUrlDialog(tempid) {
|
|
||||||
this.urlDialog.data = _.findWhere(this.myex, {id: tempid})
|
|
||||||
this.qrValue = this.urlDialog.data.lnurlpay
|
|
||||||
await this.connectWebocket(this.urlDialog.data.id)
|
|
||||||
this.urlDialog.show = true
|
|
||||||
},
|
|
||||||
async sendMyExtensionData() {
|
async sendMyExtensionData() {
|
||||||
const data = {
|
const data = {
|
||||||
name: this.formDialog.data.name,
|
name: this.formDialog.data.name,
|
||||||
|
|
@ -172,11 +166,25 @@ window.app = Vue.createApp({
|
||||||
this.formDialog.data.currency = myextension.currency
|
this.formDialog.data.currency = myextension.currency
|
||||||
this.formDialog.show = true
|
this.formDialog.show = true
|
||||||
},
|
},
|
||||||
|
async openUrlDialog(tempid) {
|
||||||
|
this.urlDialog.data = _.findWhere(this.myex, {id: tempid})
|
||||||
|
this.qrValue = this.urlDialog.data.lnurlpay
|
||||||
|
|
||||||
|
// Connecting to our websocket fired in tasks.py
|
||||||
|
this.connectWebocket(this.urlDialog.data.id)
|
||||||
|
|
||||||
|
// We can also use this Lnbits core websocket function for getting a payment reaction
|
||||||
|
const wallet = _.findWhere(this.g.user.wallets, {
|
||||||
|
id: this.urlDialog.data.wallet
|
||||||
|
})
|
||||||
|
eventReactionWebocket(wallet.inkey)
|
||||||
|
|
||||||
|
this.urlDialog.show = true
|
||||||
|
},
|
||||||
async closeformDialog() {
|
async closeformDialog() {
|
||||||
this.formDialog.show = false
|
this.formDialog.show = false
|
||||||
this.formDialog.data = {}
|
this.formDialog.data = {}
|
||||||
},
|
},
|
||||||
|
|
||||||
async createInvoice(tempid) {
|
async createInvoice(tempid) {
|
||||||
///////////////////////////////////////////////////
|
///////////////////////////////////////////////////
|
||||||
///Simple call to the api to create an invoice/////
|
///Simple call to the api to create an invoice/////
|
||||||
|
|
@ -190,44 +198,15 @@ window.app = Vue.createApp({
|
||||||
}
|
}
|
||||||
await LNbits.api
|
await LNbits.api
|
||||||
.request('POST', `/myextension/api/v1/myex/payment`, wallet.inkey, data)
|
.request('POST', `/myextension/api/v1/myex/payment`, wallet.inkey, data)
|
||||||
.then(async response => {
|
.then(response => {
|
||||||
this.qrValue = response.data.payment_request
|
this.qrValue = response.data.payment_request
|
||||||
await this.connectWebocket(wallet.id)
|
this.connectWebocket(wallet.inkey)
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async makeItRain() {
|
connectWebocket(myextension_id) {
|
||||||
document.getElementById('vue').disabled = true
|
|
||||||
var end = Date.now() + 2 * 1000
|
|
||||||
var colors = ['#FFD700', '#ffffff']
|
|
||||||
async function frame() {
|
|
||||||
confetti({
|
|
||||||
particleCount: 2,
|
|
||||||
angle: 60,
|
|
||||||
spread: 55,
|
|
||||||
origin: {x: 0},
|
|
||||||
colors: colors,
|
|
||||||
zIndex: 999999
|
|
||||||
})
|
|
||||||
confetti({
|
|
||||||
particleCount: 2,
|
|
||||||
angle: 120,
|
|
||||||
spread: 55,
|
|
||||||
origin: {x: 1},
|
|
||||||
colors: colors,
|
|
||||||
zIndex: 999999
|
|
||||||
})
|
|
||||||
if (Date.now() < end) {
|
|
||||||
requestAnimationFrame(frame)
|
|
||||||
} else {
|
|
||||||
document.getElementById('vue').disabled = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await frame()
|
|
||||||
},
|
|
||||||
async connectWebocket(wallet_id) {
|
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
///wait for pay action to happen and do a thing////
|
///wait for pay action to happen and do a thing////
|
||||||
///////////////////////////////////////////////////
|
///////////////////////////////////////////////////
|
||||||
|
|
@ -238,7 +217,7 @@ window.app = Vue.createApp({
|
||||||
':' +
|
':' +
|
||||||
location.port +
|
location.port +
|
||||||
'/api/v1/ws/' +
|
'/api/v1/ws/' +
|
||||||
wallet_id
|
myextension_id
|
||||||
} else {
|
} else {
|
||||||
localUrl =
|
localUrl =
|
||||||
'ws://' +
|
'ws://' +
|
||||||
|
|
@ -246,11 +225,11 @@ window.app = Vue.createApp({
|
||||||
':' +
|
':' +
|
||||||
location.port +
|
location.port +
|
||||||
'/api/v1/ws/' +
|
'/api/v1/ws/' +
|
||||||
wallet_id
|
myextension_id
|
||||||
}
|
}
|
||||||
this.connection = new WebSocket(localUrl)
|
this.connection = new WebSocket(localUrl)
|
||||||
this.connection.onmessage = async function (e) {
|
this.connection.onmessage = () => {
|
||||||
await this.makeItRain()
|
this.urlDialog.show = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
1
tasks.py
1
tasks.py
|
|
@ -44,7 +44,6 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
|
|
||||||
# here we could send some data to a websocket on
|
# here we could send some data to a websocket on
|
||||||
# wss://<your-lnbits>/api/v1/ws/<myextension_id> and then listen to it on
|
# wss://<your-lnbits>/api/v1/ws/<myextension_id> and then listen to it on
|
||||||
# the frontend, which we do with index.html connectWebocket()
|
|
||||||
|
|
||||||
some_payment_data = {
|
some_payment_data = {
|
||||||
"name": myextension.name,
|
"name": myextension.name,
|
||||||
|
|
|
||||||
17
views_api.py
17
views_api.py
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, Query, Request
|
from fastapi import APIRouter, Depends, Request
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.core.models import WalletTypeInfo
|
from lnbits.core.models import WalletTypeInfo
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
|
|
@ -18,7 +18,7 @@ from .crud import (
|
||||||
update_myextension,
|
update_myextension,
|
||||||
)
|
)
|
||||||
from .helpers import lnurler
|
from .helpers import lnurler
|
||||||
from .models import CreateMyExtensionData, MyExtension, CreatePayment
|
from .models import CreateMyExtensionData, CreatePayment, MyExtension
|
||||||
|
|
||||||
myextension_api_router = APIRouter()
|
myextension_api_router = APIRouter()
|
||||||
|
|
||||||
|
|
@ -67,6 +67,7 @@ async def api_myextension(myextension_id: str, req: Request) -> MyExtension:
|
||||||
|
|
||||||
return myex
|
return myex
|
||||||
|
|
||||||
|
|
||||||
## Create a new record
|
## Create a new record
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -148,12 +149,8 @@ async def api_myextension_delete(
|
||||||
## This endpoint creates a payment
|
## This endpoint creates a payment
|
||||||
|
|
||||||
|
|
||||||
@myextension_api_router.post(
|
@myextension_api_router.post("/api/v1/myex/payment", status_code=HTTPStatus.CREATED)
|
||||||
"/api/v1/myex/payment", status_code=HTTPStatus.CREATED
|
async def api_myextension_create_invoice(data: CreatePayment) -> dict:
|
||||||
)
|
|
||||||
async def api_myextension_create_invoice(
|
|
||||||
data: CreatePayment
|
|
||||||
) -> dict:
|
|
||||||
myextension = await get_myextension(data.myextension_id)
|
myextension = await get_myextension(data.myextension_id)
|
||||||
|
|
||||||
if not myextension:
|
if not myextension:
|
||||||
|
|
@ -167,7 +164,9 @@ async def api_myextension_create_invoice(
|
||||||
payment = await create_invoice(
|
payment = await create_invoice(
|
||||||
wallet_id=myextension.wallet,
|
wallet_id=myextension.wallet,
|
||||||
amount=data.amount,
|
amount=data.amount,
|
||||||
memo=f"{data.memo} to {myextension.name}" if data.memo else f"{myextension.name}",
|
memo=(
|
||||||
|
f"{data.memo} to {myextension.name}" if data.memo else f"{myextension.name}"
|
||||||
|
),
|
||||||
extra={
|
extra={
|
||||||
"tag": "myextension",
|
"tag": "myextension",
|
||||||
"amount": data.amount,
|
"amount": data.amount,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue