Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrate StandardBounties#increasePayout()
Gives the funder the ability to increase the payout. Changes: - add new route for increase_bounty view - add increase_bounty view and js - DRY up duplicate code in new_bounty.js and increase_bounty.js - implement bounty increase notification through git, slack and twitter
- Loading branch information
Showing
9 changed files
with
335 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
load_tokens(); | ||
|
||
// Wait until page is loaded, then run the function | ||
$(document).ready(function() { | ||
$('input[name=amount]').keyup(setUsdAmount); | ||
$('input[name=amount]').blur(setUsdAmount); | ||
$('select[name=deonomination]').change(setUsdAmount); | ||
|
||
$('input[name=amount]').focus(); | ||
|
||
var denomSelect = $('select[name=deonomination]'); | ||
|
||
localStorage['tokenAddress'] = denomSelect.data('tokenAddress'); | ||
localStorage['amount'] = 0; | ||
denomSelect.select2(); | ||
$('.js-select2').each(function() { | ||
$(this).select2(); | ||
}); | ||
|
||
// submit bounty button click | ||
$('#submitBounty').click(function(e) { | ||
mixpanel.track('Increase Bounty Clicked (funder)', {}); | ||
|
||
// setup | ||
e.preventDefault(); | ||
loading_button($(this)); | ||
|
||
var issueURL = $('input[name=issueURL]').val(); | ||
var amount = $('input[name=amount]').val(); | ||
var tokenAddress = $('select[name=deonomination]').val(); | ||
var token = tokenAddressToDetails(tokenAddress); | ||
var decimals = token['decimals']; | ||
var tokenName = token['name']; | ||
var decimalDivisor = Math.pow(10, decimals); | ||
|
||
// validation | ||
var isError = false; | ||
|
||
if ($('#terms:checked').length == 0) { | ||
_alert({ message: 'Please accept the terms of service.' }); | ||
isError = true; | ||
} else { | ||
localStorage['acceptTOS'] = true; | ||
} | ||
var is_issueURL_invalid = issueURL == '' || | ||
issueURL.indexOf('http') != 0 || | ||
issueURL.indexOf('github') == -1 || | ||
issueURL.indexOf('javascript:') != -1 | ||
|
||
; | ||
if (is_issueURL_invalid) { | ||
_alert({ message: 'Please enter a valid github issue URL.' }); | ||
isError = true; | ||
} | ||
if (amount == '') { | ||
_alert({ message: 'Please enter an amount.' }); | ||
isError = true; | ||
} | ||
if (isError) { | ||
unloading_button($(this)); | ||
return; | ||
} | ||
$(this).attr('disabled', 'disabled'); | ||
|
||
// setup web3 | ||
// TODO: web3 is using the web3.js file. In the future we will move | ||
// to the node.js package. github.com/ethereum/web3.js | ||
var isETH = tokenAddress == '0x0000000000000000000000000000000000000000'; | ||
var token_contract = web3.eth.contract(token_abi).at(tokenAddress); | ||
var account = web3.eth.coinbase; | ||
|
||
amount = amount * decimalDivisor; | ||
// Create the bounty object. | ||
// This function instantiates a contract from the existing deployed Standard Bounties Contract. | ||
// bounty_abi is a giant object containing the different network options | ||
// bounty_address() is a function that looks up the name of the network and returns the hash code | ||
var bounty = web3.eth.contract(bounty_abi).at(bounty_address()); | ||
|
||
// setup inter page state | ||
localStorage[issueURL] = JSON.stringify({ | ||
'timestamp': null, | ||
'txid': null | ||
}); | ||
|
||
function web3Callback(error, result) { | ||
if (error) { | ||
mixpanel.track('Increase Bounty Error (funder)', {step: 'post_bounty', error: error}); | ||
_alert({ message: 'There was an error. Please try again or contact support.' }); | ||
unloading_button($('#submitBounty')); | ||
return; | ||
} | ||
|
||
// update localStorage issuePackage | ||
var issuePackage = JSON.parse(localStorage[issueURL]); | ||
|
||
issuePackage['txid'] = result; | ||
issuePackage['timestamp'] = timestamp(); | ||
localStorage[issueURL] = JSON.stringify(issuePackage); | ||
|
||
_alert({ message: 'Submission sent to web3.' }, 'info'); | ||
setTimeout(function() { | ||
mixpanel.track('Submit New Bounty Success', {}); | ||
document.location.href = '/funding/details/?url=' + issueURL; | ||
}, 1000); | ||
} | ||
|
||
var bountyAmount = parseInt($('input[name=valueInToken]').val(), 10); | ||
var ethAmount = isETH ? amount : 0; | ||
var bountyId = $('input[name=standardBountiesId]').val(); | ||
var fromAddress = $('input[name=bountyOwnerAddress]').val(); | ||
|
||
var errormsg = undefined; | ||
|
||
if (bountyAmount == 0 || open == false) { | ||
errormsg = 'No active funded issue found at this address. Are you sure this is an active funded issue?'; | ||
} | ||
if (fromAddress != web3.eth.coinbase) { | ||
errormsg = 'Only the address that submitted this funded issue may increase the payout.'; | ||
} | ||
|
||
if (errormsg) { | ||
_alert({ message: errormsg }); | ||
unloading_button($('#submitBounty')); | ||
return; | ||
} | ||
|
||
function approveSuccessCallback() { | ||
bounty.increasePayout( | ||
bountyId, | ||
bountyAmount + amount, | ||
amount, | ||
{ | ||
from: account, | ||
value: ethAmount, | ||
gasPrice: web3.toHex($('#gasPrice').val()) * Math.pow(10, 9) | ||
}, | ||
web3Callback | ||
); | ||
} | ||
|
||
if (isETH) { | ||
// no approvals needed for ETH | ||
approveSuccessCallback(); | ||
} else { | ||
token_contract.approve( | ||
bounty_address(), | ||
amount, | ||
{ | ||
from: account, | ||
value: 0, | ||
gasPrice: web3.toHex($('#gasPrice').val()) * Math.pow(10, 9) | ||
}, | ||
approveSuccessCallback | ||
); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{% comment %} | ||
Copyright (C) 2017 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 static %} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
{% include 'shared/head.html' %} | ||
{% include 'shared/cards.html' %} | ||
</head> | ||
|
||
<body class="interior {{active}}"> | ||
{% include 'shared/tag_manager_2.html' %} | ||
<div class="container-fluid header dash"> | ||
{% include 'shared/nav.html' %} | ||
</div> | ||
<div class="row no-gutter"> | ||
<div class="col-12 body"> | ||
<div class="container-fluid no-gutter"> | ||
<div class="row font-smaller-2" id="form_container"> | ||
{% include 'shared/no_metamask_error.html' %} | ||
{% include 'shared/zero_balance_error.html' %} | ||
{% include 'shared/unlock_metamask.html' %} | ||
<input type="hidden" name="standardBountiesId" | ||
value="{{standard_bounties_id}}"> | ||
<input type="hidden" name="bountyOwnerAddress" | ||
value="{{bounty_owner_address}}"> | ||
<input type="hidden" name="valueInToken" | ||
value="{{value_in_token}}"> | ||
<div class="col offset-md-1 col-md-10 d-flex align-items-center justify-content-center" id="primary_form"> | ||
<div class="d-flex justify-content-center flex-column mt-5 w-50" id="primary_subform"> | ||
<div class="w-100" style="text-align: center;"> | ||
<h3>Increase Funding</h3> | ||
<img src="{% static "v2/images/prime.png" %}"> | ||
</div> | ||
{% include 'shared/network_status.html' %} | ||
<div class="w-100"> | ||
<label class="form__label" for=issueURL>Issue URL</label> | ||
<input name='issueURL' id="issueURL" class="w-100 form__input" type="url" placeholder="https://github.com/user/repo/pull/n" value="{% if issueURL %}{{issueURL}}{%endif%}" disabled/> | ||
</div> | ||
<div class="w-100 mt-2"> | ||
<label class="form__label" for="amount">Amount</label> | ||
<div class="form__flex-group"> | ||
<div class="form__amount-wrapper"> | ||
<input name='amount' id='amount' class="form__input" type="number" placeholder="Amount" /> | ||
</div> | ||
<div class="form__group-item"> | ||
<div class="form__select2"> | ||
<select name='deonomination' id='token' data-token-address='{{token_address}}' disabled></select> | ||
</div> | ||
<small class="form__input-help form__input-help--dynamic" id="usd_amount"></small> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="w-100 mt-2 terms_container"> | ||
<div class="form__checkbox"> | ||
<input name='terms' id='terms' type="checkbox" value=1 /> | ||
<label class="form__label" for=terms>I have read, understand, and agree to, the <a href="{% url "terms" %}" target=new>Terms of Service</a>:</label> | ||
</div> | ||
</div> | ||
{% include 'shared/metamask_estimate.html' %} | ||
<div class="form__footer form__footer--right"> | ||
<button class="button button--primary" type="submit" id="submitBounty">Increase Funding</button> | ||
<br /> | ||
<a target=new href="https://github.com/gitcoinco/gitcoinco/issues?q=is%3Aissue+is%3Aopen+label%3Ahelp">Having trouble? Click here.</a> | ||
</div> | ||
{% include 'shared/newsletter.html' %} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% include 'shared/bottom_notification.html' %} | ||
{% include 'shared/analytics.html' %} | ||
{% include 'shared/footer_scripts.html' %} | ||
{% include 'shared/rollbar.html' %} | ||
{% include 'shared/footer.html' %} | ||
|
||
</body> | ||
|
||
|
||
<!-- jQuery --> | ||
<script src="{% static "v2/js/ipfs-api.js" %}"></script> | ||
<script src="{% static "v2/js/ipfs.js" %}"></script> | ||
<script src="{% static "v2/js/amounts.js" %}"></script> | ||
<script src="{% static "v2/js/abi.js" %}"></script> | ||
<script src="{% static "v2/js/tokens.js" %}"></script> | ||
<script src="{% static "v2/js/shared.js" %}"></script> | ||
<script src="{% static "v2/js/pages/shared_bounty_mutation_estimate_gas.js" %}"></script> | ||
<script src="{% static "v2/js/pages/increase_bounty.js" %}"></script> | ||
|
||
|
||
</html> |
Oops, something went wrong.