This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Display local/completed transactions #3630
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0ea3b8c
Initial fetch of local transactions
jacogr f91e713
Merge branch 'master' into jg-signer-local
jacogr e4d432b
Container allows for title specification
jacogr 59aa24a
Introduce TxList component
jacogr 4d1a14f
Display local transactions in signer list
jacogr 3b7aee4
Merge branch 'master' into jg-signer-local
jacogr 292ec27
Simplify
jacogr 0e265bd
Pass only hashes from calling components
jacogr 222b40c
Simplify no pending display
jacogr 61b96f9
Render pending blocks at the top
jacogr edf8139
Get rid of time for 0 blocks
jacogr 48f3b19
Indeed sort Pending to the top
jacogr 4aee815
Allow retrieval of pending transactions
jacogr bb0bd5c
Merge branch 'master' into jg-signer-local
jacogr 031ecfa
setTimeout with clearTimeout
jacogr 3cc9544
Merge branch 'master' into jg-signer-local
jacogr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright 2015, 2016 Ethcore (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import { action, observable, transaction } from 'mobx'; | ||
import { uniq } from 'lodash'; | ||
|
||
export default class Store { | ||
@observable blocks = {}; | ||
@observable sortedHashes = []; | ||
@observable transactions = {}; | ||
|
||
constructor (api) { | ||
this._api = api; | ||
this._subscriptionId = 0; | ||
this._pendingHashes = []; | ||
|
||
this.subscribe(); | ||
} | ||
|
||
@action addBlocks = (blocks) => { | ||
this.blocks = Object.assign({}, this.blocks, blocks); | ||
} | ||
|
||
@action addTransactions = (transactions) => { | ||
transaction(() => { | ||
this.transactions = Object.assign({}, this.transactions, transactions); | ||
this.sortedHashes = Object | ||
.keys(this.transactions) | ||
.sort((ahash, bhash) => { | ||
const bnA = this.transactions[ahash].blockNumber; | ||
const bnB = this.transactions[bhash].blockNumber; | ||
|
||
if (bnB.eq(0)) { | ||
return bnB.eq(bnA) ? 0 : 1; | ||
} | ||
|
||
return bnB.comparedTo(bnA); | ||
}); | ||
this._pendingHashes = this.sortedHashes.filter((hash) => this.transactions[hash].blockNumber.eq(0)); | ||
}); | ||
} | ||
|
||
@action clearPending () { | ||
this._pendingHashes = []; | ||
} | ||
|
||
subscribe () { | ||
this._api | ||
.subscribe('eth_blockNumber', (error, blockNumber) => { | ||
if (error) { | ||
return; | ||
} | ||
|
||
if (this._pendingHashes.length) { | ||
this.loadTransactions(this._pendingHashes); | ||
this.clearPending(); | ||
} | ||
}) | ||
.then((subscriptionId) => { | ||
this._subscriptionId = subscriptionId; | ||
}); | ||
} | ||
|
||
unsubscribe () { | ||
if (!this._subscriptionId) { | ||
return; | ||
} | ||
|
||
this._api.unsubscribe(this._subscriptionId); | ||
this._subscriptionId = 0; | ||
} | ||
|
||
loadTransactions (_txhashes) { | ||
const txhashes = _txhashes.filter((hash) => !this.transactions[hash] || this._pendingHashes.includes(hash)); | ||
|
||
if (!txhashes || !txhashes.length) { | ||
return; | ||
} | ||
|
||
Promise | ||
.all(txhashes.map((txhash) => this._api.eth.getTransactionByHash(txhash))) | ||
.then((transactions) => { | ||
this.addTransactions( | ||
transactions.reduce((transactions, tx, index) => { | ||
transactions[txhashes[index]] = tx; | ||
return transactions; | ||
}, {}) | ||
); | ||
|
||
this.loadBlocks(transactions.map((tx) => tx.blockNumber ? tx.blockNumber.toNumber() : 0)); | ||
}) | ||
.catch((error) => { | ||
console.warn('loadTransactions', error); | ||
}); | ||
} | ||
|
||
loadBlocks (_blockNumbers) { | ||
const blockNumbers = uniq(_blockNumbers).filter((bn) => !this.blocks[bn]); | ||
|
||
if (!blockNumbers || !blockNumbers.length) { | ||
return; | ||
} | ||
|
||
Promise | ||
.all(blockNumbers.map((blockNumber) => this._api.eth.getBlockByNumber(blockNumber))) | ||
.then((blocks) => { | ||
this.addBlocks( | ||
blocks.reduce((blocks, block, index) => { | ||
blocks[blockNumbers[index]] = block; | ||
return blocks; | ||
}, {}) | ||
); | ||
}) | ||
.catch((error) => { | ||
console.warn('loadBlocks', error); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* Copyright 2015, 2016 Ethcore (UK) Ltd. | ||
/* This file is part of Parity. | ||
/* | ||
/* Parity is free software: you can redistribute it and/or modify | ||
/* it under the terms of the GNU General Public License as published by | ||
/* the Free Software Foundation, either version 3 of the License, or | ||
/* (at your option) any later version. | ||
/* | ||
/* Parity is distributed in the hope that it will be useful, | ||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
/* GNU General Public License for more details. | ||
/* | ||
/* You should have received a copy of the GNU General Public License | ||
/* along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
.transactions { | ||
width: 100%; | ||
border-collapse: collapse; | ||
|
||
tr { | ||
line-height: 32px; | ||
vertical-align: top; | ||
|
||
&:nth-child(even) { | ||
background: rgba(255, 255, 255, 0.04); | ||
} | ||
} | ||
|
||
th { | ||
color: #aaa; | ||
text-align: center; | ||
} | ||
|
||
td { | ||
vertical-align: top; | ||
padding: 0.75em 0.75em; | ||
|
||
&.method { | ||
width: 40%; | ||
} | ||
|
||
&.timestamp { | ||
padding-top: 1.5em; | ||
text-align: right; | ||
line-height: 1.5em; | ||
opacity: 0.5; | ||
} | ||
|
||
&.transaction { | ||
padding-top: 1.5em; | ||
text-align: center; | ||
|
||
& div { | ||
line-height: 1.25em; | ||
min-height: 1.25em; | ||
} | ||
} | ||
} | ||
|
||
.icon { | ||
margin: 0; | ||
} | ||
|
||
.link { | ||
vertical-align: top; | ||
} | ||
|
||
.right { | ||
text-align: right; | ||
} | ||
|
||
.center { | ||
text-align: center; | ||
} | ||
|
||
.left { | ||
text-align: left; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an
@action
right ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be. Technically the only updates happen in the
addTransactions
function. So@action
won't hurt, however the function itself doesn't update the object state by modifying the variables directly. (Split the change out into a different@action
- async does not play well withsetStrict
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh that's right, didn't think of that. Not sure what it changes.