1- import { useState } from 'react' ;
2- import { WalletProvider } from '@provablehq/aleo-wallet-adaptor-react' ;
3- import { WalletMultiButton } from '@provablehq/aleo-wallet-adaptor-react-ui' ;
4- import { LeoWalletAdapter } from '@provablehq/aleo-wallet-adaptor-leo ' ;
1+ import React , { useMemo } from 'react' ;
2+ import { AleoWalletProvider } from '@provablehq/aleo-wallet-adaptor-react' ;
3+ import { WalletConnectButton } from '@provablehq/aleo-wallet-adaptor-react-ui' ;
4+ import { PuzzleWalletAdapter } from '@provablehq/aleo-wallet-adaptor-puzzle ' ;
55import { useWallet } from '@provablehq/aleo-wallet-adaptor-react' ;
66import './App.css' ;
77
88// Component to display wallet information
99const WalletInfo = ( ) => {
1010 const { wallet, account } = useWallet ( ) ;
11-
11+
1212 if ( ! wallet || ! account ) {
1313 return < p > Please connect your wallet first.</ p > ;
1414 }
15-
15+
1616 return (
1717 < div className = "wallet-info" >
1818 < h2 > Wallet Connected</ h2 >
19- < p > < strong > Wallet Name:</ strong > { wallet . name } </ p >
20- < p > < strong > Address:</ strong > { account . address } </ p >
19+ < p >
20+ < strong > Wallet Name:</ strong > { wallet . name }
21+ </ p >
22+ < p >
23+ < strong > Address:</ strong > { account . address }
24+ </ p >
2125 </ div >
2226 ) ;
2327} ;
2428
2529// Example transaction component
26- const ExecuteTransaction = ( ) => {
27- const { executeTransaction, connected } = useWallet ( ) ;
28- const [ txId , setTxId ] = useState < string | null > ( null ) ;
29- const [ loading , setLoading ] = useState ( false ) ;
30-
31- const handleExecute = async ( ) => {
32- if ( ! connected ) return ;
33-
34- try {
35- setLoading ( true ) ;
36-
37- // This is just an example - you would need a real program and function to call
38- const tx = await executeTransaction ( {
39- program : 'hello_world.aleo' ,
40- function : 'main' ,
41- inputs : [ ] ,
42- } ) ;
43-
44- setTxId ( tx . id ) ;
45- } catch ( error ) {
46- console . error ( 'Transaction failed' , error ) ;
47- } finally {
48- setLoading ( false ) ;
49- }
50- } ;
51-
52- if ( ! connected ) {
53- return null ;
54- }
55-
56- return (
57- < div className = "transaction" >
58- < button
59- onClick = { handleExecute }
60- disabled = { loading }
61- >
62- { loading ? 'Executing...' : 'Execute Transaction' }
63- </ button >
64-
65- { txId && (
66- < div className = "tx-result" >
67- < p > Transaction ID: { txId } </ p >
68- </ div >
69- ) }
70- </ div >
71- ) ;
72- } ;
30+ // const ExecuteTransaction = () => {
31+ // const { executeTransaction, connected } = useWallet();
32+ // const [txId, setTxId] = useState<string | null>(null);
33+ // const [loading, setLoading] = useState(false);
34+
35+ // const handleExecute = async () => {
36+ // if (!connected) return;
7337
74- function App ( ) {
75- // Initialize wallet adapters
76- const wallets = [
77- new LeoWalletAdapter ( ) ,
78- ] ;
38+ // try {
39+ // setLoading(true);
40+
41+ // // This is just an example - you would need a real program and function to call
42+ // const tx = await executeTransaction({
43+ // program: 'hello_world.aleo',
44+ // function: 'main',
45+ // inputs: [],
46+ // });
47+
48+ // setTxId(tx.id);
49+ // } catch (error) {
50+ // console.error('Transaction failed', error);
51+ // } finally {
52+ // setLoading(false);
53+ // }
54+ // };
55+
56+ // if (!connected) {
57+ // return null;
58+ // }
59+
60+ // return (
61+ // <div className="transaction">
62+ // <button
63+ // onClick={handleExecute}
64+ // disabled={loading}
65+ // >
66+ // {loading ? 'Executing...' : 'Execute Transaction'}
67+ // </button>
68+
69+ // {txId && (
70+ // <div className="tx-result">
71+ // <p>Transaction ID: {txId}</p>
72+ // </div>
73+ // )}
74+ // </div>
75+ // );
76+ // };
77+
78+ export function App ( ) {
79+ // memoize to avoid re‑instantiating adapters on each render
80+ const wallets = useMemo (
81+ ( ) => [
82+ new PuzzleWalletAdapter ( {
83+ appName : 'Aleo Wallet Example' ,
84+ appDescription : 'Example application for Puzzle wallet' ,
85+ programIdPermissions : {
86+ AleoTestnet : [ 'hello_world.aleo' ] , // Example program IDs
87+ } ,
88+ } ) ,
89+ ] ,
90+ [ ] ,
91+ ) ;
7992
8093 return (
81- < WalletProvider wallets = { wallets } autoConnect >
82- < div className = "app" >
83- < h1 > Aleo Wallet Example</ h1 >
84-
85- < div className = "card" >
86- < WalletMultiButton />
87-
94+ < AleoWalletProvider wallets = { wallets } autoConnect >
95+ < header >
96+ < div className = "app" >
97+ < h1 > Aleo Wallet Example</ h1 >
98+ < WalletConnectButton />
99+
88100 < WalletInfo />
89-
90- < ExecuteTransaction />
91101 </ div >
92- </ div >
93- </ WalletProvider >
102+ </ header >
103+ < main > { /* your DApp's components */ } </ main >
104+ </ AleoWalletProvider >
94105 ) ;
95106}
96107
97- export default App ;
108+ export default App ;
0 commit comments