From 5153f2abf83b54c2f7fa27745dcf67950d504f34 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Sun, 22 Mar 2020 02:22:23 +0530 Subject: [PATCH 1/4] replace match_direction -> is_positive_vote --- app/assets/v2/js/grants/fund.js | 2 ++ app/grants/clr.py | 19 +++++++++------- .../migrations/0046_auto_20200321_2043.py | 22 +++++++++++++++++++ app/grants/models.py | 7 +----- app/grants/views.py | 11 ++++------ 5 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 app/grants/migrations/0046_auto_20200321_2043.py diff --git a/app/assets/v2/js/grants/fund.js b/app/assets/v2/js/grants/fund.js index 5ea6e52013c..845ed5a1892 100644 --- a/app/assets/v2/js/grants/fund.js +++ b/app/assets/v2/js/grants/fund.js @@ -239,6 +239,8 @@ $(document).ready(function() { data[this.name] = this.value; }); + data.is_postive_vote = (data.match_direction == '-') ? 0 : 1; + if (data.frequency) { // translate timeAmount&timeType to requiredPeriodSeconds diff --git a/app/grants/clr.py b/app/grants/clr.py index a1b95574fed..7da8c316832 100644 --- a/app/grants/clr.py +++ b/app/grants/clr.py @@ -154,6 +154,9 @@ def calculate_new_clr(aggregated_contributions, pair_totals, threshold=0.0, tota def calculate_new_clr_final(totals_pos, totals_neg, total_pot=0.0): # calculate final totals + # print(f'+ve {len(totals_pos)} {totals_pos}') + # print(f'-ve {len(totals_neg)} {totals_neg}') + if len(totals_neg) == 0: totals = totals_pos else: @@ -295,8 +298,8 @@ def populate_data_for_clr(clr_type=None, network='mainnet'): grant_id = grant.defer_clr_to.pk if grant.defer_clr_to else grant.id # Get the +ve and -ve contributions - positive_contributions = copy.deepcopy(contributions).filter(subscription__grant_id=grant.id, subscription__match_direction='+') - negative_contributions = copy.deepcopy(contributions).filter(subscription__grant_id=grant.id, subscription__match_direction='-') + positive_contributions = copy.deepcopy(contributions).filter(subscription__grant_id=grant.id, subscription__is_postive_vote=True) + negative_contributions = copy.deepcopy(contributions).filter(subscription__grant_id=grant.id, subscription__is_postive_vote=False) # Generate list of profiles who've made +ve and -ve contributions to the grant phantom_funding_profiles = PhantomFunding.objects.filter(grant_id=grant.id, created_on__gte=CLR_START_DATE, created_on__lte=from_date) @@ -408,7 +411,7 @@ def predict_clr(save_to_db=False, from_date=None, clr_type=None, network='mainne grant: - grant to be funded contributor: - contributor making a contribution amount: - amount with which is grant is to be funded - match_direction: + , - + is_postive_vote: positive_grant_contributions: [Object] negative_grant_contributions: [Object] total_pot: @@ -417,7 +420,7 @@ def predict_clr(save_to_db=False, from_date=None, clr_type=None, network='mainne Returns: clr_amount ''' -def calculate_clr_for_donation_live(grant, contributor, amount, match_direction, positive_grant_contributions, negative_grant_contributions, total_pot, threshold): +def calculate_clr_for_donation_live(grant, contributor, amount, is_postive_vote, positive_grant_contributions, negative_grant_contributions, total_pot, threshold): if amount == 0: return 0 @@ -427,7 +430,7 @@ def calculate_clr_for_donation_live(grant, contributor, amount, match_direction, profile_id = str(contributor.pk) - if match_direction == '+': + if is_postive_vote: for grant_contribution in _positive_grant_contributions: if grant_contribution['id'] == grant.id: grant_contribution['contributions'].append({ @@ -461,12 +464,12 @@ def calculate_clr_for_donation_live(grant, contributor, amount, match_direction, grant: contributor: amount: - match_direction: + , - + is_postive_vote: Returns: predicted_clr_match ''' -def predict_clr_live(grant, contributor, amount, match_direction='+'): +def predict_clr_live(grant, contributor, amount, is_postive_vote=True): if not grant or not contributor: print('error: predict_clr_live - missing parameters') @@ -480,7 +483,7 @@ def predict_clr_live(grant, contributor, amount, match_direction='+'): _, positive_contrib_data, negative_contrib_data , total_pot, threshold = populate_data_for_clr(clr_type, network) predicted_clr_match = calculate_clr_for_donation_live( - grant, contributor, amount, match_direction, positive_contrib_data, negative_contrib_data, total_pot, threshold + grant, contributor, amount, is_postive_vote, positive_contrib_data, negative_contrib_data, total_pot, threshold ) return predicted_clr_match diff --git a/app/grants/migrations/0046_auto_20200321_2043.py b/app/grants/migrations/0046_auto_20200321_2043.py new file mode 100644 index 00000000000..cf8c0e5bb4e --- /dev/null +++ b/app/grants/migrations/0046_auto_20200321_2043.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2.4 on 2020-03-21 20:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('grants', '0045_flag'), + ] + + operations = [ + migrations.RemoveField( + model_name='subscription', + name='match_direction', + ), + migrations.AddField( + model_name='subscription', + name='is_postive_vote', + field=models.BooleanField(default=True, help_text='Whether this is positive or negative vote'), + ), + ] diff --git a/app/grants/models.py b/app/grants/models.py index beca6d5421d..9ac39cd7b8f 100644 --- a/app/grants/models.py +++ b/app/grants/models.py @@ -511,12 +511,7 @@ class Subscription(SuperModel): help_text=_('The tx id of the split transfer'), blank=True, ) - match_direction = models.CharField( - default='+', - max_length=255, - help_text=_('The direction of the match'), - blank=True, - ) + is_postive_vote = models.BooleanField(default=True, help_text=_('Whether this is positive or negative vote')) split_tx_confirmed = models.BooleanField(default=False, help_text=_('Whether or not the split tx succeeded.')) subscription_hash = models.CharField( diff --git a/app/grants/views.py b/app/grants/views.py index 3f35369d796..425cc934b02 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -696,7 +696,7 @@ def grant_fund(request, grant_id, grant_slug): subscription.active = False subscription.contributor_address = request.POST.get('contributor_address', '') - subscription.match_direction = request.POST.get('match_direction', '') + subscription.is_postive_vote = request.POST.get('is_postive_vote', True) subscription.amount_per_period = request.POST.get('amount_per_period', 0) subscription.real_period_seconds = request.POST.get('real_period_seconds', 2592000) subscription.frequency = request.POST.get('frequency', 30) @@ -771,8 +771,6 @@ def grant_fund(request, grant_id, grant_slug): 'url': reverse('grants:details', args=(grant.pk, grant.slug)) }) - splitter_contract_address = settings.SPLITTER_CONTRACT_ADDRESS - # handle phantom funding active_tab = 'normal' fund_reward = None @@ -1080,7 +1078,7 @@ def predict_clr_v1(request, grant_id): ''' { amount: , - match_direction: +, - + is_postive_vote: +, - } ''' response = { @@ -1111,14 +1109,13 @@ def predict_clr_v1(request, grant_id): response['message'] = 'error: missing parameter amount' return JsonResponse(response) - - match_direction = request.GET.get('match_direction', '+') + is_postive_vote = True if request.GET.get('is_postive_vote', 1) else False predicted_clr_match = predict_clr_live( grant, profile, float(amount), - match_direction + is_postive_vote ) response = { From 6af3b94a3a310d7da8ce743cc8cc472067a4c4df Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Sun, 22 Mar 2020 02:35:07 +0530 Subject: [PATCH 2/4] handle corner case when first contribution is negative in clr --- app/grants/clr.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/grants/clr.py b/app/grants/clr.py index 7da8c316832..1169dea665f 100644 --- a/app/grants/clr.py +++ b/app/grants/clr.py @@ -159,6 +159,8 @@ def calculate_new_clr_final(totals_pos, totals_neg, total_pot=0.0): if len(totals_neg) == 0: totals = totals_pos + elif len(totals_pos) == 0: + totals = [{'id': x['id'], 'clr_amount': 0 } for x in totals_neg] else: totals = [{'id': x['id'], 'clr_amount': (math.sqrt(x['clr_amount']) - math.sqrt(y['clr_amount']))**2} for x in totals_pos for y in totals_neg if x['id'] == y['id']] From 4270f6c4bcc762d5e1866c8c99ff8975e9eb0e88 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Sun, 22 Mar 2020 02:47:49 +0530 Subject: [PATCH 3/4] fix bug --- app/grants/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/grants/views.py b/app/grants/views.py index 425cc934b02..17b5a455907 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -694,9 +694,10 @@ def grant_fund(request, grant_id, grant_slug): if 'contributor_address' in request.POST: subscription = Subscription() + is_postive_vote = True if request.GET.get('is_postive_vote', 1) else False + subscription.is_postive_vote = is_postive_vote subscription.active = False subscription.contributor_address = request.POST.get('contributor_address', '') - subscription.is_postive_vote = request.POST.get('is_postive_vote', True) subscription.amount_per_period = request.POST.get('amount_per_period', 0) subscription.real_period_seconds = request.POST.get('real_period_seconds', 2592000) subscription.frequency = request.POST.get('frequency', 30) From 60fd43a15eb0cbb7d05f966f8da58e43f2461035 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Sun, 22 Mar 2020 22:13:42 +0530 Subject: [PATCH 4/4] remove banner from grant fund --- app/assets/v2/css/grants/fund.css | 25 +------------ app/assets/v2/js/grants/detail.js | 2 +- app/assets/v2/js/grants/fund.js | 10 ++--- app/grants/templates/grants/banner.html | 37 ------------------- app/grants/templates/grants/cancel.html | 4 +- app/grants/templates/grants/detail/info.html | 5 ++- app/grants/templates/grants/fund.html | 7 ++-- .../grants/shared/landing_announce.html | 2 +- app/kudos/templates/kudos_about.html | 1 - app/kudos/templates/kudos_details.html | 1 - app/kudos/templates/kudos_marketplace.html | 1 - 11 files changed, 16 insertions(+), 79 deletions(-) delete mode 100644 app/grants/templates/grants/banner.html diff --git a/app/assets/v2/css/grants/fund.css b/app/assets/v2/css/grants/fund.css index fd0190f8773..5b80fd7b6ed 100644 --- a/app/assets/v2/css/grants/fund.css +++ b/app/assets/v2/css/grants/fund.css @@ -3,9 +3,11 @@ border-bottom: 1px solid #515151; } } + .est_direction{ font-weight: 900; } + .admin_profile a, #grant-link { color: #0D0764; @@ -15,17 +17,6 @@ width: 100%; } -.banner-img { - max-height: 22rem; - overflow-y: hidden; -} - -.banner-img img { - height: auto; - width: 100%; - object-fit: cover; -} - #grants_form .nav-link { border-top-left-radius: 4px; border-top-right-radius: 4px; @@ -266,18 +257,6 @@ } } -@media (max-width: 767.98px) { - - .banner-img { - text-align: center; - } - - .banner-img img { - width: auto; - max-width: 100%; - } -} - @media (max-width: 1199.98px) { .clr_estimate { display: none; diff --git a/app/assets/v2/js/grants/detail.js b/app/assets/v2/js/grants/detail.js index 5fc14863a2a..b98c96ec179 100644 --- a/app/assets/v2/js/grants/detail.js +++ b/app/assets/v2/js/grants/detail.js @@ -47,7 +47,7 @@ $(document).ready(function() { if (lgi) { $('#backgrants').attr('href', lgi); - $('#backgrants').text('< Back to ' + lgt); + $('#backgrants').text(' Back to ' + lgt); } diff --git a/app/assets/v2/js/grants/fund.js b/app/assets/v2/js/grants/fund.js index 1e0c3f5cc4f..08b915c2fa7 100644 --- a/app/assets/v2/js/grants/fund.js +++ b/app/assets/v2/js/grants/fund.js @@ -53,10 +53,6 @@ $(document).ready(function() { gitcoinDonationAddress = $('#gitcoin_donation_address').val(); splitterAddress = $('#splitter_contract_address').val(); - $('.select2-selection__rendered').hover(function() { - $(this).removeAttr('title'); - }); - updateSummary(); $('#grants_form .nav-item').click(function(e) { @@ -438,6 +434,9 @@ $(document).ready(function() { }); $('#js-token').select2(); $('.contribution_type select').trigger('change'); + $('.select2-selection__rendered').hover(function() { + $(this).removeAttr('title'); + }); updateSummary(); }); // waitforWeb3 }); // document ready @@ -830,5 +829,4 @@ const predictCLRLive = (amount) => { console.error(`error: predictCLRLive - status ${response.status} - ${response.message}`); } }); -}; - +}; \ No newline at end of file diff --git a/app/grants/templates/grants/banner.html b/app/grants/templates/grants/banner.html deleted file mode 100644 index 5852053a4e1..00000000000 --- a/app/grants/templates/grants/banner.html +++ /dev/null @@ -1,37 +0,0 @@ -{% load static humanize i18n grants_extra %} - -
- -
-

- {{ grant.title }} -

- -
- {% trans "by" %} - - {{ grant.admin_profile }} - -
- -
-
-
-
-
-
-
- {{ grant.amount_received_with_phantom_funds|floatformat:2|intcomma }} DAI -

Funding

-
-
- {{ grant.amount_goal|floatformat:2|intcomma }} DAI -

Monthly Goal

-
-
-
-
-
-
diff --git a/app/grants/templates/grants/cancel.html b/app/grants/templates/grants/cancel.html index 525869f080b..f553efd5e60 100644 --- a/app/grants/templates/grants/cancel.html +++ b/app/grants/templates/grants/cancel.html @@ -49,11 +49,9 @@
-

{% trans "Cancel Contribution" %}

+

Cancel Contribution for {{ grant.title }}

- {% include 'grants/banner.html' %} -
diff --git a/app/grants/templates/grants/detail/info.html b/app/grants/templates/grants/detail/info.html index e6058e5581c..c0117bdd166 100644 --- a/app/grants/templates/grants/detail/info.html +++ b/app/grants/templates/grants/detail/info.html @@ -16,7 +16,10 @@ {% endcomment %} {% load static humanize i18n grants_extra %}
- < Back to Grants + + + Back to Grants + - {% include 'grants/banner.html' %} - {% if can_phantom_fund %}