Skip to content
Permalink
Browse files

Merge pull request #210 from gnosis/develop

Develop
  • Loading branch information...
giacomolicari committed Nov 16, 2018
2 parents 1584998 + d619af9 commit 8cd19b0d7e97e548529b07c5e84b02c18564e620
@@ -19,14 +19,14 @@ clone_depth: 5 # clone entire repository history if not defined
# to run your custom scripts instead of automatic tests
# test_script:
# - npm run test-dapp
# - npm run test
# - npm run test

# scripts that run after cloning repository
install:
- ps: Install-Product node 8 x64
- ps: $env:DEBUG = "electron-builder"
- npm i -g --production windows-build-tools
- cd dapp && rm -rf node_modules && rm package-lock.json && yarn add secp256k1 && yarn install && cd ..
- cd dapp && rm -rf node_modules && rm package-lock.json && yarn config set msvs_version 2015 --global && yarn add secp256k1 && yarn add sha3 && yarn install && cd ..

# to run your custom scripts instead of automatic MSBuild
build_script:
@@ -54,4 +54,4 @@ deploy:
secret_access_key: "%secret_access_key%"
bucket: wallet-desktop-builds
region: us-east-1
artifact: "exe"
artifact: "exe"
@@ -6,6 +6,7 @@
$scope.navCollapsed = true;
$scope.isElectron = isElectron;
$scope.config = Config.getConfiguration();
$scope.metamaskInjected = Web3Service.isMetamaskInjected();

// Reload config when it changes
$scope.$watch(
@@ -88,6 +89,25 @@
}
}

/**
* Opens Metamask widget and asks the user to allow the DApp accessing the accounts
*/
$scope.openMetamaskWidget = function (resolve, reject) {
// Ask to reload provider, it takes care of re-ejecuting metamask checks.
Web3Service.enableMetamask(function (error) {
if (error && reject) {
$scope.loggedIn = false;
reject();
}
else if (!error) {
$scope.loggedIn = true;
if (resolve) {
resolve();
}
}
});
};


