Skip to content

Commit

Permalink
Merge pull request #366 from Bitcoin-com/wallet/dev
Browse files Browse the repository at this point in the history
5.1-rc4
  • Loading branch information
Jean-Baptiste Dominguez authored Sep 26, 2018
2 parents c3043e6 + e14ab5d commit 6369336
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 62 deletions.
6 changes: 3 additions & 3 deletions app-template/bitcoincom/appConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"windowsAppId": "804636ee-b017-4cad-8719-e58ac97ffa5c",
"pushSenderId": "1036948132229",
"description": "A Secure Bitcoin Wallet",
"version": "5.1.4",
"fullVersion": "5.1-rc3",
"androidVersion": "501400",
"version": "5.1.5",
"fullVersion": "5.1-rc4",
"androidVersion": "501500",
"_extraCSS": "",
"_enabledExtensions": {
"coinbase": false,
Expand Down
7 changes: 6 additions & 1 deletion src/js/controllers/amount.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
vm.sendableFunds = '';
vm.showSendMaxButton = false;
vm.showSendLimitMaxButton = false;
vm.thirdParty = false;
vm.thirdParty = null;
vm.unit = '';

// Functions
Expand Down Expand Up @@ -88,11 +88,16 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
sendFlowService.state.pop();
}



initCurrencies();

passthroughParams = sendFlowService.state.getClone();
console.log('amount onBeforeEnter after back sendflow ', passthroughParams);

// Init thirdParty, should be done for all the variable
vm.thirdParty = null;

vm.fromWalletId = passthroughParams.fromWalletId;
vm.toWalletId = passthroughParams.toWalletId;
vm.minAmount = parseFloat(passthroughParams.minAmount);
Expand Down
93 changes: 45 additions & 48 deletions src/js/controllers/review.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular
.module('copayApp.controllers')
.controller('reviewController', reviewController);

