client: Hide offers where coins are not enabled.
Better rate calculation.
This commit is contained in:
parent
5eb34a8c4b
commit
6516c6d138
@ -5134,6 +5134,12 @@ class BasicSwap(BaseApp):
|
||||
if offset is not None:
|
||||
q = q.offset(offset)
|
||||
for row in q:
|
||||
# Show offers for enabled coins only
|
||||
try:
|
||||
ci_from = self.ci(row.coin_from)
|
||||
ci_to = self.ci(row.coin_to)
|
||||
except Exception as e:
|
||||
continue
|
||||
rv.append(row)
|
||||
return rv
|
||||
finally:
|
||||
|
@ -447,7 +447,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
errors.append('Amount To')
|
||||
|
||||
if 'amt_to' in parsed_data and 'amt_from' in parsed_data:
|
||||
parsed_data['rate'] = int((parsed_data['amt_to'] / parsed_data['amt_from']) * ci_from.COIN())
|
||||
parsed_data['rate'] = ci_from.make_int(parsed_data['amt_to'] / parsed_data['amt_from'], r=1)
|
||||
|
||||
if b'step1' in form_data:
|
||||
if len(errors) == 0 and b'continue' in form_data:
|
||||
|
@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019-2020 tecnovert
|
||||
# Copyright (c) 2019-2021 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import secrets
|
||||
import hashlib
|
||||
import secrets
|
||||
import unittest
|
||||
|
||||
import basicswap.contrib.ed25519_fast as edf
|
||||
@ -216,28 +216,52 @@ class Test(unittest.TestCase):
|
||||
def test_rate(self):
|
||||
scale_from = 8
|
||||
scale_to = 12
|
||||
amount_from = 100 * (10 ** scale_from)
|
||||
rate = 0.1 * (10 ** scale_to)
|
||||
amount_from = make_int(100, scale_from)
|
||||
rate = make_int(0.1, scale_to)
|
||||
|
||||
amount_to = int((amount_from * rate) // (10 ** scale_from))
|
||||
assert('100.00000000' == format_amount(amount_from, scale_from))
|
||||
assert('10.000000000000' == format_amount(amount_to, scale_to))
|
||||
|
||||
rate_check = int((amount_to / amount_from) * (10 ** scale_from))
|
||||
rate_check = make_int((amount_to / amount_from), scale_from)
|
||||
assert(rate == rate_check)
|
||||
|
||||
scale_from = 12
|
||||
scale_to = 8
|
||||
amount_from = 1 * (10 ** scale_from)
|
||||
rate = 12 * (10 ** scale_to)
|
||||
amount_from = make_int(1, scale_from)
|
||||
rate = make_int(12, scale_to)
|
||||
|
||||
amount_to = int((amount_from * rate) // (10 ** scale_from))
|
||||
assert('1.000000000000' == format_amount(amount_from, scale_from))
|
||||
assert('12.00000000' == format_amount(amount_to, scale_to))
|
||||
|
||||
rate_check = int((amount_to / amount_from) * (10 ** scale_from))
|
||||
rate_check = make_int((amount_to / amount_from), scale_from)
|
||||
assert(rate == rate_check)
|
||||
|
||||
scale_from = 8
|
||||
scale_to = 8
|
||||
amount_from = make_int(0.073, scale_from)
|
||||
amount_to = make_int(10, scale_to)
|
||||
rate = make_int(amount_to / amount_from, scale_to, r=1)
|
||||
amount_to_recreate = int((amount_from * rate) // (10 ** scale_from))
|
||||
assert('10.00000000' == format_amount(amount_to_recreate, scale_to))
|
||||
|
||||
scale_from = 8
|
||||
scale_to = 12
|
||||
amount_from = make_int(10.0, scale_from)
|
||||
amount_to = make_int(0.06935, scale_to)
|
||||
rate = make_int(amount_to / amount_from, scale_from, r=1)
|
||||
amount_to_recreate = int((amount_from * rate) // (10 ** scale_from))
|
||||
assert('0.069350000000' == format_amount(amount_to_recreate, scale_to))
|
||||
|
||||
scale_from = 12
|
||||
scale_to = 8
|
||||
amount_from = make_int(0.06935, scale_from)
|
||||
amount_to = make_int(10.0, scale_to)
|
||||
rate = make_int(amount_to / amount_from, scale_from, r=1)
|
||||
amount_to_recreate = int((amount_from * rate) // (10 ** scale_from))
|
||||
assert('10.00000000' == format_amount(amount_to_recreate, scale_to))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user