Skip to content

Commit

Permalink
Merge pull request gnosis#158 from gnosis/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
denisgranha authored Jun 5, 2018
2 parents 676c5f6 + f0f0a96 commit c52b007
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 26 deletions.
1 change: 1 addition & 0 deletions dapp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var txDefaultOrig =
url : "https://www.google.com",
checkInterval: 5000
},
ethGasStation: "https://safe-relay.gnosis.pm/api/v1/gas-station/",
wallet: "injected",
defaultChainID: null,
// Mainnet
Expand Down
7 changes: 6 additions & 1 deletion dapp/controllers/accountCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,12 @@

$scope.importAccount = function () {
// Import light wallet account
Web3Service.importLightWalletAccount($scope.fileContent, $scope.account.password, function (newAddress) {
Web3Service.importLightWalletAccount($scope.fileContent, $scope.account.password, function (error, newAddress) {
if (error) {
Utils.dangerAlert(error);
return;
}

var accounts = Config.getConfiguration('accounts');
var accountName = $scope.account.name;

Expand Down
4 changes: 1 addition & 3 deletions dapp/controllers/footerCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
.controller('footerCtrl', function ($scope) {
$scope.navCollapsed = true;
$scope.isElectron = isElectron;
console.log(isElectron, shell)


// electron show terms and policy
$scope.openTerms = function() {
Expand All @@ -23,4 +21,4 @@

});
}
)();
)();
36 changes: 34 additions & 2 deletions dapp/controllers/navCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,28 @@
$scope.nonce = Wallet.txParams.nonce;
$scope.paramsPromise = null;
}
else if (txDefault.wallet == "lightwallet") {
// Retrieves accounts from localStorage, cannot get them from the injected web3 as we
// are offline
if (Config.getConfiguration('accounts')) {
$scope.accounts = Config.getConfiguration('accounts').map(function (account) {
return account.address;
});

if (Web3Service.coinbase) {
$scope.coinbase = Web3Service.coinbase;
}
else {
$scope.coinbase = $scope.accounts[0];
}

$scope.loggedIn = true;
}
else {
// $scope.accounts = [];
$scope.loggedIn = false;
}
}
else {
var syncErrorShown = Config.getConfiguration('syncErrorShown');
if (!syncErrorShown) {
Expand All @@ -159,10 +181,17 @@

};

/**
* Update info independently we're online or offline
*/
$scope.updateInfo();
$scope.interval = $interval($scope.updateInfo, 5000);

/**
* Initialize web3
*/
Web3Service.webInitialized.then(
function () {
$scope.interval = $interval($scope.updateInfo, 5000);

/**
* Lookup connection status
* Check connectivity first on page loading
Expand Down Expand Up @@ -193,6 +222,9 @@
});
}
});
},
function (error, e) {
// do nothing
}
);

Expand Down
4 changes: 3 additions & 1 deletion dapp/controllers/sendTransactionCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
$scope.params = [];

$scope.send = function () {
var tx = {};
var tx = Wallet.txDefaults({
gas: 21000
});
Object.assign(tx, $scope.tx);
var params = [];
Object.assign(params, $scope.params);
Expand Down
10 changes: 5 additions & 5 deletions dapp/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@
}
else {
scope.selectedItem = null;
}
}

scope.changeEvent = function() {
scope.$parent.config.wallet = scope.selectedItem.name;
if (attrs.onChangeFunction !== undefined) {
var func = scope.$parent[attrs.onChangeFunction];
func();
}
}
};
}
};
Expand All @@ -308,7 +308,7 @@
require: '^ngModel',
scope: {
ngModel: '=',
options: '=',
options: '=',
other: '@'
},
replace: true,
Expand Down Expand Up @@ -408,7 +408,7 @@
});
};
})
.directive('disabledIfInvalidAddress', function () {
.directive('disabledIfInvalidAddress', function (Web3Service) {
// Disables an element until the ng-model passed to
// the directive is valid
return {
Expand All @@ -424,7 +424,7 @@
if (attrs.disabledIfInvalidAddress.length < 42) {
isAddressValid = false;
}
else if (web3.isAddress(attrs.disabledIfInvalidAddress)) {
else if (Web3Service.web3.isAddress(attrs.disabledIfInvalidAddress)) {
// Address valid (0x0........)
isAddressValid = true;
}
Expand Down
4 changes: 2 additions & 2 deletions dapp/services/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
return $q(
function(resolve, reject){
$http
.get('https://ethgasstation.info/json/ethgasAPI.json')
.get(txDefault.ethGasStation)
.then(
function(response) {
resolve((response.data.safeLow / 10) * 1e9)
resolve(response.data.standard)
},
function (error) {
// Get gas price from Ethereum Node
Expand Down
36 changes: 24 additions & 12 deletions dapp/services/Web3Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
* Configure gas limit and gas price
* Used for ledger wallet, lightwallet and ethereum node providers
**/
factory.configureGas = function (params, cb) {
factory.configureGas = function (params, cb) {
$uibModal
.open(
{
Expand All @@ -102,14 +102,14 @@
$uibModalInstance.dismiss();
}

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

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

$scope.calculateFee();
}
Expand All @@ -131,15 +131,15 @@
cb(e);
}
else {
if (result) {
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);
Expand All @@ -148,8 +148,8 @@
else {
args = params.concat(sendIfSuccess);
method.call.apply(method.call, args);
}
});
}
});
};

/**
Expand Down Expand Up @@ -342,7 +342,7 @@
getAccounts: function (cb) {
if(!factory.accounts.length) {
TrezorConnect.ethereumGetAddress("m/44'/60'/0'/0/0", function(response) {
if(response.success){
if(response.success){
factory.accounts = ["0x" + response.address];
cb(null, factory.accounts)
}
Expand Down Expand Up @@ -390,7 +390,7 @@
cb(response.error)
}
})
});
});
}
});

Expand Down Expand Up @@ -573,14 +573,26 @@

factory.importLightWalletAccount = function (v3, password, ctrlCallback) {
// DIRTY but MyEtherWallet doesn't generate an standard V3 file, it adds a word Crypto instead of crypto
v3.crypto = v3.Crypto;
delete v3.Crypto;
if (v3.Crypto && !v3.crypto) {
v3.crypto = v3.Crypto;
delete v3.Crypto;
}
var v3String = JSON.stringify(v3);
// Verify passphrase is correct
try {
v3Instance = ethereumWallet.fromV3(v3String, password);
} catch (error) {
ctrlCallback(error);
return;
}


// key => value object (address => V3)
var keystoreObj = JSON.parse(factory.getKeystore()) || {};

// Set keystore in V3 format
factory.keystore = v3;

// Encrypt V3
encryptor.encrypt(password, v3String)
.then(function (encryptedV3String) {
Expand All @@ -601,7 +613,7 @@
// Do web3 setup
factory.lightWalletSetup(false);

ctrlCallback(generatedAddress);
ctrlCallback(null, generatedAddress);
});
};

Expand Down

0 comments on commit c52b007

Please sign in to comment.