From 59ecaf344991cfd32638391fecd4685a8bd3f52c Mon Sep 17 00:00:00 2001 From: erditkurteshiSQA <95851348+erditkurteshiSQA@users.noreply.github.com> Date: Thu, 21 Sep 2023 15:22:46 +0200 Subject: [PATCH] fix: Added installed and mobile check for near snap (#938) * added isInstall method for near-snap * added isMobile method for near-snap * fixed check for nightly * removed default wallet from documentation --- README.md | 2 -- packages/near-snap/src/lib/index.ts | 34 ++++++++++++++++++++++++++++- packages/nightly/src/lib/nightly.ts | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0f8495044..1022bf15c 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,6 @@ yarn add \ @near-wallet-selector/ledger \ @near-wallet-selector/wallet-connect \ @near-wallet-selector/nightly-connect \ - @near-wallet-selector/default-wallets \ @near-wallet-selector/coin98-wallet \ @near-wallet-selector/opto-wallet \ @near-wallet-selector/neth \ @@ -90,7 +89,6 @@ npm install \ @near-wallet-selector/ledger \ @near-wallet-selector/wallet-connect \ @near-wallet-selector/nightly-connect \ - @near-wallet-selector/default-wallets \ @near-wallet-selector/coin98-wallet \ @near-wallet-selector/opto-wallet \ @near-wallet-selector/neth \ diff --git a/packages/near-snap/src/lib/index.ts b/packages/near-snap/src/lib/index.ts index 0d0947239..467bd18a3 100644 --- a/packages/near-snap/src/lib/index.ts +++ b/packages/near-snap/src/lib/index.ts @@ -1,14 +1,46 @@ +import { isMobile } from "is-mobile"; import type { WalletModuleFactory } from "@near-wallet-selector/core"; import { initNearSnap } from "./selector"; import icon from "./icon"; export { icon }; +declare global { + interface Window { + ethereum: { + chainId: string; + // eslint-disable-next-line + request: any; + }; + } +} + +const isInstalled = async (): Promise => { + try { + const provider = window.ethereum; + const clientVersion = await provider?.request({ + method: "web3_clientVersion", + }); + + const isFlaskDetected = (clientVersion as Array)?.includes("flask"); + return Boolean(provider && isFlaskDetected); + } catch { + return false; + } +}; + export function setupNearSnap({ deprecated = false, iconUrl = icon, } = {}): WalletModuleFactory { return async () => { + const mobile = isMobile(); + if (mobile) { + return null; + } + + const installed = await isInstalled(); + return { id: "near-snap", type: "injected", @@ -19,7 +51,7 @@ export function setupNearSnap({ downloadUrl: "https://near-snap.surge.sh", iconUrl, deprecated, - available: true, + available: installed, }, }; }; diff --git a/packages/nightly/src/lib/nightly.ts b/packages/nightly/src/lib/nightly.ts index 238da134b..48d7e9056 100644 --- a/packages/nightly/src/lib/nightly.ts +++ b/packages/nightly/src/lib/nightly.ts @@ -193,7 +193,7 @@ const Nightly: WalletBehaviourFactory = async ({ state, }); - if (_state.wallet.isConnected) { + if (!_state.wallet.isConnected) { await _state.wallet.connect(); }