Skip to content

React Component

The <WaspadaScanner /> component is a self-contained, drop-in fraud evidence scanner with built-in UI, state management, and visual telemetry.

Installation

bash
pnpm add @waspada/react @waspada/sdk @waspada/types

Basic Usage

tsx
import { WaspadaScanner } from '@waspada/react';
import '@waspada/react/dist/style.css';

export default function SecurityCenter() {
  return (
    <WaspadaScanner
      config={{ source_platform: 'PARTNER_123', signPayload: myKeySigner }}
      onThreatDetected={(alert) => sendToFMS(alert)}
    />
  );
}

5 Lines of Code

That's all it takes to add enterprise-grade fraud detection to your app. The component handles model loading, file processing, PII stripping, and result display.

Props

PropTypeRequiredDescription
configWaspadaSdkConfigYesSDK configuration (platform ID, signer)
onThreatDetected(result, metrics) => voidFires when threat indicators are extracted
onClean(result, metrics) => voidFires when no threats are found
onError(error) => voidFires on SDK or processing errors
classNamestringAdditional CSS class for the root element

State Machine

The component follows a deterministic state machine:

IDLE → LOADING_MODELS → READY → SCANNING → THREAT_DETECTED
                          ↑                       │
                          └───── (Scan Another) ───┘

                     SCANNING → CLEAN
                          ↑       │
                          └───────┘
StateUIDescription
IDLEInitial mount, before SDK init
LOADING_MODELSProgress barDownloading OCR + NER models
READYDrop zoneReady to accept evidence files
SCANNINGProgress animationProcessing file through pipeline
THREAT_DETECTEDMetrics + IndicatorsThreat indicators found
CLEANMetricsNo actionable indicators
ERRORError messageSDK or processing failure

Visual Telemetry

When a scan completes, the component renders four real-time metrics:

MetricColor CodingData Source
Latency🟢 <100ms · 🟡 <500ms · 🔴 >500msperformance.now() delta
Engine Tier🔵 Regex · 🟣 NER · 🔷 Hybridresult.extraction_tier
ConfidencePercentageresult.confidence
PII Status🟢 Clean · 🔴 DetectedWarning scan

useWaspada() Hook

For custom UIs, use the hook directly:

tsx
import { useWaspada } from '@waspada/react';

function CustomScanner() {
  const {
    state,
    initStatus,
    lastResult,
    lastMetrics,
    processFile,
    reset,
    error,
  } = useWaspada(
    { source_platform: 'MY_APP', signPayload: signer },
    {
      onThreatDetected: (result, metrics) => {
        console.log(`Threat found in ${metrics.latencyMs}ms`);
      },
    }
  );

  return (
    <div>
      <p>State: {state}</p>
      {state === 'READY' && (
        <input
          type="file"
          onChange={(e) => e.target.files?.[0] && processFile(e.target.files[0])}
        />
      )}
      {lastResult && (
        <pre>{JSON.stringify(lastResult.indicators, null, 2)}</pre>
      )}
    </div>
  );
}

Hook Return Values

PropertyTypeDescription
stateScannerStateCurrent state machine state
initStatusInitStatus | nullSDK init details (storage backend, cached models)
lastResultExtractionResult | nullMost recent extraction result
lastMetricsScanMetrics | nullPerformance metrics for last scan
versionstringSDK version
warningsstring[]Warnings from last operation
errorstring | nullError message (if in ERROR state)
processFile(file: File) => Promise<void>Trigger evidence processing
reset() => voidReset to READY state

Styling

The component ships with encapsulated CSS Module styles that won't conflict with your app. Import the stylesheet:

tsx
import '@waspada/react/dist/style.css';

To customize, override CSS variables on the component's root:

css
.my-scanner {
  --w-blue: #2563eb;      /* Brand blue */
  --w-purple: #7c3aed;    /* Brand purple */
  --w-bg-deep: #0f172a;   /* Background */
  --w-radius: 16px;       /* Border radius */
}
tsx
<WaspadaScanner className="my-scanner" config={config} />

Waspada AI: Enterprise infrastructure powering public defense.