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

fix: POAP - Ensures that all tokens are considered and not just the token with the lowest ID #8994

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 11 additions & 8 deletions app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def get_poap_transfers(uri, address):

def get_poap_earliest_owned_token_timestamp(network, address):
# returning None when no tokens are held for address
timestamp = None
tokens_timestamps = []
# must query the graph using lowercase address
address = address.lower()

Expand All @@ -483,9 +483,9 @@ def get_poap_earliest_owned_token_timestamp(network, address):
pass
else:
# flatten tokenIds into a dict
tokens_dict = list()
tokens_list = []
for token in poap_tokens:
tokens_dict.append(token['id'])
tokens_list.append(token['id'])

# pull the transfers so that we can check timestamps
poap_transfers = get_poap_transfers(uri, address)
Expand All @@ -494,15 +494,18 @@ def get_poap_earliest_owned_token_timestamp(network, address):
# check the earliest received token that is still owned by the address
for token in tokens_transfered:
# token still owned by the address?
if token['id'] in tokens_dict:
if token['id'] in tokens_list:
# use timestamp of most recent transfer
timestamp = int(token['transfers'][0]['timestamp'])
break
tokens_timestamps.append(int(token['transfers'][0]['timestamp']))
except:
# returning 0 will print a failed (try again) error
timestamp = 0
tokens_timestamps[0] = 0

# sort to discover earliest
tokens_timestamps.sort()

return timestamp
# return the earliest timestamp
return tokens_timestamps[0] if len(tokens_timestamps) else None


def get_ens_contract_addresss(network, legacy=False):
Expand Down
9 changes: 8 additions & 1 deletion app/townsquare/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,14 @@ def api(request, activity_id):

# deletion request
if request.POST.get('method') == 'delete':
activity.delete()
has_perms = False
if request.user.is_authenticated:
if activity.profile and request.user.profile.pk == activity.profile.pk:
has_perms = True
if activity.other_profile and request.user.other_profile.pk == activity.other_profile.pk:
has_perms = True
if has_perms:
activity.delete()

# deletion request
if request.POST.get('method') == 'vote':
Expand Down