Skip to content

Commit 8ed3bb5

Browse files
authored
Merge pull request bitpay#6684 from cmgustavo/bug/send-max-fee-levels
Bug/send max fee levels
2 parents 92887ad + 9f9bb1b commit 8ed3bb5

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

src/js/controllers/amount.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
309309
if (a) {
310310
$scope.alternativeAmount = txFormatService.formatAmount(a * unitToSatoshi, true);
311311
} else {
312-
$scope.alternativeAmount = 'N/A'; //TODO
312+
$scope.alternativeAmount = 'N/A'; //TODO
313313
$scope.allowSend = false;
314314
}
315315
} else {
@@ -369,7 +369,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
369369
id: _id,
370370
amount: $scope.useSendMax ? null : _amount,
371371
currency: unit.id.toUpperCase(),
372-
coin: coin,
372+
coin: $scope.useSendMax ? null : coin,
373373
useSendMax: $scope.useSendMax
374374
});
375375
} else {
@@ -388,7 +388,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
388388
toName: $scope.toName,
389389
toEmail: $scope.toEmail,
390390
toColor: $scope.toColor,
391-
coin: coin,
391+
coin: $scope.useSendMax ? null : coin,
392392
useSendMax: $scope.useSendMax
393393
});
394394
}

src/js/controllers/confirm.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
2828
function refresh() {
2929
$timeout(function() {
3030
$scope.$apply();
31-
}, 1);
31+
}, 10);
3232
}
3333

3434

@@ -119,11 +119,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
119119
});
120120
};
121121

122-
// TODO: Default fee level for BCH
123-
if (data.stateParams.coin == 'bch') {
124-
configFeeLevel = 'normal';
125-
}
126-
127122
// Setup $scope
128123

129124
// Grab stateParams
@@ -147,6 +142,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
147142
txp: {},
148143
};
149144

145+
if (tx.coin && tx.coin == 'bch') tx.feeLevel = 'normal';
146+
150147
// Other Scope vars
151148
$scope.isCordova = isCordova;
152149
$scope.isWindowsPhoneApp = isWindowsPhoneApp;
@@ -230,6 +227,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
230227
};
231228

232229
function updateTx(tx, wallet, opts, cb) {
230+
ongoingProcess.set('calculatingFee', true);
233231

234232
if (opts.clearCache) {
235233
tx.txp = {};
@@ -253,19 +251,23 @@ angular.module('copayApp.controllers').controller('confirmController', function(
253251
refresh();
254252

255253
// End of quick refresh, before wallet is selected.
256-
if (!wallet) return cb();
254+
if (!wallet) {
255+
ongoingProcess.set('calculatingFee', false);
256+
return cb();
257+
}
257258

258259
feeService.getFeeRate(wallet.coin, tx.network, tx.feeLevel, function(err, feeRate) {
259-
if (err) return cb(err);
260+
if (err) {
261+
ongoingProcess.set('calculatingFee', false);
262+
return cb(err);
263+
}
260264

261265
if (!usingCustomFee) tx.feeRate = feeRate;
262266
tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
263267

264-
if (!wallet)
265-
return cb();
266-
267268
getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) {
268269
if (err) {
270+
ongoingProcess.set('calculatingFee', false);
269271
var msg = gettextCatalog.getString('Error getting SendMax information');
270272
return setSendError(msg);
271273
}
@@ -275,6 +277,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
275277
$log.debug('Send max info', sendMaxInfo);
276278

277279
if (tx.sendMax && sendMaxInfo.amount == 0) {
280+
ongoingProcess.set('calculatingFee', false);
278281
setNoWallet(gettextCatalog.getString('Insufficient funds'));
279282
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
280283
return cb('no_funds');
@@ -283,17 +286,22 @@ angular.module('copayApp.controllers').controller('confirmController', function(
283286
tx.sendMaxInfo = sendMaxInfo;
284287
tx.toAmount = tx.sendMaxInfo.amount;
285288
updateAmount();
289+
ongoingProcess.set('calculatingFee', false);
286290
showSendMaxWarning(wallet, sendMaxInfo);
287291
}
288292

289293
// txp already generated for this wallet?
290294
if (tx.txp[wallet.id]) {
295+
ongoingProcess.set('calculatingFee', false);
291296
refresh();
292297
return cb();
293298
}
294299

295300
getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) {
296-
if (err) return cb(err);
301+
ongoingProcess.set('calculatingFee', false);
302+
if (err) {
303+
return cb(err);
304+
}
297305

298306
txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee);
299307
txFormatService.formatAlternativeStr(wallet.coin, txp.fee, function(v) {
@@ -425,6 +433,11 @@ angular.module('copayApp.controllers').controller('confirmController', function(
425433

426434
$scope.wallet = wallet;
427435

436+
// If select another wallet
437+
tx.coin = wallet.coin;
438+
tx.feeLevel = wallet.coin == 'bch' ? 'normal' : configFeeLevel;
439+
usingCustomFee = null;
440+
428441
setButtonText(wallet.credentials.m > 1, !!tx.paypro);
429442

430443
if (tx.paypro)

src/js/services/feeService.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
1717

1818
var cache = {
1919
updateTs: 0,
20+
coin: ''
2021
};
2122

2223
root.getCurrentFeeLevel = function() {
@@ -60,7 +61,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
6061
root.getFeeLevels = function(coin, cb) {
6162
coin = coin || 'btc';
6263

63-
if (cache.updateTs > Date.now() - CACHE_TIME_TS * 1000) {
64+
if (cache.coin == coin && cache.updateTs > Date.now() - CACHE_TIME_TS * 1000) {
6465
return cb(null, cache.data, true);
6566
}
6667

@@ -73,6 +74,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
7374
}
7475

7576
cache.updateTs = Date.now();
77+
cache.coin = coin;
7678
cache.data = {
7779
'livenet': levelsLivenet,
7880
'testnet': levelsTestnet

0 commit comments

Comments
 (0)