cosmology-tech / cosmos-kit

Universal wallet connector for the Cosmos ⚛️
https://cosmology.zone/products/cosmos-kit
BSD 3-Clause Clear License
173 stars 129 forks source link

Add check connectable session before connect to mobile on `Keplr Mobile` #468

Closed HeesungB closed 1 month ago

HeesungB commented 1 month ago

Overview

When connecting the Keplr Mobile wallet with Wallect Connect, I set it to connect to an existing session if one exists.

Reasons for the change

For examples, proceed to the example source in cosmos-kit.

  1. The connection works fine when there are no sessions. ![first connect]()
  2. However, if you refresh the page after connecting, it will request connect multiple times due to the source below in the packages/react-lite/src/hooks/useChain.ts file.
    // temporary solution for sync not working when the used chain is changed without page rendering (only component rendering)
    useEffect(() => {
    const currentWallet = window.localStorage.getItem(
      'cosmos-kit@2:core//current-wallet'
    );
    if (
      sync &&
      chainWalletContext &&
      chainWalletContext.isWalletDisconnected &&
      currentWallet
    ) {
      connect(currentWallet);
    }
    }, [chain, assetList]);
  3. Ask the app to confirm the connection via wallect connect signClinet.connect.
  4. You'll see multiple requests, as shown below. ![try to connect]()

What changed.