Skip to content

Commit

Permalink
feat(ensDomains): add getUser avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
developerfred committed May 25, 2022
1 parent 1fdc76b commit 123308a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
9 changes: 9 additions & 0 deletions src/hooks/useSearchEns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {useMemo} from "react";
import {ethers} from "ethers";
import {networks} from "../redux/networks";
import {useAppSelector} from "../redux/hooks";
import {ensApi} from "../redux/slices/ensResolver.slice";

const ensQuery = ensApi.useResolveNameQuery(
searchTermDebounced ? searchTermDebounced : skipToken
);
53 changes: 26 additions & 27 deletions src/redux/slices/ensResolver.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface NameInfo {
address: string
}

export interface ProfileInfo {
avatar: string[]
bio: string
name: string
}


export const getNameById = async (id: string ) => {
if (!id) return ''
Expand All @@ -24,33 +30,14 @@ export const getAddressByName = async (id: string) => {
return rsp.address
}

// export const createEntryNameId = (ensName: string | null, address: string) => (`${ensName}_${address.toLowerCase()}`);

// export const getEntryNameId = (nameInfo: NameInfo) => {

// return `${nameInfo.ensName}_${nameInfo.address.toLowerCase()}`;
// }

// export const ensAdapter = createEntityAdapter({
// selectId: (entry: NameInfo) => getEntryNameId(entry),
// })

// const sliceName = 'ensAddress';
export const getUserAvatar = async (address: string) => {
if (!address) return ''
const url = urlcat('https://hub.pass3.me/:address', { address })
const userInfo = (await (await fetch(url)).json()) as ProfileInfo
return userInfo.avatar

// export const ensResolverSlice = createSlice({
// name: sliceName,
// initialState: ensAdapter.getInitialState(),
// reducers: {
// entryUpserted: ensAdapter.upsertOne,
// entryRemoved: ensAdapter.removeOne
// },
// extraReducers: {
// [REHYDRATE]: (state, {payload}) => ({
// ...state,
// ...(payload ? payload[sliceName] : {}),
// }),
// },
// })
}


export const ensApi = createApi({
Expand Down Expand Up @@ -94,9 +81,21 @@ export const ensApi = createApi({
};
},
}),
lookupAvatar: builder.query<
{ address: string; avatar: string } | null,
string>({
queryFn: async (address) => {
const avatar = await getUserAvatar(address);
return {
data: avatar ? {
address,
avatar: avatar[0]
}
: null,
}
}
})
};
},
});

// export const ensResolveApi = ensAdapter.getSelectors((state: RootState) => state.ensAdapter)

0 comments on commit 123308a

Please sign in to comment.