fabianbormann / cardano-peer-connect

This library aims to provide simple interfaces to implement CIP-0045 for dApps and wallets
Apache License 2.0
11 stars 4 forks source link

How can the dapp disconnect from the wallet? #57

Open hrajchert opened 8 months ago

hrajchert commented 8 months ago

I've seen that the class CardanoPeerConnect that wallets should implement have a disconnect method, but the dapp class DAppPeerConnect only has an onDisconnect handler. How can I terminate the connection from the dapp?

fabianbormann commented 8 months ago

Hi @hrajchert, I think it should be part of the demo implementation here: https://github.com/fabianbormann/cip-0045-demo-implementation/blob/main/demo-dapp/src/App.tsx#L78

Please let me know in case that it doesn't fit your needs.

hrajchert commented 8 months ago

Hi @fabianbormann! Thanks for the reply, sadly I wasn't able to use the demo code as I'm not using the @cardano-foundation/cardano-connect-with-wallet-core library. I tried looking up the library's source code (to try to replicate the disconnect logic) but couldn't find the repo. Here is my current attempt, which is failing due to infinite recursion.

For more context, I'm trying to add mobile support to Marlowe contracts by adding some connector capabilities to the Marlowe TS-SDK. The PR that I mentioned allows any Marlowe user to interact with Marlowe contracts using a cip-45 wallet, but I had some problems trying to do a more realistic prototype.

The prototype I had in mind was a split-the-bill dapp, where a restaurant can charge a table splitting the bill among the different diners. Each diner could say how much tip they want to give, and the tips are distributed automatically to the staff.

The flow I had in mind:

  1. The restaurant has a dapp in a tablet carried by the waiter. They can configure a payment address and addresses for each staff member(to distribute tips).
  2. When it is time to charge, they put the full amount (or item per item) and ask the table how many shares is the bill going to be split and creates a contract that expects that many deposits
  3. Each diner can scan the QR code to connect to the dapp. With the current limitations, the waiter needs to ask for a tip percentage as the dapp needs to run in the browser. It would be ideal if the diner could access a mobile dapp and select the tip themselves.
  4. After all diners have made their deposits, the contract pays the restaurant and distributes the tips evenly to the staff.
hrajchert commented 8 months ago

I found the code for wallet core 😅, but I'm not sure the code there applies to my example

fabianbormann commented 8 months ago

@hrajchert did it work for you? Otherwise I would invite you to join our CF Dev Discord server. https://discord.gg/HwTp2wyhjy

There is a channel for cip45 (which I should maybe rename to cardano-connect) and we could probably have a deeper discussion there or we could have a call 😊 ?

hrajchert commented 7 months ago

Hi @fabianbormann, as I mentioned in the message the disconnection method available in the demo app does not work for me as I'm not using the @cardano-foundation/cardano-connect-with-wallet-core library. I've read the code but it seems internal cleanup. I'm missing something that notifies the wallet that the Dapp wants to disconnect.

If you have some time I would love to have a call and discuss use cases :).

fabianbormann commented 7 months ago

My twitter handle is @YetAnotherAiGuy or my Discord user is abundzugamer ;) .. Would be nice if you could reach out to me on one channel so that we can find a good meeting slot.