2021-04-11 21:17:23 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
|
|
|
|
2021-12-09 09:23:19 -08:00
|
|
|
export type Notification = {
|
|
|
|
type: 'success' | 'info' | 'error' | 'confirm'
|
|
|
|
title: string
|
|
|
|
description?: null | string
|
|
|
|
txid?: string
|
|
|
|
show: boolean
|
|
|
|
id: number
|
|
|
|
}
|
|
|
|
|
2021-04-11 21:17:23 -07:00
|
|
|
export function notify(newNotification: {
|
2021-12-09 09:23:19 -08:00
|
|
|
type?: 'success' | 'info' | 'error' | 'confirm'
|
2021-07-06 15:04:20 -07:00
|
|
|
title: string
|
2021-04-11 21:17:23 -07:00
|
|
|
description?: string
|
|
|
|
txid?: string
|
|
|
|
}) {
|
|
|
|
const setMangoStore = useMangoStore.getState().set
|
2021-04-12 13:01:55 -07:00
|
|
|
const notifications = useMangoStore.getState().notifications
|
2021-12-09 13:21:53 -08:00
|
|
|
const lastId = useMangoStore.getState().notificationIdCounter
|
|
|
|
const newId = lastId + 1
|
2021-04-11 21:17:23 -07:00
|
|
|
|
2021-12-09 09:23:19 -08:00
|
|
|
const newNotif: Notification = {
|
|
|
|
id: newId,
|
|
|
|
type: 'success',
|
|
|
|
show: true,
|
|
|
|
description: null,
|
|
|
|
...newNotification,
|
|
|
|
}
|
|
|
|
|
2021-04-11 21:17:23 -07:00
|
|
|
setMangoStore((state) => {
|
2021-12-09 13:21:53 -08:00
|
|
|
state.notificationIdCounter = newId
|
2021-12-09 09:23:19 -08:00
|
|
|
state.notifications = [...notifications, newNotif]
|
2021-04-11 21:17:23 -07:00
|
|
|
})
|
2021-04-02 11:26:21 -07:00
|
|
|
}
|