Skip to content

Commit

Permalink
renamed endpoints and stripped out some dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
arcbtc committed Jun 3, 2024
1 parent 4d182ee commit ac689dd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 53 deletions.
67 changes: 23 additions & 44 deletions templates/myextension/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ <h5 class="text-subtitle1 q-my-none">MyExtension</h5>
<q-btn flat color="grey" @click="exportCSV">Export to CSV</q-btn>
</div>
</div>
<q-table dense flat :data="temps" row-key="id" :columns="tempsTable.columns"
:pagination.sync="tempsTable.pagination">
<q-table dense flat :data="myex" row-key="id" :columns="myexTable.columns"
:pagination.sync="myexTable.pagination">
<myextension v-slot:header="props">
<q-tr :props="props">
<q-th v-for="col in props.cols" :key="col.name" :props="props">
Expand Down Expand Up @@ -175,8 +175,8 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
return {
invoiceAmount: 10,
qrValue: 'lnurlpay',
temps: [],
tempsTable: {
myex: [],
myexTable: {
columns: [
{ name: 'id', align: 'left', label: 'ID', field: 'id' },
{ name: 'name', align: 'left', label: 'Name', field: 'name' },
Expand All @@ -194,15 +194,8 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
},
formDialog: {
show: false,
data: {
withdrawpin: 878787,
tip_options: [],
withdrawbtwn: 10
},
advanced: {
tips: false,
otc: false
}
data: {},
advanced: {}
},
urlDialog: {
show: false,
Expand All @@ -218,23 +211,19 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
methods: {
closeFormDialog() {
this.formDialog.show = false
this.formDialog.data = {
withdrawpin: 878787,
tip_options: [],
withdrawbtwn: 10
}
this.formDialog.data = {}
},
getMyExtensions: function () {
var self = this

LNbits.api
.request(
'GET',
'/myextension/api/v1/temps?all_wallets=true',
'/myextension/api/v1/myex?all_wallets=true',
this.g.user.wallets[0].inkey
)
.then(function (response) {
self.temps = response.data.map(function (obj) {
self.myex = response.data.map(function (obj) {
return mapMyExtension(obj)
})
})
Expand All @@ -258,7 +247,7 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
}
},
updateMyExtensionForm(tempId) {
const myextension = _.findWhere(this.temps, { id: tempId })
const myextension = _.findWhere(this.myex, { id: tempId })
this.formDialog.data = {
...myextension
}
Expand All @@ -272,9 +261,9 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
},
createMyExtension(wallet, data) {
LNbits.api
.request('POST', '/myextension/api/v1/temps', wallet.adminkey, data)
.request('POST', '/myextension/api/v1/myex', wallet.adminkey, data)
.then(response => {
this.temps.push(mapMyExtension(response.data))
this.myex.push(mapMyExtension(response.data))
this.closeFormDialog()
})
.catch(error => {
Expand All @@ -285,15 +274,15 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
LNbits.api
.request(
'PUT',
`/myextension/api/v1/temps/${data.id}`,
`/myextension/api/v1/myex/${data.id}`,
wallet.adminkey,
data
)
.then(response => {
this.temps = _.reject(this.temps, obj => {
this.myex = _.reject(this.myex, obj => {
return obj.id == data.id
})
this.temps.push(mapMyExtension(response.data))
this.myex.push(mapMyExtension(response.data))
this.closeFormDialog()
})
.catch(error => {
Expand All @@ -302,19 +291,19 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
},
deleteMyExtension: function (tempId) {
var self = this
var myextension = _.findWhere(this.temps, { id: tempId })
var myextension = _.findWhere(this.myex, { id: tempId })

LNbits.utils
.confirmDialog('Are you sure you want to delete this MyExtension?')
.onOk(function () {
LNbits.api
.request(
'DELETE',
'/myextension/api/v1/temps/' + tempId,
'/myextension/api/v1/myex/' + tempId,
_.findWhere(self.g.user.wallets, { id: myextension.wallet }).adminkey
)
.then(function (response) {
self.temps = _.reject(self.temps, function (obj) {
self.myex = _.reject(self.myex, function (obj) {
return obj.id == tempId
})
})
Expand All @@ -324,20 +313,15 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
})
},
exportCSV: function () {
LNbits.utils.exportCSV(this.tempsTable.columns, this.temps)
LNbits.utils.exportCSV(this.myexTable.columns, this.myex)
},
itemsArray(tempId) {
const myextension = _.findWhere(this.temps, { id: tempId })
const myextension = _.findWhere(this.myex, { id: tempId })
return [...myextension.itemsMap.values()]
},
itemFormatPrice(price, id) {
const myextension = id.split(':')[0]
const currency = _.findWhere(this.temps, { id: myextension }).currency
return LNbits.utils.formatCurrency(Number(price).toFixed(2), currency)
},
openformDialog(id) {
const [tempId, itemId] = id.split(':')
const myextension = _.findWhere(this.temps, { id: tempId })
const myextension = _.findWhere(this.myex, { id: tempId })
if (itemId) {
const item = myextension.itemsMap.get(id)
this.formDialog.data = {
Expand All @@ -352,15 +336,10 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} MyExtension extension</h6>
},
closeformDialog() {
this.formDialog.show = false
this.formDialog.data = {
title: '',
image: '',
price: '',
disabled: false
}
this.formDialog.data = {}
},
openUrlDialog(id) {
this.urlDialog.data = _.findWhere(this.temps, { id })
this.urlDialog.data = _.findWhere(this.myex, { id })
this.qrValue = this.urlDialog.data.lnurlpay
console.log(this.urlDialog.data.id)
this.connectWebocket(this.urlDialog.data.id)
Expand Down
2 changes: 1 addition & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from . import myextension_ext, myextension_renderer
from .crud import get_myextension

temps = Jinja2Templates(directory="temps")
myex = Jinja2Templates(directory="myex")


#######################################
Expand Down
14 changes: 6 additions & 8 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
## Get all the records belonging to the user


@myextension_ext.get("/api/v1/temps", status_code=HTTPStatus.OK)
@myextension_ext.get("/api/v1/myex", status_code=HTTPStatus.OK)
async def api_myextensions(
req: Request,
all_wallets: bool = Query(False),
Expand All @@ -55,7 +55,7 @@ async def api_myextensions(
## Get a single record


@myextension_ext.get("/api/v1/temps/{myextension_id}", status_code=HTTPStatus.OK)
@myextension_ext.get("/api/v1/myex/{myextension_id}", status_code=HTTPStatus.OK)
async def api_myextension(
req: Request, myextension_id: str, WalletTypeInfo=Depends(get_key_type)
):
Expand All @@ -70,7 +70,7 @@ async def api_myextension(
## update a record


@myextension_ext.put("/api/v1/temps/{myextension_id}")
@myextension_ext.put("/api/v1/myex/{myextension_id}")
async def api_myextension_update(
req: Request,
data: CreateMyExtensionData,
Expand All @@ -97,7 +97,7 @@ async def api_myextension_update(
## Create a new record


@myextension_ext.post("/api/v1/temps", status_code=HTTPStatus.CREATED)
@myextension_ext.post("/api/v1/myex", status_code=HTTPStatus.CREATED)
async def api_myextension_create(
req: Request,
data: CreateMyExtensionData,
Expand All @@ -112,7 +112,7 @@ async def api_myextension_create(
## Delete a record


@myextension_ext.delete("/api/v1/temps/{myextension_id}")
@myextension_ext.delete("/api/v1/myex/{myextension_id}")
async def api_myextension_delete(
myextension_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
):
Expand All @@ -138,7 +138,7 @@ async def api_myextension_delete(


@myextension_ext.post(
"/api/v1/temps/payment/{myextension_id}", status_code=HTTPStatus.CREATED
"/api/v1/myex/payment/{myextension_id}", status_code=HTTPStatus.CREATED
)
async def api_tpos_create_invoice(
myextension_id: str, amount: int = Query(..., ge=1), memo: str = ""
Expand All @@ -159,8 +159,6 @@ async def api_tpos_create_invoice(
memo=f"{memo} to {myextension.name}" if memo else f"{myextension.name}",
extra={
"tag": "myextension",
"tipAmount": tipAmount,
"tempId": tempId,
"amount": amount,
},
)
Expand Down

0 comments on commit ac689dd

Please sign in to comment.