add funding sources options

This commit is contained in:
Tiago vasconcelos 2022-10-12 19:04:46 +01:00
parent a3b05e26b7
commit 9a48b174c6
4 changed files with 259 additions and 25 deletions

View file

@ -84,6 +84,7 @@ async def check_funding_source() -> None:
def signal_handler(signal, frame):
logger.debug(f"SIGINT received, terminating LNbits.")
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
WALLET = get_wallet_class()

View file

@ -24,3 +24,34 @@ class UpdateSettings(BaseModel):
lnbits_theme: str = Query(None)
lnbits_custom_logo: str = Query(None)
lnbits_ad_space: List[str] = Query(None)
# funding sources
fake_wallet_secret: str = Query(None)
lnbits_endpoint: str = Query(None)
lnbits_key: str = Query(None)
cliche_endpoint: str = Query(None)
corelightning_rpc: str = Query(None)
eclair_url: str = Query(None)
eclair_pass: str = Query(None)
lnd_rest_endpoint: str = Query(None)
lnd_rest_cert: str = Query(None)
lnd_rest_macaroon: str = Query(None)
lnd_rest_macaroon_encrypted: str = Query(None)
lnd_cert: str = Query(None)
lnd_admin_macaroon: str = Query(None)
lnd_invoice_macaroon: str = Query(None)
lnd_grpc_endpoint: str = Query(None)
lnd_grpc_cert: str = Query(None)
lnd_grpc_port: int = Query(None, ge=0)
lnd_grpc_admin_macaroon: str = Query(None)
lnd_grpc_invoice_macaroon: str = Query(None)
lnd_grpc_macaroon_encrypted: str = Query(None)
lnpay_api_endpoint: str = Query(None)
lnpay_api_key: str = Query(None)
lnpay_wallet_key: str = Query(None)
lntxbot_api_endpoint: str = Query(None)
lntxbot_key: str = Query(None)
opennode_api_endpoint: str = Query(None)
opennode_key: str = Query(None)
spark_url: str = Query(None)
spark_token: str = Query(None)

View file

@ -8,9 +8,7 @@
<p>Funding Source Info</p>
<ul>
{%raw%}
<li>
Funding Source: {{settings.lnbits_backend_wallet_class}}
</li>
<li>Funding Source: {{settings.lnbits_backend_wallet_class}}</li>
<li>Balance: {{balance / 1000}} sats</li>
{%endraw%}
</ul>
@ -60,21 +58,30 @@
<br />
</div>
</div>
<p>Funding Sources</p>
<p>Funding Sources<small> (Requires server restart)</small></p>
<q-list
v-for="(fund, idx) in settings.lnbits_allowed_funding_sources"
:key="idx"
>
<q-expansion-item expand-separator icon="payments" :label="fund">
<q-expansion-item
expand-separator
icon="payments"
:label="fund"
v-if="funding_sources.get(fund)"
>
<q-card>
<q-card-section>
<!-- TODO A BUNCH OF V-IFS -->
<q-card-section
v-for="([key, prop], i) in Object.entries(funding_sources.get(fund))"
:key="i"
>
<q-input
dense
filled
type="text"
v-model="formData.lnbits_backend_wallet_class"
label="Wallet class"
v-model="formData[key]"
:label="prop.label"
class="q-pr-md"
:hint="prop.hint"
></q-input>
</q-card-section>
</q-card>

View file

