Initial Commit
This commit is contained in:
86
openspec/changes/enterprise-react-crypto/proposal.md
Normal file
86
openspec/changes/enterprise-react-crypto/proposal.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# OpenSpec Change: enterprise-react-crypto
|
||||
|
||||
- **Change ID**: enterprise-react-crypto
|
||||
- **Package**: `@suaveplan/react-crypto`
|
||||
- **Category**: react
|
||||
- **Target path**: `react/auth/react-crypto`
|
||||
- **Status**: PROPOSED
|
||||
- **Date**: 2026-04-24
|
||||
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/react-crypto.md`
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Deliver `@suaveplan/react-crypto` on genesis from scratch at enterprise quality. Wallet UI for EVM chains: `WalletConnect`, `AddressDisplay`, `BalanceDisplay`, `TransactionList`, and `useWallet` hook — fully implemented (no stub `0x000...` address, no README-vs-reality gaps). Integrates with `@suaveplan/crypto` for signing and `@suaveplan/crypto-browser` for WebCrypto operations. `useWallet` fully implements MetaMask/WalletConnect via injected provider interface, `autoConnect`, `switchNetwork`, `sendTransaction`, `signMessage`.
|
||||
|
||||
---
|
||||
|
||||
## Current-state audit (genesis)
|
||||
|
||||
Package does not exist on genesis — fresh build.
|
||||
|
||||
---
|
||||
|
||||
## Available workspace deps on genesis
|
||||
|
||||
| Package | Role |
|
||||
|---|---|
|
||||
| `@suaveplan/error` (`workspace:^`) | `WalletError` |
|
||||
| `@suaveplan/crypto` (`workspace:^`) | Signing utilities |
|
||||
| `@suaveplan/crypto-browser` (`workspace:^`) | WebCrypto adapters |
|
||||
| `@suaveplan/react-translate` (`workspace:^`) | i18n |
|
||||
| `zod` (`catalog:forms`) | Network/transaction schemas |
|
||||
| `@opentelemetry/api` (`catalog:observability`) | `wallet.connect` / `wallet.sign` spans |
|
||||
|
||||
External: `tslib catalog:build`. React 18 peer.
|
||||
|
||||
---
|
||||
|
||||
## Public API surface
|
||||
|
||||
```ts
|
||||
WalletConnect, AddressDisplay, BalanceDisplay, TransactionList
|
||||
useWallet
|
||||
|
||||
explorerUrl, formatAddress, formatBalance, isValidEvmAddress, networkDisplayName
|
||||
|
||||
// Types
|
||||
Network, TokenBalance, Transaction, TransactionDirection, TransactionStatus,
|
||||
WalletInfo, WalletStatus
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## New additions for genesis
|
||||
|
||||
1. **Full `useWallet` implementation** — injected `WalletProvider` interface (MetaMask/WalletConnect adapters); `connect()`, `disconnect()`, `autoConnect`, `switchNetwork(chainId)`, `sendTransaction(tx)`, `signMessage(msg)`. No stubs.
|
||||
2. **`WalletError`** — codes: `WALLET_CONNECT_FAILED`, `WALLET_NOT_CONNECTED`, `WALLET_SIGN_FAILED`, `WALLET_NETWORK_ERROR`.
|
||||
3. **OTel spans** — `wallet.connect`, `wallet.sign`, `wallet.send_transaction`.
|
||||
4. **Stories** — connected, disconnected, loading, wrong-network, playground.
|
||||
5. **Playwright E2E** — injected mock provider; connect → address shown; signMessage → tx hash shown.
|
||||
|
||||
---
|
||||
|
||||
## File layout
|
||||
|
||||
```text
|
||||
react/auth/react-crypto/
|
||||
package.json
|
||||
tsconfig.json
|
||||
vitest.config.ts
|
||||
src/
|
||||
index.ts
|
||||
hooks/
|
||||
use-wallet/ (ts + types + md + test + stories + index)
|
||||
components/
|
||||
wallet-connect/ address-display/ balance-display/ transaction-list/
|
||||
providers/
|
||||
wallet-provider/ (ts + types + md + test + index)
|
||||
utils/
|
||||
evm-utils/ (ts + md + test + index)
|
||||
types/
|
||||
crypto.types.ts
|
||||
e2e/
|
||||
wallet.spec.ts
|
||||
```
|
||||
99
openspec/changes/enterprise-react-crypto/tasks.md
Normal file
99
openspec/changes/enterprise-react-crypto/tasks.md
Normal file
@@ -0,0 +1,99 @@
|
||||
# Tasks: enterprise-react-crypto
|
||||
|
||||
**Change ID**: enterprise-react-crypto
|
||||
**Package**: `@suaveplan/react-crypto`
|
||||
**Target path**: `react/auth/react-crypto`
|
||||
**Prerequisite packages on Verdaccio**: `@suaveplan/error`, `@suaveplan/crypto`, `@suaveplan/crypto-browser`, `@suaveplan/react-translate`
|
||||
|
||||
---
|
||||
|
||||
## 0. Pre-flight (non-negotiable)
|
||||
|
||||
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
|
||||
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
|
||||
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
|
||||
|
||||
## 1. Scaffold
|
||||
|
||||
- [ ] Create directory tree per proposal layout.
|
||||
- [ ] Write `package.json` at `0.1.0` with `"sideEffects": false`, exports map.
|
||||
- [ ] Dependencies: `@suaveplan/error workspace:^`, `@suaveplan/crypto workspace:^`, `@suaveplan/crypto-browser workspace:^`, `@suaveplan/react-translate workspace:^`, `zod catalog:forms`, `@opentelemetry/api catalog:observability`, `tslib catalog:build`.
|
||||
- [ ] Write `tsconfig.json`, `vitest.config.ts`, scripts.
|
||||
|
||||
---
|
||||
|
||||
## 2. Error codes and types
|
||||
|
||||
- [ ] Define `WalletError` extending `SuaveplanError`; codes: `WALLET_CONNECT_FAILED`, `WALLET_NOT_CONNECTED`, `WALLET_SIGN_FAILED`, `WALLET_NETWORK_ERROR`.
|
||||
- [ ] Define `WalletProvider` interface (injectable): `connect()`, `disconnect()`, `getAddress()`, `getBalance()`, `getNetwork()`, `switchNetwork(chainId)`, `sendTransaction(tx)`, `signMessage(msg)`.
|
||||
- [ ] Define `Network`, `TokenBalance`, `Transaction`, `TransactionDirection`, `TransactionStatus`, `WalletInfo`, `WalletStatus`.
|
||||
- [ ] Write Zod schemas for `Network`, `Transaction`.
|
||||
|
||||
---
|
||||
|
||||
## 3. WalletProvider adapters
|
||||
|
||||
- [ ] `MetaMaskAdapter` — wraps `window.ethereum` EIP-1193 provider.
|
||||
- [ ] `WalletConnectAdapter` — wraps injected `WalletConnectProvider`.
|
||||
- [ ] Both implement `WalletProvider` interface.
|
||||
- [ ] Write tests using DI (inject mock `window.ethereum`) + md.
|
||||
|
||||
---
|
||||
|
||||
## 4. EVM utils
|
||||
|
||||
- [ ] `explorerUrl(network, txHash)`, `formatAddress(addr, length?)`, `formatBalance(wei, decimals?)`, `isValidEvmAddress(addr): boolean`, `networkDisplayName(chainId): string`.
|
||||
- [ ] Write `evm-utils.test.ts` (all functions, edge cases) + md.
|
||||
|
||||
---
|
||||
|
||||
## 5. Hook — `useWallet`
|
||||
|
||||
- [ ] Accepts `provider: WalletProvider` + `autoConnect?: boolean`.
|
||||
- [ ] State: `address`, `balance`, `network`, `status: WalletStatus`, `transactions`.
|
||||
- [ ] `connect()` — calls `provider.connect()`; throws `WalletError(WALLET_CONNECT_FAILED)` on failure. OTel `wallet.connect` span.
|
||||
- [ ] `disconnect()` — calls `provider.disconnect()`.
|
||||
- [ ] `switchNetwork(chainId)` — calls `provider.switchNetwork()`; throws `WalletError(WALLET_NETWORK_ERROR)` on failure.
|
||||
- [ ] `sendTransaction(tx)` — throws `WalletError(WALLET_NOT_CONNECTED)` if not connected. OTel `wallet.send_transaction` span.
|
||||
- [ ] `signMessage(msg)` — throws `WalletError(WALLET_SIGN_FAILED)` on error. OTel `wallet.sign` span.
|
||||
- [ ] Write `use-wallet.test.ts` (≤500 lines): connect, disconnect, autoConnect, switchNetwork, sendTransaction, signMessage, all error cases. DI injected mock `WalletProvider`. `{ timeout: 10000 }`.
|
||||
- [ ] Write `use-wallet.stories.tsx`: connected, disconnected, loading, wrong-network, playground.
|
||||
- [ ] Write `use-wallet.md`.
|
||||
|
||||
---
|
||||
|
||||
## 6. Components
|
||||
|
||||
### WalletConnect
|
||||
|
||||
- [ ] Connect/disconnect button; shows address when connected.
|
||||
- [ ] Write test, stories, md.
|
||||
|
||||
### AddressDisplay
|
||||
|
||||
- [ ] Shortened address with copy-to-clipboard. Write test, stories, md.
|
||||
|
||||
### BalanceDisplay
|
||||
|
||||
- [ ] Token balance with symbol. Write test, stories, md.
|
||||
|
||||
### TransactionList
|
||||
|
||||
- [ ] Paginated list of `Transaction` items with status badges, explorer links. Write test, stories, md.
|
||||
|
||||
---
|
||||
|
||||
## 7. E2E
|
||||
|
||||
- [ ] `e2e/wallet.spec.ts` — Playwright with injected mock provider:
|
||||
- Click "Connect" → address displayed.
|
||||
- Call `signMessage('hello')` → mock returns signature, displayed.
|
||||
|
||||
---
|
||||
|
||||
## 8. Verify and publish
|
||||
|
||||
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/react-crypto` — green.
|
||||
- [ ] `bunx turbo test:coverage --filter=@suaveplan/react-crypto` — 100%.
|
||||
- [ ] `bun scripts/publish.ts --package @suaveplan/react-crypto`.
|
||||
- [ ] Archive change folder.
|
||||
Reference in New Issue
Block a user