function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, clipboardService, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicModal, ionicToast, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, sendFlowService, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) {
function reviewController(addressbookService, externalLinkService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, clipboardService, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicModal, ionicToast, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, sendFlowService, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) {
var vm = this;

vm.buttonText = '';
Expand Down Expand Up @@ -49,7 +49,7 @@ angular
vm.sendingTitle = gettextCatalog.getString('You are sending');
vm.sendStatus = '';
vm.showAddress = true;
vm.thirdParty = false;
vm.thirdParty = null;
vm.wallet = null;
vm.memoExpanded = false;

Expand Down Expand Up @@ -79,20 +79,16 @@ angular

$scope.$on("$ionicView.beforeEnter", onBeforeEnter);


function onBeforeEnter(event, data) {
console.log('review onBeforeEnter sendflow ', sendFlowService.state);
$log.debug('reviewController onBeforeEnter sendflow ', sendFlowService.state);

// Reset from last time
vm.memo = '';
vm.thirdParty = null;

defaults = configService.getDefaults();
sendFlowData = sendFlowService.state.getClone();
originWalletId = sendFlowData.fromWalletId;
if (typeof sendFlowData.amount === 'string') {
satoshis = parseInt(sendFlowData.amount, 10);
} else {
satoshis = sendFlowData.amount;
}
satoshis = parseInt(sendFlowData.amount, 10);
toAddress = sendFlowData.toAddress;
destinationWalletId = sendFlowData.toWalletId;

Expand All @@ -105,11 +101,14 @@ angular
vm.thirdParty = sendFlowData.thirdParty;
switch (vm.thirdParty.id) {
case 'shapeshift':
initShapeshift(function (err) {
initShapeshift(function onInitShapeshift(err) {
if (err) {
// Error stop here
ongoingProcess.set('connectingShapeshift', false);
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
popupService.showConfirm(gettextCatalog.getString('Shapeshift Error'), err.toString(), gettextCatalog.getString('Open') + " Shapeshift", gettextCatalog.getString('Go Back'), function onConfirm(hasConfirm) {
if (hasConfirm) {
externalLinkService.open("https://shapeshift.io");
}
$ionicHistory.goBack();
});
} else {
Expand All @@ -135,7 +134,6 @@ angular
config = configCache;
priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat';
vm.origin.currencyColor = (vm.originWallet.coin === 'btc' ? defaults.bitcoinWalletColor : defaults.bitcoinCashWalletColor);
console.log("coin", vm.originWallet.coin, vm.origin.currencyColor, config.bitcoinWalletColor, vm.originWallet.coin === 'btc');
unitFromSat = 1 / config.wallet.settings.unitToSatoshi;
}
updateSendAmounts();
Expand All @@ -152,18 +150,18 @@ angular
if (!tx || !vm.originWallet) return;

if (vm.paymentExpired) {
popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.', function () {
popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.', function onAlert() {
$ionicHistory.goBack();
}));
vm.sendStatus = '';
$timeout(function() {
$timeout(function onTimeout() {
$scope.$apply();
});
return;
}

ongoingProcess.set('creatingTx', true, statusChangeHandler);
getTxp(lodash.clone(tx), vm.originWallet, false, function(err, txp) {
getTxp(lodash.clone(tx), vm.originWallet, false, function onGetTxp(err, txp) {
ongoingProcess.set('creatingTx', false, statusChangeHandler);
if (err) return;

Expand All @@ -180,12 +178,12 @@ angular
if (!vm.originWallet.canSign() && !vm.originWallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key');

return walletService.onlyPublish(vm.originWallet, txp, function(err) {
return walletService.onlyPublish(vm.originWallet, txp, function onOnlyPublish(err) {
if (err) setSendError(err);
}, statusChangeHandler);
}

walletService.publishAndSign(vm.originWallet, txp, function(err, txp) {
walletService.publishAndSign(vm.originWallet, txp, function onPublishAndSign(err, txp) {
if (err) return setSendError(err);
if (config.confirmedTxsNotifications && config.confirmedTxsNotifications.enabled) {
txConfirmNotification.subscribe(vm.originWallet, {
Expand All @@ -199,7 +197,7 @@ angular
confirmTx(function(nok) {
if (nok) {
vm.sendStatus = '';
$timeout(function() {
$timeout(function onTimeout() {
$scope.$apply();
});
return;
Expand Down Expand Up @@ -256,7 +254,6 @@ angular
};

function createVanityTransaction(data) {
console.log('createVanityTransaction()');
var configFeeLevel = config.wallet.settings.feeLevel ? config.wallet.settings.feeLevel : 'normal';

// Grab stateParams
Expand All @@ -280,6 +277,9 @@ angular
txp: {},
};

if (vm.thirdParty && vm.thirdParty.id === "shapeshift") {
tx.toAddress = vm.thirdParty.toAddress;
}

if (data.stateParams.requiredFeeRate) {
vm.usingMerchantFee = true;
Expand All @@ -293,29 +293,35 @@ angular
var B = tx.coin === 'bch' ? bitcoreCash : bitcore;
var networkName;
try {
if (vm.destination.kind === 'wallet') { // This is a wallet-to-wallet transfer
// Final destination is a wallet, but this transaction must go to an address for the first stage of the exchange.
if (sendFlowData.thirdParty && sendFlowData.thirdParty.id === 'shapeshift') {
networkName = (new B.Address(tx.toAddress)).network.name;
tx.network = networkName;
setupTx(tx);

} else if (vm.destination.kind === 'wallet') { // This is a wallet-to-wallet transfer
ongoingProcess.set('generatingNewAddress', true);
var toWallet = profileService.getWallet(destinationWalletId);

// We need an address to send to, so we ask the walletService to create a new address for the toWallet.
console.log('Getting address for wallet...');
walletService.getAddress(toWallet, true, function onWalletAddress(err, addr) {
console.log('getAddress cb called', err);
if (err) {
$log.error('Error getting address for wallet.', err);
throw new Error(err.message);
}
ongoingProcess.set('generatingNewAddress', false);
tx.toAddress = addr;
networkName = (new B.Address(tx.toAddress)).network.name;
tx.network = networkName;
console.log('calling setupTx() for wallet.');
setupTx(tx);
});
} else { // This is a Wallet-to-address transfer
networkName = (new B.Address(tx.toAddress)).network.name;
tx.network = networkName;
console.log('calling setupTx() for address.');
setupTx(tx);
}
} catch (e) {
console.error('Error setting up tx', e);
$log.error('Error setting up tx', e);
var message = gettextCatalog.getString('Invalid address');
popupService.showAlert(null, message, function () {
$ionicHistory.nextViewOptions({
Expand Down Expand Up @@ -385,7 +391,7 @@ angular
}
txp.excludeUnconfirmedUtxos = !tx.spendUnconfirmed;
txp.dryRun = dryRun;
walletService.createTx(wallet, txp, function(err, ctxp) {
walletService.createTx(wallet, txp, function onCreateTx(err, ctxp) {
if (err) {
setSendError(err);
return cb(err);
Expand All @@ -405,7 +411,7 @@ angular
var walletStatus = null;
if (wallet.status && wallet.status.isValid) {
walletStatus = wallet.status;
} else if (wallet.cachedStatus.isValid) {
} else if (wallet.cachedStatus && wallet.cachedStatus.isValid) {
walletStatus = wallet.cachedStatus;
}

Expand Down Expand Up @@ -444,7 +450,7 @@ angular
}

// Check if the recipient is a contact
addressbookService.get(originCoin + address, function(err, contact) {
addressbookService.get(originCoin + address, function onGetContact(err, contact) {
if (!err && contact) {
handleDestinationAsAddressOfContact(contact);
} else {
Expand Down Expand Up @@ -517,7 +523,6 @@ angular
vm.destination.color = toWallet.color;
vm.destination.currency = toWallet.coin.toUpperCase();


ongoingProcess.set('connectingShapeshift', true);
walletService.getAddress(vm.originWallet, false, function onReturnWalletAddress(err, returnAddr) {
if (err) {
Expand All @@ -535,9 +540,8 @@ angular
if (err) {
return cb(err);
} else {
vm.destination.kind = 'shapeshift';
vm.destination.address = toAddress;
tx.toAddress = shapeshiftData.toAddress;
// Want it to appear like a wallet-to-wallet transfer, so don't set the main toAddress.
vm.thirdParty.toAddress = shapeshiftData.toAddress;
vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId;
vm.memoExpanded = !!vm.memo;
ongoingProcess.set('connectingShapeshift', false);
Expand Down Expand Up @@ -572,7 +576,6 @@ angular
}, 1000);

function setExpirationTime() {
console.log('setExpirationTime()');
var now = Math.floor(Date.now() / 1000);

if (now > expirationTime) {
Expand Down Expand Up @@ -690,7 +693,7 @@ angular
$timeout(function() {
$scope.$apply();
});
popupService.showAlert(gettextCatalog.getString('Error at confirm'), bwcError.msg(msg), function () {
popupService.showAlert(gettextCatalog.getString('Error at confirm'), bwcError.msg(msg), function onAlert() {
$ionicHistory.goBack();
});
};
Expand All @@ -702,7 +705,7 @@ angular
tx.displayAddress = tx.toAddress;
}

addressbookService.get(tx.coin+tx.toAddress, function(err, addr) { // Check if the recipient is a contact
addressbookService.get(tx.coin+tx.toAddress, function onGetContact(err, addr) { // Check if the recipient is a contact
if (!err && addr) {
tx.toName = addr.name;
tx.toEmail = addr.email;
Expand All @@ -721,7 +724,7 @@ angular
updateTx(tx, vm.originWallet, {
dryRun: true
}, function(err) {
$timeout(function() {
$timeout(function onTimeout() {
$scope.$apply();
}, 10);

Expand Down Expand Up @@ -848,7 +851,7 @@ angular
// refresh();

var feeServiceLevel = usingMerchantFee && vm.originWallet.coin == 'btc' ? 'urgent' : tx.feeLevel;
feeService.getFeeRate(vm.originWallet.coin, tx.network, feeServiceLevel, function(err, feeRate) {
feeService.getFeeRate(vm.originWallet.coin, tx.network, feeServiceLevel, function onGetFeeRate(err, feeRate) {
if (err) {
ongoingProcess.set('calculatingFee', false);
return cb(err);
Expand All @@ -867,7 +870,7 @@ angular
tx.feeRate = feeRate;
}

getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) {
getSendMaxInfo(lodash.clone(tx), wallet, function onGetSendmaxInfo(err, sendMaxInfo) {
if (err) {
ongoingProcess.set('calculatingFee', false);
var msg = gettextCatalog.getString('Error getting SendMax information');
Expand All @@ -881,7 +884,7 @@ angular
if (tx.sendMax && sendMaxInfo.amount == 0) {
ongoingProcess.set('calculatingFee', false);
setNotReady(gettextCatalog.getString('Insufficient confirmed funds'));
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'), function () {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'), function onAlert() {
$ionicHistory.goBack();
});
return cb('no_funds');
Expand All @@ -906,8 +909,7 @@ angular
return cb();
}

console.log('calling getTxp() from getSendMaxInfo cb.');
getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) {
getTxp(lodash.clone(tx), wallet, opts.dryRun, function onGetTxp(err, txp) {
ongoingProcess.set('calculatingFee', false);
if (err) {
if (err.message == 'Insufficient funds') {
Expand All @@ -919,7 +921,7 @@ angular
}

txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee);
txFormatService.formatAlternativeStr(wallet.coin, txp.fee, function(v) {
txFormatService.formatAlternativeStr(wallet.coin, txp.fee, function onFormatAlternativeStr(v) {
// txp.alternativeFeeStr = v;
// if (txp.alternativeFeeStr.substring(0, 4) == '0.00')
// txp.alternativeFeeStr = '< ' + txp.alternativeFeeStr;
Expand All @@ -928,8 +930,6 @@ angular
if (v.substring(0, 1) === "<") {
vm.feeLessThanACent = true;
}

console.log("fiat", vm.feeFiat);

});

Expand All @@ -939,14 +939,11 @@ angular
txp.feeToHigh = per > FEE_TOO_HIGH_LIMIT_PERCENTAGE;
vm.feeCrypto = (unitFromSat * txp.fee).toFixed(8);
vm.feeIsHigh = txp.feeToHigh;
console.log("crypto", vm.feeCrypto);


tx.txp[wallet.id] = txp;
$log.debug('Confirm. TX Fully Updated for wallet:' + wallet.id, tx);
vm.readyToSend = true;
updateSendAmounts();
console.log('readyToSend:', vm.readyToSend);
$scope.$apply();

return cb();
Expand Down
Loading

0 comments on commit 6369336

Please sign in to comment.