Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add location to F2F payment option (backend) #867

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 4.2.5 on 2023-10-03 20:12

KoalaSat marked this conversation as resolved.
Show resolved Hide resolved
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),
],
),
),
Copy link
Member Author

@KoalaSat KoalaSat Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bond_size was generated together with makemigrations, not sure if it was just missing or a mistake on my side

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a mistake, but it is an undesired change. It is best to delete lines L39 to L51 before merging (that is migrations.AlterField(...) . Alternatively, you can also delete the migration file, edit .env to MIN_BOND_SIZE = 2 (instead of current value of 1) and the run manage.py makemigrations again. Should yield the same migration without altering the field bond_size.

The reason why this happened is that /api/models/order.py Order field bond_size depends on two config parameters that are read from the .env file. In my setup the .env file defines the MIN_BOND_SIZE as 2%, while the .env-sample defines it as 1% (at some point, there was a deviation, I changed my own .env without updating the .env-sample...). This migration will therefore allow bond sizes to be smaller than the current minimum of 2%.

I have opened a new issue (#873) so we make sure backend models are not dependant on any coordinator specific setting (.env) and therefore, we do not have any sort of conflict at run time when coordinators change values on their .env file.

]
22 changes: 22 additions & 0 deletions api/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(-90),
MaxValueValidator(90),
],
blank=False,
)
longitude = models.DecimalField(
max_digits=9,
decimal_places=6,
null=True,
validators=[
MinValueValidator(-180),
MaxValueValidator(180),
],
blank=False,
)

# how many sats at creation and at last check (relevant for marked to market)
t0_satoshis = models.PositiveBigIntegerField(
null=True,
Expand Down
16 changes: 16 additions & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Meta:
"taker",
"escrow_duration",
"bond_size",
"latitude",
"longitude"
)


Expand Down Expand Up @@ -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`",
Expand Down Expand Up @@ -391,6 +401,8 @@ class Meta:
"sent_satoshis",
"txid",
"network",
"latitude",
"longitude",
)


Expand Down Expand Up @@ -430,6 +442,8 @@ class Meta:
"escrow_duration",
"satoshis_now",
"bond_size",
"latitude",
"longitude"
)


Expand Down Expand Up @@ -469,6 +483,8 @@ class Meta:
"public_duration",
"escrow_duration",
"bond_size",
"latitude",
"longitude"
)


Expand Down
6 changes: 6 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -161,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)
Expand Down Expand Up @@ -283,6 +287,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
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/models/Book.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/models/Order.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading