Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exchange rate uses core api endpoint #115

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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