Skip to content

Commit

Permalink
check wallet key on endpoint (#35)
Browse files Browse the repository at this point in the history
* check wallet key on endpoint
* add items functionality to readme
* make colors optional and persistent
* clean logs
* contrast of item cart
* admin key instead of invoice
* fix wallet on import json
  • Loading branch information
talvasconcelos authored Nov 24, 2023
1 parent 2079378 commit 178c0e8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 16 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,54 @@ An easy, fast and secure way to accept Bitcoin, over Lightning Network, at your
- after payment, the tip amount is sent to the defined wallet (for example an employees wallet) and the rest to the main wallet\
![paym 1](https://i.imgur.com/zvDf1y5.png)

## Add Items to PoS

You can add items to a TPoS and use it on a list.

1. After creating a TPos, or on an existing TPoS, click the expand button\
![items](https://i.imgur.com/V468a7q.png)

- you can add an item
- delete all items
- import/export items from a JSON

2. Clicking the _Add Item_ fill the Item details\
![add item](https://i.imgur.com/dNQGFXa.png)

- title and price are mandatory

3. Or you can import a JSON with your products, using the format:

```
[
{
"image": "https://image.url",
"price": 1.99,
"title": "Item 1",
"tax": 3.5,
"disabled": false
},
{
"price": 0.99,
"title": "Item 2",
"description": "My cool Item #2",
},
...
]
```

After adding your products, when launching your TPoS, if there are products, it will default to the items view (PoS view)\
![pos](https://i.imgur.com/Adh0fdO.png)

Click the items _Add_ button, to add to a "cart" or a total.
![pos add](https://i.imgur.com/uZCQpZD.png)

When done, click _Pay_ to show the invoice for customer to pay, or choose the tip if you have it set. If you need the regular TPoS, click the button on the bottom.

**There's also a `+` button on the regular TPoS**
On the regular TPoS you can also add value to a total. Enter a value and click the `+` button. Keep doing it until you're done. After that click _OK_ as usual.\
![plus](https://i.imgur.com/DSOusVA.png)

## OTC ATM functionality

1. Create or edit an existing TPOS and activate _Enable selling bitcoin_\
Expand Down
8 changes: 5 additions & 3 deletions templates/tpos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,6 @@ <h6 class="text-subtitle1 q-my-none">
self.tposs = response.data.map(function (obj) {
return mapTPoS(obj)
})
console.log(self.tposs)
})
},
sendTPosData() {
Expand Down Expand Up @@ -1034,7 +1033,7 @@ <h6 class="text-subtitle1 q-my-none">
.request(
'PUT',
`/tpos/api/v1/tposs/${tposId}/items`,
wallet.inkey,
wallet.adminkey,
data
)
.then(response => {
Expand Down Expand Up @@ -1097,6 +1096,9 @@ <h6 class="text-subtitle1 q-my-none">
},
openFileDataDialog(tposId, data) {
const tpos = _.findWhere(this.tposs, {id: tposId})
const wallet = _.findWhere(this.g.user.wallets, {
id: tpos.wallet
})
data.forEach(item => {
item.formattedPrice = LNbits.utils.formatCurrency(
Number(item.price).toFixed(2),
Expand All @@ -1110,7 +1112,7 @@ <h6 class="text-subtitle1 q-my-none">
let updatedData = {
items: [...tpos.items, ...data]
}
this.updateTposItems(tpos.id, tpos.wallet, updatedData)
this.updateTposItems(tpos.id, wallet, updatedData)
this.fileDataDialog.data = {}
this.fileDataDialog.show = false
}
Expand Down
31 changes: 19 additions & 12 deletions templates/tpos/tpos.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
icon="share"
color="white"
></q-btn>
<q-btn-toggle
v-model="monochrome"
toggle-color="primary"
:options="[
{label: 'Color', value: false},
{label: 'Mono', value: true}
]"
size="sm"
@input="handleColorScheme"
class="q-ml-md"
/>
{% endblock %} {% block footer %}{% endblock %} {% block page_container %}
<q-page-container>
<q-page>
Expand Down Expand Up @@ -115,7 +126,7 @@ <h5>
size="xl"
:outline="!($q.dark.isActive)"
rounded
color="secondary"
:color="monochrome ? 'secondary' : 'negative'"
>C</q-btn
>
<q-btn
Expand All @@ -133,7 +144,7 @@ <h5>
size="xl"
:outline="!($q.dark.isActive)"
rounded
color="secondary"
:color="monochrome ? 'secondary' : 'warning'"
class="btn-cancel"
></q-btn
>
Expand All @@ -153,7 +164,7 @@ <h5>
size="xl"
:outline="!($q.dark.isActive)"
rounded
color="secondary"
:color="monochrome ? 'secondary' : 'positive'"
class="btn-confirm"
>Ok</q-btn
>
Expand Down Expand Up @@ -247,9 +258,7 @@ <h5 class="q-mt-none q-mb-sm">${totalfsat}<small> sat</small></h5>
:disabled="item.quantity == 1"
></q-btn>
<div class="text-center">
<span class="text-primary text-bold"
>${item.quantity}</span
>
<span class="text-bold">${item.quantity}</span>
</div>
<q-btn
@click="addToCart(item)"
Expand Down Expand Up @@ -604,11 +613,6 @@ <h5 class="q-mt-none">
object-fit: scale-down;
}

/* .q-drawer {
width: 85% !important;
max-width: 450px;
} */

.table {
border-collapse: collapse;
width: 100%;
Expand Down Expand Up @@ -710,6 +714,7 @@ <h5 class="q-mt-none">
rowsPerPage: 10
}
},
monochrome: this.$q.localStorage.getItem('lnbits.tpos.color'),
showPoS: true,
cartDrawer: this.$q.screen.width > 1200,
searchTerm: '',
Expand Down Expand Up @@ -1137,6 +1142,9 @@ <h5 class="q-mt-none">
})
})
.catch(err => console.error(err))
},
handleColorScheme(val) {
this.$q.localStorage.set('lnbits.tpos.color', val)
}
},
created: function () {
Expand Down Expand Up @@ -1167,7 +1175,6 @@ <h5 class="q-mt-none">
setInterval(function () {
getRates()
}, 120000)
console.log(this.cart.size)
}
})
</script>
Expand Down
9 changes: 8 additions & 1 deletion views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
check_admin,
get_key_type,
require_admin_key,
require_invoice_key,
)
from lnbits.utils.exchange_rates import get_fiat_rate_satoshis

Expand Down Expand Up @@ -275,12 +276,18 @@ async def api_check_fiat_rate(currency):

## ITEMS
@tpos_ext.put("/api/v1/tposs/{tpos_id}/items", status_code=HTTPStatus.CREATED)
async def api_tpos_create_items(data: CreateUpdateItemData, tpos_id: str):
async def api_tpos_create_items(
data: CreateUpdateItemData,
tpos_id: str,
wallet: WalletTypeInfo = Depends(require_admin_key),
):
tpos = await get_tpos(tpos_id)
if not tpos:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
)
if wallet.wallet.id != tpos.wallet:
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your TPoS.")

items = json.dumps(data.dict()["items"])
tpos = await update_tpos(tpos_id=tpos_id, items=items)
Expand Down

0 comments on commit 178c0e8

Please sign in to comment.