1- import { useState } from 'react' ;
21import { Address } from '@iexec/dataprotector' ;
2+ import { useState } from 'react' ;
3+ import './App.css' ;
4+ import loader from './assets/loader.gif' ;
5+ import successIcon from './assets/success.png' ;
6+ import {
7+ getDataProtectorCoreClient ,
8+ initDataProtectorClient ,
9+ } from './externals/dataProtectorClient' ;
10+ import { useWalletConnection } from './hooks/useWalletConnection' ;
311import {
412 AddressOrEnsName ,
513 checkIsConnected ,
6- IEXEC_EXPLORER_URL ,
7- WEB3MAIL_APP_ENS ,
814 SUPPORTED_CHAINS ,
15+ WEB3MAIL_APP_ENS ,
916} from './utils/utils.ts' ;
10- import { getDataProtectorCoreClient , initDataProtectorClient } from './externals/dataProtectorClient' ;
11- import { useWalletConnection } from './hooks/useWalletConnection' ;
12- import './App.css' ;
13- import loader from './assets/loader.gif' ;
14- import successIcon from './assets/success.png' ;
17+ import { NULL_ADDRESS } from 'iexec/utils' ;
1518
1619export default function App ( ) {
1720 const { isConnected, address, chainId } = useWalletConnection ( ) ;
18- const [ selectedChain , setSelectedChain ] = useState ( SUPPORTED_CHAINS [ 0 ] . id ) ;
21+ const [ selectedChain , setSelectedChain ] = useState ( SUPPORTED_CHAINS [ 2 ] . id ) ;
1922 const [ protectedData , setProtectedData ] = useState < Address | '' > ( '' ) ;
2023 const [ authorizedUser , setAuthorizedUser ] = useState < AddressOrEnsName | '' > (
2124 ''
@@ -43,7 +46,7 @@ export default function App() {
4346 }
4447
4548 // Find the chain configuration
46- const chain = SUPPORTED_CHAINS . find ( c => c . id === targetChainId ) ;
49+ const chain = SUPPORTED_CHAINS . find ( ( c ) => c . id === targetChainId ) ;
4750 if ( ! chain ) {
4851 throw new Error ( `Chain with ID ${ targetChainId } not supported` ) ;
4952 }
@@ -81,7 +84,9 @@ export default function App() {
8184 }
8285 } ;
8386
84- const handleChainChange = async ( event : React . ChangeEvent < HTMLSelectElement > ) => {
87+ const handleChainChange = async (
88+ event : React . ChangeEvent < HTMLSelectElement >
89+ ) => {
8590 const newChainId = Number ( event . target . value ) ;
8691 setSelectedChain ( newChainId ) ;
8792
@@ -112,7 +117,7 @@ export default function App() {
112117 // Reinitialize the DataProtector client with the correct chain
113118 await initDataProtectorClient ( {
114119 provider : window . ethereum ,
115- chainId : selectedChain
120+ chainId : selectedChain ,
116121 } ) ;
117122 } catch ( err ) {
118123 setErrorProtect ( 'Please install MetaMask or switch to the correct chain' ) ;
@@ -128,11 +133,10 @@ export default function App() {
128133 try {
129134 setLoadingProtect ( true ) ;
130135 const client = await getDataProtectorCoreClient ( ) ;
131- const protectedDataResponse =
132- await client . protectData ( {
133- data,
134- name,
135- } ) ;
136+ const protectedDataResponse = await client . protectData ( {
137+ data,
138+ name,
139+ } ) ;
136140 setProtectedData ( protectedDataResponse . address as Address ) ;
137141 setErrorProtect ( '' ) ;
138142 } catch ( error ) {
@@ -141,9 +145,13 @@ export default function App() {
141145
142146 // Provide more specific error messages
143147 if ( String ( error ) . includes ( 'Internal JSON-RPC error' ) ) {
144- setErrorProtect ( 'RPC Error: Please check your network connection and ensure you have sufficient xRLC for gas fees on Bellecour' ) ;
148+ setErrorProtect (
149+ 'RPC Error: Please check your network connection and ensure you have sufficient xRLC for gas fees on Bellecour'
150+ ) ;
145151 } else if ( String ( error ) . includes ( 'insufficient funds' ) ) {
146- setErrorProtect ( 'Insufficient funds: Please ensure you have enough xRLC tokens for gas fees' ) ;
152+ setErrorProtect (
153+ 'Insufficient funds: Please ensure you have enough xRLC tokens for gas fees'
154+ ) ;
147155 } else if ( String ( error ) . includes ( 'user rejected' ) ) {
148156 setErrorProtect ( 'Transaction rejected by user' ) ;
149157 } else {
@@ -162,7 +170,7 @@ export default function App() {
162170 // Reinitialize the DataProtector client with the correct chain
163171 await initDataProtectorClient ( {
164172 provider : window . ethereum ,
165- chainId : selectedChain
173+ chainId : selectedChain ,
166174 } ) ;
167175 } catch ( err ) {
168176 setErrorGrant ( 'Please install MetaMask or switch to the correct chain' ) ;
@@ -179,7 +187,7 @@ export default function App() {
179187 await client . grantAccess ( {
180188 protectedData,
181189 authorizedUser : userAddress ,
182- authorizedApp : WEB3MAIL_APP_ENS ,
190+ authorizedApp : SUPPORTED_CHAINS . find ( ( c ) => c . id === selectedChain ) ?. web3mailAppAddress as Address ,
183191 numberOfAccess,
184192 } ) ;
185193 setAuthorizedUser ( userAddress ) ;
@@ -200,7 +208,7 @@ export default function App() {
200208 // Reinitialize the DataProtector client with the correct chain
201209 await initDataProtectorClient ( {
202210 provider : window . ethereum ,
203- chainId : selectedChain
211+ chainId : selectedChain ,
204212 } ) ;
205213 } catch ( err ) {
206214 setErrorRevoke ( 'Please install MetaMask or switch to the correct chain' ) ;
@@ -210,12 +218,11 @@ export default function App() {
210218 try {
211219 setLoadingRevoke ( true ) ;
212220 const client = await getDataProtectorCoreClient ( ) ;
213- const allGrantedAccess =
214- await client . getGrantedAccess ( {
215- protectedData,
216- authorizedUser,
217- authorizedApp : WEB3MAIL_APP_ENS ,
218- } ) ;
221+ const allGrantedAccess = await client . getGrantedAccess ( {
222+ protectedData,
223+ authorizedUser,
224+ authorizedApp : SUPPORTED_CHAINS . find ( ( c ) => c . id === selectedChain ) ?. web3mailAppAddress as Address ,
225+ } ) ;
219226 if ( allGrantedAccess . count === 0 ) {
220227 throw new Error ( 'No access to revoke' ) ;
221228 }
@@ -242,7 +249,9 @@ export default function App() {
242249 setName ( event . target . value ) ;
243250 } ;
244251
245- const handleNumberOfAccessChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
252+ const handleNumberOfAccessChange = (
253+ event : React . ChangeEvent < HTMLInputElement >
254+ ) => {
246255 setNumberOfAccess ( Number ( event . target . value ) ) ;
247256 } ;
248257
@@ -258,13 +267,31 @@ export default function App() {
258267 return (
259268 < >
260269 { /* Chain Selection */ }
261- < div style = { { marginBottom : '20px' , padding : '20px' , border : '1px solid #ddd' , borderRadius : '8px' } } >
262- < h2 style = { { margin : '0 0 10px 0' , display : 'flex' , alignItems : 'center' , gap : '10px' } } >
270+ < div
271+ style = { {
272+ marginBottom : '20px' ,
273+ padding : '20px' ,
274+ border : '1px solid #ddd' ,
275+ borderRadius : '8px' ,
276+ } }
277+ >
278+ < h2
279+ style = { {
280+ margin : '0 0 10px 0' ,
281+ display : 'flex' ,
282+ alignItems : 'center' ,
283+ gap : '10px' ,
284+ } }
285+ >
263286 Chain Selection
264287 < select
265288 value = { selectedChain }
266289 onChange = { handleChainChange }
267- style = { { padding : '5px' , borderRadius : '4px' , border : '1px solid #ccc' } }
290+ style = { {
291+ padding : '5px' ,
292+ borderRadius : '4px' ,
293+ border : '1px solid #ccc' ,
294+ } }
268295 >
269296 { SUPPORTED_CHAINS . map ( ( chain ) => (
270297 < option key = { chain . id } value = { chain . id } >
@@ -274,22 +301,28 @@ export default function App() {
274301 </ select >
275302 </ h2 >
276303 < p style = { { margin : '5px 0' , color : '#666' } } >
277- Selected chain: { SUPPORTED_CHAINS . find ( c => c . id === selectedChain ) ?. name } (ID: { selectedChain } )
304+ Selected chain:{ ' ' }
305+ { SUPPORTED_CHAINS . find ( ( c ) => c . id === selectedChain ) ?. name } (ID:{ ' ' }
306+ { selectedChain } )
278307 </ p >
279308
280309 { /* Wallet Status */ }
281310 < div style = { { marginTop : '10px' , fontSize : '14px' } } >
282311 < p style = { { margin : '2px 0' } } >
283- < strong > Wallet Status:</ strong > { isConnected ? 'Connected' : 'Disconnected' }
312+ < strong > Wallet Status:</ strong > { ' ' }
313+ { isConnected ? 'Connected' : 'Disconnected' }
284314 </ p >
285315 { address && (
286316 < p style = { { margin : '2px 0' } } >
287- < strong > Address:</ strong > { address . slice ( 0 , 6 ) } ...{ address . slice ( - 4 ) }
317+ < strong > Address:</ strong > { address . slice ( 0 , 6 ) } ...
318+ { address . slice ( - 4 ) }
288319 </ p >
289320 ) }
290321 { chainId && (
291322 < p style = { { margin : '2px 0' } } >
292- < strong > Current MetaMask Chain:</ strong > { SUPPORTED_CHAINS . find ( c => c . id === chainId ) ?. name || `Chain ${ chainId } ` }
323+ < strong > Current MetaMask Chain:</ strong > { ' ' }
324+ { SUPPORTED_CHAINS . find ( ( c ) => c . id === chainId ) ?. name ||
325+ `Chain ${ chainId } ` }
293326 </ p >
294327 ) }
295328 </ div >
@@ -347,7 +380,10 @@ export default function App() {
347380 />
348381 Your data has been protected!
349382 < a
350- href = { IEXEC_EXPLORER_URL + protectedData }
383+ href = {
384+ SUPPORTED_CHAINS . find ( ( c ) => c . id === selectedChain )
385+ ?. explorerUrl + protectedData
386+ }
351387 rel = "noreferrer"
352388 target = "_blank"
353389 >
0 commit comments