Permalink
Browse files

feat(portfolio): asset listing on portfolio tab

  • Loading branch information...
1 parent bc1ddb8 commit a4fda811a97a763051be9ca72d43d2b762e8399d @beregovoy68 beregovoy68 committed Nov 11, 2016
View
@@ -152,6 +152,9 @@ module.exports = function (grunt) {
'src/js/community/community.module.js',
'src/js/community/community.controller.js',
+ 'src/js/portfolio/portfolio.module.js',
+ 'src/js/portfolio/asset.list.controller.js',
+
'src/js/**/*.spec.js'
]
}
View
@@ -438,7 +438,7 @@ <h2 id="AccHeader">{{accounts.caption}}</h2>
<!-- PORTFOLIO TAB -->
<div id="mBB-portfolio" class="mBB-content" ng-switch-when="portfolio">
- <div class="phContent">
+ <div class="phContent" ng-controller="assetListController as assetList">
<h1>PORTFOLIO</h1>
<table>
<thead>
@@ -450,13 +450,11 @@ <h2 id="AccHeader">{{accounts.caption}}</h2>
<td>OPTIONS</td>
</tr>
</thead>
- <tbody ng-if="false">
- <tr>
+ <tbody ng-switch on="assetList.assets.length">
+ <tr ng-switch-when="0">
<td colspan="5">You do not own or issued any assets</td>
</tr>
- </tbody>
- <tbody ng-if="true">
- <tr>
+ <tr ng-switch-default>
<td></td>
<td></td>
<td></td>
@@ -763,6 +761,9 @@ <h2 id="AccHeader">{{accounts.caption}}</h2>
<script src="js/community/community.module.js"></script>
<script src="js/community/community.controller.js"></script>
+ <script src="js/portfolio/portfolio.module.js"></script>
+ <script src="js/portfolio/asset.list.controller.js"></script>
+
<script src="js/style.js"></script>
</body>
</html>
View
@@ -25,7 +25,8 @@ var app = angular.module('app', [
'app.wallet',
'app.tokens',
'app.history',
- 'app.community'
+ 'app.community',
+ 'app.portfolio'
]).config(AngularApplicationConfig).run(AngularApplicationRun);
function AngularApplicationConfig($validatorProvider) {
@@ -78,10 +79,10 @@ function AngularApplicationRun(rest, coreConstants, notificationService, address
rest.setDefaultHttpFields({
timeout: 10000 // milliseconds
});
- //var url = coreConstants.NODE_ADDRESS;
+ var url = coreConstants.NODE_ADDRESS;
//var url = 'http://52.28.66.217:6869';
//var url = 'http://52.77.111.219:6869';
- var url = 'http://127.0.0.1:6869';
+ //var url = 'http://127.0.0.1:6869';
rest.setBaseUrl(url);
// override mock methods cos in config phase services are not available yet
@@ -2,8 +2,37 @@
'use strict';
function ApplicationContextFactory() {
+
+ var assets = {};
+
+ assets.put = function (issueTransaction) {
+ var currency = new Currency({
+ id: transaction.assetId,
+ displayName: transaction.name,
+ precision: transaction.decimals
+ });
+ var balance = new Money(0, currency);
+ var asset = {
+ currency: currency,
+ description: transaction.description,
+ reissuable: transaction.reissuable,
+ timestamp: transaction.timestamp,
+ totalTokens: Money.fromCoins(transaction.quantity, currency),
+ };
+
+ if (angular.isDefined(assets[currency.id]))
+ balance = assets[currency.id].balance;
+
+ asset.balance = balance;
+
+ assets[currency.id] = asset;
+ };
+
return {
- account: {}
+ account: {},
+ cache: {
+ assets: assets
+ }
};
}
@@ -1,8 +1,87 @@
(function () {
'use strict';
+ function WavesAssetListController($scope, $interval, applicationContext, apiService, formattingService) {
+ var assetList = this;
+ var refreshPromise;
+ var refreshDelay = 15 * 1000;
+
+ assetList.assets = [];
+ assetList.transferValidationOptions = {};
+
+ loadDataFromBackend();
+
+ $scope.$on('$destroy', function () {
+ if (angular.isDefined(refreshPromise)) {
+ $interval.cancel(refreshPromise);
+ refreshPromise = undefined;
+ }
+ });
+
+ function loadDataFromBackend() {
+ refreshAssets();
+
+ refreshPromise = $interval(function() {
+ refreshAssets();
+ }, refreshDelay);
+ }
+
+ function tryToLoadAssetDataFromCache(asset) {
+ if (angular.isUndefined(applicationContext.cache.assets[asset.id]))
+ return false;
+
+ var cached = applicationContext.cache.assets[id];
+ cached.balance = new Money(assetBalance.balance, cached.currency);
+
+ asset.name = cached.currency.displayName;
+ asset.total = cached.totalTokens.formatAmount();
+ asset.balance = cached.balance.formatAmount();
+ asset.timestamp = formattingService.formatTimestamp(cached.timestamp);
+
+ return true;
+ }
+
+ function refreshAssets() {
+ apiService.assets.balance(applicationContext.account.address).then(function (response) {
+ var balances = response.balances;
+ var assets = [];
+ var cacheMiss = [];
+ _.forEach(balances, function (assetBalance) {
+ var id = assetBalance.assetId;
+ var asset = {
+ id: id,
+ total: '',
+ name: '',
+ balance: '',
+ issued: assetBalance.issued
+ };
+
+ if (!tryToLoadAssetDataFromCache(asset))
+ cacheMiss.push(id);
+
+ assets.push(asset);
+ });
+
+ _.forEach(cacheMiss, function getAssetTransactionInfo(assetId) {
+ apiService.transactions.info(assetId).then(function (response) {
+ var id = response.id;
+ applicationContext.cache.assets.put(response);
+ var index = _.findIndex(assetList.assets, function (asset) {
+ return asset.id === id;
+ });
+ tryToLoadAssetDataFromCache(assetList.assets[index]);
+ });
+ });
+
+ assetList.assets = assets;
+ });
+ }
+ }
+
+ WavesAssetListController.$inject = ['$scope', '$interval',
+ 'applicationContext', 'apiService', 'formattingService'];
+
angular
.module('app.portfolio')
- .controller('assetListController', ['$scope', function ($scope) {
- }]);
+ .controller('assetListController', WavesAssetListController);
})();
@@ -102,11 +102,14 @@
// disable confirm button
ctrl.confirm.pendingIssuance = true;
- apiService.assets.issue(transaction).then(function () {
+ apiService.assets.issue(transaction).then(function (response) {
var displayMessage = 'Asset ' + ctrl.confirm.name + ' has been issued!<br/>' +
'Total tokens amount: ' + ctrl.confirm.totalTokens + '<br/>' +
'Date: ' + formattingService.formatTimestamp(transaction.timestamp);
notificationService.notice(displayMessage);
+
+ applicationContext.cache.assets.put(response);
+
transaction = undefined;
resetIssueAssetForm();
}, function (response) {
@@ -125,7 +128,7 @@
ctrl.asset.name = '';
ctrl.asset.description = '';
ctrl.asset.totalTokens = '0';
- ctrl.asset.tokenDecimalPlaces = '0';
+ ctrl.asset.decimalPlaces = '0';
ctrl.asset.reissuable = false;
}
}

0 comments on commit a4fda81

Please sign in to comment.