Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/frol/near-connect-ios/llms.txt

Use this file to discover all available pages before exploring further.

Overview

WalletBridgeSheet is a ready-to-use SwiftUI view component that presents the wallet connection interface as a full-screen modal sheet. It handles the complete wallet interaction flow including connection, transaction approval, and message signing.
This component automatically manages the wallet WebView lifecycle and displays a loading indicator while the bridge is initializing.

Declaration

public struct WalletBridgeSheet: View

Usage

Present WalletBridgeSheet using .fullScreenCover bound to NEARWalletManager.showWalletUI:
struct ContentView: View {
    @EnvironmentObject var walletManager: NEARWalletManager
    
    var body: some View {
        NavigationView {
            // Your main content
            VStack {
                Button("Connect Wallet") {
                    walletManager.connect()
                }
            }
        }
        .fullScreenCover(isPresented: $walletManager.showWalletUI) {
            WalletBridgeSheet()
                .environmentObject(walletManager)
        }
    }
}

Features

Automatic Flow Management

The sheet automatically handles different wallet interaction flows:
  • Wallet Connection: When user initiates connection via walletManager.connect()
  • Transaction Signing: When transactions need approval
  • Message Signing: When messages need to be signed
  • Connect & Sign: Combined connection and message signing flow

Loading State

While the wallet bridge is initializing, the sheet displays a loading indicator with the message “Loading wallet connector…”:
if !walletManager.isBridgeReady {
    VStack(spacing: 16) {
        ProgressView()
        Text("Loading wallet connector...")
            .font(.subheadline)
            .foregroundColor(.secondary)
    }
}

Close Button

A close button (X icon) is positioned in the top-right corner, allowing users to cancel the wallet interaction at any time. This sets walletManager.showWalletUI to false and triggers cleanup.
The sheet automatically calls walletManager.cleanUpOnDismiss() when dismissed, ensuring proper cleanup of resources.

Environment Requirements

WalletBridgeSheet requires NEARWalletManager to be available in the SwiftUI environment:
@EnvironmentObject var walletManager: NEARWalletManager
Make sure to inject the wallet manager at the app level:
@main
struct MyApp: App {
    @StateObject private var walletManager = NEARWalletManager(
        network: .testnet,
        contractId: "your-contract.testnet"
    )
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(walletManager)
        }
    }
}

Example

Here’s a complete example from the NEAR Connect demo app:
import SwiftUI
import NEARConnect

struct ContentView: View {
    @EnvironmentObject var walletManager: NEARWalletManager
    
    var body: some View {
        NavigationView {
            VStack(spacing: 20) {
                if walletManager.isSignedIn, let account = walletManager.currentAccount {
                    // Connected state
                    VStack(spacing: 16) {
                        Text("Connected")
                            .font(.headline)
                        Text(account.accountId)
                            .font(.title3)
                        
                        Button("Disconnect") {
                            walletManager.disconnect()
                        }
                        .padding()
                        .background(Color.red)
                        .foregroundColor(.white)
                        .cornerRadius(12)
                    }
                } else {
                    // Disconnected state
                    VStack(spacing: 20) {
                        Text("Connect your NEAR wallet to get started")
                            .font(.title3)
                            .multilineTextAlignment(.center)
                        
                        Button("Connect Wallet") {
                            walletManager.connect()
                        }
                        .padding()
                        .background(Color.blue)
                        .foregroundColor(.white)
                        .cornerRadius(12)
                    }
                }
            }
            .padding()
        }
        .fullScreenCover(isPresented: $walletManager.showWalletUI) {
            WalletBridgeSheet()
                .environmentObject(walletManager)
        }
    }
}

Implementation Details

Initialization

public init() {}
The initializer is parameterless since all configuration comes from the injected NEARWalletManager.

Lifecycle Hooks

  • onAppear: Triggers pending wallet flows when the bridge is ready
  • onDisappear: Calls walletManager.cleanUpOnDismiss() to clean up resources
  • onChange(isBridgeReady): Monitors bridge initialization state

Pending Flow Handling

The sheet checks for pending operations when the bridge becomes ready:
  1. Sign Message Flow: If pendingSignMessageParams exists, triggers triggerConnectWithSignMessage()
  2. Standard Connection: If pendingConnect is true, triggers triggerWalletSelector()
A 0.3-second delay is added before triggering flows to ensure the WebView is fully rendered and ready to receive JavaScript calls.

Build docs developers (and LLMs) love