P-2202: Examples: Add Angular example for the Formo Web SDK#78
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds detailed documentation and code examples for integrating the Formo SDK with Angular, including installation steps, polyfill setup, and usage examples for identifying users and tracking events. The review feedback suggests standardizing package manager commands to npm for consistency, adding null checks for window.ethereum to prevent potential runtime crashes, and correcting a version number typo from Angular 21 to 19.
| pnpm add @formo/analytics buffer viem | ||
| pnpm add -D @ngx-env/builder |
| async connect(): Promise<void> { | ||
| const [account] = await window.ethereum!.request({ method: 'eth_requestAccounts' }); | ||
| this.address.set(account); | ||
| this.formo.identify(account); | ||
| } |
There was a problem hiding this comment.
Using a non-null assertion (!) on window.ethereum can lead to runtime errors if the user does not have a wallet extension installed. It is safer to check for its existence before attempting to use it.
async connect(): Promise<void> {
if (!window.ethereum) return;
const [account] = await window.ethereum.request({ method: 'eth_requestAccounts' });
this.address.set(account);
this.formo.identify(account);
}
| async connect(): Promise<void> { | ||
| const [account] = await window.ethereum!.request({ method: 'eth_requestAccounts' }); | ||
| this.address.set(account); | ||
| this.formo.identify(account); | ||
| } |
There was a problem hiding this comment.
Using a non-null assertion (!) on window.ethereum can lead to runtime errors if the user does not have a wallet extension installed. It is safer to check for its existence before attempting to use it.
async connect(): Promise<void> {
if (!window.ethereum) return;
const [account] = await window.ethereum.request({ method: 'eth_requestAccounts' });
this.address.set(account);
this.formo.identify(account);
}
| icon="file-code" | ||
| href="https://github.com/getformo/examples/tree/main/with-angular" | ||
| > | ||
| Angular 21 + bare EIP-1193 + viem. Uses the framework-agnostic SDK core. |
|
Cursor size is huge 🆙 |
export-1779247736242.mp4
Summary
Adds an Angular install path to the Web SDK install instructions on both
/installand/sdks/web, plus three new "Code examples" cards (with-crossmint,with-openfort,with-angular). Angular gets its own section becauseFormoAnalyticsProvider/useFormo()and wagmi are React-only — Angular apps install Formo via the framework-agnosticFormoAnalytics.init()core, which carries a couple of esbuild-specific gotchas (Bufferpolyfill,allowedCommonJsDependencies) worth surfacing inline rather than only in the example app.Key Changes
sdks/web.mdx:### Angularsection under## Installation— install command,src/polyfills.ts+angular.json(Buffer polyfill +allowedCommonJsDependenciesfor the SDK's React re-exports),FormoAnalyticsServicewrappingFormoAnalytics.init(),provideAppInitializerwiring, and a one-line note that Angular RouterpushStatepage events are autocaptured (don't subscribe toNavigationEnd)<Tab title="Angular">in the## Identify usersTabs block — minimalWalletService.connect()showing identify-on-connect## Code examples: Crossmint (Next.js + Crossmint embedded smart wallets, manual instrumentation — no EIP-1193), Openfort (Vite + React + Shield encryption sessions + Aave demo), Angular (Angular 21 + bare EIP-1193 + viem)install.mdx:<Tab icon="angular" title="Angular">in the main install Tabs block — same numbered structure as the Wagmi/React/Next.js tabs (install → polyfill → service → app initializer → identify → track)Heads up:
https://github.com/getformo/examples/tree/main/with-angular, which is still on PR branchkeilok/angular-example-with-formo-web-sdk(getformo/examples#27) — those links 404 until that PR merges.Need help on this PR? Tag
@codesmithwith what you need.