fix merge conflicts

This commit is contained in:
Marty Alcala 2016-10-18 17:23:43 -04:00
commit 78bd523391
272 changed files with 8069 additions and 5496 deletions

View file

@ -1,195 +1,239 @@
'use strict';
angular.module('copayApp.services').factory('bitpayCardService', function($http, $log, lodash, storageService) {
angular.module('copayApp.services').factory('bitpayCardService', function($http, $log, lodash, storageService, bitauthService, platformInfo, moment) {
var root = {};
var credentials = {};
var bpSession = {};
var BITPAY_CARD_NETWORK = 'livenet';
var BITPAY_CARD_API_URL = BITPAY_CARD_NETWORK == 'livenet' ? 'https://bitpay.com' : 'https://test.bitpay.com';
var _setCredentials = function() {
/*
* Development: 'testnet'
* Production: 'livenet'
*/
credentials.NETWORK = 'livenet';
if (credentials.NETWORK == 'testnet') {
credentials.BITPAY_API_URL = 'https://test.bitpay.com';
}
else {
credentials.BITPAY_API_URL = 'https://bitpay.com';
};
var _getCredentials = function(cb) {
var pubkey, sin, isNew;
storageService.getBitpayCardCredentials(BITPAY_CARD_NETWORK, function(err, data) {
if (err) return cb(err);
if (lodash.isString(data)) {
data = JSON.parse(data);
}
var credentials = data || {};
if (lodash.isEmpty(credentials) || (credentials && !credentials.priv)) {
isNew = true;
credentials = bitauthService.generateSin();
}
try {
pubkey = bitauthService.getPublicKeyFromPrivateKey(credentials.priv);
sin = bitauthService.getSinFromPublicKey(pubkey);
if (isNew)
storageService.setBitpayCardCredentials(BITPAY_CARD_NETWORK, JSON.stringify(credentials), function(err) {});
}
catch (e) {
$log.error(e);
return cb(e);
};
return cb(null, credentials);
});
};
var _setError = function(msg, e) {
$log.error(msg);
return e;
var error = e.data ? e.data.error : msg;
return error;
};
var _getUser = function(cb) {
_setCredentials();
storageService.getBitpayCard(credentials.NETWORK, function(err, user) {
if (err) return cb(err);
if (lodash.isString(user)) {
user = JSON.parse(user);
}
return cb(null, user);
});
};
var _setUser = function(user, cb) {
_setCredentials();
user = JSON.stringify(user);
storageService.setBitpayCard(credentials.NETWORK, user, function(err) {
return cb(err);
});
// Show pending task from the UI
storageService.setNextStep('BitpayCard', true, function(err) {});
};
var _getSession = function(cb) {
_setCredentials();
$http({
var _get = function(endpoint) {
return {
method: 'GET',
url: credentials.BITPAY_API_URL + '/visa-api/session',
url: BITPAY_CARD_API_URL + endpoint,
headers: {
'content-type': 'application/json'
}
}).then(function(data) {
$log.info('BitPay Get Session: SUCCESS');
bpSession = data.data.data;
return cb(null, bpSession);
};
};
var _post = function(endpoint, json, credentials) {
var dataToSign = BITPAY_CARD_API_URL + endpoint + JSON.stringify(json);
var signedData = bitauthService.sign(dataToSign, credentials.priv);
return {
method: 'POST',
url: BITPAY_CARD_API_URL + endpoint,
headers: {
'content-type': 'application/json',
'x-identity': credentials.pub,
'x-signature': signedData
},
data: json
};
};
var _postAuth = function(endpoint, json, credentials) {
json['params'].signature = bitauthService.sign(JSON.stringify(json.params), credentials.priv);
json['params'].pubkey = credentials.pub;
json['params'] = JSON.stringify(json.params);
var ret = {
method: 'POST',
url: BITPAY_CARD_API_URL + endpoint,
headers: {
'content-type': 'application/json'
},
data: json
};
$log.debug('post auth:' + JSON.stringify(ret));
return ret;
};
var _afterBitAuthSuccess = function(token, obj, credentials, cb) {
var json = {
method: 'getDebitCards'
};
// Get Debit Cards
$http(_post('/api/v2/' + token, json, credentials)).then(function(data) {
if (data && data.data.error) return cb(data.data.error);
$log.info('BitPay Get Debit Cards: SUCCESS');
return cb(data.data.error, {token: token, cards: data.data.data, email: obj.email});
}, function(data) {
return cb(_setError('BitPay Card Error: Get Session', data));
return cb(_setError('BitPay Card Error: Get Debit Cards', data));
});
};
var _getBitPay = function(endpoint) {
_setCredentials();
return {
method: 'GET',
url: credentials.BITPAY_API_URL + endpoint,
headers: {
'content-type': 'application/json',
'x-csrf-token': bpSession.csrfToken
var _processTransactions = function(invoices, history) {
invoices = invoices || [];
for (var i = 0; i < invoices.length; i++) {
var matched = false;
for (var j = 0; j < history.length; j++) {
if (history[j].description[0].indexOf(invoices[i].id) > -1) {
matched = true;
}
}
};
};
var isInvoiceLessThanOneDayOld = moment() < moment(new Date(invoices[i].invoiceTime)).add(1, 'day');
if (!matched && isInvoiceLessThanOneDayOld) {
var isInvoiceUnderpaid = invoices[i].exceptionStatus === 'paidPartial';
var _postBitPay = function(endpoint, data) {
_setCredentials();
return {
method: 'POST',
url: credentials.BITPAY_API_URL + endpoint,
headers: {
'Content-Type': 'application/json',
'x-csrf-token': bpSession.csrfToken
},
data: data
};
if(['paid', 'confirmed', 'complete'].indexOf(invoices[i].status) >= 0
|| (invoices[i].status === 'invalid' || isInvoiceUnderpaid)) {
history.unshift({
timestamp: new Date(invoices[i].invoiceTime),
description: invoices[i].itemDesc,
amount: invoices[i].price,
type: '00611 = Client Funded Deposit',
pending: true,
status: invoices[i].status
});
}
}
}
return history;
};
root.getEnvironment = function() {
_setCredentials();
return credentials.NETWORK;
return BITPAY_CARD_NETWORK;
};
root.topUp = function(data, cb) {
var dataSrc = {
amount: data.amount,
currency: data.currency
};
$http(_postBitPay('/visa-api/topUp', dataSrc)).then(function(data) {
$log.info('BitPay TopUp: SUCCESS');
return cb(null, data.data.data.invoice);
}, function(data) {
return cb(_setError('BitPay Card Error: TopUp', data));
root.getCredentials = function(cb) {
_getCredentials(function(err, credentials) {
return cb(err, credentials);
});
};
root.transactionHistory = function(dateRange, cb) {
var params;
if (!dateRange.startDate) {
params = '';
} else {
params = '/?startDate=' + dateRange.startDate + '&endDate=' + dateRange.endDate;
root.bitAuthPair = function(obj, cb) {
var deviceName = 'Unknow device';
if (platformInfo.isNW) {
deviceName = require('os').platform();
} else if (platformInfo.isCordova) {
deviceName = device.model;
}
$http(_getBitPay('/visa-api/transactionHistory' + params)).then(function(data) {
$log.info('BitPay Get Transaction History: SUCCESS');
return cb(null, data.data.data);
}, function(data) {
return cb(_setError('BitPay Card Error: Get Transaction History', data));
var json = {
method: 'createToken',
params: {
secret: obj.secret,
version: 2,
deviceName: deviceName,
code: obj.otp
}
};
_getCredentials(function(err, credentials) {
if (err) return cb(err);
$http(_postAuth('/api/v2/', json, credentials)).then(function(data) {
if (data && data.data.error) return cb(data.data.error);
$log.info('BitPay Card BitAuth Create Token: SUCCESS');
_afterBitAuthSuccess(data.data.data, obj, credentials, cb);
}, function(data) {
return cb(_setError('BitPay Card Error Create Token: BitAuth', data));
});
});
};
root.invoiceHistory = function(cb) {
$http(_getBitPay('/visa-api/invoiceHistory')).then(function(data) {
$log.info('BitPay Get Invoice History: SUCCESS');
return cb(null, data.data.data);
}, function(data) {
return cb(_setError('BitPay Card Error: Get Invoice History', data));
root.getHistory = function(cardId, params, cb) {
var invoices, transactions;
params = params || {};
var json = {
method: 'getInvoiceHistory',
params: JSON.stringify(params)
};
_getCredentials(function(err, credentials) {
if (err) return cb(err);
root.getBitpayDebitCards(function(err, data) {
if (err) return cb(err);
var card = lodash.find(data.cards, {id : cardId});
if (!card) return cb(_setError('Not card found'));
// Get invoices
$http(_post('/api/v2/' + card.token, json, credentials)).then(function(data) {
$log.info('BitPay Get Invoices: SUCCESS');
invoices = data.data.data || [];
if (lodash.isEmpty(invoices)) $log.info('No invoices');
json = {
method: 'getTransactionHistory',
params: JSON.stringify(params)
};
// Get transactions list
$http(_post('/api/v2/' + card.token, json, credentials)).then(function(data) {
$log.info('BitPay Get Transactions: SUCCESS');
transactions = data.data.data || {};
transactions['txs'] = _processTransactions(invoices, transactions.transactionList);
return cb(data.data.error, transactions);
}, function(data) {
return cb(_setError('BitPay Card Error: Get Transactions', data));
});
}, function(data) {
return cb(_setError('BitPay Card Error: Get Invoices', data));
});
});
});
};
root.topUp = function(cardId, params, cb) {
params = params || {};
var json = {
method: 'generateTopUpInvoice',
params: JSON.stringify(params)
};
_getCredentials(function(err, credentials) {
if (err) return cb(err);
root.getBitpayDebitCards(function(err, data) {
if (err) return cb(err);
var card = lodash.find(data.cards, {id : cardId});
if (!card) return cb(_setError('Not card found'));
$http(_post('/api/v2/' + card.token, json, credentials)).then(function(data) {
$log.info('BitPay TopUp: SUCCESS');
return cb(data.data.error, data.data.data.invoice);
}, function(data) {
return cb(_setError('BitPay Card Error: TopUp', data));
});
});
});
};
root.getInvoice = function(id, cb) {
$http(_getBitPay('/invoices/' + id)).then(function(data) {
$http(_get('/invoices/' + id)).then(function(data) {
$log.info('BitPay Get Invoice: SUCCESS');
return cb(null, data.data.data);
return cb(data.data.error, data.data.data);
}, function(data) {
return cb(_setError('BitPay Card Error: Get Invoice', data));
});
};
root.authenticate = function(userData, cb) {
_setUser(userData, function(err) {
$http(_postBitPay('/visa-api/authenticate', userData)).then(function(data) {
$log.info('BitPay Authenticate: SUCCESS');
_getSession(function(err, session) {
if (err) return cb(err);
return cb(null, session);
});
}, function(data) {
if (data && data.data && data.data.error.twoFactorPending) {
$log.error('BitPay Card needs 2FA Authentication');
_getSession(function(err, session) {
if (err) return cb(err);
return cb(null, session);
});
} else {
return cb(data);
}
});
});
};
root.authenticate2FA = function(userData, cb) {
$http(_postBitPay('/visa-api/verify-two-factor', userData)).then(function(data) {
$log.info('BitPay 2FA: SUCCESS');
return cb(null, data);
}, function(data) {
return cb(_setError('BitPay Card Error: 2FA', data));
});
};
root.isAuthenticated = function(cb) {
_getSession(function(err, session) {
if (err) return cb(err);
if (!session.isAuthenticated) {
_getUser(function(err, user) {
if (err) return cb(err);
if (lodash.isEmpty(user)) return cb(null, session);
root.authenticate(user, function(err, session) {
if (err) return cb(err);
return cb(null, session);
});
});
} else {
return cb(null, session);
}
});
};
root.getCacheData = function(cb) {
_setCredentials();
storageService.getBitpayCardCache(credentials.NETWORK, function(err, data) {
root.getBitpayDebitCards = function(cb) {
storageService.getBitpayDebitCards(BITPAY_CARD_NETWORK, function(err, data) {
if (err) return cb(err);
if (lodash.isString(data)) {
data = JSON.parse(data);
@ -199,32 +243,54 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
});
};
root.setCacheData = function(data, cb) {
_setCredentials();
root.setBitpayDebitCards = function(data, cb) {
data = JSON.stringify(data);
storageService.setBitpayCardCache(credentials.NETWORK, data, function(err) {
storageService.setBitpayDebitCards(BITPAY_CARD_NETWORK, data, function(err) {
if (err) return cb(err);
return cb();
});
};
root.removeCacheData = function(cb) {
_setCredentials();
storageService.removeBitpayCardCache(credentials.NETWORK, function(err) {
root.getBitpayDebitCardsHistory = function(cardId, cb) {
storageService.getBitpayDebitCardsHistory(BITPAY_CARD_NETWORK, function(err, data) {
if (err) return cb(err);
return cb();
if (lodash.isString(data)) {
data = JSON.parse(data);
}
data = data || {};
if (cardId) data = data[cardId];
return cb(null, data);
});
};
root.logout = function(cb) {
_setCredentials();
root.removeCacheData(function() {});
storageService.removeBitpayCard(credentials.NETWORK, function(err) {
$http(_getBitPay('/visa-api/logout')).then(function(data) {
$log.info('BitPay Logout: SUCCESS');
return cb(data);
}, function(data) {
return cb(_setError('BitPay Card Error: Logout ', data));
root.setBitpayDebitCardsHistory = function(cardId, data, opts, cb) {
storageService.getBitpayDebitCardsHistory(BITPAY_CARD_NETWORK, function(err, oldData) {
if (lodash.isString(oldData)) {
oldData = JSON.parse(oldData);
}
if (lodash.isString(data)) {
data = JSON.parse(data);
}
var inv = oldData || {};
inv[cardId] = data;
if (opts && opts.remove) {
delete(inv[cardId]);
}
inv = JSON.stringify(inv);
storageService.setBitpayDebitCardsHistory(BITPAY_CARD_NETWORK, inv, function(err) {
return cb(err);
});
});
};
root.remove = function(cb) {
storageService.removeBitpayCardCredentials(BITPAY_CARD_NETWORK, function(err) {
storageService.removeBitpayDebitCards(BITPAY_CARD_NETWORK, function(err) {
storageService.removeBitpayDebitCardsHistory(BITPAY_CARD_NETWORK, function(err) {
$log.info('BitPay Debit Cards Removed: SUCCESS');
return cb();
});
});
});
};

View file

@ -1,8 +1,14 @@
'use strict';
angular.module('copayApp.services').service('externalLinkService', function($window, $timeout, $log, platformInfo, nodeWebkitService) {
angular.module('copayApp.services').service('externalLinkService', function(platformInfo, nodeWebkitService, popupService, gettextCatalog, $window, $log, $timeout) {
this.open = function(url, target) {
var _restoreHandleOpenURL = function(old) {
$timeout(function() {
$window.handleOpenURL = old;
}, 500);
};
this.open = function(url, optIn, title, message, okText, cancelText) {
var old = $window.handleOpenURL;
$window.handleOpenURL = function(url) {
@ -10,15 +16,24 @@ angular.module('copayApp.services').service('externalLinkService', function($win
$log.debug('Skip: ' + url);
};
$timeout(function() {
$window.handleOpenURL = old;
}, 500);
if (platformInfo.isNW) {
nodeWebkitService.openExternalLink(url);
_restoreHandleOpenURL(old);
} else {
target = target || '_blank';
var ref = window.open(url, target, 'location=no');
if (optIn) {
var message = gettextCatalog.getString(message),
title = gettextCatalog.getString(title),
okText = gettextCatalog.getString(okText),
cancelText = gettextCatalog.getString(cancelText),
openBrowser = function(res) {
if (res) window.open(url, '_system');
_restoreHandleOpenURL(old);
};
popupService.showConfirm(title, message, okText, cancelText, openBrowser);
} else {
window.open(url, '_system');
_restoreHandleOpenURL(old);
}
}
};

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('incomingData', function($log, $ionicModal, $state, $window, $timeout, bitcore, profileService, popupService, ongoingProcess, platformInfo, gettextCatalog, scannerService, $rootScope) {
angular.module('copayApp.services').factory('incomingData', function($log, $ionicModal, $state, $window, $timeout, bitcore, profileService, popupService, ongoingProcess, platformInfo, gettextCatalog, scannerService, $rootScope, lodash) {
var root = {};
@ -14,7 +14,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
// }, 2000);
root.redir = function(data) {
$log.debug('Processing incoming data:' +data);
$log.debug('Processing incoming data: ' + data);
function sanitizeUri(data) {
// Fixes when a region uses comma to separate decimals
@ -32,17 +32,25 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
return newUri;
}
function getParameterByName(name, url) {
if (!url) return;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// data extensions for Payment Protocol with non-backwards-compatible request
if ((/^bitcoin:\?r=[\w+]/).exec(data)) {
data = decodeURIComponent(data.replace('bitcoin:?r=', ''));
$state.go('tabs.send');
$timeout(function() {
$state.go('tabs.send').then(function() {
$state.transitionTo('tabs.send.confirm', {paypro: data});
}, 100);
});
return true;
}
data = sanitizeUri(data);
data = '1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX';
@ -56,6 +64,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
var amount = parsed.amount ? parsed.amount : '';
$state.go('tabs.send');
// Timeout is required to enable the "Back" button
$timeout(function() {
if (parsed.r) {
$state.transitionTo('tabs.send.confirm', {paypro: parsed.r});
@ -66,7 +75,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
$state.transitionTo('tabs.send.amount', {toAddress: addr});
}
}
}, 100);
});
return true;
// Plain URL
@ -91,40 +100,41 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
});
// Plain Address
} else if (bitcore.Address.isValid(data, 'livenet')) {
return root.showMenu({data: data, type: 'bitcoinAddress'});
$state.go('tabs.send');
$timeout(function() {
$state.transitionTo('tabs.send.amount', {toAddress: data});
}, 100);
return true;
root.showMenu({data: data, type: 'bitcoinAddress'});
} else if (bitcore.Address.isValid(data, 'testnet')) {
return root.showMenu({data: data, type: 'bitcoinAddress'});
$state.go('tabs.send');
$timeout(function() {
$state.transitionTo('tabs.send.amount', {toAddress: data});
}, 100);
return true;
root.showMenu({data: data, type: 'bitcoinAddress'});
// Protocol
} else if (data && data.indexOf($window.appConfig.name + '://glidera')==0) {
return $state.go('uriglidera', {url: data});
} else if (data && data.indexOf($window.appConfig.name + '://coinbase')==0) {
return $state.go('uricoinbase', {url: data});
// BitPayCard Authentication
} else if (data && data.indexOf($window.appConfig.name + '://')==0) {
var secret = getParameterByName('secret', data);
var email = getParameterByName('email', data);
var otp = getParameterByName('otp', data);
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.bitpayCardIntro', {
secret: secret,
email: email,
otp: otp
});
});
return true;
// Join
} else if (data && data.match(/^copay:[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
$state.go('tabs.home');
$timeout(function() {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.join', {url: data});
}, 100);
});
return true;
// Old join
} else if (data && data.match(/^[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
$state.go('tabs.home');
$timeout(function() {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.join', {url: data});
}, 100);
});
return true;
}

View file

@ -77,7 +77,7 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni
this.showAlert = function(title, msg, cb, buttonName) {
var message = (msg && msg.message) ? msg.message : msg;
$log.warn(title + ": " + message);
$log.warn(title ? (title + ': ' + message) : message);
if (isCordova)
_cordovaAlert(title, message, cb, buttonName);
@ -97,7 +97,7 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni
*/
this.showConfirm = function(title, message, okText, cancelText, cb) {
$log.warn(title + ": " + message);
$log.warn(title ? (title + ': ' + message) : message);
if (isCordova)
_cordovaConfirm(title, message, okText, cancelText, cb);
@ -116,7 +116,7 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni
*/
this.showPrompt = function(title, message, opts, cb) {
$log.warn(title + ": " + message);
$log.warn(title ? (title + ': ' + message) : message);
if (isCordova && !opts.forceHTMLPrompt)
_cordovaPrompt(title, message, opts, cb);

View file

@ -134,8 +134,7 @@ angular.module('copayApp.services')
if (n.type == "NewBlock" && n.data.network == "testnet") {
throttledBwsEvent(n, wallet);
}
else newBwsEvent(n, wallet);
} else newBwsEvent(n, wallet);
});
wallet.on('walletCompleted', function() {
@ -600,6 +599,7 @@ angular.module('copayApp.services')
var walletClient = bwcService.getClient(null, opts);
$log.debug('Importing Wallet:', opts);
try {
walletClient.import(str, {
compressed: opts.compressed,
@ -611,6 +611,12 @@ angular.module('copayApp.services')
str = JSON.parse(str);
if (str.xPrivKey && str.xPrivKeyEncrypted) {
$log.warn('Found both encrypted and decrypted key. Deleting the encrypted version');
delete str.xPrivKeyEncrypted;
delete str.mnemonicEncrypted;
}
var addressBook = str.addressBook || {};
addAndBindWalletClient(walletClient, {

View file

@ -325,28 +325,40 @@ angular.module('copayApp.services')
storage.remove('coinbaseTxs-' + network, cb);
};
root.setBitpayCard = function(network, data, cb) {
storage.set('bitpayCard-' + network, data, cb);
root.setBitpayDebitCardsHistory = function(network, data, cb) {
storage.set('bitpayDebitCardsHistory-' + network, data, cb);
};
root.getBitpayCard = function(network, cb) {
storage.get('bitpayCard-' + network, cb);
root.getBitpayDebitCardsHistory = function(network, cb) {
storage.get('bitpayDebitCardsHistory-' + network, cb);
};
root.removeBitpayCard = function(network, cb) {
storage.remove('bitpayCard-' + network, cb);
root.removeBitpayDebitCardsHistory = function(network, cb) {
storage.remove('bitpayDebitCardsHistory-' + network, cb);
};
root.setBitpayCardCache = function(network, data, cb) {
storage.set('bitpayCardCache-' + network, data, cb);
root.setBitpayDebitCards = function(network, data, cb) {
storage.set('bitpayDebitCards-' + network, data, cb);
};
root.getBitpayCardCache = function(network, cb) {
storage.get('bitpayCardCache-' + network, cb);
root.getBitpayDebitCards = function(network, cb) {
storage.get('bitpayDebitCards-' + network, cb);
};
root.removeBitpayCardCache = function(network, cb) {
storage.remove('bitpayCardCache-' + network, cb);
root.removeBitpayDebitCards = function(network, cb) {
storage.remove('bitpayDebitCards-' + network, cb);
};
root.setBitpayCardCredentials = function(network, data, cb) {
storage.set('bitpayCardCredentials-' + network, data, cb);
};
root.getBitpayCardCredentials = function(network, cb) {
storage.get('bitpayCardCredentials-' + network, cb);
};
root.removeBitpayCardCredentials = function(network, cb) {
storage.remove('bitpayCardCredentials-' + network, cb);
};
root.removeAllWalletData = function(walletId, cb) {

View file

@ -507,7 +507,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
wallet.getTxNote({
txid: txid
}, function(err, note) {
if (err || !note) return cb(true);
if (err) return cb(err);
return cb(null, note);
});
};
@ -869,9 +869,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (!root.isEncrypted(wallet)) return cb();
askPassword(wallet.name, gettext('Enter Spending Password'), function(password) {
if (!password) return cb('no password');
if (!wallet.checkPassword(password)) return cb('wrong password');
if (!password) return cb('No password');
if (!wallet.checkPassword(password)) return cb('Wrong password');
return cb(null, password);
});
@ -990,8 +989,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
root.getEncodedWalletInfo = function(wallet, cb) {
root.getEncodedWalletInfo = function(wallet, password, cb) {
var derivationPath = wallet.credentials.getBaseAddressDerivationPath();
var encodingType = {
mnemonic: 1,
@ -1002,25 +1000,23 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
// not supported yet
if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign())
return null;
return cb(gettextCatalog.getString('Exporting via QR not supported for this wallet'));
root.getKeys(wallet, function(err, keys) {
if (err || !keys) return cb(err);
var keys = root.getKeysWithPassword(wallet, password);
if (keys.mnemonic) {
info = {
type: encodingType.mnemonic,
data: keys.mnemonic,
}
} else {
info = {
type: encodingType.xpriv,
data: keys.xPrivKey
}
if (keys.mnemonic) {
info = {
type: encodingType.mnemonic,
data: keys.mnemonic,
}
return cb(null, info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase));
} else {
info = {
type: encodingType.xpriv,
data: keys.xPrivKey
}
}
});
return cb(null, info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase));
};
root.setTouchId = function(wallet, enabled, cb) {
@ -1055,6 +1051,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
root.getKeysWithPassword = function(wallet, password) {
try {
return wallet.getKeys(password);
} catch (e) {}
}
root.getViewStatus = function(wallet, txp) {
var status = txp.status;
var type;