$scope.updateInfo = function () {

@@ -104,7 +124,7 @@

// init params
$scope.paramsPromise = Wallet.initParams().then(function () {
$scope.loggedIn = Web3Service.coinbase;
$scope.loggedIn = !isElectron ? (Web3Service.coinbase !== undefined && Web3Service.coinbase !== null) : true;
$scope.coinbase = Web3Service.coinbase;
$scope.nonce = Wallet.txParams.nonce;
$scope.balance = Wallet.balance;
@@ -121,7 +141,8 @@
});
}
else {
$scope.accounts = [];
var accounts = Web3Service.accounts;
$scope.accounts = accounts || [];
}
}
}, function (error) {
@@ -212,10 +233,21 @@
size: 'md',
backdrop: 'static',
windowClass: 'bootstrap-dialog type-info',
scope: $scope,
controller: function ($scope, $uibModalInstance) {
$scope.ok = function () {
$uibModalInstance.close();
};

$scope.metamaskInjected = Web3Service.isMetamaskInjected();

$scope.openMetamaskWidgetAndClose = function () {
$scope.openMetamaskWidget(function () {
$scope.ok();
}, function () {
// DO nothing, user rejected unlocking Metamask
});
};
}
});
}
@@ -179,6 +179,9 @@
<span class="navbar-text">{{ethereumChain.chain.substr(0, 1).toUpperCase() + ethereumChain.chain.substr(1)}}</span>
<span class="navbar-text" ng-bind-html="statusIcon"></span>
</li>
<li ng-show="metamaskInjected && !loggedIn">
<a hef="#" ng-click="openMetamaskWidget()">Unlock Metamask</a>
</li>
</ul>
</div>
</nav>
@@ -1,6 +1,6 @@
{
"name": "multisigweb",
"version": "1.3.7",
"version": "1.4.0",
"eslintConfig": {
"env": {
"browser": true,
@@ -15,8 +15,6 @@
"certs": "openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt -subj '/CN=localhost/O=Multisig/C=US'",
"dist": "zip -x node_modules/\\* -x npm-debug.log -x tests/\\* -x config.karma.js -x .DS_Store -x .gitignore -r ../multisigWallet.zip ./",
"postinstall": "grunt ngtemplates",
"install-electron": "npm install && ./node_modules/.bin/electron-rebuild",
"electron-rebuild": "electron-rebuild --force --module_dir . -w node-hid -e node_modules/electron && npm rebuild leveldown scrypt",
"start": "http-server -a 0.0.0.0 -p 5000",
"start-electron": "NODE_ENV=development electron .",
"package-linux-x64": "electron-packager . MultisigWallet --prune --ignore=tests/* --ignore=testrpc.sh --platform=linux --out=./dist --overwrite=true --asar=true",
@@ -92,9 +90,9 @@
"asar": "0.13.1",
"babel-register": "6.26.0",
"coffee-script": "1.10.0",
"electron": "1.8.4",
"electron-builder": "20.15.1",
"electron-packager": "8.7.2",
"electron": "1.8.6",
"growl": "^1.10.5",
"grunt": "1.0.0",
"grunt-contrib-jshint": "1.1.0",
@@ -37,6 +37,6 @@
</div>
<div class="modal-footer">
<button type="button" ng-click="ok()" class="btn btn-default" id="terms-button" >
Cancel
Ok
</button>
</div>
@@ -15,6 +15,9 @@
<p>
You can monitor existing wallets without an account management software but you cannot create new wallets or sign transactions.
</p>
<p ngIf="metamaskInjected">
<a href="#" ng-click="openMetamaskWidgetAndClose()">Unlock Metamask</a>
</p>
</div>
<div class="modal-footer">
<button type="button" ng-click="ok()" class="btn btn-default" id="terms-button" >
@@ -4,7 +4,10 @@
.module('multiSigWeb')
.service("Web3Service", function ($window, $q, Utils, $uibModal, Connection, Config, $http) {

var factory = {};
var factory = {
coinbase: null,
accounts: []
};

factory.webInitialized = $q(function (resolve, reject) {
window.addEventListener('load', function () {
@@ -13,6 +16,33 @@
});
});

/**
* Asks Metamask to open its widget.
* Returns a callback call with the list of accounts or null in case the
* user rejects the approval request.
* @param callback, function (error, accounts)
*/
factory.enableMetamask = function (callback) {
$window.ethereum.enable().then(function (accounts) {
factory.reloadWeb3Provider();
// Set accounts and coinbase
factory.accounts = accounts;
factory.coinbase = accounts[0];
callback(null, accounts)
}).catch(function (error) {
callback(error, null)
});
};

/**
* Returns true if metamask is injected, false otherwise
**/
factory.isMetamaskInjected = function () {
return window && (typeof window.web3 !== 'undefined' &&
(window.web3.currentProvider.constructor.name === 'MetamaskInpageProvider' || window.web3.currentProvider.isMetaMask)
);
};

/**
* Reloads web3 provider
* @param resolve, function (optional)
@@ -22,14 +52,35 @@

factory.accounts = [];
factory.coinbase = null;
var web3 = null;

// Legacy dapp browsers...
if ($window.web3 && !$window.ethereum) {
web3 = $window.web3;
}
// TODO: figure out whether Metamask standardize isEnabled() or find out
// another way to manage it
else if ($window.ethereum && window.ethereum._metamask.isEnabled()) {
web3 = $window.ethereum;
}

// Ledger wallet
if (txDefault.wallet == "ledger") {
if (isElectron) {
factory.ledgerElectronSetup();
if (resolve) {
resolve();
}
factory.web3.eth.getAccounts(function (e, accounts) {
if (e) {
if (reject) {
reject(e);
}
} else {
factory.accounts = accounts;
factory.coinbase = factory.accounts[0];
if (resolve) {
resolve();
}
}
});
}
else {
factory.ledgerSetup();
@@ -45,8 +96,12 @@
}
}
// injected web3 provider (Metamask, mist, etc)
else if (txDefault.wallet == "injected" && $window && $window.web3 && !isElectron) {
factory.web3 = new MultisigWeb3($window.web3.currentProvider);
else if (txDefault.wallet == "injected" && web3 && !isElectron) {
factory.web3 = web3.currentProvider !== undefined ? new MultisigWeb3(web3.currentProvider) : new MultisigWeb3(web3);
// Set accounts
factory.accounts = factory.web3.eth.accounts;
factory.coinbase = factory.accounts[0];

if (resolve) {
resolve();
}
@@ -57,24 +112,44 @@
resolve();
}
}
else {
else if (txDefault.wallet == 'remotenode') {
// Connect to Ethereum Node
// factory.web3 = new MultisigWeb3(new RpcSubprovider({
// rpcUrl: txDefault.ethereumNode
// }));
factory.web3 = new MultisigWeb3(new MultisigWeb3.providers.HttpProvider(txDefault.ethereumNode));
// Check connection
factory.web3.net.getListening(function(e){
factory.web3.net.getListening(function(e) {
if (e) {
Utils.dangerAlert("You are not connected to any node.");
if (reject) {
reject();
}
}
else {
if (resolve) {
resolve();
}
// Get accounts from remote node
factory.web3.eth.getAccounts(function(e, accounts) {
if (e) {
if (reject) {
reject(e);
}
}
else {
// Set accounts
factory.accounts = accounts;
factory.coinbase = accounts[0];

if (resolve) {
resolve();
}
}
});
}
});
}
else if (resolve) {
resolve();
}
};

/**
@@ -169,28 +244,33 @@
* Get ethereum accounts and update account list.
*/
factory.updateAccounts = function (cb) {
return factory.web3.eth.getAccounts(
function (e, accounts) {
if (e) {
cb(e);
}
else {
factory.accounts = accounts;

if (factory.coinbase && accounts && accounts.length && accounts.indexOf(factory.coinbase) != -1) {
// same coinbase
}
else if (accounts) {
factory.coinbase = accounts[0];
if (!isElectron && factory.coinbase) {
return factory.web3.eth.getAccounts(
function (e, accounts) {
if (e) {
cb(e);
}
else {
factory.coinbase = null;
}
factory.accounts = accounts;

cb(null, accounts);
if (factory.coinbase && accounts && accounts.length && accounts.indexOf(factory.coinbase) != -1) {
// same coinbase
}
else if (accounts) {
factory.coinbase = accounts[0];
}
else {
factory.coinbase = null;
}

cb(null, accounts);
}
}
}
);
);
}
else {
cb(null, null);
}
};

/* Ledger setup on browser*/
@@ -6,4 +6,3 @@ sleep 5;
karma start config.karma.js
echo "Shutting down TestRpc..."
kill -9 $testrpc_pid
./node_modules/.bin/electron-rebuild;
@@ -1,6 +1,6 @@
{
"name": "multisig-wallet-gnosis",
"version": "1.3.7",
"version": "1.4.0",
"description": "Main module, for installing all dependencies",
"scripts": {
"test-dapp": "cd dapp && npm test",
@@ -27,6 +27,7 @@
"dependencies": {
"child_process": "1.0.2",
"ethereumjs-testrpc": "4.1.3",
"ganache-cli": "^6.1.8",
"truffle": "3.4.11"
},
"devDependencies": {

0 comments on commit 8cd19b0

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