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

Recreation of #6220 which was accidently merged #6387

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
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_2, name='tip'),

url(r'^requestmoney/?', dashboard.tip_views.request_money, name='request_money'),
# Legal
re_path(r'^terms/?', dashboard.views.terms, name='_terms'),
re_path(r'^legal/terms/?', dashboard.views.terms, name='terms'),
Expand Down
83 changes: 83 additions & 0 deletions app/assets/onepager/js/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
$(document).ready(function() {
$('#request').on('click', function(e) {
e.preventDefault();
if ($(this).hasClass('disabled'))
return;
loading_button($(this));
// get form data
var username = $('.username-search').select2('data')[0] ? $('.username-search').select2('data')[0].text : '';
var amount = parseFloat($('#amount').val());
var comments = $('#comments').val();
var tokenAddress = (
($('#token').val() == '0x0') ?
'0x0000000000000000000000000000000000000000'
: $('#token').val());


// derived info
var isSendingETH = (tokenAddress == '0x0' || tokenAddress == '0x0000000000000000000000000000000000000000');
var tokenDetails = tokenAddressToDetails(tokenAddress);
var tokenName = 'ETH';

if (!isSendingETH) {
tokenName = tokenDetails.name;
}

if (!username) {
_alert('Please enter a recipient', 'error');
return;
}

var success_callback = function() {
unloading_button($('#request'));
};
var failure_callback = function() {
unloading_button($('#request'));
};

return requestFunds(username, amount, comments, tokenAddress, tokenName, success_callback, failure_callback);

});

});

function requestFunds(username, amount, comments, tokenAddress, tokenName, success_callback, failure_callback) {
if (username.indexOf('@') == -1) {
username = '@' + username;
}

var tokenDetails = tokenAddressToDetails(tokenAddress);

if (!isNumeric(amount) || amount == 0) {
_alert({ message: gettext('You must enter an number for the amount!') }, 'warning');
failure_callback();
return;
}
if (username == '') {
_alert({ message: gettext('You must enter a username.') }, 'warning');
failure_callback();
return;
}

const csrfmiddlewaretoken = $('[name=csrfmiddlewaretoken]').val();
const url = '/requestmoney';
const formData = new FormData();

formData.append('username', username);
formData.append('amount', amount);
formData.append('tokenName', tokenName);
formData.append('comments', comments);
formData.append('tokenAddress', tokenAddress);
formData.append('csrfmiddlewaretoken', csrfmiddlewaretoken);

fetch(url, {
method: 'POST',
body: formData
}).then(function(json) {
_alert('The funder has been notified', 'success');
success_callback();
}).catch(function(error) {
_alert('Something goes wrong, try later.', 'error');
failure_callback();
});
}
37 changes: 37 additions & 0 deletions app/dashboard/migrations/0093_auto_20200324_1653.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 2.2.4 on 2020-03-24 16:53

from django.db import migrations, models
import django.db.models.deletion
import economy.models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0092_auto_20200316_2228'),
]

