forked from blockscout/frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lukso-network/feature/display-up-names
Feature: display up names
- Loading branch information
Showing
7 changed files
with
131 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export type UPResponse = { | ||
type: string; | ||
hasProfileName: boolean; | ||
hasProfileImage: boolean; | ||
LSP3Profile: { | ||
name: string; | ||
profileImage: { | ||
[key: number]: { | ||
url: string; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
ui/shared/entities/address/IdenticonUniversalProfileQuery.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Box } from '@chakra-ui/react'; | ||
import type { QueryClient } from '@tanstack/react-query'; | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import type { UPResponse } from '../../../../types/api/universalProfile'; | ||
|
||
import config from '../../../../configs/app'; | ||
import { getEnvValue } from '../../../../configs/app/utils'; | ||
|
||
interface Props { | ||
address: string; | ||
fallbackIcon: JSX.Element; | ||
} | ||
|
||
export const getUniversalProfile = async(address: string, queryClient: QueryClient) => { | ||
if (config.UI.views.address.identiconType !== 'universal_profile') { | ||
return undefined; | ||
} | ||
const query = queryClient.getQueryData<UPResponse>([ 'universalProfile', { address: address } ]); | ||
if (query !== undefined) { | ||
return query; | ||
} | ||
|
||
return await queryClient.fetchQuery({ | ||
queryKey: [ 'universalProfile', { address: address } ], | ||
queryFn: async() => { | ||
const upApiUrl = getEnvValue('NEXT_PUBLIC_UP_API_URL') || ''; | ||
const networkId = getEnvValue('NEXT_PUBLIC_NETWORK_ID') || '42'; | ||
|
||
const url = `${ upApiUrl }/v1/${ networkId }/address/${ address }`; | ||
try { | ||
const resp = await fetch(url); | ||
const json = await resp.json(); | ||
return json as UPResponse; | ||
} catch (err) { | ||
return undefined; | ||
} | ||
}, | ||
}); | ||
}; | ||
|
||
export const IdenticonUniversalProfile: React.FC<Props> = ({ address, fallbackIcon }) => { | ||
const [ up, setUp ] = useState({} as UPResponse); | ||
const queryClient = useQueryClient(); | ||
useEffect(() => { | ||
(async() => { | ||
const upData = await getUniversalProfile(address, queryClient); | ||
if (upData !== undefined) { | ||
setUp(upData); | ||
|
||
return; | ||
} | ||
})(); | ||
}, [ address, up, setUp, queryClient ]); | ||
|
||
if (up === undefined || up.LSP3Profile === undefined) { | ||
return fallbackIcon; | ||
} | ||
|
||
const lastImageIndex = Object.values(up.LSP3Profile.profileImage).length - 1; | ||
|
||
const profileImageUrl = up.hasProfileImage ? up.LSP3Profile.profileImage[lastImageIndex].url : ''; | ||
return ( | ||
<Box mr={ 2 }> | ||
<lukso-profile | ||
size="x-small" | ||
profile-url={ profileImageUrl } | ||
profile-address={ address } | ||
has-identicon={ true } | ||
></lukso-profile> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default IdenticonUniversalProfile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 19 additions & 2 deletions
21
ui/snippets/searchBar/SearchBarSuggest/SearchBarSuggestAddress.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters