refactor: move copyText and formatBalance into utils (#3584)

This commit is contained in:
dni ⚡
2025-11-27 12:23:42 +01:00
committed by GitHub
parent 9c257aa23d
commit e6ca8a33c6
9 changed files with 53 additions and 24 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+7
View File
@@ -95,6 +95,8 @@ window.i18n = new VueI18n.createI18n({
window.app.mixin({
data() {
return {
api: window._lnbitsApi,
utils: window._lnbitsUtils,
g: window.g,
utils: window._lnbitsUtils,
...WINDOW_SETTINGS
@@ -107,6 +109,11 @@ window.app.mixin({
const isVueRoute = matchedRoute?.matched?.length > 0
return isVueRoute
}
},
// backwards compatibility for extensions, should not be used in the future
methods: {
copyText: window._lnbitsUtils.copyText,
formatBalance: window._lnbitsUtils.formatBalance
}
})
+14
View File
@@ -1,4 +1,12 @@
window._lnbitsUtils = {
copyText(text, message, position) {
Quasar.copyToClipboard(text).then(() => {
Quasar.Notify.create({
message: message || 'Copied to clipboard!',
position: position || 'bottom'
})
})
},
confirmDialog(msg) {
return Quasar.Dialog.create({
message: msg,
@@ -52,6 +60,12 @@ window._lnbitsUtils = {
const timestampMs = new Date(isoDateString).getTime()
return moment.utc(timestampMs).local().fromNow()
},
formatBalance(amount, denomination = 'sats') {
if (denomination === 'sats') {
return LNbits.utils.formatSat(amount) + ' sats'
}
return LNbits.utils.formatCurrency(amount / 100, denomination)
},
formatCurrency(value, currency) {
return new Intl.NumberFormat(window.i18n.global.locale, {
style: 'currency',
-15
View File
@@ -60,21 +60,6 @@ window.windowMixin = {
}
})
},
formatBalance(amount) {
if (LNBITS_DENOMINATION != 'sats') {
return LNbits.utils.formatCurrency(amount / 100, LNBITS_DENOMINATION)
} else {
return LNbits.utils.formatSat(amount) + ' sats'
}
},
copyText(text, message, position) {
Quasar.copyToClipboard(text).then(() => {
Quasar.Notify.create({
message: message || 'Copied to clipboard!',
position: position || 'bottom'
})
})
},
refreshRoute() {
const path = window.location.pathname
console.log(path)