# @zerohash-sdk/fiat-account-link-react

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

Connect Fiat Account Link provides a secure, customizable flow for linking external bank accounts 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-account-link-react
```

## Getting Started

### 1. Import the FiatAccountLink Component

```tsx
import { FiatAccountLink } from '@zerohash-sdk/fiat-account-link-react';
```

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

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

  return (
    <FiatAccountLink
      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 (
    <FiatAccountLink
      jwt={jwt}
      env="prod"
      theme="auto"
      onCompleted={({ externalAccountId, institutionName }) => {
        console.log('Account linked:', externalAccountId, institutionName);
      }}
      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 React from 'react';
import { FiatAccountLink } from '@zerohash-sdk/fiat-account-link-react';

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

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

      <FiatAccountLink
        jwt={jwt}
        env="prod"
        theme="auto"
        onCompleted={({ externalAccountId, institutionName }) => {
          console.log('Linked:', externalAccountId, institutionName);
        }}
        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

### FiatAccountLink 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` | `({ externalAccountId, institutionName }) => void` | No       | -        | Callback when account linking 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/).
