|
|
@ -3,6 +3,8 @@ var _ = require('lodash'); |
|
|
|
var $ = require('preconditions').singleton(); |
|
|
|
var async = require('async'); |
|
|
|
var log = require('npmlog'); |
|
|
|
var config = require('../config'); |
|
|
|
|
|
|
|
log.debug = log.verbose; |
|
|
|
log.disableColor(); |
|
|
|
var EmailValidator = require('email-validator'); |
|
|
@ -24,6 +26,8 @@ var MessageBroker = require('./messagebroker'); |
|
|
|
var BlockchainExplorer = require('./blockchainexplorer'); |
|
|
|
var FiatRateService = require('./fiatrateservice'); |
|
|
|
|
|
|
|
var request = require('request'); |
|
|
|
|
|
|
|
var Model = require('./model'); |
|
|
|
var Wallet = Model.Wallet; |
|
|
|
|
|
|
@ -80,6 +84,8 @@ WalletService.initialize = function(opts, cb) { |
|
|
|
lock = opts.lock || new Lock(opts.lockOpts); |
|
|
|
blockchainExplorer = opts.blockchainExplorer; |
|
|
|
blockchainExplorerOpts = opts.blockchainExplorerOpts; |
|
|
|
if (opts.request) |
|
|
|
request = opts.request; |
|
|
|
|
|
|
|
function initStorage(cb) { |
|
|
|
if (opts.storage) { |
|
|
@ -644,8 +650,8 @@ WalletService.prototype.joinWallet = function(opts, cb) { |
|
|
|
} |
|
|
|
|
|
|
|
if (_.find(wallet.copayers, { |
|
|
|
xPubKey: opts.xPubKey |
|
|
|
})) return cb(Errors.COPAYER_IN_WALLET); |
|
|
|
xPubKey: opts.xPubKey |
|
|
|
})) return cb(Errors.COPAYER_IN_WALLET); |
|
|
|
|
|
|
|
if (wallet.copayers.length == wallet.n) return cb(Errors.WALLET_FULL); |
|
|
|
|
|
|
@ -738,8 +744,8 @@ WalletService.prototype._canCreateAddress = function(ignoreMaxGap, cb) { |
|
|
|
isChange: true |
|
|
|
}), Defaults.MAX_MAIN_ADDRESS_GAP); |
|
|
|
if (latestAddresses.length < Defaults.MAX_MAIN_ADDRESS_GAP || _.any(latestAddresses, { |
|
|
|
hasActivity: true |
|
|
|
})) return cb(null, true); |
|
|
|
hasActivity: true |
|
|
|
})) return cb(null, true); |
|
|
|
|
|
|
|
var bc = self._getBlockchainExplorer(latestAddresses[0].network); |
|
|
|
var activityFound = false; |
|
|
@ -2421,6 +2427,38 @@ WalletService.prototype.getFiatRate = function(opts, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
WalletService.prototype.pushNotificationsSubscribe = function(opts, cb) { |
|
|
|
if (!Utils.checkRequired(opts, ['token'])) |
|
|
|
return cb(new ClientError('Required argument missing')); |
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
opts.user = self.walletId + '$' + self.copayerId + '$' + opts.token; |
|
|
|
|
|
|
|
request({ |
|
|
|
url: config.pushNotificationsOpts.pushServerUrl + '/subscribe', |
|
|
|
method: 'POST', |
|
|
|
json: true, |
|
|
|
body: opts |
|
|
|
}, function(err, response) { |
|
|
|
return cb(err, response); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
WalletService.prototype.pushNotificationsUnsubscribe = function(token, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
request({ |
|
|
|
url: config.pushNotificationsOpts.pushServerUrl + '/unsubscribe', |
|
|
|
method: 'POST', |
|
|
|
json: true, |
|
|
|
body: { |
|
|
|
user: self.walletId + '$' + self.copayerId + '$' + token |
|
|
|
} |
|
|
|
}, function(err, response) { |
|
|
|
return cb(err, response); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = WalletService; |
|
|
|
module.exports.ClientError = ClientError; |
|
|
|