2016-08-15 10:25:43 -03:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2018-08-08 17:10:47 +02:00
|
|
|
|
angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, sendFlowService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService) {
|
2016-09-08 12:13:37 -03:00
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
var HISTORY_SHOW_LIMIT = 10;
|
2016-09-29 19:04:52 -03:00
|
|
|
|
var currentTxHistoryPage = 0;
|
|
|
|
|
|
var listeners = [];
|
2016-08-23 17:31:50 -03:00
|
|
|
|
$scope.txps = [];
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.completeTxHistory = [];
|
|
|
|
|
|
$scope.openTxpModal = txpModalService.open;
|
2016-10-10 15:19:33 -03:00
|
|
|
|
$scope.isCordova = platformInfo.isCordova;
|
2016-10-14 10:24:20 -03:00
|
|
|
|
$scope.isAndroid = platformInfo.isAndroid;
|
2016-11-11 16:52:41 -05:00
|
|
|
|
$scope.isIOS = platformInfo.isIOS;
|
2016-08-23 17:31:50 -03:00
|
|
|
|
|
2018-07-25 16:17:42 +09:00
|
|
|
|
var channel = "ga";
|
|
|
|
|
|
if (platformInfo.isCordova) {
|
|
|
|
|
|
channel = "firebase";
|
2018-07-13 17:19:31 +09:00
|
|
|
|
}
|
|
|
|
|
|
var log = new window.BitAnalytics.LogEvent("wallet_details_open", [], [channel]);
|
|
|
|
|
|
window.BitAnalytics.LogEventHandlers.postEvent(log);
|
|
|
|
|
|
|
2016-11-14 18:26:45 -05:00
|
|
|
|
$scope.amountIsCollapsible = !$scope.isAndroid;
|
|
|
|
|
|
|
2016-09-05 14:59:11 -03:00
|
|
|
|
$scope.openExternalLink = function(url, target) {
|
|
|
|
|
|
externalLinkService.open(url, target);
|
|
|
|
|
|
};
|
2016-08-23 17:31:50 -03:00
|
|
|
|
|
|
|
|
|
|
var setPendingTxps = function(txps) {
|
2016-09-20 10:02:28 -03:00
|
|
|
|
|
|
|
|
|
|
/* Uncomment to test multiple outputs */
|
|
|
|
|
|
|
|
|
|
|
|
// var txp = {
|
|
|
|
|
|
// message: 'test multi-output',
|
|
|
|
|
|
// fee: 1000,
|
|
|
|
|
|
// createdOn: new Date() / 1000,
|
|
|
|
|
|
// outputs: [],
|
2016-09-29 19:04:52 -03:00
|
|
|
|
// wallet: $scope.wallet
|
2016-09-20 10:02:28 -03:00
|
|
|
|
// };
|
|
|
|
|
|
//
|
|
|
|
|
|
// function addOutput(n) {
|
|
|
|
|
|
// txp.outputs.push({
|
|
|
|
|
|
// amount: 600,
|
|
|
|
|
|
// toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
|
|
|
|
|
|
// message: 'output #' + (Number(n) + 1)
|
|
|
|
|
|
// });
|
|
|
|
|
|
// };
|
|
|
|
|
|
// lodash.times(15, addOutput);
|
|
|
|
|
|
// txps.push(txp);
|
|
|
|
|
|
|
2016-08-23 17:31:50 -03:00
|
|
|
|
if (!txps) {
|
|
|
|
|
|
$scope.txps = [];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
$scope.txps = lodash.sortBy(txps, 'createdOn').reverse();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-06-22 13:44:49 -03:00
|
|
|
|
var analyzeUtxosDone;
|
|
|
|
|
|
|
|
|
|
|
|
var analyzeUtxos = function() {
|
|
|
|
|
|
if (analyzeUtxosDone) return;
|
|
|
|
|
|
|
2017-08-29 15:47:39 -03:00
|
|
|
|
feeService.getFeeLevels($scope.wallet.coin, function(err, levels) {
|
2017-06-23 12:11:54 -03:00
|
|
|
|
if (err) return;
|
2017-07-07 17:58:24 -03:00
|
|
|
|
walletService.getLowUtxos($scope.wallet, levels, function(err, resp) {
|
2017-06-23 12:11:54 -03:00
|
|
|
|
if (err || !resp) return;
|
2017-06-22 13:44:49 -03:00
|
|
|
|
analyzeUtxosDone = true;
|
|
|
|
|
|
$scope.lowUtxosWarning = resp.warning;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
var updateStatus = function(force) {
|
2016-08-23 17:31:50 -03:00
|
|
|
|
$scope.updatingStatus = true;
|
2016-11-14 12:53:43 -03:00
|
|
|
|
$scope.updateStatusError = null;
|
2016-09-08 12:13:37 -03:00
|
|
|
|
$scope.walletNotRegistered = false;
|
2016-08-23 17:31:50 -03:00
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
walletService.getStatus($scope.wallet, {
|
2016-08-23 17:31:50 -03:00
|
|
|
|
force: !!force,
|
|
|
|
|
|
}, function(err, status) {
|
|
|
|
|
|
$scope.updatingStatus = false;
|
|
|
|
|
|
if (err) {
|
2016-09-08 12:13:37 -03:00
|
|
|
|
if (err === 'WALLET_NOT_REGISTERED') {
|
|
|
|
|
|
$scope.walletNotRegistered = true;
|
|
|
|
|
|
} else {
|
2017-01-16 16:00:09 -03:00
|
|
|
|
$scope.updateStatusError = bwcError.msg(err, gettextCatalog.getString('Could not update wallet'));
|
2016-09-08 12:13:37 -03:00
|
|
|
|
}
|
2016-08-23 17:31:50 -03:00
|
|
|
|
$scope.status = null;
|
2016-11-14 12:53:43 -03:00
|
|
|
|
} else {
|
|
|
|
|
|
setPendingTxps(status.pendingTxps);
|
2018-02-08 21:07:24 -04:00
|
|
|
|
if (!$scope.status || status.balance.totalAmount != $scope.status.balance.totalAmount) {
|
2018-02-06 17:50:25 -04:00
|
|
|
|
$scope.status = status;
|
|
|
|
|
|
}
|
2016-08-23 17:31:50 -03:00
|
|
|
|
}
|
2018-02-06 17:50:25 -04:00
|
|
|
|
|
2016-08-24 17:54:01 -03:00
|
|
|
|
$timeout(function() {
|
2016-08-23 17:45:23 -03:00
|
|
|
|
$scope.$apply();
|
2016-11-14 12:53:43 -03:00
|
|
|
|
});
|
2016-08-24 17:54:01 -03:00
|
|
|
|
|
2017-06-22 13:44:49 -03:00
|
|
|
|
analyzeUtxos();
|
|
|
|
|
|
|
2016-08-23 17:31:50 -03:00
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$scope.openSearchModal = function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.color = $scope.wallet.color;
|
2017-05-30 16:19:06 -03:00
|
|
|
|
$scope.isSearching = true;
|
|
|
|
|
|
$scope.txHistorySearchResults = [];
|
|
|
|
|
|
$scope.filteredTxHistory = [];
|
2016-08-15 10:25:43 -03:00
|
|
|
|
|
|
|
|
|
|
$ionicModal.fromTemplateUrl('views/modals/search.html', {
|
|
|
|
|
|
scope: $scope,
|
|
|
|
|
|
focusFirstInput: true
|
|
|
|
|
|
}).then(function(modal) {
|
|
|
|
|
|
$scope.searchModal = modal;
|
|
|
|
|
|
$scope.searchModal.show();
|
|
|
|
|
|
});
|
2016-09-02 14:29:34 -03:00
|
|
|
|
|
|
|
|
|
|
$scope.close = function() {
|
2017-05-30 16:19:06 -03:00
|
|
|
|
$scope.isSearching = false;
|
2016-09-02 14:29:34 -03:00
|
|
|
|
$scope.searchModal.hide();
|
2016-10-21 19:13:14 -04:00
|
|
|
|
};
|
2016-11-04 17:15:18 -03:00
|
|
|
|
|
|
|
|
|
|
$scope.openTx = function(tx) {
|
|
|
|
|
|
$ionicHistory.nextViewOptions({
|
|
|
|
|
|
disableAnimate: true
|
|
|
|
|
|
});
|
2017-05-30 16:19:06 -03:00
|
|
|
|
$scope.close();
|
2016-11-04 17:15:18 -03:00
|
|
|
|
$scope.openTxModal(tx);
|
|
|
|
|
|
};
|
2016-08-15 10:25:43 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 17:56:04 -03:00
|
|
|
|
$scope.openTxModal = function(btx) {
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$scope.btx = lodash.cloneDeep(btx);
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.walletId = $scope.wallet.id;
|
2016-10-22 17:43:05 -03:00
|
|
|
|
$state.transitionTo('tabs.wallet.tx-details', {
|
|
|
|
|
|
txid: $scope.btx.txid,
|
|
|
|
|
|
walletId: $scope.walletId
|
|
|
|
|
|
});
|
2016-08-15 10:25:43 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-12-09 16:42:11 -05:00
|
|
|
|
$scope.openBalanceModal = function() {
|
|
|
|
|
|
$ionicModal.fromTemplateUrl('views/modals/wallet-balance.html', {
|
|
|
|
|
|
scope: $scope
|
|
|
|
|
|
}).then(function(modal) {
|
|
|
|
|
|
$scope.walletBalanceModal = modal;
|
|
|
|
|
|
$scope.walletBalanceModal.show();
|
|
|
|
|
|
});
|
2016-12-13 12:30:28 -05:00
|
|
|
|
|
|
|
|
|
|
$scope.close = function() {
|
|
|
|
|
|
$scope.walletBalanceModal.hide();
|
|
|
|
|
|
};
|
2016-12-09 16:42:11 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.recreate = function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
walletService.recreate($scope.wallet, function(err) {
|
2016-09-08 12:13:37 -03:00
|
|
|
|
if (err) return;
|
|
|
|
|
|
$timeout(function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
walletService.startScan($scope.wallet, function() {
|
2016-11-14 12:53:43 -03:00
|
|
|
|
$scope.updateAll();
|
2016-09-08 12:13:37 -03:00
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2016-08-18 10:37:08 -03:00
|
|
|
|
};
|
2016-08-17 18:48:30 -03:00
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
var updateTxHistory = function(cb) {
|
2016-09-07 15:35:14 -03:00
|
|
|
|
if (!cb) cb = function() {};
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.updateTxHistoryError = false;
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.updatingTxHistoryProgress = 0;
|
2016-08-18 10:37:08 -03:00
|
|
|
|
|
2017-08-29 15:47:39 -03:00
|
|
|
|
feeService.getFeeLevels($scope.wallet.coin, function(err, levels) {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
walletService.getTxHistory($scope.wallet, {
|
2018-02-07 11:44:27 -04:00
|
|
|
|
feeLevels: levels
|
2016-08-18 10:37:08 -03:00
|
|
|
|
}, function(err, txHistory) {
|
|
|
|
|
|
$scope.updatingTxHistory = false;
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
$scope.txHistory = null;
|
|
|
|
|
|
$scope.updateTxHistoryError = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-11-01 16:26:42 +09:00
|
|
|
|
|
|
|
|
|
|
applyCurrencyAliases(txHistory);
|
2018-01-31 14:52:14 -04:00
|
|
|
|
|
|
|
|
|
|
var config = configService.getSync();
|
|
|
|
|
|
var fiatCode = config.wallet.settings.alternativeIsoCode;
|
|
|
|
|
|
lodash.each(txHistory, function(t) {
|
|
|
|
|
|
var r = rateService.toFiat(t.amount, fiatCode, $scope.wallet.coin);
|
|
|
|
|
|
t.alternativeAmountStr = r.toFixed(2) + ' ' + fiatCode;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2018-02-06 17:50:25 -04:00
|
|
|
|
$scope.completeTxHistory = txHistory;
|
2018-01-31 14:52:14 -04:00
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.showHistory();
|
2017-08-07 13:11:12 -03:00
|
|
|
|
$timeout(function() {
|
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
});
|
2016-08-24 17:54:01 -03:00
|
|
|
|
return cb();
|
2016-08-18 10:37:08 -03:00
|
|
|
|
});
|
2016-08-15 16:07:30 -03:00
|
|
|
|
});
|
2016-08-15 10:25:43 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-11-01 16:26:42 +09:00
|
|
|
|
function applyCurrencyAliases(txHistory) {
|
|
|
|
|
|
var defaults = configService.getDefaults();
|
|
|
|
|
|
var configCache = configService.getSync();
|
|
|
|
|
|
|
|
|
|
|
|
lodash.each(txHistory, function(t) {
|
|
|
|
|
|
t.amountUnitStr = $scope.wallet.coin == 'btc'
|
|
|
|
|
|
? (configCache.bitcoinAlias || defaults.bitcoinAlias)
|
|
|
|
|
|
: (configCache.bitcoinCashAlias || defaults.bitcoinCashAlias);
|
|
|
|
|
|
|
|
|
|
|
|
t.amountUnitStr = t.amountUnitStr.toUpperCase();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.showHistory = function() {
|
2016-08-22 18:20:01 -03:00
|
|
|
|
if ($scope.completeTxHistory) {
|
|
|
|
|
|
$scope.txHistory = $scope.completeTxHistory.slice(0, (currentTxHistoryPage + 1) * HISTORY_SHOW_LIMIT);
|
|
|
|
|
|
$scope.txHistoryShowMore = $scope.completeTxHistory.length > $scope.txHistory.length;
|
2016-08-18 10:37:08 -03:00
|
|
|
|
}
|
2016-11-01 17:47:07 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.getDate = function(txCreated) {
|
2016-11-02 17:01:32 -04:00
|
|
|
|
var date = new Date(txCreated * 1000);
|
|
|
|
|
|
return date;
|
2016-08-18 10:37:08 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-11-04 13:29:19 -04:00
|
|
|
|
$scope.isFirstInGroup = function(index) {
|
2016-11-15 11:03:45 -03:00
|
|
|
|
if (index === 0) {
|
2016-11-02 16:35:05 -04:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
var curTx = $scope.txHistory[index];
|
|
|
|
|
|
var prevTx = $scope.txHistory[index - 1];
|
2017-06-08 15:01:11 -04:00
|
|
|
|
return !$scope.createdDuringSameMonth(curTx, prevTx);
|
2016-11-02 16:35:05 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-11-04 13:29:19 -04:00
|
|
|
|
$scope.isLastInGroup = function(index) {
|
2016-11-15 11:03:45 -03:00
|
|
|
|
if (index === $scope.txHistory.length - 1) {
|
2016-11-04 13:29:19 -04:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return $scope.isFirstInGroup(index + 1);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-06-07 18:55:43 -04:00
|
|
|
|
$scope.createdDuringSameMonth = function(curTx, prevTx) {
|
2017-06-08 10:38:58 -04:00
|
|
|
|
return timeService.withinSameMonth(curTx.time * 1000, prevTx.time * 1000);
|
2017-06-07 18:55:43 -04:00
|
|
|
|
};
|
2016-11-02 17:01:32 -04:00
|
|
|
|
|
2016-11-03 17:29:29 -04:00
|
|
|
|
$scope.createdWithinPastDay = function(time) {
|
2017-06-07 18:55:43 -04:00
|
|
|
|
return timeService.withinPastDay(time);
|
2016-11-03 15:50:22 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-11-02 17:01:32 -04:00
|
|
|
|
$scope.isDateInCurrentMonth = function(date) {
|
2017-06-07 18:55:43 -04:00
|
|
|
|
return timeService.isDateInCurrentMonth(date);
|
2016-11-02 17:01:32 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-11-03 17:29:29 -04:00
|
|
|
|
$scope.isUnconfirmed = function(tx) {
|
2016-11-07 15:32:28 -05:00
|
|
|
|
return !tx.confirmations || tx.confirmations === 0;
|
2016-11-03 17:29:29 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.showMore = function() {
|
2016-10-03 11:52:48 -03:00
|
|
|
|
$timeout(function() {
|
|
|
|
|
|
currentTxHistoryPage++;
|
|
|
|
|
|
$scope.showHistory();
|
|
|
|
|
|
$scope.$broadcast('scroll.infiniteScrollComplete');
|
|
|
|
|
|
}, 100);
|
2016-08-18 10:37:08 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-10-10 15:19:33 -03:00
|
|
|
|
$scope.onRefresh = function() {
|
2016-10-14 10:25:52 -03:00
|
|
|
|
$timeout(function() {
|
|
|
|
|
|
$scope.$broadcast('scroll.refreshComplete');
|
|
|
|
|
|
}, 300);
|
2016-10-10 15:19:33 -03:00
|
|
|
|
$scope.updateAll(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.updateAll = function(force, cb) {
|
|
|
|
|
|
updateStatus(force);
|
|
|
|
|
|
updateTxHistory(cb);
|
2016-09-22 10:34:00 -03:00
|
|
|
|
};
|
2016-08-18 10:37:08 -03:00
|
|
|
|
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$scope.hideToggle = function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
profileService.toggleHideBalanceFlag($scope.wallet.credentials.walletId, function(err) {
|
2016-08-31 12:03:44 -03:00
|
|
|
|
if (err) $log.error(err);
|
|
|
|
|
|
});
|
2016-09-22 10:34:00 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-11-11 16:52:41 -05:00
|
|
|
|
var prevPos;
|
2016-11-15 11:03:45 -03:00
|
|
|
|
|
|
|
|
|
|
function getScrollPosition() {
|
2016-11-15 10:51:00 -05:00
|
|
|
|
var scrollPosition = $ionicScrollDelegate.getScrollPosition();
|
2016-12-13 12:30:28 -05:00
|
|
|
|
if (!scrollPosition) {
|
2016-11-15 10:51:00 -05:00
|
|
|
|
$window.requestAnimationFrame(function() {
|
|
|
|
|
|
getScrollPosition();
|
|
|
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
var pos = scrollPosition.top;
|
2016-11-15 11:03:45 -03:00
|
|
|
|
if (pos === prevPos) {
|
2016-11-11 17:24:01 -05:00
|
|
|
|
$window.requestAnimationFrame(function() {
|
|
|
|
|
|
getScrollPosition();
|
|
|
|
|
|
});
|
2016-11-11 16:52:41 -05:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
prevPos = pos;
|
2016-12-14 12:29:09 -05:00
|
|
|
|
refreshAmountSection(pos);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function refreshAmountSection(scrollPos) {
|
2018-08-13 16:13:29 +09:00
|
|
|
|
var AMOUNT_HEIGHT_BASE = 210;
|
2016-12-15 15:38:15 -05:00
|
|
|
|
$scope.showBalanceButton = false;
|
2017-02-06 10:15:12 -03:00
|
|
|
|
if ($scope.status) {
|
2017-02-01 15:41:20 -03:00
|
|
|
|
$scope.showBalanceButton = ($scope.status.totalBalanceSat != $scope.status.spendableAmount);
|
2018-08-13 16:13:29 +09:00
|
|
|
|
if ($scope.showBalanceButton) {
|
|
|
|
|
|
AMOUNT_HEIGHT_BASE = 270;
|
|
|
|
|
|
}
|
2016-12-15 15:38:15 -05:00
|
|
|
|
}
|
|
|
|
|
|
if (!$scope.amountIsCollapsible) {
|
|
|
|
|
|
var t = ($scope.showBalanceButton ? 15 : 45);
|
|
|
|
|
|
$scope.amountScale = 'translateY(' + t + 'px)';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-14 12:29:09 -05:00
|
|
|
|
scrollPos = scrollPos || 0;
|
2018-08-13 16:45:46 +12:00
|
|
|
|
var amountHeight = AMOUNT_HEIGHT_BASE - scrollPos;
|
2016-11-15 11:03:45 -03:00
|
|
|
|
if (amountHeight < 80) {
|
2016-11-09 12:34:38 -05:00
|
|
|
|
amountHeight = 80;
|
|
|
|
|
|
}
|
2016-11-09 13:37:14 -05:00
|
|
|
|
var contentMargin = amountHeight;
|
2018-08-13 16:45:46 +12:00
|
|
|
|
if (contentMargin > AMOUNT_HEIGHT_BASE) {
|
|
|
|
|
|
contentMargin = AMOUNT_HEIGHT_BASE;
|
2016-11-09 13:37:14 -05:00
|
|
|
|
}
|
2016-11-09 13:15:42 -05:00
|
|
|
|
|
2018-08-13 16:45:46 +12:00
|
|
|
|
var amountScale = (amountHeight / AMOUNT_HEIGHT_BASE);
|
2016-11-15 11:03:45 -03:00
|
|
|
|
if (amountScale < 0.5) {
|
2016-11-09 13:15:42 -05:00
|
|
|
|
amountScale = 0.5;
|
|
|
|
|
|
}
|
2016-11-15 11:03:45 -03:00
|
|
|
|
if (amountScale > 1.1) {
|
2016-11-09 13:15:42 -05:00
|
|
|
|
amountScale = 1.1;
|
|
|
|
|
|
}
|
2016-11-10 18:12:40 -05:00
|
|
|
|
|
2016-11-09 13:15:42 -05:00
|
|
|
|
var s = amountScale;
|
|
|
|
|
|
|
2016-12-13 12:30:28 -05:00
|
|
|
|
// Make space for the balance button when it needs to display.
|
2016-12-15 15:38:15 -05:00
|
|
|
|
var TOP_NO_BALANCE_BUTTON = 115;
|
|
|
|
|
|
var TOP_BALANCE_BUTTON = 30;
|
2016-12-13 12:30:28 -05:00
|
|
|
|
var top = TOP_NO_BALANCE_BUTTON;
|
|
|
|
|
|
if ($scope.showBalanceButton) {
|
|
|
|
|
|
top = TOP_BALANCE_BUTTON;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-30 15:17:15 +02:00
|
|
|
|
var amountTop = ((amountScale - 0.80) / 0.80) * top;
|
2018-07-30 09:37:14 +02:00
|
|
|
|
if (amountTop < -2) {
|
|
|
|
|
|
amountTop = -2;
|
2016-12-13 12:30:28 -05:00
|
|
|
|
}
|
|
|
|
|
|
if (amountTop > top) {
|
|
|
|
|
|
amountTop = top;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var t = amountTop;
|
|
|
|
|
|
|
2016-11-15 11:03:45 -03:00
|
|
|
|
$scope.altAmountOpacity = (amountHeight - 100) / 80;
|
2018-07-30 15:17:15 +02:00
|
|
|
|
$scope.buttonsOpacity = (amountHeight - 140) / 70;
|
2016-11-11 17:24:01 -05:00
|
|
|
|
$window.requestAnimationFrame(function() {
|
2016-11-09 12:34:38 -05:00
|
|
|
|
$scope.amountHeight = amountHeight + 'px';
|
2016-11-09 13:37:14 -05:00
|
|
|
|
$scope.contentMargin = contentMargin + 'px';
|
2016-12-13 12:30:28 -05:00
|
|
|
|
$scope.amountScale = 'scale3d(' + s + ',' + s + ',' + s + ') translateY(' + t + 'px)';
|
2016-11-11 17:24:01 -05:00
|
|
|
|
$scope.$digest();
|
|
|
|
|
|
getScrollPosition();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2016-11-11 16:52:41 -05:00
|
|
|
|
|
2016-11-11 18:51:43 -05:00
|
|
|
|
var scrollWatcherInitialized;
|
2016-09-22 10:34:00 -03:00
|
|
|
|
|
2016-11-11 16:52:41 -05:00
|
|
|
|
$scope.$on("$ionicView.enter", function(event, data) {
|
2016-12-13 12:08:05 -03:00
|
|
|
|
if ($scope.isCordova && $scope.isAndroid) setAndroidStatusBarColor();
|
2016-11-15 11:03:45 -03:00
|
|
|
|
if (scrollWatcherInitialized || !$scope.amountIsCollapsible) {
|
2016-11-11 18:51:43 -05:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
scrollWatcherInitialized = true;
|
2016-11-11 16:52:41 -05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
2018-08-08 17:29:28 +02:00
|
|
|
|
sendFlowService.clear();
|
2018-04-25 13:59:25 +09:00
|
|
|
|
|
|
|
|
|
|
configService.whenAvailable(function (config) {
|
|
|
|
|
|
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
|
|
|
|
|
|
|
|
|
|
|
|
$timeout(function () {
|
2018-04-26 10:28:08 +09:00
|
|
|
|
$scope.$apply();
|
2018-04-25 13:59:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2016-11-07 17:22:51 -05:00
|
|
|
|
$scope.walletId = data.stateParams.walletId;
|
|
|
|
|
|
$scope.wallet = profileService.getWallet($scope.walletId);
|
2017-02-23 12:01:06 -03:00
|
|
|
|
if (!$scope.wallet) return;
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.requiresMultipleSignatures = $scope.wallet.credentials.m > 1;
|
|
|
|
|
|
|
2017-08-30 14:52:30 -03:00
|
|
|
|
$scope.updatingTxHistory = true;
|
|
|
|
|
|
|
2016-10-21 11:58:33 -03:00
|
|
|
|
addressbookService.list(function(err, ab) {
|
|
|
|
|
|
if (err) $log.error(err);
|
|
|
|
|
|
$scope.addressbook = ab || {};
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
listeners = [
|
|
|
|
|
|
$rootScope.$on('bwsEvent', function(e, walletId) {
|
2017-02-01 15:41:20 -03:00
|
|
|
|
if (walletId == $scope.wallet.id && e.type != 'NewAddress')
|
2017-01-17 11:41:39 -03:00
|
|
|
|
$scope.updateAll();
|
2016-09-29 19:04:52 -03:00
|
|
|
|
}),
|
|
|
|
|
|
$rootScope.$on('Local/TxAction', function(e, walletId) {
|
|
|
|
|
|
if (walletId == $scope.wallet.id)
|
2017-01-17 11:41:39 -03:00
|
|
|
|
$scope.updateAll();
|
2016-09-29 19:04:52 -03:00
|
|
|
|
}),
|
|
|
|
|
|
];
|
|
|
|
|
|
});
|
2016-09-22 10:34:00 -03:00
|
|
|
|
|
2017-12-18 12:07:41 +00:00
|
|
|
|
var refreshInterval;
|
|
|
|
|
|
|
2017-02-02 18:04:08 -03:00
|
|
|
|
$scope.$on("$ionicView.afterEnter", function(event, data) {
|
|
|
|
|
|
$scope.updateAll();
|
|
|
|
|
|
refreshAmountSection();
|
2018-02-06 17:50:25 -04:00
|
|
|
|
refreshInterval = $interval($scope.onRefresh, 10 * 1000);
|
2017-02-02 18:04:08 -03:00
|
|
|
|
});
|
|
|
|
|
|
|
2017-07-07 17:58:24 -03:00
|
|
|
|
$scope.$on("$ionicView.afterLeave", function(event, data) {
|
2017-12-18 12:07:41 +00:00
|
|
|
|
$interval.cancel(refreshInterval);
|
2016-12-12 17:29:11 -03:00
|
|
|
|
if ($window.StatusBar) {
|
2018-05-16 14:22:37 +02:00
|
|
|
|
$window.StatusBar.backgroundColorByHexString('#000000');
|
2016-11-17 14:58:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.$on("$ionicView.leave", function(event, data) {
|
|
|
|
|
|
lodash.each(listeners, function(x) {
|
|
|
|
|
|
x();
|
2016-09-22 10:34:00 -03:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2016-11-17 14:58:49 -05:00
|
|
|
|
|
|
|
|
|
|
function setAndroidStatusBarColor() {
|
|
|
|
|
|
var SUBTRACT_AMOUNT = 15;
|
2017-07-07 17:58:24 -03:00
|
|
|
|
var walletColor;
|
|
|
|
|
|
if (!$scope.wallet.color) walletColor = appConfigService.name == 'copay' ? '#019477' : '#4a90e2';
|
|
|
|
|
|
else walletColor = $scope.wallet.color;
|
|
|
|
|
|
var rgb = hexToRgb(walletColor);
|
2016-11-17 14:58:49 -05:00
|
|
|
|
var keys = Object.keys(rgb);
|
|
|
|
|
|
keys.forEach(function(k) {
|
2016-12-12 17:29:11 -03:00
|
|
|
|
if (rgb[k] - SUBTRACT_AMOUNT < 0) {
|
2016-11-17 14:58:49 -05:00
|
|
|
|
rgb[k] = 0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
rgb[k] -= SUBTRACT_AMOUNT;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
var statusBarColorHexString = rgbToHex(rgb.r, rgb.g, rgb.b);
|
2016-12-13 12:08:05 -03:00
|
|
|
|
if ($window.StatusBar)
|
|
|
|
|
|
$window.StatusBar.backgroundColorByHexString(statusBarColorHexString);
|
2016-11-17 14:58:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function hexToRgb(hex) {
|
|
|
|
|
|
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
|
|
|
|
|
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
|
|
|
|
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
|
|
|
|
|
|
return r + r + g + g + b + b;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
|
|
|
|
return result ? {
|
|
|
|
|
|
r: parseInt(result[1], 16),
|
|
|
|
|
|
g: parseInt(result[2], 16),
|
|
|
|
|
|
b: parseInt(result[3], 16)
|
|
|
|
|
|
} : null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function componentToHex(c) {
|
|
|
|
|
|
var hex = c.toString(16);
|
|
|
|
|
|
return hex.length == 1 ? "0" + hex : hex;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function rgbToHex(r, g, b) {
|
|
|
|
|
|
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
|
|
|
|
}
|
2018-08-09 11:10:26 +12:00
|
|
|
|
|
2018-07-26 19:38:29 +02:00
|
|
|
|
$scope.goToSend = function() {
|
2018-08-09 11:10:26 +12:00
|
|
|
|
sendFlowService.startSend({
|
|
|
|
|
|
fromWalletId: $scope.wallet.id
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Go home first so that the Home tab works properly
|
2018-08-08 17:10:47 +02:00
|
|
|
|
$state.go('tabs.home').then(function () {
|
2018-07-26 19:38:29 +02:00
|
|
|
|
$ionicHistory.clearHistory();
|
|
|
|
|
|
$state.go('tabs.send');
|
|
|
|
|
|
});
|
2018-08-09 11:10:26 +12:00
|
|
|
|
|
2018-07-26 19:38:29 +02:00
|
|
|
|
};
|
2018-07-26 15:04:42 +02:00
|
|
|
|
$scope.goToReceive = function() {
|
|
|
|
|
|
$state.go('tabs.home', {
|
|
|
|
|
|
walletId: $scope.wallet.id
|
|
|
|
|
|
}).then(function () {
|
|
|
|
|
|
$ionicHistory.clearHistory();
|
|
|
|
|
|
$state.go('tabs.receive', {
|
|
|
|
|
|
walletId: $scope.wallet.id
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2018-08-09 15:41:17 +09:00
|
|
|
|
|
2018-07-26 19:38:29 +02:00
|
|
|
|
$scope.goToBuy = function() {
|
|
|
|
|
|
$state.go('tabs.home', {
|
|
|
|
|
|
walletId: $scope.wallet.id
|
|
|
|
|
|
}).then(function () {
|
|
|
|
|
|
$ionicHistory.clearHistory();
|
|
|
|
|
|
$state.go('tabs.buyandsell');
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2016-08-15 10:25:43 -03:00
|
|
|
|
});
|