Skip to content

Commit

Permalink
Update Ethereum checkout completion so it does not clear all grants f…
Browse files Browse the repository at this point in the history
…rom cart
  • Loading branch information
mds1 committed Oct 20, 2020
1 parent 0da7e19 commit 4b8afd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
9 changes: 2 additions & 7 deletions app/assets/v2/js/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ Vue.component('grants-cart', {
},

/**
* @notice POSTs donation data to database. Intended to be called from finalizeCheckout()
* @notice POSTs donation data to database
*/
async postToDatabase(txHash, contractAddress, userAddress) {
// this.donationInputs is the array used for bulk donations
Expand Down Expand Up @@ -1291,17 +1291,12 @@ Vue.component('grants-cart', {
// Clear cart, redirect back to grants page, and show success alert
localStorage.setItem('contributions_were_successful', 'true');
localStorage.setItem('contributions_count', String(this.grantsByTenant.length));
var network = document.web3network;
let timeout_amount = 1500 + (CartData.loadCart().length * 500);

setTimeout(function() {
_alert('Contributions saved', 'success', 1000);
setTimeout(function() {
if (network === 'rinkeby') {
window.location.href = `${window.location.origin}/grants/?network=rinkeby&category=`;
} else {
window.location.href = `${window.location.origin}/grants`;
}
window.location.href = `${window.location.origin}/grants`;
}, 500);
}, timeout_amount);
},
Expand Down
17 changes: 11 additions & 6 deletions app/assets/v2/js/grants/funding.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ $(document).ready(function() {
const shouldShowAlert = Boolean(localStorage.getItem('contributions_were_successful'));

if (shouldShowAlert) {
// This alert currently shows after Ethereum checkouts only. As a result, we make sure to
// only clear ETH grants from local storage
const numberOfContributions = Number(localStorage.getItem('contributions_count'));
const grantWord = numberOfContributions === 1 ? 'grant' : 'grants';
const message = `You have successfully funded ${numberOfContributions} ${grantWord}. Thank you for your contribution!`;
Expand All @@ -15,23 +17,26 @@ $(document).ready(function() {
localStorage.removeItem('contributions_were_successful');
localStorage.removeItem('contributions_count');
$('#tweetModal').modal('show');
let donations = CartData.loadCart();

if (donations.length) {
const allDonations = CartData.loadCart();
const ethereumDonations = allDonations.filter((grant) => grant.tenants[0] === 'ETH');
const otherDonations = allDonations.filter((grant) => grant.tenants[0] !== 'ETH');

if (allDonations.length) {
let cart_html = 'You just funded: ';
let bulk_add_cart = CartData.share_url();

for (let i = 0; i < donations.length; i += 1) {
const donation = donations[i];
for (let i = 0; i < allDonations.length; i += 1) {
const donation = allDonations[i];

cart_html += '<li><a href=' + donation.grant_url + ' target=_blank>' + donation['grant_title'] + '</a> for ' + donation['grant_donation_amount'] + ' ' + donation['grant_donation_currency'] + ' (+' + donation['grant_donation_clr_match'] + ' DAI match)</li>';
}
cart_html += '<HR><a href=' + bulk_add_cart + ' target=_blank>Here is a handy link</a> for sharing this collection with others.';
$("<span class='mt-2 mb-2 w-100'>" + cart_html + '</span>').insertBefore($('#tweetModal span.copy'));
$('#tweetModal a.button').attr('href', 'https://twitter.com/intent/tweet?text=I%20just%20funded%20these%20' + donations.length + '%20grants%20on%20@gitcoin%20=%3E%20' + bulk_add_cart);
$('#tweetModal a.button').attr('href', 'https://twitter.com/intent/tweet?text=I%20just%20funded%20these%20' + allDonations.length + '%20grants%20on%20@gitcoin%20=%3E%20' + bulk_add_cart);
$('#tweetModal a.button').text('Tweet about it');
}
CartData.setCart([]);
CartData.setCart(otherDonations);
}

$('#js-addToCart-form').submit(function(event) {
Expand Down

0 comments on commit 4b8afd7

Please sign in to comment.