From b6b94c2940a43434e71fa3974d355070d3ffd988 Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Sat, 30 Sep 2023 20:48:38 +0200 Subject: [PATCH 1/6] Add location to F2F payment option --- api/models/order.py | 22 ++++++++++++++++++++++ api/serializers.py | 16 ++++++++++++++++ api/views.py | 4 ++++ frontend/src/models/Book.model.ts | 2 ++ frontend/src/models/Order.model.ts | 2 ++ 5 files changed, 46 insertions(+) diff --git a/api/models/order.py b/api/models/order.py index 109f3377d..d1a3ee937 100644 --- a/api/models/order.py +++ b/api/models/order.py @@ -128,6 +128,28 @@ class ExpiryReasons(models.IntegerChoices): blank=False, ) + # optionally makers can choose a coordinate for F2F + latitude = models.DecimalField( + max_digits=8, + decimal_places=6, + null=True, + validators=[ + MinValueValidator(config(-90, cast=float)), + MaxValueValidator(config(90, cast=float)), + ], + blank=False, + ) + longitude = models.DecimalField( + max_digits=9, + decimal_places=6, + null=True, + validators=[ + MinValueValidator(config(-180, cast=float)), + MaxValueValidator(config(180, cast=float)), + ], + blank=False, + ) + # how many sats at creation and at last check (relevant for marked to market) t0_satoshis = models.PositiveBigIntegerField( null=True, diff --git a/api/serializers.py b/api/serializers.py index 0aeb7e1a6..ad909499b 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -61,6 +61,8 @@ class Meta: "taker", "escrow_duration", "bond_size", + "latitude", + "longitude" ) @@ -253,6 +255,14 @@ class OrderDetailSerializer(serializers.ModelSerializer): required=False, help_text="in percentage, the swap fee rate the platform charges", ) + latitude = serializers.FloatField( + required=False, + help_text="Latitude of the order for F2F payments", + ) + longitude = serializers.FloatField( + required=False, + help_text="Longitude of the order for F2F payments", + ) pending_cancel = serializers.BooleanField( required=False, help_text="Your counterparty requested for a collaborative cancel when `status` is either `8`, `9` or `10`", @@ -391,6 +401,8 @@ class Meta: "sent_satoshis", "txid", "network", + "latitude", + "longitude", ) @@ -430,6 +442,8 @@ class Meta: "escrow_duration", "satoshis_now", "bond_size", + "latitude", + "longitude" ) @@ -469,6 +483,8 @@ class Meta: "public_duration", "escrow_duration", "bond_size", + "latitude", + "longitude" ) diff --git a/api/views.py b/api/views.py index f4cf083f0..6c7681e27 100644 --- a/api/views.py +++ b/api/views.py @@ -110,6 +110,8 @@ def post(self, request): public_duration = serializer.data.get("public_duration") escrow_duration = serializer.data.get("escrow_duration") bond_size = serializer.data.get("bond_size") + latitude = serializer.data.get("latitude") + longitude = serializer.data.get("longitude") # Optional params if public_duration is None: @@ -283,6 +285,8 @@ def get(self, request, format=None): data["taker_nick"] = str(order.taker) data["status_message"] = Order.Status(order.status).label data["is_fiat_sent"] = order.is_fiat_sent + data["latitude"] = order.latitude + data["longitude"] = order.longitude data["is_disputed"] = order.is_disputed data["ur_nick"] = request.user.username data["satoshis_now"] = order.last_satoshis diff --git a/frontend/src/models/Book.model.ts b/frontend/src/models/Book.model.ts index 403a44e3d..fd2f83820 100644 --- a/frontend/src/models/Book.model.ts +++ b/frontend/src/models/Book.model.ts @@ -14,6 +14,8 @@ export interface PublicOrder { premium: number; satoshis: number; satoshis_now: number; + latitude: number; + longitude: number; bond_size: number; maker: number; escrow_duration: number; diff --git a/frontend/src/models/Order.model.ts b/frontend/src/models/Order.model.ts index 08f152dcc..bc885daeb 100644 --- a/frontend/src/models/Order.model.ts +++ b/frontend/src/models/Order.model.ts @@ -50,6 +50,8 @@ export interface Order { taker_status: 'Active' | 'Seen recently' | 'Inactive'; price_now: number | undefined; satoshis_now: number; + latitude: number; + longitude: number; premium_now: number | undefined; premium_percentile: number; num_similar_orders: number; From 9e53f410475887a33d6e07cde325bcdc07b590a7 Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Sat, 30 Sep 2023 20:55:36 +0200 Subject: [PATCH 2/6] Fix py linterns --- api/models/order.py | 2 +- api/views.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/api/models/order.py b/api/models/order.py index d1a3ee937..7fd96c9ed 100644 --- a/api/models/order.py +++ b/api/models/order.py @@ -140,7 +140,7 @@ class ExpiryReasons(models.IntegerChoices): blank=False, ) longitude = models.DecimalField( - max_digits=9, + max_digits=9, decimal_places=6, null=True, validators=[ diff --git a/api/views.py b/api/views.py index 6c7681e27..8e458d5a8 100644 --- a/api/views.py +++ b/api/views.py @@ -163,6 +163,8 @@ def post(self, request): public_duration=public_duration, escrow_duration=escrow_duration, bond_size=bond_size, + latitude=latitude, + longitude=longitude, ) order.last_satoshis = order.t0_satoshis = Logics.satoshis_now(order) From 718a22823ec5e085d751506bc5d34d4e7b7e2384 Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Tue, 3 Oct 2023 22:18:30 +0200 Subject: [PATCH 3/6] Include migration --- ...e_order_longitude_alter_order_bond_size.py | 52 +++++++++++++++++++ api/models/order.py | 8 +-- docker-compose.yml | 11 ++-- 3 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py diff --git a/api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py b/api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py new file mode 100644 index 000000000..1c972c3a0 --- /dev/null +++ b/api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py @@ -0,0 +1,52 @@ +# Generated by Django 4.2.5 on 2023-10-03 20:12 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("api", "0042_alter_order_logs_alter_robot_avatar"), + ] + + operations = [ + migrations.AddField( + model_name="order", + name="latitude", + field=models.DecimalField( + decimal_places=6, + max_digits=8, + null=True, + validators=[ + django.core.validators.MinValueValidator(-90), + django.core.validators.MaxValueValidator(90), + ], + ), + ), + migrations.AddField( + model_name="order", + name="longitude", + field=models.DecimalField( + decimal_places=6, + max_digits=9, + null=True, + validators=[ + django.core.validators.MinValueValidator(-180), + django.core.validators.MaxValueValidator(180), + ], + ), + ), + migrations.AlterField( + model_name="order", + name="bond_size", + field=models.DecimalField( + decimal_places=2, + default=3.0, + max_digits=4, + validators=[ + django.core.validators.MinValueValidator(1.0), + django.core.validators.MaxValueValidator(15.0), + ], + ), + ), + ] diff --git a/api/models/order.py b/api/models/order.py index 7fd96c9ed..4d568381f 100644 --- a/api/models/order.py +++ b/api/models/order.py @@ -134,8 +134,8 @@ class ExpiryReasons(models.IntegerChoices): decimal_places=6, null=True, validators=[ - MinValueValidator(config(-90, cast=float)), - MaxValueValidator(config(90, cast=float)), + MinValueValidator(-90), + MaxValueValidator(90), ], blank=False, ) @@ -144,8 +144,8 @@ class ExpiryReasons(models.IntegerChoices): decimal_places=6, null=True, validators=[ - MinValueValidator(config(-180, cast=float)), - MaxValueValidator(config(180, cast=float)), + MinValueValidator(-180), + MaxValueValidator(180), ], blank=False, ) diff --git a/docker-compose.yml b/docker-compose.yml index 7b9ade4b0..08611a601 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,6 @@ services: backend: build: . - image: backend container_name: django-dev restart: always depends_on: @@ -61,7 +60,7 @@ services: - ./frontend/static:/usr/src/robosats/static clean-orders: - image: backend + build: . restart: always container_name: clord-dev environment: @@ -74,7 +73,7 @@ services: network_mode: service:tor follow-invoices: - image: backend + build: . container_name: invo-dev restart: always depends_on: @@ -90,7 +89,7 @@ services: network_mode: service:tor telegram-watcher: - image: backend + build: . container_name: tg-dev restart: always environment: @@ -103,7 +102,7 @@ services: network_mode: service:tor celery-worker: - image: backend + build: . container_name: cele-worker-dev restart: always environment: @@ -119,7 +118,7 @@ services: network_mode: service:tor celery-beat: - image: backend + build: . container_name: cele-beat-dev restart: always environment: From 8cbe1af6e987181b8ceb4417f97ad8f7467850b3 Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Wed, 4 Oct 2023 08:35:24 +0200 Subject: [PATCH 4/6] Revert docker-compose changes --- docker-compose.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 08611a601..7b9ade4b0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,7 @@ services: backend: build: . + image: backend container_name: django-dev restart: always depends_on: @@ -60,7 +61,7 @@ services: - ./frontend/static:/usr/src/robosats/static clean-orders: - build: . + image: backend restart: always container_name: clord-dev environment: @@ -73,7 +74,7 @@ services: network_mode: service:tor follow-invoices: - build: . + image: backend container_name: invo-dev restart: always depends_on: @@ -89,7 +90,7 @@ services: network_mode: service:tor telegram-watcher: - build: . + image: backend container_name: tg-dev restart: always environment: @@ -102,7 +103,7 @@ services: network_mode: service:tor celery-worker: - build: . + image: backend container_name: cele-worker-dev restart: always environment: @@ -118,7 +119,7 @@ services: network_mode: service:tor celery-beat: - build: . + image: backend container_name: cele-beat-dev restart: always environment: From f5cb0f759a4a9775ccdb7f99ae19be7459b8b7e1 Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Wed, 4 Oct 2023 20:48:25 +0200 Subject: [PATCH 5/6] Remove bond_size from migration --- ...atitude_order_longitude_alter_order_bond_size.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py b/api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py index 1c972c3a0..fe59aad31 100644 --- a/api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py +++ b/api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py @@ -36,17 +36,4 @@ class Migration(migrations.Migration): ], ), ), - migrations.AlterField( - model_name="order", - name="bond_size", - field=models.DecimalField( - decimal_places=2, - default=3.0, - max_digits=4, - validators=[ - django.core.validators.MinValueValidator(1.0), - django.core.validators.MaxValueValidator(15.0), - ], - ), - ), ] From eb462ecf5558aab2cc4ee0760f943d053a1a689d Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Thu, 5 Oct 2023 19:16:50 +0200 Subject: [PATCH 6/6] Rename 0043_order_latitude_order_longitude_alter_order_bond_size.py to 0043_order_latitude_order_longitude.py --- ..._order_bond_size.py => 0043_order_latitude_order_longitude.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename api/migrations/{0043_order_latitude_order_longitude_alter_order_bond_size.py => 0043_order_latitude_order_longitude.py} (100%) diff --git a/api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py b/api/migrations/0043_order_latitude_order_longitude.py similarity index 100% rename from api/migrations/0043_order_latitude_order_longitude_alter_order_bond_size.py rename to api/migrations/0043_order_latitude_order_longitude.py