@ 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项目IDfetchWithdrawableBalanceFn- 获取钱包余额的函数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.