Skip to content

Commit

Permalink
feat(ens): add redux hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
developerfred committed May 25, 2022
1 parent 123308a commit 1dc16b1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 39 deletions.
21 changes: 0 additions & 21 deletions src/hooks/useEns.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions src/hooks/useSearchAddressBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import {ethers} from "ethers";
import {networks} from "../redux/networks";
import {useAppSelector} from "../redux/hooks";
import {addressBookSelectors} from "../redux/slices/addressBook.slice";
import {ensApi} from "../redux/store";

export const useSearchAddressBook = (searchTerm: string) => {
const isSearchTermAddress = useMemo(
() => ethers.utils.isAddress(searchTerm),
[searchTerm]
);


const ensQuery = ensApi.useResolveNameQuery(
searchTerm
)

return networks.map((network) => {
const addressBookEntries = useAppSelector((state) =>
searchTerm !== "" && !isSearchTermAddress
Expand Down
9 changes: 0 additions & 9 deletions src/hooks/useSearchEns.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/hooks/useSearchSubgraphByAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useMemo} from "react";
import {ethers} from "ethers";
import {networks} from "../redux/networks";
import {sfSubgraph} from "../redux/store";
import {ensApi} from "../redux/store";
import {skipToken} from "@reduxjs/toolkit/query";
import {gql} from "graphql-request";

Expand Down Expand Up @@ -51,6 +52,10 @@ export const useSearchSubgraphByAddress = (searchTerm: string) => {
[searchTerm]
);

// const ensQuery = ensApi.useResolveNameQuery(
// searchTerm ? searchTerm : skipToken
// )

return networks.map((network) =>
sfSubgraph.useCustomQuery(
isSearchTermAddress
Expand All @@ -63,6 +68,14 @@ export const useSearchSubgraphByAddress = (searchTerm: string) => {
},
}
: skipToken
// : {
// chainId: network.chainId,
// document: searchByAddressDocument,
// variables: {
// addressId: ensQuery.address,
// addressBytes: ensQuery.address,
// },
// }
)
);
};
2 changes: 1 addition & 1 deletion src/pages/[_network]/supertokens/[_id].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext, useEffect, useState } from "react";
import { sfSubgraph } from "../../../redux/store";
import { sfSubgraph} from "../../../redux/store";
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
import { TabContext, TabList, TabPanel } from "@mui/lab";
import {
Expand Down
4 changes: 2 additions & 2 deletions src/redux/slices/ensResolver.slice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import urlcat from 'urlcat'
import { fakeBaseQuery } from "@reduxjs/toolkit/dist/query";
import { createApi } from "@reduxjs/toolkit/dist/query/react";
import { ethers } from "ethers";
import { createApi, fetchBaseQuery, fakeBaseQuery } from "@reduxjs/toolkit/query/react";

export interface NameInfo {
rnsName: string
Expand Down Expand Up @@ -99,3 +98,4 @@ export const ensApi = createApi({
},
});

export const { useResolveNameQuery, useLookupAvatar, useLookupAddress } = ensApi
8 changes: 2 additions & 6 deletions src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ export const makeStore = wrapMakeStore(() => {
addressBookSlice.reducer
);

// const ensReducer = persistReducer(
// { key: "ens-address", version: 1, storage: storageLocal },
// ensResolverSlice.reducer
// )

const store = configureStore({
reducer: {
[rpcApi.reducerPath]: rpcApi.reducer,
Expand Down Expand Up @@ -92,7 +87,8 @@ export const makeStore = wrapMakeStore(() => {
})
)
.concat(rpcApi.middleware)
.concat(sfSubgraph.middleware),
.concat(sfSubgraph.middleware)
.concat(ensApi.middleware),
});

if (!isServer()) {
Expand Down

0 comments on commit 1dc16b1

Please sign in to comment.