feat: mage block/allow accounts

This commit is contained in:
Vlad Stan 2023-02-16 14:17:21 +02:00
parent 2c5dfbbf92
commit 5a984bddcd
5 changed files with 188 additions and 58 deletions

View file

@ -526,33 +526,101 @@
</q-tab-panel>
<q-tab-panel name="accounts">
<div v-if="relay">
<q-card
><q-card-section>
<div class="row items-center no-wrap q-mb-md">
<div class="col-2 q-pr-lg">Public Key:</div>
<div class="col-6 q-pr-lg">
<q-input
filled
dense
v-model.trim="accountPubkey"
type="text"
></q-input>
</div>
<div class="col-2 q-pr-md">
<q-btn
unelevated
color="green"
class="float-right"
@click="allowPublicKey(accountPubkey, true)"
>Allow</q-btn
>
</div>
<div class="col-2">
<q-btn
unelevated
color="pink"
class="float-right"
@click="blockPublicKey(accountPubkey, true)"
>Block</q-btn
>
</div>
</div>
</q-card-section>
</q-card>
<q-separator></q-separator>
<div class="row items-center no-wrap q-mb-md">
<div class="col-2 q-pr-lg">Public Key:</div>
<div class="col-6 q-pr-lg">
<q-input
filled
<div class="col-3 q-pr-lg">Filter:</div>
<div class="col-9 q-pr-lg">
<q-toggle
size="sm"
color="secodary"
class="q-mr-lg"
v-model="showAllowedAccounts"
@input="getAccounts()"
>Show Allowed Account</q-toggle
>
<q-toggle
size="sm"
color="secodary"
class="q-mr-lg"
v-model="showBlockedAccounts"
@input="getAccounts()"
>
Show Blocked Accounts</q-toggle
>
</div>
</div>
<q-separator></q-separator>
<div class="row items-center no-wrap q-mb-md">
<div class="col-12 q-pr-lg">
<q-table
flat
dense
v-model.trim="accountPubkey"
type="text"
></q-input>
</div>
<div class="col-2 q-pr-md">
<q-btn
unelevated
color="green"
class="float-right"
@click="allowPublicKey(true)"
>Allow</q-btn
>
</div>
<div class="col-2">
<q-btn
unelevated
color="pink"
class="float-right"
@click="blockPublicKey(true)"
>Block</q-btn
:data="accounts"
row-key="pubkey"
:columns="accountsTable.columns"
:pagination.sync="accountsTable.pagination"
:filter="accountsFilter"
>
<template v-slot:body="props">
<q-tr :props="props">
<q-td key="pubkey" :props="props">
{{props.row.pubkey}}
</q-td>
<q-td key="allowed" :props="props">
<q-toggle
size="sm"
color="secodary"
v-model="props.row.allowed"
@input="togglePublicKey(props.row, 'allow')"
></q-toggle>
</q-td>
<q-td key="blocked" :props="props">
<q-toggle
size="sm"
color="secodary"
v-model="props.row.blocked"
@input="togglePublicKey(props.row, 'block')"
></q-toggle>
</q-td>
<q-td auto-width> {{props.row.paid_to_join}} </q-td>
<q-td auto-width> {{props.row.sats}} </q-td>
<q-td auto-width> {{props.row.storage}} </q-td>
</q-tr>
</template>
</q-table>
</div>
</div>
</div>

View file

@ -9,6 +9,7 @@ async function relayDetails(path) {
return {
tab: 'info',
relay: null,
accounts: [],
accountPubkey: '',
formDialogItem: {
show: false,
@ -17,6 +18,52 @@ async function relayDetails(path) {
description: ''
}
},
accountsFilter: '',
showBlockedAccounts: true,
showAllowedAccounts: false,
accountsTable: {
columns: [
{
name: 'pubkey',
align: 'left',
label: 'Public Key',
field: 'pubkey'
},
{
name: 'allowed',
align: 'left',
label: 'Allowed',
field: 'allowed'
},
{
name: 'blocked',
align: 'left',
label: 'Blocked',
field: 'blocked'
},
{
name: 'paid_to_join',
align: 'left',
label: 'Paid to join',
field: 'paid_to_join'
},
{
name: 'sats',
align: 'left',
label: 'Spent Sats',
field: 'sats'
},
{
name: 'storage',
align: 'left',
label: 'Storage',
field: 'storage'
}
],
pagination: {
rowsPerPage: 10
}
},
skipEventKind: 0,
forceEventKind: 0
}
@ -113,11 +160,39 @@ async function relayDetails(path) {
this.relay.config.wallet =
this.relay.config.wallet || this.walletOptions[0].value
},
allowPublicKey: async function (allowed) {
await this.updatePublicKey({allowed})
getAccounts: async function () {
try {
const {data} = await LNbits.api.request(
'GET',
`/nostrrelay/api/v1/account?relay_id=${this.relay.id}&allowed=${this.showAllowedAccounts}&blocked=${this.showBlockedAccounts}`,
this.inkey
)
this.accounts = data
console.log('### this.accounts', this.accounts)
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
blockPublicKey: async function (blocked = true) {
await this.updatePublicKey({blocked})
allowPublicKey: async function (pubkey, allowed) {
await this.updatePublicKey({pubkey, allowed})
},
blockPublicKey: async function (pubkey, blocked = true) {
await this.updatePublicKey({pubkey, blocked})
},
togglePublicKey: async function (account, action) {
if (action === 'allow') {
await this.updatePublicKey({
pubkey: account.pubkey,
allowed: account.allowed
})
}
if (action === 'block') {
await this.updatePublicKey({
pubkey: account.pubkey,
blocked: account.blocked
})
}
},
updatePublicKey: async function (ops) {
try {
@ -127,7 +202,7 @@ async function relayDetails(path) {
this.adminkey,
{
relay_id: this.relay.id,
pubkey: this.accountPubkey,
pubkey: ops.pubkey,
allowed: ops.allowed,
blocked: ops.blocked
}
@ -138,18 +213,11 @@ async function relayDetails(path) {
timeout: 5000
})
this.accountPubkey = ''
await this.getAccounts()
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
deleteAllowedPublicKey: function (pubKey) {
this.relay.config.allowedPublicKeys =
this.relay.config.allowedPublicKeys.filter(p => p !== pubKey)
},
deleteBlockedPublicKey: function (pubKey) {
this.relay.config.blockedPublicKeys =
this.relay.config.blockedPublicKeys.filter(p => p !== pubKey)
},
addSkipAuthForEvent: function () {
value = +this.skipEventKind
@ -179,6 +247,7 @@ async function relayDetails(path) {
created: async function () {
await this.getRelay()
await this.getAccounts()
}
})
}