Toast success and danger for donate action (#511)

Danger case was already handled by the common `Form` component,
but success wasn't happening. I like having feedback on actions like this one.
Now, the danger toast is also specific to the donate action, and not just the underlying
JS error that occurred (which is logged, instead).
This commit is contained in:
SatsAllDay 2023-09-23 21:26:12 -04:00 committed by GitHub
parent 6d48330a61
commit 9f333518c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import PageLoading from '../../components/page-loading'
import { useShowModal } from '../../components/modal'
import dynamic from 'next/dynamic'
import { SSR } from '../../lib/constants'
import { useToast } from '../../components/toast'
const GrowthPieChart = dynamic(() => import('../../components/charts').then(mod => mod.GrowthPieChart), {
loading: () => <div>Loading...</div>
@ -88,6 +89,7 @@ export default function Rewards ({ ssrData }) {
export function DonateButton () {
const showModal = useShowModal()
const toaster = useToast()
const [donateToRewards] = useMutation(
gql`
mutation donateToRewards($sats: Int!) {
@ -103,12 +105,18 @@ export function DonateButton () {
}}
schema={amountSchema}
onSubmit={async ({ amount }) => {
await donateToRewards({
variables: {
sats: Number(amount)
}
})
onClose()
try {
await donateToRewards({
variables: {
sats: Number(amount)
}
})
onClose()
toaster.success('donated')
} catch (err) {
console.error(err)
toaster.danger('failed to donate')
}
}}
>
<Input