Skip to content

Commit

Permalink
fix(wallet): transfer transactions are correctly shown
Browse files Browse the repository at this point in the history
Fixed a bug with display of asset transfer transactions.
Added unit tests for the assets cache implementation.
  • Loading branch information
beregovoy68 committed Nov 18, 2016
1 parent c28d348 commit 9d6c6ce
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/js/application.context.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
if (angular.isDefined(asset)) {
var reissued = Money.fromCoins(reissuedAmount, asset.currency);
asset.totalTokens = asset.totalTokens.plus(reissued);
console.log(asset.totalTokens.formatAmount());
}
}

Expand Down
143 changes: 143 additions & 0 deletions src/js/application.context.factory.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
describe('Application.Context', function() {
var context;
var assetId = 'GAXAj8T4pSjunDqpz6Q3bit4fJJN9PD4t8AK8JZVSa5u';

// Initialization of the module before each test case
beforeEach(module('waves.core'));
beforeEach(module('app.ui'));

// Injection of dependencies
beforeEach(inject(function($injector) {
context = $injector.get('applicationContext');
}));

it('should cache assets and update issued tokens count', function () {
var unknownAssetId = '------T4pSjunDqpz6Q3bit4fJJN9PD4t8AK8JZVSa5u';
var tx = [
{
'type': 2,
'fee': 106151,
'timestamp': 1474706165244,
'signature': '5RbVW57WEnuSXyz2Ba5sFkjXkWWBnc81fGZq1Zpwoetk1JkWkufMTaMnukgGsahxmiwNCtsLuuPYDB5mzkBBt8Bk',
'sender': '3Mv61qe6egMSjRDZiiuvJDnf3Q1qW9tTZDB',
'recipient': '3MtCKcpwnQvK2fiVWsKJAhVEpXuFFopDqeE',
'amount': 723987
},
{
'type': 3,
'id': assetId,
'sender': '3MtMoVbAHSitzohEvd6dJGR3kmJZHSePUkS',
'assetId': assetId,
'name': '4wHKwCUAGbpPVg3gk',
'description': 'ziu6bcfZ1gm5fRDb9R79HUnHMoE',
'quantity': 100000000,
'decimals': 2,
'reissuable': true,
'fee': 100000000,
'timestamp': 1479119236120,
'signature': '2Tc7kQDPE2LnhtkuN4CPgFaMPcdP6wUAJPaWDnZ16HcCurezt8oJPyGwo7wDGF7r7TSeEgsQXDCqDC5Qqb9z6JUu'
},
{
'type': 2,
'fee': 59291,
'timestamp': 1474706165774,
'signature': '5fjGRrNS9wg1RzcWuQUddPNfhm72CGAHWFo6bHpD5bGf3iyjNiXWLwVxdjeiw2Hnmrki61FYM5VAgpyTHmMaxc2y',
'sender': '3Mv61qe6egMSjRDZiiuvJDnf3Q1qW9tTZDB',
'recipient': '3MuTjWD6muPQ3nbSAPtYMkyKwJwSAzC8C2J',
'amount': 237099
},
{
'type': 5,
'id': '7bTtoTrGQhfjKvQQ35cNVrFURCBfQXqEyEeZYYVkJKNx',
'sender': '3MtMoVbAHSitzohEvd6dJGR3kmJZHSePUkS',
'assetId': assetId,
'quantity': 10000,
'reissuable': false,
'fee': 100000000,
'timestamp': 1479308287927,
'signature': '5vBwHfKRWXinQLgZUM6fsyJc6ikTjEyt4iDNNxDEhKx22RMp77eXVDsWCur3tbyzzKpvxu5uoseu5w9CUyaUUFxL'
},
{
'type': 5,
'id': '7bTtoTrGQhfjKvQQ35cNVrFURCBfQXqEyEeZYYVkJKNx',
'sender': '3MtMoVbAHSitzohEvd6dJGR3kmJZHSePUkS',
'assetId': assetId,
'quantity': 5000,
'reissuable': false,
'fee': 100000000,
'timestamp': 1479308287927,
'signature': '5vBwHfKRWXinQLgZUM6fsyJc6ikTjEyt4iDNNxDEhKx22RMp77eXVDsWCur3tbyzzKpvxu5uoseu5w9CUyaUUFxL'
},
{
'type': 5,
'id': '7bTtoTrGQhfjKvQQ35cNVrFURCBfQXqEyEeZYYVkJKNx',
'sender': '3MtMoVbAHSitzohEvd6dJGR3kmJZHSePUkS',
'assetId': unknownAssetId,
'quantity': 5000,
'reissuable': false,
'fee': 100000000,
'timestamp': 1479308287927,
'signature': '5vBwHfKRWXinQLgZUM6fsyJc6ikTjEyt4iDNNxDEhKx22RMp77eXVDsWCur3tbyzzKpvxu5uoseu5w9CUyaUUFxL'
}
];

context.cache.assets.grab(tx);

expect(context.cache.assets[unknownAssetId]).toBeUndefined();
expect(context.cache.assets[assetId].currency.precision).toEqual(2);
expect(context.cache.assets[assetId].currency.id).toEqual(assetId);
expect(context.cache.assets[assetId].totalTokens.toTokens()).toEqual(1000000 + 100 + 50);
});

it('should put an issue transaction to cache', function () {
var tx = {
'type': 3,
'id': assetId,
'sender': '3MtMoVbAHSitzohEvd6dJGR3kmJZHSePUkS',
'assetId': assetId,
'name': 'Asset',
'description': 'Description',
'quantity': 100000000,
'decimals': 4,
'reissuable': true,
'fee': 100000000,
'timestamp': 1479119236120
};

expect(context.cache.assets[assetId]).toBeUndefined();

context.cache.assets.put(tx);

expect(context.cache.assets[assetId].balance.toTokens()).toEqual(0);
expect(context.cache.assets[assetId].currency.id).toEqual(assetId);
expect(context.cache.assets[assetId].currency.precision).toEqual(4);
expect(context.cache.assets[assetId].reissuable).toBe(true);
});

it('should update the issue transaction in cache', function () {
var currency = new Currency({
id: assetId,
precision: 4
});
var tx = {
'type': 3,
'id': assetId,
'sender': '3MtMoVbAHSitzohEvd6dJGR3kmJZHSePUkS',
'assetId': assetId,
'name': 'Asset',
'description': 'Description',
'quantity': 100000000,
'decimals': 4,
'reissuable': true,
'fee': 100000000,
'timestamp': 1479119236120
};

context.cache.assets[assetId] = {balance: Money.fromTokens(10, currency)};
context.cache.assets.put(tx);

expect(context.cache.assets[assetId].balance.toTokens()).toEqual(10);
expect(context.cache.assets[assetId].currency.id).toEqual(assetId);
expect(context.cache.assets[assetId].currency.displayName).toEqual('Asset');
});
});
5 changes: 4 additions & 1 deletion src/js/portfolio/asset.list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
}

