auramaxx 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/README.md +77 -0
- package/apps/desktop-electron/main.js +428 -0
- package/bin/auramaxx.js +1063 -0
- package/docs/ADAPTERS.md +466 -0
- package/docs/AGENT_SETUP.md +159 -0
- package/docs/API.md +127 -0
- package/docs/APPS.md +199 -0
- package/docs/ARCHITECTURE.md +235 -0
- package/docs/AUTH.md +318 -0
- package/docs/BEST-PRACTICES.md +82 -0
- package/docs/CLI.md +141 -0
- package/docs/DESKTOP_ELECTRON.md +26 -0
- package/docs/DEVELOPING-APPS.md +453 -0
- package/docs/MCP.md +122 -0
- package/docs/PACKAGING_POLICY.md +19 -0
- package/docs/PERMISSION.md +137 -0
- package/docs/PROTOCOL.md +142 -0
- package/docs/README.md +50 -0
- package/docs/SKILLS.md +132 -0
- package/docs/TROUBLESHOOTING.md +376 -0
- package/docs/WORKSPACE.md +673 -0
- package/docs/agent-auth.md +14 -0
- package/docs/api/authentication.md +79 -0
- package/docs/api/secrets/api-keys.md +28 -0
- package/docs/api/secrets/credentials.md +80 -0
- package/docs/api/secrets/sharing.md +48 -0
- package/docs/api/system.md +41 -0
- package/docs/api/wallets/apps-strategies.md +66 -0
- package/docs/api/wallets/core.md +46 -0
- package/docs/api/wallets/data-portfolio.md +42 -0
- package/docs/aura-file.md +48 -0
- package/docs/core-concepts/FEATURES.md +114 -0
- package/docs/credentials.md +120 -0
- package/docs/external/HOW_TO_AURAMAXX/GETTING_SECRETS.md +33 -0
- package/docs/external/HOW_TO_AURAMAXX/README.md +45 -0
- package/docs/external/getting-started.md +10 -0
- package/docs/external/overview.md +19 -0
- package/docs/external/persona-paths.md +7 -0
- package/docs/external/share-secret.md +76 -0
- package/docs/external/why-aura.md +7 -0
- package/docs/security.md +227 -0
- package/docs/templates/RELEASE_NOTES_TEMPLATE.md +22 -0
- package/docs/wallet/AI.md +508 -0
- package/docs/wallet/DEVELOPING-STRATEGIES.md +713 -0
- package/docs/wallet/README.md +47 -0
- package/docs/wallet/STRATEGY.md +89 -0
- package/next.config.ts +28 -0
- package/package.json +167 -0
- package/postcss.config.mjs +8 -0
- package/prisma/migrations/20260214170000_baseline/migration.sql +511 -0
- package/prisma/migrations/20260216214537_add_passkey_model/migration.sql +18 -0
- package/prisma/migrations/20260217150500_add_credential_access_audit/migration.sql +31 -0
- package/prisma/migrations/20260222090000_update_admin_ttl_default/migration.sql +10 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +447 -0
- package/public/logo.webp +0 -0
- package/scripts/add-app.js +245 -0
- package/server/abi/SwapHelper.json +438 -0
- package/server/cli/approval.ts +447 -0
- package/server/cli/commands/actions.ts +474 -0
- package/server/cli/commands/api.ts +220 -0
- package/server/cli/commands/apikey.ts +277 -0
- package/server/cli/commands/app.ts +204 -0
- package/server/cli/commands/auth.ts +464 -0
- package/server/cli/commands/cron.ts +24 -0
- package/server/cli/commands/diary.ts +274 -0
- package/server/cli/commands/doctor.ts +1247 -0
- package/server/cli/commands/env.ts +476 -0
- package/server/cli/commands/experimental.ts +69 -0
- package/server/cli/commands/init.ts +798 -0
- package/server/cli/commands/lock.ts +157 -0
- package/server/cli/commands/mcp.ts +285 -0
- package/server/cli/commands/quickhack.ts +86 -0
- package/server/cli/commands/release-check.ts +231 -0
- package/server/cli/commands/restore.ts +314 -0
- package/server/cli/commands/service.ts +320 -0
- package/server/cli/commands/shell-hook.ts +512 -0
- package/server/cli/commands/skill.ts +216 -0
- package/server/cli/commands/start.ts +139 -0
- package/server/cli/commands/status.ts +59 -0
- package/server/cli/commands/stop.ts +36 -0
- package/server/cli/commands/token.ts +180 -0
- package/server/cli/commands/unlock.ts +50 -0
- package/server/cli/commands/vault.ts +1323 -0
- package/server/cli/commands/wallet.ts +209 -0
- package/server/cli/index.ts +280 -0
- package/server/cli/lib/approval-poll.ts +94 -0
- package/server/cli/lib/aura-parser.ts +64 -0
- package/server/cli/lib/credential-create.ts +74 -0
- package/server/cli/lib/credential-resolve.ts +280 -0
- package/server/cli/lib/dotenv-migrate.ts +116 -0
- package/server/cli/lib/dotenv-parser.ts +146 -0
- package/server/cli/lib/escalation.ts +57 -0
- package/server/cli/lib/http.ts +91 -0
- package/server/cli/lib/init-steps.ts +76 -0
- package/server/cli/lib/local-agent-trust.ts +45 -0
- package/server/cli/lib/lock-unlock-helper.ts +71 -0
- package/server/cli/lib/process.ts +162 -0
- package/server/cli/lib/prompt.ts +294 -0
- package/server/cli/lib/theme.ts +240 -0
- package/server/cli/socket.ts +579 -0
- package/server/cli/transport-client.ts +50 -0
- package/server/cron/index.ts +137 -0
- package/server/cron/job.ts +31 -0
- package/server/cron/jobs/balance-sync.ts +436 -0
- package/server/cron/jobs/incoming-scan.ts +506 -0
- package/server/cron/jobs/native-price.ts +70 -0
- package/server/cron/jobs/orphan-cleanup.ts +40 -0
- package/server/cron/jobs/strategy-runner.ts +175 -0
- package/server/cron/scheduler.ts +125 -0
- package/server/index.ts +420 -0
- package/server/lib/adapters/factory.ts +119 -0
- package/server/lib/adapters/index.ts +19 -0
- package/server/lib/adapters/router.ts +297 -0
- package/server/lib/adapters/telegram.ts +645 -0
- package/server/lib/adapters/types.ts +89 -0
- package/server/lib/adapters/webhook.ts +95 -0
- package/server/lib/address.ts +49 -0
- package/server/lib/agent-auth/contracts.ts +1194 -0
- package/server/lib/agent-profiles.ts +419 -0
- package/server/lib/ai.ts +285 -0
- package/server/lib/api-registry/contracts.ts +86 -0
- package/server/lib/api-registry/validation.ts +172 -0
- package/server/lib/apikey-migration.ts +258 -0
- package/server/lib/app-installer.ts +505 -0
- package/server/lib/app-tokens.ts +247 -0
- package/server/lib/approval-link.ts +27 -0
- package/server/lib/auth.ts +314 -0
- package/server/lib/auto-execute.ts +160 -0
- package/server/lib/batch.ts +242 -0
- package/server/lib/cold.ts +1048 -0
- package/server/lib/config.ts +408 -0
- package/server/lib/credential-access-audit.ts +85 -0
- package/server/lib/credential-access-policy.ts +111 -0
- package/server/lib/credential-health.ts +343 -0
- package/server/lib/credential-import.ts +608 -0
- package/server/lib/credential-scope.ts +102 -0
- package/server/lib/credential-shares.ts +190 -0
- package/server/lib/credential-transport.ts +533 -0
- package/server/lib/credential-vault.ts +77 -0
- package/server/lib/credentials.ts +422 -0
- package/server/lib/crypto.ts +8 -0
- package/server/lib/db.ts +58 -0
- package/server/lib/defaults.ts +386 -0
- package/server/lib/dex/index.ts +80 -0
- package/server/lib/dex/relay.ts +235 -0
- package/server/lib/dex/types.ts +59 -0
- package/server/lib/dex/uniswap.ts +370 -0
- package/server/lib/diary.ts +34 -0
- package/server/lib/dont-ask-again-policy.ts +41 -0
- package/server/lib/e2e-agent/artifacts.ts +36 -0
- package/server/lib/e2e-agent/contracts.ts +112 -0
- package/server/lib/e2e-agent/validation.ts +135 -0
- package/server/lib/encrypt.ts +114 -0
- package/server/lib/error.ts +20 -0
- package/server/lib/events.ts +217 -0
- package/server/lib/feature-flags.ts +93 -0
- package/server/lib/hot.ts +357 -0
- package/server/lib/human-action-summary.ts +80 -0
- package/server/lib/key-fingerprint.ts +28 -0
- package/server/lib/logger.ts +340 -0
- package/server/lib/network.ts +137 -0
- package/server/lib/notifications.ts +230 -0
- package/server/lib/oauth2-refresh.ts +241 -0
- package/server/lib/oursecret.ts +71 -0
- package/server/lib/passkey-credential.ts +360 -0
- package/server/lib/passkey.ts +68 -0
- package/server/lib/permissions.ts +299 -0
- package/server/lib/pino.ts +24 -0
- package/server/lib/policy-preview.ts +138 -0
- package/server/lib/price.ts +338 -0
- package/server/lib/prices.ts +34 -0
- package/server/lib/project-scope.ts +297 -0
- package/server/lib/resolve-action.ts +328 -0
- package/server/lib/resolve.ts +36 -0
- package/server/lib/secret-gist-share.ts +296 -0
- package/server/lib/sessions.ts +634 -0
- package/server/lib/socket-path.ts +56 -0
- package/server/lib/solana/connection.ts +26 -0
- package/server/lib/solana/jupiter.ts +128 -0
- package/server/lib/solana/transfer.ts +108 -0
- package/server/lib/solana/wallet.ts +136 -0
- package/server/lib/strategy/emits.ts +21 -0
- package/server/lib/strategy/engine.ts +1305 -0
- package/server/lib/strategy/executor.ts +115 -0
- package/server/lib/strategy/hook-context.ts +159 -0
- package/server/lib/strategy/hooks.ts +990 -0
- package/server/lib/strategy/index.ts +28 -0
- package/server/lib/strategy/installer.ts +305 -0
- package/server/lib/strategy/loader.ts +256 -0
- package/server/lib/strategy/message.ts +237 -0
- package/server/lib/strategy/repository.ts +218 -0
- package/server/lib/strategy/session-logger.ts +693 -0
- package/server/lib/strategy/sources.ts +288 -0
- package/server/lib/strategy/state.ts +189 -0
- package/server/lib/strategy/templates.ts +403 -0
- package/server/lib/strategy/tick.ts +404 -0
- package/server/lib/strategy/types.ts +230 -0
- package/server/lib/swap.ts +3 -0
- package/server/lib/temp.ts +86 -0
- package/server/lib/token-metadata.ts +86 -0
- package/server/lib/token-safety.ts +200 -0
- package/server/lib/token-search.ts +444 -0
- package/server/lib/totp.ts +194 -0
- package/server/lib/transactions.ts +123 -0
- package/server/lib/transport.ts +84 -0
- package/server/lib/txhistory/decoder.ts +262 -0
- package/server/lib/txhistory/enricher.ts +652 -0
- package/server/lib/txhistory/index.ts +391 -0
- package/server/lib/txhistory/signatures.ts +59 -0
- package/server/lib/update-check.ts +35 -0
- package/server/lib/verified-summary.ts +414 -0
- package/server/lib/view-registry.ts +80 -0
- package/server/mcp/profile-policy.ts +30 -0
- package/server/mcp/server.ts +1589 -0
- package/server/mcp/tools.ts +276 -0
- package/server/middleware/auth.ts +119 -0
- package/server/middleware/requestLogger.ts +84 -0
- package/server/routes/actions.ts +539 -0
- package/server/routes/adapters.ts +711 -0
- package/server/routes/addressbook.ts +113 -0
- package/server/routes/ai.ts +34 -0
- package/server/routes/apikeys.ts +343 -0
- package/server/routes/apps.ts +601 -0
- package/server/routes/auth.ts +406 -0
- package/server/routes/backup.ts +404 -0
- package/server/routes/batch.ts +270 -0
- package/server/routes/bookmarks.ts +162 -0
- package/server/routes/credential-shares.ts +380 -0
- package/server/routes/credential-vaults.ts +159 -0
- package/server/routes/credentials.ts +1782 -0
- package/server/routes/dashboard.ts +97 -0
- package/server/routes/defaults.ts +124 -0
- package/server/routes/flags.ts +11 -0
- package/server/routes/fund.ts +225 -0
- package/server/routes/heartbeat.ts +375 -0
- package/server/routes/import.ts +364 -0
- package/server/routes/launch.ts +665 -0
- package/server/routes/lock.ts +54 -0
- package/server/routes/logs.ts +68 -0
- package/server/routes/nuke.ts +111 -0
- package/server/routes/passkey-credentials.ts +99 -0
- package/server/routes/passkey.ts +366 -0
- package/server/routes/portfolio.ts +217 -0
- package/server/routes/price.ts +63 -0
- package/server/routes/resolve.ts +31 -0
- package/server/routes/security.ts +45 -0
- package/server/routes/send-evm.ts +241 -0
- package/server/routes/send-solana.ts +281 -0
- package/server/routes/send.ts +178 -0
- package/server/routes/setup.ts +210 -0
- package/server/routes/strategy.ts +894 -0
- package/server/routes/swap-evm.ts +352 -0
- package/server/routes/swap-solana.ts +176 -0
- package/server/routes/swap.ts +356 -0
- package/server/routes/token.ts +247 -0
- package/server/routes/unlock.ts +467 -0
- package/server/routes/views.ts +41 -0
- package/server/routes/wallet-assets.ts +361 -0
- package/server/routes/wallet-transactions.ts +515 -0
- package/server/routes/wallet.ts +709 -0
- package/server/types.ts +146 -0
- package/shared/credential-field-schema.ts +248 -0
- package/skills/auramaxx/HEARTBEAT.md +78 -0
- package/skills/auramaxx/SKILL.md +745 -0
- package/skills/auramaxx/docs/AGENT_SETUP.md +155 -0
- package/skills/auramaxx/docs/API.md +127 -0
- package/skills/auramaxx/docs/AUTH.md +318 -0
- package/skills/auramaxx/docs/CLI.md +130 -0
- package/skills/auramaxx/docs/MCP.md +122 -0
- package/skills/auramaxx/docs/TROUBLESHOOTING.md +357 -0
- package/skills/auramaxx/docs/WORKSPACE.md +673 -0
- package/skills/auramaxx/docs/security.md +227 -0
- package/skills/task-lifecycle/SKILL.md +378 -0
- package/src/app/api/[...doc]/page.tsx +36 -0
- package/src/app/api/agent-requests/route.ts +30 -0
- package/src/app/api/apps/install/route.ts +132 -0
- package/src/app/api/apps/manifests/route.ts +16 -0
- package/src/app/api/apps/static/[...path]/route.ts +57 -0
- package/src/app/api/docs/plain/route.ts +74 -0
- package/src/app/api/events/route.ts +92 -0
- package/src/app/api/page.tsx +290 -0
- package/src/app/api/workspace/[id]/apps/[wid]/route.ts +119 -0
- package/src/app/api/workspace/[id]/apps/route.ts +81 -0
- package/src/app/api/workspace/[id]/export/route.ts +67 -0
- package/src/app/api/workspace/[id]/route.ts +168 -0
- package/src/app/api/workspace/auth.ts +40 -0
- package/src/app/api/workspace/config/route.ts +121 -0
- package/src/app/api/workspace/import/route.ts +127 -0
- package/src/app/api/workspace/route.ts +116 -0
- package/src/app/app-legacy-do-not-use/page.tsx +2245 -0
- package/src/app/apple-icon.png +0 -0
- package/src/app/approve/[actionId]/page.tsx +409 -0
- package/src/app/docs/DocsPageContent.tsx +269 -0
- package/src/app/docs/[...doc]/page.tsx +41 -0
- package/src/app/docs/page.tsx +38 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +819 -0
- package/src/app/health/page.tsx +5 -0
- package/src/app/hello/page.tsx +102 -0
- package/src/app/icon.png +0 -0
- package/src/app/layout.tsx +39 -0
- package/src/app/page.tsx +1964 -0
- package/src/app/privacy/page.tsx +63 -0
- package/src/app/providers.tsx +87 -0
- package/src/app/share/[token]/page.tsx +295 -0
- package/src/app/terms/page.tsx +80 -0
- package/src/components/ChainSelector.tsx +44 -0
- package/src/components/HumanActionBar.tsx +697 -0
- package/src/components/NotificationDrawer.tsx +387 -0
- package/src/components/PasskeyEnrollmentPrompt.tsx +235 -0
- package/src/components/apps/AgentKeysApp.tsx +490 -0
- package/src/components/apps/App.tsx +153 -0
- package/src/components/apps/AppGrid.tsx +15 -0
- package/src/components/apps/DetailedAddressDrawer.tsx +325 -0
- package/src/components/apps/DraggableApp.tsx +562 -0
- package/src/components/apps/IFrameApp.tsx +73 -0
- package/src/components/apps/LogsApp.tsx +360 -0
- package/src/components/apps/SendApp.tsx +394 -0
- package/src/components/apps/SetupWizardApp.tsx +1004 -0
- package/src/components/apps/SystemDefaultsApp.tsx +845 -0
- package/src/components/apps/ThirdPartyApp.tsx +428 -0
- package/src/components/apps/TokenApp.tsx +319 -0
- package/src/components/apps/TransactionsApp.tsx +438 -0
- package/src/components/apps/WalletDetailApp.tsx +1505 -0
- package/src/components/apps/index.ts +13 -0
- package/src/components/design-system/Button.tsx +88 -0
- package/src/components/design-system/ChainIndicator.tsx +65 -0
- package/src/components/design-system/ChainSelector.tsx +147 -0
- package/src/components/design-system/ConfirmationModal.tsx +107 -0
- package/src/components/design-system/ConfirmationPopover.tsx +81 -0
- package/src/components/design-system/DownloadButton.tsx +149 -0
- package/src/components/design-system/Drawer.tsx +133 -0
- package/src/components/design-system/FilterDropdown.tsx +183 -0
- package/src/components/design-system/ItemPicker.tsx +157 -0
- package/src/components/design-system/Modal.tsx +296 -0
- package/src/components/design-system/Popover.tsx +142 -0
- package/src/components/design-system/TextInput.tsx +85 -0
- package/src/components/design-system/Toggle.tsx +65 -0
- package/src/components/design-system/TyvekCollapsibleSection.tsx +55 -0
- package/src/components/design-system/index.ts +14 -0
- package/src/components/docs/ClientSideMarkdown.tsx +51 -0
- package/src/components/docs/DocsSearchBar.tsx +118 -0
- package/src/components/docs/DocsThemeToggle.tsx +38 -0
- package/src/components/docs/PersistentDocGroup.tsx +91 -0
- package/src/components/docs/ShareUrlButton.tsx +33 -0
- package/src/components/docs/SidebarScrollMemory.tsx +56 -0
- package/src/components/health/CredentialHealthDashboard.tsx +214 -0
- package/src/components/icons/ChainIcons.tsx +72 -0
- package/src/components/layout/AppStoreDrawer.tsx +369 -0
- package/src/components/layout/ContentArea.tsx +21 -0
- package/src/components/layout/CreateViewModal.tsx +88 -0
- package/src/components/layout/LeftRail.tsx +114 -0
- package/src/components/layout/TabBar.tsx +284 -0
- package/src/components/layout/WalletSidebar.tsx +1030 -0
- package/src/components/layout/index.ts +6 -0
- package/src/components/marketing/AuraMaxxSpecOverlay.tsx +653 -0
- package/src/components/marketing/DeviceMorphExperience.tsx +216 -0
- package/src/components/vault/ApiKeysConsole.tsx +1272 -0
- package/src/components/vault/AuditConsole.tsx +600 -0
- package/src/components/vault/CredentialDetail.tsx +625 -0
- package/src/components/vault/CredentialEmpty.tsx +55 -0
- package/src/components/vault/CredentialField.tsx +583 -0
- package/src/components/vault/CredentialForm.tsx +1484 -0
- package/src/components/vault/CredentialList.tsx +265 -0
- package/src/components/vault/CredentialRow.tsx +130 -0
- package/src/components/vault/CredentialShareModal.tsx +273 -0
- package/src/components/vault/CredentialVault.tsx +1662 -0
- package/src/components/vault/CredentialWalletWidget.tsx +103 -0
- package/src/components/vault/DocsConsole.tsx +113 -0
- package/src/components/vault/ImportCredentialsModal.tsx +578 -0
- package/src/components/vault/LargeTypeModal.tsx +88 -0
- package/src/components/vault/PasswordGenerator.tsx +232 -0
- package/src/components/vault/TOTPDisplay.tsx +108 -0
- package/src/components/vault/TotpSetupPanel.tsx +198 -0
- package/src/components/vault/VaultSidebar.tsx +881 -0
- package/src/components/vault/credentialFormName.ts +91 -0
- package/src/components/vault/hooks/useVaultKeyboardShortcuts.ts +69 -0
- package/src/components/vault/types.ts +56 -0
- package/src/context/AuthContext.tsx +365 -0
- package/src/context/PriceContext.tsx +113 -0
- package/src/context/ThemeContext.tsx +164 -0
- package/src/context/WebSocketContext.tsx +269 -0
- package/src/context/WorkspaceContext.tsx +668 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useAgentActions.ts +552 -0
- package/src/hooks/useBalance.ts +103 -0
- package/src/hooks/useBalances.ts +129 -0
- package/src/hooks/useTheme.ts +156 -0
- package/src/instrumentation.ts +12 -0
- package/src/lib/api-docs.ts +154 -0
- package/src/lib/api.ts +474 -0
- package/src/lib/app-loader.ts +148 -0
- package/src/lib/app-registry.ts +178 -0
- package/src/lib/app-sdk.ts +157 -0
- package/src/lib/audit-console-adapter.ts +151 -0
- package/src/lib/auth-client.ts +75 -0
- package/src/lib/config.ts +74 -0
- package/src/lib/credential-field-schema.ts +11 -0
- package/src/lib/crypto.ts +112 -0
- package/src/lib/db.ts +21 -0
- package/src/lib/docs.ts +544 -0
- package/src/lib/events.ts +363 -0
- package/src/lib/pino.ts +24 -0
- package/src/lib/theme-handlers.ts +168 -0
- package/src/lib/theme.ts +351 -0
- package/src/lib/tokenData.ts +378 -0
- package/src/lib/totp-import.ts +57 -0
- package/src/lib/vault-crypto.ts +129 -0
- package/src/lib/view-registry.ts +57 -0
- package/src/lib/websocket-server.ts +302 -0
- package/src/lib/websocket-setup.ts +79 -0
- package/src/lib/wordlist.ts +2050 -0
- package/src/lib/workspace-handlers.ts +285 -0
- package/start.sh +170 -0
- package/tailwind.config.ts +99 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
import { useAuth } from '@/context/AuthContext';
|
|
4
|
+
|
|
5
|
+
interface BalanceMap {
|
|
6
|
+
[address: string]: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface UseBalancesResult {
|
|
10
|
+
balances: BalanceMap;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: string | null;
|
|
13
|
+
refetch: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Hook to fetch ETH balances for multiple addresses using batch RPC calls
|
|
18
|
+
* Uses eth_getBalance with JSON-RPC batch request for efficiency
|
|
19
|
+
*/
|
|
20
|
+
export function useBalances(addresses: string[], chain?: string): UseBalancesResult {
|
|
21
|
+
const { getRpcUrl, getConfiguredChains } = useAuth();
|
|
22
|
+
const [balances, setBalances] = useState<BalanceMap>({});
|
|
23
|
+
const [loading, setLoading] = useState(false);
|
|
24
|
+
const [error, setError] = useState<string | null>(null);
|
|
25
|
+
|
|
26
|
+
// Track previous values to detect changes
|
|
27
|
+
const prevAddressesRef = useRef<string>('');
|
|
28
|
+
const prevRpcUrlRef = useRef<string>('');
|
|
29
|
+
|
|
30
|
+
const chains = getConfiguredChains();
|
|
31
|
+
const defaultChain = Object.keys(chains)[0] || 'base';
|
|
32
|
+
const targetChain = chain || defaultChain;
|
|
33
|
+
|
|
34
|
+
// Get current RPC URL for comparison
|
|
35
|
+
const rpcUrl = getRpcUrl(targetChain);
|
|
36
|
+
|
|
37
|
+
const fetchBalances = useCallback(async () => {
|
|
38
|
+
if (!addresses || addresses.length === 0) {
|
|
39
|
+
setBalances({});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const currentRpcUrl = getRpcUrl(targetChain);
|
|
44
|
+
|
|
45
|
+
setLoading(true);
|
|
46
|
+
setError(null);
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
// Build batch request for all addresses
|
|
50
|
+
const batchRequest = addresses.map((address, index) => ({
|
|
51
|
+
jsonrpc: '2.0',
|
|
52
|
+
id: index,
|
|
53
|
+
method: 'eth_getBalance',
|
|
54
|
+
params: [address, 'latest'],
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
const response = await fetch(currentRpcUrl, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: { 'Content-Type': 'application/json' },
|
|
60
|
+
body: JSON.stringify(batchRequest),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw new Error(`RPC request failed: ${response.status}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const results = await response.json();
|
|
68
|
+
|
|
69
|
+
// Handle both array response (batch) and single response
|
|
70
|
+
const resultsArray = Array.isArray(results) ? results : [results];
|
|
71
|
+
|
|
72
|
+
// Sort by id to match original order
|
|
73
|
+
resultsArray.sort((a, b) => a.id - b.id);
|
|
74
|
+
|
|
75
|
+
const newBalances: BalanceMap = {};
|
|
76
|
+
resultsArray.forEach((result, index) => {
|
|
77
|
+
const address = addresses[index];
|
|
78
|
+
if (result.result) {
|
|
79
|
+
const wei = BigInt(result.result);
|
|
80
|
+
newBalances[address.toLowerCase()] = ethers.formatEther(wei);
|
|
81
|
+
} else {
|
|
82
|
+
newBalances[address.toLowerCase()] = '0';
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
setBalances(newBalances);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.error('[useBalances] Failed to fetch balances:', err);
|
|
89
|
+
setError(err instanceof Error ? err.message : 'Failed to fetch balances');
|
|
90
|
+
|
|
91
|
+
// Set all balances to '0' on error
|
|
92
|
+
const fallbackBalances: BalanceMap = {};
|
|
93
|
+
addresses.forEach(addr => {
|
|
94
|
+
fallbackBalances[addr.toLowerCase()] = '0';
|
|
95
|
+
});
|
|
96
|
+
setBalances(fallbackBalances);
|
|
97
|
+
} finally {
|
|
98
|
+
setLoading(false);
|
|
99
|
+
}
|
|
100
|
+
}, [addresses, targetChain, getRpcUrl]);
|
|
101
|
+
|
|
102
|
+
// Refetch when addresses, chain, or RPC URL changes
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const addressKey = addresses.map(a => a.toLowerCase()).sort().join(',');
|
|
105
|
+
const shouldRefetch =
|
|
106
|
+
addressKey !== prevAddressesRef.current ||
|
|
107
|
+
rpcUrl !== prevRpcUrlRef.current;
|
|
108
|
+
|
|
109
|
+
if (shouldRefetch && addresses.length > 0) {
|
|
110
|
+
prevAddressesRef.current = addressKey;
|
|
111
|
+
prevRpcUrlRef.current = rpcUrl;
|
|
112
|
+
fetchBalances();
|
|
113
|
+
}
|
|
114
|
+
}, [addresses, rpcUrl, fetchBalances]);
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
balances,
|
|
118
|
+
loading,
|
|
119
|
+
error,
|
|
120
|
+
refetch: fetchBalances,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Helper to get balance for a specific address from the balances map
|
|
126
|
+
*/
|
|
127
|
+
export function getBalance(balances: BalanceMap, address: string): string {
|
|
128
|
+
return balances[address.toLowerCase()] || '0';
|
|
129
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createElement,
|
|
5
|
+
createContext,
|
|
6
|
+
useCallback,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect,
|
|
9
|
+
useMemo,
|
|
10
|
+
useState,
|
|
11
|
+
type ReactNode,
|
|
12
|
+
} from 'react';
|
|
13
|
+
|
|
14
|
+
export type ColorMode = 'light' | 'dark';
|
|
15
|
+
export type UiScale = 'normal' | 'big';
|
|
16
|
+
export type AuraTheme = 'default' | 'dark' | 'big';
|
|
17
|
+
|
|
18
|
+
const LEGACY_THEME_STORAGE_KEY = 'aura-theme';
|
|
19
|
+
const THEME_PREFS_STORAGE_KEY = 'vault-theme-preferences';
|
|
20
|
+
const DEFAULT_THEME_PREFS: { colorMode: ColorMode; uiScale: UiScale } = {
|
|
21
|
+
colorMode: 'light',
|
|
22
|
+
uiScale: 'normal',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
interface ThemeContextValue {
|
|
26
|
+
colorMode: ColorMode;
|
|
27
|
+
uiScale: UiScale;
|
|
28
|
+
setColorMode: (mode: ColorMode) => void;
|
|
29
|
+
setUiScale: (scale: UiScale) => void;
|
|
30
|
+
// Back-compat shim for existing callers/tests
|
|
31
|
+
theme: AuraTheme;
|
|
32
|
+
setTheme: (theme: AuraTheme) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ThemeContext = createContext<ThemeContextValue | null>(null);
|
|
36
|
+
|
|
37
|
+
function normalizeTheme(theme: AuraTheme): { colorMode: ColorMode; uiScale: UiScale } {
|
|
38
|
+
if (theme === 'dark') return { colorMode: 'dark', uiScale: 'normal' };
|
|
39
|
+
if (theme === 'big') return { colorMode: 'light', uiScale: 'big' };
|
|
40
|
+
return { colorMode: 'light', uiScale: 'normal' };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function toLegacyTheme(colorMode: ColorMode, uiScale: UiScale): AuraTheme {
|
|
44
|
+
if (uiScale === 'big') return 'big';
|
|
45
|
+
return colorMode === 'dark' ? 'dark' : 'default';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readStoredPrefs(): { colorMode: ColorMode; uiScale: UiScale } {
|
|
49
|
+
if (typeof window === 'undefined') return DEFAULT_THEME_PREFS;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const rawPrefs = window.localStorage.getItem(THEME_PREFS_STORAGE_KEY);
|
|
53
|
+
if (rawPrefs) {
|
|
54
|
+
const parsed = JSON.parse(rawPrefs) as { colorMode?: string; uiScale?: string };
|
|
55
|
+
const colorMode: ColorMode = parsed.colorMode === 'dark' ? 'dark' : 'light';
|
|
56
|
+
const uiScale: UiScale = parsed.uiScale === 'big' ? 'big' : 'normal';
|
|
57
|
+
return { colorMode, uiScale };
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
// ignore malformed local state
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const legacyTheme = window.localStorage.getItem(LEGACY_THEME_STORAGE_KEY) as AuraTheme | null;
|
|
64
|
+
return normalizeTheme(legacyTheme === 'dark' || legacyTheme === 'big' ? legacyTheme : 'default');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function applyThemeAttributes(colorMode: ColorMode, uiScale: UiScale): void {
|
|
68
|
+
if (typeof document === 'undefined') return;
|
|
69
|
+
const root = document.documentElement;
|
|
70
|
+
|
|
71
|
+
if (colorMode === 'dark') root.setAttribute('data-theme', 'dark');
|
|
72
|
+
else root.removeAttribute('data-theme');
|
|
73
|
+
|
|
74
|
+
root.setAttribute('data-ui-scale', uiScale);
|
|
75
|
+
|
|
76
|
+
const scale = uiScale === 'big' ? 1.25 : 1;
|
|
77
|
+
root.style.setProperty('--ui-scale-factor', String(scale));
|
|
78
|
+
|
|
79
|
+
root.style.setProperty('--font-size-xs', `${Math.round(10 * scale)}px`);
|
|
80
|
+
root.style.setProperty('--font-size-sm', `${Math.round(12 * scale)}px`);
|
|
81
|
+
root.style.setProperty('--font-size-md', `${Math.round(14 * scale)}px`);
|
|
82
|
+
root.style.setProperty('--font-size-lg', `${Math.round(18 * scale)}px`);
|
|
83
|
+
|
|
84
|
+
root.style.setProperty('--space-1', `${Math.round(4 * scale)}px`);
|
|
85
|
+
root.style.setProperty('--space-2', `${Math.round(8 * scale)}px`);
|
|
86
|
+
root.style.setProperty('--space-3', `${Math.round(12 * scale)}px`);
|
|
87
|
+
root.style.setProperty('--space-4', `${Math.round(16 * scale)}px`);
|
|
88
|
+
root.style.setProperty('--space-6', `${Math.round(24 * scale)}px`);
|
|
89
|
+
|
|
90
|
+
root.style.setProperty('--radius-sm', `${Math.round(6 * scale)}px`);
|
|
91
|
+
root.style.setProperty('--radius-md', `${Math.round(10 * scale)}px`);
|
|
92
|
+
root.style.setProperty('--radius-lg', `${Math.round(14 * scale)}px`);
|
|
93
|
+
root.style.setProperty('--shadow-sm', uiScale === 'big' ? '0 2px 4px rgba(0,0,0,0.15)' : '0 1px 2px rgba(0,0,0,0.12)');
|
|
94
|
+
root.style.setProperty('--shadow-md', uiScale === 'big' ? '0 8px 20px rgba(0,0,0,0.24)' : '0 6px 16px rgba(0,0,0,0.18)');
|
|
95
|
+
|
|
96
|
+
root.style.setProperty('--control-height-sm', `${Math.round(32 * scale)}px`);
|
|
97
|
+
root.style.setProperty('--control-height-md', `${Math.round(36 * scale)}px`);
|
|
98
|
+
root.style.setProperty('--control-height-lg', `${Math.round(40 * scale)}px`);
|
|
99
|
+
|
|
100
|
+
// keep existing aliases used around the codebase
|
|
101
|
+
root.style.setProperty('--space-xs', `var(--space-1)`);
|
|
102
|
+
root.style.setProperty('--space-sm', `var(--space-2)`);
|
|
103
|
+
root.style.setProperty('--space-md', `var(--space-3)`);
|
|
104
|
+
root.style.setProperty('--space-lg', `var(--space-4)`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function ThemeProvider({ children }: { children: ReactNode }) {
|
|
108
|
+
const [colorMode, setColorModeState] = useState<ColorMode>(DEFAULT_THEME_PREFS.colorMode);
|
|
109
|
+
const [uiScale, setUiScaleState] = useState<UiScale>(DEFAULT_THEME_PREFS.uiScale);
|
|
110
|
+
const [hasHydratedPrefs, setHasHydratedPrefs] = useState(false);
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
const stored = readStoredPrefs();
|
|
114
|
+
setColorModeState(stored.colorMode);
|
|
115
|
+
setUiScaleState(stored.uiScale);
|
|
116
|
+
setHasHydratedPrefs(true);
|
|
117
|
+
applyThemeAttributes(stored.colorMode, stored.uiScale);
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (!hasHydratedPrefs) return;
|
|
122
|
+
applyThemeAttributes(colorMode, uiScale);
|
|
123
|
+
if (typeof window === 'undefined') return;
|
|
124
|
+
window.localStorage.setItem(THEME_PREFS_STORAGE_KEY, JSON.stringify({ colorMode, uiScale }));
|
|
125
|
+
const legacy = toLegacyTheme(colorMode, uiScale);
|
|
126
|
+
if (legacy === 'default') window.localStorage.removeItem(LEGACY_THEME_STORAGE_KEY);
|
|
127
|
+
else window.localStorage.setItem(LEGACY_THEME_STORAGE_KEY, legacy);
|
|
128
|
+
}, [hasHydratedPrefs, colorMode, uiScale]);
|
|
129
|
+
|
|
130
|
+
const setColorMode = useCallback((mode: ColorMode) => setColorModeState(mode), []);
|
|
131
|
+
const setUiScale = useCallback((scale: UiScale) => setUiScaleState(scale), []);
|
|
132
|
+
const setTheme = useCallback((theme: AuraTheme) => {
|
|
133
|
+
const parsed = normalizeTheme(theme);
|
|
134
|
+
setColorModeState(parsed.colorMode);
|
|
135
|
+
setUiScaleState(parsed.uiScale);
|
|
136
|
+
}, []);
|
|
137
|
+
|
|
138
|
+
const theme = useMemo(() => toLegacyTheme(colorMode, uiScale), [colorMode, uiScale]);
|
|
139
|
+
|
|
140
|
+
const value = useMemo<ThemeContextValue>(() => ({
|
|
141
|
+
colorMode,
|
|
142
|
+
uiScale,
|
|
143
|
+
setColorMode,
|
|
144
|
+
setUiScale,
|
|
145
|
+
theme,
|
|
146
|
+
setTheme,
|
|
147
|
+
}), [colorMode, uiScale, setColorMode, setUiScale, theme, setTheme]);
|
|
148
|
+
|
|
149
|
+
return createElement(ThemeContext.Provider, { value }, children);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function useTheme(): ThemeContextValue {
|
|
153
|
+
const context = useContext(ThemeContext);
|
|
154
|
+
if (!context) throw new Error('useTheme must be used within a ThemeProvider');
|
|
155
|
+
return context;
|
|
156
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js instrumentation hook
|
|
3
|
+
* Sets up WebSocket server for real-time events
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export async function register() {
|
|
7
|
+
// Only run on server
|
|
8
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
9
|
+
const { setupWebSocketServer } = await import('./lib/websocket-setup');
|
|
10
|
+
setupWebSocketServer();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
const DOCS_DIR = path.join(process.cwd(), 'docs');
|
|
7
|
+
export const API_ENTRY_DOC = 'API.md';
|
|
8
|
+
|
|
9
|
+
interface ApiDocGroupConfig {
|
|
10
|
+
label: string;
|
|
11
|
+
collapsible?: boolean;
|
|
12
|
+
filenames: string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const API_DOC_GROUP_CONFIG: ApiDocGroupConfig[] = [
|
|
16
|
+
{
|
|
17
|
+
label: 'GETTING STARTED',
|
|
18
|
+
collapsible: false,
|
|
19
|
+
filenames: [
|
|
20
|
+
'API.md',
|
|
21
|
+
'api/authentication.md',
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'SECRETS',
|
|
26
|
+
filenames: [
|
|
27
|
+
'api/secrets/credentials.md',
|
|
28
|
+
'api/secrets/sharing.md',
|
|
29
|
+
'api/secrets/api-keys.md',
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: 'WALLETS',
|
|
34
|
+
filenames: [
|
|
35
|
+
'api/wallets/core.md',
|
|
36
|
+
'api/wallets/data-portfolio.md',
|
|
37
|
+
'api/wallets/apps-strategies.md',
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: 'SYSTEM',
|
|
42
|
+
filenames: [
|
|
43
|
+
'api/system.md',
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const stripMarkdown = (value: string) => value.replace(/[`*_]/g, '').trim();
|
|
49
|
+
|
|
50
|
+
const normalizeDocPath = (value: string): string =>
|
|
51
|
+
path.posix.normalize(value.replace(/\\/g, '/').replace(/^\/+/, ''));
|
|
52
|
+
|
|
53
|
+
const safeDecodeURIComponent = (value: string): string => {
|
|
54
|
+
try {
|
|
55
|
+
return decodeURIComponent(value);
|
|
56
|
+
} catch {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const parseSummary = (content: string): string => {
|
|
62
|
+
const lines = content.split(/\r?\n/);
|
|
63
|
+
for (const rawLine of lines) {
|
|
64
|
+
const line = rawLine.trim();
|
|
65
|
+
if (!line) continue;
|
|
66
|
+
if (line.startsWith('#')) continue;
|
|
67
|
+
if (line.startsWith('```')) continue;
|
|
68
|
+
if (line.startsWith('|')) continue;
|
|
69
|
+
if (line === '---') continue;
|
|
70
|
+
return stripMarkdown(line);
|
|
71
|
+
}
|
|
72
|
+
return 'No summary available.';
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const parseTitle = (filename: string, content: string): string => {
|
|
76
|
+
const headingMatch = content.match(/^#\s+(.+)$/m);
|
|
77
|
+
if (headingMatch) return stripMarkdown(headingMatch[1]);
|
|
78
|
+
return path.basename(filename).replace(/\.md$/i, '').toUpperCase();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const API_DOC_FILENAMES = [...new Set(API_DOC_GROUP_CONFIG.flatMap((group) => group.filenames))];
|
|
82
|
+
const API_DOC_FILENAME_SET = new Set(API_DOC_FILENAMES);
|
|
83
|
+
|
|
84
|
+
export interface ApiDocFile {
|
|
85
|
+
filename: string;
|
|
86
|
+
title: string;
|
|
87
|
+
summary: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ApiDocGroup {
|
|
91
|
+
label: string;
|
|
92
|
+
collapsible: boolean;
|
|
93
|
+
docs: ApiDocFile[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const readApiDocMeta = async (filename: string): Promise<ApiDocFile> => {
|
|
97
|
+
const content = await readApiDocFile(filename);
|
|
98
|
+
return {
|
|
99
|
+
filename,
|
|
100
|
+
title: parseTitle(filename, content),
|
|
101
|
+
summary: parseSummary(content),
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const listApiDocGroups = async (): Promise<ApiDocGroup[]> => {
|
|
106
|
+
const groups = await Promise.all(API_DOC_GROUP_CONFIG.map(async (group) => ({
|
|
107
|
+
label: group.label,
|
|
108
|
+
collapsible: group.collapsible ?? true,
|
|
109
|
+
docs: await Promise.all(group.filenames.map((filename) => readApiDocMeta(filename))),
|
|
110
|
+
})));
|
|
111
|
+
|
|
112
|
+
return groups;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const listApiDocFiles = async (): Promise<ApiDocFile[]> => {
|
|
116
|
+
const groups = await listApiDocGroups();
|
|
117
|
+
return groups.flatMap((group) => group.docs);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const normalizeApiDocFilename = (value?: string | null): string => {
|
|
121
|
+
const raw = (value || API_ENTRY_DOC).trim();
|
|
122
|
+
const normalized = normalizeDocPath(safeDecodeURIComponent(raw).replace(/^\.\/?/, '').replace(/^docs\//i, ''));
|
|
123
|
+
if (!normalized || normalized === '.') return API_ENTRY_DOC;
|
|
124
|
+
return normalized;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const parseApiDocFilenameFromRouteSegments = (segments: string[]): string =>
|
|
128
|
+
normalizeApiDocFilename((segments || []).map((segment) => safeDecodeURIComponent(segment)).join('/'));
|
|
129
|
+
|
|
130
|
+
export const getApiDocHref = (filename: string): string => {
|
|
131
|
+
const normalized = normalizeApiDocFilename(filename);
|
|
132
|
+
if (normalized === API_ENTRY_DOC) return '/api';
|
|
133
|
+
const encoded = normalized.split('/').map((segment) => encodeURIComponent(segment)).join('/');
|
|
134
|
+
return `/api/${encoded}`;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const readApiDocFile = async (filename: string): Promise<string> => {
|
|
138
|
+
const normalized = normalizeApiDocFilename(filename);
|
|
139
|
+
if (!normalized.toLowerCase().endsWith('.md')) {
|
|
140
|
+
throw new Error(`Invalid API doc file: ${filename}`);
|
|
141
|
+
}
|
|
142
|
+
if (!API_DOC_FILENAME_SET.has(normalized)) {
|
|
143
|
+
throw new Error(`Unknown API doc file: ${filename}`);
|
|
144
|
+
}
|
|
145
|
+
if (normalized.startsWith('../') || normalized === '..') {
|
|
146
|
+
throw new Error('Path traversal attempt blocked');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const fullPath = path.join(DOCS_DIR, normalized);
|
|
150
|
+
if (!fullPath.startsWith(DOCS_DIR)) {
|
|
151
|
+
throw new Error('Path traversal attempt blocked');
|
|
152
|
+
}
|
|
153
|
+
return fs.readFile(fullPath, 'utf8');
|
|
154
|
+
};
|