Skip to content

Commit

Permalink
Adding conversion rate to bounties
Browse files Browse the repository at this point in the history
Fixes: gitcoinco#165

adding usdt conversion to all bounty marketing.

Fixing: gitcoinco#165

Fixing line issue

Updating html to display the eth price.

Fixing build issue

Removing unused property per code review.

fixing issue with cherry pick

Fixing build issue with imports
  • Loading branch information
bhenze committed Feb 14, 2018
1 parent c535c54 commit eda5222
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 15 deletions.
7 changes: 7 additions & 0 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var rows = [
'value_in_token',
'value_in_eth',
'value_in_usdt',
'eth_value_in_usdt',
'web3_created',
'status',
'bounty_owner_address',
Expand Down Expand Up @@ -131,6 +132,12 @@ var callbacks = {
}
return [ "Amount_usd" , val];
},
'eth_value_in_usdt': function(key, val, result){
if(val == null){
return [null, null];
}
return [ "Eth_amount_usd" , val];
},
'web3_created': function(key, val, result){
return [ "updated" , timeDifference(new Date(result['now']), new Date(result['created_on']))];
},
Expand Down
4 changes: 3 additions & 1 deletion app/dashboard/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import requests
from dashboard.models import Bounty
from economy.utils import get_eth_to_usdt
from github.utils import get_user, org_name
from PIL import Image, ImageDraw, ImageFont, ImageOps
from ratelimit.decorators import ratelimit
Expand Down Expand Up @@ -218,9 +219,10 @@ def embed(request):
i += 1
value_eth = str(round(bounty.value_in_eth/10**18, 2)) + "ETH" if bounty.value_in_eth else ""
value_in_usdt = str(round(bounty.value_in_usdt, 2)) + "USD" if bounty.value_in_usdt else ""
eth_value_in_usdt = str(round(get_eth_to_usdt(), 2)) + "/ETH"
value_native = "{} {}".format(round(bounty.value_true, 2), bounty.token_name)

value = "{}, {}".format(value_eth, value_in_usdt)
value = "{}, (${} @ {})".format(value_eth, value_in_usdt, eth_value_in_usdt)
if not value_eth:
value = value_native
text = "{}{}\n{}\n\nWorth: {}".format("", line, wrap_text(bounty.title_or_desc, 30), value)
Expand Down
11 changes: 10 additions & 1 deletion app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import requests
from dashboard.tokens import addr_to_token
from economy.models import SuperModel
from economy.utils import convert_amount
from economy.utils import convert_amount, get_eth_to_usdt
from github.utils import HEADERS, TOKEN_URL, build_auth_dict, get_issue_comments, get_user, org_name
from rest_framework import serializers

Expand Down Expand Up @@ -279,6 +279,10 @@ def value_in_usdt(self):
except Exception:
return None

@property
def eth_value_in_usdt(self):
return round(get_eth_to_usdt(), 4)

@property
def desc(self):
return "{} {} {} {}".format(naturaltime(self.web3_created), self.idx_project_length, self.bounty_type,
Expand Down Expand Up @@ -429,6 +433,11 @@ def value_in_usdt(self):
except Exception:
return None

# TODO: DRY
@property
def eth_value_in_usdt(self):
return round(get_eth_to_usdt(), 4)

@property
def status(self):
if self.receive_txid:
Expand Down
12 changes: 6 additions & 6 deletions app/dashboard/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import rollbar
import twitter
from economy.utils import get_eth_to_usdt
from github.utils import delete_issue_comment, patch_issue_comment, post_issue_comment
from marketing.mails import tip_email
from marketing.models import GithubOrgToTwitterHandleMapping
Expand Down Expand Up @@ -85,7 +86,7 @@ def maybe_market_to_twitter(bounty, event_name):
new_tweet = tweet_txt.format(
round(bounty.get_natural_value(), 4),
bounty.token_name,
("(${})".format(bounty.value_in_usdt) if bounty.value_in_usdt else ""),
("(${} @ {}/ETH)".format(bounty.value_in_usdt, get_eth_to_usdt()) if bounty.value_in_usdt else ""),
shortener.short(bounty.get_absolute_url())
)
new_tweet = new_tweet + " " + github_org_to_twitter_tags(bounty.org_name) #twitter tags
Expand Down Expand Up @@ -123,7 +124,7 @@ def maybe_market_to_slack(bounty, event_name):
return False

title = bounty.title if bounty.title else bounty.github_url
msg = "{} worth {} {}: {} \n\n{}&slack=1".format(event_name.replace('bounty', 'funded_issue'), round(bounty.get_natural_value(), 4), bounty.token_name, title, bounty.get_absolute_url())
msg = "{} worth {} {} (${} @ {}/ETH): {} \n\n{}&slack=1".format(event_name.replace('bounty', 'funded_issue'), round(bounty.get_natural_value(), 4), bounty.value_in_usdt, get_eth_to_usdt(), bounty.token_name, title, bounty.get_absolute_url())

try:
channel = 'notif-gitcoin'
Expand Down Expand Up @@ -214,7 +215,7 @@ def maybe_market_to_github(bounty, event_name, interested=None):

# prepare message
msg = ''
usdt_value = "(" + str(round(bounty.value_in_usdt, 2)) + " USD)" if bounty.value_in_usdt else ""
usdt_value = "(" + str(round(bounty.value_in_usdt, 2)) + " USD @ $" + str(round(get_eth_to_usdt())) + "/ETH)" if bounty.value_in_usdt else ""
if event_name == 'new_bounty':
msg = "__This issue now has a funding of {} {} {} attached to it.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n"
msg = msg.format(
Expand Down Expand Up @@ -320,7 +321,6 @@ def amount_usdt_open_work():
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]), 2)


