Skip to content

Commit

Permalink
fix: connect/disconnect in tezos-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina committed Sep 2, 2024
1 parent 0731f36 commit 2ca9ec9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ Catalogue of various wallet and dapp examples implementing WalletConnect's **SDK

**Wallets:**

- [React Wallet (Sign v1 + v2)](https://github.com/WalletConnect/web-examples/tree/main/advanced/wallets/react-wallet-v2) ([Demo](https://react-wallet.walletconnect.com/))

**dApps:**

- [React dApp (with standalone client) - v2](https://github.com/WalletConnect/web-examples/tree/main/advanced/dapps/react-dapp-v2) ([Demo](https://react-app.walletconnect.com/))
- [React dApp (with EthereumProvider + Ethers.js) - v2](https://github.com/WalletConnect/web-examples/tree/main/advanced/dapps/react-dapp-v2-with-ethers) ([Demo](https://react-dapp-v2-with-ethers.vercel.app/))
- [React dApp (with EthereumProvider + web3.js) - v2](https://github.com/WalletConnect/web-examples/tree/main/advanced/dapps/react-dapp-v2-with-web3js) ([Demo](https://react-dapp-v2-with-web3js.vercel.app/))
- [React dApp (with TezosProvider) - v2](https://github.com/WalletConnect/web-examples/tree/main/dapps/tezos-provider)

### Auth API

Expand Down
55 changes: 34 additions & 21 deletions dapps/tezos-provider/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,43 @@ const App = () => {
const [contractAddress, setContractAddress] = useState("");
const [balance, setBalance] = useState("");

console.log("Provider", provider);

// 3. handle display_uri event and open modal
if (provider.signer) {
provider.signer.on("display_uri", async (uri: string) => {
console.log("event display_uri", uri);
await modal.openModal({
uri,
const subscribe = async () => {
if (provider.signer) {
console.log("Subscribing to events...");
provider.signer.on("display_uri", async (uri: string) => {
console.log("event display_uri", uri);
await modal.openModal({
uri,
});
});
});

provider.signer.on("session_ping", ({ id, topic }: { id: string; topic: string }) => {
console.log("Event session_ping:", id, topic);
});
provider.signer.on("session_ping", ({ id, topic }: { id: string; topic: string }) => {
console.log("Event session_ping:", id, topic);
});

provider.signer.on("session_event", ({ event, chainId }: { event: any; chainId: string }) => {
console.log("Event session_event:", event, chainId);
});
provider.signer.on("session_event", ({ event, chainId }: { event: any; chainId: string }) => {
console.log("Event session_event:", event, chainId);
});

provider.signer.on("session_update", ({ topic, params }: { topic: string; params: any }) => {
console.log("Event session_update:", topic, params);
});
provider.signer.on("session_update", ({ topic, params }: { topic: string; params: any }) => {
console.log("Event session_update:", topic, params);
});

provider.signer.on("session_delete", ({ id, topic }: { id: string; topic: string }) => {
console.log("Event session_delete:", id, topic);
});
}
provider.signer.on("session_delete", ({ id, topic }: { id: string; topic: string }) => {
console.log("Event session_delete:", id, topic);
});

provider.signer.on("connect", ({ id, topic }: { id: string; topic: string }) => {
console.log("Event connect:", id, topic);
});

provider.signer.on("disconnect", ({ id, topic }: { id: string; topic: string }) => {
console.log("Event disconnect:", id, topic);
setIsConnected(false);
});
}
};

const getBalance = async () => {
if (provider) {
Expand All @@ -68,7 +78,9 @@ const App = () => {
// 4. handle connect event
const connect = async () => {
window.localStorage.removeItem('walletconnect');
console.log("Connecting...");
try {
await subscribe();
await provider.connect({chains: [TezosChainDataTestnet, TezosChainDataMainnet]});
setIsConnected(true);
console.log("Connected successfully. Provider", provider);
Expand All @@ -83,6 +95,7 @@ const App = () => {

// 5. handle disconnect event
const disconnect = async () => {
console.log("Disconnecting...");
if (provider.signer) {
await provider.signer.disconnect();
}
Expand Down
7 changes: 1 addition & 6 deletions dapps/tezos-provider/src/utils/tezos-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ import {
TezosEndorsementWithSlotOperation,
TezosFailingNoopOperation,
TezosOperationType,
TezosPreAttestationOperation,
TezosPreAttestationOperation,
TezosProposalOperation,
TezosSeedNonceRevelationOperation,
TezosVdfRevelationOperation
} from "@airgap/beacon-types";

import { ScriptedContracts } from "@taquito/rpc";
import { TezosPreEndorsementOperation } from "@airgap/beacon-types/dist/esm/types/tezos/operations/PreEndorsement";

interface PartialTezosOriginationOperation extends Omit<PartialTezosOriginationOperationOriginal, "script"> {
script: ScriptedContracts;
Expand Down Expand Up @@ -538,10 +537,6 @@ class TezosProvider {
return this.tezosSend(op);
}

public async tezosSendPreEndorsement(op: TezosPreEndorsementOperation): Promise<TezosSendResponse> {
return this.tezosSend(op);
}

public async tezosSendProposal(op: TezosProposalOperation): Promise<TezosSendResponse> {
return this.tezosSend(op);
}
Expand Down

0 comments on commit 2ca9ec9

Please sign in to comment.