copay/old/index.js

1347 lines
39 KiB
JavaScript
Raw Normal View History

2015-03-06 07:00:10 -08:00
'use strict';
2016-07-29 11:30:38 -07:00
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, $ionicSideMenuDelegate, $httpBackend, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwcError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService, ongoingProcess) {
2016-07-21 07:18:48 -07:00
2015-03-06 07:00:10 -08:00
var self = this;
2015-10-23 09:26:59 -07:00
var SOFT_CONFIRMATION_LIMIT = 12;
2016-01-22 13:16:50 -08:00
var errors = bwcService.getErrors();
var historyUpdateInProgress = {};
var isChromeApp = platformInfo.isChromeApp;
var isCordova = platformInfo.isCordova;
2016-05-31 12:52:38 -07:00
var isNW = platformInfo.isNW;
var ret = {};
ret.isCordova = isCordova;
ret.isChromeApp = isChromeApp;
ret.isSafari = platformInfo.isSafari;
ret.isWindowsPhoneApp = platformInfo.isWP;
ret.historyShowLimit = 10;
ret.historyShowMoreLimit = 10;
2016-02-23 05:52:20 -08:00
ret.isSearching = false;
ret.prevState = 'walletHome';
ret.physicalScreenWidth = ((window.innerWidth > 0) ? window.innerWidth : screen.width);
2016-08-10 13:35:40 -07:00
ret.appConfig = window.appConfig;
// Only for testing
//storageService.checkQuota();
ret.menu = [{
'title': gettext('Receive'),
'icon': {
false: 'icon-receive',
true: 'icon-receive-active'
},
2015-04-21 22:48:00 -07:00
'link': 'receive'
2015-12-02 13:20:22 -08:00
}, {
2015-12-04 10:43:17 -08:00
'title': gettext('Activity'),
'icon': {
false: 'icon-activity',
true: 'icon-activity-active'
},
2015-12-02 13:20:22 -08:00
'link': 'walletHome'
2015-04-21 22:48:00 -07:00
}, {
'title': gettext('Send'),
'icon': {
false: 'icon-send',
true: 'icon-send-active'
},
2015-04-21 22:48:00 -07:00
'link': 'send'
2015-04-23 11:19:30 -07:00
}];
2015-04-21 22:48:00 -07:00
ret.addonViews = addonManager.addonViews();
ret.txTemplateUrl = addonManager.txTemplateUrl() || 'views/includes/transaction.html';
ret.tab = 'walletHome';
var vanillaScope = ret;
2015-04-23 08:27:43 -07:00
2016-05-31 12:52:38 -07:00
if (isNW) {
2016-04-11 08:56:18 -07:00
latestReleaseService.checkLatestRelease(function(err, newRelease) {
if (err) {
$log.warn(err);
return;
}
if (newRelease)
$scope.newRelease = gettext('There is a new version of Copay. Please update');
});
}
function strip(number) {
return (parseFloat(number.toPrecision(12)));
};
self.goHome = function() {
go.walletHome();
};
2015-07-30 11:26:16 -07:00
self.allowRefresher = function() {
2016-07-14 14:55:46 -07:00
if ($ionicSideMenuDelegate.getOpenRatio() != 0) self.allowPullToRefresh = false;
}
2016-05-13 11:05:43 -07:00
self.hideBalance = function() {
storageService.getHideBalanceFlag(self.walletId, function(err, shouldHideBalance) {
2016-05-20 07:37:13 -07:00
if (err) self.shouldHideBalance = false;
else self.shouldHideBalance = (shouldHideBalance == 'true') ? true : false;
2016-05-13 11:05:43 -07:00
});
}
2016-05-20 07:37:13 -07:00
self.onHold = function() {
self.shouldHideBalance = !self.shouldHideBalance;
2016-08-10 12:57:17 -07:00
storageService.setHideBalanceFlag(self.walletId, self.shouldHideBalance.toString(), function() {});
2016-05-13 11:05:43 -07:00
}
2016-06-14 08:07:54 -07:00
self.setWalletPreferencesTitle = function() {
return gettext("Wallet Preferences");
}
self.cleanInstance = function() {
$log.debug('Cleaning Index Instance');
lodash.each(self, function(v, k) {
if (lodash.isFunction(v)) return;
// This are to prevent flicker in mobile:
if (k == 'hasProfile') return;
if (k == 'tab') return;
if (k == 'noFocusedWallet') return;
if (k == 'backgroundColor') return;
if (k == 'physicalScreenWidth') return;
if (k == 'loadingWallet') {
self.loadingWallet = true;
return;
}
if (!lodash.isUndefined(vanillaScope[k])) {
self[k] = vanillaScope[k];
return;
}
delete self[k];
});
};
2015-03-06 07:00:10 -08:00
self.setFocusedWallet = function() {
var fc = profileService.focusedClient;
if (!fc) return;
self.cleanInstance();
2015-12-03 12:44:02 -08:00
self.loadingWallet = true;
2015-08-11 13:45:57 -07:00
self.setSpendUnconfirmed();
2015-03-06 07:00:10 -08:00
$timeout(function() {
2015-11-11 11:23:56 -08:00
$rootScope.$apply();
2016-06-13 07:44:58 -07:00
2015-03-06 07:00:10 -08:00
self.hasProfile = true;
self.isSingleAddress = false;
2015-03-06 07:00:10 -08:00
self.noFocusedWallet = false;
2016-06-14 04:39:34 -07:00
self.updating = false;
2015-03-06 07:00:10 -08:00
2015-04-29 08:16:28 -07:00
// Credentials Shortcuts
2015-03-06 07:00:10 -08:00
self.m = fc.credentials.m;
self.n = fc.credentials.n;
self.network = fc.credentials.network;
self.copayerId = fc.credentials.copayerId;
self.copayerName = fc.credentials.copayerName;
self.requiresMultipleSignatures = fc.credentials.m > 1;
self.isShared = fc.credentials.n > 1;
self.walletName = fc.credentials.walletName;
self.walletId = fc.credentials.walletId;
self.isComplete = fc.isComplete();
self.canSign = fc.canSign();
2015-09-04 06:17:59 -07:00
self.isPrivKeyExternal = fc.isPrivKeyExternal();
self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted();
2015-09-04 06:17:59 -07:00
self.externalSource = fc.getPrivKeyExternalSourceName();
2015-11-04 10:45:33 -08:00
self.account = fc.credentials.account;
2016-06-14 08:28:21 -07:00
self.incorrectDerivation = fc.keyDerivationOk === false;
2015-11-04 10:45:33 -08:00
if (self.externalSource == 'trezor')
self.account++;
2015-03-06 07:00:10 -08:00
self.txps = [];
self.copayers = [];
2015-04-28 16:13:28 -07:00
self.updateColor();
2015-05-14 06:39:22 -07:00
self.updateAlias();
2015-10-30 14:34:34 -07:00
self.setAddressbook();
2015-09-15 05:41:42 -07:00
self.initGlidera();
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
self.initCoinbase();
2015-03-06 07:00:10 -08:00
2016-05-13 11:05:43 -07:00
self.hideBalance();
2015-12-10 09:52:42 -08:00
self.setCustomBWSFlag();
if (!self.isComplete) {
$log.debug('Wallet not complete BEFORE update... redirecting');
go.path('copayers');
} else {
if (go.is('copayers')) {
$log.debug('Wallet Complete BEFORE update... redirect to home');
go.walletHome();
}
}
2016-06-06 14:26:45 -07:00
profileService.needsBackup(fc, function(needsBackup) {
2016-02-16 09:37:34 -08:00
self.needsBackup = needsBackup;
self.openWallet(function() {
if (!self.isComplete) {
$log.debug('Wallet not complete after update... redirecting');
go.path('copayers');
} else {
if (go.is('copayers')) {
$log.debug('Wallet Complete after update... redirect to home');
go.walletHome();
}
}
});
2016-02-16 09:37:34 -08:00
});
2015-03-06 07:00:10 -08:00
});
};
2015-11-10 15:05:05 -08:00
self.setCustomBWSFlag = function() {
var defaults = configService.getDefaults();
var config = configService.getSync();
2015-11-17 06:10:09 -08:00
self.usingCustomBWS = config.bwsFor && config.bwsFor[self.walletId] && (config.bwsFor[self.walletId] != defaults.bws.url);
2015-11-10 15:05:05 -08:00
};
2015-12-05 15:50:31 -08:00
self.setTab = function(tab, reset, tries, switchState) {
2015-04-28 16:13:28 -07:00
tries = tries || 0;
// check if the whole menu item passed
if (typeof tab == 'object') {
if (tab.open) {
if (tab.link) {
self.tab = tab.link;
}
tab.open();
return;
} else {
return self.setTab(tab.link, reset, tries, switchState);
}
}
2015-04-28 16:13:28 -07:00
if (self.tab === tab && !reset)
return;
2015-05-04 08:23:43 -07:00
if (!document.getElementById('menu-' + tab) && ++tries < 5) {
2015-04-28 16:13:28 -07:00
return $timeout(function() {
self.setTab(tab, reset, tries, switchState);
2015-04-28 16:13:28 -07:00
}, 300);
}
2016-05-24 11:58:59 -07:00
if (!self.tab || !go.is('walletHome'))
self.tab = 'walletHome';
var changeTab = function() {
if (document.getElementById(self.tab)) {
document.getElementById(self.tab).className = 'tab-out tab-view ' + self.tab;
var old = document.getElementById('menu-' + self.tab);
if (old) {
old.className = '';
}
}
2015-04-23 10:12:32 -07:00
if (document.getElementById(tab)) {
document.getElementById(tab).className = 'tab-in tab-view ' + tab;
var newe = document.getElementById('menu-' + tab);
if (newe) {
newe.className = 'active';
}
2015-04-23 14:05:31 -07:00
}
self.tab = tab;
$rootScope.$emit('Local/TabChanged', tab);
};
2016-05-24 11:58:59 -07:00
if (switchState && !go.is('walletHome')) {
go.path('walletHome', function() {
changeTab();
});
return;
2015-09-07 07:14:09 -07:00
}
2015-04-23 10:12:32 -07:00
changeTab();
2015-04-23 09:12:30 -07:00
};
2015-05-19 10:10:47 -07:00
2015-12-23 13:05:22 -08:00
self.setSpendUnconfirmed = function(spendUnconfirmed) {
self.spendUnconfirmed = spendUnconfirmed || configService.getSync().wallet.spendUnconfirmed;
2016-02-23 08:19:37 -08:00
};
2015-07-24 08:11:07 -07:00
2015-03-06 07:00:10 -08:00
self.updateBalance = function() {
var fc = profileService.focusedClient;
$timeout(function() {
2016-06-13 07:44:58 -07:00
ongoingProcess.set('updatingBalance', true);
2015-03-06 07:00:10 -08:00
$log.debug('Updating Balance');
fc.getBalance(function(err, balance) {
2016-06-13 07:44:58 -07:00
ongoingProcess.set('updatingBalance', false);
2015-03-06 07:00:10 -08:00
if (err) {
self.handleError(err);
2015-03-06 07:00:10 -08:00
return;
}
$log.debug('Wallet Balance:', balance);
self.setBalance(balance);
});
});
};
self.updatePendingTxps = function() {
var fc = profileService.focusedClient;
$timeout(function() {
2016-06-14 04:39:34 -07:00
self.updating = true;
2015-03-06 07:00:10 -08:00
$log.debug('Updating PendingTxps');
2015-04-18 03:08:08 -07:00
fc.getTxProposals({}, function(err, txps) {
2016-06-14 04:39:34 -07:00
self.updating = false;
2015-03-06 07:00:10 -08:00
if (err) {
self.handleError(err);
2015-03-06 07:00:10 -08:00
} else {
$log.debug('Wallet PendingTxps:', txps);
self.setPendingTxps(txps);
}
$rootScope.$apply();
});
2016-05-30 09:26:48 -07:00
});
2015-03-06 07:00:10 -08:00
};
2016-01-16 15:04:01 -08:00
// This handles errors from BWS/index which normally
2015-11-26 08:25:38 -08:00
// trigger from async events (like updates).
// Debounce function avoids multiple popups
var _handleError = function(err) {
$log.warn('Client ERROR: ', err);
2016-01-22 13:16:50 -08:00
if (err instanceof errors.NOT_AUTHORIZED) {
self.notAuthorized = true;
go.walletHome();
2016-01-22 13:16:50 -08:00
} else if (err instanceof errors.NOT_FOUND) {
self.showErrorPopup(gettext('Could not access Wallet Service: Not found'));
2015-03-06 07:00:10 -08:00
} else {
var msg = ""
2015-04-27 10:18:22 -07:00
$scope.$emit('Local/ClientError', (err.error ? err.error : err));
2016-07-11 07:46:48 -07:00
var msg = bwcError.msg(err, gettext('Error at Wallet Service'));
self.showErrorPopup(msg);
2015-03-06 07:00:10 -08:00
}
};
2015-11-26 08:25:38 -08:00
self.handleError = lodash.debounce(_handleError, 1000);
self.openWallet = function(cb) {
2015-03-06 07:00:10 -08:00
var fc = profileService.focusedClient;
$timeout(function() {
2015-04-23 11:32:11 -07:00
$rootScope.$apply();
2016-06-14 04:39:34 -07:00
self.updating = true;
2015-04-14 12:06:04 -07:00
self.updateError = false;
2015-03-06 07:00:10 -08:00
fc.openWallet(function(err, walletStatus) {
2016-06-14 04:39:34 -07:00
self.updating = false;
2015-03-06 07:00:10 -08:00
if (err) {
2015-04-14 12:06:04 -07:00
self.updateError = true;
2015-03-06 07:00:10 -08:00
self.handleError(err);
return;
}
$log.debug('Wallet Opened');
2015-06-29 17:46:34 -07:00
self.updateAll(lodash.isObject(walletStatus) ? {
walletStatus: walletStatus,
cb: cb,
} : {
cb: cb
});
2015-03-06 07:00:10 -08:00
$rootScope.$apply();
});
});
};
self.setPendingTxps = function(txps) {
self.pendingTxProposalsCountForUs = 0;
var now = Math.floor(Date.now() / 1000);
2015-12-16 11:22:40 -08:00
/* Uncomment to test multiple outputs */
/*
var txp = {
message: 'test multi-output',
fee: 1000,
createdOn: new Date() / 1000,
outputs: []
};
function addOutput(n) {
txp.outputs.push({
amount: 600,
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
message: 'output #' + (Number(n) + 1)
});
};
lodash.times(150, addOutput);
txps.push(txp);
*/
2015-03-06 07:00:10 -08:00
lodash.each(txps, function(tx) {
2015-09-18 09:59:18 -07:00
2015-09-09 12:17:08 -07:00
tx = txFormatService.processTx(tx);
2015-03-06 07:00:10 -08:00
// no future transactions...
if (tx.createdOn > now)
tx.createdOn = now;
2015-03-06 07:00:10 -08:00
var action = lodash.find(tx.actions, {
copayerId: self.copayerId
});
if (!action && tx.status == 'pending') {
tx.pendingForUs = true;
}
if (action && action.type == 'accept') {
tx.statusForUs = 'accepted';
} else if (action && action.type == 'reject') {
tx.statusForUs = 'rejected';
} else {
tx.statusForUs = 'pending';
}
2015-06-18 07:17:35 -07:00
if (!tx.deleteLockTime)
tx.canBeRemoved = true;
2015-03-06 07:00:10 -08:00
if (tx.creatorId != self.copayerId) {
self.pendingTxProposalsCountForUs = self.pendingTxProposalsCountForUs + 1;
}
addonManager.formatPendingTxp(tx);
2015-03-06 07:00:10 -08:00
});
self.txps = txps;
};
2015-09-18 09:59:18 -07:00
var SAFE_CONFIRMATIONS = 6;
2015-11-06 08:06:08 -08:00
self.processNewTxs = function(txs) {
2015-07-17 10:30:55 -07:00
var config = configService.getSync().wallet.settings;
2015-07-13 09:31:05 -07:00
var now = Math.floor(Date.now() / 1000);
2015-11-06 08:06:08 -08:00
var txHistoryUnique = {};
var ret = [];
2015-09-18 09:59:18 -07:00
self.hasUnsafeConfirmed = false;
2015-11-06 08:06:08 -08:00
2015-03-06 07:00:10 -08:00
lodash.each(txs, function(tx) {
2015-09-09 12:17:08 -07:00
tx = txFormatService.processTx(tx);
2015-07-13 09:31:05 -07:00
// no future transactions...
if (tx.time > now)
tx.time = now;
2015-09-18 09:59:18 -07:00
if (tx.confirmations >= SAFE_CONFIRMATIONS) {
tx.safeConfirmed = SAFE_CONFIRMATIONS + '+';
} else {
tx.safeConfirmed = false;
self.hasUnsafeConfirmed = true;
}
2016-06-03 11:21:30 -07:00
if (tx.note) {
delete tx.note.encryptedEditedByName;
delete tx.note.encryptedBody;
}
2015-11-06 08:06:08 -08:00
if (!txHistoryUnique[tx.txid]) {
ret.push(tx);
txHistoryUnique[tx.txid] = true;
2015-10-22 06:14:57 -07:00
} else {
$log.debug('Ignoring duplicate TX in history: ' + tx.txid)
2015-03-06 07:00:10 -08:00
}
});
2015-11-06 08:06:08 -08:00
return ret;
2015-03-06 07:00:10 -08:00
};
2015-05-14 06:39:22 -07:00
self.updateAlias = function() {
var config = configService.getSync();
config.aliasFor = config.aliasFor || {};
self.alias = config.aliasFor[self.walletId];
var fc = profileService.focusedClient;
fc.alias = self.alias;
};
2015-03-06 07:00:10 -08:00
self.updateColor = function() {
var config = configService.getSync();
config.colorFor = config.colorFor || {};
2015-05-29 11:25:41 -07:00
self.backgroundColor = config.colorFor[self.walletId] || '#4A90E2';
2015-03-06 07:00:10 -08:00
var fc = profileService.focusedClient;
fc.backgroundColor = self.backgroundColor;
2015-12-01 12:16:39 -08:00
if (isCordova && StatusBar.isVisible) {
StatusBar.backgroundColorByHexString(fc.backgroundColor);
}
2015-03-06 07:00:10 -08:00
};
self.setBalance = function(balance) {
if (!balance) return;
var config = configService.getSync().wallet.settings;
var COIN = 1e8;
2015-08-11 13:11:40 -07:00
2015-03-06 07:00:10 -08:00
// Address with Balance
self.balanceByAddress = balance.byAddress;
2015-12-24 08:43:12 -08:00
// Spend unconfirmed funds
2015-08-11 13:45:57 -07:00
if (self.spendUnconfirmed) {
self.totalBalanceSat = balance.totalAmount;
self.lockedBalanceSat = balance.lockedAmount;
self.availableBalanceSat = balance.availableAmount;
2015-12-24 08:43:12 -08:00
self.totalBytesToSendMax = balance.totalBytesToSendMax;
2015-08-11 13:45:57 -07:00
self.pendingAmount = null;
} else {
self.totalBalanceSat = balance.totalConfirmedAmount;
self.lockedBalanceSat = balance.lockedConfirmedAmount;
self.availableBalanceSat = balance.availableConfirmedAmount;
2015-12-24 08:43:12 -08:00
self.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax;
2015-08-11 13:45:57 -07:00
self.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
}
2015-03-06 07:00:10 -08:00
// Selected unit
self.unitToSatoshi = config.unitToSatoshi;
self.satToUnit = 1 / self.unitToSatoshi;
self.unitName = config.unitName;
//STR
self.totalBalanceStr = profileService.formatAmount(self.totalBalanceSat) + ' ' + self.unitName;
self.lockedBalanceStr = profileService.formatAmount(self.lockedBalanceSat) + ' ' + self.unitName;
self.availableBalanceStr = profileService.formatAmount(self.availableBalanceSat) + ' ' + self.unitName;
2015-08-11 13:45:57 -07:00
if (self.pendingAmount) {
self.pendingAmountStr = profileService.formatAmount(self.pendingAmount) + ' ' + self.unitName;
} else {
self.pendingAmountStr = null;
}
2015-03-06 07:00:10 -08:00
self.alternativeName = config.alternativeName;
self.alternativeIsoCode = config.alternativeIsoCode;
// Check address
2015-06-29 17:46:34 -07:00
addressService.isUsed(self.walletId, balance.byAddress, function(err, used) {
if (used) {
2015-06-27 09:22:56 -07:00
$log.debug('Address used. Creating new');
$rootScope.$emit('Local/AddressIsUsed');
2015-06-27 09:22:56 -07:00
}
});
2015-03-06 07:00:10 -08:00
rateService.whenAvailable(function() {
2015-08-11 13:45:57 -07:00
var totalBalanceAlternative = rateService.toFiat(self.totalBalanceSat, self.alternativeIsoCode);
var lockedBalanceAlternative = rateService.toFiat(self.lockedBalanceSat, self.alternativeIsoCode);
2015-03-06 07:00:10 -08:00
var alternativeConversionRate = rateService.toFiat(100000000, self.alternativeIsoCode);
2016-07-14 07:04:12 -07:00
self.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative);
self.lockedBalanceAlternative = $filter('formatFiatAmount')(lockedBalanceAlternative);
self.alternativeConversionRate = $filter('formatFiatAmount')(alternativeConversionRate);
2015-03-06 07:00:10 -08:00
self.alternativeBalanceAvailable = true;
self.isRateAvailable = true;
$rootScope.$apply();
});
if (!rateService.isAvailable()) {
$rootScope.$apply();
}
};
2016-02-23 08:19:37 -08:00
self.removeAndMarkSoftConfirmedTx = function(txs) {
return lodash.filter(txs, function(tx) {
2015-10-23 09:26:59 -07:00
if (tx.confirmations >= SOFT_CONFIRMATION_LIMIT)
return tx;
2016-02-23 08:19:37 -08:00
tx.recent = true;
});
}
2016-02-09 10:10:25 -08:00
2016-02-22 12:33:41 -08:00
self.showMore = function() {
2015-11-06 08:06:08 -08:00
$timeout(function() {
2016-02-23 06:29:11 -08:00
if (self.isSearching) {
2016-02-25 11:03:03 -08:00
self.txHistorySearchResults = self.result.slice(0, self.nextTxHistory);
$log.debug('Total txs: ', self.txHistorySearchResults.length + '/' + self.result.length);
if (self.txHistorySearchResults.length >= self.result.length)
self.historyShowMore = false;
} else {
self.txHistory = self.completeHistory.slice(0, self.nextTxHistory);
$log.debug('Total txs: ', self.txHistory.length + '/' + self.completeHistory.length);
if (self.txHistory.length >= self.completeHistory.length)
2016-02-25 11:03:03 -08:00
self.historyShowMore = false;
}
self.nextTxHistory += self.historyShowMoreLimit;
$scope.$broadcast('scroll.infiniteScrollComplete');
2015-11-10 15:14:06 -08:00
}, 100);
2015-11-06 08:06:08 -08:00
};
2015-10-08 10:29:35 -07:00
2015-10-22 08:31:54 -07:00
2015-03-06 07:00:10 -08:00
2016-05-18 11:15:14 -07:00
self.toggleLeftMenu = function() {
2016-02-23 06:12:49 -08:00
profileService.isDisclaimerAccepted(function(val) {
2016-05-18 11:15:14 -07:00
if (val) go.toggleLeftMenu();
2016-02-23 06:12:49 -08:00
else
2016-02-22 14:32:24 -08:00
$log.debug('Disclaimer not accepted, cannot open menu');
});
2015-03-06 07:00:10 -08:00
};
2015-09-05 10:30:02 -07:00
self.initGlidera = function(accessToken) {
2015-09-11 09:11:41 -07:00
self.glideraEnabled = configService.getSync().glidera.enabled;
self.glideraTestnet = configService.getSync().glidera.testnet;
var network = self.glideraTestnet ? 'testnet' : 'livenet';
2015-09-11 09:11:41 -07:00
self.glideraToken = null;
self.glideraError = null;
self.glideraPermissions = null;
self.glideraEmail = null;
self.glideraPersonalInfo = null;
self.glideraTxs = null;
self.glideraStatus = null;
2015-10-05 11:06:53 -07:00
if (!self.glideraEnabled) return;
2015-09-11 09:11:41 -07:00
glideraService.setCredentials(network);
2015-09-05 10:30:02 -07:00
var getToken = function(cb) {
if (accessToken) {
cb(null, accessToken);
} else {
2015-09-11 09:11:41 -07:00
storageService.getGlideraToken(network, cb);
2015-09-05 10:30:02 -07:00
}
};
getToken(function(err, accessToken) {
if (err || !accessToken) return;
2015-09-02 12:02:40 -07:00
else {
2015-09-07 07:14:09 -07:00
glideraService.getAccessTokenPermissions(accessToken, function(err, p) {
2015-09-05 10:30:02 -07:00
if (err) {
self.glideraError = err;
2015-09-18 09:59:18 -07:00
} else {
2015-09-07 07:14:09 -07:00
self.glideraToken = accessToken;
2015-09-05 10:30:02 -07:00
self.glideraPermissions = p;
2015-09-18 09:59:18 -07:00
self.updateGlidera({
fullUpdate: true
});
2015-09-05 10:30:02 -07:00
}
2015-09-02 12:02:40 -07:00
});
}
2015-08-28 14:23:24 -07:00
});
};
self.updateGlidera = function(opts) {
if (!self.glideraToken || !self.glideraPermissions) return;
var accessToken = self.glideraToken;
var permissions = self.glideraPermissions;
opts = opts || {};
2015-09-08 08:04:27 -07:00
glideraService.getStatus(accessToken, function(err, data) {
self.glideraStatus = data;
});
2015-09-08 13:36:08 -07:00
glideraService.getLimits(accessToken, function(err, limits) {
self.glideraLimits = limits;
});
if (permissions.transaction_history) {
glideraService.getTransactions(accessToken, function(err, data) {
self.glideraTxs = data;
});
}
2015-09-18 09:59:18 -07:00
if (permissions.view_email_address && opts.fullUpdate) {
2015-09-05 10:30:02 -07:00
glideraService.getEmail(accessToken, function(err, data) {
self.glideraEmail = data.email;
});
}
if (permissions.personal_info && opts.fullUpdate) {
2015-09-05 10:30:02 -07:00
glideraService.getPersonalInfo(accessToken, function(err, data) {
self.glideraPersonalInfo = data;
});
}
2015-09-05 10:30:02 -07:00
};
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
self.initCoinbase = function(accessToken) {
self.coinbaseEnabled = configService.getSync().coinbase.enabled;
self.coinbaseTestnet = configService.getSync().coinbase.testnet;
var network = self.coinbaseTestnet ? 'testnet' : 'livenet';
self.coinbaseToken = null;
self.coinbaseError = null;
self.coinbasePermissions = null;
self.coinbaseEmail = null;
self.coinbasePersonalInfo = null;
self.coinbaseTxs = null;
self.coinbaseStatus = null;
if (!self.coinbaseEnabled) return;
coinbaseService.setCredentials(network);
var getToken = function(cb) {
if (accessToken) {
cb(null, accessToken);
} else {
storageService.getCoinbaseToken(network, cb);
}
};
getToken(function(err, accessToken) {
if (err || !accessToken) return;
else {
coinbaseService.getAccounts(accessToken, function(err, a) {
if (err) {
self.coinbaseError = err;
if (err.errors[0] && err.errors[0].id == 'expired_token') {
self.refreshCoinbaseToken();
}
} else {
self.coinbaseToken = accessToken;
lodash.each(a.data, function(account) {
if (account.primary && account.type == 'wallet') {
self.coinbaseAccount = account;
self.updateCoinbase();
}
});
}
});
}
});
};
self.updateCoinbase = lodash.debounce(function(opts) {
if (!self.coinbaseToken || !self.coinbaseAccount) return;
var accessToken = self.coinbaseToken;
var accountId = self.coinbaseAccount.id;
opts = opts || {};
if (opts.updateAccount) {
coinbaseService.getAccount(accessToken, accountId, function(err, a) {
if (err) {
self.coinbaseError = err;
if (err.errors[0] && err.errors[0].id == 'expired_token') {
self.refreshCoinbaseToken();
}
return;
}
self.coinbaseAccount = a.data;
});
}
coinbaseService.getCurrentUser(accessToken, function(err, u) {
if (err) {
self.coinbaseError = err;
if (err.errors[0] && err.errors[0].id == 'expired_token') {
self.refreshCoinbaseToken();
}
return;
}
self.coinbaseUser = u.data;
});
coinbaseService.getPendingTransactions(function(err, txs) {
self.coinbasePendingTransactions = lodash.isEmpty(txs) ? null : txs;
lodash.forEach(txs, function(dataFromStorage, txId) {
if ((dataFromStorage.type == 'sell' && dataFromStorage.status == 'completed') ||
2016-05-20 07:37:13 -07:00
(dataFromStorage.type == 'buy' && dataFromStorage.status == 'completed') ||
dataFromStorage.status == 'error' ||
(dataFromStorage.type == 'send' && dataFromStorage.status == 'completed')) return;
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
coinbaseService.getTransaction(accessToken, accountId, txId, function(err, tx) {
if (err) {
if (err.errors[0] && err.errors[0].id == 'expired_token') {
self.refreshCoinbaseToken();
return;
}
2016-05-20 07:37:13 -07:00
coinbaseService.savePendingTransaction(dataFromStorage, {
status: 'error',
error: err
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
if (err) $log.debug(err);
});
return;
}
_updateCoinbasePendingTransactions(dataFromStorage, tx.data);
self.coinbasePendingTransactions[txId] = dataFromStorage;
if (tx.data.type == 'send' && tx.data.status == 'completed' && tx.data.from) {
coinbaseService.sellPrice(accessToken, dataFromStorage.sell_price_currency, function(err, s) {
if (err) {
if (err.errors[0] && err.errors[0].id == 'expired_token') {
self.refreshCoinbaseToken();
return;
}
2016-05-20 07:37:13 -07:00
coinbaseService.savePendingTransaction(dataFromStorage, {
status: 'error',
error: err
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
if (err) $log.debug(err);
});
return;
}
var newSellPrice = s.data.amount;
var variance = Math.abs((newSellPrice - dataFromStorage.sell_price_amount) / dataFromStorage.sell_price_amount * 100);
if (variance < dataFromStorage.price_sensitivity.value) {
self.sellPending(tx.data);
} else {
2016-05-20 07:37:13 -07:00
var error = {
errors: [{
message: 'Price falls over the selected percentage'
}]
};
coinbaseService.savePendingTransaction(dataFromStorage, {
status: 'error',
error: error
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
if (err) $log.debug(err);
});
}
});
} else if (tx.data.type == 'buy' && tx.data.status == 'completed' && tx.data.buy) {
self.sendToCopay(dataFromStorage);
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
} else {
coinbaseService.savePendingTransaction(dataFromStorage, {}, function(err) {
if (err) $log.debug(err);
});
}
});
});
});
}, 1000);
2016-05-20 07:37:13 -07:00
var _updateCoinbasePendingTransactions = function(obj /*, …*/ ) {
for (var i = 1; i < arguments.length; i++) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
for (var prop in arguments[i]) {
var val = arguments[i][prop];
if (typeof val == "object")
_updateCoinbasePendingTransactions(obj[prop], val);
else
obj[prop] = val ? val : obj[prop];
}
}
return obj;
};
self.refreshCoinbaseToken = function() {
var network = self.coinbaseTestnet ? 'testnet' : 'livenet';
storageService.getCoinbaseRefreshToken(network, function(err, refreshToken) {
if (!refreshToken) return;
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
coinbaseService.refreshToken(refreshToken, function(err, data) {
if (err) {
self.coinbaseError = err;
} else if (data && data.access_token && data.refresh_token) {
storageService.setCoinbaseToken(network, data.access_token, function() {
storageService.setCoinbaseRefreshToken(network, data.refresh_token, function() {
$timeout(function() {
self.initCoinbase(data.access_token);
}, 100);
});
});
}
});
});
};
self.sendToCopay = function(tx) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
if (!tx) return;
var data = {
to: tx.toAddr,
amount: tx.amount.amount,
currency: tx.amount.currency,
description: 'To Copay Wallet'
};
coinbaseService.sendTo(self.coinbaseToken, self.coinbaseAccount.id, data, function(err, res) {
if (err) {
if (err.errors[0] && err.errors[0].id == 'expired_token') {
self.refreshCoinbaseToken();
return;
}
2016-05-20 07:37:13 -07:00
coinbaseService.savePendingTransaction(tx, {
status: 'error',
error: err
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
if (err) $log.debug(err);
});
} else {
if (!res.data.id) {
2016-05-20 07:37:13 -07:00
coinbaseService.savePendingTransaction(tx, {
status: 'error',
error: err
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
if (err) $log.debug(err);
});
return;
}
coinbaseService.getTransaction(self.coinbaseToken, self.coinbaseAccount.id, res.data.id, function(err, sendTx) {
2016-05-20 07:37:13 -07:00
coinbaseService.savePendingTransaction(tx, {
remove: true
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
coinbaseService.savePendingTransaction(sendTx.data, {}, function(err) {
$timeout(function() {
2016-05-20 07:37:13 -07:00
self.updateCoinbase({
updateAccount: true
});
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
}, 1000);
});
});
});
}
});
};
self.sellPending = function(tx) {
if (!tx) return;
var data = tx.amount;
data['commit'] = true;
coinbaseService.sellRequest(self.coinbaseToken, self.coinbaseAccount.id, data, function(err, res) {
if (err) {
if (err.errors[0] && err.errors[0].id == 'expired_token') {
self.refreshCoinbaseToken();
return;
}
2016-05-20 07:37:13 -07:00
coinbaseService.savePendingTransaction(tx, {
status: 'error',
error: err
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
if (err) $log.debug(err);
});
} else {
if (!res.data.transaction) {
2016-05-20 07:37:13 -07:00
coinbaseService.savePendingTransaction(tx, {
status: 'error',
error: err
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
if (err) $log.debug(err);
});
return;
}
2016-05-20 07:37:13 -07:00
coinbaseService.savePendingTransaction(tx, {
remove: true
}, function(err) {
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
coinbaseService.getTransaction(self.coinbaseToken, self.coinbaseAccount.id, res.data.transaction.id, function(err, updatedTx) {
coinbaseService.savePendingTransaction(updatedTx.data, {}, function(err) {
if (err) $log.debug(err);
$timeout(function() {
2016-05-20 07:37:13 -07:00
self.updateCoinbase({
updateAccount: true
});
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
}, 1000);
});
});
});
}
});
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
};
2016-06-14 08:28:21 -07:00
self.isInFocus = function(walletId) {
var fc = profileService.focusedClient;
return fc && fc.credentials.walletId == walletId;
};
2015-11-02 07:04:18 -08:00
self.setAddressbook = function(ab) {
if (ab) {
self.addressbook = ab;
return;
}
2015-10-30 14:34:34 -07:00
addressbookService.list(function(err, ab) {
if (err) {
$log.error('Error getting the addressbook');
return;
}
self.addressbook = ab;
2015-11-02 05:50:58 -08:00
});
2015-10-30 14:34:34 -07:00
};
2015-11-23 12:53:42 -08:00
$rootScope.$on('$stateChangeSuccess', function(ev, to, toParams, from, fromParams) {
self.prevState = from.name || 'walletHome';
2015-11-24 05:21:29 -08:00
self.tab = 'walletHome';
2015-11-23 12:53:42 -08:00
});
2016-06-14 08:28:21 -07:00
$rootScope.$on('Local/ValidatingWalletEnded', function(ev, walletId, isOK) {
2016-06-21 07:17:42 -07:00
2016-06-14 08:28:21 -07:00
if (self.isInFocus(walletId)) {
// NOTE: If the user changed the wallet, the flag is already turn off.
2016-06-14 08:28:21 -07:00
self.incorrectDerivation = isOK === false;
}
2016-06-13 05:50:37 -07:00
});
2015-10-30 08:57:38 -07:00
$rootScope.$on('Local/ClearHistory', function(event) {
2015-10-30 08:55:41 -07:00
$log.debug('The wallet transaction history has been deleted');
self.txHistory = self.completeHistory = self.txHistorySearchResults = [];
self.debounceUpdateHistory();
2015-10-30 08:47:37 -07:00
});
2015-11-02 07:04:18 -08:00
$rootScope.$on('Local/AddressbookUpdated', function(event, ab) {
self.setAddressbook(ab);
2015-10-30 14:34:34 -07:00
});
2015-03-06 07:00:10 -08:00
// UX event handlers
$rootScope.$on('Local/ColorUpdated', function(event) {
self.updateColor();
2015-04-27 09:11:32 -07:00
$timeout(function() {
$rootScope.$apply();
});
2015-03-06 07:00:10 -08:00
});
2015-05-14 06:39:22 -07:00
$rootScope.$on('Local/AliasUpdated', function(event) {
self.updateAlias();
$timeout(function() {
$rootScope.$apply();
});
});
2015-12-23 13:05:22 -08:00
$rootScope.$on('Local/SpendUnconfirmedUpdated', function(event, spendUnconfirmed) {
self.setSpendUnconfirmed(spendUnconfirmed);
2015-08-11 13:45:57 -07:00
self.updateAll();
2015-08-03 16:39:09 -07:00
});
2015-09-11 09:11:41 -07:00
$rootScope.$on('Local/GlideraUpdated', function(event, accessToken) {
2015-09-05 10:30:02 -07:00
self.initGlidera(accessToken);
});
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
$rootScope.$on('Local/CoinbaseUpdated', function(event, accessToken) {
self.initCoinbase(accessToken);
});
$rootScope.$on('Local/GlideraTx', function(event, accessToken, permissions) {
self.updateGlidera();
2015-08-28 14:23:24 -07:00
});
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 <[email protected]> * Fix calls if token expired
2016-04-13 10:08:03 -07:00
$rootScope.$on('Local/CoinbaseTx', function(event) {
self.updateCoinbase({
updateAccount: true
});
});
2015-09-07 13:43:55 -07:00
$rootScope.$on('Local/GlideraError', function(event) {
self.debouncedUpdate();
});
2015-04-25 08:37:04 -07:00
$rootScope.$on('Local/UnitSettingUpdated', function(event) {
2015-11-18 05:24:15 -08:00
self.updateAll({
triggerTxUpdate: true,
});
2015-05-19 10:10:47 -07:00
});
$rootScope.$on('Local/WalletCompleted', function(event, walletId) {
2016-06-14 08:28:21 -07:00
if (self.isInFocus(walletId)) {
// reset main wallet variables
self.setFocusedWallet();
go.walletHome();
}
2015-03-06 07:00:10 -08:00
});
self.debouncedUpdate = function() {
var now = Date.now();
var oneHr = 1000 * 60 * 60;
if (!self.lastUpdate || (now - self.lastUpdate) > oneHr) {
self.updateAll({
quiet: true,
triggerTxUpdate: true
});
}
};
2015-04-28 15:26:22 -07:00
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/Resume', function(event) {
$log.debug('### Resume event');
profileService.isDisclaimerAccepted(function(v) {
if (!v) {
$log.debug('Disclaimer not accepted, resume to home');
go.path('disclaimer');
}
});
self.debouncedUpdate();
2015-03-06 07:00:10 -08:00
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/BackupDone', function(event, walletId) {
self.needsBackup = false;
$log.debug('Backup done');
storageService.setBackupFlag(walletId || self.walletId, function(err) {
$log.debug('Backup stored');
});
2015-03-06 07:00:10 -08:00
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/DeviceError', function(event, err) {
self.showErrorPopup(err, function() {
if (isCordova && navigator && navigator.app) {
navigator.app.exitApp();
}
2015-04-18 03:23:11 -07:00
});
2015-03-06 07:00:10 -08:00
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/WalletImported', function(event, walletId) {
2016-08-17 20:27:23 -07:00
console.log('[index.js:1063] walletImported'); //TODO
return;
2016-06-13 07:44:58 -07:00
self.needsBackup = false;
storageService.setBackupFlag(walletId, function() {
$log.debug('Backup done stored');
addressService.expireAddress(walletId, function(err) {
$timeout(function() {
self.txHistory = self.completeHistory = self.txHistorySearchResults = [];
storageService.removeTxHistory(walletId, function() {
self.startScan(walletId);
});
}, 500);
});
});
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('NewIncomingTx', function() {
self.newTx = true;
2015-07-06 06:40:40 -07:00
self.updateAll({
walletStatus: null,
2016-06-13 07:44:58 -07:00
untilItChanges: true,
2015-07-06 06:40:40 -07:00
triggerTxUpdate: true,
});
2016-06-13 07:44:58 -07:00
});
$rootScope.$on('NewBlock', function() {
if (self.glideraEnabled) {
$timeout(function() {
self.updateGlidera();
});
2015-08-12 04:57:44 -07:00
}
2016-06-13 07:44:58 -07:00
if (self.coinbaseEnabled) {
$timeout(function() {
self.updateCoinbase();
});
}
if (self.pendingAmount) {
self.updateAll({
walletStatus: null,
untilItChanges: null,
triggerTxUpdate: true,
});
} else if (self.hasUnsafeConfirmed) {
$log.debug('Wallet has transactions with few confirmations. Updating.')
if (self.network == 'testnet') {
self.throttledUpdateHistory();
} else {
self.debounceUpdateHistory();
}
}
});
2015-08-12 04:57:44 -07:00
2016-06-13 07:44:58 -07:00
$rootScope.$on('BalanceUpdated', function(e, n) {
self.setBalance(n.data);
});
2015-05-29 08:39:17 -07:00
2016-06-13 07:44:58 -07:00
//untilItChange TRUE
lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName) {
$rootScope.$on(eventName, function(event) {
self.newTx = true;
self.updateAll({
walletStatus: null,
untilItChanges: true,
triggerTxUpdate: true,
});
2015-03-06 07:00:10 -08:00
});
});
2016-06-13 07:44:58 -07:00
//untilItChange FALSE
lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty',
'Local/GlideraTx'
], function(eventName) {
$rootScope.$on(eventName, function(event) {
self.updateAll({
walletStatus: null,
untilItChanges: null,
triggerTxUpdate: true,
});
});
});
2016-06-13 07:44:58 -07:00
//untilItChange Maybe
$rootScope.$on('Local/TxProposalAction', function(event, untilItChanges) {
self.newTx = untilItChanges;
self.updateAll({
walletStatus: null,
2016-06-13 07:44:58 -07:00
untilItChanges: untilItChanges,
triggerTxUpdate: true,
2015-03-06 07:00:10 -08:00
});
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('ScanFinished', function() {
$log.debug('Scan Finished. Updating history');
storageService.removeTxHistory(self.walletId, function() {
self.updateAll({
walletStatus: null,
triggerTxUpdate: true,
});
});
2015-03-06 07:00:10 -08:00
});
2016-06-13 07:44:58 -07:00
lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy'], function(eventName) {
$rootScope.$on(eventName, function() {
var f = function() {
2016-06-14 04:39:34 -07:00
if (self.updating) {
2016-06-13 07:44:58 -07:00
return $timeout(f, 200);
};
self.updatePendingTxps();
};
f();
});
});
2016-03-09 11:10:44 -08:00
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/NoWallets', function(event) {
$timeout(function() {
self.hasProfile = true;
self.noFocusedWallet = true;
self.isComplete = null;
self.walletName = null;
uxLanguage.update();
2015-12-05 15:50:31 -08:00
});
2015-03-06 07:00:10 -08:00
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/NewFocusedWallet', function() {
2016-08-12 07:10:26 -07:00
console.log('[index.js.1200:NewFocusedWallet:] TODO'); //TODO
return;
2016-06-13 07:44:58 -07:00
uxLanguage.update();
self.setFocusedWallet();
self.updateHistory();
storageService.getCleanAndScanAddresses(function(err, walletId) {
2016-06-13 07:44:58 -07:00
if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan ', walletId);
addressService.expireAddress(walletId, function(err) {
self.startScan(walletId);
});
storageService.removeCleanAndScanAddresses(function() {
$rootScope.$emit('Local/NewFocusedWalletReady');
});
} else {
$rootScope.$emit('Local/NewFocusedWalletReady');
2016-06-13 07:44:58 -07:00
}
});
2015-04-23 10:37:44 -07:00
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/SetTab', function(event, tab, reset) {
self.setTab(tab, reset);
});
2016-07-11 06:06:09 -07:00
$rootScope.$on('disclaimerAccepted', function(event) {
$scope.isDisclaimerAccepted = true;
});
2016-06-23 12:18:18 -07:00
$rootScope.$on('Local/WindowResize', function() {
self.physicalScreenWidth = ((window.innerWidth > 0) ? window.innerWidth : screen.width);
2016-06-23 12:18:18 -07:00
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) {
2016-06-13 07:44:58 -07:00
function openConfirmationPopup(txp, cb) {
var config = configService.getSync();
$scope.color = config.colorFor[txp.walletId] || '#4A90E2';
$scope.tx = txFormatService.processTx(txp);
2016-06-13 07:44:58 -07:00
self.confirmationPopup = $ionicPopup.show({
templateUrl: 'views/includes/confirm-tx.html',
scope: $scope,
});
2016-06-13 07:44:58 -07:00
$scope.processFee = function(amount, fee) {
var walletSettings = configService.getSync().wallet.settings;
var feeAlternativeIsoCode = walletSettings.alternativeIsoCode;
2016-06-13 07:44:58 -07:00
$scope.feeLevel = feeService.feeOpts[feeService.getCurrentFeeLevel()];
$scope.feeAlternativeStr = parseFloat((rateService.toFiat(fee, feeAlternativeIsoCode)).toFixed(2), 10) + ' ' + feeAlternativeIsoCode;
$scope.feeRateStr = (fee / (amount + fee) * 100).toFixed(2) + '%';
};
2016-06-13 07:44:58 -07:00
$scope.cancel = function() {
return cb();
};
2016-06-13 07:44:58 -07:00
$scope.accept = function() {
return cb(true);
};
}
2016-06-13 07:44:58 -07:00
openConfirmationPopup(txp, function(accept) {
self.confirmationPopup.close();
return cb(accept);
});
});
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
2016-06-13 07:44:58 -07:00
function openPasswordPopup(isSetup, cb) {
$scope.data = {};
$scope.data.password = null;
$scope.isSetup = isSetup;
$scope.isVerification = false;
$scope.loading = false;
var pass = null;
2016-06-13 07:44:58 -07:00
self.passwordPopup = $ionicPopup.show({
templateUrl: 'views/includes/password.html',
scope: $scope,
});
2016-06-13 07:44:58 -07:00
$scope.cancel = function() {
return cb('No spending password given');
};
$scope.keyPress = function(event) {
if (!$scope.data.password || $scope.loading) return;
if (event.keyCode == 13) $scope.set();
}
2016-06-13 07:44:58 -07:00
$scope.set = function() {
$scope.loading = true;
$scope.error = null;
2016-06-13 07:44:58 -07:00
$timeout(function() {
if (isSetup && !$scope.isVerification) {
$scope.loading = false;
$scope.isVerification = true;
pass = $scope.data.password;
$scope.data.password = null;
return;
}
if (isSetup && pass != $scope.data.password) {
$scope.loading = false;
$scope.error = gettext('Spending Passwords do not match');
$scope.isVerification = false;
$scope.data.password = null;
pass = null;
return;
}
return cb(null, $scope.data.password);
}, 100);
};
2015-03-06 07:00:10 -08:00
};
2016-06-13 07:44:58 -07:00
openPasswordPopup(isSetup, function(err, pass) {
self.passwordPopup.close();
return cb(err, pass);
});
2015-03-06 07:00:10 -08:00
2016-06-13 07:44:58 -07:00
});
2016-06-06 14:26:45 -07:00
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/EmailUpdated', function(event, email) {
self.preferences.email = email;
});
2016-06-13 07:44:58 -07:00
lodash.each(['NewCopayer', 'CopayerUpdated'], function(eventName) {
$rootScope.$on(eventName, function() {
2016-08-17 20:27:23 -07:00
console.log('[index.js:1324] NewCopayer, CopayerUpdated'); //TODO
return;
2016-06-13 07:44:58 -07:00
// Re try to open wallet (will triggers)
self.setFocusedWallet();
});
2015-03-06 07:00:10 -08:00
});
2015-11-10 15:05:05 -08:00
2016-06-13 07:44:58 -07:00
$rootScope.$on('Local/NewEncryptionSetting', function() {
var fc = profileService.focusedClient;
self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted();
$timeout(function() {
$rootScope.$apply();
});
2015-11-10 15:05:05 -08:00
});
2016-06-13 07:44:58 -07:00
/* Start setup */
lodash.assign(self, vanillaScope);
openURLService.init();
2015-11-02 07:04:18 -08:00
});