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

Commit

Permalink
Merge pull request #369 from isocolsky/feat/tx-confirm-notif
Browse files Browse the repository at this point in the history
Add endpoint for tx confirmations notifications API
  • Loading branch information
isocolsky authored May 25, 2017
2 parents 8789f9e + c9fa141 commit 2508673
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
29 changes: 25 additions & 4 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ API.prototype.getFiatRate = function(opts, cb) {
}

/**
* Returns subscription status.
* Subscribe to push notifications.
* @param {Object} opts
* @param {String} opts.type - Device type (ios or android).
* @param {String} opts.token - Device token.
Expand All @@ -2390,18 +2390,39 @@ API.prototype.pushNotificationsSubscribe = function(opts, cb) {
};

/**
* Returns unsubscription status.
* Unsubscribe from push notifications.
* @param {String} token - Device token
* @return {Callback} cb - Return error if exists
*/
API.prototype.pushNotificationsUnsubscribe = function(token, cb) {
var url = '/v2/pushnotifications/subscriptions/' + token;
this._doDeleteRequest(url, function(err) {
this._doDeleteRequest(url, cb);
};

/**
* Listen to a tx for its first confirmation.
* @param {Object} opts
* @param {String} opts.txid - The txid to subscribe to.
* @returns {Object} response - Status of subscription.
*/
API.prototype.txConfirmationSubscribe = function(opts, cb) {
var url = '/v1/txconfirmations/';
this._doPostRequest(url, opts, function(err, response) {
if (err) return cb(err);
return cb(null);
return cb(null, response);
});
};

/**
* Stop listening for a tx confirmation.
* @param {String} txid - The txid to unsubscribe from.
* @return {Callback} cb - Return error if exists
*/
API.prototype.txConfirmationUnsubscribe = function(txid, cb) {
var url = '/v1/txconfirmations/' + txid;
this._doDeleteRequest(url, cb);
};

/**
* Returns send max information.
* @param {String} opts
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bitcore-wallet-client",
"description": "Client for bitcore-wallet-service",
"author": "BitPay Inc",
"version": "5.1.2",
"version": "5.2.0",
"license": "MIT",
"keywords": [
"bitcoin",
Expand Down Expand Up @@ -36,7 +36,7 @@
"superagent": "^3.4.1"
},
"devDependencies": {
"bitcore-wallet-service": "~1.15.0",
"bitcore-wallet-service": "~1.17.0",
"browserify": "^13.1.0",
"chai": "^1.9.1",
"coveralls": "^2.11.2",
Expand Down
28 changes: 28 additions & 0 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,34 @@ describe('client API', function() {
});
});

describe('Tx confirmations', function() {
it('should do a post request', function(done) {
helpers.createAndJoinWallet(clients, 1, 1, function() {
clients[0]._doRequest = sinon.stub().yields(null, {
statusCode: 200,
});
clients[0].txConfirmationSubscribe({
txid: '123'
}, function(err, res) {
should.not.exist(err);
should.exist(res);
res.statusCode.should.be.equal(200);
done();
});
});
});

it('should do a delete request', function(done) {
helpers.createAndJoinWallet(clients, 1, 1, function() {
clients[0]._doRequest = sinon.stub().yields(null);
clients[0].txConfirmationUnsubscribe('123', function(err) {
should.not.exist(err);
done();
});
});
});
});

describe('Get send max information', function() {
var balance;
beforeEach(function(done) {
Expand Down

0 comments on commit 2508673

Please sign in to comment.