Skip to content

Commit

Permalink
chore: make improvs to missing contiribution ingestions (#9242)
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc authored Jul 1, 2021
1 parent 557c8e6 commit 64d136d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion app/assets/v2/js/grants/ingest-missing-contributions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 6 additions & 2 deletions app/grants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ def txn_url(self, obj):
return format_html("<a href='{}' target='_blank'>{}</a>", tx_url, tx_id)

def profile(self, obj):
return format_html(f"<a href='/{obj.subscription.contributor_profile.handle}'>{obj.subscription.contributor_profile}</a>")
if obj.subscription.contributor_profile:
return format_html(f"<a href='/{obj.subscription.contributor_profile.handle}'>{obj.subscription.contributor_profile}</a>")
return None

def created_on_nt(self, obj):
return naturaltime(obj.created_on)
Expand All @@ -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"<a href={obj.subscription.grant.url}>{obj.subscription.grant.title}</a>")
Expand Down
21 changes: 15 additions & 6 deletions app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'):
Expand Down

0 comments on commit 64d136d

Please sign in to comment.