view only mode added

pull/5/head
moneroexamples 7 years ago
parent f0e72ba614
commit fea5a0da5e

@ -22,6 +22,7 @@ They include:
- improved handling of mempool, coinbase, locked and unlocked transactions.
- added dynamic fees for testnet.
- minimum mixin set to 4 for the next hard fork.
- view only mode - no spendkey required for frontend.
## Testnet version

@ -106,22 +106,31 @@ thinwalletCtrls.controller('AccountCtrl', function($scope, $rootScope, $http, $q
address: AccountService.getAddress(),
view_key: AccountService.getViewKey()
}).success(function(data) {
var promises = [];
for (var i = 0; i < (data.spent_outputs || []).length; ++i) {
var view_only = AccountService.isViewOnly();
for (var i = 0; i < (data.spent_outputs || []).length; ++i)
{
var deferred = $q.defer();
promises.push(deferred.promise);
(function(deferred, spent_output) {
setTimeout(function() {
var key_image = AccountService.cachedKeyImage(
spent_output.tx_pub_key,
spent_output.out_index
);
if (spent_output.key_image !== key_image) {
data.total_sent = new JSBigInt(data.total_sent).subtract(spent_output.amount);
}
deferred.resolve();
}, 0);
})(deferred, data.spent_outputs[i]);
if (view_only === false)
{
(function(deferred, spent_output) {
setTimeout(function() {
var key_image = AccountService.cachedKeyImage(
spent_output.tx_pub_key,
spent_output.out_index
);
if (spent_output.key_image !== key_image) {
data.total_sent = new JSBigInt(data.total_sent).subtract(spent_output.amount);
}
deferred.resolve();
}, 0);
})(deferred, data.spent_outputs[i]);
}
}
$q.all(promises).then(function() {
$scope.locked_balance = new JSBigInt(data.locked_funds || 0);
@ -137,7 +146,11 @@ thinwalletCtrls.controller('AccountCtrl', function($scope, $rootScope, $http, $q
};
$scope.fetchTransactions = function() {
if (AccountService.loggedIn()) {
if (AccountService.loggedIn())
{
var view_only = AccountService.isViewOnly();
$http.post(config.apiUrl + 'get_address_txs', AccountService.getAddressAndViewKey())
.success(function(data) {
$scope.account_scanned_height = data.scanned_height || 0;
@ -149,30 +162,54 @@ thinwalletCtrls.controller('AccountCtrl', function($scope, $rootScope, $http, $q
for (var i = 0; i < transactions.length; ++i) {
if ((transactions[i].spent_outputs || []).length > 0)
{
for (var j = 0; j < transactions[i].spent_outputs.length; ++j)
if (view_only === false)
{
var key_image = AccountService.cachedKeyImage(
transactions[i].spent_outputs[j].tx_pub_key,
transactions[i].spent_outputs[j].out_index
);
if (transactions[i].spent_outputs[j].key_image !== key_image)
for (var j = 0; j < transactions[i].spent_outputs.length; ++j)
{
transactions[i].total_sent = new JSBigInt(transactions[i].total_sent).subtract(transactions[i].spent_outputs[j].amount).toString();
transactions[i].spent_outputs.splice(j, 1);
j--;
var key_image = AccountService.cachedKeyImage(
transactions[i].spent_outputs[j].tx_pub_key,
transactions[i].spent_outputs[j].out_index
);
if (transactions[i].spent_outputs[j].key_image !== key_image)
{
transactions[i].total_sent = new JSBigInt(transactions[i].total_sent).subtract(transactions[i].spent_outputs[j].amount).toString();
transactions[i].spent_outputs.splice(j, 1);
j--;
}
}
}
}
if (new JSBigInt(transactions[i].total_received || 0).add(transactions[i].total_sent || 0).compare(0) <= 0)
//console.log(transactions[i].total_received, transactions[i].total_sent);
if (view_only === false)
{
transactions.splice(i, 1);
i--;
continue;
if (new JSBigInt(transactions[i].total_received || 0).add(transactions[i].total_sent || 0).compare(0) <= 0)
{
transactions.splice(i, 1);
i--;
continue;
}
transactions[i].amount = new JSBigInt(transactions[i].total_received || 0)
.subtract(transactions[i].total_sent || 0).toString();
}
else
{
//remove tx if zero xmr recievied. probably spent only tx,
//but we dont have spendkey to verify this.
if (new JSBigInt(transactions[i].total_received).compare(0) === true)
{
transactions.splice(i, 1);
i--;
continue;
}
transactions[i].amount = new JSBigInt(transactions[i].total_received).toString();
//console.log(transactions[i].total_received, transactions[i].total_sent);
}
transactions[i].amount = new JSBigInt(transactions[i].total_received || 0).subtract(transactions[i].total_sent || 0).toString();
transactions[i].approx_float_amount = parseFloat(cnUtil.formatMoney(transactions[i].amount));
transactions[i].timestamp = new Date(transactions[i].timestamp);
}

@ -33,6 +33,8 @@ thinwalletCtrls.controller('AccountOverviewCtrl', function ($scope, $rootScope,
var fetchInterval = $interval($scope.fetchTransactions, 10 * 1000);
$scope.fetchTransactions();
$scope.view_only = AccountService.isViewOnly();
$scope.$on('$destroy', function () {
$interval.cancel(fetchInterval);
});

@ -34,6 +34,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS
$scope.targets = [{}];
$scope.totalAmount = JSBigInt.ZERO;
$scope.mixins = config.defaultMixin;
$scope.view_only = AccountService.isViewOnly();
$scope.success_page = false;
$scope.sent_tx = {};

@ -10,7 +10,7 @@
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// materials provided wit $interval.cancel(fetchInterval);h the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
@ -26,7 +26,7 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
thinwalletCtrls.controller('TransactionsCtrl', function ($scope, $rootScope, $http, $interval) {
thinwalletCtrls.controller('TransactionsCtrl', function ($scope, $rootScope, $http, $interval, AccountService) {
"use strict";
$scope.pageNum = 0;
@ -35,6 +35,8 @@ thinwalletCtrls.controller('TransactionsCtrl', function ($scope, $rootScope, $ht
$scope.predicate = 'id';
$scope.reverse = true;
$scope.view_only = AccountService.isViewOnly();
$scope.predicateIcon = function(expected) {
if ($scope.predicate === expected) {
if($scope.reverse) {

@ -154,6 +154,9 @@ thinwalletServices
accountService.getSpendKey = function() {
return private_keys.spend;
};
accountService.isViewOnly = function() {
return view_only;
};
accountService.getSeed = function() {
return account_seed;
};

@ -10,7 +10,9 @@
<div class="subhead-text modal">
Dont yet have an account?&nbsp;
<a class="login-link" data-ix="close-overlay" hide-modal href="#/create-your-account">Create a Monero account</a>
<a class="login-link" data-ix="close-overlay" hide-modal href="#/create-your-account">
Create a Monero account
</a>
</div>
</div>
<div class="form-div">
@ -20,7 +22,7 @@
<div>Login with Private Login Key</div>
</a>
<a class="w-tab-link w-inline-block tab-link-2" ng-class="{'w--current': tab_number == 2}" data-w-tab="Tab 2" ng-click="set_tab(2)">
<div>Login with Public Key</div>
<div>Login with Address and viewkey</div>
</a>
</div>
<div class="w-tab-content">
@ -60,9 +62,13 @@
<input class="w-input form-layout" id="view-key" type="text" placeholder="Enter your view key here"
name="View-Key" data-name="View Key" autocomplete="off" required="required" ng-model="view_key">
<label class="field-label" for="spend-key">Spend Key</label>
<input class="w-input form-layout" id="spend-key" type="text" placeholder="Enter your spend key here"
name="Spend-Key" data-name="Spend Key" autocomplete="off" required="required" ng-model="spend_key">
<input class="w-input form-layout" id="spend-key" type="text" placeholder="Optionally, enter your spend key here."
name="Spend-Key" data-name="Spend Key" autocomplete="off" ng-model="spend_key">
<div class="subhead-text modal">
Without spendkey, you will login in a view only mode.
Only incoming transactions will be shown, and
sending transactions will not be possible.
</div>
<div class="submit-div">
<input class="w-button login-btn pointer" id="form-submit2" type="submit" value="Enter my account"
data-wait="Please wait...">
@ -71,6 +77,7 @@
<p>{{error}}</p>
</div>
</form>
</div>
</div>
</div>

@ -6,7 +6,14 @@
<div class="w-row">
<div class="w-col w-col-6">
<h1>Account Overview</h1>
<div class="subhead-text inner overview-page">Your account overview and recent transactions.</div>
<div class="subhead-text inner overview-page">
Your account overview and recent transactions.
<span ng-show="view_only"><rb/>This is <b>view only</b> wallet.
<br/>Balance and transactions do not account for any spendings.
Thus if there were any spendings made, the balance here
will be incorrect.
</span>
</div>
</div>
<div class="w-col w-col-6">
<div class="balance-div">

@ -7,7 +7,10 @@
<div class="w-col w-col-6 w-clearfix">
<div class="header-div-block">
<h1 class="heading-contained">Transactions</h1>
<div class="subhead-text inner">A complete statement of all transactions for your account.</div>
<div class="subhead-text inner">
A complete statement of all transactions for your account.
<span ng-show="view_only"><rb/>This is <b>view only</b> wallet.
</div>
</div>
</div>
<div class="w-col w-col-6">

@ -7,7 +7,9 @@
<div class="w-col w-col-6 w-clearfix">
<div class="header-div-block">
<h1 class="heading-contained">Receive</h1>
<div class="subhead-text inner">Receive funds from any Monero user.</div>
<div class="subhead-text inner">
Receive funds from any Monero user.
</div>
</div>
</div>
<div class="w-col w-col64">

@ -1,6 +1,8 @@
<div ng-include src="'partials/account-nav.html'"></div>
<!--
<div ng-include src="'modals/openalias-confirm.html'" ng-show="openaliasDialog"></div>
-->
<div class="body-section">
<div class="w-container">
@ -36,7 +38,7 @@
</div>
</div>
</div>
<div class="w-container middle-container send">
<div class="w-container middle-container send" ng-show="!view_only">
<div class="middle-div send" ng-show="!success_page">
<div class="w-form send-form">
<form name="email-form" data-name="Email Form" data-redirect="/transaction-successful.html"
@ -102,4 +104,9 @@
</div>
</div>
</div>
<div class="w-container middle-container send" ng-show="view_only">
<div class="w-col w-col-11">
<div class="middle-text ">View only wallets can't sent any transactions, as spendkey is unknown</div>
</div>
</div>
</div>

@ -660,7 +660,7 @@ CurrentBlockchainStatus::start_tx_search_thread(XmrAccount acc)
{
// thread for this address exist, dont make new one
cout << "Thread exisist, dont make new one" << endl;
return false;
return true; // this is still OK, so return true.
}
try

Loading…
Cancel
Save