Skip to content

Commit bf91bef

Browse files
fix: update Web3mail and Web3telegram to use new returned value and simplify ContactItem components (#133)
1 parent 3811ee1 commit bf91bef

File tree

3 files changed

+23
-75
lines changed

3 files changed

+23
-75
lines changed

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"@fontsource/space-mono": "^5.2.5",
2424
"@graphql-codegen/introspection": "^4.0.3",
2525
"@iexec/dataprotector": "^2.0.0-beta.18",
26-
"@iexec/web3mail": "^1.3.1",
27-
"@iexec/web3telegram": "^0.1.0-alpha.2",
26+
"@iexec/web3mail": "^1.4.0",
27+
"@iexec/web3telegram": "^0.1.0-alpha.3",
2828
"@radix-ui/react-dialog": "^1.1.6",
2929
"@radix-ui/react-label": "^2.1.2",
3030
"@radix-ui/react-select": "^2.1.6",

src/modules/send-message/ContactItem.tsx

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import {
2-
WEB3MAIL_IDAPPS_WHITELIST_SC,
3-
WEB3TELEGRAM_IDAPPS_WHITELIST_SC,
4-
} from '@/config/config';
51
import { Contact as Web3mailContact } from '@iexec/web3mail';
62
import { Contact as Web3telegramContact } from '@iexec/web3telegram';
7-
import { useQuery } from '@tanstack/react-query';
83
import { Link } from 'react-router-dom';
9-
import { LoadingSpinner } from '@/components/LoadingSpinner';
104
import { Button } from '@/components/ui/button';
11-
import { getDataProtectorCoreClient } from '@/externals/iexecSdkClient';
125
import useUserStore from '@/stores/useUser.store';
136
import { cn } from '@/utils/style.utils';
147

@@ -18,63 +11,16 @@ interface ContactItemProps {
1811
};
1912
}
2013

21-
const fetchContactDetails = async (
22-
contact: (Web3telegramContact | Web3mailContact) & {
23-
contactType: 'mail' | 'telegram';
24-
},
25-
userAddress: string
26-
) => {
27-
const dataProtectorCore = await getDataProtectorCoreClient();
28-
29-
const contactProtectedData = await dataProtectorCore.getProtectedData({
30-
protectedDataAddress: contact.address,
31-
});
32-
33-
const grantedAccess = await dataProtectorCore.getGrantedAccess({
34-
protectedData: contact.address,
35-
authorizedUser: userAddress,
36-
authorizedApp:
37-
contact.contactType === 'mail'
38-
? WEB3MAIL_IDAPPS_WHITELIST_SC
39-
: WEB3TELEGRAM_IDAPPS_WHITELIST_SC,
40-
});
41-
42-
return {
43-
...contactProtectedData[0],
44-
contactType: contact.contactType,
45-
volume: grantedAccess.grantedAccess[0].volume,
46-
};
47-
};
48-
4914
export default function ContactItem({ contact }: ContactItemProps) {
5015
const { address: userAddress } = useUserStore();
5116

52-
const {
53-
data: contactDetails,
54-
isLoading,
55-
isError,
56-
} = useQuery({
57-
queryKey: ['contactDetails', contact.address, userAddress],
58-
queryFn: () => fetchContactDetails(contact, userAddress as string),
59-
enabled: !!userAddress,
60-
refetchOnWindowFocus: false,
61-
staleTime: 5 * 60 * 1000, // 5 minutes
62-
});
63-
64-
if (isError) {
65-
// TODO: Handle error more gracefully. Do not display error in the UI.
66-
console.error('Error loading contact details:', contact.address);
67-
}
68-
6917
return (
7018
<div
7119
className={cn(
7220
'bg-grey-50 even:*:bg-grey-800 *:border-grey-600 contents text-sm *:flex *:h-full *:items-center *:border-t *:px-5 *:py-3'
7321
)}
7422
>
75-
<div className="truncate">
76-
{isLoading ? <LoadingSpinner /> : contactDetails?.name || '(No name)'}
77-
</div>
23+
<div className="truncate">{contact.name || '(No name)'}</div>
7824
<div className="truncate">
7925
<span className="truncate whitespace-nowrap">{contact.address}</span>
8026
</div>
@@ -86,7 +32,9 @@ export default function ContactItem({ contact }: ContactItemProps) {
8632
</span>
8733
</div>
8834
<div className="truncate">
89-
{isLoading ? <LoadingSpinner /> : contactDetails?.volume || 'N/A'}
35+
{contact.remainingAccess !== undefined
36+
? contact.remainingAccess
37+
: 'N/A'}
9038
</div>
9139
<div className="text-primary truncate uppercase">
9240
{contact.contactType}

0 commit comments

Comments
 (0)