Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displays all tokens in user profile #4597

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2603,6 +2603,44 @@ def get_eth_sum(self, sum_type='collected', network='mainnet', bounties=None):

return eth_sum

def get_all_tokens_sum(self, sum_type='collected', network='mainnet', bounties=None):
"""Get the sum of collected or funded tokens based on the provided type.

Args:
sum_type (str): The sum to lookup. Defaults to: collected.
network (str): The network to query results for.
Defaults to: mainnet.
bounties (dashboard.models.BountyQuerySet): Override the BountyQuerySet this function processes.
Defaults to: None.

Returns:
query: Grouped query by token_name and sum all token value
"""
all_tokens_sum = None
if not bounties:
if sum_type == 'funded':
bounties = self.get_funded_bounties(network=network)
elif sum_type == 'collected':
bounties = self.get_fulfilled_bounties(network=network)
elif sum_type == 'org':
bounties = self.get_orgs_bounties(network=network)

if bounties and sum_type == 'funded':
bounties = bounties.has_funds()
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved

try:
if bounties.exists():
all_tokens_sum = bounties.values(
'token_name'
).annotate(
value_in_token=Sum('value_in_token') / 10**18,
).order_by('token_name')

except Exception:
pass

return all_tokens_sum

def get_who_works_with(self, work_type='collected', network='mainnet', bounties=None):
"""Get an array of profiles that this user works with.

Expand Down Expand Up @@ -2743,6 +2781,10 @@ def to_dict(self, activities=True, leaderboards=True, network=None, tips=True):
works_with_funded = self.get_who_works_with(work_type='funded', bounties=funded_bounties)
works_with_collected = self.get_who_works_with(work_type='collected', bounties=fulfilled_bounties)

sum_all_funded_tokens = self.get_all_tokens_sum(sum_type='funded', bounties=funded_bounties, network=network)
sum_all_collected_tokens = self.get_all_tokens_sum(
sum_type='collected', bounties=fulfilled_bounties, network=network
)
# org only
count_bounties_on_repo = 0
sum_eth_on_repos = 0
Expand Down Expand Up @@ -2775,6 +2817,8 @@ def to_dict(self, activities=True, leaderboards=True, network=None, tips=True):
'sum_eth_on_repos': sum_eth_on_repos,
'works_with_org': works_with_org,
'count_bounties_on_repo': count_bounties_on_repo,
'sum_all_funded_tokens': sum_all_funded_tokens,
'sum_all_collected_tokens': sum_all_collected_tokens
}

if activities:
Expand Down
14 changes: 12 additions & 2 deletions app/dashboard/templates/profiles/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ <h1 class="profile-header__handle">
<div class="card-body">
<ul>
<li><b>{{ count_bounties_completed }}</b> {% trans "bounties completed" %}</li>
<li><b>{{ sum_eth_collected|floatformat:2 }} ETH</b> {% trans "collected" %}</li>
{% for token in sum_all_collected_tokens %}
<li><b>{{ token.value_in_token|floatformat:2 }} {{ token.token_name }}</b> {% trans "collected" %}</li>
{% endfor %}
{% if not sum_all_collected_tokens %}
<li><b>{{ sum_eth_collected|floatformat:2 }} ETH</b> {% trans "collected" %}</li>
{% endif %}
{% if no_times_been_removed %}
<li> - {% trans "removed from" %} <b>{{ no_times_been_removed }}</b> {% trans "bounties" %}</li>
{% endif %}
Expand Down Expand Up @@ -170,7 +175,12 @@ <h1 class="profile-header__handle">
<div class="card-body font-subheader">
<ul>
<li><b>{{ funded_bounties_count }}</b> {% trans "bounties funded" %}</li>
<li><b>{{ sum_eth_funded|floatformat:2 }} ETH</b> {% trans "funded" %}</li>
{% for row in sum_all_funded_tokens %}
<li><b>{{ row.value_in_token|floatformat:2 }} {{ row.token_name }}</b> {% trans "funded" %}</li>
{% endfor %}
{% if not sum_all_funded_tokens %}
<li><b>{{ sum_eth_funded|floatformat:2 }} ETH</b> {% trans "funded" %}</li>
{% endif %}
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved
<li class="works_with_list">
{% if works_with_funded|length %}
<span class="font-body"><i class="fab fa-ethereum"></i> {% trans "Funds" %}:</span>
Expand Down
36 changes: 36 additions & 0 deletions app/dashboard/tests/test_dashboard_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,39 @@ def test_bounty_clean_gh_url_on_save():
)
assert bounty.github_url == 'https://github.com/gitcoinco/web/issues/305'
bounty.delete()

@staticmethod
def get_all_tokens_sum():
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved
"""Test all users funded tokens."""
token_names = ['ETH', 'ETH', 'DAI']
for name in token_names:
Bounty.objects.create(
title='foo',
value_in_token=3,
token_name=name,
web3_created=datetime(2008, 10, 31, tzinfo=pytz.UTC),
github_url='https://github.com/gitcoinco/web/issues/305#issuecomment-999999999',
token_address='0x0',
issue_description='hello world',
bounty_owner_github_username='gitcoinco',
is_open=True,
expires_date=datetime(2008, 11, 30, tzinfo=pytz.UTC),
idx_project_length=5,
project_length='Months',
bounty_type='Feature',
experience_level='Intermediate',
raw_data={},
current_bounty=True,
network='mainnet',
)

profile = Profile(
handle='gitcoinco',
data={'type': 'Organization'},
)
query = profile.to_dict()['sum_all_funded_tokens']
assert query[0]['token_name'] == 'DAI'
assert query[0]['value_in_token'] == 3

assert query[1]['token_name'] == 'ETH'
assert query[1]['value_in_token'] == 6