npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rathfi/widget

v0.0.8

Published

Embeddable cross-chain swap widget by Rath Finance

Downloads

1,061

Readme

Rath Widget

Embeddable cross-chain swap widget by Rath Finance.

Install

npm install @rathfi/widget

When imported into a React app (import RathWidget from "@rathfi/widget", see External wallet management below), these peer dependencies must also be installed: react, react-dom, wagmi, viem, @tanstack/react-query. If you're only using the CDN/<script> embed, none of this applies — it bundles everything itself.

The default and named React imports are equivalent. The API key can be passed directly or as part of config:

import RathWidget from "@rathfi/widget";
// Also supported: import { RathWidget } from "@rathfi/widget";

<RathWidget apiKey="YOUR_RATH_API_KEY" />;
// Equivalent: <RathWidget config={{ apiKey: "YOUR_RATH_API_KEY" }} />;

Or load it straight from a CDN:

<link rel="stylesheet" href="https://unpkg.com/@rathfi/widget/dist/widget.css" />
<script src="https://unpkg.com/@rathfi/widget/dist/widget.js"></script>

Usage

The widget auto-mounts into an element with id rath-widget-root. Pass your API key from the host page — it is never bundled into the widget:

<div id="rath-widget-root" data-rath-api-key="YOUR_RATH_API_KEY"></div>
<link rel="stylesheet" href="https://unpkg.com/@rathfi/widget/dist/widget.css" />
<script src="https://unpkg.com/@rathfi/widget/dist/widget.js"></script>

Or mount manually into any element:

<div id="swap-container"></div>
<script>
  window.RathWidget.mount(document.getElementById("swap-container"), {
    apiKey: "YOUR_RATH_API_KEY",
    theme: { accent: "#0536A0" },
  });
</script>

Note: like any key shipped to the browser, the API key is visible to end users. Use a publishable key and restrict it server-side (e.g. by allowed origins/domains).

External wallet management (host-provided wagmi)

When the widget component is rendered inside a React host app that already has a wagmi setup, the widget detects the surrounding WagmiContext and reuses it instead of creating a second WagmiProvider. The wallet the user connected in the host app is picked up automatically — no duplicate connections, no second connect prompt.

import { WagmiProvider, createConfig, http } from "wagmi";
import { mainnet, base } from "wagmi/chains";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import RathWidget from "@rathfi/widget"; // the widget React component

const wagmiConfig = createConfig({
  chains: [mainnet, base],
  transports: { [mainnet.id]: http(), [base.id]: http() },
});
const queryClient = new QueryClient();

function App() {
  return (
    <WagmiProvider config={wagmiConfig}>
      <QueryClientProvider client={queryClient}>
        {/* your app… */}
        <RathWidget
          config={{
            apiKey: "YOUR_RATH_API_KEY",
            walletConfig: {
              // Open your own wallet modal (RainbowKit, ConnectKit, AppKit, …)
              // when the user clicks the widget's connect button.
              onConnect: () => openMyWalletModal(),
            },
          }}
        />
      </QueryClientProvider>
    </WagmiProvider>
  );
}

walletConfig options

| Option | Effect | | --- | --- | | onConnect?: () => void | Called when the user clicks the widget's connect button, so the host opens its own wallet modal. Without it the widget opens its internal connector menu. | | forceInternalWalletManagement?: boolean | Always use the widget's internal wallet UI, even when onConnect is provided. | | usePartialWalletManagement?: boolean | Keep the widget's internal wallet menu reachable (e.g. via the rath-wallet-open event) alongside onConnect, so the widget can still connect wallets the host does not manage. |

Connect-button behaviour:

  1. If walletConfig.onConnect is set and forceInternalWalletManagement is not true, the widget calls onConnect() and the host shows its modal.
  2. Otherwise the widget opens its internal wallet/connector selection UI (or auto-connects when only one connector is available).

Inside the widget, useWallet() exposes the unified wallet state regardless of who manages the connection: address, chainId, isConnected, the active connector (id, name, icon), the installed connectors, and connect(connectorId) / disconnect(). usesExternalWagmi reports whether a host context was detected.

Requirements & caveats:

  • Context detection only works when the widget renders in the same React tree as the host's WagmiProvider, with wagmi deduped to a single package instance (a second copy of wagmi has its own React context and won't be detected).
  • The CDN/IIFE embed (window.RathWidget.mount) creates its own React root, so it cannot see a host React context — it always falls back to the widget's internal wallet management. walletConfig.onConnect still works there via the mount config.
  • Without a surrounding wagmi context, the widget keeps its existing behaviour: it creates its own WagmiProvider (or uses the wagmiConfig prop passed to RathWalletProvider) and manages wallets internally.

Development

cp .env.example .env   # add your dev API key (used only by npm run dev)
npm install
npm run dev

Publishing

npm publish

prepublishOnly rebuilds dist/ and runs scripts/check-publish-safety.mjs, which blocks the publish if the output contains source maps, VITE_ env references, or any secret value from local .env files. Only dist/ is included in the package (files allowlist in package.json).