operations = [
migrations.AlterField(
model_name='activity',
name='activity_type',
field=models.CharField(blank=True, choices=[('wall_post', 'Wall Post'), ('status_update', 'Update status'), ('new_bounty', 'New Bounty'), ('start_work', 'Work Started'), ('stop_work', 'Work Stopped'), ('work_submitted', 'Work Submitted'), ('work_done', 'Work Done'), ('worker_approved', 'Worker Approved'), ('worker_rejected', 'Worker Rejected'), ('worker_applied', 'Worker Applied'), ('increased_bounty', 'Increased Funding'), ('killed_bounty', 'Canceled Bounty'), ('new_tip', 'New Tip'), ('receive_tip', 'Tip Received'), ('bounty_abandonment_escalation_to_mods', 'Escalated checkin from @gitcoinbot about bounty status'), ('bounty_abandonment_warning', 'Checkin from @gitcoinbot about bounty status'), ('bounty_removed_slashed_by_staff', 'Dinged and Removed from Bounty by Staff'), ('bounty_removed_by_staff', 'Removed from Bounty by Staff'), ('bounty_removed_by_funder', 'Removed from Bounty by Funder'), ('new_crowdfund', 'New Crowdfund Contribution'), ('new_grant', 'New Grant'), ('update_grant', 'Updated Grant'), ('killed_grant', 'Cancelled Grant'), ('new_grant_contribution', 'Contributed to Grant'), ('new_grant_subscription', 'Subscribed to Grant'), ('killed_grant_contribution', 'Cancelled Grant Contribution'), ('new_milestone', 'New Milestone'), ('update_milestone', 'Updated Milestone'), ('new_kudos', 'New Kudos'), ('created_kudos', 'Created Kudos'), ('receive_kudos', 'Receive Kudos'), ('joined', 'Joined Gitcoin'), ('played_quest', 'Played Quest'), ('beat_quest', 'Beat Quest'), ('created_quest', 'Created Quest'), ('updated_avatar', 'Updated Avatar'), ('mini_clr_payout', 'Mini CLR Payout'), ('leaderboard_rank', 'Leaderboard Rank'), ('consolidated_leaderboard_rank', 'Consolidated Leaderboard Rank'), ('consolidated_mini_clr_payout', 'Consolidated CLR Payout'), ('hackathon_registration', 'Hackathon Registration')], db_index=True, max_length=50),
),
migrations.CreateModel(
name='FundRequest',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('token_name', models.CharField(default='ETH', max_length=255)),
('amount', models.DecimalField(decimal_places=4, default=1, max_digits=50)),
('comments', models.TextField(blank=True, default='')),
('created_on', models.DateTimeField(auto_now_add=True)),
('profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='requests_receiver', to='dashboard.Profile')),
('requester', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='requests_sender', to='dashboard.Profile')),
('tip', models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.Tip')),
],
options={
'abstract': False,
},
),
]
22 changes: 21 additions & 1 deletion app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
_AUTH, HEADERS, TOKEN_URL, build_auth_dict, get_gh_issue_details, get_issue_comments, issue_number, org_name,
repo_name,
)
from marketing.mails import featured_funded_bounty, start_work_approved
from marketing.mails import featured_funded_bounty, start_work_approved, fund_request_email
from marketing.models import LeaderboardRank
from rest_framework import serializers
from web3 import Web3
Expand Down Expand Up @@ -1773,6 +1773,26 @@ def __str__(self):
return f"tip: {self.tip.pk} profile: {self.profile.handle}"


class FundRequest(SuperModel):
profile = models.ForeignKey(
'dashboard.Profile', related_name='requests_receiver', on_delete=models.CASCADE
)
requester = models.ForeignKey(
'dashboard.Profile', related_name='requests_sender', on_delete=models.CASCADE
)
token_name = models.CharField(max_length=255, default='ETH')
amount = models.DecimalField(default=1, decimal_places=4, max_digits=50)
comments = models.TextField(default='', blank=True)
tip = models.OneToOneField(Tip, on_delete=models.CASCADE, null=True)
created_on = models.DateTimeField(auto_now_add=True)


@receiver(post_save, sender=FundRequest, dispatch_uid="post_save_fund_request")
def psave_fund_request(sender, instance, created, **kwargs):
if created:
fund_request_email(instance, [instance.profile.email])


