Require Connection

A component that conditionally renders content based on blockchain connection status.

Introduction

RequireConnection is a component that conditionally renders content based on blockchain connection status, ensuring that protected UI components only display when connected to the required chain.

Installation

npx polkadot-ui@latest add require-connection

Usage

Require Connection
Render children only when a connection is established
Make sure your app is connected to Paseo to continue. This is the content that will be displayed when you are not connected to Paseo.
Require Connection - Basic Example
Render content when connected to the target chain
Please connect to Paseo to continue
Require Connection - With Loading State
Show a loading fallback while connecting
Connecting to Paseo...
Require Connection - Protecting Transaction UI
Gate transaction interfaces behind connection status
Please connect to Paseo to submit transactions

Props

PropTypeRequiredDescription
chainIdChainIdThe chain ID that must be connected
childrenReactNodeContent to render when connected
fallbackReactNodeContent to render when not connected
loadingFallbackReactNodeOptional content to show while connecting

Connection States

The component handles three distinct states:

  1. Loading: Connection is being established (shows loadingFallback if provided)
  2. Connected: Chain is connected (shows children)
  3. Disconnected: Chain is not connected (shows fallback)

Supported Chain IDs

The component works with any chain ID configured in your polkadot-ui config:

  • "paseo" - Paseo Relay Chain
  • "paseoPeople" - Paseo People Chain
  • Any custom chains you've added to your configuration

Use Cases

Multi-Chain Support

function MultiChainComponent() {
  return (
    <div className="space-y-6">
      <RequireConnection
        chainId={paseo.id}
        fallback={<ConnectMessage chain="paseo" />}
      >
        <RelayChainFeatures />
      </RequireConnection>

      <RequireConnection
        chainId={paseo.id}
        fallback={<ConnectMessage chain="paseoPeople" />}
      >
        <PeopleChainFeatures />
      </RequireConnection>
    </div>
  );
}

Dashboard Sections

<RequireConnection
  chainId={paseo.id}
  loadingFallback={<DashboardSkeleton />}
  fallback={<ConnectPrompt />}
>
  <ChainDashboard />
</RequireConnection>

Nested Protection

<RequireConnection chainId={paseo.id} fallback={<ConnectRelay />}>
  <RequireConnection chainId="paseoPeople" fallback={<ConnectPeople />}>
    <CrossChainFeature />
  </RequireConnection>
</RequireConnection>