import { PayloadAction } from '@reduxjs/toolkit' import { call, put, takeLatest } from 'redux-saga/effects' import { profileActions } from '.' import { GetProfileProps } from './types' import * as userApi from '../../apis/userApi' import { CustomError, showToastError } from '../../utils' export function* getProfile(action: PayloadAction) { try { const { payload } = action const { publicAddress } = payload const resp = yield call(userApi.checkExistPublicAddress, { publicAddress }) const { isSuccess, data } = resp if (isSuccess) { yield put(profileActions.getProfileSuccess(data)) } else { throw new CustomError('Get user data failed!') } } catch (error) { yield put(profileActions.getProfileFailed()) showToastError(error) } } export default function* userSaga() { yield takeLatest(profileActions.getProfile.type, getProfile) }