Can fetch balance from mem.space
This commit is contained in:
@@ -137,7 +137,6 @@ async def get_payment(payment_id: str) -> Payments:
|
||||
|
||||
async def get_payments(user: str) -> List[Payments]:
|
||||
rows = await db.fetchall("SELECT * FROM payments WHERE user = ?", (user,))
|
||||
print(rows[0])
|
||||
return [Payments.from_row(row) for row in rows]
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<q-card-section>
|
||||
{% raw %}
|
||||
<q-btn unelevated color="deep-purple" @click="formDialog.show = true"
|
||||
>New wallet</q-btn
|
||||
>New wallet </q-btn
|
||||
>
|
||||
<q-btn unelevated color="deep-purple"
|
||||
icon="edit">
|
||||
@@ -424,6 +424,7 @@
|
||||
</style>
|
||||
<script>
|
||||
Vue.component(VueQrcode.name, VueQrcode)
|
||||
|
||||
Vue.filter('reverse', function(value) {
|
||||
// slice to make a copy of array, then reverse the copy
|
||||
return value.slice().reverse();
|
||||
@@ -459,6 +460,7 @@
|
||||
data: function () {
|
||||
return {
|
||||
filter: '',
|
||||
balance: null,
|
||||
checker: null,
|
||||
walletLinks: [],
|
||||
paymentLinks: [],
|
||||
@@ -511,6 +513,18 @@
|
||||
label: 'Amount',
|
||||
field: 'amount'
|
||||
},
|
||||
{
|
||||
name: 'balance',
|
||||
align: 'left',
|
||||
label: 'Paid',
|
||||
field: 'getAddressBalance("1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC")'
|
||||
},
|
||||
{
|
||||
name: 'address',
|
||||
align: 'left',
|
||||
label: 'Address',
|
||||
field: 'address'
|
||||
},
|
||||
{
|
||||
name: 'time to pay',
|
||||
align: 'left',
|
||||
@@ -561,8 +575,10 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
|
||||
getAddresses: function (walletID) {
|
||||
var self = this
|
||||
|
||||
@@ -639,8 +655,6 @@
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
getWalletLinks: function () {
|
||||
var self = this
|
||||
|
||||
@@ -691,6 +705,7 @@
|
||||
|
||||
getPayments: function () {
|
||||
var self = this
|
||||
var getAddressBalance = this.getAddressBalance
|
||||
|
||||
LNbits.api
|
||||
.request(
|
||||
@@ -709,10 +724,12 @@
|
||||
else{
|
||||
response.data[i].timeleft = timeleft
|
||||
}
|
||||
getAddressBalance("1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC")
|
||||
console.log(this.balance)
|
||||
response.data[i].balance = this.balance
|
||||
|
||||
}
|
||||
console.log(response.data)
|
||||
self.paymentLinks = response.data.map(function (obj) {
|
||||
console.log(mapPayment(obj))
|
||||
return mapPayment(obj)
|
||||
})
|
||||
})
|
||||
@@ -726,7 +743,6 @@
|
||||
var data = self.formDialogPayment.data
|
||||
data.amount = parseInt(data.amount)
|
||||
data.time = parseInt(data.time)
|
||||
console.log(data)
|
||||
if (data.id) {
|
||||
this.updatePayment(wallet, data)
|
||||
} else {
|
||||
@@ -760,7 +776,6 @@
|
||||
.then(function (response) {
|
||||
self.paymentLinks.push(mapPayment(response.data))
|
||||
self.formDialogPayment.show = false
|
||||
console.log(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
@@ -789,7 +804,24 @@
|
||||
})
|
||||
})
|
||||
},
|
||||
getAddressBalance: function (address) {
|
||||
var self = this
|
||||
|
||||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/watchonly/api/v1/mempool/' + address,
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
this.balance = response.data.balance
|
||||
console.log(this.balance)
|
||||
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
updateWalletLink: function (wallet, data) {
|
||||
var self = this
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import hashlib
|
||||
from quart import g, jsonify, request, url_for
|
||||
from http import HTTPStatus
|
||||
import httpx
|
||||
import requests
|
||||
|
||||
from lnbits.core.crud import get_user
|
||||
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||
@@ -125,8 +126,8 @@ async def api_payments_retrieve():
|
||||
print(payments)
|
||||
if not payments:
|
||||
return (
|
||||
jsonify({"message": "Cant fetch."}),
|
||||
HTTPStatus.UPGRADE_REQUIRED,
|
||||
jsonify(""),
|
||||
HTTPStatus.OK
|
||||
)
|
||||
else:
|
||||
return jsonify([payment._asdict() for payment in payments]), HTTPStatus.OK
|
||||
@@ -202,13 +203,8 @@ async def api_get_mempool():
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_get_mempool_address_balance(address):
|
||||
mempool = await get_mempool(g.wallet.user)
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
r = await client.get(
|
||||
mempool.endpoint + "/" + address,
|
||||
timeout=40,
|
||||
)
|
||||
print(r)
|
||||
except AssertionError:
|
||||
webhook = None
|
||||
return jsonify(mempool._asdict()), HTTPStatus.OK
|
||||
print(mempool.endpoint)
|
||||
r = requests.get(mempool.endpoint + "/api/address/" + address)
|
||||
balance = r.json()['chain_stats']['funded_txo_sum'] - r.json()['chain_stats']['spent_txo_sum']
|
||||
|
||||
return jsonify({"balance":balance}), HTTPStatus.OK
|
||||
Reference in New Issue
Block a user