refactor: extract wallet-config
This commit is contained in:
parent
46dfd337b2
commit
b18a4d37e3
7 changed files with 124 additions and 132 deletions
4
Makefile
4
Makefile
|
|
@ -7,7 +7,7 @@ format: prettier isort black
|
||||||
check: mypy checkprettier checkblack
|
check: mypy checkprettier checkblack
|
||||||
|
|
||||||
prettier: $(shell find lnbits -name "*.js" -name ".html")
|
prettier: $(shell find lnbits -name "*.js" -name ".html")
|
||||||
./node_modules/.bin/prettier --write lnbits/static/js/*.js lnbits/core/static/js/*.js lnbits/extensions/*/templates/*/*.html ./lnbits/core/templates/core/*.html lnbits/templates/*.html lnbits/extensions/*/static/js/*.js
|
./node_modules/.bin/prettier --write lnbits/static/js/*.js lnbits/core/static/js/*.js lnbits/extensions/*/templates/*/*.html ./lnbits/core/templates/core/*.html lnbits/templates/*.html lnbits/extensions/*/static/js/*.js lnbits/extensions/*/static/components/*/*.js
|
||||||
|
|
||||||
black: $(shell find lnbits -name "*.py")
|
black: $(shell find lnbits -name "*.py")
|
||||||
./venv/bin/black lnbits
|
./venv/bin/black lnbits
|
||||||
|
|
@ -21,7 +21,7 @@ isort: $(shell find lnbits -name "*.py")
|
||||||
./venv/bin/isort --profile black lnbits
|
./venv/bin/isort --profile black lnbits
|
||||||
|
|
||||||
checkprettier: $(shell find lnbits -name "*.js" -name ".html")
|
checkprettier: $(shell find lnbits -name "*.js" -name ".html")
|
||||||
./node_modules/.bin/prettier --check lnbits/static/js/*.js lnbits/core/static/js/*.js lnbits/extensions/*/templates/*/*.html ./lnbits/core/templates/core/*.html lnbits/templates/*.html lnbits/extensions/*/static/js/*.js
|
./node_modules/.bin/prettier --check lnbits/static/js/*.js lnbits/core/static/js/*.js lnbits/extensions/*/templates/*/*.html ./lnbits/core/templates/core/*.html lnbits/templates/*.html lnbits/extensions/*/static/js/*.js lnbits/extensions/*/static/components/*/*.js
|
||||||
|
|
||||||
checkblack: $(shell find lnbits -name "*.py")
|
checkblack: $(shell find lnbits -name "*.py")
|
||||||
./venv/bin/black --check lnbits
|
./venv/bin/black --check lnbits
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,9 @@ async function initMyCheckbox(path) {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
check() {
|
check() {
|
||||||
this.checked = !this.checked;
|
this.checked = !this.checked
|
||||||
console.log('### checked', this.checked)
|
console.log('### checked', this.checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
<div>
|
||||||
|
<q-card>
|
||||||
|
|
||||||
|
<div class="row items-center no-wrap q-mb-md">
|
||||||
|
<div class="col-11">
|
||||||
|
<div class="row justify-center q-gutter-x-md items-center">
|
||||||
|
<div class="text-h3 q-pa-sm">{{satBtc(total)}}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-1">
|
||||||
|
<q-btn unelevated @click="config.show = true" color="primary" icon="settings">
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-card>
|
||||||
|
|
||||||
|
<q-dialog v-model="config.show" position="top">
|
||||||
|
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
||||||
|
<q-form @submit="updateConfig" class="q-gutter-md">
|
||||||
|
<q-input filled dense v-model.trim="config.data.mempool_endpoint" type="text" label="Mempool Endpoint">
|
||||||
|
</q-input>
|
||||||
|
|
||||||
|
<q-input filled dense v-model.number="config.data.receive_gap_limit" type="number" min="0"
|
||||||
|
label="Receive Gap Limit"></q-input>
|
||||||
|
|
||||||
|
<q-input filled dense v-model.number="config.data.change_gap_limit" type="number" min="0"
|
||||||
|
label="Change Gap Limit"></q-input>
|
||||||
|
|
||||||
|
<q-toggle :label="config.data.sats_denominated ? 'sats denominated' : 'BTC denominated'"
|
||||||
|
color="secodary" v-model="config.data.sats_denominated"></q-toggle>
|
||||||
|
|
||||||
|
<div class="row q-mt-lg">
|
||||||
|
<q-btn unelevated color="primary" :disable="
|
||||||
|
!config.data.mempool_endpoint " type="submit">Update</q-btn>
|
||||||
|
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Cancel</q-btn>
|
||||||
|
</div>
|
||||||
|
</q-form>
|
||||||
|
</q-card>
|
||||||
|
</q-dialog>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
async function walletConfig(path) {
|
||||||
|
const t = await loadTemplateAsync(path)
|
||||||
|
Vue.component('wallet-config', {
|
||||||
|
name: 'wallet-config',
|
||||||
|
template: t,
|
||||||
|
|
||||||
|
props: ['total', 'config', 'adminkey'],
|
||||||
|
data: function () {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
satBtc(val, showUnit = true) {
|
||||||
|
return satOrBtc(val, showUnit, this.config.data.sats_denominated)
|
||||||
|
},
|
||||||
|
updateConfig: async function () {
|
||||||
|
// const wallet = this.g.user.wallets[0]
|
||||||
|
try {
|
||||||
|
await LNbits.api.request(
|
||||||
|
'PUT',
|
||||||
|
'/watchonly/api/v1/config',
|
||||||
|
this.adminkey,
|
||||||
|
this.config.data
|
||||||
|
)
|
||||||
|
this.config.show = false
|
||||||
|
} catch (error) {
|
||||||
|
LNbits.utils.notifyApiError(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getConfig: async function () {
|
||||||
|
try {
|
||||||
|
const {data} = await LNbits.api.request(
|
||||||
|
'GET',
|
||||||
|
'/watchonly/api/v1/config',
|
||||||
|
this.adminkey
|
||||||
|
)
|
||||||
|
this.config.data = data
|
||||||
|
} catch (error) {
|
||||||
|
LNbits.utils.notifyApiError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created: async function () {
|
||||||
|
await this.getConfig()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
const watchOnly = async () => {
|
const watchOnly = async () => {
|
||||||
Vue.component(VueQrcode.name, VueQrcode)
|
Vue.component(VueQrcode.name, VueQrcode)
|
||||||
await initMyCheckbox('static/components/my-checkbox/my-checkbox.html')
|
|
||||||
|
await walletConfig('static/components/wallet-config/wallet-config.html')
|
||||||
|
|
||||||
Vue.filter('reverse', function (value) {
|
Vue.filter('reverse', function (value) {
|
||||||
// slice to make a copy of array, then reverse the copy
|
// slice to make a copy of array, then reverse the copy
|
||||||
|
|
@ -10,9 +11,6 @@ const watchOnly = async () => {
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#vue',
|
el: '#vue',
|
||||||
mixins: [windowMixin],
|
mixins: [windowMixin],
|
||||||
mounted: function () {
|
|
||||||
console.log('### mounted')
|
|
||||||
},
|
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
DUST_LIMIT: 546,
|
DUST_LIMIT: 546,
|
||||||
|
|
@ -81,32 +79,6 @@ const watchOnly = async () => {
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
//################### CONFIG ###################
|
//################### CONFIG ###################
|
||||||
getConfig: async function () {
|
|
||||||
try {
|
|
||||||
const {data} = await LNbits.api.request(
|
|
||||||
'GET',
|
|
||||||
'/watchonly/api/v1/config',
|
|
||||||
this.g.user.wallets[0].adminkey
|
|
||||||
)
|
|
||||||
this.config.data = data
|
|
||||||
} catch (error) {
|
|
||||||
LNbits.utils.notifyApiError(error)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
updateConfig: async function () {
|
|
||||||
const wallet = this.g.user.wallets[0]
|
|
||||||
try {
|
|
||||||
await LNbits.api.request(
|
|
||||||
'PUT',
|
|
||||||
'/watchonly/api/v1/config',
|
|
||||||
wallet.adminkey,
|
|
||||||
this.config.data
|
|
||||||
)
|
|
||||||
this.config.show = false
|
|
||||||
} catch (error) {
|
|
||||||
LNbits.utils.notifyApiError(error)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
//################### WALLETS ###################
|
//################### WALLETS ###################
|
||||||
getWalletName: function (walletId) {
|
getWalletName: function (walletId) {
|
||||||
|
|
@ -1202,15 +1174,7 @@ const watchOnly = async () => {
|
||||||
},
|
},
|
||||||
|
|
||||||
satBtc(val, showUnit = true) {
|
satBtc(val, showUnit = true) {
|
||||||
const value = this.config.data.sats_denominated
|
return satOrBtc(val, showUnit, this.config.data.sats_denominated)
|
||||||
? LNbits.utils.formatSat(val)
|
|
||||||
: val == 0
|
|
||||||
? 0.0
|
|
||||||
: (val / 100000000).toFixed(8)
|
|
||||||
if (!showUnit) return value
|
|
||||||
return this.config.data.sats_denominated
|
|
||||||
? value + ' sat'
|
|
||||||
: value + ' BTC'
|
|
||||||
},
|
},
|
||||||
getAccountDescription: function (accountType) {
|
getAccountDescription: function (accountType) {
|
||||||
return getAccountDescription(accountType)
|
return getAccountDescription(accountType)
|
||||||
|
|
@ -1218,7 +1182,6 @@ const watchOnly = async () => {
|
||||||
},
|
},
|
||||||
created: async function () {
|
created: async function () {
|
||||||
if (this.g.user.wallets.length) {
|
if (this.g.user.wallets.length) {
|
||||||
await this.getConfig()
|
|
||||||
await this.refreshWalletAccounts()
|
await this.refreshWalletAccounts()
|
||||||
await this.refreshAddresses()
|
await this.refreshAddresses()
|
||||||
await this.scanAddressWithAmount()
|
await this.scanAddressWithAmount()
|
||||||
|
|
|
||||||
|
|
@ -140,10 +140,19 @@ const readFromSerialPort = serial => {
|
||||||
return readStringUntil
|
return readStringUntil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function satOrBtc(val, showUnit = true, showSats = false) {
|
||||||
|
const value = showSats
|
||||||
|
? LNbits.utils.formatSat(val)
|
||||||
|
: val == 0
|
||||||
|
? 0.0
|
||||||
|
: (val / 100000000).toFixed(8)
|
||||||
|
if (!showUnit) return value
|
||||||
|
return showSats ? value + ' sat' : value + ' BTC'
|
||||||
|
}
|
||||||
|
|
||||||
function loadTemplateAsync(path) {
|
function loadTemplateAsync(path) {
|
||||||
const result = new Promise(resolve => {
|
const result = new Promise(resolve => {
|
||||||
const xhttp = new XMLHttpRequest()
|
const xhttp = new XMLHttpRequest()
|
||||||
console.log('### 300')
|
|
||||||
|
|
||||||
xhttp.onreadystatechange = function () {
|
xhttp.onreadystatechange = function () {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
|
|
|
||||||
|
|
@ -2,25 +2,12 @@
|
||||||
%} {% block page %}
|
%} {% block page %}
|
||||||
<div class="row q-col-gutter-md">
|
<div class="row q-col-gutter-md">
|
||||||
<div class="col-12 col-md-7 q-gutter-y-md">
|
<div class="col-12 col-md-7 q-gutter-y-md">
|
||||||
<q-card>
|
<wallet-config
|
||||||
|
:total="utxos.total"
|
||||||
|
:config="config"
|
||||||
|
:adminkey="g.user.wallets[0].adminkey"
|
||||||
|
></wallet-config>
|
||||||
{% raw %}
|
{% raw %}
|
||||||
<div class="row items-center no-wrap q-mb-md">
|
|
||||||
<div class="col-11">
|
|
||||||
<div class="row justify-center q-gutter-x-md items-center">
|
|
||||||
<div class="text-h3 q-pa-sm">{{satBtc(utxos.total)}}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-1">
|
|
||||||
<q-btn
|
|
||||||
unelevated
|
|
||||||
@click="config.show = true"
|
|
||||||
color="primary"
|
|
||||||
icon="settings"
|
|
||||||
>
|
|
||||||
</q-btn>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</q-card>
|
|
||||||
|
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
|
|
@ -31,9 +18,7 @@
|
||||||
</q-btn>
|
</q-btn>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-auto q-pr-lg">
|
<div class="col-auto q-pr-lg"></div>
|
||||||
<my-checkbox></my-checkbox>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto q-pl-lg">
|
<div class="col-auto q-pl-lg">
|
||||||
<q-input
|
<q-input
|
||||||
borderless
|
borderless
|
||||||
|
|
@ -1455,57 +1440,6 @@
|
||||||
</q-form>
|
</q-form>
|
||||||
</q-card>
|
</q-card>
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
<q-dialog v-model="config.show" position="top">
|
|
||||||
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
|
||||||
<q-form @submit="updateConfig" class="q-gutter-md">
|
|
||||||
<q-input
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="config.data.mempool_endpoint"
|
|
||||||
type="text"
|
|
||||||
label="Mempool Endpoint"
|
|
||||||
></q-input>
|
|
||||||
|
|
||||||
<q-input
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.number="config.data.receive_gap_limit"
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
label="Receive Gap Limit"
|
|
||||||
></q-input>
|
|
||||||
|
|
||||||
<q-input
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.number="config.data.change_gap_limit"
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
label="Change Gap Limit"
|
|
||||||
></q-input>
|
|
||||||
|
|
||||||
<q-toggle
|
|
||||||
:label="config.data.sats_denominated ? 'sats denominated' : 'BTC denominated'"
|
|
||||||
color="secodary"
|
|
||||||
v-model="config.data.sats_denominated"
|
|
||||||
></q-toggle>
|
|
||||||
|
|
||||||
<div class="row q-mt-lg">
|
|
||||||
<q-btn
|
|
||||||
unelevated
|
|
||||||
color="primary"
|
|
||||||
:disable="
|
|
||||||
!config.data.mempool_endpoint "
|
|
||||||
type="submit"
|
|
||||||
>Update</q-btn
|
|
||||||
>
|
|
||||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
|
||||||
>Cancel</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</q-form>
|
|
||||||
</q-card>
|
|
||||||
</q-dialog>
|
|
||||||
|
|
||||||
<q-dialog v-model="addresses.show" position="top">
|
<q-dialog v-model="addresses.show" position="top">
|
||||||
<q-card v-if="addresses.data" class="q-pa-lg lnbits__dialog-card">
|
<q-card v-if="addresses.data" class="q-pa-lg lnbits__dialog-card">
|
||||||
|
|
@ -1713,5 +1647,6 @@
|
||||||
<script src="{{ url_for('watchonly_static', path='js/map.js') }}"></script>
|
<script src="{{ url_for('watchonly_static', path='js/map.js') }}"></script>
|
||||||
<script src="{{ url_for('watchonly_static', path='js/utils.js') }}"></script>
|
<script src="{{ url_for('watchonly_static', path='js/utils.js') }}"></script>
|
||||||
<script src="{{ url_for('watchonly_static', path='components/my-checkbox/my-checkbox.js') }}"></script>
|
<script src="{{ url_for('watchonly_static', path='components/my-checkbox/my-checkbox.js') }}"></script>
|
||||||
|
<script src="{{ url_for('watchonly_static', path='components/wallet-config/wallet-config.js') }}"></script>
|
||||||
<script src="{{ url_for('watchonly_static', path='js/index.js') }}"></script>
|
<script src="{{ url_for('watchonly_static', path='js/index.js') }}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue