1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-30 13:41:54 +02:00
blog/src/components/molecules/Web3Donation/Alert.tsx

44 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-05-22 14:38:19 +02:00
import React, { ReactElement } from 'react'
2021-03-14 01:34:04 +01:00
import { success, error, alert } from './Alert.module.css'
2019-11-22 21:26:50 +01:00
2021-05-23 13:38:15 +02:00
export function getTransactionMessage(transactionHash?: string): {
[key: string]: string
} {
2019-11-22 21:26:50 +01:00
return {
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!'
}
}
const constructMessage = (
transactionHash: string,
message?: { text?: string }
) =>
transactionHash
2021-03-15 21:01:55 +01:00
? message?.text +
'<br /><br />' +
getTransactionMessage(transactionHash).transaction
2019-11-22 21:26:50 +01:00
: message && message.text
const classes = (status: string) =>
2021-03-14 01:34:04 +01:00
status === 'success' ? success : status === 'error' ? error : alert
2019-11-22 21:26:50 +01:00
export default function Alert({
transactionHash,
message
}: {
2021-03-23 21:38:06 +01:00
transactionHash?: string
message: { text?: string; status?: string }
2020-05-22 14:38:19 +02:00
}): ReactElement {
2019-11-22 21:26:50 +01:00
return (
<div
className={classes(message.status)}
dangerouslySetInnerHTML={{
__html: `${constructMessage(transactionHash, message)}`
}}
/>
)
}