From 02946c1d1c0a8c5cd2298a14fbf6a0f009d74dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Tue, 13 Dec 2022 10:17:40 +0100 Subject: [PATCH] remove old topup route using new one, change wallet.js handling of that url --- lnbits/core/static/js/wallet.js | 43 ++++++++++++++++++--------------- lnbits/core/views/api.py | 25 ------------------- 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/lnbits/core/static/js/wallet.js b/lnbits/core/static/js/wallet.js index 668013135..d145e8a26 100644 --- a/lnbits/core/static/js/wallet.js +++ b/lnbits/core/static/js/wallet.js @@ -259,26 +259,31 @@ new Vue({ this.parse.camera.show = false }, updateBalance: function (credit) { - if (LNBITS_DENOMINATION != 'sats') { - credit = credit * 100 - } - LNbits.api - .request('PUT', '/api/v1/wallet/balance/' + credit, this.g.wallet.inkey) - .catch(err => { - LNbits.utils.notifyApiError(err) - }) - .then(response => { - let data = response.data - if (data.status === 'ERROR') { + LNbits.api + .request( + 'PUT', + '/admin/api/v1/topup/?usr=' + this.g.user.id, + this.g.user.wallets[0].adminkey, + { + amount: credit, + id: this.g.user.wallets[0].id + } + ) + .then(response => { this.$q.notify({ - timeout: 5000, - type: 'warning', - message: `Failed to update.` - }) - return - } - this.balance = this.balance + data.balance - }) + type: 'positive', + message: + 'Success! Added ' + + credit + + ' sats to ' + + this.g.user.wallets[0].id, + icon: null + }); + this.balance += parseInt(credit); + }) + .catch(function (error) { + LNbits.utils.notifyApiError(error) + }); }, closeReceiveDialog: function () { setTimeout(() => { diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 8d66a2285..add0785de 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -83,31 +83,6 @@ async def api_wallet(wallet: WalletTypeInfo = Depends(get_key_type)): return {"name": wallet.wallet.name, "balance": wallet.wallet.balance_msat} -@core_app.put("/api/v1/wallet/balance/{amount}", dependencies=[Depends(check_admin)]) -async def api_update_balance( - amount: int, wallet: WalletTypeInfo = Depends(get_key_type) -): - - payHash = urlsafe_short_hash() - await create_payment( - wallet_id=wallet.wallet.id, - checking_id=payHash, - payment_request="selfPay", - payment_hash=payHash, - amount=amount * 1000, - memo="selfPay", - fee=0, - ) - await update_payment_status(checking_id=payHash, pending=False) - updatedWallet = await get_wallet(wallet.wallet.id) - - return { - "id": wallet.wallet.id, - "name": wallet.wallet.name, - "balance": amount, - } - - @core_app.put("/api/v1/wallet/{new_name}") async def api_update_wallet( new_name: str, wallet: WalletTypeInfo = Depends(require_admin_key)