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 049379d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 37 deletions.
21 changes: 0 additions & 21 deletions src/hooks/useEns.tsx

This file was deleted.

8 changes: 7 additions & 1 deletion src/hooks/useSearchAddressBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ 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/slices/ensResolver.slice";

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
searchTerm !== "" && !isSearchTermAddress && !ensQuery
? addressBookSelectors
.selectAll(state)
.filter((x) => x.chainId === network.chainId)
Expand Down
9 changes: 0 additions & 9 deletions src/hooks/useSearchEns.ts

This file was deleted.

14 changes: 13 additions & 1 deletion 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 @@ -62,7 +67,14 @@ export const useSearchSubgraphByAddress = (searchTerm: string) => {
addressBytes: searchTerm.toLowerCase(),
},
}
: skipToken
: {
chainId: network.chainId,
document: searchByAddressDocument,
variables: {
addressId: ensQuery.address,
addressBytes: ensQuery.address,
},
}
)
);
};
5 changes: 0 additions & 5 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

0 comments on commit 049379d

Please sign in to comment.