Display more info before purchase
This commit is contained in:
parent
0f7fc66c36
commit
4a62cf1fba
2 changed files with 58 additions and 14 deletions
|
|
@ -14,6 +14,11 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
|
||||||
externalLinkService.open(url);
|
externalLinkService.open(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _resetValues = function() {
|
||||||
|
$scope.totalAmountStr = $scope.amount = $scope.invoiceFee = $scope.networkFee = $scope.totalAmount = $scope.wallet = null;
|
||||||
|
createdTx = message = invoiceId = null;
|
||||||
|
};
|
||||||
|
|
||||||
var showErrorAndBack = function(title, msg) {
|
var showErrorAndBack = function(title, msg) {
|
||||||
title = title || gettextCatalog.getString('Error');
|
title = title || gettextCatalog.getString('Error');
|
||||||
$scope.sendStatus = '';
|
$scope.sendStatus = '';
|
||||||
|
|
@ -58,6 +63,30 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var satToFiat = function(sat, cb) {
|
||||||
|
txFormatService.toFiat(sat, $scope.currencyIsoCode, function(value) {
|
||||||
|
return cb(value);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var setTotalAmount = function(amountSat, invoiceFeeSat, networkFeeSat) {
|
||||||
|
satToFiat(amountSat, function(a) {
|
||||||
|
$scope.amount = Number(a);
|
||||||
|
|
||||||
|
satToFiat(invoiceFeeSat, function(i) {
|
||||||
|
$scope.invoiceFee = Number(i);
|
||||||
|
|
||||||
|
satToFiat(networkFeeSat, function(n) {
|
||||||
|
$scope.networkFee = Number(n);
|
||||||
|
$scope.totalAmount = $scope.amount + $scope.invoiceFee + $scope.networkFee;
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$digest();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var createInvoice = function(data, cb) {
|
var createInvoice = function(data, cb) {
|
||||||
mercadoLibreService.createBitPayInvoice(data, function(err, dataInvoice) {
|
mercadoLibreService.createBitPayInvoice(data, function(err, dataInvoice) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -184,7 +213,9 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
|
||||||
'leading': true
|
'leading': true
|
||||||
});
|
});
|
||||||
|
|
||||||
var initialize = function(wallet, parsedAmount) {
|
var initialize = function(wallet) {
|
||||||
|
var parsedAmount = txFormatService.parseAmount(amount, currency);
|
||||||
|
$scope.currencyIsoCode = parsedAmount.currency;
|
||||||
$scope.amountUnitStr = parsedAmount.amountUnitStr;
|
$scope.amountUnitStr = parsedAmount.amountUnitStr;
|
||||||
var dataSrc = {
|
var dataSrc = {
|
||||||
amount: parsedAmount.amount,
|
amount: parsedAmount.amount,
|
||||||
|
|
@ -198,16 +229,18 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
|
||||||
showErrorAndBack(err.title, err.message);
|
showErrorAndBack(err.title, err.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Sometimes API does not return this element;
|
||||||
|
invoice['buyerPaidBtcMinerFee'] = invoice.buyerPaidBtcMinerFee || 0;
|
||||||
|
var invoiceFeeSat = (invoice.buyerPaidBtcMinerFee * 100000000).toFixed();
|
||||||
|
|
||||||
message = gettextCatalog.getString("Mercado Libre Gift Card {{amountStr}}", {
|
message = gettextCatalog.getString("{{amountStr}} for Mercado Livre Brazil Gift Card", {
|
||||||
amountStr: $scope.amountUnitStr
|
amountStr: $scope.amountUnitStr
|
||||||
});
|
});
|
||||||
|
|
||||||
createTx(wallet, invoice, message, function(err, ctxp) {
|
createTx(wallet, invoice, message, function(err, ctxp) {
|
||||||
ongoingProcess.set('loadingTxInfo', false);
|
ongoingProcess.set('loadingTxInfo', false);
|
||||||
if (err) {
|
if (err) {
|
||||||
// Clear variables
|
_resetValues();
|
||||||
createdTx = message = $scope.totalFeeStr = $scope.totalAmountStr = $scope.wallet = null;
|
|
||||||
showError(err.title, err.message);
|
showError(err.title, err.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -225,8 +258,8 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
|
||||||
invoiceUrl: invoice.url,
|
invoiceUrl: invoice.url,
|
||||||
invoiceTime: invoice.invoiceTime
|
invoiceTime: invoice.invoiceTime
|
||||||
};
|
};
|
||||||
$scope.totalFeeStr = txFormatService.formatAmountStr(ctxp.fee);
|
$scope.totalAmountStr = txFormatService.formatAmountStr(ctxp.amount);
|
||||||
$scope.totalAmountStr = txFormatService.formatAmountStr(ctxp.amount + ctxp.fee);
|
setTotalAmount(parsedAmount.amountSat, invoiceFeeSat, ctxp.fee);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -295,8 +328,7 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
|
||||||
|
|
||||||
$scope.onWalletSelect = function(wallet) {
|
$scope.onWalletSelect = function(wallet) {
|
||||||
$scope.wallet = wallet;
|
$scope.wallet = wallet;
|
||||||
var parsedAmount = txFormatService.parseAmount(amount, currency);
|
initialize(wallet);
|
||||||
initialize(wallet, parsedAmount);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.goBackHome = function() {
|
$scope.goBackHome = function() {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<div class="item item-icon-right" ng-click="showWalletSelector()">
|
<div class="item item-icon-right" ng-click="showWalletSelector()">
|
||||||
<div class="label">From</div>
|
<div class="label" translate>From</div>
|
||||||
<div class="wallet">
|
<div class="wallet">
|
||||||
<i class="icon big-icon-svg">
|
<i class="icon big-icon-svg">
|
||||||
<img src="img/icon-wallet.svg" ng-class="{'wallet-background-color-default': !wallet.color}" ng-style="{'background-color': wallet.color}" class="bg">
|
<img src="img/icon-wallet.svg" ng-class="{'wallet-background-color-default': !wallet.color}" ng-style="{'background-color': wallet.color}" class="bg">
|
||||||
|
|
@ -34,21 +34,33 @@
|
||||||
</div>
|
</div>
|
||||||
<i class="icon bp-arrow-right"></i>
|
<i class="icon bp-arrow-right"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-show="totalAmountStr">
|
<div ng-show="totalAmountStr">
|
||||||
<div class="item item-divider" translate>
|
<div class="item item-divider" translate>
|
||||||
Details
|
Details
|
||||||
</div>
|
</div>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<span translate>Network fee</span>
|
<span translate>Gift card</span>
|
||||||
<span class="item-note">
|
<span class="item-note">
|
||||||
{{totalFeeStr}}
|
{{amount | currency:'$ ':2}}<span ng-if="amount"> {{currencyIsoCode}}</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<span translate>Total to pay</span>
|
<span translate>Invoice Fee</span>
|
||||||
<span class="item-note">
|
<span class="item-note">
|
||||||
{{totalAmountStr}}
|
<span>{{invoiceFee | currency:'$ ':2}}<span ng-if="invoiceFee"> {{currencyIsoCode}}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="item">
|
||||||
|
<span translate>Network Fee</span>
|
||||||
|
<span class="item-note">
|
||||||
|
<span>{{networkFee | currency:'$ ':2}}<span ng-if="networkFee"> {{currencyIsoCode}}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="item">
|
||||||
|
<span translate>Total</span>
|
||||||
|
<span class="item-note">
|
||||||
|
<span ng-if="totalAmount">{{totalAmount | currency:'$ ':2}} {{currencyIsoCode}}</span>
|
||||||
|
<span ng-if="totalAmountStr">({{totalAmountStr}})</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue