Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #83 from LiskHQ/62_send-all
Browse files Browse the repository at this point in the history
Adding "send all funds" feature - Closes #62
  • Loading branch information
karmacoma authored Apr 4, 2017
2 parents 324af62 + af5d7c4 commit 5e51059
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
cd src
grunt eslint
grunt test

exit $?
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Make sure there are some transactions on the master account so we can test they
```
for i in {1..20}
do
curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"wagon stock borrow episode laundry kitten salute link globe zero feed marble","amount":'"$i"',"recipientId":"537318935439898807L"}' http://localhost:4000/api/transactions; echo ''
curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"wagon stock borrow episode laundry kitten salute link globe zero feed marble","amount":'"$i"'0000000,"recipientId":"537318935439898807L"}' http://localhost:4000/api/transactions; echo ''
done
```

Expand Down
8 changes: 5 additions & 3 deletions src/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ module.exports = function (grunt) {
format: 'codeframe',
fix: false,
},
target: ['app/**/*.js', 'spec/**/*.js', 'test/**/*.js', '*.js'],
all: {
src: ['app/**/*.js', 'spec/**/*.js', 'test/**/*.js', '*.js'],
},
},
});

grunt.registerTask('test', ['eslint']);
grunt.registerTask('test', ['newer:eslint']);
grunt.registerTask('travis', ['test']);
grunt.registerTask('default', ['test']);

grunt.registerTask('eslint-fix', 'Run eslint and fix formatting', () => {
grunt.config.set('eslint.options.fix', true);
grunt.task.run('eslint');
grunt.task.run('newer:eslint');
});
};
4 changes: 4 additions & 0 deletions src/app/components/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ app.component('send', {
this.loading = false;
});
}

setMaxAmount() {
this.amount.value = this.amount.max;
}
},
});

Expand Down
15 changes: 15 additions & 0 deletions src/app/components/send/send.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ send {
input[type='number'] {
-moz-appearance: textfield;
}

.fee {
position: absolute;
left: auto;
right: 6px;
bottom: 7px;
font-size: 12px;
line-height: 14px;
transition: all 0.3s cubic-bezier(0.55, 0, 0.55, 0.2);
color: grey;
}

md-card-title md-menu {
margin: -8px -14px;
}
}
9 changes: 9 additions & 0 deletions src/app/components/send/send.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ md-card.offline-hide
md-card-title
md-card-title-text
span.md-title Send
md-menu(md-position-mode='target-right target')
md-button.md-icon-button(ng-click='$mdOpenMenu()')
i.material-icons more_vert
md-menu-content(width='4')
md-menu-item
md-button(ng-click='$ctrl.setMaxAmount()')
div(layout='row', flex='')
p(flex='') Set maximum amount
md-card-content
form(name='$ctrl.sendForm')
md-content(flex='100', flex-gt-sm='70', flex-offset-gt-sm='15')
Expand All @@ -14,6 +22,7 @@ md-card.offline-hide
md-input-container.md-block
label Transaction Amount
input(type='number', name='amount', ng-model='$ctrl.amount.value', required, ng-pattern='$ctrl.amount.regexp', ng-disabled='$ctrl.loading', ng-max='$ctrl.amount.max', ignore-mouse-wheel)
div.fee(ng-show='$ctrl.amount.value') Fee: 0.1 LSK
div(ng-messages='$ctrl.sendForm.amount.$error')
div(ng-message='required') Required
div(ng-message='pattern') Invalid
Expand Down
7 changes: 5 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"angular-mocks": "=1.5.8",
"babel-core": "=6.9.1",
"babel-loader": "=6.2.4",
"babel-plugin-syntax-trailing-function-commas": "=6.22.0",
"babel-plugin-istanbul": "^4.0.0",
"babel-plugin-syntax-trailing-function-commas": "=6.22.0",
"babel-preset-es2015": "=6.9.0",
"chai": "=3.5.0",
"clean-webpack-plugin": "=0.1.9",
Expand All @@ -46,6 +46,7 @@
"git-hooks": "=1.1.8",
"grunt": "=1.0.1",
"grunt-eslint": "=19.0.0",
"grunt-newer": "^1.2.0",
"html-webpack-plugin": "=2.19.0",
"imports-loader": "=0.6.5",
"jasmine-spec-reporter": "^3.2.0",
Expand Down Expand Up @@ -88,7 +89,9 @@
"presets": [
"es2015"
],
"plugins": ["syntax-trailing-function-commas"],
"plugins": [
"syntax-trailing-function-commas"
],
"env": {
"test": {
"plugins": [
Expand Down
36 changes: 31 additions & 5 deletions src/test/components/send/send.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ describe('Send component', () => {
let $rootScope;
let element;
let $scope;
let lsk;

beforeEach(angular.mock.module('app'));

beforeEach(inject((_$compile_, _$rootScope_) => {
beforeEach(inject((_$compile_, _$rootScope_, _lsk_) => {
$compile = _$compile_;
$rootScope = _$rootScope_;
lsk = _lsk_;
}));

beforeEach(() => {
$scope = $rootScope.$new();
$scope.passphrase = 'robust swift grocery peasant forget share enable convince deputy road keep cheap';
$scope.account = {
address: '8273455169423958419L',
balance: '10000',
balance: lsk.from(100),
};
element = $compile('<send passphrase="passphrase" account="account"></send>')($scope);
$scope.$digest();
Expand Down Expand Up @@ -64,10 +66,10 @@ describe('Send component', () => {
const RECIPIENT_ADDRESS = '5932438298200837883L';
const AMOUNT = '10';

$peers.active = { sendTransaction() {} };
$peers.active = { sendLSKPromise() {} };
const mock = sinon.mock($peers.active);
const deffered = $q.defer();
mock.expects('sendTransaction').returns(deffered.promise);
mock.expects('sendLSKPromise').returns(deffered.promise);

const spy = sinon.spy(success, 'dialog');

Expand All @@ -76,9 +78,33 @@ describe('Send component', () => {
$scope.$apply();
element.find('button.md-raised').click();

deffered.resolve();
deffered.resolve({});
$scope.$apply();
expect(spy).to.have.been.calledWith({ text: `${AMOUNT} sent to ${RECIPIENT_ADDRESS}` });
mock.verify();
});

it('should allow to send all funds', () => {
const RECIPIENT_ADDRESS = '5932438298200837883L';
const AMOUNT = lsk.normalize($scope.account.balance) - 0.1;

$peers.active = { sendLSKPromise() {} };
const mock = sinon.mock($peers.active);
const deffered = $q.defer();
mock.expects('sendLSKPromise').returns(deffered.promise);

const spy = sinon.spy(success, 'dialog');

element.find('md-menu-item button').click();
element.find('form input[name="recipient"]').val(RECIPIENT_ADDRESS).trigger('input');
$scope.$apply();
expect(element.find('form input[name="amount"]').val()).to.equal(`${AMOUNT}`);
element.find('button.md-raised').click();

deffered.resolve({});
$scope.$apply();
expect(spy).to.have.been.calledWith();
expect(spy).to.have.been.calledWith({ text: `${AMOUNT} sent to ${RECIPIENT_ADDRESS}` });
mock.verify();
});
});
Expand Down

0 comments on commit 5e51059

Please sign in to comment.