Skip to content
Permalink
Browse files

Merge pull request gnosis#55 from gnosis/feature/DEV-59-gas-modal

Feature/dev 59 gas modal
  • Loading branch information...
denisgranha committed Jan 24, 2018
2 parents 39b1755 + 8ecc571 commit 2cbad1b41c1097031cb6979c1916406099f28e14
@@ -5,12 +5,14 @@
.controller("depositCtrl", function ($scope, Transaction, $routeParams, $uibModalInstance, Wallet, Utils, wallet, Web3Service) {
$scope.wallet = wallet;
$scope.amount = 10;
$scope.deposit = function () {
$scope.deposit = function () {
Transaction.send(
{
to: $scope.wallet.address,
from: Web3Service.coinbase,
value: new ethereumjs.BN(new Web3().toWei($scope.amount))
value: new ethereumjs.BN(new Web3().toWei($scope.amount)),
gas: 50000,
gasPrice: Wallet.txParams.gasPrice
},
function (e, tx) {
if (e) {
@@ -13,6 +13,7 @@

$scope.confirmations = 1;
$scope.limit = 0;
$scope.maxAllowedConfirmations = 1;

$scope.removeOwner = function (address) {
delete $scope.owners[address];
@@ -102,6 +103,7 @@
$scope.addOwner = function () {
$scope.owners[$scope.newOwner.address] = $scope.newOwner;
$scope.newOwner = {}; // reset values
$scope.maxAllowedConfirmations = Object.keys($scope.owners).length
};
});
}
@@ -4,9 +4,6 @@
<title>Multisignature Wallet</title>
<script src="./bower_components/web3/dist/web3.js">
</script>
<script>
var Web3Local = Web3;
</script>
<script>
// Detect if it's an Electron app or not
var isElectron = (window && window.process && window.process.type) ? true : false;
@@ -0,0 +1,29 @@
<div class="modal-header">
<h3 class="modal-title">
Configure Gas
</h3>
</div>
<div class="modal-body">
<div class="form-group">
<label for="value">Gas limit:</label>
<input id="value" type="number" class="form-control" ng-model="gasLimit" step="any" ng-change="calculateFee()"
min="0" max="999999999999999" required >
</div>
<div class="form-group">
<label for="value">Gas price (GWei):</label>
<input id="value" type="number" class="form-control" ng-model="gasPrice" step="any" min="0" ng-change="calculateFee()"
max="999999999999999" required >
</div>
<div class="form-group">
<label for="value">Tx fees (ETH):</label>
<input id="value" disabled type="number" class="form-control" ng-model="txFee" step="any" min="0" max="999999999999999" required >
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="send()">
Send transaction
</button>
<button type="button" class="btn btn-danger" ng-click="cancel()">
Cancel
</button>
</div>
@@ -11,7 +11,7 @@ <h3 class="modal-title">
</div>
<div class="form-group">
<label for="required">Required confirmations</label>
<input id="required" type="number" class="form-control" ng-min="1" ng-max="owners.length" ng-model="confirmations" required />
<input id="required" type="number" class="form-control" ng-min="1" ng-max="{{maxAllowedConfirmations}}" ng-model="confirmations" required />
</div>
<div class="form-group">
<label for="daily-limit"> Daily limit (ETH) </label>
@@ -51,16 +51,14 @@
wallet.getGasPrice = function () {
return $q(
function(resolve, reject){
Web3Service.web3.eth.getGasPrice(
function (e, gasPrice) {
if (e) {
reject(e);
}
else {
resolve(gasPrice);
}
}
);
$http
.get('https://ethgasstation.info/json/ethgasAPI.json')
.then(
function(response) {
resolve(response.data.safeLow * 1e9)
},
reject
)
}
);
};
@@ -71,8 +69,8 @@
**/
wallet.txDefaults = function (tx) {
var txParams = {
gasPrice: ethereumjs.Util.intToHex(wallet.txParams.gasPrice),
gas: ethereumjs.Util.intToHex(wallet.txParams.gasLimit),
gasPrice: wallet.txParams.gasPrice,
gas: wallet.txParams.gasLimit,
from: Web3Service.coinbase
};

@@ -174,16 +172,12 @@

wallet.updateGasPrice = function (cb) {
if (Connection.isConnected) {
return Web3Service.web3.eth.getGasPrice.request(
function (e, gasPrice) {
if (e) {
cb(e);
}
else {
wallet.txParams.gasPrice = gasPrice.toNumber();
cb(null, gasPrice);
}
}
wallet.getGasPrice().then(
function (gasPrice) {
wallet.txParams.gasPrice = gasPrice;
cb(null, gasPrice);
},
cb
);
}
else {
@@ -533,32 +527,40 @@

wallet.deployWithLimit = function (owners, requiredConfirmations, limit, cb) {
var MyContract = Web3Service.web3.eth.contract(wallet.json.multiSigDailyLimit.abi);

MyContract.new(
owners,
requiredConfirmations,
limit,
wallet.txDefaults({
data: wallet.json.multiSigDailyLimit.binHex,
gas: (2556980 + 42733 * owners.length) // Gas to create multisig with dynamic gas for owners
}),
cb
);
var gasNeeded = 2556980 + 42733 * owners.length; // Gas to create multisig with dynamic gas for owners

Web3Service.configureGas({gas: gasNeeded, gasPrice: wallet.txParams.gasPrice}, function (gasOptions){
MyContract.new(
owners,
requiredConfirmations,
limit,
wallet.txDefaults({
data: wallet.json.multiSigDailyLimit.binHex,
gas: gasOptions.gas,
gasPrice: gasOptions.gasPrice
}),
cb
);
});
};

wallet.deployWithLimitFactory = function (owners, requiredConfirmations, limit, cb) {
var walletFactory = Web3Service.web3.eth.contract(wallet.json.multiSigDailyLimitFactory.abi).at(txDefault.walletFactoryAddress);

walletFactory.create(
owners,
requiredConfirmations,
limit,
wallet.txDefaults({
data: wallet.json.multiSigDailyLimit.binHex,
gas: (2002000 + 27820 * owners.length)
}),
cb
);
var gasNeeded = 2002000 + 27820 * owners.length;

Web3Service.configureGas({gas: gasNeeded, gasPrice: wallet.txParams.gasPrice}, function (gasOptions){
walletFactory.create(
owners,
requiredConfirmations,
limit,
wallet.txDefaults({
data: wallet.json.multiSigDailyLimit.binHex,
gas: gasOptions.gas,
gasPrice: gasOptions.gasPrice
}),
cb
);
});
};

wallet.deployWithLimitFactoryOffline = function (owners, requiredConfirmations, limit, cb) {
@@ -71,31 +71,78 @@
}
};

factory.sendTransaction = function (method, params, options, cb) {
// Simulate first
function sendIfSuccess(e, result) {
if (e) {
cb(e);
/**
* Configure gas limit and gas price
* Used for ledger wallet, lightwallet and ethereum node providers
**/
factory.configureGas = function (params, cb) {
$uibModal
.open(
{
animation: false,
templateUrl: 'partials/modals/configureGas.html',
size: 'md',
resolve: {
options: function () {
return params;
}
},
controller: function ($scope, $uibModalInstance, Web3Service, options) {
$scope.send = function () {
$uibModalInstance.close({gas: $scope.gasLimit, gasPrice: $scope.gasPrice * 1e9});
};

$scope.cancel = function () {
$uibModalInstance.dismiss();
}

$scope.close = $uibModalInstance.dismiss;
$scope.gasLimit = options.gas;
$scope.gasPrice = options.gasPrice / 1e9;

$scope.calculateFee = function () {
$scope.txFee = $scope.gasLimit * ($scope.gasPrice * 1e9) / 1e18;
}

$scope.calculateFee();
}
}
else {
if (result) {
method.sendTransaction.apply(method.sendTransaction, params.concat(cb));
)
.result
.then(cb);
};

factory.sendTransaction = function (method, params, options, cb) {

factory.configureGas(params[params.length-1], function(gasOptions){
var refinedTxOptions = Object.assign({}, params[params.length-1], gasOptions);
// Ugly but needed
params[params.length-1] = refinedTxOptions
// Simulate first
function sendIfSuccess(e, result) {
if (e) {
cb(e);
}
else {
cb("Simulated transaction failed");
if (result) {
method.sendTransaction.apply(method.sendTransaction, params.concat(cb));
}
else {
cb("Simulated transaction failed");
}
}
}
}

var args;
if ( options && options.onlySimulate) {
args = params.concat(cb);
method.call.apply(method.call, args);
}
else {
args = params.concat(sendIfSuccess);
method.call.apply(method.call, args);
}

var args;
if ( options && options.onlySimulate) {
args = params.concat(cb);
method.call.apply(method.call, args);
}
else {
args = params.concat(sendIfSuccess);
method.call.apply(method.call, args);
}
});
};

/**

0 comments on commit 2cbad1b

Please sign in to comment.
You can’t perform that action at this time.