Skip to content

Commit

Permalink
Merge pull request #5415 from zoek1/feature/tip-shortcut
Browse files Browse the repository at this point in the history
Add shortcut to tip user
  • Loading branch information
owocki authored Dec 13, 2019
2 parents 07360ad + c82443b commit ce6f397
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
url(r'^tip/send/2/?', dashboard.tip_views.send_tip_2, name='send_tip_2'),
url(r'^tip/send/?', dashboard.tip_views.send_tip, name='send_tip'),
url(r'^send/?', dashboard.tip_views.send_tip, name='tip'),
url(r'^tip/?', dashboard.tip_views.send_tip, name='tip'),
url(r'^tip/?', dashboard.tip_views.send_tip_2, name='tip'),

# Legal
re_path(r'^terms/?', dashboard.views.terms, name='_terms'),
Expand Down
14 changes: 13 additions & 1 deletion app/assets/v2/js/user-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,20 @@ function userSearch(elem, showAddress, theme, initialData, allowClear, suppress_
return selected;
}

function formatUserSelectionWithAddress(user) {
function formatUserSelectionWithAddress(base_user) {
let selected;
let existent_properties = {};

if (base_user.element) {
const attr = base_user.element.attributes;
const attr_length = attr.length;

for (let i = 0; i < attr_length; i++) {
existent_properties[attr[i].nodeName] = attr[i].nodeValue;
}
}

let user = $.extend({}, existent_properties, base_user);

if (user.id) {
selected = `
Expand Down
14 changes: 13 additions & 1 deletion app/dashboard/templates/onepager/send2.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ <h1>{% trans "Send Tip." %}</h1>
<div id="tooltip" class="ethinfo-hover">{% trans "Where is my Eth going? " %}<i class='fa fa-info-circle'></i></div><br>
<div class="pb-1 to_name">
<label>{% trans "To Github Username" %}:</label> <br>
<select id="username" class="username-search custom-select" style="max-width: 400px; margin-left: auto; margin-right: auto;"></select>
<select id="username" class="username-search custom-select" style="max-width: 400px; margin-left: auto; margin-right: auto;">
{% 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>
</div>
<div>
<label>{% trans "From Github Username" %} {% if not request.user.is_authenticated %}(<a href="{% url 'social:begin' 'github' %}?next=/tip" onclick="dataLayer.push({'event': 'login'});">{% trans "Login" %}</a>) {%endif%}</label>
Expand Down Expand Up @@ -164,4 +168,12 @@ <h3>{% trans "with instructions about how to receive their tip." %}</h1>
{% trans "We send the funds directly to the address associated with the user." %}</span>
</div>
</section>

{% if not user_json and username %}
<script>
setTimeout(function() {
_alert("Sorry, we can't find the user");
}, 1000);
</script>
{% endif %}
{% endblock %}
3 changes: 3 additions & 0 deletions app/dashboard/templates/profiles/header_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ <h1 class="profile-header__handle">
<p>Please note - use your judgement on whether this is the right contributor for your task.</p>
'><img src="{% static 'v2/images/badge-verify.svg' %}" alt=""></button>
{% endif %}
<a class="btn btn-sm" style="border: 2px solid #3E00FF;" href="{% url 'tip' %}?username={{ profile.handle }}">
<i style="color: #3E00FF;" class="fab fa-ethereum"></i>
</a>
</h1>
<p class="mb-0">{{ profile.handle }}
{% if profile.custom_tagline %}
Expand Down
20 changes: 20 additions & 0 deletions app/dashboard/tip_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,26 @@ def send_tip_2(request):
TemplateResponse: Render the submission form.
"""

username = request.GET.get('username', None)
is_user_authenticated = request.user.is_authenticated
from_username = request.user.username if is_user_authenticated else ''
primary_from_email = request.user.email if is_user_authenticated else ''

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

params = {
'issueURL': request.GET.get('source'),
'class': 'send2',
Expand All @@ -380,4 +396,8 @@ def send_tip_2(request):
'title': 'Send Tip | Gitcoin',
'card_desc': 'Send a tip to any github user at the click of a button.',
}

if user:
params['user_json'] = user

return TemplateResponse(request, 'onepager/send2.html', params)

0 comments on commit ce6f397

Please sign in to comment.