36 lines
834 B
TypeScript
36 lines
834 B
TypeScript
|
import mangoStore from '../store/state'
|
||
|
|
||
|
export type Notification = {
|
||
|
type: 'success' | 'info' | 'error' | 'confirm'
|
||
|
title: string
|
||
|
description?: null | string
|
||
|
txid?: string
|
||
|
show: boolean
|
||
|
id: number
|
||
|
}
|
||
|
|
||
|
export function notify(newNotification: {
|
||
|
type?: 'success' | 'info' | 'error' | 'confirm'
|
||
|
title: string
|
||
|
description?: string
|
||
|
txid?: string
|
||
|
}) {
|
||
|
const setMangoStore = mangoStore.getState().set
|
||
|
const notifications = mangoStore.getState().notifications
|
||
|
const lastId = mangoStore.getState().notificationIdCounter
|
||
|
const newId = lastId + 1
|
||
|
|
||
|
const newNotif: Notification = {
|
||
|
id: newId,
|
||
|
type: 'success',
|
||
|
show: true,
|
||
|
description: null,
|
||
|
...newNotification,
|
||
|
}
|
||
|
|
||
|
setMangoStore((state) => {
|
||
|
state.notificationIdCounter = newId
|
||
|
state.notifications = [...notifications, newNotif]
|
||
|
})
|
||
|
}
|