0.1.0 • Published 8 months ago

@keepkey/connection-indicator v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@keepkey/connection-indicator

A React component for displaying the connection status of KeepKey Desktop.

Features

  • Real-time status monitoring of KeepKey Desktop
  • Customizable appearance
  • Automatic polling
  • Launch KeepKey Desktop functionality

Installation

npm install @keepkey/connection-indicator
# or
yarn add @keepkey/connection-indicator
# or
pnpm add @keepkey/connection-indicator

Usage

Basic Usage

import { ConnectionIndicator } from '@keepkey/connection-indicator';

function App() {
  return (
    <div>
      <h1>My KeepKey App</h1>
      <ConnectionIndicator />
    </div>
  );
}

With Custom Options

import { ConnectionIndicator } from '@keepkey/connection-indicator';

function App() {
  return (
    <div>
      <h1>My KeepKey App</h1>
      <ConnectionIndicator 
        connectionOptions={{
          pollingInterval: 5000, // Check every 5 seconds
          timeout: 1000, // 1 second timeout
        }}
        showTooltip={true}
        onClick={(e, isConnected) => {
          if (!isConnected) {
            console.log('Launching KeepKey Desktop...');
          }
        }}
      />
    </div>
  );
}

Using the Hook Directly

import { useDesktopConnection } from '@keepkey/connection-indicator';

function CustomIndicator() {
  const { isConnected, checkConnection, launchDesktop } = useDesktopConnection();
  
  return (
    <button 
      style={{ 
        backgroundColor: isConnected ? 'green' : 'red',
        color: 'white',
        padding: '8px 16px',
        borderRadius: '4px'
      }}
      onClick={() => !isConnected && launchDesktop()}
    >
      {isConnected ? 'Connected to KeepKey' : 'Launch KeepKey Desktop'}
    </button>
  );
}

API

ConnectionIndicator Props

PropTypeDefaultDescription
classNamestring''Custom class name for the indicator
styleCSSPropertiesundefinedCustom style for the indicator
connectionOptionsUseDesktopConnectionOptions{}Options for the useDesktopConnection hook
showTooltipbooleantrueWhether to show a tooltip with connection status
connectedIndicatorReactNodeundefinedCustom connected indicator component
disconnectedIndicatorReactNodeundefinedCustom disconnected indicator component
tooltipComponentReactNodeundefinedCustom tooltip component
onClickfunctionundefinedCallback for when the indicator is clicked

UseDesktopConnectionOptions

OptionTypeDefaultDescription
pollingIntervalnumber15000Polling interval in milliseconds
timeoutnumber2000Timeout for connection check in milliseconds
endpointstring'http://localhost:1646/docs'Endpoint to check for KeepKey Desktop

License

MIT

0.1.0

8 months ago