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

Commit

Permalink
Merge 1496b5a into b9e87ca
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Nov 21, 2017
2 parents b9e87ca + 1496b5a commit c6f9654
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function (config) {
logLevel: config.LOG_WARN,

client: {
captureConsole: true
captureConsole: false
},

autoWatch: true,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitcoin-unocoin-client",
"version": "0.3.4",
"version": "0.3.6",
"description": "Buy and sell Bitcoin using Unocoin API.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,7 +33,7 @@
"babel-polyfill": "6.16.*",
"babel-preset-es2015": "6.16.*",
"babelify": "7.3.*",
"bitcoin-exchange-client": "~0.4.1"
"bitcoin-exchange-client": "^0.5.0"
},
"devDependencies": {
"browserify": "13.*",
Expand Down
11 changes: 6 additions & 5 deletions src/trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Trade extends Exchange.Trade {
if (obj) {
this._id = obj.id;
this._state = obj.state;
this._txHash = obj.tx_hash;

this._delegate.deserializeExtraFields(obj, this);
this._confirmed = obj.confirmed;
Expand Down Expand Up @@ -92,17 +93,17 @@ class Trade extends Exchange.Trade {
this._sendAmount = this._inAmount;

this._outAmount = null;
this._outAmountExpected = null;
this._receiveAmount = null;

if (obj.btc && obj.btc !== '' && obj.btc !== '0') {
if (this.state !== 'completed') {
this._outAmountExpected = parseFloat(obj.btc) * 100000000.0;
this._receiveAmount = parseFloat(obj.btc);
} else {
this._outAmount = parseFloat(obj.btc) * 100000000.0;
this._outAmountExpected = this._outAmount;
this._outAmount = parseFloat(obj.btc);
this._receiveAmount = this._outAmount;
}
} else if (this._delegate.ticker) {
this._outAmountExpected = Math.round(this._inAmount / this._delegate.ticker.buy.price * 100000000);
this._receiveAmount = parseFloat((this._inAmount / this._delegate.ticker.buy.price).toFixed(8));
}
}

Expand Down
14 changes: 4 additions & 10 deletions tests/trade_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,25 +327,19 @@ describe('Trade', function () {
expect(window.console.warn).toHaveBeenCalled();
});

it('should use btc value as outAmountExpected before completed', () => {
it('should use btc value as receiveAmount before completed', () => {
tradeJsonAPI.btc = '1.0';
t.setFromAPI(tradeJsonAPI);
expect(t.outAmountExpected).toEqual(100000000);
console.log(t._receiveAmount);
expect(t._receiveAmount).toEqual(1);
expect(t.outAmount).toEqual(null);
});

it('should use btc value as outAmount once completed', () => {
tradeJsonAPI.btc = '1.0';
tradeJsonAPI.status = 'Completed';
t.setFromAPI(tradeJsonAPI);
expect(t.outAmount).toEqual(100000000);
});

it('should use ticker if btc field is missing or 0', () => {
tradeJsonAPI.btc = undefined;
t._delegate.ticker = {buy: {price: 75000}};
t.setFromAPI(tradeJsonAPI);
expect(t.outAmountExpected).toEqual(200000000);
expect(t._receiveAmount).toEqual(2);
});
});

Expand Down

0 comments on commit c6f9654

Please sign in to comment.