|
7 | 7 | TezosGetAccountResponse,
|
8 | 8 | TezosSendResponse,
|
9 | 9 | TezosSignResponse,
|
| 10 | + ChainData, |
| 11 | + TezosChainDataMainnet, |
10 | 12 | } from "@trili/tezos-provider";
|
11 | 13 | import { ErrorObject } from "@walletconnect/utils";
|
12 | 14 | import { stringToBytes } from "@taquito/utils";
|
@@ -98,21 +100,31 @@ const App = () => {
|
98 | 100 | }, []);
|
99 | 101 |
|
100 | 102 | // Connect to Tezos
|
101 |
| - const connect = useCallback(async () => { |
102 |
| - if (!provider) return; |
| 103 | + const connect = useCallback( |
| 104 | + async (chain: string) => { |
| 105 | + if (!provider) return; |
103 | 106 |
|
104 |
| - try { |
105 |
| - await provider.connect({ chain: TezosChainDataTestnet }); |
106 |
| - setIsConnected(true); |
107 |
| - console.log("Connected to Tezos"); |
108 |
| - const balance = await provider.getBalance(); |
109 |
| - setBalance(TezosProvider.formatTezosBalance(balance)); |
110 |
| - } catch (error) { |
111 |
| - console.error("Error connecting to Tezos:", error); |
112 |
| - } finally { |
113 |
| - modal.closeModal(); |
114 |
| - } |
115 |
| - }, [provider]); |
| 107 | + try { |
| 108 | + switch (chain) { |
| 109 | + case "mainnet": |
| 110 | + await provider.connect({ chain: TezosChainDataMainnet }); |
| 111 | + break; |
| 112 | + case "ghostnet": |
| 113 | + await provider.connect({ chain: TezosChainDataTestnet }); |
| 114 | + break; |
| 115 | + default: |
| 116 | + throw new Error(`Unsupported chain: ${chain}`); |
| 117 | + } |
| 118 | + setIsConnected(true); |
| 119 | + console.log("Connected to Tezos"); |
| 120 | + modal.closeModal(); |
| 121 | + const balance = await provider.getBalance(); |
| 122 | + setBalance(TezosProvider.formatTezosBalance(balance)); |
| 123 | + } catch (error) { |
| 124 | + console.error("Error connecting to Tezos:", error); |
| 125 | + } |
| 126 | + }, [provider], |
| 127 | + ); |
116 | 128 |
|
117 | 129 | // Disconnect from Tezos
|
118 | 130 | const disconnect = useCallback(async () => {
|
@@ -390,7 +402,16 @@ const App = () => {
|
390 | 402 | ) : (
|
391 | 403 | <>
|
392 | 404 | <p>Connect your wallet to get started</p>
|
393 |
| - <button onClick={connect}>Connect</button> |
| 405 | + <div className="layout-container"> |
| 406 | + <div className="btn-container"> |
| 407 | + <button onClick={() => connect("ghostnet")}> |
| 408 | + Connect ghostnet |
| 409 | + </button> |
| 410 | + <button onClick={() => connect("mainnet")}> |
| 411 | + Connect mainnet |
| 412 | + </button> |
| 413 | + </div> |
| 414 | + </div> |
394 | 415 | </>
|
395 | 416 | )}
|
396 | 417 | </div>
|
|
0 commit comments