Implement wallet model and CRUD
This commit is contained in:
parent
6e6b23da63
commit
0723f14c53
32
app/urls.py
32
app/urls.py
|
@ -20,7 +20,16 @@ from django.contrib.auth.views import LogoutView
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from two_factor.urls import urlpatterns as tf_urls
|
from two_factor.urls import urlpatterns as tf_urls
|
||||||
|
|
||||||
from core.views import ads, aggregators, banks, base, notifications, platforms, profit
|
from core.views import (
|
||||||
|
ads,
|
||||||
|
aggregators,
|
||||||
|
banks,
|
||||||
|
base,
|
||||||
|
notifications,
|
||||||
|
platforms,
|
||||||
|
profit,
|
||||||
|
wallets,
|
||||||
|
)
|
||||||
|
|
||||||
# from core.views.stripe_callbacks import Callback
|
# from core.views.stripe_callbacks import Callback
|
||||||
|
|
||||||
|
@ -200,4 +209,25 @@ urlpatterns = [
|
||||||
profit.Profit.as_view(),
|
profit.Profit.as_view(),
|
||||||
name="profit",
|
name="profit",
|
||||||
),
|
),
|
||||||
|
# Wallets
|
||||||
|
path(
|
||||||
|
"wallets/<str:type>/",
|
||||||
|
wallets.WalletList.as_view(),
|
||||||
|
name="wallets",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"wallets/<str:type>/create/",
|
||||||
|
wallets.WalletCreate.as_view(),
|
||||||
|
name="wallet_create",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"wallets/<str:type>/update/<str:pk>/",
|
||||||
|
wallets.WalletUpdate.as_view(),
|
||||||
|
name="wallet_update",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"wallets/<str:type>/delete/<str:pk>/",
|
||||||
|
wallets.WalletDelete.as_view(),
|
||||||
|
name="wallet_delete",
|
||||||
|
),
|
||||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
|
|
|
@ -13,6 +13,7 @@ from .models import (
|
||||||
Provider,
|
Provider,
|
||||||
Requisition,
|
Requisition,
|
||||||
User,
|
User,
|
||||||
|
Wallet,
|
||||||
)
|
)
|
||||||
|
|
||||||
# flake8: noqa: E501
|
# flake8: noqa: E501
|
||||||
|
@ -90,10 +91,11 @@ class PlatformForm(RestrictedFormMixin, ModelForm):
|
||||||
upper = ["usd", "otp"]
|
upper = ["usd", "otp"]
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
for up in upper:
|
for up in upper:
|
||||||
if up in self.fields[field].label:
|
if self.fields[field].label:
|
||||||
self.fields[field].label = self.fields[field].label.replace(
|
if up in self.fields[field].label:
|
||||||
up, up.upper()
|
self.fields[field].label = self.fields[field].label.replace(
|
||||||
)
|
up, up.upper()
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Platform
|
model = Platform
|
||||||
|
@ -117,6 +119,7 @@ class PlatformForm(RestrictedFormMixin, ModelForm):
|
||||||
"no_reference_amount_check_max_usd",
|
"no_reference_amount_check_max_usd",
|
||||||
"base_usd",
|
"base_usd",
|
||||||
"withdrawal_trigger",
|
"withdrawal_trigger",
|
||||||
|
"payees",
|
||||||
"enabled",
|
"enabled",
|
||||||
)
|
)
|
||||||
help_texts = {
|
help_texts = {
|
||||||
|
@ -139,9 +142,17 @@ class PlatformForm(RestrictedFormMixin, ModelForm):
|
||||||
"no_reference_amount_check_max_usd": "When ticked, when no reference was found and a trade is higher than this amount, we will not accept payment even if it is the only one with this amount.",
|
"no_reference_amount_check_max_usd": "When ticked, when no reference was found and a trade is higher than this amount, we will not accept payment even if it is the only one with this amount.",
|
||||||
"base_usd": "The amount in USD to keep in the platform.",
|
"base_usd": "The amount in USD to keep in the platform.",
|
||||||
"withdrawal_trigger": "The amount above the base USD to trigger a withdrawal.",
|
"withdrawal_trigger": "The amount above the base USD to trigger a withdrawal.",
|
||||||
|
"payees": "The wallet addresses to send profit concerning this platform to.",
|
||||||
"enabled": "Whether or not the platform connection is enabled.",
|
"enabled": "Whether or not the platform connection is enabled.",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payees = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Wallet.objects.all(),
|
||||||
|
widget=forms.CheckboxSelectMultiple,
|
||||||
|
help_text=Meta.help_texts["payees"],
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AdForm(RestrictedFormMixin, ModelForm):
|
class AdForm(RestrictedFormMixin, ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -214,9 +225,32 @@ class RequisitionForm(RestrictedFormMixin, ModelForm):
|
||||||
fields = (
|
fields = (
|
||||||
"payment_details",
|
"payment_details",
|
||||||
"transaction_source",
|
"transaction_source",
|
||||||
|
"payees",
|
||||||
)
|
)
|
||||||
|
|
||||||
help_texts = {
|
help_texts = {
|
||||||
"payment_details": "Shown once a user opens a trade.",
|
"payment_details": "Shown once a user opens a trade.",
|
||||||
"transaction_source": "Whether to check pending or booked transactions.",
|
"transaction_source": "Whether to check pending or booked transactions.",
|
||||||
|
"payees": "The wallet addresses to send profit concerning this requisition to.",
|
||||||
|
}
|
||||||
|
|
||||||
|
payees = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Wallet.objects.all(),
|
||||||
|
widget=forms.CheckboxSelectMultiple,
|
||||||
|
help_text=Meta.help_texts["payees"],
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class WalletForm(RestrictedFormMixin, ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Wallet
|
||||||
|
fields = (
|
||||||
|
"name",
|
||||||
|
"address",
|
||||||
|
)
|
||||||
|
|
||||||
|
help_texts = {
|
||||||
|
"name": "The name of the wallet.",
|
||||||
|
"address": "The XMR address to send funds to.",
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Generated by Django 4.1.7 on 2023-03-17 18:15
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0027_alter_requisition_payment_details'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='requisition',
|
||||||
|
name='throughput',
|
||||||
|
field=models.FloatField(default=0),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Wallet',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255)),
|
||||||
|
('address', models.CharField(max_length=255)),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='platform',
|
||||||
|
name='payees',
|
||||||
|
field=models.ManyToManyField(blank=True, to='core.wallet'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='requisition',
|
||||||
|
name='payees',
|
||||||
|
field=models.ManyToManyField(blank=True, to='core.wallet'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 4.1.7 on 2023-03-17 18:31
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0028_requisition_throughput_wallet_platform_payees_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='requisition',
|
||||||
|
name='id',
|
||||||
|
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='wallet',
|
||||||
|
name='id',
|
||||||
|
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -158,6 +158,17 @@ class Aggregator(models.Model):
|
||||||
return transaction
|
return transaction
|
||||||
|
|
||||||
|
|
||||||
|
class Wallet(models.Model):
|
||||||
|
"""
|
||||||
|
A wallet for a user.
|
||||||
|
"""
|
||||||
|
|
||||||
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
address = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
|
||||||
class Platform(models.Model):
|
class Platform(models.Model):
|
||||||
"""
|
"""
|
||||||
A connection to an arbitrage platform like AgoraDesk.
|
A connection to an arbitrage platform like AgoraDesk.
|
||||||
|
@ -192,7 +203,7 @@ class Platform(models.Model):
|
||||||
base_usd = models.FloatField(default=2800)
|
base_usd = models.FloatField(default=2800)
|
||||||
withdrawal_trigger = models.FloatField(default=200)
|
withdrawal_trigger = models.FloatField(default=200)
|
||||||
|
|
||||||
# payees = models.ManyToManyField(Wallet, blank=True)
|
payees = models.ManyToManyField(Wallet, blank=True)
|
||||||
|
|
||||||
enabled = models.BooleanField(default=True)
|
enabled = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
@ -488,21 +499,12 @@ class Trade(models.Model):
|
||||||
release_response = models.JSONField(default=dict)
|
release_response = models.JSONField(default=dict)
|
||||||
|
|
||||||
|
|
||||||
# class BankAccount(models.Model):
|
|
||||||
# """
|
|
||||||
# Extra information for an account.
|
|
||||||
# """
|
|
||||||
# account_id = models.CharField(max_length=255)
|
|
||||||
# payment_details = models.TextField()
|
|
||||||
|
|
||||||
# enabled = models.BooleanField(default=True)
|
|
||||||
|
|
||||||
|
|
||||||
class Requisition(models.Model):
|
class Requisition(models.Model):
|
||||||
"""
|
"""
|
||||||
A requisition for an Aggregator
|
A requisition for an Aggregator
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
aggregator = models.ForeignKey(Aggregator, on_delete=models.CASCADE)
|
aggregator = models.ForeignKey(Aggregator, on_delete=models.CASCADE)
|
||||||
requisition_id = models.CharField(max_length=255)
|
requisition_id = models.CharField(max_length=255)
|
||||||
|
@ -512,8 +514,8 @@ class Requisition(models.Model):
|
||||||
max_length=255, choices=TRANSACTION_SOURCE_CHOICES, default="booked"
|
max_length=255, choices=TRANSACTION_SOURCE_CHOICES, default="booked"
|
||||||
)
|
)
|
||||||
|
|
||||||
# throughput = models.FloatField(default=0)
|
throughput = models.FloatField(default=0)
|
||||||
# payees = models.ManyToManyField(Wallet, blank=True)
|
payees = models.ManyToManyField(Wallet, blank=True)
|
||||||
|
|
||||||
|
|
||||||
assets = {
|
assets = {
|
||||||
|
|
|
@ -271,6 +271,9 @@
|
||||||
<a class="navbar-item" href="{% url 'platforms' type='page' %}">
|
<a class="navbar-item" href="{% url 'platforms' type='page' %}">
|
||||||
Platform Connections
|
Platform Connections
|
||||||
</a>
|
</a>
|
||||||
|
<a class="navbar-item" href="{% url 'wallets' type='page' %}">
|
||||||
|
Wallets
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-item has-dropdown is-hoverable">
|
<div class="navbar-item has-dropdown is-hoverable">
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<td>
|
<td>
|
||||||
<a
|
<a
|
||||||
class="has-text-grey"
|
class="has-text-grey"
|
||||||
onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.id }}/');">
|
onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.id }}');">
|
||||||
<span class="icon" data-tooltip="Copy to clipboard">
|
<span class="icon" data-tooltip="Copy to clipboard">
|
||||||
<i class="fa-solid fa-copy" aria-hidden="true"></i>
|
<i class="fa-solid fa-copy" aria-hidden="true"></i>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
{% load cache %}
|
||||||
|
{% load cachalot cache %}
|
||||||
|
{% get_last_invalidation 'core.Ad' as last %}
|
||||||
|
{% include 'mixins/partials/notify.html' %}
|
||||||
|
{# cache 600 objects_ads request.user.id object_list type last #}
|
||||||
|
<table
|
||||||
|
class="table is-fullwidth is-hoverable"
|
||||||
|
hx-target="#{{ context_object_name }}-table"
|
||||||
|
id="{{ context_object_name }}-table"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-trigger="{{ context_object_name_singular }}Event from:body"
|
||||||
|
hx-get="{{ list_url }}">
|
||||||
|
<thead>
|
||||||
|
<th>id</th>
|
||||||
|
<th>user</th>
|
||||||
|
<th>name</th>
|
||||||
|
<th>address</th>
|
||||||
|
<th>actions</th>
|
||||||
|
</thead>
|
||||||
|
{% for item in object_list %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a
|
||||||
|
class="has-text-grey"
|
||||||
|
onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.id }}');">
|
||||||
|
<span class="icon" data-tooltip="Copy to clipboard">
|
||||||
|
<i class="fa-solid fa-copy" aria-hidden="true"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>{{ item.user }}</td>
|
||||||
|
<td>{{ item.name }}</td>
|
||||||
|
<td>{{ item.address }}</td>
|
||||||
|
<td>
|
||||||
|
<div class="buttons">
|
||||||
|
<button
|
||||||
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
hx-get="{% url 'wallet_update' type=type pk=item.id %}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#{{ type }}s-here"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
class="button">
|
||||||
|
<span class="icon-text">
|
||||||
|
<span class="icon">
|
||||||
|
<i class="fa-solid fa-pencil"></i>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
hx-delete="{% url 'wallet_delete' type=type pk=item.id %}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#modals-here"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
hx-confirm="Are you sure you wish to delete {{ item.name }}?"
|
||||||
|
class="button">
|
||||||
|
<span class="icon-text">
|
||||||
|
<span class="icon">
|
||||||
|
<i class="fa-solid fa-xmark"></i>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</table>
|
||||||
|
{# endcache #}
|
|
@ -0,0 +1,35 @@
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from mixins.views import ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate
|
||||||
|
from two_factor.views.mixins import OTPRequiredMixin
|
||||||
|
|
||||||
|
from core.forms import WalletForm
|
||||||
|
from core.models import Wallet
|
||||||
|
|
||||||
|
|
||||||
|
class WalletList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
|
||||||
|
list_template = "partials/wallet-list.html"
|
||||||
|
model = Wallet
|
||||||
|
page_title = "List of wallets"
|
||||||
|
|
||||||
|
list_url_name = "wallets"
|
||||||
|
list_url_args = ["type"]
|
||||||
|
|
||||||
|
submit_url_name = "wallet_create"
|
||||||
|
|
||||||
|
|
||||||
|
class WalletCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate):
|
||||||
|
model = Wallet
|
||||||
|
form_class = WalletForm
|
||||||
|
|
||||||
|
submit_url_name = "wallet_create"
|
||||||
|
|
||||||
|
|
||||||
|
class WalletUpdate(LoginRequiredMixin, OTPRequiredMixin, ObjectUpdate):
|
||||||
|
model = Wallet
|
||||||
|
form_class = WalletForm
|
||||||
|
|
||||||
|
submit_url_name = "wallet_update"
|
||||||
|
|
||||||
|
|
||||||
|
class WalletDelete(LoginRequiredMixin, OTPRequiredMixin, ObjectDelete):
|
||||||
|
model = Wallet
|
Loading…
Reference in New Issue