function tryToLoadAssetDataFromCache(asset) {
if (angular.isUndefined(applicationContext.cache.assets[asset.id]))
if (angular.isUndefined(applicationContext.cache.assets[asset.id])) {
asset.balance = 'Loading';

return false;
}

var cached = applicationContext.cache.assets[asset.id];
cached.balance = Money.fromCoins(asset.balance, cached.currency);
Expand Down
4 changes: 2 additions & 2 deletions src/js/portfolio/asset.transfer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
},
assetAmount: {
required: true,
decimal: 0,
min: 1
decimal: 0, // stub value updated on validation
min: 1 // stub value updated on validation
},
assetFee: {
required: true,
Expand Down
4 changes: 4 additions & 0 deletions src/js/shared/transaction.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
}

function processAssetTransferTransaction(transaction) {
var asset = applicationContext.cache.assets[transaction.assetId];
if (angular.isUndefined(asset))
return;

transaction.formatted.amount = Money.fromCoins(transaction.amount, asset.currency).formatAmount();
}

function processAssetReissueTransaction(transaction) {
Expand Down
10 changes: 5 additions & 5 deletions src/js/wallet/wallet.controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(function () {
'use strict';

function WalletController($scope, $timeout, $interval, constants, autocomplete, applicationContext, dialogService,
addressService, utilityService, apiService, notificationService, formattingService,
transferService, transactionLoadingService) {
function WavesWalletController($scope, $timeout, $interval, constants, autocomplete, applicationContext,
dialogService, addressService, utilityService, apiService, notificationService,
formattingService, transferService, transactionLoadingService) {
var wallet = this;
var transaction, refreshPromise;
var refreshDelay = 10 * 1000;
Expand Down Expand Up @@ -258,12 +258,12 @@
}
}

WalletController.$inject = ['$scope', '$timeout', '$interval', 'constants.ui',
WavesWalletController.$inject = ['$scope', '$timeout', '$interval', 'constants.ui',
'autocomplete.fees', 'applicationContext',
'dialogService', 'addressService', 'utilityService', 'apiService', 'notificationService',
'formattingService', 'transferService', 'transactionLoadingService'];

angular
.module('app.wallet')
.controller('walletController', WalletController);
.controller('walletController', WavesWalletController);
})();

0 comments on commit 9d6c6ce

Please sign in to comment.