From a1f0a8564604e4abbd9840c17fd6e0f7f85579d5 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 1 May 2023 10:24:48 -0700 Subject: [PATCH] Small fixes --- api/lightning/node.py | 10 ++++----- api/models/currency.py | 3 ++- docker-compose.yml | 2 +- frontend/src/components/RobotAvatar/index.tsx | 2 +- robosats/routing.py | 22 ++++++++++--------- robosats/settings.py | 16 ++++++++++++-- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/api/lightning/node.py b/api/lightning/node.py index a1908c43..0ec5318a 100644 --- a/api/lightning/node.py +++ b/api/lightning/node.py @@ -20,20 +20,20 @@ from . import verrpc_pb2 as verrpc from . import verrpc_pb2_grpc as verrpcstub ####### -# Works with LND (c-lightning in the future for multi-vendor resiliance) +# Works with LND (c-lightning in the future for multi-vendor resilience) ####### # Read tls.cert from file or .env variable string encoded as base64 try: - CERT = open(os.path.join(config("LND_DIR"), "tls.cert"), "rb").read() + with open(os.path.join(config("LND_DIR"), "tls.cert"), "rb") as f: + CERT = f.read() except Exception: CERT = b64decode(config("LND_CERT_BASE64")) # Read macaroon from file or .env variable string encoded as base64 try: - MACAROON = open( - os.path.join(config("LND_DIR"), config("MACAROON_path")), "rb" - ).read() + with open(os.path.join(config("LND_DIR"), config("MACAROON_path")), "rb") as f: + MACAROON = f.read() except Exception: MACAROON = b64decode(config("LND_MACAROON_BASE64")) diff --git a/api/models/currency.py b/api/models/currency.py index a6a3ffef..7ac957d3 100644 --- a/api/models/currency.py +++ b/api/models/currency.py @@ -7,7 +7,8 @@ from django.utils import timezone class Currency(models.Model): - currency_dict = json.load(open("frontend/static/assets/currencies.json")) + with open("frontend/static/assets/currencies.json") as f: + currency_dict = json.load(f) currency_choices = [(int(val), label) for val, label in list(currency_dict.items())] currency = models.PositiveSmallIntegerField( diff --git a/docker-compose.yml b/docker-compose.yml index ab8fc909..004df94c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,7 +35,7 @@ services: - .:/usr/src/robosats - ./node/lnd:/lnd network_mode: service:tor - command: python3 -Wa -u manage.py runserver 0.0.0.0:8000 + command: python3 -u manage.py runserver 0.0.0.0:8000 frontend: build: ./frontend diff --git a/frontend/src/components/RobotAvatar/index.tsx b/frontend/src/components/RobotAvatar/index.tsx index 3046bb87..aefe0f32 100644 --- a/frontend/src/components/RobotAvatar/index.tsx +++ b/frontend/src/components/RobotAvatar/index.tsx @@ -105,7 +105,7 @@ const RobotAvatar: React.FC = ({ border: '0.3px solid #55555', filter: 'dropShadow(0.5px 0.5px 0.5px #000000)', ...imageStyle, - onLoad: setTimeout(() => setActiveBackground(false), 300), + onLoad: setTimeout(() => setActiveBackground(false), 1000), }} /> diff --git a/robosats/routing.py b/robosats/routing.py index 2ee7126d..d56ba5c6 100644 --- a/robosats/routing.py +++ b/robosats/routing.py @@ -2,6 +2,7 @@ import os from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter +from decouple import config from django.core.asgi import get_asgi_application import chat.routing @@ -11,14 +12,15 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "robosats.settings") # is populated before importing code that may import ORM models. django_asgi_app = get_asgi_application() -application = ProtocolTypeRouter( - { - "http": django_asgi_app, - "websocket": AuthMiddlewareStack( - URLRouter( - chat.routing.websocket_urlpatterns, - # TODO add api.routing.websocket_urlpatterns when Order page works with websocket - ) - ), - } +protocols = {} +protocols["websocket"] = AuthMiddlewareStack( + URLRouter( + chat.routing.websocket_urlpatterns, + # add api.routing.websocket_urlpatterns when Order page works with websocket + ) ) + +if config("DEVELOPMENT", default=False): + protocols["http"] = django_asgi_app + +application = ProtocolTypeRouter(protocols) diff --git a/robosats/settings.py b/robosats/settings.py index 28c739e9..08955cac 100644 --- a/robosats/settings.py +++ b/robosats/settings.py @@ -36,7 +36,7 @@ STATIC_ROOT = "/usr/src/static/" # SECURITY WARNING: don't run with debug turned on in production! -if os.environ.get("DEVELOPMENT"): +if config("DEVELOPMENT", default=False): DEBUG = True STATIC_ROOT = "frontend/static/" @@ -53,7 +53,19 @@ ALLOWED_HOSTS = [ ] CORS_ALLOW_ALL_ORIGINS = True -CSRF_TRUSTED_ORIGINS = ["http://*", "https://*"] + +CSRF_TRUSTED_ORIGINS = [ + f'http://{config("HOST_NAME")}', + f'http://{config("HOST_NAME2")}', + f'http://{config("I2P_ALIAS")}', + f'http://{config("I2P_LONG")}', + f'http://{config("LOCAL_ALIAS")}', + "http://localhost", + "http://*.onion", + "http://*", + "https://*.com", + "https://*", +] # Allows Session Cookie to be read by Javascript on Client side. SESSION_COOKIE_HTTPONLY = False