Feat/coinbase integration (#4012)

* Oauth2 and first view

* Connect with Coinbase using mobile

* Buy and Sell through Coinbase

* Fix buy

* Receive and send bitcoin to Coinbase account

* Receive bitcoin from Coinbase to Copay

* Complete user and account information. Connection errors

* Improves error handler

* Removes console.log

* Coinbase background color. Send to Coinbase form validation

* Fix send from different wallet

* Send and receive using Coinbase

* Pagination activity

* Fix Buy and Sell

* One option in the sidebar to Buy and Sell

* Native balance on Coinbase homepage

* Rename receive and send

* Auto-close window after authenticate

* Reorder

* Get payment methods

* Fix when token expired

* Fix token expired

* Integration: sell and send to Coinbase

* Store pending transaction before sell

* Sell flow completed

* Removing files

* Fix sell

* Fix sell

* Fix sell

* Sell completed

* Buy bitcoin through coinbase

* Buy auto

* Currency set to USD

* Select payment methods. Limits

* Removes payment methods from preferences

* Fix signs. Tx ordered by updated. Minor fixes

* Removes console.log

* Improving ux-language things

* Fix selectedpaymentmethod if not verified

* Set error if tx not found

* Price sensitivity. Minor fixes

* Adds coinbase api key to gitignore

* Coinbase production ready

* Fix sell in usd

* Bug fixes

* New Sensitivity step

* Refresh token with a simple click

* Refresh token

* Refactor

* Fix auto reconnect if token expired

Signed-off-by: Gustavo Maximiliano Cortez <cmgustavo83@gmail.com>

* Fix calls if token expired
This commit is contained in:
Gustavo Maximiliano Cortez 2016-04-13 14:08:03 -03:00 committed by Matias Alejo Garcia
commit d0dbd85711
39 changed files with 2365 additions and 55 deletions

View file

@ -4,9 +4,10 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
var root = {};
var reportSigningStatus = function(opts) {
opts = opts || {};
if (!opts.reporterFn) return;
var fc = profileService.focusedClient;
var fc = opts.selectedClient || profileService.focusedClient;
if (fc.isPrivKeyExternal()) {
if (fc.getPrivKeyExternalSourceName() == 'ledger') {
@ -58,9 +59,10 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
}
};
root.checkTouchId = function(cb) {
root.checkTouchId = function(opts, cb) {
opts = opts || {};
var config = configService.getSync();
var fc = profileService.focusedClient;
var fc = opts.selectedClient || profileService.focusedClient;
config.touchIdFor = config.touchIdFor || {};
if (window.touchidAvailable && config.touchIdFor[fc.credentials.walletId]) {
requestTouchId(cb);
@ -69,17 +71,18 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
}
};
root.prepare = function(cb) {
var fc = profileService.focusedClient;
root.prepare = function(opts, cb) {
opts = opts || {};
var fc = opts.selectedClient || profileService.focusedClient;
if (!fc.canSign() && !fc.isPrivKeyExternal())
return cb('Cannot sign'); // should never happen, no need to translate
root.checkTouchId(function(err) {
root.checkTouchId(opts, function(err) {
if (err) {
return cb(err);
};
profileService.unlockFC(function(err) {
profileService.unlockFC(opts, function(err) {
if (err) {
return cb(bwsError.msg(err));
};
@ -90,8 +93,18 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
});
};
root.removeTx = function(txp, opts, cb) {
opts = opts || {};
var fc = opts.selectedClient || profileService.focusedClient;
fc.removeTxProposal(txp, function(err) {
return cb(err);
});
};
root.createTx = function(opts, cb) {
var fc = profileService.focusedClient;
opts = opts || {};
var fc = opts.selectedClient || profileService.focusedClient;
var currentSpendUnconfirmed = configService.getSync().wallet.spendUnconfirmed;
var getFee = function(cb) {
@ -114,16 +127,18 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
});
};
root.publishTx = function(txp, cb) {
var fc = profileService.focusedClient;
root.publishTx = function(txp, opts, cb) {
opts = opts || {};
var fc = opts.selectedClient || profileService.focusedClient;
fc.publishTxProposal({txp: txp}, function(err, txp) {
if (err) return cb(err);
else return cb(null, txp);
});
};
var _signWithLedger = function(txp, cb) {
var fc = profileService.focusedClient;
var _signWithLedger = function(txp, opts, cb) {
opts = opts || {};
var fc = opts.selectedClient || profileService.focusedClient;
$log.info('Requesting Ledger Chrome app to sign the transaction');
ledger.signTx(txp, fc.credentials.account, function(result) {
@ -138,8 +153,9 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
});
};
var _signWithTrezor = function(txp, cb) {
var fc = profileService.focusedClient;
var _signWithTrezor = function(txp, opts, cb) {
opts = opts || {};
var fc = opts.selectedClient || profileService.focusedClient;
$log.info('Requesting Trezor to sign the transaction');
var xPubKeys = lodash.pluck(fc.credentials.publicKeyRing, 'xPubKey');
@ -152,15 +168,16 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
});
};
root.sign = function(txp, cb) {
var fc = profileService.focusedClient;
root.sign = function(txp, opts, cb) {
opts = opts || {};
var fc = opts.selectedClient || profileService.focusedClient;
if (fc.isPrivKeyExternal()) {
switch (fc.getPrivKeyExternalSourceName()) {
case 'ledger':
return _signWithLedger(txp, cb);
return _signWithLedger(txp, opts, cb);
case 'trezor':
return _signWithTrezor(txp, cb);
return _signWithTrezor(txp, opts, cb);
default:
var msg = 'Unsupported External Key:' + fc.getPrivKeyExternalSourceName();
$log.error(msg);
@ -175,10 +192,11 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
};
root.signAndBroadcast = function(txp, opts, cb) {
opts = opts || {};
reportSigningStatus(opts);
var fc = profileService.focusedClient;
root.sign(txp, function(err, txp) {
var fc = opts.selectedClient || profileService.focusedClient;
root.sign(txp, opts, function(err, txp) {
if (err) {
stopReport(opts);
return cb(bwsError.msg(err), gettextCatalog.getString('Could not accept payment'));
@ -208,7 +226,8 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
};
root.prepareAndSignAndBroadcast = function(txp, opts, cb) {
root.prepare(function(err) {
opts = opts || {};
root.prepare(opts, function(err) {
if (err) {
stopReport(opts);
return cb(err);