Skip to content

Commit

Permalink
feat: Add saga to fetch external ens requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Sep 20, 2023
1 parent 236d7b1 commit 1b8aa15
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"SSO_URL": "https://id.decentraland.zone",
"SENTRY_DSN": "https://428e8d298fb3f0fbcea645314a4a388c@o4504361728212992.ingest.sentry.io/4505748381564928",
"DCL_LISTS_SERVER": "https://dcl-lists.decentraland.zone",
"INSPECTOR_CONTENT_URL": "https://builder-items.decentraland.zone"
"INSPECTOR_CONTENT_URL": "https://builder-items.decentraland.zone",
"ENS_SUBGRAPH_URL": "https://api.studio.thegraph.com/query/49574/enssepolia/version/latest"
}
3 changes: 2 additions & 1 deletion src/config/env/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"SSO_URL": "https://id.decentraland.org",
"SENTRY_DSN": "https://428e8d298fb3f0fbcea645314a4a388c@o4504361728212992.ingest.sentry.io/4505748381564928",
"DCL_LISTS_SERVER": "https://dcl-lists.decentraland.org",
"INSPECTOR_CONTENT_URL": "https://builder-items.decentraland.org"
"INSPECTOR_CONTENT_URL": "https://builder-items.decentraland.org",
"ENS_SUBGRAPH_URL": "https://api.thegraph.com/subgraphs/name/ensdomains/ens"
}
3 changes: 2 additions & 1 deletion src/config/env/stg.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"SSO_URL": "https://id.decentraland.today",
"SENTRY_DSN": "https://428e8d298fb3f0fbcea645314a4a388c@o4504361728212992.ingest.sentry.io/4505748381564928",
"DCL_LISTS_SERVER": "https://dcl-lists.decentraland.today",
"INSPECTOR_CONTENT_URL": "https://builder-items.decentraland.zone"
"INSPECTOR_CONTENT_URL": "https://builder-items.decentraland.zone",
"ENS_SUBGRAPH_URL": "https://api.thegraph.com/subgraphs/name/ensdomains/ens"
}
11 changes: 9 additions & 2 deletions src/modules/common/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { uiSaga } from 'modules/ui/sagas'
import { walletSaga } from 'modules/wallet/sagas'
import { PEER_URL } from 'lib/api/peer'
import { BuilderAPI } from 'lib/api/builder'
import { ENSApi } from 'lib/api/ens'
import { entitySaga } from 'modules/entity/sagas'
import { loginSaga } from 'modules/login/sagas'
import { newsletterSagas } from 'modules/newsletter/sagas'
Expand All @@ -49,7 +50,13 @@ import { RootStore } from './types'

const profileSaga = createProfileSaga({ peerUrl: PEER_URL, peerWithNoGbCollectorUrl: getPeerWithNoGBCollectorURL() })

export function* rootSaga(builderAPI: BuilderAPI, newBuilderClient: BuilderClient, catalystClient: CatalystClient, store: RootStore) {
export function* rootSaga(
builderAPI: BuilderAPI,
newBuilderClient: BuilderClient,
catalystClient: CatalystClient,
store: RootStore,
ensApi: ENSApi
) {
yield all([
analyticsSaga(),
assetPackSaga(builderAPI),
Expand All @@ -59,7 +66,7 @@ export function* rootSaga(builderAPI: BuilderAPI, newBuilderClient: BuilderClien
committeeSaga(builderAPI),
deploymentSaga(builderAPI, catalystClient),
editorSaga(),
ensSaga(newBuilderClient),
ensSaga(newBuilderClient, ensApi),
entitySaga(catalystClient),
forumSaga(builderAPI),
identitySaga(),
Expand Down
5 changes: 4 additions & 1 deletion src/modules/common/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { isDevelopment } from 'lib/environment'
import { BuilderAPI, BUILDER_SERVER_URL } from 'lib/api/builder'
import { Authorization } from 'lib/api/auth'
import { PEER_URL } from 'lib/api/peer'
import { ENSApi } from 'lib/api/ens'
import { createRootReducer } from './reducer'
import { rootSaga } from './sagas'
import { RootState, RootStore } from './types'
Expand Down Expand Up @@ -168,7 +169,9 @@ const builderClientUrl: string = BUILDER_SERVER_URL.replace('/v1', '')

const newBuilderClient = new BuilderClient(builderClientUrl, getClientAuthAuthority, getClientAddress, fetch)

sagasMiddleware.run(rootSaga, builderAPI, newBuilderClient, catalystClient, store)
const ensApi = new ENSApi(config.get('ENS_SUBGRAPH_URL'))

sagasMiddleware.run(rootSaga, builderAPI, newBuilderClient, catalystClient, store, ensApi)
loadStorageMiddleware(store)

if (isDevelopment) {
Expand Down
21 changes: 19 additions & 2 deletions src/modules/ens/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { marketplace } from 'lib/api/marketplace'
import { lists } from 'lib/api/lists'
import { WorldInfo, content as WorldsAPIContent } from 'lib/api/worlds'
import { extractEntityId } from 'lib/urn'
import { ENSApi } from 'lib/api/ens'
import {
FETCH_ENS_REQUEST,
FetchENSRequestAction,
Expand Down Expand Up @@ -67,13 +68,17 @@ import {
FETCH_ENS_WORLD_STATUS_REQUEST,
FetchENSWorldStatusRequestAction,
fetchENSWorldStatusSuccess,
fetchENSWorldStatusFailure
fetchENSWorldStatusFailure,
FETCH_EXTERNAL_ENS_NAMES_REQUEST,
FetchExternalENSNamesRequestAction,
fetchExternalENSNamesSuccess,
fetchExternalENSNamesFailure
} from './actions'
import { getENSBySubdomain } from './selectors'
import { ENS, ENSOrigin, ENSError, Authorization } from './types'
import { getDomainFromName } from './utils'

export function* ensSaga(builderClient: BuilderClient) {
export function* ensSaga(builderClient: BuilderClient, ensApi: ENSApi) {
yield takeLatest(FETCH_LANDS_SUCCESS, handleFetchLandsSuccess)
yield takeEvery(FETCH_ENS_REQUEST, handleFetchENSRequest)
yield takeEvery(FETCH_ENS_WORLD_STATUS_REQUEST, handleFetchENSWorldStatusRequest)
Expand All @@ -84,6 +89,7 @@ export function* ensSaga(builderClient: BuilderClient) {
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)

function* handleFetchLandsSuccess() {
yield put(fetchENSAuthorizationRequest())
Expand Down Expand Up @@ -482,4 +488,15 @@ export function* ensSaga(builderClient: BuilderClient) {
yield put(allowClaimManaFailure(ensError))
}
}

function* handleFetchExternalENSNamesRequest(action: FetchExternalENSNamesRequestAction) {
const owner = action.payload.owner
try {
const names: string[] = yield call([ensApi, ensApi.fetchENSList], owner)
yield put(fetchExternalENSNamesSuccess(owner, names))
} catch (error) {
const ensError: ENSError = { message: error.message }
yield put(fetchExternalENSNamesFailure(owner, ensError))
}
}
}

0 comments on commit 1b8aa15

Please sign in to comment.