Skip to content

Commit

Permalink
Merge pull request #6 from josemmo/fix-inclusion
Browse files Browse the repository at this point in the history
v1.0.3
  • Loading branch information
josemmo authored Apr 14, 2018
2 parents 76b5325 + dc2aa57 commit 0b7851a
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

## 1.0.2 - 2018-02-05
- First public release

## 1.0.3 - 2018-04-14
- Fixed [issue #2](https://github.com/josemmo/iotawebwallet/issues/2) (excluded reattached balance from unconfirmed total)
- Added reattachment confirmed status to history ([issue #1](https://github.com/josemmo/iotawebwallet/issues/1))
- Added unconfirmed balance to address list in summary
2 changes: 1 addition & 1 deletion app/constants.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
define('APP_VERSION', '1.0.2');
define('APP_VERSION', '1.0.3');

define('DEP_IOTA_VERSION', '0.4.7');
define('DEP_JQUERY_VERSION', '3.3.1');
Expand Down
6 changes: 6 additions & 0 deletions images/reattached.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 95 additions & 37 deletions js/iotaController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
(function() {

var TX_STATUS = {
CONFIRMED: 1,
PENDING: 2,
REATTACHED: 3
};
var TX_TYPE = {
SENT: 1,
RECEIVED: 2
};

var iota = null;
var useFallbackNode = false;
var SEED = null;
Expand Down Expand Up @@ -161,30 +171,73 @@
}


/**
* Get parsed transactions
* @return {object} data Raw iota.lib.js account data
* @return {object} Parsed transactions array
*/
function getParsedTransactions(data) {
var res = [];

// Category transfers
var transfers = iota.utils.categorizeTransfers(data.transfers, data.addresses);
var confirmedBundles = [];
for (var type in transfers) {
transfers[type].forEach(function(bundle) {
bundle.forEach(function(tx) {
// Check transaction belongs to user
if ((type == 'received') && (data.addresses.indexOf(tx.address) < 0)) return;

// Include new attributes
tx.type = (type == 'received') ? TX_TYPE.RECEIVED : TX_TYPE.SENT;
if (tx.persistence) {
if (confirmedBundles.indexOf(tx.bundle) < 0) confirmedBundles.push(tx.bundle);
tx.status = TX_STATUS.CONFIRMED;
} else if (confirmedBundles.indexOf(tx.bundle) > -1) {
tx.status = TX_STATUS.REATTACHED;
} else {
tx.status = TX_STATUS.PENDING;
}

// Add transaction to response
res.push(tx);
});
});
}

return res;
}


/**
* Parse account data
* @param {object} data Account data
*/
function parseAccountData(data) {
var transactions = getParsedTransactions(data);

// Update balance
$('.max-iotas').html(formatIotas(data.balance)).data('value', data.balance);

// Update unconfirmed balance
var unconfirmed = 0;
data.transfers.forEach(function(bundle) {
bundle.forEach(function(tx) {
if ((data.addresses.indexOf(tx.address) > -1) && !tx.persistence) {
unconfirmed += tx.value;
var unconfirmedTotal = 0;
var unconfirmedAddrs = {};
transactions.forEach(function(tx) {
if ((tx.status == TX_STATUS.PENDING) && (tx.value !== 0)) {
unconfirmedTotal += tx.value;
if (typeof unconfirmedAddrs[tx.address] == 'undefined') {
unconfirmedAddrs[tx.address] = 0;
}
});
unconfirmedAddrs[tx.address] += tx.value;
}
});
var $unconfirmed = $('.unconfirmed-iotas');
if (unconfirmed == 0) {
if (unconfirmedTotal == 0) {
$unconfirmed.hide();
} else {
$unconfirmed.html(
(unconfirmed < 0 ? '-' : '+') +
' <strong>' + formatIotas(unconfirmed) + '</strong> unconfirmed'
(unconfirmedTotal < 0 ? '-' : '+') +
' <strong>' + formatIotas(unconfirmedTotal) + '</strong> unconfirmed'
).show();
}

Expand All @@ -205,9 +258,14 @@
break;
}
}
var unconfirmedBalance = '';
if (typeof unconfirmedAddrs[addr] !== 'undefined') {
unconfirmedBalance = ' <span class="text-muted">(' +
formatIotas(unconfirmedAddrs[addr]) + ')</span>';
}
aHTML += '<tr>' +
'<td><a href="' + window.SETTINGS.explorer + 'address/' + addr + '" target="_blank">' + addr + '</a></td>' +
'<td>' + formatIotas(balance) + '</td>' +
'<td>' + formatIotas(balance) + unconfirmedBalance + '</td>' +
'</tr>';
});
aHTML += '</tbody></table>';
Expand All @@ -220,33 +278,33 @@
var $container = $('section[data-page="history"] .container');
if (data.transfers.length > 0) {
var dataSet = [];
var transfers = iota.utils.categorizeTransfers(data.transfers, data.addresses);
for (var type in transfers) {
transfers[type].forEach(function(bundle) {
bundle.forEach(function(tx) {
// Check transaction belongs to user
if ((type == 'received') && (data.addresses.indexOf(tx.address) < 0)) return;

// Add transaction to table
var typeHTML = (type == 'sent') ?
'<h>O</h><img width="15" src="images/outgoing.svg" alt="🔺" title="Outgoing">' :
'<h>I</h><img width="15" src="images/incoming.svg" alt="🔻" title="Incoming">';
var confirmedHTML = tx.persistence ?
'<h>C</h><img width="15" src="images/confirmed.svg" alt="✔️" title="Confirmed">' :
'<h>P</h><img width="15" src="images/pending.svg" alt="💬" title="Pending">';
dataSet.push([
typeHTML,
confirmedHTML,
'<h>' + tx.attachmentTimestamp + '</h>' + window.formatDate(tx.attachmentTimestamp),
'<a href="' + window.SETTINGS.explorer + 'bundle/' + tx.bundle + '" target="_blank">' + tx.bundle + '</a>',
'<a href="' + window.SETTINGS.explorer + 'address/' + tx.address + '" target="_blank">' + tx.address + '</a>',
'<a href="' + window.SETTINGS.explorer + 'transaction/' + tx.hash + '" target="_blank">' + tx.hash + '</a>',
'<a href="' + window.SETTINGS.explorer + 'tag/' + tx.tag + '" target="_blank">' + tx.tag.replace(/9+$/g, '') + '</a>',
'<h>' + tx.value + '</h>' + formatIotas(tx.value)
]);
});
});
}
transactions.forEach(function(tx) {
var typeHTML = (tx.type == TX_TYPE.SENT) ?
'<h>O</h><img width="15" src="images/outgoing.svg" alt="🔺" title="Outgoing">' :
'<h>I</h><img width="15" src="images/incoming.svg" alt="🔻" title="Incoming">';
var statusHTML = '';
switch (tx.status) {
case TX_STATUS.CONFIRMED:
statusHTML = '<h>C</h><img width="15" src="images/confirmed.svg" alt="✔️" title="Confirmed">';
break;
case TX_STATUS.PENDING:
statusHTML = '<h>P</h><img width="15" src="images/pending.svg" alt="💬" title="Pending">';
break;
case TX_STATUS.REATTACHED:
statusHTML = '<h>R</h><img width="15" src="images/reattached.svg" alt="🔁" title="Reattachment confirmed">';
break;
}
dataSet.push([
typeHTML,
statusHTML,
'<h>' + tx.attachmentTimestamp + '</h>' + window.formatDate(tx.attachmentTimestamp),
'<a href="' + window.SETTINGS.explorer + 'bundle/' + tx.bundle + '" target="_blank">' + tx.bundle + '</a>',
'<a href="' + window.SETTINGS.explorer + 'address/' + tx.address + '" target="_blank">' + tx.address + '</a>',
'<a href="' + window.SETTINGS.explorer + 'transaction/' + tx.hash + '" target="_blank">' + tx.hash + '</a>',
'<a href="' + window.SETTINGS.explorer + 'tag/' + tx.tag + '" target="_blank">' + tx.tag.replace(/9+$/g, '') + '</a>',
'<h>' + tx.value + '</h>' + formatIotas(tx.value)
]);
});
$container.html('<table class="table table-striped"></table>');
$container.find('table').DataTable({
scrollX: true,
Expand Down

0 comments on commit 0b7851a

Please sign in to comment.