add funding sources options

This commit is contained in:
Tiago vasconcelos 2022-10-12 19:04:46 +01:00 committed by dni ⚡
parent 001f6589bb
commit 1cc54ff4b7
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): def signal_handler(signal, frame):
logger.debug(f"SIGINT received, terminating LNbits.") logger.debug(f"SIGINT received, terminating LNbits.")
sys.exit(1) sys.exit(1)
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
WALLET = get_wallet_class() WALLET = get_wallet_class()

View file

@ -24,3 +24,34 @@ class UpdateSettings(BaseModel):
lnbits_theme: str = Query(None) lnbits_theme: str = Query(None)
lnbits_custom_logo: str = Query(None) lnbits_custom_logo: str = Query(None)
lnbits_ad_space: List[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> <p>Funding Source Info</p>
<ul> <ul>
{%raw%} {%raw%}
<li> <li>Funding Source: {{settings.lnbits_backend_wallet_class}}</li>
Funding Source: {{settings.lnbits_backend_wallet_class}}
</li>
<li>Balance: {{balance / 1000}} sats</li> <li>Balance: {{balance / 1000}} sats</li>
{%endraw%} {%endraw%}
</ul> </ul>
@ -60,21 +58,30 @@
<br /> <br />
</div> </div>
</div> </div>
<p>Funding Sources</p> <p>Funding Sources<small> (Requires server restart)</small></p>
<q-list <q-list
v-for="(fund, idx) in settings.lnbits_allowed_funding_sources" v-for="(fund, idx) in settings.lnbits_allowed_funding_sources"
:key="idx" :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>
<q-card-section> <q-card-section
<!-- TODO A BUNCH OF V-IFS --> v-for="([key, prop], i) in Object.entries(funding_sources.get(fund))"
:key="i"
>
<q-input <q-input
dense
filled filled
type="text" type="text"
v-model="formData.lnbits_backend_wallet_class" v-model="formData[key]"
label="Wallet class" :label="prop.label"
class="q-pr-md" class="q-pr-md"
:hint="prop.hint"
></q-input> ></q-input>
</q-card-section> </q-card-section>
</q-card> </q-card>

View file

@ -3,7 +3,13 @@
<div class="row q-col-gutter-md justify-center"> <div class="row q-col-gutter-md justify-center">
<div class="col q-gutter-y-md q-my-md"> <div class="col q-gutter-y-md q-my-md">
<q-btn label="Save" color="primary" @click="updateSettings"> <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>
<q-btn <q-btn
label="Restart server" label="Restart server"
@ -114,19 +120,195 @@
topUpDialog: { topUpDialog: {
show: false 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 () { created: function () {
this.settings = JSON.parse('{{ settings|tojson|safe }}') //DB data this.settings = JSON.parse('{{ settings|tojson|safe }}') //DB data
this.balance = +'{{ balance|safe }}' this.balance = +'{{ balance|safe }}'
this.formData = _.clone(this.settings) //model this.formData = _.clone(this.settings) //model
console.log(_.isEqual(this.settings, this.formData)) this.updateFundingData()
console.log(this.settings)
}, },
computed: { computed: {
checkChanges(){ checkChanges() {
return !_.isEqual(this.settings, this.formData) return !_.isEqual(this.settings, this.formData)
} },
}, },
methods: { methods: {
addAdminUser() { addAdminUser() {
@ -140,9 +322,7 @@
}, },
removeAdminUser(user) { removeAdminUser(user) {
let admin_users = this.settings.lnbits_admin_users let admin_users = this.settings.lnbits_admin_users
this.settings.lnbits_admin_users = admin_users.filter( this.settings.lnbits_admin_users = admin_users.filter(u => u !== user)
u => u !== user
)
}, },
addAllowedUser() { addAllowedUser() {
let addUser = this.formData.allowed_users_add let addUser = this.formData.allowed_users_add
@ -155,7 +335,9 @@
}, },
removeAllowedUser(user) { removeAllowedUser(user) {
let allowed_users = this.settings.lnbits_allowed_users 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() { addAdSpace() {
let adSpace = this.formData.ad_space_add let adSpace = this.formData.ad_space_add
@ -208,6 +390,17 @@
LNbits.utils.notifyApiError(error) 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() { updateSettings() {
let data = { let data = {
...this.formData ...this.formData
@ -222,11 +415,13 @@
.then(response => { .then(response => {
this.settings = response.data.settings this.settings = response.data.settings
this.formData = _.clone(this.settings) this.formData = _.clone(this.settings)
this.updateFundingData()
this.$q.notify({ this.$q.notify({
type: 'positive', type: 'positive',
message: 'Success! Settings changed!', message: 'Success! Settings changed!',
icon: null icon: null
}) })
console.log(this.settings)
}) })
.catch(function (error) { .catch(function (error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
@ -262,7 +457,7 @@
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
} }
}, }
}) })
</script> </script>
{% endblock %} {% endblock %}