mirror of
https://github.com/lnbits/lnbits.git
synced 2025-04-22 14:34:27 +02:00
allow wallet rename issue #141
This commit is contained in:
parent
16f8071731
commit
b3856d5aff
@ -112,6 +112,18 @@ async def create_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(
|
||||
*, user_id: str, wallet_id: str, conn: Optional[Connection] = None
|
||||
@ -390,7 +402,7 @@ async def check_internal(
|
||||
row = await (conn or db).fetchone(
|
||||
"""
|
||||
SELECT checking_id FROM apipayments
|
||||
WHERE hash = ? AND pending AND amount > 0
|
||||
WHERE hash = ? AND pending AND amount > 0
|
||||
""",
|
||||
(payment_hash,),
|
||||
)
|
||||
|
@ -184,7 +184,8 @@ new Vue({
|
||||
show: false,
|
||||
location: window.location
|
||||
},
|
||||
balance: 0
|
||||
balance: 0,
|
||||
newName: ''
|
||||
}
|
||||
},
|
||||
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) {
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete this wallet?')
|
||||
|
@ -277,6 +277,28 @@
|
||||
</q-card>
|
||||
</q-expansion-item>
|
||||
<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
|
||||
group="extras"
|
||||
icon="remove_circle"
|
||||
|
@ -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 .. 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 (
|
||||
PaymentFailure,
|
||||
InvoiceFailure,
|
||||
@ -38,6 +38,22 @@ async def api_wallet():
|
||||
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"])
|
||||
@api_check_wallet_key("invoice")
|
||||
|
Loading…
x
Reference in New Issue
Block a user