Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Display local/completed transactions #3630

Merged
merged 16 commits into from
Nov 29, 2016
Merged
Next Next commit
Initial fetch of local transactions
  • Loading branch information
jacogr committed Nov 25, 2016

Unverified

The signing certificate or its chain could not be verified.
commit 0ea3b8cc34ecc4fd99f1e8363df27af31b75025e
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ class RequestsPage extends Component {
isTest: PropTypes.bool.isRequired
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

};

store = new Store(this.context.api);
store = new Store(this.context.api, true);

render () {
const { pending, finished } = this.props.signer;
64 changes: 63 additions & 1 deletion js/src/views/Signer/store.js
Original file line number Diff line number Diff line change
@@ -14,13 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import BigNumber from 'bignumber.js';
import { isEqual } from 'lodash';
import { action, observable } from 'mobx';

export default class Store {
@observable balances = {};
@observable localTransactions = [];

constructor (api) {
constructor (api, withLocalTransactions = false) {
this._api = api;

if (withLocalTransactions) {
this.fetchLocalTransactions();
}
}

@action setBalance = (address, balance) => {
@@ -31,6 +38,12 @@ export default class Store {
this.balances = Object.assign({}, this.balances, balances);
}

@action setLocalTransactions = (localTransactions) => {
if (!isEqual(localTransactions, this.localTransactions)) {
this.localTransactions = localTransactions;
}
}

fetchBalance (address) {
this._api.eth
.getBalance(address)
@@ -63,4 +76,53 @@ export default class Store {
console.warn('Store:fetchBalances', error);
});
}

fetchLocalTransactions = () => {
const nextTimeout = () => {
setTimeout(this.fetchLocalTransactions, 1500);
};

Promise
.all([
this._api.parity.pendingTransactions(),
this._api.parity.pendingTransactionsStats(),
this._api.parity.localTransactions()
])
.then(([pending, stats, local]) => {
pending
.filter((transaction) => local[transaction.hash])
.forEach((transaction) => {
local[transaction.hash].transaction = transaction;
local[transaction.hash].stats = stats[transaction.hash].stats;
});

const localTransactions = Object
.keys(local)
.map((hash) => {
const data = local[hash];

data.txHash = hash;
return data;
});

localTransactions.sort((a, b) => {
a = a.transaction || {};
b = b.transaction || {};

if (a.from && b.from && a.from !== b.from) {
return a.from < b.from;
}

if (!a.nonce || !b.nonce) {
return !a.nonce ? 1 : -1;
}

return new BigNumber(a.nonce || 0).cmp(new BigNumber(b.nonce || 0));
});

this.setLocalTransactions(localTransactions);
})
.then(nextTimeout)
.catch(nextTimeout);
}
}