Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
updates confirmation window size issue (#1665)
Browse files Browse the repository at this point in the history
* updates confirmation window size issue

* updated to web3.js 0.18.2, please run yarn

* improved gas estimation errors

* add error check only when estimatedGas is lower than providedGas
  • Loading branch information
alexvansande authored and frozeman committed Feb 17, 2017
1 parent 34b395e commit 8429c2d
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 28 deletions.
12 changes: 9 additions & 3 deletions interface/client/lib/ethereum/1_web3js_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
if(typeof web3 !== 'undefined') {
console.info('Web3 already initialized, re-using provider.');

web3 = new Web3(web3.currentProvider);
// add web3 backwards compatibility
if(!web3.currentProvider.sendAsync) {
web3.currentProvider.sendAsync = web3.currentProvider.send;
web3.currentProvider.send = web3.currentProvider.sendSync;
}

web3 = new Web3(web3.currentProvider);
} else {
console.info('Web3 not yet initialized, doing so now with HttpProvider.');
console.info('Web3 not yet initialized, doing so now with HttpProvider.');

web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ <h1>{{i18n "mist.popupWindows.sendTransactionConfirmation.title.createContract"}
{{/if}}

<div class="container">
<div class="transaction-parties">
<div class="inner-container">
<div class="transaction-parties">
<div>
{{#if TemplateVar.get "fromIsContract"}}
<i class="overlap-icon icon-doc"></i>
Expand Down Expand Up @@ -54,15 +55,35 @@ <h1>{{i18n "mist.popupWindows.sendTransactionConfirmation.title.createContract"}
</div>

{{#if transactionInvalid}}
<p class="info dapp-error"> {{{i18n "mist.popupWindows.sendTransactionConfirmation.estimatedGasError"}}} </p>
<p class="info dapp-error">
{{i18n "mist.popupWindows.sendTransactionConfirmation.estimatedGasError"}}
</p>
{{else}}
{{#if $and data (TemplateVar.get "toIsContract")}}
<p class="info">{{{i18n "mist.popupWindows.sendTransactionConfirmation.contractExecutionInfo"}}}</p>
{{/if}}
{{#unless $eq (TemplateVar.get "gasError") "notEnoughGas"}}
{{#if $eq (TemplateVar.get "gasError") "overBlockGasLimit"}}
<div class="info dapp-error">
{{i18n "mist.popupWindows.sendTransactionConfirmation.overBlockGasLimit"}}
</div>
{{else}}
{{#if $and data (TemplateVar.get "toIsContract")}}
<p class="info">
{{i18n "mist.popupWindows.sendTransactionConfirmation.contractExecutionInfo"}}
</p>
{{/if}}

{{#unless to}}
<p class="info">
{{i18n "mist.popupWindows.sendTransactionConfirmation.contractCreationInfo"}}
</p>
{{/unless}}

{{#unless to}}
<p class="info">{{{i18n "mist.popupWindows.sendTransactionConfirmation.contractCreationInfo"}}}</p>
{{/if}}
{{else}}
<div class="info dapp-error not-enough-gas" style="cursor: pointer;">
{{{i18n "mist.popupWindows.sendTransactionConfirmation.notEnoughGas"}}}
</div>
{{/unless}}

{{/if}}

<div class="fees">
Expand Down Expand Up @@ -107,8 +128,8 @@ <h1>{{i18n "mist.popupWindows.sendTransactionConfirmation.title.createContract"}
{{#if data}}
{{#if showFormattedParams}}
<div class="parameters">
<h3>{{{i18n "mist.popupWindows.sendTransactionConfirmation.parameters"}}}
<a href="#" class="toggle-panel">{{{i18n "mist.popupWindows.sendTransactionConfirmation.showRawBytecode"}}}</a>
<h3>{{i18n "mist.popupWindows.sendTransactionConfirmation.parameters"}}
<a href="#" class="toggle-panel">{{i18n "mist.popupWindows.sendTransactionConfirmation.showRawBytecode"}}</a>
</h3>
<ol>
{{# each param in params}}
Expand All @@ -121,7 +142,7 @@ <h3>{{{i18n "mist.popupWindows.sendTransactionConfirmation.parameters"}}}
<h3>{{i18n "mist.popupWindows.sendTransactionConfirmation.data"}}

{{# if params}}
<a href="#" class="toggle-panel">{{{i18n "mist.popupWindows.sendTransactionConfirmation.showDecodedParameters"}}}</a>
<a href="#" class="toggle-panel">{{i18n "mist.popupWindows.sendTransactionConfirmation.showDecodedParameters"}}</a>
{{else}}
{{#if to}}
{{#unless (TemplateVar.get "lookingUpFunctionSignature")}}
Expand All @@ -137,6 +158,7 @@ <h3>{{i18n "mist.popupWindows.sendTransactionConfirmation.data"}}
{{/if}}
{{/if}}

</div>
</div>
<footer>
{{#if TemplateVar.get "unlocking"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Template Controllers

var setWindowSize = function(template){
Tracker.afterFlush(function(){
ipc.send('backendAction_setWindowSize', 580, template.$('.popup-windows').height() + 120);
ipc.send('backendAction_setWindowSize', 580, template.$('.popup-windows .inner-container').height() + 240);
});
}


var defaultEstimateGas = 50000000;
var defaultEstimateGas = 50000000;

/**
The sendTransaction confirmation popup window template
Expand Down Expand Up @@ -89,6 +89,7 @@ var signatureLookupCallback = function(textSignature) {
}
};


Template['popupWindows_sendTransactionConfirmation'].onCreated(function(){
var template = this;

Expand All @@ -97,6 +98,18 @@ Template['popupWindows_sendTransactionConfirmation'].onCreated(function(){
TemplateVar.set(template, 'params', params);
});

// check reactively if provided gas is enough
this.autorun(function(){
if(TemplateVar.get('estimatedGas') > Number(TemplateVar.get('providedGas')))
TemplateVar.set('gasError', 'notEnoughGas');
else if(TemplateVar.get('estimatedGas') > 4000000)
TemplateVar.set('gasError', 'overBlockGasLimit');
else
TemplateVar.set('gasError', null);
});


// check inital data and gas estimates
this.autorun(function(){
TemplateVar.set(template, 'displayDecodedParams', true);

Expand Down Expand Up @@ -156,23 +169,24 @@ Template['popupWindows_sendTransactionConfirmation'].onCreated(function(){
});
}

// esitmate gas usage
// estimate gas usage
var estimateData = _.clone(data);
estimateData.gas = defaultEstimateGas;
web3.eth.estimateGas(estimateData, function(e, res){
console.log('Estimated gas: ', res, e);
if(!e && res) {

// set the gas to the estimation, if not provided or lower
Tracker.nonreactive(function(){
var gas = Number(TemplateVar.get(template, 'providedGas'));

if(defaultEstimateGas === res)
if(res === defaultEstimateGas)
return TemplateVar.set(template, 'estimatedGas', 'invalid');
else
TemplateVar.set(template, 'estimatedGas', res);

// set the gas to the estimation, if not provided or lower
var gas = TemplateVar.get(template, 'providedGas');
TemplateVar.set(template, 'estimatedGas', res);


if(gas == 0) {
if(!gas && res) {
TemplateVar.set(template, 'providedGas', res + 100000);
TemplateVar.set(template, 'initialProvidedGas', res + 100000);
}
Expand Down Expand Up @@ -279,6 +293,16 @@ Template['popupWindows_sendTransactionConfirmation'].events({
TemplateVar.set('providedGas', gas);
},
/**
Increase the estimated gas
@event click .not-enough-gas
*/
'click .not-enough-gas': function(){
var gas = Number(TemplateVar.get('estimatedGas')) + 100000;
TemplateVar.set('initialProvidedGas', gas);
TemplateVar.set('providedGas', gas);
},
/**
Cancel the transaction confirmation and close the popup
@event click .cancel
Expand Down Expand Up @@ -319,7 +343,7 @@ Template['popupWindows_sendTransactionConfirmation'].events({
TemplateVar.set('unlocking', true);

// unlock and send transaction!
web3.personal.unlockAccountAndSendTransaction(data, pw || '', function(e, res){
web3.personal.sendTransaction(data, pw || '', function(e, res){
pw = null;
TemplateVar.set(template, 'unlocking', false);

Expand Down
4 changes: 3 additions & 1 deletion interface/i18n/mist.en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@
"unlocking": "Confirming...",
"createContract": "Create contract",
"estimatedFee": "Estimated fee consumption",
"estimatedGasError": "It seems this transaction will fail. If you submit it, it may consume all the gas you send.",
"estimatedGasError": "It seems this transaction will fail. If you submit it, it may consume all the gas you provide.",
"transactionThrow": "The contract won't allow this transaction to be executed",
"overBlockGasLimit": "The gas required for this execution could exceed the block gas limit.",
"notEnoughGas": "Gas might not be enough to successfully finish this transaction.<br>Click here to increase the gas amount.",
"noEstimate": "We couldn't estimate the gas.",
"gasPrice": "Gas price",
"perMillionGas": "ether per million gas",
Expand Down
2 changes: 2 additions & 0 deletions modules/ipc/methods/eth_sendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ module.exports = class extends BaseProcessor {
width: 580,
height: 550,
alwaysOnTop: true,
enableLargerThanScreen: false,
resizable: true
},
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"underscore": "^1.8.3",
"underscore-deep-extend": "^1.1.5",
"uuid": "^3.0.1",
"web3": "^0.17.0-alpha",
"web3": "^0.18.2",
"yargs": "^6.6.0"
},
"devDependencies": {
Expand Down
11 changes: 8 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4231,13 +4231,14 @@ wdio-dot-reporter@^0.0.6:
dependencies:
babel-runtime "^5.8.25"

web3@^0.17.0-alpha:
version "0.17.0-beta"
resolved "https://registry.yarnpkg.com/web3/-/web3-0.17.0-beta.tgz#57af38245bff7a32099f7ce5780fad5bbc00da5b"
web3@^0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/web3/-/web3-0.18.2.tgz#61b1a6edf5056820e22e1ef082f54c279f4bf758"
dependencies:
bignumber.js "git+https://github.com/debris/bignumber.js.git#94d7146671b9719e00a09c29b01a691bc85048c2"
crypto-js "^3.1.4"
utf8 "^2.1.1"
xhr2 "*"
xmlhttprequest "*"

webdriverio@^4.0.4:
Expand Down Expand Up @@ -4335,6 +4336,10 @@ xdg-basedir@^2.0.0:
dependencies:
os-homedir "^1.0.0"

xhr2@*:
version "0.1.4"
resolved "https://registry.yarnpkg.com/xhr2/-/xhr2-0.1.4.tgz#7f87658847716db5026323812f818cadab387a5f"

xml2js@^0.4.17:
version "0.4.17"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.17.tgz#17be93eaae3f3b779359c795b419705a8817e868"
Expand Down

0 comments on commit 8429c2d

Please sign in to comment.