# @zerohash-sdk/fiat-withdrawals-react

A React SDK that enables frontend React applications to seamlessly integrate with the Connect Fiat Withdrawals product.

Connect Fiat Withdrawals provides a secure, customizable flow for withdrawing fiat currency directly within your application.

## Requirements

- React 18.0.0 or higher
- React DOM 18.0.0 or higher

## Installation

```bash
npm install @zerohash-sdk/fiat-withdrawals-react
```

## Getting Started

### 1. Import the FiatWithdrawals Component

```tsx
import { FiatWithdrawals } from '@zerohash-sdk/fiat-withdrawals-react';
```

### 2. Add the FiatWithdrawals Component to Your App

```tsx
function App() {
  const jwt = 'your-jwt-token'; // Obtain this from your backend

  return (
    <FiatWithdrawals
      jwt={jwt}
      env="prod" // or "cert" for testing
      theme="auto" // 'auto' (default), 'light', or 'dark'
    />
  );
}
```

### 3. Configure Event Callbacks (Optional)

```tsx
function App() {
  const jwt = 'your-jwt-token';

  return (
    <FiatWithdrawals
      jwt={jwt}
      env="prod"
      theme="auto"
      onCompleted={({ amountWithdrawn, assetSymbol }) => {
        console.log('Withdrawal completed:', amountWithdrawn, assetSymbol);
      }}
      onError={({ errorCode, reason }) => {
        console.log('Error:', errorCode, 'Reason:', reason);
      }}
      onClose={() => console.log('Widget closed')}
      onEvent={({ type, data }) => console.log('Event:', type, data)}
      onLoaded={() => console.log('Widget loaded and ready')}
    />
  );
}
```

## Complete Example

```tsx
import { FiatWithdrawals } from '@zerohash-sdk/fiat-withdrawals-react';
import React from 'react';

function App() {
  const jwt = 'your-jwt-token';

  return (
    <div className="App">
      <h1>My App</h1>

      <FiatWithdrawals
        jwt={jwt}
        env="prod"
        theme="auto"
        onCompleted={({ amountWithdrawn, assetSymbol }) => {
          console.log('Withdrawn:', amountWithdrawn, assetSymbol);
        }}
        onError={({ errorCode, reason }) => console.log('Error:', errorCode, reason)}
        onClose={() => console.log('Widget closed')}
        onEvent={({ type, data }) => console.log('Event type:', type, 'Event data:', data)}
        onLoaded={() => console.log('Widget loaded and ready')}
      />
    </div>
  );
}

export default App;
```

## API Reference

### FiatWithdrawals Component Props

| Prop          | Type                                         | Required | Default  | Description                                              |
| ------------- | -------------------------------------------- | -------- | -------- | -------------------------------------------------------- |
| `jwt`         | `string`                                     | Yes      | -        | JWT token for authentication with Connect                |
| `env`         | `"prod" \| "cert" \| "dev" \| "local"`       | No       | `"prod"` | Target environment                                       |
| `theme`       | `"auto" \| "light" \| "dark"`                | No       | `"auto"` | Theme mode for the interface                             |
| `onCompleted` | `({ amountWithdrawn, assetSymbol }) => void` | No       | -        | Callback when the withdrawal flow completes successfully |
| `onError`     | `({ errorCode, reason }) => void`            | No       | -        | Callback for error events                                |
| `onClose`     | `() => void`                                 | No       | -        | Callback when the widget is closed                       |
| `onEvent`     | `({ type, data }) => void`                   | No       | -        | Callback for general events                              |
| `onLoaded`    | `() => void`                                 | No       | -        | Callback when the widget is loaded and ready             |

## More Information & Support

For comprehensive documentation or support about Connect, visit our [Documentation Page](https://docs.zerohash.com/).
