forked from LBRYCommunity/lbry-sdk
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']
|
||||
|
||||
def _get_amount(self):
|
||||
if isinstance(self[self.currency_symbol]['amount'], float):
|
||||
return self[self.currency_symbol]['amount']
|
||||
amt = self[self.currency_symbol]['amount']
|
||||
if isinstance(amt, float):
|
||||
return amt
|
||||
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):
|
||||
# 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):
|
||||
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:
|
||||
if market.rate.currency_pair == (from_currency, to_currency):
|
||||
return amount * market.rate.spot
|
||||
for market in self.market_feeds:
|
||||
if market.rate.currency_pair[0] == from_currency:
|
||||
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):
|
||||
return {market: market.rate.as_dict() for market in self.market_feeds}
|
||||
|
|
Loading…
Add table
Reference in a new issue