Ref custom amount. Also fixes small screen issue

This commit is contained in:
Gustavo Maximiliano Cortez 2017-05-11 15:43:35 -03:00
commit 1c91420581
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
6 changed files with 170 additions and 71 deletions

View file

@ -1,23 +1,64 @@
'use strict';
angular.module('copayApp.controllers').controller('customAmountController', function($rootScope, $scope, $stateParams, $ionicHistory, txFormatService, platformInfo, profileService) {
angular.module('copayApp.controllers').controller('customAmountController', function($rootScope, $scope, $stateParams, $ionicHistory, txFormatService, platformInfo, configService, profileService, walletService, popupService) {
var showErrorAndBack = function(title, msg) {
popupService.showAlert(title, msg, function() {
$scope.close();
});
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
var satToBtc = 1 / 100000000;
$scope.isCordova = platformInfo.isCordova;
$scope.address = data.stateParams.toAddress;
$scope.amount = parseInt(data.stateParams.toAmount);
$scope.amountBtc = ($scope.amount * satToBtc).toFixed(8);
$scope.amountStr = txFormatService.formatAmountStr($scope.amount);
$scope.altAmountStr = txFormatService.formatAlternativeStr($scope.amount);
$scope.wallet = profileService.getWallet($stateParams.walletId);
var walletId = data.stateParams.id;
if (!walletId) {
showErrorAndBack('Error', 'No wallet selected');
return;
}
$scope.wallet = profileService.getWallet(walletId);
walletService.getAddress($scope.wallet, false, function(err, addr) {
if (!addr) {
showErrorAndBack('Error', 'Could not get the address');
return;
}
$scope.address = addr;
var parsedAmount = txFormatService.parseAmount(
data.stateParams.amount,
data.stateParams.currency);
// Amount in USD or BTC
var amount = parsedAmount.amount;
var currency = parsedAmount.currency;
$scope.amountUnitStr = parsedAmount.amountUnitStr;
if (currency != 'BTC') {
// Convert to BTC
var config = configService.getSync().wallet.settings;
var amountUnit = txFormatService.satToUnit(parsedAmount.amountSat);
var btcParsedAmount = txFormatService.parseAmount(amountUnit, config.unitName);
$scope.amountBtc = btcParsedAmount.amount;
$scope.altAmountStr = btcParsedAmount.amountUnitStr;
} else {
$scope.amountBtc = amount; // BTC
$scope.altAmountStr = txFormatService.formatAlternativeStr(parsedAmount.amountSat);
}
});
});
$scope.finish = function() {
$scope.close = function() {
$ionicHistory.nextViewOptions({
disableAnimate: false
disableAnimate: true
});
$ionicHistory.goBack(-2);
};
$scope.copyToClipboard = function() {
return 'bitcoin:' + $scope.address + '?amount=' + $scope.amountBtc;
};
});