Skip to content

Commit 14c2e98

Browse files
committed
update
1 parent bf69f37 commit 14c2e98

File tree

3 files changed

+265
-23
lines changed

3 files changed

+265
-23
lines changed

client/js/controllers/bank.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
"use strict";
2-
app.controller("BankController", ["$scope", "$rootScope", "Blockchaininfo", "LocalStorage", "Encryption", "modals","Session", "Security", "Wallet", "WalletManager",
3-
function($scope,$rootScope, Blockchaininfo,LocalStorage, Encryption, modals, Session, Security, Wallet, WalletManager) {
2+
app.controller("BankController", ["$scope", "$rootScope", '$network', '$vaultClient',
3+
function($scope,$rootScope, $network, $vaultClient) {
44

5+
$scoperevenue;
6+
$scope.totalProfit;
7+
$scope.networth;
8+
$scope.invested;
9+
$scope.gateways;
10+
$rootScope.network = $network;
11+
12+
13+
$scope.update = function () {
14+
15+
}
516

617

718

client/js/controllers/login.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
var w = angular.element($window);
99

1010
$scope.submit = function() {
11-
12-
login(this.username, this.password)
13-
11+
login(this.username, this.password);
1412
}
1513

1614

@@ -20,27 +18,17 @@
2018
$vaultClient.vaultClient.login(username, password, "lightchain.co",userBlob);
2119

2220
function userBlob(err, data) {
23-
24-
console.log(data)
25-
$scope.userBlob = data.blob
26-
$scope.username = data.username
27-
28-
//$scope.secret = data.secret
29-
30-
console.log($scope.userBlob)
31-
32-
33-
34-
$location.path('/wallet')
35-
$scope.header_hidden = true
36-
$scope.navbar_visible = true
21+
$scope.userBlob = data.blob;
22+
$scope.username = data.username;
23+
console.log($scope.userBlob);
24+
$location.path('/wallet');
3725

38-
$scope.$apply();
26+
$scope.header_hidden = true;
27+
$scope.navbar_visible = true;
28+
$scope.$apply();
3929

40-
$scope.$on('$routeChangeSuccess', function () { $scope.stopSpin() })
30+
$scope.$on('$routeChangeSuccess', function () { console.log("success") });
4131
};//end blob_function()
42-
43-
4432
}//end login()
4533

4634

client/js/controllers/wallet.js

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
"use strict";
2+
3+
app.controller('WalletCtrl', ['$scope', '$location', 'MongoDB','$modal', '$connection_status','WebSocket', "Wallet", "WalletManager",
4+
function ($scope, $location, MongoDB, $modal, $connection_status, WebSocket ,Wallet, WalletManager)
5+
{
6+
7+
$scope.curWallet = WalletManager.getCurrentWallet();
8+
$scope.wallets = WalletManager.getWallets();
9+
$rootScope.curWallet = $scope.curWallet;
10+
11+
var backupFile;
12+
$scope.currentAddress = "1Yj564jDqoB6L7hg5ETYKhqRsB65WrWPB";
13+
$scope.isActive = true;
14+
var fileClicked = false;
15+
setTimeout(function() {
16+
var el = document.getElementById("first");
17+
angular.element(el).triggerHandler("click");
18+
},0);
19+
20+
$connection_status.check();
21+
22+
/**
23+
* Add a currency
24+
*/
25+
$scope.create = function (ROR)
26+
{
27+
var lightchain = {
28+
currency: "Credit",
29+
incomeRate: ROR
30+
};
31+
// Add an element
32+
$scope.userBlob.unshift("/lightchain", lightchain);
33+
34+
MongoDB.collection($scope.userBlob.data.account_id);
35+
36+
var wallet = {type: "contract", currency: lightchain.currency, taxRate: lightchain.incomeRate}
37+
38+
new MongoDB(wallet).$save().then(function (data) {console.log(data);});
39+
$connection_status.connect();
40+
};
41+
42+
43+
/**
44+
* Remove currency
45+
*
46+
* @param index
47+
*/
48+
49+
50+
$scope.remove = function (currency) {
51+
52+
// Update blob
53+
$scope.userBlob.unset('/lightchain_blob');
54+
55+
56+
// remove from MongoDB
57+
MongoDB.collection($scope.userBlob.data.account_id);
58+
59+
MongoDB.query({type: "contract"}).then(function(data){
60+
61+
var temp = data;
62+
var id;
63+
id = temp[0]._id;
64+
65+
MongoDB.remove_one(id);
66+
67+
})
68+
69+
$connection_status.disconnect();
70+
}
71+
72+
73+
MongoDB.collection($scope.userBlob.data.account_id)
74+
75+
MongoDB.query({ type: "safety_net" }).then(function(data){
76+
var temp = data;
77+
$scope.safety_net = data[0].total_pathway;
78+
79+
});
80+
81+
MongoDB.query({ type: "lightchain_blob" }).then(function(data){
82+
83+
$scope.total_amount = data[0].total_amount;
84+
85+
});
86+
87+
/***
88+
updateBalance will work properly but only 30 seconds later since it is a callback.
89+
***/
90+
var updateBalance = function() {
91+
$scope.curWallet.updateBalance();
92+
//setTimeout(function() {
93+
$scope.Balance = $rootScope.Balance = $scope.curWallet.getBalance();
94+
console.log("Balance " + $scope.Balance);
95+
//}, 1000);
96+
};
97+
updateBalance();
98+
setInterval(updateBalance, 30000);
99+
100+
101+
/***
102+
Helper function for download
103+
should be created into module
104+
***/
105+
function download(filename, data) {
106+
try {
107+
var a = document.createElement("a");
108+
a.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(data));
109+
a.setAttribute("download", filename);
110+
a.click();
111+
} catch(e) {
112+
console.log("download failed " + e);
113+
}
114+
115+
};
116+
117+
/***
118+
Controller to back up current wallet
119+
View location is view\partials\main.html
120+
File download name is the wallet's name
121+
JSON is used to format wallet data
122+
***/
123+
$scope.backup = function() {
124+
var _success = function(password) {
125+
try {
126+
var _password = password || Security.get("password");
127+
var data = Encryption.encrypt(JSON.stringify($scope.curWallet.getAllAddresses()), _password);
128+
var fileName = $scope.curWallet.getName();
129+
download(fileName+".json", data);
130+
} catch(e) {
131+
console.log("backup failed " + e);
132+
}
133+
};
134+
/* var checkPassword = {
135+
check : Security.get("password"),
136+
success : _success,
137+
fail : function() {
138+
modals.open("modalpassword", {
139+
"message":"Please input password",
140+
"databaseName":"password",
141+
"objectName":"password"
142+
}, _success);
143+
}
144+
};*/
145+
//Security.check(checkPassword,"password","password");
146+
};
147+
148+
/***
149+
Controller to import a wallet that was previously backed up
150+
View location is view\partials\main.html
151+
Only imports when file is properly opened
152+
***/
153+
$scope.import = function() {
154+
var _success = function() {
155+
var el = document.getElementById("fileUpload");
156+
angular.element(el).trigger("click");
157+
var f = document.getElementById("file").files[0];
158+
if(!f) {
159+
return;
160+
}
161+
var r = new FileReader();
162+
r.onload = function(e){
163+
backupFile = e.target.result;
164+
console.log(backupFile)
165+
$scope.fileLoaded = true;
166+
}
167+
r.readAsText(f);
168+
};
169+
var checkPassword = {
170+
success : _success,
171+
fail : function() {
172+
modals.open("modalpassword", {
173+
"message":"Please input password",
174+
"databaseName":"password",
175+
"objectName":"password"
176+
}, _success);
177+
}
178+
};
179+
//Security.check(checkPassword,"password","password");
180+
};
181+
182+
/***
183+
Controller to generate new address
184+
View location is view\partials\main.html
185+
Address generated will show QR code on html
186+
Address will be stored in current wallet and walletmanager
187+
will update.
188+
***/
189+
$scope.generateAddress = function() {
190+
var _success = function(passphrase) {
191+
var _passphrase = passphrase ;//|| Security.get("password");
192+
$scope.currentAddress = $scope.curWallet.generatePublicAddress(_passphrase);
193+
WalletManager.updateCurrent();
194+
};
195+
/* var checkPassword = {
196+
check : Security.get("password"),
197+
success : _success,
198+
fail : function() {
199+
modals.open("modalpassword", {
200+
"message":"Please input password",
201+
"databaseName":"password",
202+
"objectName":"password"
203+
}, _success);
204+
}
205+
};
206+
Security.check(checkPassword,"password","password");*/
207+
};
208+
209+
/***
210+
Controller to add a new wallet name after what user typed
211+
View location is view\partials\sidemenu.html
212+
WalletManager adds the newly created wallet
213+
scope.wallets updates list
214+
WalletManager is called to return current wallet in case user had no wallets to auto-select currently created wallet
215+
***/
216+
$scope.generateWallet = function(WalletName) {
217+
if(!WalletName || WalletName.length == 0) {
218+
throw new Error("Improper Wallet Name");
219+
} else {
220+
WalletManager.addWallet(new Wallet(WalletName));
221+
$scope.wallets = WalletManager.getWallets();
222+
$rootScope.curWallet = $scope.curWallet = WalletManager.getCurrentWallet();
223+
}
224+
};
225+
226+
/***
227+
Controller to select current wallet in sidemenu
228+
View location is view\partials\sidemenu.html
229+
WalletManager,scope.curWallet, and rootScope.curWallet
230+
are all set to the selected wallet
231+
***/
232+
$scope.select = function(walletRef) {
233+
if(!walletRef) {
234+
throw new Error("Undefined Wallet");
235+
}
236+
WalletManager.setWalletR(walletRef);
237+
$rootScope.curWallet = $scope.curWallet = walletRef;
238+
};
239+
240+
241+
}]);
242+
243+

0 commit comments

Comments
 (0)