Merge pull request #217 from Bitcoin-com/wallet/task/416
Improvement - 416 - New Send Tab screen
This commit is contained in:
commit
4cbaef5af6
19 changed files with 744 additions and 318 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('addressbookAddController', function($scope, $state, $stateParams, $timeout, $ionicHistory, gettextCatalog, addressbookService, popupService, configService, bitcoinCashJsService) {
|
||||
angular.module('copayApp.controllers').controller('addressbookAddController', function($scope, $state, $stateParams, $timeout, $ionicHistory, gettextCatalog, addressbookService, popupService, configService, bitcoinCashJsService, platformInfo) {
|
||||
|
||||
var config = configService.getSync();
|
||||
var defaults = configService.getDefaults();
|
||||
|
|
|
|||
|
|
@ -38,9 +38,11 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
$scope.minShapeshiftAmount = parseFloat(data.stateParams.minShapeshiftAmount);
|
||||
$scope.maxShapeshiftAmount = parseFloat(data.stateParams.maxShapeshiftAmount);
|
||||
$scope.shapeshiftOrderId = data.stateParams.shapeshiftOrderId;
|
||||
$scope.fromWalletId = data.stateParams.fromWalletId;
|
||||
}
|
||||
|
||||
// To get the wallet from with the new flow
|
||||
$scope.fromWalletId = data.stateParams.fromWalletId;
|
||||
|
||||
if (data.stateParams.noPrefix) {
|
||||
$scope.showWarningMessage = data.stateParams.noPrefix != 0;
|
||||
if ($scope.showWarningMessage) {
|
||||
|
|
@ -458,7 +460,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
amount: $scope.useSendMax ? null : _amount,
|
||||
currency: unit.id.toUpperCase(),
|
||||
coin: coin,
|
||||
useSendMax: $scope.useSendMax
|
||||
useSendMax: $scope.useSendMax,
|
||||
fromWalletId: $scope.fromWalletId
|
||||
});
|
||||
} else {
|
||||
var amount = _amount;
|
||||
|
|
@ -479,6 +482,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
toColor: $scope.toColor,
|
||||
coin: coin,
|
||||
useSendMax: $scope.useSendMax,
|
||||
fromWalletId: $scope.fromWalletId
|
||||
};
|
||||
|
||||
if ($scope.shapeshiftOrderId) {
|
||||
|
|
|
|||
|
|
@ -1,32 +1,139 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicNavBarDelegate) {
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) {
|
||||
var clipboardHasAddress = false;
|
||||
var clipboardHasContent = false;
|
||||
var originalList;
|
||||
var CONTACTS_SHOW_LIMIT;
|
||||
var currentContactsPage;
|
||||
$scope.isChromeApp = platformInfo.isChromeApp;
|
||||
$scope.sectionDisplay = {
|
||||
transferToWallet: false
|
||||
$scope.displayBalanceAsFiat = true;
|
||||
$scope.walletSelectorTitleForce = true;
|
||||
|
||||
$scope.addContact = function() {
|
||||
$state.go('tabs.send.addressbook');
|
||||
};
|
||||
|
||||
$scope.pasteClipboard = function() {
|
||||
if ($scope.clipboardHasAddress || $scope.clipboardHasContent) {
|
||||
clipboardService.readFromClipboard(function(text) {
|
||||
$scope.$apply(function() {
|
||||
$scope.formData.search = text;
|
||||
$scope.findContact($scope.formData.search);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
$ionicPopup.alert({
|
||||
title: gettextCatalog.getString('Clipboard'),
|
||||
template: gettextCatalog.getString('Your Clipboard is empty')
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
clipboardService.readFromClipboard(function(text) {
|
||||
if (text.length > 200) {
|
||||
text = text.substring(0, 200);
|
||||
}
|
||||
|
||||
$scope.clipboardHasAddress = false;
|
||||
$scope.clipboardHasContent = false;
|
||||
if ((text.indexOf('bitcoincash:') === 0 || text[0] === 'C' || text[0] === 'H' || text[0] === 'p' || text[0] === 'q') && text.replace('bitcoincash:', '').length === 42) { // CashAddr
|
||||
$scope.clipboardHasAddress = true;
|
||||
} else if ((text[0] === "1" || text[0] === "3" || text.substring(0, 3) === "bc1") && text.length >= 26 && text.length <= 35) { // Legacy Addresses
|
||||
$scope.clipboardHasAddress = true;
|
||||
} else if (text.length > 1) {
|
||||
$scope.clipboardHasContent = true;
|
||||
}
|
||||
});
|
||||
|
||||
$ionicNavBarDelegate.showBar(true);
|
||||
if (!$scope.hasWallets) {
|
||||
$scope.checkingBalance = false;
|
||||
return;
|
||||
}
|
||||
updateHasFunds();
|
||||
updateContactsList(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) {
|
||||
|
||||
if (incomingData.redir(search)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!search || search.length < 1) {
|
||||
$scope.list = originalList;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var result = lodash.filter(originalList, function(item) {
|
||||
var val = item.name;
|
||||
return lodash.startsWith(val.toLowerCase(), search.toLowerCase());
|
||||
});
|
||||
|
||||
$scope.list = result;
|
||||
};
|
||||
|
||||
var hasWallets = function() {
|
||||
$scope.walletsWithFunds = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
hasFunds: true
|
||||
});
|
||||
$scope.wallets = profileService.getWallets({
|
||||
onlyComplete: true
|
||||
onlyComplete: true,
|
||||
});
|
||||
$scope.walletsBch = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
coin: 'bch'
|
||||
});
|
||||
$scope.walletsBtc = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
coin: 'btc'
|
||||
});
|
||||
$scope.hasWallets = lodash.isEmpty($scope.wallets) ? false : true;
|
||||
};
|
||||
|
||||
// THIS is ONLY to show the 'buy bitcoins' message
|
||||
// does not has any other function.
|
||||
|
||||
var updateHasFunds = function() {
|
||||
|
||||
if ($rootScope.everHasFunds) {
|
||||
$scope.hasFunds = true;
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.hasFunds = false;
|
||||
var index = 0;
|
||||
lodash.each($scope.wallets, function(w) {
|
||||
|
|
@ -41,10 +148,9 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
$scope.hasFunds = true;
|
||||
} else if (status.availableBalanceSat > 0) {
|
||||
$scope.hasFunds = true;
|
||||
$rootScope.everHasFunds = true;
|
||||
}
|
||||
|
||||
if (index == $scope.wallets.length) {
|
||||
if (index === $scope.wallets.length) {
|
||||
$scope.checkingBalance = false;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
|
|
@ -54,52 +160,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
});
|
||||
};
|
||||
|
||||
var updateWalletsList = function() {
|
||||
var config = configService.getSync();
|
||||
var networkResult = lodash.countBy($scope.wallets, 'network');
|
||||
|
||||
$scope.showTransferCard = $scope.hasWallets && (networkResult.livenet > 1 || networkResult.testnet > 1);
|
||||
|
||||
if ($scope.showTransferCard) {
|
||||
var walletsToTransfer = $scope.wallets;
|
||||
if (!(networkResult.livenet > 1)) {
|
||||
walletsToTransfer = lodash.filter(walletsToTransfer, function(item) {
|
||||
return item.network == 'testnet';
|
||||
});
|
||||
}
|
||||
if (!(networkResult.testnet > 1)) {
|
||||
walletsToTransfer = lodash.filter(walletsToTransfer, function(item) {
|
||||
return item.network == 'livenet';
|
||||
});
|
||||
}
|
||||
|
||||
var walletList = [];
|
||||
lodash.each(walletsToTransfer, function(v) {
|
||||
var displayBalanceAsFiat =
|
||||
// BD got v.status as undefined here once during development, just
|
||||
// after creating a new wallet.
|
||||
v.status &&
|
||||
v.status.alternativeBalanceAvailable &&
|
||||
config.wallet.settings.priceDisplay === 'fiat';
|
||||
|
||||
walletList.push({
|
||||
color: v.color,
|
||||
name: v.name,
|
||||
recipientType: 'wallet',
|
||||
coin: v.coin,
|
||||
network: v.network,
|
||||
balanceString: displayBalanceAsFiat ?
|
||||
v.status.totalBalanceAlternative + ' ' + v.status.alternativeIsoCode :
|
||||
v.cachedBalance,
|
||||
getAddress: function(cb) {
|
||||
walletService.getAddress(v, false, cb);
|
||||
},
|
||||
});
|
||||
});
|
||||
originalList = originalList.concat(walletList);
|
||||
}
|
||||
}
|
||||
|
||||
var updateContactsList = function(cb) {
|
||||
var config = configService.getSync();
|
||||
var defaults = configService.getDefaults();
|
||||
|
|
@ -118,16 +178,14 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
recipientType: 'contact',
|
||||
coin: v.coin,
|
||||
displayCoin: (v.coin == 'bch'
|
||||
? (config.bitcoinCashAlias || defaults.bitcoinCashAlias)
|
||||
: (config.bitcoinAlias || defaults.bitcoinAlias)).toUpperCase(),
|
||||
? (config.bitcoinCashAlias || defaults.bitcoinCashAlias)
|
||||
: (config.bitcoinAlias || defaults.bitcoinAlias)).toUpperCase(),
|
||||
getAddress: function(cb) {
|
||||
return cb(null, k);
|
||||
},
|
||||
});
|
||||
});
|
||||
var contacts = completeContacts.slice(0, (currentContactsPage + 1) * CONTACTS_SHOW_LIMIT);
|
||||
$scope.contactsShowMore = completeContacts.length > contacts.length;
|
||||
originalList = originalList.concat(contacts);
|
||||
originalList = completeContacts;
|
||||
return cb();
|
||||
});
|
||||
};
|
||||
|
|
@ -140,28 +198,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
}, 10);
|
||||
};
|
||||
|
||||
$scope.openScanner = function() {
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
|
||||
if (!isWindowsPhoneApp) {
|
||||
$state.go('tabs.scan');
|
||||
return;
|
||||
}
|
||||
|
||||
scannerService.useOldScanner(function(err, contents) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
}
|
||||
incomingData.redir(contents);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.showMore = function() {
|
||||
currentContactsPage++;
|
||||
updateWalletsList();
|
||||
};
|
||||
|
||||
$scope.searchInFocus = function() {
|
||||
$scope.searchFocus = true;
|
||||
};
|
||||
|
|
@ -172,28 +208,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
}
|
||||
};
|
||||
|
||||
$scope.findContact = function(search) {
|
||||
|
||||
if (incomingData.redir(search)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!search || search.length < 2) {
|
||||
$scope.list = originalList;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var result = lodash.filter(originalList, function(item) {
|
||||
var val = item.name;
|
||||
return lodash.includes(val.toLowerCase(), search.toLowerCase());
|
||||
});
|
||||
|
||||
$scope.list = result;
|
||||
};
|
||||
|
||||
$scope.goToAmount = function(item) {
|
||||
$timeout(function() {
|
||||
item.getAddress(function(err, addr) {
|
||||
|
|
@ -236,34 +250,19 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
};
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
$scope.isIOS = platformInfo.isIOS && platformInfo.isCordova;
|
||||
$scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false;
|
||||
|
||||
$scope.checkingBalance = true;
|
||||
$scope.formData = {
|
||||
search: null
|
||||
};
|
||||
originalList = [];
|
||||
CONTACTS_SHOW_LIMIT = 10;
|
||||
currentContactsPage = 0;
|
||||
hasWallets();
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
$ionicNavBarDelegate.showBar(true);
|
||||
if (!$scope.hasWallets) {
|
||||
$scope.checkingBalance = false;
|
||||
return;
|
||||
}
|
||||
updateHasFunds();
|
||||
updateWalletsList();
|
||||
updateContactsList(function() {
|
||||
updateList();
|
||||
configService.whenAvailable(function(_config) {
|
||||
$scope.displayBalanceAsFiat = _config.wallet.settings.priceDisplay === 'fiat';
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$scope.toggle = function(section) {
|
||||
$scope.sectionDisplay[section] = !$scope.sectionDisplay[section];
|
||||
$timeout(function() {
|
||||
$ionicScrollDelegate.resize();
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue