Skip to content

Commit

Permalink
unstash (#8488)
Browse files Browse the repository at this point in the history
  • Loading branch information
owocki authored Mar 11, 2021
1 parent 50b6322 commit efc260e
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,55 @@ def __str__(self):
"""
return f'BountyFulfillment ID: ({self.pk}) - Bounty ID: ({self.bounty.pk})'

@property
def get_value_in_usdt_now(self):
return self.value_in_usdt_at_time(None)

@property
def get_value_in_usdt(self):
if self.status in self.OPEN_STATUSES:
return self.value_in_usdt_now
return self.value_in_usdt_then

@property
def value_in_usdt_then(self):
return self.value_in_usdt_at_time(self.created_on)

# TODO: DRY
def get_natural_value(self):
token = token_by_name(self.token_name)
decimals = token['decimals']
amount = self.payout_amount if self.payout_amount else 0
return float(amount) / 10**decimals

@property
def value_true(self):
return self.get_natural_value()


def value_in_usdt_at_time(self, at_time):
decimals = 10 ** 18
if self.token_name in ['USDT', 'USDC']:
return float(self.payout_amount / 10 ** 6)
if self.token_name in settings.STABLE_COINS:
return float(self.payout_amount / 10 ** 18)
try:
return round(float(convert_amount(self.value_true, self.token_name, 'USDT', at_time)), 2)
except ConversionRateNotFoundError:
try:
in_eth = round(float(convert_amount(self.value_true, self.token_name, 'ETH', at_time)), 2)
return round(float(convert_amount(in_eth, 'USDT', 'USDT', at_time)), 2)
except ConversionRateNotFoundError:
return None

@property
def token_value_in_usdt_now(self):
if self.token_name in settings.STABLE_COINS:
return 1
try:
return round(convert_token_to_usdt(self.token_name), 2)
except ConversionRateNotFoundError:
return None

@property
def fulfiller_email(self):
Expand Down Expand Up @@ -2056,7 +2105,7 @@ def psave_bounty_fulfilll(sender, instance, **kwargs):
"org_profile":instance.bounty.org_profile,
"from_profile":instance.bounty.bounty_owner_profile,
"to_profile":instance.profile,
"value_usd":instance.bounty.value_in_usdt_then,
"value_usd":instance.value_in_usdt_then,
"url":instance.bounty.url,
"network":instance.bounty.network,
"txid": instance.payout_tx_id,
Expand Down

0 comments on commit efc260e

Please sign in to comment.