Solved conflicts

This commit is contained in:
Jean-Baptiste Dominguez 2018-09-26 15:09:14 +02:00
commit 390f8b2427
2 changed files with 41 additions and 49 deletions

View file

@ -49,7 +49,7 @@ angular
vm.sendingTitle = gettextCatalog.getString('You are sending'); vm.sendingTitle = gettextCatalog.getString('You are sending');
vm.sendStatus = ''; vm.sendStatus = '';
vm.showAddress = true; vm.showAddress = true;
vm.thirdParty = false; vm.thirdParty = null;
vm.wallet = null; vm.wallet = null;
vm.memoExpanded = false; vm.memoExpanded = false;
@ -81,18 +81,11 @@ angular
function onBeforeEnter(event, data) { function onBeforeEnter(event, data) {
console.log('review onBeforeEnter sendflow ', sendFlowService.state); $log.debug('reviewController onBeforeEnter sendflow ', sendFlowService.state);
// Reset from last time
vm.memo = '';
defaults = configService.getDefaults(); defaults = configService.getDefaults();
sendFlowData = sendFlowService.state.getClone(); sendFlowData = sendFlowService.state.getClone();
originWalletId = sendFlowData.fromWalletId; originWalletId = sendFlowData.fromWalletId;
if (typeof sendFlowData.amount === 'string') { satoshis = parseInt(sendFlowData.amount, 10);
satoshis = parseInt(sendFlowData.amount, 10);
} else {
satoshis = sendFlowData.amount;
}
toAddress = sendFlowData.toAddress; toAddress = sendFlowData.toAddress;
destinationWalletId = sendFlowData.toWalletId; destinationWalletId = sendFlowData.toWalletId;
@ -105,11 +98,11 @@ angular
vm.thirdParty = sendFlowData.thirdParty; vm.thirdParty = sendFlowData.thirdParty;
switch (vm.thirdParty.id) { switch (vm.thirdParty.id) {
case 'shapeshift': case 'shapeshift':
initShapeshift(function (err) { initShapeshift(function onInitShapeshift(err) {
if (err) { if (err) {
// Error stop here // Error stop here
ongoingProcess.set('connectingShapeshift', false); ongoingProcess.set('connectingShapeshift', false);
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () { popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function onAlert() {
$ionicHistory.goBack(); $ionicHistory.goBack();
}); });
} else { } else {
@ -135,7 +128,6 @@ angular
config = configCache; config = configCache;
priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat'; priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat';
vm.origin.currencyColor = (vm.originWallet.coin === 'btc' ? defaults.bitcoinWalletColor : defaults.bitcoinCashWalletColor); 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; unitFromSat = 1 / config.wallet.settings.unitToSatoshi;
} }
updateSendAmounts(); updateSendAmounts();
@ -152,18 +144,18 @@ angular
if (!tx || !vm.originWallet) return; if (!tx || !vm.originWallet) return;
if (vm.paymentExpired) { 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(); $ionicHistory.goBack();
})); }));
vm.sendStatus = ''; vm.sendStatus = '';
$timeout(function() { $timeout(function onTimeout() {
$scope.$apply(); $scope.$apply();
}); });
return; return;
} }
ongoingProcess.set('creatingTx', true, statusChangeHandler); 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); ongoingProcess.set('creatingTx', false, statusChangeHandler);
if (err) return; if (err) return;
@ -180,12 +172,12 @@ angular
if (!vm.originWallet.canSign() && !vm.originWallet.isPrivKeyExternal()) { if (!vm.originWallet.canSign() && !vm.originWallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key'); $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); if (err) setSendError(err);
}, statusChangeHandler); }, statusChangeHandler);
} }
walletService.publishAndSign(vm.originWallet, txp, function(err, txp) { walletService.publishAndSign(vm.originWallet, txp, function onPublishAndSign(err, txp) {
if (err) return setSendError(err); if (err) return setSendError(err);
if (config.confirmedTxsNotifications && config.confirmedTxsNotifications.enabled) { if (config.confirmedTxsNotifications && config.confirmedTxsNotifications.enabled) {
txConfirmNotification.subscribe(vm.originWallet, { txConfirmNotification.subscribe(vm.originWallet, {
@ -199,7 +191,7 @@ angular
confirmTx(function(nok) { confirmTx(function(nok) {
if (nok) { if (nok) {
vm.sendStatus = ''; vm.sendStatus = '';
$timeout(function() { $timeout(function onTimeout() {
$scope.$apply(); $scope.$apply();
}); });
return; return;
@ -256,7 +248,6 @@ angular
}; };
function createVanityTransaction(data) { function createVanityTransaction(data) {
console.log('createVanityTransaction()');
var configFeeLevel = config.wallet.settings.feeLevel ? config.wallet.settings.feeLevel : 'normal'; var configFeeLevel = config.wallet.settings.feeLevel ? config.wallet.settings.feeLevel : 'normal';
// Grab stateParams // Grab stateParams
@ -280,6 +271,9 @@ angular
txp: {}, txp: {},
}; };
if (vm.thirdParty && vm.thirdParty.id === "shapeshift") {
tx.toAddress = vm.thirdParty.toAddress;
}
if (data.stateParams.requiredFeeRate) { if (data.stateParams.requiredFeeRate) {
vm.usingMerchantFee = true; vm.usingMerchantFee = true;
@ -293,29 +287,35 @@ angular
var B = tx.coin === 'bch' ? bitcoreCash : bitcore; var B = tx.coin === 'bch' ? bitcoreCash : bitcore;
var networkName; var networkName;
try { 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); ongoingProcess.set('generatingNewAddress', true);
var toWallet = profileService.getWallet(destinationWalletId); 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. // 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) { 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); ongoingProcess.set('generatingNewAddress', false);
tx.toAddress = addr; tx.toAddress = addr;
networkName = (new B.Address(tx.toAddress)).network.name; networkName = (new B.Address(tx.toAddress)).network.name;
tx.network = networkName; tx.network = networkName;
console.log('calling setupTx() for wallet.');
setupTx(tx); setupTx(tx);
}); });
} else { // This is a Wallet-to-address transfer } else { // This is a Wallet-to-address transfer
networkName = (new B.Address(tx.toAddress)).network.name; networkName = (new B.Address(tx.toAddress)).network.name;
tx.network = networkName; tx.network = networkName;
console.log('calling setupTx() for address.');
setupTx(tx); setupTx(tx);
} }
} catch (e) { } catch (e) {
console.error('Error setting up tx', e); $log.error('Error setting up tx', e);
var message = gettextCatalog.getString('Invalid address'); var message = gettextCatalog.getString('Invalid address');
popupService.showAlert(null, message, function () { popupService.showAlert(null, message, function () {
$ionicHistory.nextViewOptions({ $ionicHistory.nextViewOptions({
@ -385,7 +385,7 @@ angular
} }
txp.excludeUnconfirmedUtxos = !tx.spendUnconfirmed; txp.excludeUnconfirmedUtxos = !tx.spendUnconfirmed;
txp.dryRun = dryRun; txp.dryRun = dryRun;
walletService.createTx(wallet, txp, function(err, ctxp) { walletService.createTx(wallet, txp, function onCreateTx(err, ctxp) {
if (err) { if (err) {
setSendError(err); setSendError(err);
return cb(err); return cb(err);
@ -405,7 +405,7 @@ angular
var walletStatus = null; var walletStatus = null;
if (wallet.status && wallet.status.isValid) { if (wallet.status && wallet.status.isValid) {
walletStatus = wallet.status; walletStatus = wallet.status;
} else if (wallet.cachedStatus.isValid) { } else if (wallet.cachedStatus && wallet.cachedStatus.isValid) {
walletStatus = wallet.cachedStatus; walletStatus = wallet.cachedStatus;
} }
@ -444,7 +444,7 @@ angular
} }
// Check if the recipient is a contact // 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) { if (!err && contact) {
handleDestinationAsAddressOfContact(contact); handleDestinationAsAddressOfContact(contact);
} else { } else {
@ -517,7 +517,6 @@ angular
vm.destination.color = toWallet.color; vm.destination.color = toWallet.color;
vm.destination.currency = toWallet.coin.toUpperCase(); vm.destination.currency = toWallet.coin.toUpperCase();
ongoingProcess.set('connectingShapeshift', true); ongoingProcess.set('connectingShapeshift', true);
walletService.getAddress(vm.originWallet, false, function onReturnWalletAddress(err, returnAddr) { walletService.getAddress(vm.originWallet, false, function onReturnWalletAddress(err, returnAddr) {
if (err) { if (err) {
@ -535,9 +534,8 @@ angular
if (err) { if (err) {
return cb(err); return cb(err);
} else { } else {
vm.destination.kind = 'shapeshift'; // Want it to appear like a wallet-to-wallet transfer, so don't set the main toAddress.
vm.destination.address = toAddress; vm.thirdParty.toAddress = shapeshiftData.toAddress;
tx.toAddress = shapeshiftData.toAddress;
vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId; vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId;
vm.memoExpanded = !!vm.memo; vm.memoExpanded = !!vm.memo;
ongoingProcess.set('connectingShapeshift', false); ongoingProcess.set('connectingShapeshift', false);
@ -572,7 +570,6 @@ angular
}, 1000); }, 1000);
function setExpirationTime() { function setExpirationTime() {
console.log('setExpirationTime()');
var now = Math.floor(Date.now() / 1000); var now = Math.floor(Date.now() / 1000);
if (now > expirationTime) { if (now > expirationTime) {
@ -690,7 +687,7 @@ angular
$timeout(function() { $timeout(function() {
$scope.$apply(); $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(); $ionicHistory.goBack();
}); });
}; };
@ -702,7 +699,7 @@ angular
tx.displayAddress = tx.toAddress; 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) { if (!err && addr) {
tx.toName = addr.name; tx.toName = addr.name;
tx.toEmail = addr.email; tx.toEmail = addr.email;
@ -721,7 +718,7 @@ angular
updateTx(tx, vm.originWallet, { updateTx(tx, vm.originWallet, {
dryRun: true dryRun: true
}, function(err) { }, function(err) {
$timeout(function() { $timeout(function onTimeout() {
$scope.$apply(); $scope.$apply();
}, 10); }, 10);
@ -848,7 +845,7 @@ angular
// refresh(); // refresh();
var feeServiceLevel = usingMerchantFee && vm.originWallet.coin == 'btc' ? 'urgent' : tx.feeLevel; 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) { if (err) {
ongoingProcess.set('calculatingFee', false); ongoingProcess.set('calculatingFee', false);
return cb(err); return cb(err);
@ -867,7 +864,7 @@ angular
tx.feeRate = feeRate; tx.feeRate = feeRate;
} }
getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) { getSendMaxInfo(lodash.clone(tx), wallet, function onGetSendmaxInfo(err, sendMaxInfo) {
if (err) { if (err) {
ongoingProcess.set('calculatingFee', false); ongoingProcess.set('calculatingFee', false);
var msg = gettextCatalog.getString('Error getting SendMax information'); var msg = gettextCatalog.getString('Error getting SendMax information');
@ -881,7 +878,7 @@ angular
if (tx.sendMax && sendMaxInfo.amount == 0) { if (tx.sendMax && sendMaxInfo.amount == 0) {
ongoingProcess.set('calculatingFee', false); ongoingProcess.set('calculatingFee', false);
setNotReady(gettextCatalog.getString('Insufficient confirmed funds')); 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(); $ionicHistory.goBack();
}); });
return cb('no_funds'); return cb('no_funds');
@ -906,8 +903,7 @@ angular
return cb(); return cb();
} }
console.log('calling getTxp() from getSendMaxInfo cb.'); getTxp(lodash.clone(tx), wallet, opts.dryRun, function onGetTxp(err, txp) {
getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) {
ongoingProcess.set('calculatingFee', false); ongoingProcess.set('calculatingFee', false);
if (err) { if (err) {
if (err.message == 'Insufficient funds') { if (err.message == 'Insufficient funds') {
@ -919,7 +915,7 @@ angular
} }
txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee); 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; // txp.alternativeFeeStr = v;
// if (txp.alternativeFeeStr.substring(0, 4) == '0.00') // if (txp.alternativeFeeStr.substring(0, 4) == '0.00')
// txp.alternativeFeeStr = '< ' + txp.alternativeFeeStr; // txp.alternativeFeeStr = '< ' + txp.alternativeFeeStr;
@ -929,8 +925,6 @@ angular
vm.feeLessThanACent = true; vm.feeLessThanACent = true;
} }
console.log("fiat", vm.feeFiat);
}); });
var per = (txp.fee / (txp.amount + txp.fee) * 100); var per = (txp.fee / (txp.amount + txp.fee) * 100);
@ -939,14 +933,11 @@ angular
txp.feeToHigh = per > FEE_TOO_HIGH_LIMIT_PERCENTAGE; txp.feeToHigh = per > FEE_TOO_HIGH_LIMIT_PERCENTAGE;
vm.feeCrypto = (unitFromSat * txp.fee).toFixed(8); vm.feeCrypto = (unitFromSat * txp.fee).toFixed(8);
vm.feeIsHigh = txp.feeToHigh; vm.feeIsHigh = txp.feeToHigh;
console.log("crypto", vm.feeCrypto);
tx.txp[wallet.id] = txp; tx.txp[wallet.id] = txp;
$log.debug('Confirm. TX Fully Updated for wallet:' + wallet.id, tx); $log.debug('Confirm. TX Fully Updated for wallet:' + wallet.id, tx);
vm.readyToSend = true; vm.readyToSend = true;
updateSendAmounts(); updateSendAmounts();
console.log('readyToSend:', vm.readyToSend);
$scope.$apply(); $scope.$apply();
return cb(); return cb();

View file

@ -63,6 +63,7 @@ angular
} else if (amount > service.marketData.maxLimit) { } else if (amount > service.marketData.maxLimit) {
cb(new Error(gettextCatalog.getString('Amount is above the limit'))); cb(new Error(gettextCatalog.getString('Amount is above the limit')));
} else { } else {
// Init service data // Init service data
service.withdrawalAddress = withdrawalAddress; service.withdrawalAddress = withdrawalAddress;
service.returnAddress = returnAddress; service.returnAddress = returnAddress;
@ -72,7 +73,7 @@ angular
// Check the address // Check the address
shapeshiftApiService shapeshiftApiService
.ValidateAddress(withdrawalAddress, coinOut) .ValidateAddress(returnAddress, coinOut)
.then(function onSuccess(response) { .then(function onSuccess(response) {
if (response && response.isvalid) { if (response && response.isvalid) {
// Prepare the transaction shapeshift side // Prepare the transaction shapeshift side