From 6bad3e566aed707f8f4e00991d596652579c1e59 Mon Sep 17 00:00:00 2001 From: Scott Date: Sun, 29 Jan 2017 20:55:11 +1100 Subject: [PATCH] Adds "sell" component Uses rootscope to announce when a currency + exchange is selected to allow all components to adapt to new data. --- web/app/app.js | 1 + web/app/components/buy/buy.html | 10 +++--- web/app/components/buy/buy.js | 24 +++++++++----- web/app/components/filters/stringUtils.js | 9 ----- web/app/components/helpers/stringUtils.js | 25 ++++++++++++++ web/app/components/sell/sell.html | 25 ++++++++++++++ web/app/components/sell/sell.js | 40 +++++++++++++++++++++++ web/app/index.html | 3 +- web/app/views/home/home.html | 3 +- web/app/views/home/home.js | 10 ++++-- 10 files changed, 123 insertions(+), 27 deletions(-) delete mode 100644 web/app/components/filters/stringUtils.js create mode 100644 web/app/components/helpers/stringUtils.js create mode 100644 web/app/components/sell/sell.html create mode 100644 web/app/components/sell/sell.js diff --git a/web/app/app.js b/web/app/app.js index d23e2fd6..f108a0b3 100644 --- a/web/app/app.js +++ b/web/app/app.js @@ -9,6 +9,7 @@ angular.module('myApp', [ 'myApp.settings', 'myApp.version', 'myApp.buy', + 'myApp.sell', 'myApp.stringUtils' ]). config(['$locationProvider', '$routeProvider' ,'NotificationProvider', function($locationProvider, $routeProvider, NotificationProvider) { diff --git a/web/app/components/buy/buy.html b/web/app/components/buy/buy.html index 6d787233..88796d5f 100644 --- a/web/app/components/buy/buy.html +++ b/web/app/components/buy/buy.html @@ -1,13 +1,13 @@
-
- {{$ctrl.currency.CryptoCurrency}} + {{currency.CryptoCurrency}}
- +
@@ -15,8 +15,8 @@
-
- +
+
diff --git a/web/app/components/buy/buy.js b/web/app/components/buy/buy.js index 7af228b1..e522e462 100644 --- a/web/app/components/buy/buy.js +++ b/web/app/components/buy/buy.js @@ -2,15 +2,24 @@ angular.module('myApp.buy',[]).component('buy', { templateUrl: '/components/buy/buy.html', controller:'BuyController', - bindings: { - exchange: '=', - currency:'=' - }, controller: function ($scope, $http, Notification) { - - $scope.GetLatestDataFromExchangeCurrency = function () { + controller: function ($scope, $http, Notification, $rootScope) { + $scope.currency = {}; + $scope.exchange = {}; + + $rootScope.$on('CurrencyChanged', function (event, args) { + $scope.currency = args.Currency; + $scope.exchange = args.Exchange; + console.log($scope.currency); + $scope.GetLatestDataFromExchangeCurrency(); + $scope.price = $scope.currency.Ask; + }); + + $scope.GetLatestDataFromExchangeCurrency = function () { $http.get('/GetLatestDataFromExchangeCurrency?exhange=' + $scope.exchange.exchangeName + '¤cy='+ $scope.currency.CryptoCurrency).success(function (data) { $scope.currency.Last = data.Last; $scope.currency.Volume = data.Volume; + $scope.currency.Ask = data.Ask; + $scope.price = $scope.currency.Ask; }); } @@ -20,8 +29,7 @@ angular.module('myApp.buy',[]).component('buy', { obj.Currency = $scope.currency; obj.Price = $scope.price; obj.Amount = $scope.amount; - obj.Amount = $scope.amount; - $http.post('/Command/', obj).success(function (response) { + $http.post('/Command/PlaceBuyOrder', obj).success(function (response) { Notification.success("Successfully placed order"); }); }; diff --git a/web/app/components/filters/stringUtils.js b/web/app/components/filters/stringUtils.js deleted file mode 100644 index ea4ead34..00000000 --- a/web/app/components/filters/stringUtils.js +++ /dev/null @@ -1,9 +0,0 @@ -angular.module('myApp.stringUtils', []) - .filter('removeSpaces', [function () { - return function (string) { - if (!angular.isString(string)) { - return string; - } - return string.replace(/[\s]/g, ''); - }; - }]); \ No newline at end of file diff --git a/web/app/components/helpers/stringUtils.js b/web/app/components/helpers/stringUtils.js new file mode 100644 index 00000000..8f10d6b0 --- /dev/null +++ b/web/app/components/helpers/stringUtils.js @@ -0,0 +1,25 @@ +angular.module('myApp.stringUtils', []) + .filter('removeSpaces', [function () { + return function (string) { + if (!angular.isString(string)) { + return string; + } + return string.replace(/[\s]/g, ''); + }; + }]); +/* + angular.module('myApp.currenctExchangeFactory', []).factory('currentExchangeCurrency', function() { + var currentExchangeAndCurrency = {}; + var exchangeService = {}; + + exchangeService.get = function() { + return currentExchangeAndCurrency; + }; + exchangeService.update = function(exchange, currency) { + currentExchangeAndCurrency.Exchange = exchange; + currentExchangeAndCurrency.Currency = currency; + }; + + return exchangeService; +}); +*/ diff --git a/web/app/components/sell/sell.html b/web/app/components/sell/sell.html new file mode 100644 index 00000000..5df31c2e --- /dev/null +++ b/web/app/components/sell/sell.html @@ -0,0 +1,25 @@ +
+
+
+
+
+ {{currency.CryptoCurrency}} +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/web/app/components/sell/sell.js b/web/app/components/sell/sell.js new file mode 100644 index 00000000..d8c2095d --- /dev/null +++ b/web/app/components/sell/sell.js @@ -0,0 +1,40 @@ + +angular.module('myApp.sell',[]).component('sell', { + templateUrl: '/components/sell/sell.html', + controller:'SellController', + controller: function ($scope, $http, Notification, $rootScope) { + $scope.currency = {}; + $scope.exchange = {}; + + $rootScope.$on('CurrencyChanged', function (event, args) { + $scope.currency = args.Currency; + $scope.exchange = args.Exchange; + console.log($scope.currency); + $scope.GetLatestDataFromExchangeCurrency(); + $scope.price = $scope.currency.Bid; + }); + + $scope.GetLatestDataFromExchangeCurrency = function () { + $http.get('/GetLatestDataFromExchangeCurrency?exhange=' + $scope.exchange.exchangeName + '¤cy='+ $scope.currency.CryptoCurrency).success(function (data) { + $scope.currency.Last = data.Last; + $scope.currency.Volume = data.Volume; + $scope.currency.Bid = data.Bid; + $scope.price = $scope.currency.Bid; + }); + } + + $scope.placeOrder = function () { + var obj = {}; + obj.ExchangeName = $scope.exchange.exchangeName; + obj.Currency = $scope.currency; + obj.Price = $scope.price; + obj.Amount = $scope.amount; + $http.post('/Command/PlaceSellOrder', obj).success(function (response) { + Notification.success("Successfully placed order"); + }); + }; + } +}); + + + diff --git a/web/app/index.html b/web/app/index.html index 8b1f80ff..7f60ea37 100644 --- a/web/app/index.html +++ b/web/app/index.html @@ -61,9 +61,10 @@ + - + diff --git a/web/app/views/home/home.html b/web/app/views/home/home.html index f36eb379..4e70ea33 100644 --- a/web/app/views/home/home.html +++ b/web/app/views/home/home.html @@ -16,10 +16,11 @@

Buy

- +

Sell

+

Wallet quick look

diff --git a/web/app/views/home/home.js b/web/app/views/home/home.js index d8d6c260..b6fad045 100644 --- a/web/app/views/home/home.js +++ b/web/app/views/home/home.js @@ -9,7 +9,8 @@ angular.module('myApp.home', ['ngRoute']) }); }]) -.controller('HomeController', function ($scope, $http, Notification) { + .controller('HomeController', function ($scope, $http, Notification, $rootScope) { + $scope.selected = {}; $scope.getDashboardData = function() { $http({ method: 'GET', @@ -17,6 +18,7 @@ angular.module('myApp.home', ['ngRoute']) }). success(function (data, status, headers, config) { $scope.exchanges = data.data; + $scope.reloadDashboardWithExchangeCurrency($scope.exchanges[0], $scope.exchanges[0].exchangeValues[0]); Notification.info("Retrieved latest data"); }). error(function (data, status, headers, config) { @@ -25,8 +27,10 @@ angular.module('myApp.home', ['ngRoute']) }; $scope.reloadDashboardWithExchangeCurrency = function (exchange, value) { - $scope.selectedExchange = exchange; - $scope.selectedCurrency = value; + $scope.selected.Exchange = exchange; + $scope.selected.Currency = value; + $rootScope.$emit('CurrencyChanged', $scope.selected); + }; $scope.getDashboardData();