Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gitcoinco/web into issue/…
Browse files Browse the repository at this point in the history
…6870
  • Loading branch information
developerfred committed Jun 17, 2020
2 parents f3f0a46 + 6d898ef commit 6e9bc55
Show file tree
Hide file tree
Showing 75 changed files with 2,435 additions and 1,112 deletions.
3 changes: 3 additions & 0 deletions app/app/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ ETHERSCAN_API_KEY=

INFURA_USE_V3=True

SUPRESS_DEBUG_TOOLBAR=1


SENDGRID_API_KEY=
CONTACT_EMAIL=

Expand Down
10 changes: 3 additions & 7 deletions app/app/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings

from app.settings import account_sid, auth_token
from app.settings import account_sid, auth_token, verify_service
from redis import Redis
from twilio.rest import Client

Expand Down Expand Up @@ -39,10 +39,7 @@ def __create_connection(self):

if not TwilioService._client:
TwilioService._client = Client(account_sid, auth_token)
friendly_names = settings.TWILIO_FRIENDLY_NAMES
friendly_name = random.choice(friendly_names)
TwilioService._service = TwilioService._client.verify.services.create(friendly_name=friendly_name)
redis.set(f"validation:twilio:sid", TwilioService._service.sid)
TwilioService._service = TwilioService._client.verify.services(verify_service)

def __init__(self):
self.__create_connection()
Expand All @@ -54,5 +51,4 @@ def lookups(self):
@property
def verify(self):
redis = RedisService().redis
sid = redis.get(f"validation:twilio:sid")
return TwilioService._client.verify.services(sid.decode('utf-8'))
return TwilioService._client.verify.services(verify_service)
1 change: 1 addition & 0 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def callback(request):

account_sid = env('TWILIO_ACCOUNT_SID', default='')
auth_token = env('TWILIO_AUTH_TOKEN', default='')
verify_service = env('TWILIO_VERIFY_SERVICE', default='')

SMS_MAX_VERIFICATION_ATTEMPTS = env('SMS_MAX_VERIFICATION_ATTEMPTS', default=4)
SMS_COOLDOWN_IN_MINUTES = env('SMS_COOLDOWN_IN_MINUTES', default=1)
Expand Down
1 change: 1 addition & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@
url(settings.GITHUB_EVENT_HOOK_URL, gitcoinbot.views.payload, name='payload'),
url(r'^impersonate/', include('impersonate.urls')),
url(r'^api/v0.1/hackathon_project/set_winner/', dashboard.views.set_project_winner, name='project_winner'),
url(r'^api/v0.1/hackathon_project/set_winner/', dashboard.views.set_project_winner, name='project_winner'),

