diff --git a/lnbits/extensions/gerty/__init__.py b/lnbits/extensions/gerty/__init__.py index 03fdef12..bd353c78 100644 --- a/lnbits/extensions/gerty/__init__.py +++ b/lnbits/extensions/gerty/__init__.py @@ -9,6 +9,16 @@ from lnbits.tasks import catch_everything_and_restart db = Database("ext_gerty") + +gerty_static_files = [ + { + "path": "/gerty/static", + "app": StaticFiles(packages=[("lnbits", "extensions/gerty/static")]), + "name": "gerty_static", + } +] + + gerty_ext: APIRouter = APIRouter(prefix="/gerty", tags=["Gerty"]) diff --git a/lnbits/extensions/gerty/crud.py b/lnbits/extensions/gerty/crud.py index e4a1713a..c6516cf2 100644 --- a/lnbits/extensions/gerty/crud.py +++ b/lnbits/extensions/gerty/crud.py @@ -81,6 +81,7 @@ async def delete_gerty(gerty_id: str) -> None: async def get_mempool_info(endPoint: str, gerty) -> Optional[Mempool]: + logger.debug(endPoint) endpoints = MempoolEndpoint() url = "" for endpoint in endpoints: @@ -96,17 +97,21 @@ async def get_mempool_info(endPoint: str, gerty) -> Optional[Mempool]: if not row: async with httpx.AsyncClient() as client: response = await client.get(gerty.mempool_endpoint + url) + logger.debug(gerty.mempool_endpoint + url) + mempool_id = urlsafe_short_hash() await db.execute( """ INSERT INTO gerty.mempool ( + id, data, endpoint, time, mempool_endpoint ) - VALUES (?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?) """, ( + mempool_id, json.dumps(response.json()), endPoint, int(time.time()), diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index 1f8c1caf..16f0c8cb 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -80,7 +80,7 @@ async def get_mining_dashboard(gerty): if isinstance(gerty.mempool_endpoint, str): async with httpx.AsyncClient() as client: # current hashrate - r = await get_mempool_info("get_hashrate_1w", gerty) + r = await get_mempool_info("hashrate_1w", gerty) data = r hashrateNow = data["currentHashrate"] hashrateOneWeekAgo = data["hashrates"][6]["avgHashrate"] diff --git a/lnbits/extensions/gerty/migrations.py b/lnbits/extensions/gerty/migrations.py index 830b8cfd..4a5910f4 100644 --- a/lnbits/extensions/gerty/migrations.py +++ b/lnbits/extensions/gerty/migrations.py @@ -42,7 +42,8 @@ async def m004_initial(db): await db.execute( """ CREATE TABLE gerty.mempool ( - mempool_endpoint TEXT PRIMARY KEY, + id TEXT PRIMARY KEY, + mempool_endpoint TEXT NOT NULL, endpoint TEXT NOT NULL, data TEXT NOT NULL, time TIMESTAMP diff --git a/lnbits/extensions/gerty/models.py b/lnbits/extensions/gerty/models.py index 4bb82d74..11a44e6e 100644 --- a/lnbits/extensions/gerty/models.py +++ b/lnbits/extensions/gerty/models.py @@ -10,6 +10,7 @@ class Gerty(BaseModel): name: str refresh_time: int = Query(None) utc_offset: int = Query(None) + wallet: str = Query(None) type: str lnbits_wallets: str = Query( None @@ -39,6 +40,7 @@ class MempoolEndpoint(BaseModel): class Mempool(BaseModel): + id: str = Query(None) mempool_endpoint: str = Query(None) endpoint: str = Query(None) data: str = Query(None) diff --git a/lnbits/extensions/gerty/static/gerty.jpg b/lnbits/extensions/gerty/static/gerty.jpg new file mode 100644 index 00000000..fe208cdd Binary files /dev/null and b/lnbits/extensions/gerty/static/gerty.jpg differ diff --git a/lnbits/extensions/gerty/templates/gerty/_api_docs.html b/lnbits/extensions/gerty/templates/gerty/_api_docs.html index db141279..27029028 100644 --- a/lnbits/extensions/gerty/templates/gerty/_api_docs.html +++ b/lnbits/extensions/gerty/templates/gerty/_api_docs.html @@ -1,80 +1,17 @@ - - - - - - GET /gerty/api/v1/gertys -
Headers
- {"X-Api-Key": <invoice_key>}
-
Body (application/json)
-
- Returns 200 OK (application/json) -
- [<gerty_object>, ...] -
Curl example
- curl -X GET {{ request.base_url }}gerty/api/v1/gertys -H "X-Api-Key: - <invoice_key>" - -
-
-
- - - - POST /gerty/api/v1/gertys -
Headers
- {"X-Api-Key": <invoice_key>}
-
Body (application/json)
- {"name": <string>, "currency": <string*ie USD*>} -
- Returns 201 CREATED (application/json) -
- {"currency": <string>, "id": <string>, "name": - <string>, "wallet": <string>} -
Curl example
- curl -X POST {{ request.base_url }}gerty/api/v1/gertys -d '{"name": - <string>, "currency": <string>}' -H "Content-type: - application/json" -H "X-Api-Key: <admin_key>" - -
-
-
- - - - - DELETE - /gerty/api/v1/gertys/<gerty_id> -
Headers
- {"X-Api-Key": <admin_key>}
-
Returns 204 NO CONTENT
- -
Curl example
- curl -X DELETE {{ request.base_url - }}gerty/api/v1/gertys/<gerty_id> -H "X-Api-Key: - <admin_key>" - -
-
-
-
+ +

+ Gerty (your bitcoin assistant): Use the software Gerty or + hardware Gerty
+ + Created by, Black Coffee, + Ben Arc +

+ +
diff --git a/lnbits/extensions/gerty/templates/gerty/index.html b/lnbits/extensions/gerty/templates/gerty/index.html index 61a22d8a..501708bc 100644 --- a/lnbits/extensions/gerty/templates/gerty/index.html +++ b/lnbits/extensions/gerty/templates/gerty/index.html @@ -107,9 +107,21 @@
-
- {{ SITE_TITLE }} Gerty extension -
+
+
+
+ {{ SITE_TITLE }} Gerty extension +
+
+
+ +
+
@@ -309,12 +321,50 @@ >The amount of time in seconds between screen updates - -

Gerty Device Dashboards (for Gerty devices):

- - - - + +

+ Gerty Device Dashboards (for Gerty + devices): +

+ + + +
@@ -570,6 +620,8 @@ formDialog: { show: false, data: { + type: 'Mini Gerty', + exchange: 'USD', utc_offset: new Date().getTimezoneOffset(), display_preferences: { dashboard: false, @@ -597,41 +649,44 @@ } } }, - mounted() { - console.log('this.formDialog', this.formDialog.data.display_preferences) - }, methods: { - setAdvanced: function(){ - self = this - self.formDialog.data.mempool_endpoint = 'https://mempool.space' - self.formDialog.data.refresh_time = 300 - }, - setWallets: function() { - self = this - if(!self.formDialog.data.display_preferences.lnbits_wallets_balance){ - self.formDialog.data.lnbits_wallets = [] - } - }, - setOnchain: function() { - self = this - self.formDialog.data.display_preferences.onchain_difficulty_epoch_progress = self.toggleStates.onchain - self.formDialog.data.display_preferences.onchain_difficulty_retarget_date = self.toggleStates.onchain - self.formDialog.data.display_preferences.onchain_difficulty_blocks_remaining = !self.toggleStates.onchain - self.formDialog.data.display_preferences.onchain_difficulty_epoch_time_remaining = self.toggleStates.onchain - self.formDialog.data.display_preferences.onchain_block_height = self.toggleStates.onchain - }, - setMining: function() { - self = this - self.formDialog.data.display_preferences.mining_current_hash_rate = self.toggleStates.mining - self.formDialog.data.display_preferences.mining_current_difficulty = self.toggleStates.mining - }, + setAdvanced: function () { + self = this + self.formDialog.data.mempool_endpoint = 'https://mempool.space' + self.formDialog.data.refresh_time = 300 + }, + setWallets: function () { + self = this + if (!self.formDialog.data.display_preferences.lnbits_wallets_balance) { + self.formDialog.data.lnbits_wallets = [] + } + }, + setOnchain: function () { + self = this + self.formDialog.data.display_preferences.onchain_difficulty_epoch_progress = + self.toggleStates.onchain + self.formDialog.data.display_preferences.onchain_difficulty_retarget_date = + self.toggleStates.onchain + self.formDialog.data.display_preferences.onchain_difficulty_blocks_remaining = !self + .toggleStates.onchain + self.formDialog.data.display_preferences.onchain_difficulty_epoch_time_remaining = + self.toggleStates.onchain + self.formDialog.data.display_preferences.onchain_block_height = + self.toggleStates.onchain + }, + setMining: function () { + self = this + self.formDialog.data.display_preferences.mining_current_hash_rate = + self.toggleStates.mining + self.formDialog.data.display_preferences.mining_current_difficulty = + self.toggleStates.mining + }, closeFormDialog: function () { this.formDialog.data = { utc_offset: 0, lnbits_wallets: [], mempool_endpoint: 'https://mempool.space', refresh_time: 300, - type: 'Gerty', display_preferences: {} } }, @@ -651,7 +706,6 @@ }, updateformDialog: function (formId) { var gerty = _.findWhere(this.gertys, {id: formId}) - console.log('gerty.display_preferences', gerty.display_preferences) this.formDialog.data.id = gerty.id this.formDialog.data.name = gerty.name this.formDialog.data.type = gerty.type @@ -666,7 +720,6 @@ (this.formDialog.show = true) }, sendFormDataGerty: function () { - console.log(this.formDialog.data) if (this.formDialog.data.id) { this.updateGerty( this.g.user.wallets[0].adminkey, @@ -680,6 +733,14 @@ } }, createGerty: function () { + if ( + this.formDialog.data.display_preferences.dashboard || + this.formDialog.data.display_preferences.dashboard_onchain || + this.formDialog.data.display_preferences.dashboard_onchain || + this.formDialog.data.display_preferences.lightning_dashboard + ) { + this.formDialog.data.type = 'Gerty' + } var data = { name: this.formDialog.data.name, utc_offset: this.formDialog.data.utc_offset, @@ -693,7 +754,6 @@ ) } var self = this - console.log(data) LNbits.api .request( 'POST', @@ -711,6 +771,14 @@ }, updateGerty: function (wallet, data) { var self = this + if ( + this.formDialog.data.display_preferences.dashboard || + this.formDialog.data.display_preferences.dashboard_onchain || + this.formDialog.data.display_preferences.dashboard_onchain || + this.formDialog.data.display_preferences.lightning_dashboard + ) { + this.formDialog.data.type = 'Gerty' + } data.utc_offset = this.formDialog.data.utc_offset data.type = this.formDialog.data.type data.lnbits_wallets = JSON.stringify( @@ -734,8 +802,8 @@ }, deleteGerty: function (gertyId) { var self = this - var gerty = _.findWhere(this.gertys, {id: gertyId}) + var gerty = _.findWhere(self.gertys, {id: gertyId}) LNbits.utils .confirmDialog('Are you sure you want to delete this Gerty?') .onOk(function () {