cosmology-tech / cosmos-kit

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

Add client selection logic in Keplr mobile #451

Closed HeesungB closed 4 months ago

HeesungB commented 4 months ago

Overview

Users of Keplr Mobile were experiencing an error when connecting their wallet from the web browser inside the app, so I made this change to fix it.

Reasons for the change

  1. I think what you meant to do was to show the presence of window.keplr via the mobileDisabled value.

    // In the Keplr Mobile in-app browser, Keplr is available in window.keplr,
    // similar to the extension on a desktop browser. For this reason, we must
    // check what mode the window.keplr client is in once it's available.
    mobileDisabled: () =>
    !(
    typeof document !== 'undefined' &&
    document.readyState === 'complete' &&
    (window as KeplrWindow).keplr &&
    (window as KeplrWindow).keplr.mode === 'mobile-web'
    ),

    However, if there are two connection buttons, Keplr and Keplr Mobile, most users will connect to WC by pressing the Keplr Mobile button.

  2. If you look at the services developed now, most of them only show the Keplr Mobile button as shown in the screenshot below. Group 1

What changed.

  1. wallets/keplr-mobile/src/wallet-connect/main-wallet.ts Added specifying Keplr Extension Client as the client if window.keplr exists.

  2. ~~I extracted the part of getKeplrFromExtension that returns ClientNotExistError to the outside. This is the original Keplr code (https://github.com/chainapsis/keplr-wallet/blob/master/packages/stores/src/account/get-keplr.ts)~~