1
0
Fork 0
blog/src/components/Web3Donation/Alerts.tsx

60 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-10-02 13:35:50 +02:00
import React from 'react'
2018-10-13 20:37:13 +02:00
import styles from './Alerts.module.scss'
2019-10-02 13:35:50 +02:00
export const alertMessages = (
networkName?: string,
transactionHash?: string
) => ({
2018-10-30 18:08:07 +01:00
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!'
})
2018-10-13 23:35:21 +02:00
2019-10-02 13:35:50 +02:00
export default function Alerts({
transactionHash,
message
}: {
transactionHash: string | null
message: { text: MessageChannel; status: string } | null
}) {
const constructMessage = () => {
2018-10-30 18:08:07 +01:00
let messageOutput
2018-10-30 18:08:07 +01:00
if (transactionHash) {
messageOutput =
2019-10-02 13:35:50 +02:00
message &&
2018-10-30 18:08:07 +01:00
message.text +
2019-10-02 13:35:50 +02:00
'<br />' +
alertMessages(null, transactionHash).transaction
2018-10-30 18:08:07 +01:00
} else {
2019-10-02 13:35:50 +02:00
messageOutput = message && message.text
2018-10-30 18:08:07 +01:00
}
return messageOutput
}
2019-10-02 13:35:50 +02:00
const classes = () => {
const { status } = message
2018-10-30 18:08:07 +01:00
if (status === 'success') {
return styles.success
} else if (status === 'error') {
return styles.error
}
return styles.alert
}
2019-10-02 13:35:50 +02:00
return (
<div
className={classes()}
dangerouslySetInnerHTML={{ __html: constructMessage() }}
/>
)
2018-10-13 20:37:13 +02:00
}