Skip to content

Commit

Permalink
atm premium fix (#59)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavol Rusnak <[email protected]>
  • Loading branch information
talvasconcelos and prusnak authored Dec 16, 2023
1 parent 90cc230 commit 891ad1c
Showing 1 changed file with 38 additions and 33 deletions.
71 changes: 38 additions & 33 deletions templates/tpos/tpos.html
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,16 @@ <h5 class="q-mt-none q-mb-sm">${totalfsat}<small> sat</small></h5>
fab
icon="shopping_bag"
color="primary"
><q-badge color="red" floating>${[...this.cart.values()].reduce((a,i)=>a+i.quantity,0)}</q-badge></q-btn
><q-badge color="red" floating
>${[...this.cart.values()].reduce((a,i)=>a+i.quantity,0)}</q-badge
></q-btn
></q-page-sticky
>
</template>
<q-btn
v-show="atmMode"
color="negative"
@click="atmMode = false"
@click="() => {atmMode = false; getRates()}"
class="absolute-top-left"
>EXIT ATM MODE</q-btn
>
Expand Down Expand Up @@ -864,6 +866,9 @@ <h5 class="q-mt-none">
atm() {
if (this.withdrawamtposs > 0) {
this.atmBox = true
if (this.atmPremium > 0) {
this.exchangeRate = this.exchangeRate / (1 + this.atmPremium)
}
}
},
atmSubmit() {
Expand Down Expand Up @@ -924,6 +929,7 @@ <h5 class="q-mt-none">
self.atmMode = false
}
}
this.getRates()
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
Expand Down Expand Up @@ -1158,9 +1164,6 @@ <h5 class="q-mt-none">
.request('GET', `/tpos/api/v1/rate/${this.currency}`)
.then(response => {
this.exchangeRate = response.data.rate
if (this.atmPremium > 0) {
this.exchangeRate = this.exchangeRate * (1 + this.atmPremium)
}
})
.catch(e => console.error(e))
},
Expand Down Expand Up @@ -1224,39 +1227,41 @@ <h5 class="q-mt-none">
this.showPoS = false
}

window.addEventListener('keyup', (event) => {
window.addEventListener('keyup', event => {
// do nothing if the event was already processed
if (event.defaultPrevented) return

// active only in the the PoS mode, not in the Cart mode
if (!this.showPoS) return
// active only in the the PoS mode, not in the Cart mode or ATM pin
if (!this.showPoS || this.atmBox) return

const { key } = event
if (key >= '0' && key <= '9') { // buttons 0 ... 9
const {key} = event
if (key >= '0' && key <= '9') {
// buttons 0 ... 9
this.stack.push(Number(key))
} else switch (key) {
case 'Backspace': // button ⬅
this.stack.pop()
break
case 'Enter': // button OK
this.submitForm()
break
case 'c': // button C
case 'C':
case 'Escape':
if (this.total > 0.0) {
this.cancelAddAmount()
} else {
this.stack = []
}
break
case '+': // button +
this.addAmount()
break
default:
// return if we didn't handle anything
return
}
} else
switch (key) {
case 'Backspace': // button ⬅
this.stack.pop()
break
case 'Enter': // button OK
this.submitForm()
break
case 'c': // button C
case 'C':
case 'Escape':
if (this.total > 0.0) {
this.cancelAddAmount()
} else {
this.stack = []
}
break
case '+': // button +
this.addAmount()
break
default:
// return if we didn't handle anything
return
}

// cancel the default action to avoid it being handled twice
event.preventDefault()
Expand Down

0 comments on commit 891ad1c

Please sign in to comment.