add merchant data in tx proposals

This commit is contained in:
Matias Alejo Garcia 2014-11-20 03:10:43 -03:00
parent d4a0f5c008
commit 088a616736
6 changed files with 77 additions and 82 deletions

View File

@ -13,6 +13,7 @@ angular.module('copayApp.controllers').controller('SendController',
$rootScope.title = 'Send'; $rootScope.title = 'Send';
$scope.loading = false; $scope.loading = false;
$scope.error = $scope.success = null;
var satToUnit = 1 / w.settings.unitToSatoshi; var satToUnit = 1 / w.settings.unitToSatoshi;
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit; $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
$scope.unitToBtc = w.settings.unitToSatoshi / bitcore.util.COIN; $scope.unitToBtc = w.settings.unitToSatoshi / bitcore.util.COIN;
@ -145,15 +146,7 @@ angular.module('copayApp.controllers').controller('SendController',
if (w.requiresMultipleSignatures()) { if (w.requiresMultipleSignatures()) {
$scope.loading = false; $scope.loading = false;
var message = 'The transaction proposal has been created'; notification.success('Success', 'The transaction proposal created');
if (merchantData) {
if (merchantData.pr.ca) {
message += ' This payment protocol transaction' + ' has been verified through ' + merchantData.pr.ca + '.';
}
message += merchantData.pr.pd.memo;
message += ' Merchant: ' + merchantData.pr.pd.payment_url;
}
$scope.success = message;
$scope.loadTxs(); $scope.loadTxs();
} else { } else {
w.sendTx(ntxid, function(txid, merchantData) { w.sendTx(ntxid, function(txid, merchantData) {
@ -362,7 +355,6 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.submitAddressBook = function(form) { $scope.submitAddressBook = function(form) {
if (form.$invalid) { if (form.$invalid) {
scope.error = 'Please complete required fields';
return; return;
} }
var entry = { var entry = {
@ -409,14 +401,15 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.send = function(ntxid, cb) { $scope.send = function(ntxid, cb) {
$scope.error = $scope.success = null;
$scope.loading = true; $scope.loading = true;
$rootScope.txAlertCount = 0; $rootScope.txAlertCount = 0;
w.sendTx(ntxid, function(txid, merchantData) { w.sendTx(ntxid, function(txid, merchantData) {
if (!txid) { if (!txid) {
$scope.error = 'There was an error sending the transaction'; notification.error('Error', 'There was an error sending the transaction');
} else { } else {
if (!merchantData) { if (!merchantData) {
$scope.success = 'Transaction broadcasted!'; notification.success('Success', 'Transaction broadcasted!');
} else { } else {
var message = 'Transaction ID: ' + txid; var message = 'Transaction ID: ' + txid;
if (merchantData.pr.ca) { if (merchantData.pr.ca) {
@ -424,7 +417,7 @@ angular.module('copayApp.controllers').controller('SendController',
} }
message += ' Message from server: ' + merchantData.ack.memo; message += ' Message from server: ' + merchantData.ack.memo;
message += ' For merchant: ' + merchantData.pr.pd.payment_url; message += ' For merchant: ' + merchantData.pr.pd.payment_url;
$scope.success = 'Transaction sent' + message; notification.success('Success', 'Transaction sent' + message);
} }
} }
@ -435,15 +428,15 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.sign = function(ntxid) { $scope.sign = function(ntxid) {
$scope.loading = true; $scope.loading = true;
$scope.error = $scope.success = null;
try { try {
w.sign(ntxid); w.sign(ntxid);
} catch (e) { } catch (e) {
$scope.error = 'There was an error signing the transaction'; notification.error('Error','There was an error signing the transaction');
$scope.loadTxs(); $scope.loadTxs();
return; return;
} }
$scope.error = undefined;
var p = w.txProposals.getTxProposal(ntxid); var p = w.txProposals.getTxProposal(ntxid);
if (p.builder.isFullySigned()) { if (p.builder.isFullySigned()) {
@ -465,16 +458,15 @@ angular.module('copayApp.controllers').controller('SendController',
}; };
$scope.clearMerchant = function(callback) { $scope.clearMerchant = function(callback) {
var scope = $scope;
// TODO: Find a better way of detecting // TODO: Find a better way of detecting
// whether we're in the Send scope or not. // whether we're in the Send scope or not.
if (!scope.sendForm || !scope.sendForm.address) { if (!$scope.sendForm || !$scope.sendForm.address) {
delete $rootScope.merchant; delete $rootScope.merchant;
$rootScope.merchantError = false; $rootScope.merchantError = false;
if (callback) callback(); if (callback) callback();
return; return;
} }
var val = scope.sendForm.address.$viewValue || ''; var val = $scope.sendForm.address.$viewValue || '';
var uri; var uri;
// If we're setting the domain, ignore the change. // If we're setting the domain, ignore the change.
if ($rootScope.merchant && $rootScope.merchant.domain && val === $rootScope.merchant.domain) { if ($rootScope.merchant && $rootScope.merchant.domain && val === $rootScope.merchant.domain) {
@ -491,8 +483,8 @@ angular.module('copayApp.controllers').controller('SendController',
} }
if (!uri || !uri.merchant) { if (!uri || !uri.merchant) {
delete $rootScope.merchant; delete $rootScope.merchant;
scope.sendForm.amount.$setViewValue(''); $scope.sendForm.amount.$setViewValue('');
scope.sendForm.amount.$render(); $scope.sendForm.amount.$render();
if (callback) callback(); if (callback) callback();
if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') { if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') {
$rootScope.$apply(); $rootScope.$apply();
@ -501,10 +493,10 @@ angular.module('copayApp.controllers').controller('SendController',
}; };
$scope.onChanged = function() { $scope.onChanged = function() {
var scope = $scope; var value = $scope.address || '';
var value = scope.address || '';
var uri; var uri;
$scope.error = $scope.success = null;
// If we're setting the domain, ignore the change. // If we're setting the domain, ignore the change.
if ($rootScope.merchant && $rootScope.merchant.domain && value === $rootScope.merchant.domain) { if ($rootScope.merchant && $rootScope.merchant.domain && value === $rootScope.merchant.domain) {
return; return;
@ -528,28 +520,28 @@ angular.module('copayApp.controllers').controller('SendController',
} }
}; };
scope.fetchingURL = uri.merchant; $scope.fetchingURL = uri.merchant;
scope.loading = true; $scope.loading = true;
apply(); apply();
var timeout = setTimeout(function() { var timeout = setTimeout(function() {
timeout = null; timeout = null;
scope.fetchingURL = null; $scope.fetchingURL = null;
scope.loading = false; $scope.loading = false;
scope.sendForm.address.$setViewValue(''); $scope.sendForm.address.$setViewValue('');
scope.sendForm.address.$render(); $scope.sendForm.address.$render();
scope.sendForm.address.$isValid = false; $scope.sendForm.address.$isValid = false;
scope.error = 'Payment server timed out'; $scope.error = 'Payment server timed out';
apply(); apply();
}, 10 * 1000); }, 10 * 1000);
// Payment Protocol URI (BIP-72) // Payment Protocol URI (BIP-72)
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) { $scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
if (!timeout) return; if (!timeout) return;
clearTimeout(timeout); clearTimeout(timeout);
scope.loading = false; $scope.loading = false;
scope.fetchingURL = null; $scope.fetchingURL = null;
apply(); apply();
var balance = $rootScope.availableBalance; var balance = $rootScope.availableBalance;
@ -561,28 +553,29 @@ angular.module('copayApp.controllers').controller('SendController',
if (err) { if (err) {
if (err.amount) { if (err.amount) {
scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi); $scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi);
scope.sendForm.amount.$render(); $scope.sendForm.amount.$render();
scope.sendForm.amount.$isValid = false; $scope.sendForm.amount.$isValid = false;
scope.notEnoughAmount = true; $scope.notEnoughAmount = true;
$rootScope.merchantError = true; $rootScope.merchantError = true;
var lastAddr = scope.sendForm.address.$viewValue; var lastAddr = $scope.sendForm.address.$viewValue;
var unregister = scope.$watch('address', function() { var unregister = $scope.$watch('address', function() {
if (scope.sendForm.address.$viewValue !== lastAddr) { if ($scope.sendForm.address.$viewValue !== lastAddr) {
delete $rootScope.merchantError; delete $rootScope.merchantError;
scope.sendForm.amount.$setViewValue(''); $scope.sendForm.amount.$setViewValue('');
scope.sendForm.amount.$render(); $scope.sendForm.amount.$render();
unregister(); unregister();
apply(); apply();
} }
}); });
} else { } else {
scope.sendForm.address.$setViewValue(''); $scope.sendForm.address.$setViewValue('');
scope.sendForm.address.$render(); $scope.sendForm.address.$render();
} }
scope.sendForm.address.$isValid = false; $scope.sendForm.address.$isValid = false;
copay.logger.error(err);
scope.error = err.message || 'Bad payment server'; $scope.error = 'Could not fetch payment request';
apply(); apply();
return; return;
@ -593,18 +586,18 @@ angular.module('copayApp.controllers').controller('SendController',
merchantData.unitTotal = (+merchantData.total / w.settings.unitToSatoshi) + ''; merchantData.unitTotal = (+merchantData.total / w.settings.unitToSatoshi) + '';
merchantData.expiration = new Date( merchantData.expiration = new Date(
merchantData.pr.pd.expires * 1000).toISOString(); merchantData.pr.pd.expires * 1000);
merchantData.domain = domain; merchantData.domain = domain;
$rootScope.merchant = merchantData; $rootScope.merchant = merchantData;
scope.sendForm.address.$setViewValue(domain); $scope.sendForm.address.$setViewValue(domain);
scope.sendForm.address.$render(); $scope.sendForm.address.$render();
scope.sendForm.address.$isValid = true; $scope.sendForm.address.$isValid = true;
scope.sendForm.amount.$setViewValue(merchantData.unitTotal); $scope.sendForm.amount.$setViewValue(merchantData.unitTotal);
scope.sendForm.amount.$render(); $scope.sendForm.amount.$render();
scope.sendForm.amount.$isValid = true; $scope.sendForm.amount.$isValid = true;
// If the address changes to a non-payment-protocol one, // If the address changes to a non-payment-protocol one,
// delete the `merchant` property from the scope. // delete the `merchant` property from the scope.
@ -613,9 +606,6 @@ angular.module('copayApp.controllers').controller('SendController',
}); });
apply(); apply();
scope.success = 'Payment Request:' + merchantData.unitTotal +
' ' + w.settings.unitName + '. ' + (merchantData.pr.pd.memo || '');
}); });
}; };
}); });

View File

@ -186,7 +186,7 @@ angular.module('copayApp.directives')
} }
element.bind('click', function() { element.bind('click', function() {
selectText(elm[0]); selectText(element[0]);
}); });
} }
}; };

View File

@ -362,6 +362,11 @@ angular.module('copayApp.services')
var res = w.getPendingTxProposals(); var res = w.getPendingTxProposals();
_.each(res.txs, function(tx) { _.each(res.txs, function(tx) {
root.computeAlternativeAmount(w, tx); root.computeAlternativeAmount(w, tx);
if (tx.merchant) {
var url = tx.merchant.request_url;
var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1];
tx.merchant.domain = domain;
}
}); });
$rootScope.txps = res.txs; $rootScope.txps = res.txs;
if ($rootScope.pendingTxCount < res.pendingForUs) { if ($rootScope.pendingTxCount < res.pendingForUs) {

View File

@ -49,9 +49,6 @@
<div class="box-setup"> <div class="box-setup">
<h4 class="size-12" tooltip="HOLA">http://HOLA 1234 </h4>
<h4 class="size-12" clip-copy="HOLA">http://HOLA 1234 </h4>
<h1><span translate>Sign in to</span> <b>Copay</b></h1> <h1><span translate>Sign in to</span> <b>Copay</b></h1>
<form name="loginForm" ng-submit="openProfile(loginForm)" novalidate> <form name="loginForm" ng-submit="openProfile(loginForm)" novalidate>
<p class="text-warning size-12" <p class="text-warning size-12"

View File

@ -20,7 +20,20 @@
<contact address="{{out.address}}" tooltip-popup-delay="500" tooltip tooltip-placement="right" /> <contact address="{{out.address}}" tooltip-popup-delay="500" tooltip tooltip-placement="right" />
</div> </div>
</div> </div>
<div class="line-t" ng-show="!!tx.merchant">
<div class="send-note">
<p>
<b>{{tx.merchant.pr.pd.memo}}</b>
<p>
Expires {{tx.merchant.pr.pd.expires * 1000 | amTimeAgo }}
<span ng-show="tx.merchant.domain">[{{tx.merchant.domain}}]</span>
<span ng-show="!!tx.merchant.pr.ca"><i class="fi-lock"></i> {{tx.merchant.pr.ca}}</span>
<span ng-show="!tx.merchant.pr.ca" style="color:red;weight:bold;"><i class="fi-unlock"></i> Untrusted</span>
</div>
</div>
</div> </div>
<table class="last-transactions-content"> <table class="last-transactions-content">
<tbody> <tbody>
<tr ng-repeat="c in tx.actionList"> <tr ng-repeat="c in tx.actionList">

View File

@ -129,7 +129,7 @@
<div class="row"> <div class="row">
<div class="large-12 columns" ng-show="fetchingURL"> <div class="large-12 columns" ng-show="fetchingURL">
<h3> <h3>
<i class="glyphicon glyphicon-refresh icon-rotate"></i> <i class="fi-bitcoin-circle icon-rotate spinner"></i>
Fetching payment Fetching payment
</h3> </h3>
<p> From {{fetchingURL}} <p> From {{fetchingURL}}
@ -139,34 +139,24 @@
<h3>This is a payment protocol transaction</h3> <h3>This is a payment protocol transaction</h3>
<div class="send-note"> <div class="send-note">
<p> <p>
<b translate>Send to</b>: <b>{{$root.merchant.pr.pd.memo}}</b>
{{$root.merchant.domain}}
</p> </p>
<p> <p>
<b translate>Total amount for this transaction</b>:
<i>{{amount + defaultFee |noFractionNumber}} {{$root.wallet.settings.unitName}}</i> <i>{{amount + defaultFee |noFractionNumber}} {{$root.wallet.settings.unitName}}</i>
<small ng-if="isRateAvailable"> <span class="text-gray" ng-if="isRateAvailable">
{{ rateService.toFiat((amount + defaultFee) * unitToSatoshi, alternativeIsoCode) | noFractionNumber: 2 }} {{ alternativeIsoCode }} {{ rateService.toFiat((amount + defaultFee) * unitToSatoshi, alternativeIsoCode) | noFractionNumber: 2 }} {{ alternativeIsoCode }}
</small> </span>
<small> <span class="text-gray" >
(<span translate>Including fee of</span> (<span translate>Including fee of</span>
{{defaultFee|noFractionNumber}} {{defaultFee|noFractionNumber}}
{{$root.wallet.settings.unitName}}) {{$root.wallet.settings.unitName}})
</small> </span>
</p>
<p> <p>
<b translate>Server Says</b>: Expires {{$root.merchant.expiration | amTimeAgo }}
{{$root.merchant.pr.pd.memo}} [{{$root.merchant.domain}}]
</p> <span ng-show="!!$root.merchant.pr.ca"><i class="fi-lock"></i> {{$root.merchant.pr.ca}}</span>
<p> <span ng-show="!$root.merchant.pr.ca" style="color:red;weight:bold;"><i class="fi-unlock"></i> Untrusted</span>
<b translate>Certificate</b>:
<span ng-show="!!$root.merchant.pr.ca">{{$root.merchant.pr.ca}}</span>
<span ng-show="!$root.merchant.pr.ca" style="color:red;weight:bold;">Untrusted</span>
</p>
<p>
<b translate>Payment Expiration</b>:
{{$root.merchant.expiration}}
</p>
</div> </div>
</div> </div>
</div> </div>