Skip to content

Commit

Permalink
fix: Rename actions
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Sep 22, 2023
1 parent 53a7f56 commit a36a966
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 74 deletions.
30 changes: 15 additions & 15 deletions src/modules/ens/actions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
fetchExternalENSNamesRequest,
FETCH_EXTERNAL_ENS_NAMES_REQUEST,
FETCH_EXTERNAL_ENS_NAMES_SUCCESS,
fetchExternalENSNamesSuccess,
fetchExternalENSNamesFailure,
FETCH_EXTERNAL_ENS_NAMES_FAILURE
fetchExternalNamesRequest,
FETCH_EXTERNAL_NAMES_REQUEST,
FETCH_EXTERNAL_NAMES_SUCCESS,
fetchExternalNamesSuccess,
fetchExternalNamesFailure,
FETCH_EXTERNAL_NAMES_FAILURE
} from './actions'
import { ENSError } from './types'

Expand All @@ -18,20 +18,20 @@ beforeEach(() => {
error = { message: 'Some Error' }
})

describe('when creating the action that signals the start of an external ens fetch request', () => {
it('should return an action signaling the start of an external ens fetch request', () => {
expect(fetchExternalENSNamesRequest(owner)).toEqual({ type: FETCH_EXTERNAL_ENS_NAMES_REQUEST, payload: { owner } })
describe('when creating the action that signals the start of an external names fetch request', () => {
it('should return an action signaling the start of an external names fetch request', () => {
expect(fetchExternalNamesRequest(owner)).toEqual({ type: FETCH_EXTERNAL_NAMES_REQUEST, payload: { owner } })
})
})

describe('when creating the action that signals the successful fetch of external ens names', () => {
it('should return an action signaling the successful fetch of external ens names', () => {
expect(fetchExternalENSNamesSuccess(owner, names)).toEqual({ type: FETCH_EXTERNAL_ENS_NAMES_SUCCESS, payload: { owner, names } })
describe('when creating the action that signals the successful fetch of external names', () => {
it('should return an action signaling the successful fetch of external names', () => {
expect(fetchExternalNamesSuccess(owner, names)).toEqual({ type: FETCH_EXTERNAL_NAMES_SUCCESS, payload: { owner, names } })
})
})

describe('when creating the action that signals the unsuccessful fetch of external ens names', () => {
it('should return an action signaling the unsuccessful fetch of external ens names', () => {
expect(fetchExternalENSNamesFailure(owner, error)).toEqual({ type: FETCH_EXTERNAL_ENS_NAMES_FAILURE, payload: { owner, error } })
describe('when creating the action that signals the unsuccessful fetch of external names', () => {
it('should return an action signaling the unsuccessful fetch of external names', () => {
expect(fetchExternalNamesFailure(error, owner)).toEqual({ type: FETCH_EXTERNAL_NAMES_FAILURE, payload: { owner, error } })
})
})
18 changes: 9 additions & 9 deletions src/modules/ens/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ export type AllowClaimManaSuccessAction = ReturnType<typeof allowClaimManaSucces
export type AllowClaimManaFailureAction = ReturnType<typeof allowClaimManaFailure>

// Fetch non dcl ENS names
export const FETCH_EXTERNAL_ENS_NAMES_REQUEST = '[Request] Fetch External ENS Names'
export const FETCH_EXTERNAL_ENS_NAMES_SUCCESS = '[Success] Fetch External ENS Names'
export const FETCH_EXTERNAL_ENS_NAMES_FAILURE = '[Failure] Fetch External ENS Names'
export const FETCH_EXTERNAL_NAMES_REQUEST = '[Request] Fetch External Names'
export const FETCH_EXTERNAL_NAMES_SUCCESS = '[Success] Fetch External Names'
export const FETCH_EXTERNAL_NAMES_FAILURE = '[Failure] Fetch External Names'

export const fetchExternalENSNamesRequest = (owner?: string) => action(FETCH_EXTERNAL_ENS_NAMES_REQUEST, { owner })
export const fetchExternalENSNamesSuccess = (owner: string, names: string[]) => action(FETCH_EXTERNAL_ENS_NAMES_SUCCESS, { owner, names })
export const fetchExternalENSNamesFailure = (error: ENSError, owner?: string) => action(FETCH_EXTERNAL_ENS_NAMES_FAILURE, { owner, error })
export const fetchExternalNamesRequest = (owner?: string) => action(FETCH_EXTERNAL_NAMES_REQUEST, { owner })
export const fetchExternalNamesSuccess = (owner: string, names: string[]) => action(FETCH_EXTERNAL_NAMES_SUCCESS, { owner, names })
export const fetchExternalNamesFailure = (error: ENSError, owner?: string) => action(FETCH_EXTERNAL_NAMES_FAILURE, { owner, error })

export type FetchExternalENSNamesRequestAction = ReturnType<typeof fetchExternalENSNamesRequest>
export type FetchExternalENSNamesSuccessAction = ReturnType<typeof fetchExternalENSNamesSuccess>
export type FetchExternalENSNamesFailureAction = ReturnType<typeof fetchExternalENSNamesFailure>
export type FetchExternalNamesRequestAction = ReturnType<typeof fetchExternalNamesRequest>
export type FetchExternalNamesSuccessAction = ReturnType<typeof fetchExternalNamesSuccess>
export type FetchExternalNamesFailureAction = ReturnType<typeof fetchExternalNamesFailure>
33 changes: 14 additions & 19 deletions src/modules/ens/reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
FETCH_EXTERNAL_ENS_NAMES_REQUEST,
fetchExternalENSNamesFailure,
fetchExternalENSNamesRequest,
fetchExternalENSNamesSuccess
} from './actions'
import { FETCH_EXTERNAL_NAMES_REQUEST, fetchExternalNamesFailure, fetchExternalNamesRequest, fetchExternalNamesSuccess } from './actions'
import { ENSState, INITIAL_STATE, ensReducer } from './reducer'
import { ENSError } from './types'

Expand All @@ -13,57 +8,57 @@ beforeEach(() => {
state = INITIAL_STATE
})

describe('when handling the fetch external ens actions', () => {
describe('when handling the fetch external names actions', () => {
let owner: string

beforeEach(() => {
owner = '0x123'
})

describe('when handling the fetch external ens request action', () => {
it('should add the fetch external ens request action to the loading state', () => {
const action = fetchExternalENSNamesRequest(owner)
describe('when handling the fetch external names request action', () => {
it('should add the fetch external names request action to the loading state', () => {
const action = fetchExternalNamesRequest(owner)
const newState = ensReducer(state, action)
expect(newState.loading[0]).toEqual(action)
})
})

describe('when handling the fetch external ens failure action', () => {
describe('when handling the fetch external names failure action', () => {
let error: ENSError

beforeEach(() => {
error = { message: 'Some Error' }
})

it('should set the error to the error state', () => {
const action = fetchExternalENSNamesFailure(owner, error)
const action = fetchExternalNamesFailure(error, owner)
const newState = ensReducer(state, action)
expect(newState.error).toEqual(error)
})

it('should remove the fetch external ens request action from the loading state', () => {
const action = fetchExternalENSNamesFailure(owner, error)
it('should remove the fetch external names request action from the loading state', () => {
const action = fetchExternalNamesFailure(error, owner)
const newState = ensReducer(state, action)
expect(newState.loading.length).toEqual(0)
})
})

describe('when handling the fetch external ens success action', () => {
describe('when handling the fetch external names success action', () => {
let names: string[]

beforeEach(() => {
names = ['name1.eth', 'name2.eth']
state.loading = [{ type: FETCH_EXTERNAL_ENS_NAMES_REQUEST }]
state.loading = [{ type: FETCH_EXTERNAL_NAMES_REQUEST }]
})

it('should update the external names property in the state', () => {
const action = fetchExternalENSNamesSuccess(owner, names)
const action = fetchExternalNamesSuccess(owner, names)
const newState = ensReducer(state, action)
expect(newState.externalNames[owner]).toEqual(names)
})

it('should remove the fetch external ens request action from the loading state', () => {
const action = fetchExternalENSNamesSuccess(owner, names)
it('should remove the fetch external names request action from the loading state', () => {
const action = fetchExternalNamesSuccess(owner, names)
const newState = ensReducer(state, action)
expect(newState.loading.length).toEqual(0)
})
Expand Down
24 changes: 12 additions & 12 deletions src/modules/ens/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ import {
FetchENSWorldStatusFailureAction,
CLAIM_NAME_CLEAR,
ClaimNameClearAction,
FETCH_EXTERNAL_ENS_NAMES_FAILURE,
FETCH_EXTERNAL_ENS_NAMES_REQUEST,
FetchExternalENSNamesRequestAction,
FetchExternalENSNamesSuccessAction,
FetchExternalENSNamesFailureAction,
FETCH_EXTERNAL_ENS_NAMES_SUCCESS
FETCH_EXTERNAL_NAMES_FAILURE,
FETCH_EXTERNAL_NAMES_REQUEST,
FetchExternalNamesRequestAction,
FetchExternalNamesSuccessAction,
FetchExternalNamesFailureAction,
FETCH_EXTERNAL_NAMES_SUCCESS
} from './actions'
import { ENS, ENSError, Authorization } from './types'

Expand Down Expand Up @@ -112,9 +112,9 @@ export type ENSReducerAction =
| FetchENSWorldStatusSuccessAction
| FetchENSWorldStatusFailureAction
| ClaimNameClearAction
| FetchExternalENSNamesRequestAction
| FetchExternalENSNamesSuccessAction
| FetchExternalENSNamesFailureAction
| FetchExternalNamesRequestAction
| FetchExternalNamesSuccessAction
| FetchExternalNamesFailureAction

export function ensReducer(state: ENSState = INITIAL_STATE, action: ENSReducerAction): ENSState {
switch (action.type) {
Expand All @@ -130,7 +130,7 @@ export function ensReducer(state: ENSState = INITIAL_STATE, action: ENSReducerAc
case SET_ENS_RESOLVER_SUCCESS:
case ALLOW_CLAIM_MANA_REQUEST:
case ALLOW_CLAIM_MANA_SUCCESS:
case FETCH_EXTERNAL_ENS_NAMES_REQUEST: {
case FETCH_EXTERNAL_NAMES_REQUEST: {
return {
...state,
error: null,
Expand Down Expand Up @@ -195,7 +195,7 @@ export function ensReducer(state: ENSState = INITIAL_STATE, action: ENSReducerAc
}
}
}
case FETCH_EXTERNAL_ENS_NAMES_SUCCESS: {
case FETCH_EXTERNAL_NAMES_SUCCESS: {
const { owner, names } = action.payload
return {
...state,
Expand All @@ -221,7 +221,7 @@ export function ensReducer(state: ENSState = INITIAL_STATE, action: ENSReducerAc
case FETCH_ENS_LIST_FAILURE:
case FETCH_ENS_AUTHORIZATION_FAILURE:
case ALLOW_CLAIM_MANA_FAILURE:
case FETCH_EXTERNAL_ENS_NAMES_FAILURE: {
case FETCH_EXTERNAL_NAMES_FAILURE: {
return {
...state,
loading: loadingReducer(state.loading, action),
Expand Down
22 changes: 11 additions & 11 deletions src/modules/ens/sagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
fetchENSAuthorizationRequest,
fetchENSListRequest,
fetchENSListSuccess,
fetchExternalENSNamesFailure,
fetchExternalENSNamesRequest,
fetchExternalENSNamesSuccess
fetchExternalNamesFailure,
fetchExternalNamesRequest,
fetchExternalNamesSuccess
} from './actions'
import { ensSaga } from './sagas'
import { ENS, ENSError } from './types'
Expand Down Expand Up @@ -181,8 +181,8 @@ describe('when handling the fetching of external ens names for an owner', () =>
[select(getAddress), storedAddress],
[call([ensApi, ensApi.fetchENSList], storedAddress!), []]
])
.put(fetchExternalENSNamesSuccess(storedAddress!, []))
.dispatch(fetchExternalENSNamesRequest())
.put(fetchExternalNamesSuccess(storedAddress!, []))
.dispatch(fetchExternalNamesRequest())
.silentRun()
})
})
Expand All @@ -197,8 +197,8 @@ describe('when handling the fetching of external ens names for an owner', () =>
it('should dispatch an error action with undefined as the owner and the error', async () => {
await expectSaga(ensSaga, builderClient, ensApi)
.provide([[select(getAddress), storedAddress]])
.put(fetchExternalENSNamesFailure(ensError, undefined))
.dispatch(fetchExternalENSNamesRequest())
.put(fetchExternalNamesFailure(ensError, undefined))
.dispatch(fetchExternalNamesRequest())
.silentRun()
})
})
Expand All @@ -223,8 +223,8 @@ describe('when handling the fetching of external ens names for an owner', () =>
it('should dispatch an error action with the owner and the error', async () => {
await expectSaga(ensSaga, builderClient, ensApi)
.provide([[call([ensApi, ensApi.fetchENSList], owner), throwError(error)]])
.put(fetchExternalENSNamesFailure(ensError, owner))
.dispatch(fetchExternalENSNamesRequest(owner))
.put(fetchExternalNamesFailure(ensError, owner))
.dispatch(fetchExternalNamesRequest(owner))
.silentRun()
})
})
Expand All @@ -239,8 +239,8 @@ describe('when handling the fetching of external ens names for an owner', () =>
it('should dispatch a success action with the owner and the names', async () => {
await expectSaga(ensSaga, builderClient, ensApi)
.provide([[call([ensApi, ensApi.fetchENSList], owner), names]])
.put(fetchExternalENSNamesSuccess(owner, names))
.dispatch(fetchExternalENSNamesRequest(owner))
.put(fetchExternalNamesSuccess(owner, names))
.dispatch(fetchExternalNamesRequest(owner))
.silentRun()
})
})
Expand Down
16 changes: 8 additions & 8 deletions src/modules/ens/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ import {
FetchENSWorldStatusRequestAction,
fetchENSWorldStatusSuccess,
fetchENSWorldStatusFailure,
FETCH_EXTERNAL_ENS_NAMES_REQUEST,
FetchExternalENSNamesRequestAction,
fetchExternalENSNamesSuccess,
fetchExternalENSNamesFailure
FETCH_EXTERNAL_NAMES_REQUEST,
FetchExternalNamesRequestAction,
fetchExternalNamesSuccess,
fetchExternalNamesFailure
} from './actions'
import { getENSBySubdomain } from './selectors'
import { ENS, ENSOrigin, ENSError, Authorization } from './types'
Expand All @@ -89,7 +89,7 @@ export function* ensSaga(builderClient: BuilderClient, ensApi: ENSApi) {
yield takeEvery(CLAIM_NAME_REQUEST, handleClaimNameRequest)
yield takeEvery(ALLOW_CLAIM_MANA_REQUEST, handleApproveClaimManaRequest)
yield takeEvery(RECLAIM_NAME_REQUEST, handleReclaimNameRequest)
yield takeEvery(FETCH_EXTERNAL_ENS_NAMES_REQUEST, handleFetchExternalENSNamesRequest)
yield takeEvery(FETCH_EXTERNAL_NAMES_REQUEST, handleFetchExternalNamesRequest)

function* handleFetchLandsSuccess() {
yield put(fetchENSAuthorizationRequest())
Expand Down Expand Up @@ -489,7 +489,7 @@ export function* ensSaga(builderClient: BuilderClient, ensApi: ENSApi) {
}
}

function* handleFetchExternalENSNamesRequest(action: FetchExternalENSNamesRequestAction) {
function* handleFetchExternalNamesRequest(action: FetchExternalNamesRequestAction) {
const owner = action.payload.owner ?? (yield select(getAddress))

try {
Expand All @@ -498,10 +498,10 @@ export function* ensSaga(builderClient: BuilderClient, ensApi: ENSApi) {
}

const names: string[] = yield call([ensApi, ensApi.fetchENSList], owner)
yield put(fetchExternalENSNamesSuccess(owner, names))
yield put(fetchExternalNamesSuccess(owner, names))
} catch (error) {
const ensError: ENSError = { message: error.message }
yield put(fetchExternalENSNamesFailure(ensError, owner))
yield put(fetchExternalNamesFailure(ensError, owner))
}
}
}

0 comments on commit a36a966

Please sign in to comment.