@ -3,7 +3,13 @@
<div class="row q-col-gutter-md justify-center">
<div class="col q-gutter-y-md q-my-md">
<q-btn label="Save" color="primary" @click="updateSettings">
<q-badge v-if="checkChanges" color="red" rounded floating style="padding: 6px; border-radius: 6px"/>
<q-badge
v-if="checkChanges"
color="red"
rounded
floating
style="padding: 6px; border-radius: 6px"
/>
</q-btn>
<q-btn
label="Restart server"
@ -114,19 +120,195 @@
topUpDialog: {
show: false
},
tab: 'funding'
tab: 'funding',
funding_sources: new Map([
['VoidWallet', null],
[
'FakeWallet',
{
fake_wallet_secret: {
value: null,
label: 'Secret'
}
}
],
[
'CLightningWallet',
{
corelightning_rpc: {
value: null,
label: 'Endpoint'
}
}
],
[
'LndRestWallet',
{
lnd_rest_endpoint: {
value: null,
label: 'Endpoint'
},
lnd_rest_cert: {
value: null,
label: 'Certificate'
},
lnd_rest_macaroon: {
value: null,
label: 'Macaroon'
},
lnd_rest_macaroon_encrypted: {
value: null,
label: 'Encrypted Macaroon'
},
lnd_cert: {
value: null,
label: 'Certificate'
},
lnd_admin_macaroon: {
value: null,
label: 'Admin Macaroon'
},
lnd_invoice_macaroon: {
value: null,
label: 'Invoice Macaroon'
}
}
],
[
'LndWallet',
{
lnd_grpc_endpoint: {
value: null,
label: 'Endpoint'
},
lnd_grpc_cert: {
value: null,
label: 'Certificate'
},
lnd_grpc_port: {
value: null,
label: 'Port'
},
lnd_grpc_admin_macaroon: {
value: null,
label: 'Admin Macaroon'
},
lnd_grpc_invoice_macaroon: {
value: null,
label: 'Invoice Macaroon'
},
lnd_grpc_macaroon_encrypted: {
value: null,
label: 'Encrypted Macaroon'
}
}
],
[
'LntxbotWallet',
{
lntxbot_api_endpoint: {
value: null,
label: 'Endpoint'
},
lntxbot_key: {
value: null,
label: 'Key'
}
}
],
[
'LNPayWallet',
{
lnpay_api_endpoint: {
value: null,
label: 'Endpoint'
},
lnpay_api_key: {
value: null,
label: 'API Key'
},
lnpay_wallet_key: {
value: null,
label: 'Wallet Key'
}
}
],
[
'EclairWallet',
{
eclair_url: {
value: null,
label: 'Endpoint'
},
eclair_pass: {
value: null,
label: 'Password'
}
}
],
[
'LnbitsWallet',
{
lnbits_endpoint: {
value: null,
label: 'Endpoint'
},
lnbits_key: {
value: null,
label: 'Admin Key'
}
}
],
[
'OpenNodeWallet',
{
opennode_api_endpoint: {
value: null,
label: 'Endpoint'
},
opennode_key: {
value: null,
label: 'Key'
}
}
],
[
'ClicheWallet',
{
cliche_endpoint: {
value: null,
label: 'Endpoint'
}
}
],
[
'SparkWallet',
{
spark_url: {
value: null,
label: 'Endpoint'
},
spark_token: {
value: null,
label: 'Token'
}
}
]
])
}
},
created: function () {
this.settings = JSON.parse('{{ settings|tojson|safe }}') //DB data
this.balance = +'{{ balance|safe }}'
this.formData = _.clone(this.settings) //model
console.log(_.isEqual(this.settings, this.formData))
this.updateFundingData()
console.log(this.settings)
},
computed: {
checkChanges(){
checkChanges() {
return !_.isEqual(this.settings, this.formData)
}
},
},
methods: {
addAdminUser() {
@ -140,9 +322,7 @@
},
removeAdminUser(user) {
let admin_users = this.settings.lnbits_admin_users
this.settings.lnbits_admin_users = admin_users.filter(
u => u !== user
)
this.settings.lnbits_admin_users = admin_users.filter(u => u !== user)
},
addAllowedUser() {
let addUser = this.formData.allowed_users_add
@ -155,7 +335,9 @@
},
removeAllowedUser(user) {
let allowed_users = this.settings.lnbits_allowed_users
this.settings.lnbits_allowed_users = allowed_users.filter(u => u !== user)
this.settings.lnbits_allowed_users = allowed_users.filter(
u => u !== user
)
},
addAdSpace() {
let adSpace = this.formData.ad_space_add
@ -208,6 +390,17 @@
LNbits.utils.notifyApiError(error)
})
},
updateFundingData(){
this.settings.lnbits_allowed_funding_sources.map(f => {
let opts = this.funding_sources.get(f)
if (!opts) return
Object.keys(opts).forEach(e => {
opts[e].value = this.settings[e]
})
})
console.log("funding", this.funding_sources)
},
updateSettings() {
let data = {
...this.formData
@ -222,11 +415,13 @@
.then(response => {
this.settings = response.data.settings
this.formData = _.clone(this.settings)
this.updateFundingData()
this.$q.notify({
type: 'positive',
message: 'Success! Settings changed!',
icon: null
})
console.log(this.settings)
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
@ -262,7 +457,7 @@
LNbits.utils.notifyApiError(error)
})
}
},
}
})
</script>
{% endblock %}