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

chore: fix sync_amount API + prettify conversion table #7049

Merged
merged 2 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
59 changes: 32 additions & 27 deletions app/dashboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,40 +126,45 @@ def amount(request):
"""
response = {}

try:
amount = str(request.GET.get('amount', '1'))
amount = str(request.GET.get('amount', '1'))

if not amount.replace('.','').isnumeric():
return HttpResponseBadRequest('not number')
if not amount.replace('.','').isnumeric():
return HttpResponseBadRequest('not number')

denomination = request.GET.get('denomination', 'ETH')
tokens = denomination.split(',')
denomination = request.GET.get('denomination', 'ETH')
tokens = denomination.split(',')

response = []
response = []

for token in tokens:
if token in settings.STABLE_COINS:
token = 'USDT'
if token == 'ETH':
amount_in_eth = float(amount)
else:
for token in tokens:
if token in settings.STABLE_COINS:
token = 'USDT'
if token == 'ETH':
amount_in_eth = float(amount)
else:
try:
amount_in_eth = convert_amount(amount, token, 'ETH')
amount_in_usdt = convert_amount(amount_in_eth, 'ETH', 'USDT')
except Exception as e:
logger.debug(e)
amount_in_eth = None
try:
if amount_in_eth:
amount_in_usdt = convert_amount(amount_in_eth, 'ETH', 'USDT')
else:
amount_in_usdt = convert_amount(amount, token, 'USDT')

response.append({
'token': token,
'amount': float(amount),
'eth': amount_in_eth,
'usdt': amount_in_usdt
})
except Exception as e:
logger.debug(e)
amount_in_usdt = None

return JsonResponse(response, safe=False)
except ConversionRateNotFoundError as e:
logger.debug(e)
raise Http404
except Exception as e:
logger.error(e)
raise Http404
response.append({
'token': token,
'amount': float(amount),
'eth': amount_in_eth,
'usdt': amount_in_usdt
})

return JsonResponse(response, safe=False)


@ratelimit(key='ip', rate='50/m', method=ratelimit.UNSAFE, block=True)
Expand Down
1 change: 1 addition & 0 deletions app/economy/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ConvRateAdmin(admin.ModelAdmin):

ordering = ['-id']
search_fields = ['from_currency', 'to_currency']
list_display =['id', 'from_currency', 'from_amount','to_currency', 'to_amount', 'source']


admin.site.register(ConversionRate, ConvRateAdmin)
Expand Down