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