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

Commit 8cd19b0

Browse files
Merge pull request #210 from gnosis/develop
Develop
2 parents 1584998 + d619af9 commit 8cd19b0

File tree

9 files changed

+157
-41
lines changed

9 files changed

+157
-41
lines changed

appveyor.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ clone_depth: 5 # clone entire repository history if not defined
1919
# to run your custom scripts instead of automatic tests
2020
# test_script:
2121
# - npm run test-dapp
22-
# - npm run test
22+
# - npm run test
2323

2424
# scripts that run after cloning repository
2525
install:
2626
- ps: Install-Product node 8 x64
2727
- ps: $env:DEBUG = "electron-builder"
2828
- npm i -g --production windows-build-tools
29-
- cd dapp && rm -rf node_modules && rm package-lock.json && yarn add secp256k1 && yarn install && cd ..
29+
- 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 ..
3030

3131
# to run your custom scripts instead of automatic MSBuild
3232
build_script:
@@ -54,4 +54,4 @@ deploy:
5454
secret_access_key: "%secret_access_key%"
5555
bucket: wallet-desktop-builds
5656
region: us-east-1
57-
artifact: "exe"
57+
artifact: "exe"

dapp/controllers/navCtrl.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
$scope.navCollapsed = true;
77
$scope.isElectron = isElectron;
88
$scope.config = Config.getConfiguration();
9+
$scope.metamaskInjected = Web3Service.isMetamaskInjected();
910

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

92+
/**
93+
* Opens Metamask widget and asks the user to allow the DApp accessing the accounts
94+
*/
95+
$scope.openMetamaskWidget = function (resolve, reject) {
96+
// Ask to reload provider, it takes care of re-ejecuting metamask checks.
97+
Web3Service.enableMetamask(function (error) {
98+
if (error && reject) {
99+
$scope.loggedIn = false;
100+
reject();
101+
}
102+
else if (!error) {
103+
$scope.loggedIn = true;
104+
if (resolve) {
105+
resolve();
106+
}
107+
}
108+
});
109+
};
110+
91111

92112
$scope.updateInfo = function () {
93113

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

105125
// init params
106126
$scope.paramsPromise = Wallet.initParams().then(function () {
107-
$scope.loggedIn = Web3Service.coinbase;
127+
$scope.loggedIn = !isElectron ? (Web3Service.coinbase !== undefined && Web3Service.coinbase !== null) : true;
108128
$scope.coinbase = Web3Service.coinbase;
109129
$scope.nonce = Wallet.txParams.nonce;
110130
$scope.balance = Wallet.balance;
@@ -121,7 +141,8 @@
121141
});
122142
}
123143
else {
124-
$scope.accounts = [];
144+
var accounts = Web3Service.accounts;
145+
$scope.accounts = accounts || [];
125146
}
126147
}
127148
}, function (error) {
@@ -212,10 +233,21 @@
212233
size: 'md',
213234
backdrop: 'static',
214235
windowClass: 'bootstrap-dialog type-info',
236+
scope: $scope,
215237
controller: function ($scope, $uibModalInstance) {
216238
$scope.ok = function () {
217239
$uibModalInstance.close();
218240
};
241+
242+
$scope.metamaskInjected = Web3Service.isMetamaskInjected();
243+
244+
$scope.openMetamaskWidgetAndClose = function () {
245+
$scope.openMetamaskWidget(function () {
246+
$scope.ok();
247+
}, function () {
248+
// DO nothing, user rejected unlocking Metamask
249+
});
250+
};
219251
}
220252
});
221253
}

dapp/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@
179179
<span class="navbar-text">{{ethereumChain.chain.substr(0, 1).toUpperCase() + ethereumChain.chain.substr(1)}}</span>
180180
<span class="navbar-text" ng-bind-html="statusIcon"></span>
181181
</li>
182+
<li ng-show="metamaskInjected && !loggedIn">
183+
<a hef="#" ng-click="openMetamaskWidget()">Unlock Metamask</a>
184+
</li>
182185
</ul>
183186
</div>
184187
</nav>

