Refine toast component and use cases
This commit is contained in:
parent
3054b67c28
commit
706c4ac01c
|
@ -27,7 +27,6 @@ function mapStateToProps (state) {
|
||||||
identities: state.metamask.identities,
|
identities: state.metamask.identities,
|
||||||
keyrings: state.metamask.keyrings,
|
keyrings: state.metamask.keyrings,
|
||||||
warning: state.appState.warning,
|
warning: state.appState.warning,
|
||||||
toastMsg: state.appState.toastMsg,
|
|
||||||
accounts,
|
accounts,
|
||||||
address: state.metamask.selectedAddress,
|
address: state.metamask.selectedAddress,
|
||||||
accountDetail: state.appState.accountDetail,
|
accountDetail: state.appState.accountDetail,
|
||||||
|
@ -68,7 +67,6 @@ AccountDetailScreen.prototype.render = function () {
|
||||||
h('.account-detail-section.full-flex-height', [
|
h('.account-detail-section.full-flex-height', [
|
||||||
|
|
||||||
h(ToastComponent, {
|
h(ToastComponent, {
|
||||||
msg: props.toastMsg,
|
|
||||||
isSuccess: false,
|
isSuccess: false,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ class AccountDropdowns extends Component {
|
||||||
labels: {},
|
labels: {},
|
||||||
isProxy: false,
|
isProxy: false,
|
||||||
contractProps: null,
|
contractProps: null,
|
||||||
|
preventToast: false,
|
||||||
}
|
}
|
||||||
this.accountSelectorToggleClassName = 'accounts-selector'
|
this.accountSelectorToggleClassName = 'accounts-selector'
|
||||||
this.optionsMenuToggleClassName = 'account-dropdown'
|
this.optionsMenuToggleClassName = 'account-dropdown'
|
||||||
|
@ -131,6 +132,7 @@ class AccountDropdowns extends Component {
|
||||||
this.props.actions.showAccountDetail(address)
|
this.props.actions.showAccountDetail(address)
|
||||||
if (ifHardwareAcc(keyring)) {
|
if (ifHardwareAcc(keyring)) {
|
||||||
if (isLedger(keyring.type)) {
|
if (isLedger(keyring.type)) {
|
||||||
|
|
||||||
const hdPaths = getHdPaths()
|
const hdPaths = getHdPaths()
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.props.actions.connectHardwareAndUnlockAddress(LEDGER, hdPaths[1].value, address)
|
this.props.actions.connectHardwareAndUnlockAddress(LEDGER, hdPaths[1].value, address)
|
||||||
|
@ -142,10 +144,17 @@ class AccountDropdowns extends Component {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
this.props.actions.displayWarning((e && e.message) || e)
|
if (!this.state.preventToast) {
|
||||||
this.props.actions.displayToast(e)
|
this.props.actions.displayToast(e)
|
||||||
|
} else {
|
||||||
|
this.setState({preventToast: false})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
this.setState({preventToast: true})
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.setState({preventToast: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ const { tokenInfoGetter, calcTokenAmount } = require('../../../ui/app/token-util
|
||||||
const BigNumber = require('bignumber.js')
|
const BigNumber = require('bignumber.js')
|
||||||
const ethNetProps = require('eth-net-props')
|
const ethNetProps = require('eth-net-props')
|
||||||
import { getMetaMaskAccounts } from '../../../ui/app/selectors'
|
import { getMetaMaskAccounts } from '../../../ui/app/selectors'
|
||||||
|
import ToastComponent from './toast'
|
||||||
|
|
||||||
const MIN_GAS_PRICE_BN = new BN('0')
|
const MIN_GAS_PRICE_BN = new BN('0')
|
||||||
const MIN_GAS_LIMIT_BN = new BN('21000')
|
const MIN_GAS_LIMIT_BN = new BN('21000')
|
||||||
|
@ -168,6 +169,9 @@ PendingTx.prototype.render = function () {
|
||||||
h('div', {
|
h('div', {
|
||||||
key: txMeta.id,
|
key: txMeta.id,
|
||||||
}, [
|
}, [
|
||||||
|
h(ToastComponent, {
|
||||||
|
isSuccess: false,
|
||||||
|
}),
|
||||||
|
|
||||||
h('form#pending-tx-form', {
|
h('form#pending-tx-form', {
|
||||||
onSubmit: this.onSubmit.bind(this),
|
onSubmit: this.onSubmit.bind(this),
|
||||||
|
|
|
@ -152,7 +152,7 @@ class SendTransactionScreen extends PersistentForm {
|
||||||
<SendProfile />
|
<SendProfile />
|
||||||
<SendHeader title="Execute Method" />
|
<SendHeader title="Execute Method" />
|
||||||
<ErrorComponent error={error} />
|
<ErrorComponent error={error} />
|
||||||
<ToastComponent msg={this.props.toastMsg} isSuccess={true} />
|
<ToastComponent isSuccess={true} />
|
||||||
<div style={{ padding: '0 30px' }}>
|
<div style={{ padding: '0 30px' }}>
|
||||||
<Select
|
<Select
|
||||||
clearable={false}
|
clearable={false}
|
||||||
|
@ -470,7 +470,6 @@ function mapStateToProps (state) {
|
||||||
const result = {
|
const result = {
|
||||||
address: state.metamask.selectedAddress,
|
address: state.metamask.selectedAddress,
|
||||||
warning: state.appState.warning,
|
warning: state.appState.warning,
|
||||||
toastMsg: state.appState.toastMsg,
|
|
||||||
methodSelected: contractAcc && contractAcc.methodSelected,
|
methodSelected: contractAcc && contractAcc.methodSelected,
|
||||||
methodABI: contractAcc && contractAcc.methodABI,
|
methodABI: contractAcc && contractAcc.methodABI,
|
||||||
inputValues: contractAcc && contractAcc.inputValues,
|
inputValues: contractAcc && contractAcc.inputValues,
|
||||||
|
|
|
@ -169,8 +169,6 @@ class SendTransactionScreen extends PersistentForm {
|
||||||
}
|
}
|
||||||
|
|
||||||
recipientDidChange (recipient, nickname) {
|
recipientDidChange (recipient, nickname) {
|
||||||
console.log('recipient, nickname')
|
|
||||||
console.log(recipient, nickname)
|
|
||||||
this.setState({
|
this.setState({
|
||||||
recipient,
|
recipient,
|
||||||
nickname,
|
nickname,
|
||||||
|
|
|
@ -16,6 +16,7 @@ import SendProfile from './send-profile'
|
||||||
import SendHeader from './send-header'
|
import SendHeader from './send-header'
|
||||||
import ErrorComponent from '../error'
|
import ErrorComponent from '../error'
|
||||||
import { getMetaMaskAccounts } from '../../../../ui/app/selectors'
|
import { getMetaMaskAccounts } from '../../../../ui/app/selectors'
|
||||||
|
import ToastComponent from '../toast'
|
||||||
module.exports = connect(mapStateToProps)(SendTransactionScreen)
|
module.exports = connect(mapStateToProps)(SendTransactionScreen)
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
|
@ -56,6 +57,10 @@ SendTransactionScreen.prototype.render = function () {
|
||||||
|
|
||||||
h('.send-screen.flex-column.flex-grow', [
|
h('.send-screen.flex-column.flex-grow', [
|
||||||
|
|
||||||
|
h(ToastComponent, {
|
||||||
|
isSuccess: false,
|
||||||
|
}),
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sender Profile
|
// Sender Profile
|
||||||
//
|
//
|
||||||
|
|
|
@ -7,6 +7,7 @@ import actions from '../../../ui/app/actions'
|
||||||
class ToastComponent extends Component {
|
class ToastComponent extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
msg: PropTypes.string,
|
msg: PropTypes.string,
|
||||||
|
toastMsg: PropTypes.string,
|
||||||
isSuccess: PropTypes.bool,
|
isSuccess: PropTypes.bool,
|
||||||
hideToast: PropTypes.func,
|
hideToast: PropTypes.func,
|
||||||
}
|
}
|
||||||
|
@ -17,7 +18,7 @@ class ToastComponent extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate (prevProps) {
|
componentDidUpdate (prevProps) {
|
||||||
if (!prevProps.msg && this.props.msg) {
|
if ((!prevProps.msg && this.props.msg) || (!prevProps.toastMsg && this.props.toastMsg)) {
|
||||||
this.timerID = setTimeout(() => {
|
this.timerID = setTimeout(() => {
|
||||||
this.props.hideToast()
|
this.props.hideToast()
|
||||||
clearTimeout(this.timerID)
|
clearTimeout(this.timerID)
|
||||||
|
@ -31,15 +32,16 @@ class ToastComponent extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { msg } = this.props
|
let toastMsg = this.props.msg || this.props.toastMsg
|
||||||
return msg ? (
|
toastMsg = (toastMsg && toastMsg.message) || toastMsg
|
||||||
|
return toastMsg ? (
|
||||||
<div
|
<div
|
||||||
className={classnames('toast', {
|
className={classnames('toast', {
|
||||||
'green': this.props.isSuccess,
|
'green': this.props.isSuccess,
|
||||||
'red': !this.props.isSuccess,
|
'red': !this.props.isSuccess,
|
||||||
})}
|
})}
|
||||||
onClick={(e) => this.props.hideToast()}
|
onClick={(e) => this.props.hideToast()}
|
||||||
>{(msg && msg.message) || msg}</div>
|
>{toastMsg}</div>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue