From 64d136d3682ffa64d1d12359d2de9ccea5a5119a Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Thu, 1 Jul 2021 13:23:29 +0530 Subject: [PATCH] chore: make improvs to missing contiribution ingestions (#9242) --- .../js/grants/ingest-missing-contributions.js | 6 +++++- app/grants/admin.py | 8 +++++-- app/grants/views.py | 21 +++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/assets/v2/js/grants/ingest-missing-contributions.js b/app/assets/v2/js/grants/ingest-missing-contributions.js index 4b013d9055d..76e0c02a818 100644 --- a/app/assets/v2/js/grants/ingest-missing-contributions.js +++ b/app/assets/v2/js/grants/ingest-missing-contributions.js @@ -191,7 +191,11 @@ Vue.component('grants-ingest-contributions', { if (!json.success) { console.log('ingestion failed'); this.submitted = false; - throw new Error('Your transactions could not be processed, please try again'); + const msg = json.message ? + 'Error adding contributions as ' + json.message : + 'Error adding contributions, please try again'; + + throw new Error(msg); } else { console.log('ingestion successful'); _alert('Your contributions have been added successfully!', 'success'); diff --git a/app/grants/admin.py b/app/grants/admin.py index bd161d82253..afa13ee9be5 100644 --- a/app/grants/admin.py +++ b/app/grants/admin.py @@ -348,7 +348,9 @@ def txn_url(self, obj): return format_html("{}", tx_url, tx_id) def profile(self, obj): - return format_html(f"{obj.subscription.contributor_profile}") + if obj.subscription.contributor_profile: + return format_html(f"{obj.subscription.contributor_profile}") + return None def created_on_nt(self, obj): return naturaltime(obj.created_on) @@ -360,7 +362,9 @@ def token(self, obj): return obj.subscription.token_symbol def user_sybil_score(self, obj): - return f"{obj.subscription.contributor_profile.sybil_score} ({obj.subscription.contributor_profile.sybil_score_str})" + if obj.subscription.contributor_profile: + return f"{obj.subscription.contributor_profile.sybil_score} ({obj.subscription.contributor_profile.sybil_score_str})" + return '0' def grant(self, obj): return mark_safe(f"{obj.subscription.grant.title}") diff --git a/app/grants/views.py b/app/grants/views.py index 4225757e938..de2b0e60905 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -3260,6 +3260,12 @@ def ingest_contributions(request): message = request.POST.get('message') network = request.POST.get('network') ingestion_types = [] # after each series of ingestion, we append the ingestion_method to this array + handle = request.POST.get('handle') + + if (profile.is_staff and + ( not handle or Profile.objects.filter(handle=handle).count() == 0) + ): + return JsonResponse({ 'success': False, 'message': 'Profile could not be found' }) # Setup web3 w3 = get_web3(network) @@ -3284,12 +3290,15 @@ def verify_signature(signature, message, expected_address): if recovered_address.lower() != expected_address.lower(): raise Exception("Signature could not be verified") - if txHash != '': - receipt = w3.eth.getTransactionReceipt(txHash) - from_address = receipt['from'] - verify_signature(signature, message, from_address) - if userAddress != '': - verify_signature(signature, message, userAddress) + try: + if txHash != '': + receipt = w3.eth.getTransactionReceipt(txHash) + from_address = receipt['from'] + verify_signature(signature, message, from_address) + if userAddress != '': + verify_signature(signature, message, userAddress) + except: + return JsonResponse({ 'success': False, 'message': 'Signature could not be verified' }) def get_token(w3, network, address): if (address == '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'):