dapp/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "multisigweb",
3-
"version": "1.3.7",
3+
"version": "1.4.0",
44
"eslintConfig": {
55
"env": {
66
"browser": true,
@@ -15,8 +15,6 @@
1515
"certs": "openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt -subj '/CN=localhost/O=Multisig/C=US'",
1616
"dist": "zip -x node_modules/\\* -x npm-debug.log -x tests/\\* -x config.karma.js -x .DS_Store -x .gitignore -r ../multisigWallet.zip ./",
1717
"postinstall": "grunt ngtemplates",
18-
"install-electron": "npm install && ./node_modules/.bin/electron-rebuild",
19-
"electron-rebuild": "electron-rebuild --force --module_dir . -w node-hid -e node_modules/electron && npm rebuild leveldown scrypt",
2018
"start": "http-server -a 0.0.0.0 -p 5000",
2119
"start-electron": "NODE_ENV=development electron .",
2220
"package-linux-x64": "electron-packager . MultisigWallet --prune --ignore=tests/* --ignore=testrpc.sh --platform=linux --out=./dist --overwrite=true --asar=true",
@@ -92,9 +90,9 @@
9290
"asar": "0.13.1",
9391
"babel-register": "6.26.0",
9492
"coffee-script": "1.10.0",
95-
"electron": "1.8.4",
9693
"electron-builder": "20.15.1",
9794
"electron-packager": "8.7.2",
95+
"electron": "1.8.6",
9896
"growl": "^1.10.5",
9997
"grunt": "1.0.0",
10098
"grunt-contrib-jshint": "1.1.0",

dapp/partials/modals/ledgerHelp.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
</div>
3838
<div class="modal-footer">
3939
<button type="button" ng-click="ok()" class="btn btn-default" id="terms-button" >
40-
Cancel
40+
Ok
4141
</button>
4242
</div>

dapp/partials/modals/web3Wallets.html

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<p>
1616
You can monitor existing wallets without an account management software but you cannot create new wallets or sign transactions.
1717
</p>
18+
<p ngIf="metamaskInjected">
19+
<a href="#" ng-click="openMetamaskWidgetAndClose()">Unlock Metamask</a>
20+
</p>
1821
</div>
1922
<div class="modal-footer">
2023
<button type="button" ng-click="ok()" class="btn btn-default" id="terms-button" >

dapp/services/Web3Service.js

+109-29
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
.module('multiSigWeb')
55
.service("Web3Service", function ($window, $q, Utils, $uibModal, Connection, Config, $http) {
66

7-
var factory = {};
7+
var factory = {
8+
coinbase: null,
9+
accounts: []
10+
};
811

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

19+
/**
20+
* Asks Metamask to open its widget.
21+
* Returns a callback call with the list of accounts or null in case the
22+
* user rejects the approval request.
23+
* @param callback, function (error, accounts)
24+
*/
25+
factory.enableMetamask = function (callback) {
26+
$window.ethereum.enable().then(function (accounts) {
27+
factory.reloadWeb3Provider();
28+
// Set accounts and coinbase
29+
factory.accounts = accounts;
30+
factory.coinbase = accounts[0];
31+
callback(null, accounts)
32+
}).catch(function (error) {
33+
callback(error, null)
34+
});
35+
};
36+
37+
/**
38+
* Returns true if metamask is injected, false otherwise
39+
**/
40+
factory.isMetamaskInjected = function () {
41+
return window && (typeof window.web3 !== 'undefined' &&
42+
(window.web3.currentProvider.constructor.name === 'MetamaskInpageProvider' || window.web3.currentProvider.isMetaMask)
43+
);
44+
};
45+
1646
/**
1747
* Reloads web3 provider
1848
* @param resolve, function (optional)
@@ -22,14 +52,35 @@
2252

2353
factory.accounts = [];
2454
factory.coinbase = null;
55+
var web3 = null;
56+
57+
// Legacy dapp browsers...
58+
if ($window.web3 && !$window.ethereum) {
59+
web3 = $window.web3;
60+
}
61+
// TODO: figure out whether Metamask standardize isEnabled() or find out
62+
// another way to manage it
63+
else if ($window.ethereum && window.ethereum._metamask.isEnabled()) {
64+
web3 = $window.ethereum;
65+
}
2566

2667
// Ledger wallet
2768
if (txDefault.wallet == "ledger") {
2869
if (isElectron) {
2970
factory.ledgerElectronSetup();
30-
if (resolve) {
31-
resolve();
32-
}
71+
factory.web3.eth.getAccounts(function (e, accounts) {
72+
if (e) {
73+
if (reject) {
74+
reject(e);
75+
}
76+
} else {
77+
factory.accounts = accounts;
78+
factory.coinbase = factory.accounts[0];
79+
if (resolve) {
80+
resolve();
81+
}
82+
}
83+
});
3384
}
3485
else {
3586
factory.ledgerSetup();
@@ -45,8 +96,12 @@
4596
}
4697
}
4798
// injected web3 provider (Metamask, mist, etc)
48-
else if (txDefault.wallet == "injected" && $window && $window.web3 && !isElectron) {
49-
factory.web3 = new MultisigWeb3($window.web3.currentProvider);
99+
else if (txDefault.wallet == "injected" && web3 && !isElectron) {
100+
factory.web3 = web3.currentProvider !== undefined ? new MultisigWeb3(web3.currentProvider) : new MultisigWeb3(web3);
101+
// Set accounts
102+
factory.accounts = factory.web3.eth.accounts;
103+
factory.coinbase = factory.accounts[0];
104+
50105
if (resolve) {
51106
resolve();
52107
}
@@ -57,24 +112,44 @@
57112
resolve();
58113
}
59114
}
60-
else {
115+
else if (txDefault.wallet == 'remotenode') {
61116
// Connect to Ethereum Node
117+
// factory.web3 = new MultisigWeb3(new RpcSubprovider({
118+
// rpcUrl: txDefault.ethereumNode
119+
// }));
62120
factory.web3 = new MultisigWeb3(new MultisigWeb3.providers.HttpProvider(txDefault.ethereumNode));
63121
// Check connection
64-
factory.web3.net.getListening(function(e){
122+
factory.web3.net.getListening(function(e) {
65123
if (e) {
66124
Utils.dangerAlert("You are not connected to any node.");
67125
if (reject) {
68126
reject();
69127
}
70128
}
71129
else {
72-
if (resolve) {
73-
resolve();
74-
}
130+
// Get accounts from remote node
131+
factory.web3.eth.getAccounts(function(e, accounts) {
132+
if (e) {
133+
if (reject) {
134+
reject(e);
135+
}
136+
}
137+
else {
138+
// Set accounts
139+
factory.accounts = accounts;
140+
factory.coinbase = accounts[0];
141+
142+
if (resolve) {
143+
resolve();
144+
}
145+
}
146+
});
75147
}
76148
});
77149
}
150+
else if (resolve) {
151+
resolve();
152+
}
78153
};
79154

80155
/**
@@ -169,28 +244,33 @@
169244
* Get ethereum accounts and update account list.
170245
*/
171246
factory.updateAccounts = function (cb) {
172-
return factory.web3.eth.getAccounts(
173-
function (e, accounts) {
174-
if (e) {
175-
cb(e);
176-
}
177-
else {
178-
factory.accounts = accounts;
179-
180-
if (factory.coinbase && accounts && accounts.length && accounts.indexOf(factory.coinbase) != -1) {
181-
// same coinbase
182-
}
183-
else if (accounts) {
184-
factory.coinbase = accounts[0];
247+
if (!isElectron && factory.coinbase) {
248+
return factory.web3.eth.getAccounts(
249+
function (e, accounts) {
250+
if (e) {
251+
cb(e);
185252
}
186253
else {
187-
factory.coinbase = null;
188-
}
254+
factory.accounts = accounts;
189255

190-
cb(null, accounts);
256+
if (factory.coinbase && accounts && accounts.length && accounts.indexOf(factory.coinbase) != -1) {
257+
// same coinbase
258+
}
259+
else if (accounts) {
260+
factory.coinbase = accounts[0];
261+
}
262+
else {
263+
factory.coinbase = null;
264+
}
265+
266+
cb(null, accounts);
267+
}
191268
}
192-
}
193-
);
269+
);
270+
}
271+
else {
272+
cb(null, null);
273+
}
194274
};
195275

196276
/* Ledger setup on browser*/

dapp/testrpc.sh

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ sleep 5;
66
karma start config.karma.js
77
echo "Shutting down TestRpc..."
88
kill -9 $testrpc_pid
9-
./node_modules/.bin/electron-rebuild;

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "multisig-wallet-gnosis",
3-
"version": "1.3.7",
3+
"version": "1.4.0",
44
"description": "Main module, for installing all dependencies",
55
"scripts": {
66
"test-dapp": "cd dapp && npm test",
@@ -27,6 +27,7 @@
2727
"dependencies": {
2828
"child_process": "1.0.2",
2929
"ethereumjs-testrpc": "4.1.3",
30+
"ganache-cli": "^6.1.8",
3031
"truffle": "3.4.11"
3132
},
3233
"devDependencies": {

0 commit comments

Comments
 (0)