@@ -8,14 +8,16 @@ import {
88  ThresholdMessageKit , 
99}  from  '@nucypher/taco' ; 
1010import  {  Mumbai ,  useEthers  }  from  '@usedapp/core' ; 
11- import  {  ethers  }  from  'ethers' ; 
1211import  React ,  {  useEffect ,  useState  }  from  'react' ; 
12+ import  'viem/window' ; 
13+ 
14+ import  {  createPublicClient ,  createWalletClient ,  custom  }  from  'viem' ; 
1315
1416import  {  ConditionBuilder  }  from  './ConditionBuilder' ; 
17+ import  {  DEFAULT_DOMAIN ,  DEFAULT_RITUAL_ID  }  from  './config' ; 
1518import  {  Decrypt  }  from  './Decrypt' ; 
1619import  {  Encrypt  }  from  './Encrypt' ; 
1720import  {  Spinner  }  from  './Spinner' ; 
18- import  {  DEFAULT_DOMAIN ,  DEFAULT_RITUAL_ID  }  from  './config' ; 
1921
2022export  default  function  App ( )  { 
2123  const  {  activateBrowserWallet,  deactivate,  account,  switchNetwork }  = 
@@ -36,42 +38,60 @@ export default function App() {
3638  } ,  [ ] ) ; 
3739
3840  const  encryptMessage  =  async  ( message : string )  =>  { 
41+     if  ( ! window . ethereum )  { 
42+       console . error ( 'You need to connect to your wallet first' ) ; 
43+       return ; 
44+     } 
3945    if  ( ! condition )  { 
4046      return ; 
4147    } 
4248    setLoading ( true ) ; 
4349
4450    await  switchNetwork ( Mumbai . chainId ) ; 
4551
46-     const  provider  =  new  ethers . providers . Web3Provider ( window . ethereum ) ; 
52+     const  publicClient  =  createPublicClient ( { 
53+       transport : custom ( window . ethereum ) , 
54+     } ) ; 
55+     const  walletClient  =  createWalletClient ( { 
56+       transport : custom ( window . ethereum ) , 
57+     } ) ; 
4758    const  encryptedMessage  =  await  encrypt ( 
48-       provider , 
59+       publicClient , 
4960      domain , 
5061      message , 
5162      condition , 
5263      ritualId , 
53-       provider . getSigner ( ) , 
64+       walletClient , 
5465    ) ; 
5566
5667    setEncryptedMessage ( encryptedMessage ) ; 
5768    setLoading ( false ) ; 
5869  } ; 
5970
6071  const  decryptMessage  =  async  ( encryptedMessage : ThresholdMessageKit )  =>  { 
72+     if  ( ! window . ethereum )  { 
73+       console . error ( 'You need to connect to your wallet first' ) ; 
74+       return ; 
75+     } 
6176    if  ( ! condition )  { 
6277      return ; 
6378    } 
6479    setLoading ( true ) ; 
6580    setDecryptedMessage ( '' ) ; 
6681    setDecryptionErrors ( [ ] ) ; 
6782
68-     const  provider  =  new  ethers . providers . Web3Provider ( window . ethereum ) ; 
83+     const  publicClient  =  createPublicClient ( { 
84+       transport : custom ( window . ethereum ) , 
85+     } ) ; 
86+     const  walletClient  =  createWalletClient ( { 
87+       transport : custom ( window . ethereum ) , 
88+     } ) ; 
6989    const  decryptedMessage  =  await  decrypt ( 
70-       provider , 
90+       publicClient , 
7191      domain , 
7292      encryptedMessage , 
7393      getPorterUri ( domain ) , 
74-       provider . getSigner ( ) , 
94+       walletClient , 
7595    ) ; 
7696
7797    setDecryptedMessage ( new  TextDecoder ( ) . decode ( decryptedMessage ) ) ; 
0 commit comments