Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tx notifications to campaign deployer
- Loading branch information
Showing
12 changed files
with
231 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
import { transactionActions } from "../constants"; | ||
|
||
export const newTransaction = hash => ({ | ||
type: transactionActions.NEW_TRANSATION, | ||
hash, | ||
}); | ||
|
||
export const transactionMined = hash => ({ | ||
type: transactionActions.TRANSACTION_MINED, | ||
hash, | ||
}); | ||
|
||
export const dismissTransaction = hash => ({ | ||
type: transactionActions.DISMISS_TRANSACTION, | ||
hash, | ||
}); |
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,32 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { AlertList } from "react-bs-notifier"; | ||
|
||
const NotificationList = props => ( | ||
<AlertList | ||
alerts={props.notifications} | ||
onDismiss={props.onDismiss} | ||
position={props.position} | ||
/> | ||
); | ||
|
||
NotificationList.propTypes = { | ||
onDismiss: PropTypes.func.isRequired, | ||
notifications: PropTypes.arrayOf(PropTypes.shape({ | ||
id: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number, | ||
]).isRequired, | ||
message: PropTypes.string.isRequired, | ||
headline: PropTypes.string, | ||
type: PropTypes.oneOf([ "info", "warning", "danger", "success" ]), | ||
})).isRequired, | ||
position: PropTypes.string, | ||
}; | ||
|
||
NotificationList.defaultProps = { | ||
notifications: [], | ||
position: "top-right", | ||
}; | ||
|
||
export default NotificationList; |
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,95 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { connect } from "react-redux"; | ||
import NotificationList from "../components/NotificationList"; | ||
import { dismissTransaction } from "../actions/transactions"; | ||
import { network } from "../blockchain"; | ||
|
||
class NotificationListContainer extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
notifications: this.getNotifications(), | ||
}; | ||
this.dismissNotification = this.dismissNotification.bind(this); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (this.props === nextProps) return; | ||
|
||
this.props = nextProps; | ||
this.setState(() => ({ notifications: this.getNotifications() })); | ||
} | ||
|
||
getNotifications() { | ||
const notifications = []; | ||
const wordBreak = "break-all"; | ||
|
||
this.props.transactions.forEach((tx) => { | ||
const etherscanLink = ( | ||
<a | ||
href={`${ network.etherscan }tx/${ tx.hash }`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
style={{ wordBreak }} | ||
> | ||
{tx.hash} | ||
</a > | ||
); | ||
|
||
let msg; | ||
if (tx.mined) { | ||
msg = ( | ||
<div > | ||
Transaction {etherscanLink} has been successfully mined! | ||
</div > | ||
); | ||
} else { | ||
msg = ( | ||
<div > | ||
Transaction {etherscanLink} is being added to the Ethereum blockchain | ||
</div > | ||
); | ||
} | ||
|
||
notifications.push({ | ||
id: tx.hash, | ||
message: msg, | ||
type: tx.mined ? "success" : "info", | ||
}); | ||
}); | ||
|
||
return notifications; | ||
} | ||
|
||
dismissNotification(notification) { | ||
this.props.dismissTransaction(notification.id); | ||
} | ||
|
||
render() { | ||
return ( | ||
<NotificationList | ||
onDismiss={this.dismissNotification} | ||
notifications={this.state.notifications} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
NotificationListContainer.propTypes = { | ||
dismissTransaction: PropTypes.func.isRequired, | ||
transactions: PropTypes.arrayOf(PropTypes.shape({ | ||
hash: PropTypes.string.isRequired, | ||
mined: PropTypes.bool.isRequired, | ||
})).isRequired, | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
transactions: state.transactions, | ||
}); | ||
|
||
const mapDispatchToProps = ({ | ||
dismissTransaction, | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(NotificationListContainer); |
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,43 @@ | ||
import { transactionActions } from "../constants"; | ||
|
||
const transactions = (state = [], action) => { | ||
switch (action.type) { | ||
|
||
case transactionActions.NEW_TRANSATION: { | ||
return [ | ||
...state, | ||
{ | ||
hash: action.hash, | ||
mined: false, | ||
}, | ||
]; | ||
} | ||
case transactionActions.TRANSACTION_MINED: { | ||
return state.map((tx) => { | ||
if (tx.hash !== action.hash) { | ||
return tx; | ||
} | ||
|
||
return Object.assign(tx, { mined: true }); | ||
}); | ||
} | ||
case transactionActions.DISMISS_TRANSACTION: { | ||
const i = state.findIndex(tx => tx.hash === action.hash); | ||
|
||
if (i > -1) { | ||
return [ | ||
...state.slice(0, i), | ||
...state.slice(i + 1), | ||
]; | ||
} | ||
|
||
return state; | ||
} | ||
default: { | ||
return state; | ||
} | ||
|
||
} | ||
}; | ||
|
||
export default transactions; |
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