Workshop 8: Web UI Exploration
Goal
Understand how the Pilot UI connects to the ICN gateway and trace user actions through the stack.
Prerequisites
- Completed Module 8 reading
- Node.js installed (for running the UI locally)
Estimated time
1-2 hours
Part 1: UI Project Structure
Steps
Navigate to the web UI directory:
cd web/pilot-uiList the project structure:
ls -laIdentify the main files:
index.html- Entry point and layoutapp.js- Core application logiccomponents/- Feature modules
Questions to answer
- Is this a single-page application (SPA)?
- What framework/library is used for the UI?
- Where is the routing handled?
Checkpoint
- You identified the main entry point
- You understand the project structure
Part 2: Login Flow Analysis
Steps
- Open
web/pilot-ui/app.js - Find the
loginfunction - Trace the login sequence:
- Input validation
- Health check
- Auth verification
- Session persistence
Expected flow
User Input → Validate Fields → GET /health → GET /ledger/.../balance → Store in localStorage
Code to examine
Look for localStorage operations:
localStorage.setItem('icn-gateway', state.gatewayUrl);
localStorage.setItem('icn-token', state.token);
Questions to answer
- What happens if fields are missing?
- What endpoint is called to verify auth works?
- How long is the token assumed valid?
Checkpoint
- You traced the complete login flow
- You found the session persistence code
Part 3: API Request Pattern
Steps
- Find the
apiRequestfunction inapp.js - Examine how the JWT is attached to requests
- Identify error handling patterns
Expected pattern
async function apiRequest(method, path, body) {
const response = await fetch(state.gatewayUrl + path, {
method,
headers: {
'Authorization': `Bearer ${state.token}`,
'Content-Type': 'application/json'
},
body: body ? JSON.stringify(body) : undefined
});
// Error handling...
}
Checkpoint
- You understand how the JWT is used
- You found the error handling logic
Part 4: Map UI Actions to API Endpoints
Exercise
Fill in this table by examining the UI code:
| UI Action | HTTP Method | API Endpoint |
|---|---|---|
| View balance | GET | /ledger/{coopId}/balance/{did} |
| Send transfer | ? | ? |
| List members | ? | ? |
| View proposals | ? | ? |
| Vote on proposal | ? | ? |
Steps
- Search for fetch calls in
app.jsandcomponents/ - Map each UI feature to its API call
- Note the HTTP method and path pattern
Checkpoint
- You mapped at least 3 UI actions to endpoints
- You understand the REST API pattern
Part 5: WebSocket Events
Steps
Search for WebSocket usage:
grep -r "WebSocket" web/pilot-ui/ --include="*.js"Find where the WebSocket connection is established
Identify what events are handled
Questions to answer
- What URL pattern is used for WebSocket connections?
- What events does the UI listen for?
- How does the UI handle reconnection?
Checkpoint
- You found the WebSocket connection code
- You understand what real-time events are handled
Part 6: Run the UI Locally (Optional)
Prerequisites
- A running ICN gateway (or mock server)
- Valid JWT token
Steps
Install dependencies:
cd web/pilot-ui npm installStart the development server:
npm run devOpen the browser and navigate to the local URL
Try connecting with:
- Gateway URL:
http://localhost:8080(or your gateway) - Coop ID: Your test cooperative
- DID: Your test identity
- JWT: A valid token
- Gateway URL:
Troubleshooting
If you don't have a running gateway, examine the UI behavior with invalid credentials to understand the error handling.
Checkpoint
- You ran the UI locally (or understand why you couldn't)
- You traced a real or simulated request flow
Summary
After completing this workshop you should be able to:
- Navigate the Pilot UI codebase
- Trace the login and session flow
- Map UI actions to gateway API calls
- Understand WebSocket event handling
Next steps
Proceed to Module 9: Operations and Deployment