Skip to content

Commit

Permalink
app: Refactor value_in_usdt into value_in_usdt_now.
Browse files Browse the repository at this point in the history
The bounty property and all methods were renamed to use value_in_usdt_now.

Issue: gitcoinco#693
  • Loading branch information
cryptomental committed Apr 9, 2018
1 parent d3a69bd commit 1d8962a
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 51 deletions.
10 changes: 5 additions & 5 deletions app/assets/v2/js/pages/bounty_details.js
Expand Up @@ -53,8 +53,8 @@ var rows = [
'github_url',
'value_in_token',
'value_in_eth',
'value_in_usdt',
'token_value_in_usdt',
'value_in_usdt_now',
'token_value_in_usdt_now',
'web3_created',
'status',
'bounty_owner_address',
Expand Down Expand Up @@ -150,15 +150,15 @@ var callbacks = {
}
return [ 'Amount (ETH)', Math.round((parseInt(val) / Math.pow(10, 18)) * 1000) / 1000 ];
},
'value_in_usdt': function(key, val, result) {
'value_in_usdt_now': function(key, val, result) {
if (val === null) {
return [ null, null ];
}
return [ 'Amount_usd', val ];
},
'token_value_in_usdt': function(key, val, result) {
'token_value_in_usdt_now': function(key, val, result) {
if (val === null || typeof val == 'undefined') {
$('#value_in_usdt_wrapper').addClass('hidden');
$('#value_in_usdt_now_wrapper').addClass('hidden');
return [ null, null ];
}
return [ 'Token_amount_usd', '$' + val + '/' + result['token_name'] ];
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/dashboard.js
Expand Up @@ -204,7 +204,7 @@ var process_stats = function(results) {
for (var i = 0; i < results.length; i++) {
var result = results[i];

worth_usdt += result['value_in_usdt'];
worth_usdt += result['value_in_usdt_now'];
worth_eth += result['value_in_eth'];
var token = result['token_name'];

Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/embed.py
Expand Up @@ -203,9 +203,9 @@ def embed(request):

draw.multiline_text(align="left", xy=(x + 100 - bounty_value_size[0]/2, y + 67), text=f"{round(bounty.value_true, 2)} {bounty.token_name}", fill=(44, 35, 169), font=p)

bounty_value_size = tmp.textsize(f"{round(bounty.value_in_usdt, 2)} USD", p)
bounty_value_size = tmp.textsize(f"{round(bounty.value_in_usdt_now, 2)} USD", p)

draw.multiline_text(align="left", xy=(x + 310 - bounty_value_size[0]/2, y + 67), text=f"{round(bounty.value_in_usdt, 2)} USD", fill=(45, 168, 116), font=p)
draw.multiline_text(align="left", xy=(x + 310 - bounty_value_size[0]/2, y + 67), text=f"{round(bounty.value_in_usdt_now, 2)} USD", fill=(45, 168, 116), font=p)


# blank slate
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/management/commands/activity_report.py
Expand Up @@ -92,7 +92,7 @@ def format_bounty(self, bounty):
'amount': bounty.get_natural_value(),
'denomination': bounty.token_name,
'amount_eth': bounty.value_in_eth / 10**18 if bounty.value_in_eth else None,
'amount_usdt': bounty.value_in_usdt,
'amount_usdt': bounty.value_in_usdt_now,
'from_address': bounty.bounty_owner_address,
'claimee_address': claimee_address,
'repo': self.extract_github_repo(bounty.github_url),
Expand All @@ -115,7 +115,7 @@ def format_tip(self, tip):
'amount': tip.get_natural_value() * 10**18,
'denomination': tip.tokenName,
'amount_eth': tip.value_in_eth,
'amount_usdt': tip.value_in_usdt,
'amount_usdt': tip.value_in_usdt_now,
'from_address': tip.from_address,
'claimee_address': tip.receive_address,
'repo': self.extract_github_repo(tip.github_url) if tip.github_url else '',
Expand Down
14 changes: 7 additions & 7 deletions app/dashboard/models.py
Expand Up @@ -365,7 +365,7 @@ def value_in_eth(self):
return None

@property
def value_in_usdt(self):
def value_in_usdt_now(self):
decimals = 10**18
if self.token_name == 'USDT':
return float(self.value_in_token)
Expand All @@ -377,7 +377,7 @@ def value_in_usdt(self):
return None

@property
def token_value_in_usdt(self):
def token_value_in_usdt_now(self):
return round(convert_token_to_usdt(self.token_name), 2)

@property
Expand Down Expand Up @@ -603,7 +603,7 @@ def value_in_eth(self):

# TODO: DRY
@property
def value_in_usdt(self):
def value_in_usdt_now(self):
decimals = 1
if self.tokenName == 'USDT':
return float(self.amount)
Expand All @@ -616,7 +616,7 @@ def value_in_usdt(self):

# TODO: DRY
@property
def token_value_in_usdt(self):
def token_value_in_usdt_now(self):
return round(convert_token_to_usdt(self.token_name), 2)

@property
Expand Down Expand Up @@ -651,7 +651,7 @@ def psave_bounty(sender, instance, **kwargs):
}

instance.idx_status = instance.status
instance._val_usd_db = instance.value_in_usdt if instance.value_in_usdt else 0
instance._val_usd_db = instance.value_in_usdt_now if instance.value_in_usdt_now else 0
instance.idx_experience_level = idx_experience_level.get(instance.experience_level, 0)
instance.idx_project_length = idx_project_length.get(instance.project_length, 0)

Expand Down Expand Up @@ -824,8 +824,8 @@ def desc(self):
def stats(self):
bounties = self.bounties.stats_eligible()
loyalty_rate = 0
total_funded = sum([bounty.value_in_usdt if bounty.value_in_usdt else 0 for bounty in bounties if bounty.is_funder(self.handle)])
total_fulfilled = sum([bounty.value_in_usdt if bounty.value_in_usdt else 0 for bounty in bounties if bounty.is_hunter(self.handle)])
total_funded = sum([bounty.value_in_usdt_now if bounty.value_in_usdt_now else 0 for bounty in bounties if bounty.is_funder(self.handle)])
total_fulfilled = sum([bounty.value_in_usdt_now if bounty.value_in_usdt_now else 0 for bounty in bounties if bounty.is_hunter(self.handle)])
print(total_funded, total_fulfilled)
role = 'newbie'
if total_funded > total_fulfilled:
Expand Down
10 changes: 5 additions & 5 deletions app/dashboard/notifications.py
Expand Up @@ -136,7 +136,7 @@ def maybe_market_to_twitter(bounty, event_name):
new_tweet = tweet_txt.format(
round(bounty.get_natural_value(), 4),
bounty.token_name,
f"({bounty.value_in_usdt} USD @ ${round(convert_token_to_usdt(bounty.token_name),2)}/{bounty.token_name})" if bounty.value_in_usdt else "",
f"({bounty.value_in_usdt_now} USD @ ${round(convert_token_to_usdt(bounty.token_name),2)}/{bounty.token_name})" if bounty.value_in_usdt_now else "",
url
)
new_tweet = new_tweet + " " + github_org_to_twitter_tags(bounty.org_name) # twitter tags
Expand Down Expand Up @@ -176,7 +176,7 @@ def maybe_market_to_slack(bounty, event_name):
usdt_details = ""
try:
conv_details = f"@ (${round(convert_token_to_usdt(bounty.token_name),2)}/{bounty.token_name})"
usdt_details = f"({bounty.value_in_usdt} USD {conv_details} "
usdt_details = f"({bounty.value_in_usdt_now} USD {conv_details} "
except:
pass #no USD conversion rate
title = bounty.title if bounty.title else bounty.github_url
Expand Down Expand Up @@ -256,7 +256,7 @@ def build_github_notification(bounty, event_name, profile_pairs=None):
msg = ''
usdt_value = ""
try:
usdt_value = f"({round(bounty.value_in_usdt, 2)} USD @ ${round(convert_token_to_usdt(bounty.token_name), 2)}/{bounty.token_name})" if bounty.value_in_usdt else ""
usdt_value = f"({round(bounty.value_in_usdt_now, 2)} USD @ ${round(convert_token_to_usdt(bounty.token_name), 2)}/{bounty.token_name})" if bounty.value_in_usdt_now else ""
except:
pass # no USD conv rate available
natural_value = round(bounty.get_natural_value(), 4)
Expand Down Expand Up @@ -414,7 +414,7 @@ def amount_usdt_open_work():
"""
from dashboard.models import Bounty
bounties = Bounty.objects.filter(network='mainnet', current_bounty=True, idx_status__in=['open', 'submitted'])
return round(sum([b.value_in_usdt for b in bounties if b.value_in_usdt]), 2)
return round(sum([b.value_in_usdt_now for b in bounties if b.value_in_usdt_now]), 2)

def maybe_market_tip_to_github(tip):
"""Post a Github comment for the specified Tip.
Expand All @@ -437,7 +437,7 @@ def maybe_market_tip_to_github(tip):
_comments = "\n\nThe sender had the following public comments: \n> " \
f"{tip.comments_public}" if tip.comments_public else ""
try:
value_in_usd = f"({tip.value_in_usdt} USD @ ${round(convert_token_to_usdt(tip.tokenName), 2)}/{tip.tokenName})" if tip.value_in_usdt else ""
value_in_usd = f"({tip.value_in_usdt_now} USD @ ${round(convert_token_to_usdt(tip.tokenName), 2)}/{tip.tokenName})" if tip.value_in_usdt_now else ""
except Exception:
pass # no USD conv rate
msg = f"⚡️ A tip worth {round(tip.amount, 5)} {warning} {tip.tokenName} {value_in_usd} has been " \
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/router.py
Expand Up @@ -69,7 +69,7 @@ class Meta:
'bounty_owner_email', 'bounty_owner_github_username',
'fulfillments', 'interested', 'is_open', 'expires_date', 'raw_data',
'metadata', 'current_bounty', 'value_in_eth',
'token_value_in_usdt', 'value_in_usdt', 'status', 'now',
'token_value_in_usdt_now', 'value_in_usdt_now', 'status', 'now',
'avatar_url', 'value_true', 'issue_description', 'network',
'org_name', 'pk', 'issue_description_text',
'standard_bounties_id', 'web3_type', 'can_submit_after_expiration_date',
Expand Down
6 changes: 3 additions & 3 deletions app/dashboard/templates/bounty_details.html
Expand Up @@ -109,11 +109,11 @@ <h4 id="title" class="font-title"></h4>
<span id="value_in_token"></span>
</p>
</div>
<div id=value_in_usdt_wrapper class="tag usd">
<div id=value_in_usdt_now_wrapper class="tag usd">
<p>
<span id="value_in_usdt"></span>
<span id="value_in_usdt_now"></span>
<span>USD @ </span>
<span id="token_value_in_usdt"></span>
<span id="token_value_in_usdt_now"></span>
</p>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/templates/dashboard.html
Expand Up @@ -107,10 +107,10 @@ <h3>{% trans "No results found." %}</h3>
<span>[[:token_name]]</span>
</p>
</div>
[[if value_in_usdt]]
[[if value_in_usdt_now]]
<div class="tag usd">
<p>
[[:value_in_usdt]]
[[:value_in_usdt_now]]
<span>USD</span>
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/templates/profile_details.html
Expand Up @@ -119,7 +119,7 @@ <h4>{% blocktrans %}{{profile.handle}} has received these tips{% endblocktrans %
<div class="amount">
<a class="btn btn-sm btn-darkBlue font-smaller-2">
{{tip.amount}} {{tip.tokenName}},
{{tip.value_in_usdt}}
{{tip.value_in_usdt_now}}
USD
</a>
<p>
Expand Down Expand Up @@ -189,7 +189,7 @@ <h6>
<div class="amount">
<a class="btn btn-sm btn-darkBlue font-smaller-2">
{{b.value_true}} {{b.token_name}},
{{b.value_in_usdt}}
{{b.value_in_usdt_now}}
USD
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/templates/shared/nav_auth.html
Expand Up @@ -51,7 +51,7 @@
{% for tip in unclaimed_tips %}
<a class="dropdown-item" href="{{ tip.url }}">
<i class="fas fa-dollar-sign"></i>
{% blocktrans %}Claim ${{ tip.value_in_usdt }} Tip {% endblocktrans %}
{% blocktrans %}Claim ${{ tip.value_in_usdt_now }} Tip {% endblocktrans %}
</a>
{% endfor %}
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/tests/test_dashboard_models.py
Expand Up @@ -83,7 +83,7 @@ def test_bounty(self):
assert bounty.status == 'expired'
assert bounty.value_true == 3e-18
assert bounty.value_in_eth == 3
assert bounty.value_in_usdt == 0
assert bounty.value_in_usdt_now == 0
assert 'ago 5 Feature Intermediate' in bounty.desc
assert bounty.is_legacy is False
assert bounty.get_github_api_url() == 'https://api.github.com/repos/gitcoinco/web/issues/11'
Expand All @@ -104,7 +104,7 @@ def test_tip(self):
assert str(tip) == '(net) - PENDING 7 ETH to fred, created: today, expires: tomorrow'
assert tip.get_natural_value() == 7e-18
assert tip.value_in_eth == 7
assert tip.value_in_usdt == 14
assert tip.value_in_usdt_now == 14
assert tip.status == 'PENDING'

def test_interest(self):
Expand Down
2 changes: 1 addition & 1 deletion app/economy/management/commands/get_prices.py
Expand Up @@ -110,7 +110,7 @@ def polo():
for b in Bounty.objects.all():
print('refreshed {}'.format(b.pk))
try:
b._val_usd_db = b.value_in_usdt
b._val_usd_db = b.value_in_usdt_now
b.save()
except Exception as e:
print(e)
Expand Down
16 changes: 8 additions & 8 deletions app/marketing/mails.py
Expand Up @@ -148,13 +148,13 @@ def reject_faucet_request(fr):


def new_bounty(bounty, to_emails=None):
if not bounty or not bounty.value_in_usdt:
if not bounty or not bounty.value_in_usdt_now:
return

if to_emails is None:
to_emails = []

subject = _("⚡️ New Funded Issue Match worth") + f" {bounty.value_in_usdt} USD @ " \
subject = _("⚡️ New Funded Issue Match worth") + f" {bounty.value_in_usdt_now} USD @ " \
f"${convert_token_to_usdt(bounty.token_name)}/{bounty.token_name} {bounty.keywords})"

for to_email in to_emails:
Expand All @@ -178,7 +178,7 @@ def weekly_roundup(to_emails=None):


def new_work_submission(bounty, to_emails=None):
if not bounty or not bounty.value_in_usdt:
if not bounty or not bounty.value_in_usdt_now:
return

if to_emails is None:
Expand All @@ -195,7 +195,7 @@ def new_work_submission(bounty, to_emails=None):


def new_bounty_rejection(bounty, to_emails=None):
if not bounty or not bounty.value_in_usdt:
if not bounty or not bounty.value_in_usdt_now:
return

subject = gettext("😕 Work Submission Rejected for {} 😕").format(bounty.title_or_desc)
Expand All @@ -212,7 +212,7 @@ def new_bounty_rejection(bounty, to_emails=None):


def new_bounty_acceptance(bounty, to_emails=None):
if not bounty or not bounty.value_in_usdt:
if not bounty or not bounty.value_in_usdt_now:
return

if to_emails is None:
Expand All @@ -239,7 +239,7 @@ def new_match(to_emails, bounty, github_username):


def bounty_expire_warning(bounty, to_emails=None):
if not bounty or not bounty.value_in_usdt:
if not bounty or not bounty.value_in_usdt_now:
return

if to_emails is None:
Expand All @@ -262,7 +262,7 @@ def bounty_expire_warning(bounty, to_emails=None):


def bounty_startwork_expire_warning(to_email, bounty, interest, time_delta_days):
if not bounty or not bounty.value_in_usdt:
if not bounty or not bounty.value_in_usdt_now:
return

from_email = settings.CONTACT_EMAIL
Expand All @@ -274,7 +274,7 @@ def bounty_startwork_expire_warning(to_email, bounty, interest, time_delta_days)


def bounty_startwork_expired(to_email, bounty, interest, time_delta_days):
if not bounty or not bounty.value_in_usdt:
if not bounty or not bounty.value_in_usdt_now:
return

from_email = settings.CONTACT_EMAIL
Expand Down
4 changes: 2 additions & 2 deletions app/marketing/management/commands/assemble_leaderboards.py
Expand Up @@ -113,7 +113,7 @@ def sum_bounties(b, usernames):


def sum_tips(t, usernames):
val_usd = t.value_in_usdt
val_usd = t.value_in_usdt_now
for username in usernames:
add_element('all_fulfilled', username, val_usd)
add_element('all_earners', username, val_usd)
Expand Down Expand Up @@ -161,7 +161,7 @@ def handle(self, *args, **options):
tips = Tip.objects.all()

for t in tips:
if not t.value_in_usdt:
if not t.value_in_usdt_now:
continue
usernames = []
if t.username:
Expand Down
2 changes: 1 addition & 1 deletion app/marketing/management/commands/pull_stats.py
Expand Up @@ -283,7 +283,7 @@ def joe_dominance_index():
val=val,
)

val = int(100 * sum([(b.value_in_usdt if b.value_in_usdt else 0) for b in joe_bounties]) / sum([(b.value_in_usdt if b.value_in_usdt else 0) for b in all_bounties]))
val = int(100 * sum([(b.value_in_usdt_now if b.value_in_usdt_now else 0) for b in joe_bounties]) / sum([(b.value_in_usdt_now if b.value_in_usdt_now else 0) for b in all_bounties]))
Stat.objects.create(
key='joe_dominance_index_{}_value'.format(days),
val=val,
Expand Down
4 changes: 2 additions & 2 deletions app/retail/templates/emails/bounty.html
Expand Up @@ -80,8 +80,8 @@

<p>
<b>Amount:</b> {{bounty.value_true}} {{bounty.token_name}}
{% if bounty.value_in_usdt %}
(about {{bounty.value_in_usdt}} USD @ ${{bounty.token_value_in_usdt}}/{{bounty.token_name}})
{% if bounty.value_in_usdt_now %}
(about {{bounty.value_in_usdt_now}} USD @ ${{bounty.token_value_in_usdt_now}}/{{bounty.token_name}})
{% endif %}
</p>

Expand Down
4 changes: 2 additions & 2 deletions app/retail/templates/emails/bounty.txt
@@ -1,7 +1,7 @@
* Github URL: {{bounty.github_url}}
* Value: {{bounty.value_true}} {{bounty.token_name}}
{% if bounty.value_in_usdt %}
(about {{bounty.value_in_usdt}} USD @ ${{bounty.token_value_in_usdt}}/{{bounty.token_name}})
{% if bounty.value_in_usdt_now %}
(about {{bounty.value_in_usdt_now}} USD @ ${{bounty.token_value_in_usdt_now}}/{{bounty.token_name}})
{% endif %}
* Status: {{bounty.status}}
* View More: {{bounty.absolute_url}}
4 changes: 2 additions & 2 deletions docs/API.md
Expand Up @@ -42,7 +42,7 @@ The bounties endpoint provides a listing of bounties and their current status. T
| `expires_date` | `date_time` | Date before which the bounty must be compelted |
| `raw_data` | `array` | Raw contract data, see the example below for more information |
| `value_in_eth` | `integer` | Value of the bounty in Ethereum |
| `value_in_usdt` | `float` | Approximation of current value in USD |
| `value_in_usdt_now` | `float` | Approximation of current value in USD |
| `now` | `date_time` | Current date_time on the server |

**Current Status**
Expand Down Expand Up @@ -130,7 +130,7 @@ By passing an `order_by` parameter you can order the data by the provided key. E
},
"current_bounty": true,
"value_in_eth": 1.0e+18,
"value_in_usdt": 280.65,
"value_in_usdt_now": 280.65,
"status": "expired",
"now": "2017-09-24T18:59:53.964344Z"
},
Expand Down

0 comments on commit 1d8962a

Please sign in to comment.