Skip to content

Commit

Permalink
Merge pull request #5683 from zoek1/feature/send-kudos-from-profile
Browse files Browse the repository at this point in the history
Add option to send kudos from profile
  • Loading branch information
thelostone-mc authored Mar 4, 2020
2 parents 6ddffc8 + e71a38a commit 6c34cdd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 10 deletions.
9 changes: 7 additions & 2 deletions app/dashboard/templates/profiles/header_details.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load i18n static avatar_tags add_url_schema email_obfuscator %}

<h1 class="profile-header__handle">
@{{ profile.name }}
{{ profile.name }}
{% if verification %}
<button class="btn btn-sm animate-verify" data-container="body" data-toggle="popover" data-html="true" data-placement="bottom" data-trigger="hover click" data-content='
<p class="h6 my-2 text-left">Gitcoin Verified <img width="18" src="{% static "v2/images/badge-verify.svg" %}"></p>
Expand All @@ -14,7 +14,7 @@ <h1 class="profile-header__handle">

</h1>
<p class="mb-0">
{{ profile.handle }}
@{{ profile.handle }}
{% if not profile.is_org and profile.chat_id %}
<button class="btn btn-outline-gc-blue btn-sm flex-grow-1 font-smaller-5 position-relative quick-link" data-openchat="{{profile}}">
<i class="fas fa-comment-dots" data-placement="bottom" data-toggle="tooltip" data-html="true"
Expand All @@ -29,6 +29,11 @@ <h1 class="profile-header__handle">
<i class="fab fa-ethereum"></i>
</a>

<a class="btn btn-outline-gc-blue btn-sm flex-grow-1 font-smaller-5 position-relative quick-link"
href="{% url 'kudos_send' %}?username={{ profile.handle }}" data-placement="bottom" data-toggle="tooltip" data-html="true" title="Kudos @{{ profile.handle }}">
<i class="fas fa-dice-d6"></i>
</a>

<a class="btn btn-outline-gc-blue btn-sm flex-grow-1 font-smaller-5 position-relative quick-link" href="/users?invite={{ profile.handle }}"
data-placement="bottom" data-toggle="tooltip" data-html="true" title="Invite @{{ profile.handle }} to Bounty"
>
Expand Down
70 changes: 62 additions & 8 deletions app/kudos/templates/transaction/send.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@
<script src="/dynamic/js/tokens_dynamic.js"></script>
<script>
if (window.location.hostname === 'localhost') {
document.network = 'custom network'
document.network = 'custom network';
} else {
document.network = 'mainnet'
document.network = 'mainnet';
}
</script>
<script src="{% static "v2/js/pages/kudos_send.js" %}"></script>
<script src="{% static "onepager/js/confetti.js" %}"></script>
<script src="{% static "v2/js/user-search.js" %}"></script>
<script src="{% static "v2/js/eth-price.js" %}"></script>
<script>
$(document).ready(function() {
if (typeof userSearch != 'undefined') {
userSearch('.username-search', true, 'bootstrap4');
}
$(document).ready(function() {
if (typeof userSearch != 'undefined') {
userSearch('.username-search', true, 'bootstrap4');
$('.select2').on('click', removeStoredUser);
$('.clearSelectedUser').on('click', removeStoredUser);
$('.eth').on('click', removeStoredUser);
$('.airdrop').on('click', removeStoredUser);
}
})
</script>
{% endblock %}
Expand Down Expand Up @@ -95,10 +99,14 @@ <h1 class="h2 mt-5">{% trans "Send Kudos" %}</h1>
<input type="hidden" name="send_type" value="github">

<div class="form-group username">
<select id="username" class="username-search custom-select" {% if not kudos.name %}disabled{% endif %}></select>
<select id="username" class="username-search custom-select">
{% if user_json %}
<option value="{{ user_json.id }}" avatar_id="{{ user_json.avatar_id }}" avatar_url="{{ user_json.avatar_url }}" preferred_payout_address="{{ user_json.preferred_payout_address }}">{{ user_json.text }}</option>
{% endif %}
</select>
<input type="text" placeholder="0x408c49a91e46311ddc35737f8c1aaea6191f36e0" id="to_eth_address" value="" class="form-control eth_address hidden" >
<input type="text" placeholder="(link will be displayed after you click Send)" id="airdrop_link" value="" class="form-control airdrop_link hidden" disabled="disabled">

<a href="#" style="display: none" id="clearSelectedUser">Clear selected user</a>
</div>


Expand Down Expand Up @@ -165,4 +173,50 @@ <h3 class="font-weight-300">{% blocktrans %}<span id="new_username">the user</sp
<a id="" class="btn btn-gc-purple" href="{% url 'kudos_marketplace' %}">⬅ {% trans "Start Over" %}</a>
</div>
</section>

<script>
function removeStoredUser(e) {
e.preventDefault();
localStorage.removeItem('current_receiver');
document.getElementById('username').innerHTML = '';
document.getElementById('clearSelectedUser').style.display = 'none'
}

{% if not user_json and username %}
setTimeout(function() {
_alert("Sorry, we can't find the user");
}, 1000);
{% elif user_json and username %}
localStorage.setItem('current_receiver', JSON.stringify({
id: {{user_json.id }},
avatar_id: {{ user_json.avatar_id }},
avatar_url: '{{ user_json.avatar_url }}',
preferred_payout_address: '{{ user_json.preferred_payout_address }}',
text: '{{ user_json.text }}',
date: new Date()
}));
document.getElementById('clearSelectedUser').style.display = 'block';
{% else %}
let encoded_data = localStorage.getItem('current_receiver');
if (encoded_data !== null) {
let data = JSON.parse(encoded_data);
let current = new Date();
let past = new Date(Date.parse(data.date));

if ((current.getTime() - past.getTime()) / (60 * 60) > 1440) {
localStorage.removeItem('current_receiver')
} else {
let option = document.createElement('option');
option.value = data.id;
option.setAttribute('avatar_id', data.avatar_id);
option.setAttribute('avatar_url',data.avatar_url);
option.setAttribute('preferred_payout_address', data.preferred_payout_address);
option.textContent = data.text;

document.getElementById('username').append(option);
document.getElementById('clearSelectedUser').style.display = 'block'
}
}
{% endif %}
</script>
{% endblock %}
21 changes: 21 additions & 0 deletions app/kudos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,22 @@ def send_2(request):
if _id and not str(_id).isdigit():
raise Http404

username = request.GET.get('username', None)
user = {}

if username:
profiles = Profile.objects.filter(handle__iexact=username)

if profiles.exists():
profile = profiles.first()
user['id'] = profile.id
user['text'] = profile.handle

if profile.avatar_baseavatar_related.exists():
user['avatar_id'] = profile.avatar_baseavatar_related.first().pk
user['avatar_url'] = profile.avatar_baseavatar_related.first().avatar_url
user['preferred_payout_address'] = profile.preferred_payout_address

kudos = Token.objects.filter(pk=_id).first()
if kudos and not kudos.send_enabled_for(request.user):
messages.error(request, f'This kudos is not available to be sent.')
Expand All @@ -305,7 +321,12 @@ def send_2(request):
'card_desc': _('Send a Kudos to any github user at the click of a button.'),
'numbers': range(1,100),
'kudos': kudos,
'username': username,
}

if user:
params['user_json'] = user

return TemplateResponse(request, 'transaction/send.html', params)


Expand Down

0 comments on commit 6c34cdd

Please sign in to comment.