-
Notifications
You must be signed in to change notification settings - Fork 2
feat: code refactor and request fetching optimisation #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
37da14d
feat: implement ContactItem component for displaying contact details …
ErwanDecoster c3664dc
fix: update @iexec/web3mail dependency to version 1.2.2
ErwanDecoster 08141de
fix: enable strict user fetching for Telegram contacts
ErwanDecoster e8148a3
fix: invalidate queries for fetching contacts and contact details aft…
ErwanDecoster 2dc504d
refactor: simplify code
ErwanDecoster b0d83b1
fix: remove debug log from fetchContactDetails function
ErwanDecoster 5b1a4d2
Merge branch 'fix/too-many-request-and-code-refactor' of github.com:i…
ErwanDecoster 9b2249d
fix: consolidate contact name display into a single line
ErwanDecoster 2832655
fix: replace CircularLoader with LoadingSpinner and improve loading s…
ErwanDecoster 21d7cfb
fix: improve error handling in ContactItem component
Le-Caignec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,119 @@ | ||
| import { | ||
| WEB3MAIL_IDAPPS_WHITELIST_SC, | ||
| WEB3TELEGRAM_IDAPPS_WHITELIST_SC, | ||
| } from '@/config/config'; | ||
| import { Contact as Web3mailContact } from '@iexec/web3mail'; | ||
| import { Contact as Web3telegramContact } from '@iexec/web3telegram'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { Link } from 'react-router-dom'; | ||
| import { CircularLoader } from '@/components/CircularLoader'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { getDataProtectorCoreClient } from '@/externals/iexecSdkClient'; | ||
| import useUserStore from '@/stores/useUser.store'; | ||
| import { cn } from '@/utils/style.utils'; | ||
|
|
||
| interface ContactItemProps { | ||
| contact: (Web3telegramContact | Web3mailContact) & { | ||
| contactType: 'mail' | 'telegram'; | ||
| }; | ||
| } | ||
|
|
||
| const fetchContactDetails = async ( | ||
| contact: (Web3telegramContact | Web3mailContact) & { | ||
| contactType: 'mail' | 'telegram'; | ||
| }, | ||
| userAddress: string | ||
| ) => { | ||
| console.log('Fetching contact details...'); | ||
| const dataProtectorCore = await getDataProtectorCoreClient(); | ||
|
|
||
| const contactProtectedData = await dataProtectorCore.getProtectedData({ | ||
| protectedDataAddress: contact.address, | ||
| }); | ||
|
|
||
| const grantedAccess = await dataProtectorCore.getGrantedAccess({ | ||
| protectedData: contact.address, | ||
| authorizedUser: userAddress, | ||
| authorizedApp: | ||
| contact.contactType === 'mail' | ||
| ? WEB3MAIL_IDAPPS_WHITELIST_SC | ||
| : WEB3TELEGRAM_IDAPPS_WHITELIST_SC, | ||
| }); | ||
|
|
||
| return { | ||
| ...contactProtectedData[0], | ||
| contactType: contact.contactType, | ||
| volume: grantedAccess.grantedAccess[0].volume, | ||
| }; | ||
| }; | ||
|
|
||
| export default function ContactItem({ contact }: ContactItemProps) { | ||
| const { address: userAddress } = useUserStore(); | ||
|
|
||
| const { | ||
| data: contactDetails, | ||
| isLoading, | ||
| isError, | ||
| } = useQuery({ | ||
| queryKey: ['contactDetails', contact.address, userAddress], | ||
| queryFn: () => fetchContactDetails(contact, userAddress as string), | ||
| enabled: !!userAddress, | ||
| refetchOnWindowFocus: false, | ||
| staleTime: 5 * 60 * 1000, // 5 minutes | ||
| }); | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <div className="contents"> | ||
| <div className="col-span-6 flex items-center justify-center py-4"> | ||
| <CircularLoader /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (isError || !contactDetails) { | ||
| return ( | ||
| <div className="contents"> | ||
| <div className="col-span-6 flex items-center justify-center py-4 text-red-500"> | ||
| Error loading contact details | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| 'bg-grey-50 even:*:bg-grey-800 *:border-grey-600 contents text-sm *:flex *:h-full *:items-center *:border-t *:px-5 *:py-3' | ||
| )} | ||
| > | ||
| <div className="truncate"> | ||
| {contactDetails.name ? contactDetails.name : '(No name)'} | ||
ErwanDecoster marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </div> | ||
| <div className="truncate"> | ||
| <span className="truncate whitespace-nowrap"> | ||
| {contactDetails.address} | ||
| </span> | ||
| </div> | ||
| <div className="truncate"> | ||
| <span className="truncate whitespace-nowrap"> | ||
| {contactDetails.owner === userAddress | ||
| ? `(Mine) ${contactDetails.owner}` | ||
| : contactDetails.owner} | ||
| </span> | ||
| </div> | ||
| <div className="truncate">{contactDetails.volume}</div> | ||
| <div className="text-primary truncate uppercase"> | ||
| {contactDetails.contactType} | ||
| </div> | ||
| <div className="justify-end"> | ||
| <Button asChild variant="discreet_outline"> | ||
| <Link to={`/contacts/${contactDetails.address}/send-message`}> | ||
| Send | ||
| </Link> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.