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

as a end user I would like to be able to attach ETH/tokens to my status update on gitcoin, so i can share money #5884

Merged
merged 41 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bcd11de
Add UI and interaction to setup tips on comments
zoek1 Jan 25, 2020
937b1d4
Merge style to mantain consistency
zoek1 Jan 31, 2020
a7fb1f6
Add transaction process to attach and redeem from status
zoek1 Jan 31, 2020
15a4392
Fix errors on anonymous access
zoek1 Feb 1, 2020
0fc7a56
Integrate tips on comments based into new townsquare
zoek1 Feb 18, 2020
f7ec1de
integrate with latest stable changes
zoek1 Feb 18, 2020
73ce7f8
fix conflicts
zoek1 Feb 21, 2020
376fbdc
Merge branch 'stable' into feature/tip-comments
zoek1 Feb 25, 2020
194a1cc
Fix error on migrations
zoek1 Feb 25, 2020
06df14d
Merge branch 'stable' into feature/tip-comments
zoek1 Feb 26, 2020
653748a
Merge branch 'stable' into feature/tip-comments
zoek1 Feb 27, 2020
66e3ec8
Fix visual issues with tokens
zoek1 Mar 5, 2020
2fbbdf6
Resolve conflicts with master
zoek1 Mar 5, 2020
8d64f04
Update shareactivity.html
zoek1 Mar 5, 2020
982e122
Clean migrations
zoek1 Mar 5, 2020
075bf29
Merge branch 'feature/tip-comments' of https://github.com/zoek1/web-1…
zoek1 Mar 5, 2020
b417a29
Fix lint
zoek1 Mar 5, 2020
daadac6
Merge branch 'master' into feature/tip-comments
zoek1 Mar 9, 2020
e4504d9
Merge branch 'master' into feature/tip-comments
zoek1 Mar 12, 2020
ca76c9d
Fix conflicts and update UI
zoek1 Apr 29, 2020
495f5e9
Merge branch 'master' into feature/tip-comments
danlipert Apr 29, 2020
c225f09
Merge branch 'master' into feature/tip-comments
zoek1 Apr 29, 2020
20dc77d
Remove existing libs on footer_scripts
zoek1 Apr 29, 2020
17a0155
Merge branch 'master' into feature/tip-comments
zoek1 Apr 29, 2020
2110ff3
Remove extra dependencies
zoek1 Apr 29, 2020
1cec287
Merge branch 'feature/tip-comments' of https://github.com/zoek1/web-1…
zoek1 Apr 29, 2020
716bc0e
Fix conflict with master
zoek1 May 5, 2020
d192526
Merge branch 'master' into feature/tip-comments
zoek1 May 5, 2020
7bc27e6
Merge branch 'master' into feature/tip-comments
thelostone-mc May 13, 2020
1171f12
Update status_box.html
zoek1 May 14, 2020
f58c21e
Merge branch 'master' into feature/tip-comments
zoek1 May 14, 2020
7199c69
Rollback missing library
zoek1 May 14, 2020
35d4887
Merge branch 'master' into feature/tip-comments
zoek1 May 19, 2020
5ebff37
Merge branch 'master' into feature/tip-comments
zoek1 May 20, 2020
8f3f93a
Merge branch 'master' into feature/tip-comments
zoek1 May 20, 2020
fcea83f
Update migration
zoek1 May 20, 2020
13af9cd
Merge branch 'master' into feature/tip-comments
zoek1 May 26, 2020
2d3ea32
Fix migration erros
zoek1 May 26, 2020
70e4008
Merge branch 'master' into feature/tip-comments
zoek1 May 27, 2020
f65c42b
Merge branch 'master' into feature/tip-comments
zoek1 May 27, 2020
70098d9
Merge branch 'master' into feature/tip-comments
danlipert May 27, 2020
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
3 changes: 2 additions & 1 deletion app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def callback(request):
"SHOW_TOOLBAR_CALLBACK" : callback,
}
MIDDLEWARE.append('debug_toolbar.middleware.DebugToolbarMiddleware')

# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = env('LANGUAGE_CODE', default='en-us')
Expand Down Expand Up @@ -812,6 +812,7 @@ def callback(request):
MINICLR_ADDRESS = env('MINICLR_ADDRESS', default='0x00De4B13153673BCAE2616b67bf822500d325Fc3')
MINICLR_PRIVATE_KEY = env('MINICLR_PRIVATE_KEY', default='0x00De4B13153673BCAE2616b67bf822500d325Fc3')


AVATAR_ADDRESS = env('AVATAR_ADDRESS', default='0x00De4B13153673BCAE2616b67bf822500d325Fc3')
AVATAR_PRIVATE_KEY = env('AVATAR_PRIVATE_KEY', default='0x00De4B13153673BCAE2616b67bf822500d325Fc3')

Expand Down
9 changes: 6 additions & 3 deletions app/assets/onepager/js/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function isNumeric(n) {
}


function sendTip(email, github_url, from_name, username, amount, comments_public, comments_priv, from_email, accept_tos, tokenAddress, expires, success_callback, failure_callback, is_for_bounty_fulfiller) {
function sendTip(email, github_url, from_name, username, amount, comments_public, comments_priv, from_email, accept_tos, tokenAddress, expires, success_callback, failure_callback, is_for_bounty_fulfiller, noAvailableUser) {
if (typeof web3 == 'undefined') {
_alert({ message: gettext('You must have a web3 enabled browser to do this. Please download Metamask.') }, 'warning');
failure_callback();
Expand Down Expand Up @@ -232,16 +232,19 @@ function sendTip(email, github_url, from_name, username, amount, comments_public
failure_callback();
return;
}

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

if (username == '' && !noAvailableUser) {
_alert({ message: gettext('You must enter a username.') }, 'warning');
failure_callback();
return;
}

if (!accept_tos) {
_alert({ message: gettext('You must accept the terms.') }, 'warning');
failure_callback();
Expand Down
52 changes: 50 additions & 2 deletions app/assets/v2/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,37 @@ $(document).ready(function() {
});


$(document).on('click', '.award', function(e) {
e.preventDefault();
if (!document.contxt.github_handle) {
_alert('Please login first.', 'error');
return;
}

activityId = $(this).data('activity');
commentId = $(this).data('comment');

// remote post
var params = {
'method': 'award',
'comment': commentId,
'csrfmiddlewaretoken': $('input[name=csrfmiddlewaretoken]').val()
};
var url = '/api/v0.1/activity/' + activityId;
var parent = $(this).parents('.row.box');

parent.find('.loading').removeClass('hidden');
$.post(url, params, function(response) {
// no message to be sent
$('button[data-activity=' + activityId + ']').remove();
parent.find('.loading').addClass('hidden');
_alert('Tip user successful!');
}).fail(function() {
parent.find('.error').removeClass('hidden');
});
});


// like activity
$(document).on('click', '.like_activity, .flag_activity, .favorite_activity', function(e) {
e.preventDefault();
Expand Down Expand Up @@ -679,21 +710,28 @@ $(document).ready(function() {

the_comment = urlify(the_comment);
the_comment = linkify(the_comment);

the_comment = the_comment.replace(/\r\n|\r|\n/g, '<br />');
const timeAgo = timedifferenceCvrt(new Date(comment['created_on']));
const show_tip = true;
const is_comment_owner = document.contxt.github_handle == comment['profile_handle'];

const can_award = (
response.author === document.contxt.github_handle &&
response.has_tip == true &&
response.tip_available == true);
const can_redeem = response.can_redeem;

const is_edited = typeof comment['is_edited'] !== 'undefined' ? comment['is_edited'] : false;

var sorted_match_curve_html = '';

if (comment['sorted_match_curve']) {

var match_curve = Array.from(convert_to_dict(comment['sorted_match_curve']).values());

for (let j = 0; j < match_curve.length; j++) {
let ele = match_curve[j];


sorted_match_curve_html += '<li>';
sorted_match_curve_html += `Your contribution of ${ele.name} could yield $${Math.round(ele.value * 1000) / 1000} in matching.`;
sorted_match_curve_html += '</li>';
Expand Down Expand Up @@ -777,6 +815,16 @@ $(document).ready(function() {
<div class="activity_comments_main_comment pt-1 pb-1">
${the_comment}
</div>
${can_award && `
<button data-comment=${comment['id']} data-user=${comment['profile_handle']}
data-activity=${comment['activity']}
class="award btn mt-1 mb-1 btn-radio font-smaller-5">
<i class="fas fa-gift mr-2"></i> award
</button>` || ''}
${!!comment['redeem_link'] && can_redeem && `
<a class="btn mt-1 mb-1 btn-radio font-smaller-5" href="${comment['redeem_link']}">Redeem tip</a>` || ''}
${!!comment['redeem_link'] && !can_redeem && `
<a class="btn mt-1 mb-1 btn-radio font-smaller-5" href="${comment['redeem_link']}">Tip redeemed</a>` || ''}
</div>

</div>
Expand Down
131 changes: 117 additions & 14 deletions app/assets/v2/js/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ $(document).ready(function() {
}
});

$('#btn_attach').on('click', function() {
const el = $('#attach-dropdown');

el.toggle();
});


function submitStatusUpdate() {
if ($('#btn_post').is(':disabled')) {
return;
Expand Down Expand Up @@ -470,9 +477,16 @@ $(document).ready(function() {
data.append('image', image);
}
}

const attach = $('#attach-dropdown')[0].style.display;
const amount = $('#attachAmount').val();
const address = $('#attachToken').val();
const token_name = $('#attachToken :selected').text();

$('#bg-selector').attr('data-selected', null);
$('#bg-selector').addClass('d-none');
$('#bg-selector').children('div').children('div').addClass('d-none');

var fail_callback = function() {
message.val(the_message);
localStorage.setItem(lskey, the_message);
Expand All @@ -482,21 +496,108 @@ $(document).ready(function() {
);
};

for (let i = 0; i < 5; i++) {
const val = $('#poll_container input[name=option' + i + ']').val();
const success_callback = function(txid) {
const url = 'https://' + etherscanDomain() + '/tx/' + txid;
const msg = 'This payment has been sent 👌 <a target=_blank href="' + url + '">[Etherscan Link]</a>';

_alert(msg, 'info', 1000);

data.append('attachTxId', txid);
fetch('/api/v0.1/activity', {
method: 'post',
body: data
}).then(response => {
if (response.status === 200) {
$('#thumbnail').hide();
$('#thumbnail-title').text('');
$('#thumbnail-provider').text('');
$('#thumbnail-desc').text('');
$('#thumbnail-img').attr('src', '');
$('#preview').hide();
$('#preview-img').attr('src', '');
$('#attach-dropdown').hide();
$('#attachAmount').val('');

embedded_resource = '';

_alert(
{ message: gettext('Status has been saved.') },
'success',
1000
);
const activityContainer = document.querySelector('.tab-section.active .activities');

if (!activityContainer) {
document.run_long_poller(false);
// success
return;
}
activityContainer.setAttribute('page', 0);
$('.tab-section.active .activities').html('');
message.val('');
} else {
_alert(
{ message: gettext('An error occurred. Please try again.') },
'error'
);
}
}).catch(err => fail_callback());
};

const failure_callback = function() {
$.noop(); // do nothing
};

if (!isNaN(parseFloat(amount)) && address) {
data.append('attachToken', address);
data.append('attachAmount', amount);
data.append('attachTokenName', token_name);
const email = '';
const github_url = '';
const from_name = document.contxt['github_handle'];
const username = '';
const amountInEth = amount;
const comments_priv = '';
const comments_public = '';
const from_email = '';
const accept_tos = true;
const tokenAddress = address;
const expires = 9999999999;

sendTip(
email,
github_url,
from_name,
username,
amountInEth,
comments_public,
comments_priv,
from_email,
accept_tos,
tokenAddress,
expires,
success_callback,
failure_callback,
false,
true, // No available user to send tip at this moment
);

if (val) {
data.append('option' + i, val);
} else {
for (let i = 0; i < 5; i++) {
const val = $('#poll_container input[name=option' + i + ']').val();

if (val) {
data.append('option' + i, val);
}
}
}
$('#poll_container').remove();
$('#video_container').remove();

fetch('/api/v0.1/activity', {
method: 'post',
body: data
})
.then(response => {
$('#poll_container').remove();
$('#video_container').remove();

fetch('/api/v0.1/activity', {
method: 'post',
body: data
}).then(response => {
if (response.status === 200) {
$('#thumbnail').hide();
$('#thumbnail-title').text('');
Expand All @@ -505,6 +606,8 @@ $(document).ready(function() {
$('#thumbnail-img').attr('src', '');
$('#preview').hide();
$('#preview-img').attr('src', '');
$('#attach-dropdown').hide();
$('#attachAmount').val('');
embedded_resource = '';

_alert(
Expand All @@ -525,8 +628,8 @@ $(document).ready(function() {
} else {
fail_callback();
}
})
.catch(err => fail_callback());
}).catch(err => fail_callback());
}
}

});
Expand Down
26 changes: 25 additions & 1 deletion app/dashboard/templates/profiles/status_box.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
<div id="list-gif" class="gif-grid"></div>
</div>
</div>
<button id="poll-button" class="btn btn-sm p-1" data-toggle="tooltip" title="Add a poll to post." style="bottom: 2em; right: 0em;"><i class="fas fa-fw fa-chart-bar"></i></i></button>
<button id="poll-button" class="btn btn-sm p-1" data-toggle="tooltip" title="Add a poll to post." style="bottom: 2em; right: 0em;"><i class="fas fa-fw fa-chart-bar"></i></button>
<button id="btn_attach" class="btn btn-sm p-1" data-toggle="tooltip" title="Attach tip" style="bottom: 2em; right: 0em;"><i class="fab fa-ethereum"></i></button>

</div>
<div class="d-none" id="bg-selector">
</div>
Expand Down Expand Up @@ -61,6 +63,28 @@
</button>
</div>
</div>
<div id="attach-dropdown" class="attach text-left mt-4" style="display: none">
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label class="sup featured-text">Amount</label>
<input id="attachAmount" type="number" class="form-control">

</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="sup featured-text">Token</label>
<select class="form-control" id="attachToken">
<option value="0x0">ETH</option>
{% for token in TOKENS %}
<option value="{{ token.token_addres }}">{{ token.token_name }}</option>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this only tested with ETH? There is a typo here for the token_address

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I missed that. I tested with some ERC20 tokens like MANA and GNT.
image

{% endfor %}
</select>
</div>
</div>
</div>
</div>
<div id="thumbnail" class="mt-1 mb-2" style="display: none; top: initial; left: initial;">
<div class="row" style="display: flex; justify-content: center; align-items: center; ">
<div class="col ml-1 col-sm-3 col-md-2 text-center">
Expand Down
21 changes: 19 additions & 2 deletions app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,28 @@ def mention_email(post, to_emails):

if not should_suppress_notification_email(to_email, 'mention'):
send_mail(from_email, to_email, subject, text, html, categories=['notification', func_name()])
finally:
pass
except Exception as e:
logger.error('Status Update error - Error: (%s) - Handle: (%s)', e, to_email)

translation.activate(cur_language)


def tip_comment_awarded_email(post, to_emails):
subject = gettext("🏆 @{} has awarded you.").format(post.profile.handle)
cur_language = translation.get_language()

for to_email in to_emails:
try:
setup_lang(to_email)
from_email = settings.CONTACT_EMAIL
html, text = render_mention(to_email, post)

if not should_suppress_notification_email(to_email, 'mention'):
send_mail(from_email, to_email, subject, text, html, categories=['notification', func_name()])
except Exception as e:
logger.error('Status Update error - Error: (%s) - Handle: (%s)', e, to_email)
translation.activate(cur_language)


def wall_post_email(activity):

Expand Down
7 changes: 6 additions & 1 deletion app/retail/templates/shared/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,15 @@
</p>
</div>
{% endif %}

<i class="fas fa-circle-notch fa-spin loading blue hidden"></i>
<i class="fas fa-exclamation-triangle error red hidden"></i>
{% endif %}
{% if row.metadata.attach.token %}
| <button class="btn btn-sm btn-link" style="color: #3E00FF;">
<i class="fas fa-coins gc-blue-text" ></i>
<span class="value_in_token">{{row.metadata.attach.amount}} {{row.metadata.attach.token_name}} attached</span>
</button>
{% endif %}
</div>
</div>
<div class="d-none d-sm-inline col-sm-2 pl-0 position-relative">
Expand Down
Loading