Skip to content

Commit

Permalink
Filter options for token pair and allow coingecko to update price of …
Browse files Browse the repository at this point in the history
…tokens
  • Loading branch information
guanana committed Oct 28, 2021
1 parent 70617a6 commit 36277af
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion vanir/core/account/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import messages
from django.db.models import Q
from django.shortcuts import redirect
from django.urls import reverse, reverse_lazy
from django.views.generic import DetailView
Expand All @@ -10,6 +11,7 @@
from vanir.core.exchange.libs.exchanges import ExtendedExchange
from vanir.core.token.models import Token
from vanir.core.token.tables import TokenTableValue
from vanir.utils.datasource.coingecko import CoinGeckoVanir
from vanir.utils.views import (
ObjectCreateView,
ObjectDeleteView,
Expand Down Expand Up @@ -49,6 +51,23 @@ class AccountUpdateView(ObjectUpdateView):
model = Account
fields = ("name", "exchange", "api_key", "secret", "default", "token_pair")

# Filter token_pair to only allow certain standard values and avoid
# user selecting random tokens
def get_form(self, *args, **kwargs):
form = super().get_form(*args, **kwargs)
if isinstance(self.object.exchange_obj, CoinGeckoVanir):
form.fields["token_pair"].queryset = Token.objects.filter(
Q(token_type="FIAT") | Q(symbol="USDT")
)
else:
form.fields["token_pair"].queryset = Token.objects.filter(
Q(token_type="FIAT")
| Q(symbol="BTC")
| Q(symbol="ETH")
| Q(symbol="USDT")
)
return form


class AccountDetailView(DetailView):
model = Account
Expand All @@ -72,7 +91,9 @@ class AccountTokenBulkUpdateValueView(DetailView):

def get(self, request, *args, **kwargs):
super().get(request, *args, **kwargs)
if self.object.extended_exchange:
if self.object.extended_exchange or isinstance(
self.object.exchange_obj, CoinGeckoVanir
):
update_balance(self.object)
messages.info(request, "Tokens updated")
else:
Expand Down

0 comments on commit 36277af

Please sign in to comment.