Disable BTCPay in the interface, if BTCPAY_PRIVATE_KEY is un-set #3

Merged
3wordchant merged 4 commits from optional-btcpay into master 2021-07-21 18:20:41 +00:00
Owner

I'm potentially interested in working out how BTCpay works at some point, but it's doesn't seem necessary for our trial run, so it'd be helpful to be able to hide it in Capsul if it's not configured.

These changes hide the link to /payment/btcpay, and prevent that page from loading, if BTCPAY_PRIVATE_KEY is not set.

I'm potentially interested in working out how BTCpay works at some point, but it's doesn't seem necessary for our trial run, so it'd be helpful to be able to hide it in Capsul if it's not configured. These changes hide the link to `/payment/btcpay`, and prevent that page from loading, if `BTCPAY_PRIVATE_KEY` is not set.
3wordchant added 3 commits 2021-07-20 22:29:56 +00:00
357d99cb91 Add load_config_vars context processor..
..to allow accessing config variables in the templates.

This removes the need for adding config variables manually to template
contexts.
decentral1se approved these changes 2021-07-21 09:12:48 +00:00
decentral1se left a comment
Collaborator

LGTM.

Probably more intuitive to have a BTCPAY_ENABLED=true/false?

But again, this looks fine as-is.

LGTM. Probably more intuitive to have a `BTCPAY_ENABLED=true/false`? But again, this looks fine as-is.
Author
Owner

Yeah, fair point, maybe a further change to make in future? My thinking was that BTCPAY_PRIVATE_KEY is blank by default, so the flow of "first set-up = no BTCPay", "add BTCPay private key = enabled" didn't seem terrible, but yes, still not as explicit as it could be.

Yeah, fair point, maybe a further change to make in future? My thinking was that `BTCPAY_PRIVATE_KEY` is blank by default, so the flow of "first set-up = no BTCPay", "add BTCPay private key = enabled" didn't seem terrible, but yes, still not as explicit as it could be.
forest added 1 commit 2021-07-21 17:12:44 +00:00
Collaborator

I changed this a little bit:

  1. I didn't wanna use
@app.context_processor
def load_config_vars():
  return dict(config=app.config)

Is that ok? I thought it might be better to avoid tying the config structure to the template files. So config values would have to be passed explicitly, like:

return render_template(
  "account-balance.html", 
  ...
  btcpay_enabled=current_app.config["BTCPAY_ENABLED"],
  ...
  1. I made the BTCPAY_ENABLED boolean config value get automatically set depending on app.config['BTCPAY_URL'] is not "" and btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY']) does not raise an exception (i.e. the key is valid)

Does that sound good ?

I changed this a little bit: 1. I didn't wanna use ``` @app.context_processor def load_config_vars(): return dict(config=app.config) ``` Is that ok? I thought it might be better to avoid tying the config structure to the template files. So config values would have to be passed explicitly, like: ``` return render_template( "account-balance.html", ... btcpay_enabled=current_app.config["BTCPAY_ENABLED"], ... ``` 2. I made the `BTCPAY_ENABLED` boolean config value get automatically set depending on `app.config['BTCPAY_URL'] is not ""` and `btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY'])` does not raise an exception (i.e. the key is valid) Does that sound good ?
3wordchant reviewed 2021-07-21 17:42:20 +00:00
3wordchant left a comment
Author
Owner

OK, looks excellent, merging!

OK, looks excellent, merging!
@ -73,3 +72,3 @@
BTCPAY_PRIVATE_KEY=os.environ.get("BTCPAY_PRIVATE_KEY", default="").replace("\\n", "\n"),
BTCPAY_URL=os.environ.get("BTCPAY_URL", default="https://btcpay.cyberia.club")
BTCPAY_URL=os.environ.get("BTCPAY_URL", default="")
Author
Owner

Ah, greatlooks. I didn't wanna complicate things for Cyberia's deployment, but this seems like a good generic default

Ah, greatlooks. I didn't wanna complicate things for Cyberia's deployment, but this seems like a good generic default
3wordchant merged commit f848eda931 into master 2021-07-21 18:20:41 +00:00
3wordchant deleted branch optional-btcpay 2021-07-21 18:21:36 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: 3wordchant/capsul-flask#3
No description provided.