Skip to content

Commit

Permalink
fix: exchange rate uses core api endpoint (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
talvasconcelos authored Dec 19, 2024
1 parent f8648fd commit 87e9528
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
21 changes: 10 additions & 11 deletions static/js/tpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,42 +103,42 @@ window.app = Vue.createApp({
}
},
computed: {
amount: function () {
amount() {
if (!this.stack.length) return 0.0
if (this.currency == 'sats') return Number(this.stack.join(''))
return (
this.stack.reduce((acc, dig) => acc * 10 + dig, 0) *
(this.currency == 'sats' ? 1 : 0.01)
)
},
amountFormatted: function () {
amountFormatted() {
return this.formatAmount(this.amount, this.currency)
},
totalFormatted() {
return this.formatAmount(this.total, this.currency)
},
amountWithTipFormatted: function () {
amountWithTipFormatted() {
return this.formatAmount(this.amount + this.tipAmount, this.currency)
},
sat: function () {
sat() {
if (!this.exchangeRate) return 0
return Math.ceil(this.amount * this.exchangeRate)
},
totalSat: function () {
totalSat() {
if (!this.exchangeRate) return 0
return Math.ceil(this.total * this.exchangeRate)
},
tipAmountSat: function () {
tipAmountSat() {
if (!this.exchangeRate) return 0
return Math.ceil(this.tipAmount * this.exchangeRate)
},
tipAmountFormatted: function () {
tipAmountFormatted() {
return LNbits.utils.formatSat(this.tipAmountSat)
},
fsat: function () {
fsat() {
return LNbits.utils.formatSat(this.sat)
},
totalfsat: function () {
totalfsat() {
return LNbits.utils.formatSat(this.totalSat)
},
roundToSugestion() {
Expand Down Expand Up @@ -656,10 +656,9 @@ window.app = Vue.createApp({
Quasar.Loading.hide()
} else {
LNbits.api
.request('GET', `/tpos/api/v1/rate/${this.currency}`)
.request('GET', `/api/v1/rate/${this.currency}`)
.then(response => {
this.exchangeRate = response.data.rate
console.log(this.exchangeRate)
Quasar.Loading.hide()
})
.catch(e => console.error(e))
Expand Down
12 changes: 0 additions & 12 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
require_admin_key,
require_invoice_key,
)
from lnbits.utils.exchange_rates import get_fiat_rate_satoshis
from lnurl import decode as decode_lnurl

from .crud import (
Expand Down Expand Up @@ -104,7 +103,6 @@ async def api_tpos_delete(
"/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED
)
async def api_tpos_create_invoice(tpos_id: str, data: CreateTposInvoice) -> dict:

tpos = await get_tpos(tpos_id)

if not tpos:
Expand Down Expand Up @@ -337,16 +335,6 @@ async def api_tpos_create_withdraw(
return {**lnurlcharge.dict(), **{"lnurl": lnurlcharge.lnurl(request)}}


@tpos_api_router.get("/api/v1/rate/{currency}", status_code=HTTPStatus.OK)
async def api_check_fiat_rate(currency):
try:
rate = await get_fiat_rate_satoshis(currency)
except AssertionError:
rate = None

return {"rate": rate}


@tpos_api_router.put("/api/v1/tposs/{tpos_id}/items", status_code=HTTPStatus.CREATED)
async def api_tpos_create_items(
data: CreateUpdateItemData,
Expand Down

0 comments on commit 87e9528

Please sign in to comment.