allow wallet rename issue #141

This commit is contained in:
Tiago vasconcelos
2021-08-06 11:15:07 +01:00
committed by fiatjaf
parent 16f8071731
commit b3856d5aff
4 changed files with 76 additions and 3 deletions

View File

@@ -112,6 +112,18 @@ async def create_wallet(
return new_wallet return new_wallet
async def update_wallet(
wallet_id: str, new_name: str, conn: Optional[Connection] = None
) -> Optional[Wallet]:
await (conn or db).execute(
"""
UPDATE wallets SET
name = ?
WHERE id = ?
""",
(new_name, wallet_id)
)
async def delete_wallet( async def delete_wallet(
*, user_id: str, wallet_id: str, conn: Optional[Connection] = None *, user_id: str, wallet_id: str, conn: Optional[Connection] = None
@@ -390,7 +402,7 @@ async def check_internal(
row = await (conn or db).fetchone( row = await (conn or db).fetchone(
""" """
SELECT checking_id FROM apipayments SELECT checking_id FROM apipayments
WHERE hash = ? AND pending AND amount > 0 WHERE hash = ? AND pending AND amount > 0
""", """,
(payment_hash,), (payment_hash,),
) )

View File

@@ -184,7 +184,8 @@ new Vue({
show: false, show: false,
location: window.location location: window.location
}, },
balance: 0 balance: 0,
newName: ''
} }
}, },
computed: { computed: {
@@ -583,6 +584,28 @@ new Vue({
} }
}) })
}, },
updateWalletName: function(){
let newName = this.newName
if(!newName || !newName.length) return
// let data = {name: newName}
LNbits.api
.request(
'PUT',
'/api/v1/wallet/' + newName,
this.g.wallet.inkey,
{}
).then(res => {
this.newName = ''
this.$q.notify({
message: `Wallet named updated.`,
type: 'positive',
timeout: 3500
})
}).catch(err => {
this.newName = ''
LNbits.utils.notifyApiError(err)
})
},
deleteWallet: function (walletId, user) { deleteWallet: function (walletId, user) {
LNbits.utils LNbits.utils
.confirmDialog('Are you sure you want to delete this wallet?') .confirmDialog('Are you sure you want to delete this wallet?')

View File

@@ -277,6 +277,28 @@
</q-card> </q-card>
</q-expansion-item> </q-expansion-item>
<q-separator></q-separator> <q-separator></q-separator>
<q-expansion-item
group="extras"
icon="edit"
label="Rename wallet"
>
<q-card>
<q-card-section>
<div class="" style="max-width: 320px">
<q-input filled v-model.trim="newName" label="Label" dense="dense" @update:model-value="(e) => console.log(e)"/>
</div>
<q-btn
:disable="!newName.length"
unelevated
class="q-mt-sm"
color="primary"
@click="updateWalletName()"
>Update name</q-btn
>
</q-card-section>
</q-card>
</q-expansion-item>
<q-separator></q-separator>
<q-expansion-item <q-expansion-item
group="extras" group="extras"
icon="remove_circle" icon="remove_circle"

View File

@@ -13,7 +13,7 @@ from lnbits.decorators import api_check_wallet_key, api_validate_post_request
from lnbits.utils.exchange_rates import currencies, fiat_amount_as_satoshis from lnbits.utils.exchange_rates import currencies, fiat_amount_as_satoshis
from .. import core_app, db from .. import core_app, db
from ..crud import get_payments, save_balance_check from ..crud import get_payments, save_balance_check, update_wallet
from ..services import ( from ..services import (
PaymentFailure, PaymentFailure,
InvoiceFailure, InvoiceFailure,
@@ -38,6 +38,22 @@ async def api_wallet():
HTTPStatus.OK, HTTPStatus.OK,
) )
@core_app.route("/api/v1/wallet/<new_name>", methods=["PUT"])
@api_check_wallet_key("invoice")
async def api_update_wallet(new_name):
print("UPDATE", g.wallet.id, new_name)
await update_wallet(g.wallet.id, new_name)
return (
jsonify(
{
"id": g.wallet.id,
"name": g.wallet.name,
"balance": g.wallet.balance_msat,
}
),
HTTPStatus.OK,
)
@core_app.route("/api/v1/payments", methods=["GET"]) @core_app.route("/api/v1/payments", methods=["GET"])
@api_check_wallet_key("invoice") @api_check_wallet_key("invoice")