import { TransactionReceipt } from '@ethersproject/providers' import lodash from 'lodash' import Logger from './logger/logger' import { toastError } from './uiHelper' export class CustomError extends Error { status: number | undefined data: TransactionReceipt | any constructor(message: string, status: number = 999, data = null) { super(message) this.data = data this.status = status } } export const showToastError = (error: any) => { const { status, code } = error if (status) { toastError({ title: 'Error', message: (error as any)?.data?.error?.message || (error as any)?.data?.message || (error as any).message, }) return } if (code && Number.isInteger(code)) { toastError({ title: 'Error', message: lodash.capitalize( (error as any)?.data?.message.replace('execution reverted: ', '').replace('err: ', '') || (error as any).message, ), }) return } toastError({ title: 'Error', message: 'Oops, BSC Smart Chain can not mint your request!', }) Logger.error(error) return }