From 882de56363e3f5ed15353c681d85e0f500e573c6 Mon Sep 17 00:00:00 2001 From: Dan Lipert Date: Thu, 9 Jan 2020 00:36:19 +0900 Subject: [PATCH 1/6] save empty curve if no contributions to fix sorting --- app/grants/clr.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/grants/clr.py b/app/grants/clr.py index 38b9dfc280d..90ae26c56f9 100644 --- a/app/grants/clr.py +++ b/app/grants/clr.py @@ -280,14 +280,17 @@ def predict_clr(random_data=False, save_to_db=False, from_date=None, clr_type=No base = grant.clr_prediction_curve[0][1] if base: grant.clr_prediction_curve = [[ele[0], ele[1], ele[1] - base] for ele in grant.clr_prediction_curve ] - JSONStore.objects.create( - created_on=from_date, - view='clr_contribution', - key=f'{grant.id}', - data=grant.clr_prediction_curve, - ) - if from_date > (clr_calc_start_time - timezone.timedelta(hours=1)): - grant.save() + else: + grant.clr_prediction_curve = [[0.0, 0.0, 0.0] for x in range(0, 6)] + + JSONStore.objects.create( + created_on=from_date, + view='clr_contribution', + key=f'{grant.id}', + data=grant.clr_prediction_curve, + ) + if from_date > (clr_calc_start_time - timezone.timedelta(hours=1)): + grant.save() debug_output.append({'grant': grant.id, "clr_prediction_curve": (potential_donations, potential_clr), "grants_clr": grants_clr}) return debug_output From bc66c1755b07461290f133d9ec0979e38eb75263 Mon Sep 17 00:00:00 2001 From: Dan Lipert Date: Wed, 8 Jan 2020 21:40:03 +0900 Subject: [PATCH 2/6] include all rounds in phantom funding calc --- app/grants/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/grants/views.py b/app/grants/views.py index beae5a90995..3c7afd0b146 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -217,7 +217,7 @@ def grant_details(request, grant_id, grant_slug): subscriptions = grant.subscriptions.filter(active=True, error=False).order_by('-created_on') cancelled_subscriptions = grant.subscriptions.filter(active=False, error=False).order_by('-created_on') _contributions = Contribution.objects.filter(subscription__in=grant.subscriptions.all()) - phantom_funds = grant.phantom_funding.filter(round_number=4) + phantom_funds = grant.phantom_funding.all() contributions = list(_contributions.order_by('-created_on')) + [ele.to_mock_contribution() for ele in phantom_funds.order_by('-created_on')] contributors = list(_contributions.distinct('subscription__contributor_profile')) + list(phantom_funds.distinct('profile')) activity_count = len(cancelled_subscriptions) + len(contributions) From f5742479bd5adf4e2acfc5ef380827e4e595bbd0 Mon Sep 17 00:00:00 2001 From: Dan Lipert Date: Wed, 8 Jan 2020 00:12:53 +0900 Subject: [PATCH 3/6] check token balance covers first contribution --- app/assets/v2/js/grants/fund.js | 63 +++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/app/assets/v2/js/grants/fund.js b/app/assets/v2/js/grants/fund.js index c12775a5f4a..ca9a7e42253 100644 --- a/app/assets/v2/js/grants/fund.js +++ b/app/assets/v2/js/grants/fund.js @@ -210,34 +210,43 @@ $(document).ready(function() { approvalAddress = data.contract_address; } - deployedToken.methods.approve( - approvalAddress, - web3.utils.toTwosComplement(approvalSTR) - ).send({ - from: accounts[0], - gasPrice: web3.utils.toHex($('#gasPrice').val() * Math.pow(10, 9)), - gas: web3.utils.toHex(gas_amount(document.location.href)), - gasLimit: web3.utils.toHex(gas_amount(document.location.href)) - }).on('error', function(error) { - console.log('1', error); - _alert({ message: gettext('Your approval transaction failed. Please try again.')}, 'error'); - }).on('transactionHash', function(transactionHash) { - $('#sub_new_approve_tx_id').val(transactionHash); - if (data.num_periods == 1) { - // call splitter after approval - splitPayment(accounts[0], data.admin_address, gitcoinDonationAddress, Number(grant_amount * Math.pow(10, decimals)).toLocaleString('fullwide', {useGrouping: false}), Number(gitcoin_grant_amount * Math.pow(10, decimals)).toLocaleString('fullwide', {useGrouping: false})); + deployedToken.methods.balanceOf( + accounts[0] + ).call().then(function(result) { + console.log(result); + if (result < realTokenAmount) { + _alert({ message: gettext('Your balance could not be verified')}, 'error'); } else { - if (data.contract_version == 0 && gitcoin_grant_amount > 0) { - donationPayment(deployedToken, accounts[0], Number(gitcoin_grant_amount * Math.pow(10, decimals)).toLocaleString('fullwide', {useGrouping: false})); - } - subscribeToGrant(transactionHash); - } - }).on('confirmation', function(confirmationNumber, receipt) { - waitforData(() => { - document.suppress_loading_leave_code = true; - window.location = redirectURL; - }); // waitforData - }); // approve on confirmation + deployedToken.methods.approve( + approvalAddress, + web3.utils.toTwosComplement(approvalSTR) + ).send({ + from: accounts[0], + gasPrice: web3.utils.toHex($('#gasPrice').val() * Math.pow(10, 9)), + gas: web3.utils.toHex(gas_amount(document.location.href)), + gasLimit: web3.utils.toHex(gas_amount(document.location.href)) + }).on('error', function(error) { + console.log('1', error); + _alert({ message: gettext('Your approval transaction failed. Please try again.')}, 'error'); + }).on('transactionHash', function(transactionHash) { + $('#sub_new_approve_tx_id').val(transactionHash); + if (data.num_periods == 1) { + // call splitter after approval + splitPayment(accounts[0], data.admin_address, gitcoinDonationAddress, Number(grant_amount * Math.pow(10, decimals)).toLocaleString('fullwide', {useGrouping: false}), Number(gitcoin_grant_amount * Math.pow(10, decimals)).toLocaleString('fullwide', {useGrouping: false})); + } else { + if (data.contract_version == 0 && gitcoin_grant_amount > 0) { + donationPayment(deployedToken, accounts[0], Number(gitcoin_grant_amount * Math.pow(10, decimals)).toLocaleString('fullwide', {useGrouping: false})); + } + subscribeToGrant(transactionHash); + } + }).on('confirmation', function(confirmationNumber, receipt) { + waitforData(() => { + document.suppress_loading_leave_code = true; + window.location = redirectURL; + }); // waitforData + }); // approve on confirmation + } // if (result < realTokenAmount) + }); // check token balance }); // getAccounts }); // decimals } // submitHandler From 33ecd3fedec48c21b8f9af02bec20b3ecc42f974 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Wed, 8 Jan 2020 22:22:47 +0530 Subject: [PATCH 4/6] update admin.py --- app/grants/admin.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/grants/admin.py b/app/grants/admin.py index 234bede1608..e6d01d21181 100644 --- a/app/grants/admin.py +++ b/app/grants/admin.py @@ -18,6 +18,7 @@ """ from django.contrib import admin +from django.utils.html import format_html from django.utils.safestring import mark_safe from grants.models import CLRMatch, Contribution, Grant, MatchPledge, PhantomFunding, Subscription @@ -180,6 +181,12 @@ def error_email_copy_not_active(self, instance): class ContributionAdmin(GeneralAdmin): """Define the Contribution administration layout.""" raw_id_fields = ['subscription'] + list_display = ['id', 'txn_url', 'tx_cleared', 'success'] + + def txn_url(self, obj): + tx_id = obj.tx_id + tx_url = 'https://etherscan.io/tx/' + tx_id + return format_html("{}", tx_url, tx_id) admin.site.register(PhantomFunding, GeneralAdmin) From e703deecc1cbc7bcb46638bfdb73cbe6fc8d4cde Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Wed, 8 Jan 2020 22:28:07 +0530 Subject: [PATCH 5/6] update admin --- app/grants/admin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/grants/admin.py b/app/grants/admin.py index e6d01d21181..ea1a9f6479d 100644 --- a/app/grants/admin.py +++ b/app/grants/admin.py @@ -181,13 +181,16 @@ def error_email_copy_not_active(self, instance): class ContributionAdmin(GeneralAdmin): """Define the Contribution administration layout.""" raw_id_fields = ['subscription'] - list_display = ['id', 'txn_url', 'tx_cleared', 'success'] + list_display = ['id', 'txn_url', 'tx_cleared', 'success', 'profile'] def txn_url(self, obj): tx_id = obj.tx_id tx_url = 'https://etherscan.io/tx/' + tx_id return format_html("{}", tx_url, tx_id) + def profile(self, obj): + return obj.subscription.contributor_profile + admin.site.register(PhantomFunding, GeneralAdmin) admin.site.register(MatchPledge, MatchPledgeAdmin) From 08f51d8ac163afc9b5b6f0e070128f0085d0a1b4 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Wed, 8 Jan 2020 22:41:12 +0530 Subject: [PATCH 6/6] udpate admin --- app/grants/admin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/grants/admin.py b/app/grants/admin.py index ea1a9f6479d..452ff8ff4c8 100644 --- a/app/grants/admin.py +++ b/app/grants/admin.py @@ -181,7 +181,7 @@ def error_email_copy_not_active(self, instance): class ContributionAdmin(GeneralAdmin): """Define the Contribution administration layout.""" raw_id_fields = ['subscription'] - list_display = ['id', 'txn_url', 'tx_cleared', 'success', 'profile'] + list_display = ['id', 'txn_url', 'profile', 'created_on', 'amount', 'token', 'tx_cleared', 'success'] def txn_url(self, obj): tx_id = obj.tx_id @@ -191,6 +191,12 @@ def txn_url(self, obj): def profile(self, obj): return obj.subscription.contributor_profile + def token(self, obj): + return obj.subscription.token_symbol + + def amount(self, obj): + return obj.subscription.amount_per_period + admin.site.register(PhantomFunding, GeneralAdmin) admin.site.register(MatchPledge, MatchPledgeAdmin)