fixes for other cases, address to address + contacts + thirdParty stub

This commit is contained in:
Sebastiaan Pasma 2018-07-25 17:25:38 +02:00
commit aff0dd3183
No known key found for this signature in database
GPG key ID: 9A2B0C8B95A1D26F
6 changed files with 77 additions and 77 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, $ionicLoading, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bitcoinCashJsService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService, soundService) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bitcoinCashJsService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService, soundService) {
var countDown = null;
var FEE_TOO_HIGH_LIMIT_PER = 15;
@ -116,9 +116,36 @@ angular.module('copayApp.controllers').controller('confirmController', function(
});
});
};
$scope.getContacts = function(addr) {
addressbookService.list(function(err, ab) {
if (err) $log.error(err);
$scope.hasContacts = lodash.isEmpty(ab) ? false : true;
if (!$scope.hasContacts) return cb();
var completeContacts = [];
lodash.each(ab, function(v, k) {
completeContacts.push({
name: lodash.isObject(v) ? v.name : v,
address: k,
email: lodash.isObject(v) ? v.email : null,
recipientType: 'contact',
coin: v.coin,
displayCoin: (v.coin == 'bch'
? (config.bitcoinCashAlias || defaults.bitcoinCashAlias)
: (config.bitcoinAlias || defaults.bitcoinAlias)).toUpperCase()
});
});
return cb();
});
}
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.fromWallet = profileService.getWallet(data.stateParams.fromWalletId); // Wallet to send from
// Grab stateParams
tx = {
amount: parseInt(data.stateParams.amount),
@ -173,7 +200,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
setupTx(tx);
}
} catch (e) {
console.log(e);
var message = gettextCatalog.getString('Invalid address');
popupService.showAlert(null, message, function () {
$ionicHistory.nextViewOptions({
@ -195,6 +221,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
tx.displayAddress = entry.address;
}
addressbookService.get(tx.coin+tx.toAddress, function(err, addr) { // Check if the recipient is a contact
if (!err && addr) {
tx.toName = addr.name;
tx.toEmail = addr.email;
tx.recipientType = 'contact';
}
});
// Other Scope vars
$scope.isCordova = isCordova;
$scope.showAddress = false;

View file

@ -4,16 +4,32 @@ angular.module('copayApp.controllers').controller('sendFlowController', function
$scope.$on("$ionicView.beforeEnter", function(event, data) {
var config = configService.getSync().wallet.settings;
$scope.sendFlowTitle = "";
if ($state.current.name === 'tabs.send.wallet-to-wallet') {
$scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer');
}
$scope.params = $stateParams;
$scope.coin = false; // Wallets to show (for destination screen or contacts)
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
if ($scope.params.coin) {
$scope.coin = $scope.params.coin; // Contacts have a coin embedded
}
if ($scope.params.amount) { // There is an amount, so presume that it a payment request
$scope.sendFlowTitle = gettextCatalog.getString('Payment request');
$scope.specificAmount = $scope.specificAlternativeAmount = '';
var unitToSatoshi = config.unitToSatoshi;
var satToUnit = 1 / unitToSatoshi;
var satToBtc = 1 / 100000000;
var unitDecimals = config.unitDecimals;
$scope.requestAmount = (($stateParams.amount) * satToUnit).toFixed(unitDecimals);
$scope.requestAmount = (($stateParams.amount) * (1 / config.unitToSatoshi)).toFixed(config.unitDecimals);
$scope.isPaymentRequest = true;
}
if ($scope.params.thirdParty) {
// Third Party Service
if ($scope.params.thirdParty.id === 'shapeshift') {
}
}
});
$scope.$on("$ionicView.enter", function(event, data) {
@ -21,8 +37,6 @@ angular.module('copayApp.controllers').controller('sendFlowController', function
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
});
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
$scope.coin = false; // Wallets to show (for destination screen)
$scope.walletsEmpty = []; // empty wallets for origin screen
if ($scope.type === 'origin') {

View file

@ -54,42 +54,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
updateList();
});
});
//
// var wallets;
// var walletsBch;
// var walletsBtc;
// var walletToWalletFrom = false;
//
// $scope.onWalletSelect = function(wallet) {
// if (!$scope.walletToWalletFrom) {
// $scope.walletToWalletFrom = wallet;
// if (wallet.coin === 'bch') {
// $scope.showWalletsBch = true;
// } else if (wallet.coin === 'btc') {
// $scope.showWalletsBtc = true;
// }
// $scope.walletSelectorTitleTo = gettextCatalog.getString('Send to');
// } else {
// $ionicLoading.show();
// walletService.getAddress(wallet, true, function(err, addr) {
// $ionicLoading.hide();
// return $state.transitionTo('tabs.send.amount', {
// displayAddress: $scope.walletToWalletFrom.coin === 'bch' ? bitcoinCashJsService.translateAddresses(addr).cashaddr : addr,
// recipientType: 'wallet',
// fromWalletId: $scope.walletToWalletFrom.id,
// toAddress: addr,
// coin: $scope.walletToWalletFrom.coin
// });
// });
//
// }
// };
//
// $scope.showWalletSelector = function() {
// $scope.walletToWalletFrom = false;
// $scope.walletSelectorTitleFrom = gettextCatalog.getString('Send from');
// $scope.showWallets = true;
// };
$scope.findContact = function(search) {
@ -178,10 +142,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
coin: v.coin,
displayCoin: (v.coin == 'bch'
? (config.bitcoinCashAlias || defaults.bitcoinCashAlias)
: (config.bitcoinAlias || defaults.bitcoinAlias)).toUpperCase(),
getAddress: function(cb) {
return cb(null, k);
},
: (config.bitcoinAlias || defaults.bitcoinAlias)).toUpperCase()
});
});
originalList = completeContacts;
@ -202,35 +163,26 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
};
$scope.searchBlurred = function() {
if ($scope.formData.search == null || $scope.formData.search.length == 0) {
if ($scope.formData.search == null || $scope.formData.search.length === 0) {
$scope.searchFocus = false;
}
};
$scope.goToAmount = function(item) {
$timeout(function() {
item.getAddress(function(err, addr) {
if (err || !addr) {
//Error is already formated
return popupService.showAlert(err);
}
$scope.sendToContact = function (item) {
$timeout(function () {
var toAddress = item.address;
if (item.recipientType && item.recipientType == 'contact') {
if (addr.indexOf('bch') == 0 || addr.indexOf('btc') == 0) {
addr = addr.substring(3);
}
if (item.recipientType && item.recipientType === 'contact') {
if (toAddress.indexOf('bch') === 0 || toAddress.indexOf('btc') === 0) {
toAddress = toAddress.substring(3);
}
}
$log.debug('Got toAddress:' + addr + ' | ' + item.name);
return $state.transitionTo('tabs.send.amount', {
recipientType: item.recipientType,
displayAddress: item.coin == 'bch' ? bitcoinCashJsService.translateAddresses(addr).cashaddr : addr,
toAddress: addr,
toName: item.name,
toEmail: item.email,
toColor: item.color,
coin: item.coin
});
$log.debug('Got toAddress:' + toAddress + ' | ' + item.name);
return $state.transitionTo('tabs.send.origin', {
toAddress: toAddress,
coin: item.coin
});
});
};

View file

@ -287,7 +287,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
*/
.state('tabs.send.amount', {
url: '/amount/:recipientType/:toAddress/:toName/:toEmail/:toColor/:coin/:fixedUnit/:fromWalletId/:toWalletId/:minShapeshiftAmount/:maxShapeshiftAmount/:shapeshiftOrderId/:displayAddress/:noPrefix',
url: '/amount/:thirdParty/:fromWalletId/:toWalletId/:toAddress',
views: {
'tab-send@tabs': {
controller: 'amountController',
@ -305,7 +305,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('tabs.send.origin', {
url: '/origin/:thirdParty/:amount/:toAddress/:toWalletId',
url: '/origin/:thirdParty/:amount/:toAddress/:toWalletId/:coin',
views: {
'tab-send@tabs': {
controller: 'sendFlowController',

View file

@ -90,7 +90,7 @@
</div>
<div class="list">
<a class="item item-icon-left item-icon-right" ng-repeat="item in list"
ng-if="!item.isWallet && item.recipientType != 'wallet'" ng-click="goToAmount(item)">
ng-if="!item.isWallet && item.recipientType != 'wallet'" ng-click="sendToContact(item)">
<i class="icon big-icon-svg">
<gravatar class="send-gravatar" name="{{item.name}}" width="120" email="{{item.email}}"></gravatar>
</i>

View file

@ -1,13 +1,13 @@
<ion-view id="wallet-origin-destination" show-tabs>
<ion-nav-bar class="bar-royal">
<ion-nav-title>{{'Wallet to wallet transfer' | translate}}</ion-nav-title>
<ion-nav-title>{{sendFlowTitle}}</ion-nav-title>
<ion-nav-back-button ng-click="goBack()"></ion-nav-back-button>
</ion-nav-bar>
<ion-content>
<div class="header--request" ng-if="isPaymentRequest">
<div class="header--request__title" translate>Paying</div>
<div class="header--request__amount" translate>$37.42 USD</div>
<div class="header--request__amount-alt" translate>0.04580000 BCH {{requestAmount}}</div>
<div class="header--request__amount" translate>$... USD</div>
<div class="header--request__amount-alt" translate>{{requestAmount}} {{coin.toUpperCase()}}</div>
</div>
<div class="wallets-header">
<div class="title">