fix: show wss & invoice generation
This commit is contained in:
parent
218b324347
commit
30ffcf7f55
2 changed files with 110 additions and 108 deletions
|
|
@ -11,10 +11,44 @@
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<h4 v-text="relay.name" class="q-my-none"></h4>
|
<h4 v-text="relay.name" class="q-my-none"></h4>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
<div v-if="relay.description" class="q-ma-lg">
|
||||||
|
<q-separator></q-separator>
|
||||||
|
<span class="text-subtitle1" v-text="relay.description"></span>
|
||||||
|
</div>
|
||||||
</q-card>
|
</q-card>
|
||||||
<q-card class="q-pb-xl">
|
<q-card class="q-pb-xl">
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2 q-pt-sm">
|
||||||
|
<span class="text-bold">Relay Link:</span>
|
||||||
|
</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<q-input
|
||||||
|
filled
|
||||||
|
dense
|
||||||
|
readonly
|
||||||
|
v-model.trim="wssLink"
|
||||||
|
type="text"
|
||||||
|
label="Relay Link"
|
||||||
|
></q-input>
|
||||||
|
</div>
|
||||||
|
<div class="col-2">
|
||||||
|
<q-btn
|
||||||
|
outline
|
||||||
|
color="grey"
|
||||||
|
class="float-right"
|
||||||
|
@click="copyText(wssLink)"
|
||||||
|
>Copy</q-btn
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section v-if="relay.config.isPaidRelay">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2 q-pt-sm">
|
||||||
<span class="text-bold">Public Key:</span>
|
<span class="text-bold">Public Key:</span>
|
||||||
|
</div>
|
||||||
|
<div class="col-8">
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
|
|
@ -22,17 +56,23 @@
|
||||||
type="text"
|
type="text"
|
||||||
label="User Public Key"
|
label="User Public Key"
|
||||||
></q-input>
|
></q-input>
|
||||||
|
</div>
|
||||||
|
<div class="col-2"></div>
|
||||||
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section v-if="relay.config.isPaidRelay">
|
<q-card-section v-if="relay.config.isPaidRelay">
|
||||||
<div class="row q-mb-md">
|
<div class="row">
|
||||||
<div class="col-2">
|
<div class="col-2">
|
||||||
<span class="text-bold">Cost to join: </span>
|
<span class="text-bold">Cost to join: </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
|
<div>
|
||||||
<span v-text="relay.config.costToJoin"></span>
|
<span v-text="relay.config.costToJoin"></span>
|
||||||
<span class="text-bold q-ml-sm">sats</span>
|
<span class="text-bold q-ml-sm">sats</span>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
|
<div v-if="relay.config.costToJoin">
|
||||||
<q-btn
|
<q-btn
|
||||||
@click="createInvoice('join')"
|
@click="createInvoice('join')"
|
||||||
unelevated
|
unelevated
|
||||||
|
|
@ -41,13 +81,20 @@
|
||||||
>Pay to Join</q-btn
|
>Pay to Join</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<q-badge color="green" class="float-right"
|
||||||
|
><span>Free to join</span>
|
||||||
|
</q-badge>
|
||||||
</div>
|
</div>
|
||||||
<q-separator></q-separator>
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section v-if="relay.config.isPaidRelay">
|
||||||
<div class="row q-mt-md q-mb-md">
|
<div class="row q-mt-md q-mb-md">
|
||||||
<div class="col-2">
|
<div class="col-2 q-pt-sm">
|
||||||
<span class="text-bold">Storage cost: </span>
|
<span class="text-bold">Storage cost: </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-3">
|
<div class="col-3 q-pt-sm">
|
||||||
<span v-text="relay.config.storageCostValue"></span>
|
<span v-text="relay.config.storageCostValue"></span>
|
||||||
<span class="text-bold q-ml-sm"> sats per</span>
|
<span class="text-bold q-ml-sm"> sats per</span>
|
||||||
<q-badge color="orange">
|
<q-badge color="orange">
|
||||||
|
|
@ -56,6 +103,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-2">
|
<div class="col-2">
|
||||||
<q-input
|
<q-input
|
||||||
|
v-if="relay.config.storageCostValue"
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
v-model="unitsToBuy"
|
v-model="unitsToBuy"
|
||||||
|
|
@ -64,11 +112,14 @@
|
||||||
:label="relay.config.storageCostUnit"
|
:label="relay.config.storageCostUnit"
|
||||||
></q-input>
|
></q-input>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-2">
|
<div class="col-2 q-pt-sm">
|
||||||
|
<div v-if="relay.config.storageCostValue">
|
||||||
<span class="text-bold q-ml-md" v-text="storageCost"></span>
|
<span class="text-bold q-ml-md" v-text="storageCost"></span>
|
||||||
<span>sats</span>
|
<span>sats</span>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
|
<div v-if="relay.config.storageCostValue">
|
||||||
<q-btn
|
<q-btn
|
||||||
@click="createInvoice('storage')"
|
@click="createInvoice('storage')"
|
||||||
unelevated
|
unelevated
|
||||||
|
|
@ -77,12 +128,20 @@
|
||||||
>Buy storage space</q-btn
|
>Buy storage space</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<q-badge color="green" class="float-right"
|
||||||
|
><span>Free storage</span>
|
||||||
|
</q-badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-separator></q-separator>
|
<q-separator></q-separator>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section v-else>
|
<q-card-section v-else>
|
||||||
<q-badge color="yellow" text-color="black">
|
<q-badge color="yellow" text-color="black">
|
||||||
This is a free relay
|
<h5 class="text-subtitle1 q-my-none">
|
||||||
|
This is a free Nostr Relay
|
||||||
|
</h5>
|
||||||
</q-badge>
|
</q-badge>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section v-if="invoice">
|
<q-card-section v-if="invoice">
|
||||||
|
|
@ -118,77 +177,6 @@
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-md-4 q-gutter-y-md q-pa-xl">
|
|
||||||
<q-card>
|
|
||||||
<q-card-section>
|
|
||||||
<q-expansion-item
|
|
||||||
group="extras"
|
|
||||||
icon="sensors"
|
|
||||||
label="Relay Specs"
|
|
||||||
:content-inset-level="0.5"
|
|
||||||
>
|
|
||||||
<q-separator class="q-mt-md"></q-separator>
|
|
||||||
<span v-text="relay.description"></span>
|
|
||||||
<q-separator class="q-mb-md"></q-separator>
|
|
||||||
<q-expansion-item
|
|
||||||
group="api"
|
|
||||||
dense
|
|
||||||
expand-separator
|
|
||||||
label="Payment Spec"
|
|
||||||
>
|
|
||||||
<q-card>
|
|
||||||
<q-card-section>
|
|
||||||
<code
|
|
||||||
><span class="text-blue">GET</span>
|
|
||||||
/lnurlp/api/v1/links</code
|
|
||||||
>
|
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
|
||||||
<code>{"X-Api-Key": <invoice_key>}</code><br />
|
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">
|
|
||||||
Body (application/json)
|
|
||||||
</h5>
|
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">
|
|
||||||
Returns 200 OK (application/json)
|
|
||||||
</h5>
|
|
||||||
<code>[<pay_link_object>, ...]</code>
|
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
|
||||||
</q-card-section>
|
|
||||||
</q-card>
|
|
||||||
</q-expansion-item>
|
|
||||||
<q-expansion-item
|
|
||||||
group="api"
|
|
||||||
dense
|
|
||||||
expand-separator
|
|
||||||
label="Events Spec"
|
|
||||||
>
|
|
||||||
<q-card>
|
|
||||||
<q-card-section> </q-card-section>
|
|
||||||
</q-card>
|
|
||||||
</q-expansion-item>
|
|
||||||
<q-expansion-item
|
|
||||||
group="api"
|
|
||||||
dense
|
|
||||||
expand-separator
|
|
||||||
label="Filters Spec"
|
|
||||||
>
|
|
||||||
<q-card>
|
|
||||||
<q-card-section> </q-card-section>
|
|
||||||
</q-card>
|
|
||||||
</q-expansion-item>
|
|
||||||
<q-expansion-item
|
|
||||||
group="api"
|
|
||||||
dense
|
|
||||||
expand-separator
|
|
||||||
label="Storage Spec"
|
|
||||||
>
|
|
||||||
<q-card>
|
|
||||||
<q-card-section> </q-card-section>
|
|
||||||
</q-card>
|
|
||||||
</q-expansion-item>
|
|
||||||
</q-expansion-item>
|
|
||||||
</q-card-section>
|
|
||||||
</q-card>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</q-page>
|
</q-page>
|
||||||
</q-page-container>
|
</q-page-container>
|
||||||
|
|
@ -211,11 +199,20 @@
|
||||||
storageCost: function () {
|
storageCost: function () {
|
||||||
if (!this.relay || !this.relay.config.storageCostValue) return 0
|
if (!this.relay || !this.relay.config.storageCostValue) return 0
|
||||||
return this.unitsToBuy * this.relay.config.storageCostValue
|
return this.unitsToBuy * this.relay.config.storageCostValue
|
||||||
|
},
|
||||||
|
wssLink: function () {
|
||||||
|
this.relay.config.domain =
|
||||||
|
this.relay.config.domain || window.location.hostname
|
||||||
|
return (
|
||||||
|
'wss://' + this.relay.config.domain + '/nostrrelay/' + this.relay.id
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createInvoice: async function (action) {
|
createInvoice: async function (action) {
|
||||||
|
console.log('### action', action)
|
||||||
if (!action) return
|
if (!action) return
|
||||||
|
this.invoice = ''
|
||||||
if (!this.pubkey) {
|
if (!this.pubkey) {
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
|
|
|
||||||
15
views_api.py
15
views_api.py
|
|
@ -283,11 +283,13 @@ async def api_pay_to_join(data: BuyOrder):
|
||||||
detail="Relay not found",
|
detail="Relay not found",
|
||||||
)
|
)
|
||||||
|
|
||||||
if data.action == "join" and relay.is_free_to_join:
|
amount = 0
|
||||||
raise ValueError("Relay is free to join")
|
|
||||||
|
|
||||||
storage_to_buy = 0
|
storage_to_buy = 0
|
||||||
if data.action == "storage":
|
if data.action == "join":
|
||||||
|
if relay.is_free_to_join:
|
||||||
|
raise ValueError("Relay is free to join")
|
||||||
|
amount = int(relay.config.cost_to_join)
|
||||||
|
elif data.action == "storage":
|
||||||
if relay.config.storage_cost_value == 0:
|
if relay.config.storage_cost_value == 0:
|
||||||
raise ValueError("Relay storage cost is zero. Cannot buy!")
|
raise ValueError("Relay storage cost is zero. Cannot buy!")
|
||||||
if data.units_to_buy == 0:
|
if data.units_to_buy == 0:
|
||||||
|
|
@ -295,10 +297,13 @@ async def api_pay_to_join(data: BuyOrder):
|
||||||
storage_to_buy = data.units_to_buy * relay.config.storage_cost_value * 1024
|
storage_to_buy = data.units_to_buy * relay.config.storage_cost_value * 1024
|
||||||
if relay.config.storage_cost_unit == "MB":
|
if relay.config.storage_cost_unit == "MB":
|
||||||
storage_to_buy *= 1024
|
storage_to_buy *= 1024
|
||||||
|
amount = data.units_to_buy * relay.config.storage_cost_value
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unknown action: '{data.action}'")
|
||||||
|
|
||||||
_, payment_request = await create_invoice(
|
_, payment_request = await create_invoice(
|
||||||
wallet_id=relay.config.wallet,
|
wallet_id=relay.config.wallet,
|
||||||
amount=int(relay.config.cost_to_join),
|
amount=amount,
|
||||||
memo=f"Pubkey '{data.pubkey}' wants to join {relay.id}",
|
memo=f"Pubkey '{data.pubkey}' wants to join {relay.id}",
|
||||||
extra={
|
extra={
|
||||||
"tag": "nostrrely",
|
"tag": "nostrrely",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue