Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Feature/dev 59 gas modal #55

Merged
merged 14 commits into from Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions dapp/controllers/depositCtrl.js
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions dapp/controllers/newWalletCtrl.js
Expand Up @@ -13,6 +13,7 @@

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

$scope.removeOwner = function (address) {
delete $scope.owners[address];
Expand Down Expand Up @@ -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
};
});
}
Expand Down
3 changes: 0 additions & 3 deletions dapp/index.html
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions dapp/partials/modals/configureGas.html
@@ -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>
2 changes: 1 addition & 1 deletion dapp/partials/modals/newWallet.html
Expand Up @@ -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>
Expand Down
90 changes: 46 additions & 44 deletions dapp/services/Wallet.js
Expand Up @@ -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
)
}
);
};
Expand All @@ -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
};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
87 changes: 67 additions & 20 deletions dapp/services/Web3Service.js
Expand Up @@ -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);
}
});
};

/**
Expand Down