()
| 11 | import { useToastNotification } from './useToastNotification'; |
| 12 | |
| 13 | export const useTransactionError = () => { |
| 14 | const { displayToast } = useToastNotification(); |
| 15 | const { updateUser } = useAuthContext(); |
| 16 | |
| 17 | return async (data: ApiErrorResult) => { |
| 18 | if ( |
| 19 | data.response.errors?.[0]?.extensions?.code === |
| 20 | ApiError.BalanceTransactionError |
| 21 | ) { |
| 22 | const errorExtensions = data.response |
| 23 | .errors[0] as ApiResponseError<ApiUserTransactionErrorExtension>; |
| 24 | |
| 25 | if ( |
| 26 | errorExtensions.extensions.status === |
| 27 | UserTransactionStatus.InsufficientFunds && |
| 28 | errorExtensions.extensions.balance |
| 29 | ) { |
| 30 | await updateUser({ |
| 31 | ...user, |
| 32 | balance: errorExtensions.extensions.balance, |
| 33 | }); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | displayToast(data?.response?.errors?.[0]?.message || labels.error.generic); |
| 38 | }; |
| 39 | }; |
no test coverage detected