def maybe_market_tip_to_github(tip):
"""Post a Github comment for the specified Tip.
Expand All @@ -343,8 +343,8 @@ def maybe_market_tip_to_github(tip):
_from = " from {}".format(tip.from_name) if tip.from_name else ""
warning = tip.network if tip.network != 'mainnet' else ""
_comments = "\n\nThe sender had the following public comments: \n> {}".format(tip.comments_public) if tip.comments_public else ""
msg = "⚡️ A tip worth {} {} {} {} has been granted to {} for this issue{}. ⚡️ {}\n\nNice work {}, check your email for further instructions. \n\n * ${} in Funded OSS Work Available at: https://gitcoin.co/explorer\n * Incentivize contributions to your repo: <a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>"
msg = msg.format(round(tip.amount, 5), warning, tip.tokenName, "(${})".format(tip.value_in_usdt) if tip.value_in_usdt else "" , username, _from, _comments, username, amount_usdt_open_work())
msg = "⚡️ A tip worth {} {} (${} @ {}/ETH) {} {} has been granted to {} for this issue{}. ⚡️ {}\n\nNice work {}, check your email for further instructions. \n\n * ${} in Funded OSS Work Available at: https://gitcoin.co/explorer\n * Incentivize contributions to your repo: <a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>"
msg = msg.format(round(tip.amount, 5), warning, bounty.value_in_usdt, get_eth_to_usdt(), tip.tokenName, "(${})".format(tip.value_in_usdt) if tip.value_in_usdt else "" , username, _from, _comments, username, amount_usdt_open_work())

# actually post
url = tip.github_url
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Meta:
"experience_level", "github_url", "github_comments", "bounty_owner_address", "bounty_owner_email",
"bounty_owner_github_username", "fulfiller_address", "fulfiller_email",
"fulfiller_github_username", "is_open", "expires_date", "raw_data", "metadata",
"fulfiller_metadata", "current_bounty", 'value_in_eth', 'value_in_usdt', 'status',
'now', 'avatar_url', 'value_true', 'issue_description', 'network', 'org_name',
"fulfiller_metadata", "current_bounty", 'value_in_eth', 'value_in_usdt', 'eth_value_in_usdt',
'status', 'now', 'avatar_url', 'value_true', 'issue_description', 'network', 'org_name',
'pk', 'issue_description_text', 'standard_bounties_id', 'web3_type')


Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/templates/bounty_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h6>Be the OSS Funding you wish to see in the world.</h6>

<h4 id="title">
</h4>
<span class=boldLabel>Funding Amount:</span> <span id="value_in_token"></span> <span id="value_in_usdt"></span> USD
<span class="boldLabel">Funding Amount:</span> <span id="value_in_token"></span> <span id="value_in_usdt"></span> USD @ <span id="eth_value_in_usdt">
<div id="right_actions"></div>
<h5>Issue Description</h5>
<div id="issue_description"></div>
Expand Down
3 changes: 3 additions & 0 deletions app/economy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def convert_amount(from_amount, from_currency, to_currency):
).order_by('-timestamp').first()
return (float(latest_conversion_rate.to_amount) / float(latest_conversion_rate.from_amount)) * float(from_amount)

def get_eth_to_usdt():
return convert_amount(1, "ETH", "USDT")


def etherscan_link(txid):
return 'https://etherscan.io/tx/' + txid
3 changes: 2 additions & 1 deletion app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from django.utils import timezone

import sendgrid
from economy.utils import get_eth_to_usdt
from marketing.utils import get_or_save_email_subscriber, should_suppress_notification_email
from retail.emails import (
render_bounty_expire_warning, render_bounty_startwork_expire_warning, render_match_email, render_new_bounty,
Expand Down Expand Up @@ -95,7 +96,7 @@ def new_bounty(bounty, to_emails=None):
if to_emails is None:
to_emails = []

subject = "⚡️ New Funded Issue Match worth ${} ({})".format(bounty.value_in_usdt, bounty.keywords)
subject = "⚡️ New Funded Issue Match worth ${} @ {}/ETH {})".format(bounty.value_in_usdt, get_eth_to_usdt(), bounty.keywords)

for to_email in to_emails:
from_email = settings.CONTACT_EMAIL
Expand Down
2 changes: 1 addition & 1 deletion app/retail/templates/emails/bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<span>
{{bounty.value_true}} {{bounty.token_name}}
{% if bounty.value_in_usdt %}
(about ${{bounty.value_in_usdt}} USDT)
(about ${{bounty.value_in_usdt}} USDT @ ${{bounty.eth_value_in_usdt}})
{% endif %}
</span>
</td>
Expand Down
3 changes: 1 addition & 2 deletions app/retail/templates/emails/bounty.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Github URL: {{bounty.github_url}}
* Value: {{bounty.value_true}} {{bounty.token_name}}
{% if bounty.value_in_usdt %}
(about ${{bounty.value_in_usdt}} USD)
(about ${{bounty.value_in_usdt}} USD @${{bounty.eth_value_in_usdt}}/ETH )
{% endif %}
* Status: {{bounty.status}}
* View More: {{bounty.absolute_url}}

0 comments on commit eda5222

Please sign in to comment.