@bluvo/react

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

React hooks for Bluvo SDK - Framework-agnostic state machine for crypto withdrawals

原始使用文档
文档目录11 节
  1. Installation
  2. Quick Start
  3. Available Hooks
  4. useBluvoFlow(options)
  5. useFlowMachine(machine)
  6. useWithdrawMachine(machine)
  7. Security
  8. State Flow
  9. Framework Integration
  10. Examples
  11. License

@bluvo/react

React hooks for the Bluvo SDK - providing a framework-agnostic, event-driven state machine for cryptocurrency withdrawal flows.

Installation

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

Quick Start

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>
  );
}

Available Hooks

useBluvoFlow(options)

The main hook that manages the entire withdrawal flow state machine.

Options:

  • orgId - Your Bluvo organization ID
  • projectId - Your Bluvo project ID
  • fetchWithdrawableBalanceFn - Function to fetch wallet balances
  • requestQuotationFn - Function to request withdrawal quotes
  • executeWithdrawalFn - Function to execute withdrawals
  • maxRetryAttempts? - Maximum retry attempts (default: 3)
  • topicToken? - WebSocket topic token for real-time updates
  • cacheName? - Cache name for WebSocket subscriptions
  • cache? - QR code caching options (zero config with localStorage, see core SDK docs)
  • mkUUIDFn? - Custom UUID generator function

Returns:

{
  // 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 Code Caching

QR code sessions are cached in localStorage by default — no setup needed. Users see their QR code instantly on page refresh.

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

Pass cache: { disabled: true } to disable. See core SDK docs for the full BluvoCacheOptions API.

useFlowMachine(machine)

Lower-level hook for direct state machine interaction.

useWithdrawMachine(machine)

Hook for managing the withdrawal sub-state machine.

Security

This library follows security best practices:

  • No API keys in browser: Uses callback functions that call your secure server endpoints
  • Server-side operations: All sensitive operations happen on your server
  • Type safety: Full TypeScript support with proper error handling

State Flow

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

Framework Integration

Works seamlessly with:

  • Next.js - Use with Server Actions
  • Remix - Use with action functions
  • SvelteKit - Use with form actions
  • Any React app - Use with your API layer

Examples

See the examples directory for complete implementations with different frameworks.

License

MIT © 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 是什么?

React hooks for Bluvo SDK - Framework-agnostic state machine for crypto withdrawals

如何安装 @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 和提交记录判断。