mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-27 07:23:24 +00:00
fix case where to and from currencies are the same
This commit is contained in:
parent
4387025c48
commit
15d276b0bc
2 changed files with 11 additions and 3 deletions
|
@ -43,10 +43,15 @@ class LBRYFeeValidator(dict):
|
||||||
self.address = self[self.currency_symbol]['address']
|
self.address = self[self.currency_symbol]['address']
|
||||||
|
|
||||||
def _get_amount(self):
|
def _get_amount(self):
|
||||||
if isinstance(self[self.currency_symbol]['amount'], float):
|
amt = self[self.currency_symbol]['amount']
|
||||||
return self[self.currency_symbol]['amount']
|
if isinstance(amt, float):
|
||||||
|
return amt
|
||||||
else:
|
else:
|
||||||
return float(self[self.currency_symbol]['amount'])
|
try:
|
||||||
|
return float(amt)
|
||||||
|
except TypeError:
|
||||||
|
log.error('Failed to convert %s to float', amt)
|
||||||
|
raise
|
||||||
|
|
||||||
def _verify_fee(self, currency, f):
|
def _verify_fee(self, currency, f):
|
||||||
# str in case someone made a claim with a wierd fee
|
# str in case someone made a claim with a wierd fee
|
||||||
|
|
|
@ -131,12 +131,15 @@ class ExchangeRateManager(object):
|
||||||
|
|
||||||
def convert_currency(self, from_currency, to_currency, amount):
|
def convert_currency(self, from_currency, to_currency, amount):
|
||||||
log.info("Converting %f %s to %s" % (amount, from_currency, to_currency))
|
log.info("Converting %f %s to %s" % (amount, from_currency, to_currency))
|
||||||
|
if from_currency == to_currency:
|
||||||
|
return amount
|
||||||
for market in self.market_feeds:
|
for market in self.market_feeds:
|
||||||
if market.rate.currency_pair == (from_currency, to_currency):
|
if market.rate.currency_pair == (from_currency, to_currency):
|
||||||
return amount * market.rate.spot
|
return amount * market.rate.spot
|
||||||
for market in self.market_feeds:
|
for market in self.market_feeds:
|
||||||
if market.rate.currency_pair[0] == from_currency:
|
if market.rate.currency_pair[0] == from_currency:
|
||||||
return self.convert_currency(market.rate.currency_pair[1], to_currency, amount * market.rate.spot)
|
return self.convert_currency(market.rate.currency_pair[1], to_currency, amount * market.rate.spot)
|
||||||
|
raise Exception('Unable to convert {} from {} to {}'.format(amount, from_current, to_currency))
|
||||||
|
|
||||||
def fee_dict(self):
|
def fee_dict(self):
|
||||||
return {market: market.rate.as_dict() for market in self.market_feeds}
|
return {market: market.rate.as_dict() for market in self.market_feeds}
|
||||||
|
|
Loading…
Add table
Reference in a new issue