@bluvo/react

中文文档
5.0.0发布于 2026/05/05MITTypeScriptESM + CJS零依赖近 30 天下载 13.3万

Bluvo SDK 反应钩子 - 加密退出的框架不可知状态机

中文使用文档
文档目录11 节
  1. 安装
  2. 快速启动
  3. 可用钩
  4. useBluvoFlow(options)
  5. useFlowMachine(machine)
  6. useWithdrawMachine(machine)
  7. 警卫
  8. 状态流量
  9. 框架整合
  10. 实例
  11. 许可证

@ bluvo/ 反应

Bluvo SDK的回放钩子 - 为密码货币取出流量提供一种框架-可知,事件驱动的状态机器.

安装

npm install @bluvo/react @bluvo/sdk-ts
# or
pnpm add @bluvo/react @bluvo/sdk-ts
# or
yarn add @bluvo/react @bluvo/sdk-ts

快速启动

import React from 'react';
import { useBluvoFlow } from '@bluvo/react';

function WithdrawalComponent() {
    const flow = useBluvoFlow({
        orgId: "bluvo-org-id",
        projectId: "bluvo-project-id", // <- deprecated soon to be removed

        fetchWithdrawableBalanceFn: fetchWithdrawableBalances,
        requestQuotationFn: requestQuotation,
        executeWithdrawalFn: executeWithdrawal,

        onWalletConnectedFn: (walletId, exchange) => {
            // call server action store this walletId for the currently-logged in user
        }
    });

  const handleStart = () => {
    flow.startWithdrawalFlow({
      exchange: 'coinbase',
      walletId: 'wallet-123',
      asset: 'BTC',
      amount: '0.001',
      destinationAddress: 'bc1q...'
    });
  };

  if (flow.requires2FA) {
    return (
      <div>
        <input 
          placeholder="Enter 2FA code"
          onKeyPress={(e) => {
            if (e.key === 'Enter') {
              flow.submit2FA(e.target.value);
            }
          }}
        />
      </div>
    );
  }

  return (
    <div>
      <button onClick={handleStart}>Start Withdrawal</button>
      <p>State: {flow.state?.type}</p>
    </div>
  );
}

可用钩

useBluvoFlow(options)

管理整个取出流状态机的主钩.

选项 :

  • orgId - 你的布卢沃组织的身份
  • projectId - 你的Bluvo项目ID
  • fetchWithdrawableBalanceFn - 获取钱包余额的函数
  • requestQuotationFn - 请求撤回引用的函数
  • executeWithdrawalFn - 执行退出的职能
  • maxRetryAttempts? - 最大重试尝试( 默认: 3)
  • topicToken? - 实时更新的WebSocket主题符号
  • cacheName? - WebSocket 订阅的缓存名
  • cache? - QR 码缓存选项( 0 配置到本地Storage, 见 核心 SDK 文件(中文(简体) )
  • mkUUIDFn? - 自定义 UUID 生成器函数

回返情况:

{
  // State
  state: FlowState | null,
  error: Error | null,
  context: FlowContext,
  
  // Actions  
  startWithdrawalFlow: (options) => Promise<void>,
  executeWithdrawal: (quoteId) => Promise<void>,
  submit2FA: (code) => Promise<void>,
  submitSMS: (code) => Promise<void>,
  retryWithdrawal: () => Promise<void>,
  cancel: () => void,
  
  // State Helpers
  isOAuthPending: boolean,
  isWalletReady: boolean,
  isQuoteReady: boolean,
  requires2FA: boolean,
  requiresSMS: boolean,
  requiresKYC: boolean,
  isWithdrawalComplete: boolean,
  canRetry: boolean,
  
  // Data
  walletBalances: Array<{asset: string, balance: string}>,
  quote: Quote | null,
  withdrawal: Withdrawal | null
}

QR 代码缓存

QR 代码会话被缓存于 localStorage 默认情况下——不需要设置。 用户在刷新页面时立即看到他们的QR代码.

const flow = useBluvoFlow({
  // ...other options
  cache: { prefix: "myapp:" }, // Optional: customize caching
});

过 cache: { disabled: true } 以禁用。 见 核心 SDK 文件 全文 BluvoCacheOptions API (英语).

useFlowMachine(machine)

下级钩子用于直接的状态机器交互.

useWithdrawMachine(machine)

用于管理退出子状态机器的虎克.

警卫

该图书馆遵循安保最佳做法:

  • 浏览器中没有 API 密钥: 使用调用函数调用您的安全服务器端点
  • 服务器侧操作: 所有敏感操作都发生在您的服务器上
  • 类型安全: 完整类型脚本支持,并有适当的错误处理

状态流量

idle → oauth:waiting → wallet:loading → quote:ready → withdraw:processing → completed
  ↓         ↓               ↓             ↓              ↓
cancel   cancel        error states    2FA/SMS/KYC    success/retry

框架整合

与 :

  • 下一个.js - 用于服务器动作
  • 重混合 - 用于动作功能
  • 斯维尔特基特 - 与形式动作一起使用
  • 任何反应应用程序 - 用您的 API 层

实例

见 示例目录 (c) 采用不同框架的全面执行.

许可证

麻省理工学院Bluvo Inc.

版本与发布记录

@bluvo/react 共发布 57 个版本,首次发布于 2025/08/28;过去 12 个月发布了 11 个版本。

版本发布日期距今
5.0.0latest2026/05/056 个月前
4.0.02026/04/037 个月前
3.0.02026/03/257 个月前
3.0.0-beta.2beta2026/03/247 个月前
3.0.0-beta.12026/03/217 个月前
2.2.0-beta.02026/03/018 个月前

关于 @bluvo/react 的常见问题

@bluvo/react 是什么?

Bluvo SDK 反应钩子 - 加密退出的框架不可知状态机

如何安装 @bluvo/react?

在项目目录运行 npm install @bluvo/react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bluvo/sdk-ts(5.0.0)、react(^16.8.0 || ^17.0.0 || ^18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bluvo/react 支持 TypeScript 吗?

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

@bluvo/react 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bluvo/react 可以商用吗?

@bluvo/react 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bluvo/react 的下载量有多少?

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

@bluvo/react 还在维护吗?

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