# users
url(r'^api/v0.1/user_bounties/', dashboard.views.get_user_bounties, name='get_user_bounties'),
Expand Down
3 changes: 2 additions & 1 deletion app/assets/onepager/js/receive.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ $(document).ready(function() {
} else {

// send ERC20
var data = token_contract.methods.transfer(forwarding_address, amount_in_wei.toString()).encodeABI();
var encoded_amount = new web3.utils.BN(BigInt(document.tip['amount_in_wei'])).toString();
var data = token_contract.methods.transfer(forwarding_address, encoded_amount).encodeABI();

rawTx = {
nonce: web3.utils.toHex(nonce),
Expand Down
47 changes: 31 additions & 16 deletions app/assets/onepager/js/request.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
$(document).ready(function() {
waitforWeb3(function() {
if (!$('#address').val() && web3 && web3.eth.coinbase) {
$('#address').val(web3.eth.coinbase);
}
});


$('#network').change(function(e) {
if ($(this).val() !== 'ETH') {
Expand All @@ -17,13 +11,13 @@ $(document).ready(function() {
$('#request').on('click', function(e) {
e.preventDefault();
if ($(this).hasClass('disabled'))
return;
return false;

if (!$('#tos').is(':checked')) {
_alert('Please accept the terms and conditions before submit.', 'warning');
return;
return false;
}
loading_button($(this));

// get form data
const username = $('.username-search').select2('data')[0] ? $('.username-search').select2('data')[0].text : '';
const amount = parseFloat($('#amount').val());
Expand All @@ -33,16 +27,30 @@ $(document).ready(function() {

if (!document.contxt['github_handle']) {
_alert('You must be logged in to use this form', 'warning');
return;
return false;
}

if (!provider) {
return onConnect().then(() => {
return false;
});
}

if (!username || !amount || !address) {
_alert('Please fill all the fields.', 'warning');
return false;
}

if (username == document.contxt['github_handle']) {
_alert('You cannot request money from yourself.', 'warning');
return;
return false;
}
if (!comments || comments.length < 5) {
_alert('Please leave a comment describing why this user should send you money.', 'warning');
return;
return false;
}
loading_button($(this));

const tokenAddress = (
($('#token').val() == '0x0') ?
'0x0000000000000000000000000000000000000000'
Expand Down Expand Up @@ -118,7 +126,14 @@ function requestFunds(username, amount, comments, tokenAddress, tokenName, netwo
});
}

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 5000);
listen_for_web3_changes();
});
window.addEventListener('load', async() => {
if (!provider && !web3Modal.cachedProvider || provider === 'undefined') {
onConnect().then(() => {
$('#address').val(selectedAccount);
});
} else {
web3Modal.on('connect', async(data) => {
$('#address').val(data.selectedAddress);
});
}
});
41 changes: 22 additions & 19 deletions app/assets/onepager/js/send.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
/* eslint-disable no-console */

function changeTokens() {
if (document.fundRequest && document.fundRequest.token_name) {
const is_token_selected = document.fundRequest.token_name;

$(`#token option:contains(${is_token_selected})`).attr('selected', 'selected');
$('#amount').val(document.fundRequest.amount);
}
$('#token').select2().trigger('change');
}

window.addEventListener('tokensReady', function(e) {
changeTokens();
}, false);

var get_gas_price = function() {
if (typeof defaultGasPrice != 'undefined') {
return defaultGasPrice;
Expand Down Expand Up @@ -68,18 +83,21 @@ $(document).ready(function() {
if (typeof userSearch != 'undefined') {
userSearch('.username-search', true);
}
set_metadata();
// jquery bindings
$('#advanced_toggle').on('click', function() {
advancedToggle();
});
$('#amount').on('keyup blur change', updateEstimate);
$('#token').on('change', updateEstimate);
$('#send').on('click', function(e) {
$('#send').on('click', async function(e) {
e.preventDefault();
if ($(this).hasClass('disabled'))
return;
loading_button($(this));

if (!provider) {
await onConnect();
}
// get form data
var email = $('#email').val();
var github_url = $('#issueURL').val();
Expand Down Expand Up @@ -139,22 +157,6 @@ $(document).ready(function() {

});

waitforWeb3(function() {
tokens(document.web3network).forEach(function(ele) {
if (ele && ele.addr) {
const is_token_selected = $('#token').data('token') === ele.name ? ' selected' : ' ';
const html = '<option value=' + ele.addr + is_token_selected + '>' + ele.name + '</option>';

$('#token').append(html);
}
});
let addr = tokenNameToDetails(document.web3network, document.default_token)['addr'];

console.log(addr);
$('#token').val(addr).select2();
jQuery('#token').select2();
});

});

function advancedToggle() {
Expand All @@ -175,6 +177,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, noAvailableUser) {
set_metadata();
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 @@ -329,7 +332,7 @@ function sendTip(email, github_url, from_name, username, amount, comments_public
var send_erc20 = function() {
var token_contract = new web3.eth.Contract(token_abi, tokenAddress);

token_contract.methods.transfer(destinationAccount, web3.utils.toHex(amountInDenom)).send({from: fromAccount}, post_send_callback);
token_contract.methods.transfer(destinationAccount, new web3.utils.BN(BigInt(amountInDenom)).toString()).send({from: fromAccount}, post_send_callback);
};
var send_gas_money_and_erc20 = function() {
_alert({ message: gettext('You will now be asked to confirm two transactions. The first is gas money, so your receipient doesnt have to pay it. The second is the actual token transfer. (note: check Metamask extension, sometimes the 2nd confirmation window doesnt popup)') }, 'info');
Expand Down
4 changes: 4 additions & 0 deletions app/assets/v2/css/gitcoin.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ h4,
color: #0FCE7C;
}

.gc-text-yellow {
color: #FFCE08;
}

.text-black-60 {
color: rgba(0, 0, 0, 0.6)!important;
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/css/submit_bounty.css
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ input:read-only {
}

.release-after-form-group-required {
border: 1px solid red;
border: none;
padding: 5px;
}

Expand Down
5 changes: 4 additions & 1 deletion app/assets/v2/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ $(document).ready(function() {
});
}

applyCartMenuStyles();
// TODO: MOVE TO GRANTS shared
if (typeof CartData != 'undefined') {
applyCartMenuStyles();
}

$('body').on('click', '.copy_me', function() {
$(this).focus();
Expand Down
31 changes: 30 additions & 1 deletion app/assets/v2/js/cart-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ class CartData {
return idList.includes(grantId);
}

static share_url(title) {
const donations = this.loadCart();
let bulk_add_cart = 'https://gitcoin.co/grants/cart/bulk-add/';

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

bulk_add_cart += String(donation['grant_id']) + ',';
}

if (document.contxt['github_handle']) {
bulk_add_cart += ':' + document.contxt['github_handle'];
}

if (title && typeof title != 'undefined') {
bulk_add_cart += ':' + encodeURI(title);
}

return bulk_add_cart;
}

static addToCart(grantData) {
if (this.cartContainsGrantWithId(grantData.grant_id)) {
return;
Expand All @@ -25,7 +46,15 @@ class CartData {
network = 'mainnet';
}
const acceptsAllTokens = (grantData.grant_token_address === '0x0000000000000000000000000000000000000000');
const accptedTokenName = tokenAddressToDetailsByNetwork(grantData.grant_token_address, network).name;

let accptedTokenName;

try {
accptedTokenName = tokenAddressToDetailsByNetwork(grantData.grant_token_address, network).name;
} catch (e) {
// When numbers are too small toWei fails because there's too many decimal places
accptedTokenName = 'DAI';
}

if (acceptsAllTokens || 'DAI' == accptedTokenName) {
grantData.grant_donation_amount = 5;
Expand Down
26 changes: 19 additions & 7 deletions app/assets/v2/js/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ Vue.component('grants-cart', {

if (vm.code) {
const verificationRequest = fetchData('/sms/validate/', 'POST', {
code: vm.code
code: vm.code,
phone: vm.phone
}, {'X-CSRFToken': vm.csrf});

$.when(verificationRequest).then(response => {
Expand Down Expand Up @@ -337,11 +338,21 @@ Vue.component('grants-cart', {
window.location.href = `${window.location.origin}/login/github/?next=/grants/cart`;
},

confirmClearCart() {
if (confirm('are you sure')) {
this.clearCart();
}
},

clearCart() {
CartData.setCart([]);
this.grantData = [];
update_cart_title();
},
shareCart() {
_alert('Cart URL copied to clipboard', 'success', 1000);
copyToClipboard(CartData.share_url());
},

removeGrantFromCart(id) {
CartData.removeIdFromCart(id);
Expand Down Expand Up @@ -629,14 +640,15 @@ 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.grantData.length));
this.clearCart();
var network = document.web3network;

if (network === 'rinkeby') {
window.location.href = `${window.location.origin}/grants/?network=rinkeby&category=`;
} else {
window.location.href = `${window.location.origin}/grants`;
}
setTimeout(function() {
if (network === 'rinkeby') {
window.location.href = `${window.location.origin}/grants/?network=rinkeby&category=`;
} else {
window.location.href = `${window.location.origin}/grants`;
}
}, 1500);
})
.on('error', (error, receipt) => {
// If the transaction was rejected by the network with a receipt, the second parameter will be the receipt.
Expand Down
Loading

0 comments on commit 6e9bc55

Please sign in to comment.