@receiver(pre_save, sender=Tip, dispatch_uid="psave_tip")
def psave_tip(sender, instance, **kwargs):
# when a new tip is saved, make sure it doesnt have whitespace in it
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/templates/onepager/send2.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ <h1>{% trans "Send Tip." %}</h1>
<div>
<br>
{% trans "Amount of" %}
<select id="token" style="width:100px; margin-bottom: 10px; display: inline;" >
<select id="token" style="width:100px; margin-bottom: 10px; display: inline;" data-token="{{ fund_request.token_name }}">
<option value="0x0">ETH</option>
</select>
<input name="amount" type="text" placeholder="1.1" id="amount" value="" style="width: 170px; display: inline;">
<input name="amount" type="text" placeholder="1.1" id="amount" value="{{ fund_request.amount }}" style="width: 170px; display: inline;">
</div>
<div id="usd_amount"> &nbsp;</div>
<div id="tooltip" class="ethinfo-hover">{% trans "Where is my Eth going? " %}<i class='fa fa-info-circle'></i></div><br>
Expand Down
119 changes: 119 additions & 0 deletions app/dashboard/templates/request_payment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{% extends 'onepager/base.html' %}
{% comment %}
Copyright (C) 2020 Gitcoin Core

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}
{% load i18n static %}
{% block 'scripts' %}
{% include 'shared/current_profile.html' %}
<script src="{% static "v2/js/lib/ipfs-api.js" %}"></script>
<script src="{% static "v2/js/ipfs.js" %}"></script>
<script src="{% static "v2/js/tokens.js" %}"></script>
<script src="{% static "v2/js/abi.js" %}"></script>
<script src="{% static "v2/js/amounts.js" %}"></script>
<script src="{% static "v2/js/lib/secrets.min.js" %}"></script>
<script src="{% static "v2/js/ethereumjs-accounts.js" %}"></script>
<script src="/dynamic/js/tokens_dynamic.js"></script>
<script src="{% static "onepager/js/send.js" %}"></script>
<script src="{% static "onepager/js/request.js" %}"></script>
<script src="{% static "onepager/js/confetti.js" %}"></script>
<script src="{% static "v2/js/user-search.js" %}"></script>
<script src="{% static "v2/js/tooltip_hover.js" %}"></script>
{% endblock %}
<!-- Main -->
{% block 'main' %}
<link rel="stylesheet" type="text/css" href="{% static "v2/css/tooltip_hover.css" %}">
<style>
#ethinfo-tooltip {
top: 19.5rem;
left: 25rem;
max-width: 80%;
z-index: 10000;
}

@media only screen and (max-width: 1050px) {
#ethinfo-tooltip {
top: 21rem;
left: 3.5rem;
}
}

.send2 .navbar-network {
padding: 3px;
}

.pb-1 {
padding-bottom: 1rem;
}

#fromName,
#advanced_toggle,
.to_name .select2-container,
.terms {
margin-top: 0.75rem;
}
</style>
<div>
<canvas id="world" style="position:fixed; top:0px; left: 0px;"></canvas>
</div>
<section id="main">
<header>
<span class="avatar">
<a href="{% url "tip" %}">
<img src="{% static "v2/images/helmet.png" %}" style="background-color: white; max-width: 100px; max-height: 100px;" alt="Helmet" />
</a>
</span>
</header>
<div id="send_eth">
<h1>{% trans "Request money." %}</h1>
{% csrf_token %}
<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;">
{% 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>
{% trans "Amount of" %}
<select id="token" style="width:100px; margin-bottom: 10px; display: inline;" >
<option value="0x0">ETH</option>
</select>
<input name="amount" type="text" placeholder="1.1" id="amount" value="" style="width: 170px; display: inline;">
</div>
<div id="usd_amount"> &nbsp;</div>
<div>
{% trans "Comments" %}:
<textarea id="comments"></textarea>
</div>
<div class="terms pb-1">
<input type="checkbox" id="tos" value="1" >
<label for="tos">{% blocktrans %}I understand &amp; agree to the <a href="https://gitcoin.co/terms">terms of service</a>.{% endblocktrans %}</label>
</div>
<a href="#" id="request" class="button button--primary">{% trans "Send" %} <span class="emoji">⚡️</span></a>
<br>
</div>
</section>

{% if not user_json and username %}
<script>
setTimeout(function() {
_alert("Sorry, we can't find the user");
}, 1000);
</script>
{% endif %}
{% endblock %}
Loading