@dexhunterio/swaps

中文文档
2.0.5发布于 2026/05/13TypeScriptES Module近 30 天下载 2504

How to use library (with React)

原始使用文档
文档目录3 节
  1. How to use library (with React)
  2. How to use library (with VanilaJS)
  3. Available props:

Dex Hunter - Swap Component

How to use library (with React)

  1. Install package:
    npm i @dexhunterio/swaps
    
  2. Import to your code 2.1. For ReactJS:
      import '@dexhunterio/swaps/lib/assets/style.css'
      import Swap from '@dexhunterio/swaps'
      ...
    
    2.2. For NextJS:
    "use client";
    import '@dexhunterio/swaps/lib/assets/style.css'
    const Swap = dynamic(() => import("@dexhunterio/swaps"), {
        ssr: false,
    });
    ...
    
  3. Use Swap Component:
    function App() {
      return (
        <div>
          <Swap {...settings} />
        </div>
      );
    }
    

How to use library (with VanilaJS)

  • In head tag
    <head>
      ...
      <script
        src="https://unpkg.com/[email protected]/umd/react.production.min.js"
        crossorigin
      ></script>
      <script
        src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"
        crossorigin
      ></script>
      <script
        type="module"
        src="https://unpkg.com/@dexhunterio/[email protected]/lib/umd/swaps.umd.js"
      ></script>
      ...
    </head>
    
  • In body tag:
    ...
    <div id="dexhunter"></div>
    <script type="module">
      ReactDOM.render(
        React.createElement(dexhunterSwap, {
          orderTypes: ['SWAP', 'LIMIT', 'DCA'],
          theme: 'light',
        }),
        document.getElementById('dexhunter')
      );
    </script>
    ...
    

Available props:

| Prop | Required? | Type | Default | Description | | :--------------------: | :-------: | :-------------------------------------------------------------------------------: | :---------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | --------- | -------------------------- | | defaultToken | false | string | - | The default token to be selected. | | width | false | px|% | - | The width of the component. Accepts values in pixels or percentage. | | height | false | px|% | - | The height of the component. Accepts values in pixels or percentage. | | theme | false | dark | light | dark | The theme of the component. Can be either 'dark' or 'light'. | | orderTypes | false | array | ['SWAP', 'LIMIT'] | An array of order types supported by the component. Defaults to 'SWAP' and 'LIMIT'. | | supportedTokens | false | tokenId[] | - | An array of token IDs that are supported for searching. | | partnerName | true | string | - | The name of the partner. This is a required field. | | partnerCode | true | string | - | The code of the partner. This is a required field. | | colors | false | object | - | Supported colors: mainText, subText, background, containers, buttonText, accent. | | className | false | string | - | Custom CSS class for the component. | | style | false | object | - | Inline styles for the component. | | onSwapSuccess | false | (data: any) => void | - | Callback function on successful swap. | | onSwapError | false | (err: any) => void | - | Callback function on swap error. | | selectedWallet | false | SelectedWallet | - | The wallet selected by the user. Accepts one of the specified wallet identifiers. Supported wallets: nami, eternl, flint, gerowallet, typhoncip30, nufi, lace, vespr, begin, and yoroi. | | inputs | false | string[] | - | Input fields for the component. | | onWalletConnect | false | (data: any) => void | - | Callback function when a wallet is connected. | | onClickWalletConnect | false | () => void | - | Trigger when clicking the wallet connect button | | onViewOrder | false | (data: any) => void | - | Trigger when clicking the view order button | | displayType | false | 'BUTTON' | 'DEFAULT' | 'WIDGET' | 'DEFAULT' | display type | | buttonText | false | string | Swap | Button text when displayType = 'BUTTON' | | orderTypeOnButtonClick | false | 'SWAP' | 'LIMIT' | 'DCA' | 'SWAP' | Tab default when displayed | | defaultSettings | false | { isCustomSlippage?: boolean; isAutomaticSlippage?: boolean; slippage?: number; } | - | Settings default | | autoFocus | false | boolean | false | auto focus on sell input when page loads |

版本与发布记录

@dexhunterio/swaps 共发布 179 个版本,首次发布于 2023/10/19;过去 12 个月发布了 8 个版本。

版本发布日期距今
2.0.5latest2026/05/136 个月前
2.0.42025/12/2410 个月前
2.0.32025/12/2410 个月前
2.0.22025/12/2410 个月前
2.0.12025/12/2410 个月前
2.0.02025/12/2410 个月前

关于 @dexhunterio/swaps 的常见问题

@dexhunterio/swaps 是什么?

How to use library (with React)

如何安装 @dexhunterio/swaps?

在项目目录运行 npm install @dexhunterio/swaps,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@radix-ui/react-accordion(^1.1.2 || ^1.2.3)、@radix-ui/react-checkbox(^1.0.4 || ^1.1.4)、@radix-ui/react-dialog(^1.0.4 || ^1.1.6)、@radix-ui/react-dropdown-menu(^2.0.5 || ^2.1.6)、@radix-ui/react-label(^2.0.2 || ^2.1.2)、@radix-ui/react-popover(^1.0.6 || ^1.1.6)、@radix-ui/react-progress(1.0.3)、@radix-ui/react-separator(^1.0.3 || ^1.1.2)、@radix-ui/react-slider(^1.1.2 || ^1.2.3)、@radix-ui/react-slot(^1.0.2 || ^1.1.2)、@radix-ui/react-switch(^1.0.3 || ^1.1.3)、@radix-ui/react-toast(^1.1.4 || ^1.2.6)、@radix-ui/react-tooltip(^1.0.6 || ^1.1.8)、@tabler/icons-react(^2.30.0 || ^3.31.0)、@tanstack/react-query(^5.59.16 || ^5.67.2)、axios(^1.7.7 || ^1.8.2)、bech32(^2.0.0)、cbor-x(^1.6.0)、class-variance-authority(^0.7.0 || ^0.7.1)、clsx(^2.0.0 || ^2.1.1)、immer(^10.0.2 || ^10.1.1)、lucide-react(^0.263.1 || ^0.479.0)、moment(^2.29.4 || ^2.30.1)、react(^18.2.0 || ^19.0.0)、react-currency-input-field(^3.6.11 || ^3.10.0)、react-dom(^18.2.0 || ^19.0.0)、react-hotkeys-hook(^4.4.1 || ^4.6.1)、react-spinners(^0.13.8 || ^0.15.0)、react-virtuoso(^4.4.2 || ^4.12.3)、tailwind-merge(^1.14.0)、tailwindcss-animate(^1.0.6 || ^1.0.7)、use-debounce(^9.0.4 || ^10.0.4)、zustand(^4.4.0 || ^5.0.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dexhunterio/swaps 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dexhunterio/swaps 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dexhunterio/swaps 可以商用吗?

@dexhunterio/swaps 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@dexhunterio/swaps 的下载量有多少?

根据 npm 官方下载统计,@dexhunterio/swaps 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,504 次,日均约 83 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dexhunterio/swaps 还在维护吗?

最新版本 2.0.5 发布于 2026/05/13(6 个月前);至今共发布 179 个版本,其中过去 12 个月发布了 8 个;首次发布于 2023/10/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。