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

metamask gas price preview #205

Merged
merged 11 commits into from Jan 4, 2018

preview on funded issue page:

  • Loading branch information...
owocki committed Jan 3, 2018
commit cec19192ae35fe0330b81019c87c8acf0ab4bffb
@@ -56,7 +56,6 @@ window.onload = function(){
updateInlineGasEstimate();
},100);
$('input').change(updateInlineGasEstimate);
$('input').keyup(updateInlineGasEstimate);


$('#submitBounty').click(function(e){
@@ -42,7 +42,6 @@ window.onload = function(){
updateInlineGasEstimate();
},100);
$('input').change(updateInlineGasEstimate);
$('input').keyup(updateInlineGasEstimate);

$('#submitBounty').click(function(e){
mixpanel.track("Clawback Bounty Clicked", {});
@@ -55,6 +55,70 @@ $(document).ready(function(){
}
});

var estimateGas = function(issueURL, success_callback, failure_calllback, final_callback){
//TODO: DRY
var bounty = web3.eth.contract(bounty_abi).at(bounty_address());
var githubUsername = $('input[name=githubUsername]').val();
var issueURL = $('input[name=issueURL]').val();
var notificationEmail = $('input[name=notificationEmail]').val();
var amount = $('input[name=amount]').val();
var tokenAddress = $('select[name=deonomination').val();
var token = (tokenAddress);
var decimals = token['decimals'];
var tokenName = token['name'];
var decimalDivisor = 10**decimals;
var expirationTimeDelta = $('select[name=expirationTimeDelta').val();
var isETH = tokenAddress == '0x0000000000000000000000000000000000000000';
var metadata = {
issueTitle : $('input[name=title').val(),
issueKeywords : $('input[name=keywords').val(),
tokenName : tokenName,
githubUsername : githubUsername,
notificationEmail : notificationEmail,
experienceLevel : $('select[name=experienceLevel').val(),
projectLength : $('select[name=projectLength').val(),
bountyType : $('select[name=bountyType').val(),
}
bounty.postBounty.estimateGas(issueURL,
amount,
tokenAddress,
expirationTimeDelta,
JSON.stringify(metadata),
function(errors,result){
var is_issue_taken = typeof result == 'undefined' || result > 12976605;
if(errors || is_issue_taken){
failure_calllback()
return;
}
var gas = Math.round(result * gasMultiplier);
var gasLimit = Math.round(gas * gasLimitMultiplier);
// for some reason web3 was estimating 6699496 as the gas for standardtoken transfers
if((gas > max_gas_for_erc20_bounty_post) && !isETH){
gas = Math.round(max_gas_for_erc20_bounty_post * gasMultiplier);
gasLimit = Math.round(gas * gasMultiplier);
}

success_callback(gas, gasLimit, final_callback);
});
}
//updates recommended metamask settings
var updateInlineGasEstimate = function(){
var success_callback = function(gas, gasLimit, _){
$("#gasLimit").val(parseInt(gas/16.1));
};
var failure_callback = function(){
$("#gasLimit").val('Unknown');
};
var final_callback = function(){};

estimateGas(issueURL, success_callback, failure_callback, final_callback);
};
setTimeout(function(){
updateInlineGasEstimate();
},500);
$('input').change(updateInlineGasEstimate);



//submit bounty button click
$('#submitBounty').click(function(e){
@@ -45,7 +45,6 @@ window.onload = function(){
updateInlineGasEstimate();
},100);
$('input').change(updateInlineGasEstimate);
$('input').keyup(updateInlineGasEstimate);

var bountyDetails = []

@@ -140,6 +140,7 @@ <h3>Fund an Issue</h3>
<div class="w-100 mt-2">
<a class="btn btn-sm btn-info mt-3 mb-1 pulseClick float-right" role="button" id="submitBounty" href="#">Fund Issue</a>
</div>
{% include 'shared/metamask_estimate.html' %}
<div class="w-100 mb-5 mt-1">
<a class="float-right" target=new href="https://github.com/gitcoinco/gitcoinco/issues?q=is%3Aissue+is%3Aopen+label%3Ahelp">Having trouble? Click here.</a>
</div>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.