Merge pull request #6100 from cmgustavo/feat/tx-confirm-notification-02

Notify when a tx has been confirmed
This commit is contained in:
Gabriel Edgardo Bazán 2017-05-29 14:01:00 -03:00 committed by GitHub
commit 5f39c45d61
6 changed files with 74 additions and 2 deletions

View file

@ -598,5 +598,17 @@ angular.module('copayApp.services')
storage.remove('amazonGiftCards-' + network, cb);
};
root.setTxConfirmNotification = function(txid, val, cb) {
storage.set('txConfirmNotif-' + txid, val, cb);
};
root.getTxConfirmNotification = function(txid, cb) {
storage.get('txConfirmNotif-' + txid, cb);
};
root.removeTxConfirmNotification = function(txid, cb) {
storage.remove('txConfirmNotif-' + txid, cb);
};
return root;
});

View file

@ -0,0 +1,32 @@
'use strict';
angular.module('copayApp.services').factory('txConfirmNotification', function txConfirmNotification($log, storageService) {
var root = {};
root.checkIfEnabled = function(txid, cb) {
storageService.getTxConfirmNotification(txid, function(err, res) {
if (err) $log.error(err);
return cb(!!res);
});
};
root.subscribe = function(client, opts) {
client.txConfirmationSubscribe(opts, function(err, res) {
if (err) $log.error(err);
storageService.setTxConfirmNotification(opts.txid, true, function(err) {
if (err) $log.error(err);
});
});
};
root.unsubscribe = function(client, txId) {
client.txConfirmationUnsubscribe(txId, function(err, res) {
if (err) $log.error(err);
storageService.removeTxConfirmNotification(txId, function(err) {
if (err) $log.error(err);
});
});
};
return root;
});