Add location to F2F payment option (backend) (#867)

* Add location to F2F payment option

* Fix py linterns

* Include migration

* Revert docker-compose changes

* Remove bond_size from migration

* Rename 0043_order_latitude_order_longitude_alter_order_bond_size.py to 0043_order_latitude_order_longitude.py
This commit is contained in:
KoalaSat 2023-10-10 12:47:22 +00:00 committed by GitHub
parent da87095c32
commit 4d45b884cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,39 @@
# 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),
],
),
),
]

View File

@ -128,6 +128,28 @@ class Order(models.Model):
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,

View File

@ -61,6 +61,8 @@ class ListOrderSerializer(serializers.ModelSerializer):
"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 OrderDetailSerializer(serializers.ModelSerializer):
"sent_satoshis",
"txid",
"network",
"latitude",
"longitude",
)
@ -430,6 +442,8 @@ class OrderPublicSerializer(serializers.ModelSerializer):
"escrow_duration",
"satoshis_now",
"bond_size",
"latitude",
"longitude"
)
@ -469,6 +483,8 @@ class MakeOrderSerializer(serializers.ModelSerializer):
"public_duration",
"escrow_duration",
"bond_size",
"latitude",
"longitude"
)

View File

@ -110,6 +110,8 @@ class MakerView(CreateAPIView):
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:
@ -161,6 +163,8 @@ class MakerView(CreateAPIView):
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)
@ -283,6 +287,8 @@ class OrderView(viewsets.ViewSet):
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

View File

@ -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;

View File

@ -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;