1
0
mirror of https://github.com/kremalicious/blog.git synced 2025-02-14 21:10:25 +01:00
blog/src/components/Web3Donation/Alerts.jsx
2018-10-30 18:08:07 +01:00

60 lines
1.7 KiB
JavaScript

import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import styles from './Alerts.module.scss'
export const alertMessages = (networkName, transactionHash) => ({
noAccount:
'Web3 detected, but no account. Are you logged into your MetaMask account?',
noCorrectNetwork: `Please connect to <strong>Main</strong> network. You are on <strong>${networkName}</strong> right now.`,
noWeb3:
'No Web3 detected. Install <a href="https://metamask.io">MetaMask</a>, <a href="https://brave.com">Brave</a>, or <a href="https://github.com/ethereum/mist">Mist</a>.',
transaction: `<a href="https://etherscan.io/tx/${transactionHash}" target="_blank">See your transaction on etherscan.io.</a>`,
waitingForUser: 'Waiting for your confirmation',
waitingConfirmation: 'Waiting for network confirmation, hang on',
success: 'Confirmed. You are awesome, thanks!'
})
export default class Alerts extends PureComponent {
static propTypes = {
message: PropTypes.object,
transactionHash: PropTypes.string
}
constructMessage = () => {
const { transactionHash, message } = this.props
let messageOutput
if (transactionHash) {
messageOutput =
message.text +
'<br />' +
alertMessages(null, transactionHash).transaction
} else {
messageOutput = message.text
}
return messageOutput
}
classes() {
const { status } = this.props.message
if (status === 'success') {
return styles.success
} else if (status === 'error') {
return styles.error
}
return styles.alert
}
render() {
return (
<div
className={this.classes()}
dangerouslySetInnerHTML={{ __html: this.constructMessage() }}
/>
)
}
}