Component Overview
Here we learn how to connect the user's wallet with the web application and sign messages.
The SIWAConnect
component is a React component designed to manage the authentication flow using Sign-In With Algo. It leverages several hooks and state variables for its functionality. Below is a brief overview of its core components:
Hooks:
useWalletConnection()
: Provides necessary functions and state variables for wallet connectivity, such as connecting/disconnecting wallets, loading states, and signing messages.useSIWAAccount()
: Acceptsaddress
and returns account-related information, specifically theaddress
.
State Variables:
signedMessage: Stores the message signed by the user.
pendingProvider: Tracks the wallet provider waiting for user interaction.
fullSigningMessage: Holds the comprehensive signing message object.
credentials: Stores user credentials after successful authentication.
error: Captures error information if any issues occur during the authentication flow.
verificationResult: Maintains the result of the SIWA message verification process.
siwaMessageInstance: Stores an instance of the
SiwaMessage
.activeStep: Keeps track of the current step in the authentication process.
Key Functions
The component implements several key functions:
handleConnectWallet
: Connects to the selected wallet providerhandleDisconnect
: Disconnects the current walletsignIn
: Creates and signs a SIWA messageverifySIWAMessage
: Verifies the signed SIWA message
Here's an example of the signIn
function:
UI Rendering
The UI is rendered based on the current activeStep
. Here's the complete renderStep
function:
This function renders different UI elements based on the current step of the SIWA process:
Display connect buttons for all supported wallets (Pera, Defly, Kibisis, and Lute)
Show the "Sign In" button
Show the "Verify SIWA Message" button
Display a success message
The component also includes additional UI elements for displaying the connected wallet information, error messages, and JSON representations of the signing message, credentials, and verification result.
In the next section, we'll look at how to customize the UI of the SIWA Connect component to fit your application's design.
In the next section, we'll look at how to customize the UI of the SIWA Connect component.
Last updated