Repository navigation
feat: wallet connection and holder session #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f68c60
feat: Mock data layer + SDK integration seam
sotoJ24 3cc4f96
fix: update getMockCreditCredentialSource → getCredentialSource in sh…
sotoJ24 0b15ec4
fix: align mock.ts types with @acta-products/types CreditCredential s…
sotoJ24 8e07cbb
feat: Wallet connection and holder session
sotoJ24 0963c42
feat: Wallet connection and holder session
sotoJ24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,3 +48,4 @@ MIGRATION-NOTES.md | |
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
| .env.local | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| 'use client'; | ||
|
|
||
| /** | ||
| * WalletButton — Client Component rendered inside the Server Component header. | ||
| * | ||
| * States: | ||
| * disconnected → "Connect wallet" button | ||
| * connecting → disabled button with loading spinner + i18n label | ||
| * connected → truncated G... address + truncated DID + "Disconnect" button | ||
| * | ||
| * All text via the 'session' i18n namespace. No hardcoded strings. | ||
| */ | ||
|
|
||
| import { useSession } from '@/session/session-provider'; | ||
| import { useTranslations } from 'next-intl'; | ||
| import { Button } from '@acta-products/ui'; | ||
| import { Wallet, LogOut, Loader2 } from 'lucide-react'; | ||
|
|
||
| /** GABC...7KQ4 — shows first 4 and last 4 chars */ | ||
| function truncateAddress(address: string): string { | ||
| return `${address.slice(0, 4)}...${address.slice(-4)}`; | ||
| } | ||
|
|
||
| /** did:pkh:stellar:testnet:GABC...7KQ4 — keeps prefix, truncates address */ | ||
| function truncateDid(did: string): string { | ||
| const parts = did.split(':'); | ||
| // did:pkh:stellar:{network}:{address} | ||
| if (parts.length < 5) return did; | ||
| const prefix = parts.slice(0, 4).join(':'); | ||
| const addr = parts[4]; | ||
| return `${prefix}:${addr.slice(0, 4)}...${addr.slice(-4)}`; | ||
| } | ||
|
|
||
| export function WalletButton() { | ||
| const { status, address, did, connect, disconnect } = useSession(); | ||
| const t = useTranslations('session'); | ||
|
|
||
| if (status === 'disconnected') { | ||
| return ( | ||
| <Button | ||
| size="sm" | ||
| variant="outline" | ||
| onClick={() => connect().catch(console.error)} | ||
| className="gap-1.5" | ||
| > | ||
| <Wallet className="size-3.5" /> | ||
| {t('connect')} | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| if (status === 'connecting') { | ||
| return ( | ||
| <Button size="sm" variant="outline" disabled className="gap-1.5"> | ||
| <Loader2 className="size-3.5 animate-spin" /> | ||
| {t('connecting')} | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| // connected | ||
| return ( | ||
| <div className="flex items-center gap-2"> | ||
| <div className="hidden sm:flex flex-col items-end"> | ||
| <span className="text-xs font-medium text-foreground font-mono"> | ||
| {address ? truncateAddress(address) : ''} | ||
| </span> | ||
| <span | ||
| className="text-[10px] text-muted-foreground font-mono truncate max-w-[180px]" | ||
| title={did ?? ''} | ||
| > | ||
| {did ? truncateDid(did) : ''} | ||
| </span> | ||
| </div> | ||
| <Button | ||
| size="sm" | ||
| variant="ghost" | ||
| onClick={() => disconnect().catch(console.error)} | ||
| className="gap-1.5 text-muted-foreground hover:text-destructive" | ||
| aria-label={t('disconnect')} | ||
| > | ||
| <LogOut className="size-3.5" /> | ||
| <span className="hidden sm:inline">{t('disconnect')}</span> | ||
| </Button> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 'use client'; | ||
|
|
||
| import { ActaConfig, mainNet, testNet } from '@acta-products/acta'; | ||
| import type { baseURL } from '@acta-products/acta'; | ||
| import type { StellarNetwork } from '@acta-products/acta/did'; | ||
|
|
||
| // Next.js inlines NEXT_PUBLIC_* at build time — declare so TypeScript resolves. | ||
| declare const NEXT_PUBLIC_STELLAR_NETWORK: string | undefined; | ||
| declare const NEXT_PUBLIC_ACTA_API_KEY: string | undefined; | ||
|
|
||
| function resolveBaseURL(network: StellarNetwork): baseURL { | ||
| return network === 'mainnet' ? mainNet : testNet; | ||
| } | ||
|
|
||
| function resolveNetwork(): StellarNetwork { | ||
| const raw = | ||
| typeof NEXT_PUBLIC_STELLAR_NETWORK !== 'undefined' | ||
| ? (NEXT_PUBLIC_STELLAR_NETWORK as string) | ||
| : 'testnet'; | ||
| return raw === 'mainnet' ? 'mainnet' : 'testnet'; | ||
| } | ||
|
|
||
| interface ActaProviderProps { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export function ActaProvider({ children }: ActaProviderProps) { | ||
| const network = resolveNetwork(); | ||
| const baseURL = resolveBaseURL(network); | ||
| const apiKey = | ||
| (typeof NEXT_PUBLIC_ACTA_API_KEY !== 'undefined' && | ||
| (NEXT_PUBLIC_ACTA_API_KEY as string).length > 0) | ||
| ? (NEXT_PUBLIC_ACTA_API_KEY as string) | ||
| : 'placeholder-batch1-no-api-calls'; | ||
|
|
||
| return ( | ||
| <ActaConfig baseURL={baseURL} apiKey={apiKey}> | ||
| {children} | ||
| </ActaConfig> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
Repository: ACTA-Team/products-acta
Length of output: 5470
🌐 Web query:
Next.js NEXT_PUBLIC environment variables process.env vs declare const globals💡 Result:
In Next.js, the
NEXT_PUBLIC_prefix and manual constant declarations (or configuration-based variables) serve different purposes regarding accessibility, security, and the build process. NEXT_PUBLIC_ Environment Variables By prefixing an environment variable withNEXT_PUBLIC_(e.g.,NEXT_PUBLIC_API_URL), you instruct Next.js to inline the value directly into the JavaScript bundle at build time [1][2][3]. This makes the variable accessible to both server-side code and client-side browser code [1][4][5]. Because these values are baked into the static JavaScript files, they are publicly visible to anyone who inspects the browser source code [6][7]. Consequently, you must never store sensitive secrets (such as API private keys or database passwords) using theNEXT_PUBLIC_prefix [3][6][5]. Furthermore, because they are inlined at build time, any changes to these variables require a full application rebuild; they cannot be updated at runtime without redeploying the app [1][3][6]. Process.env vs. Global Constants Next.js relies on static analysis (via tools like Webpack's DefinePlugin or Turbopack) to perform the replacement ofprocess.env.NEXT_PUBLIC_variables [8][3][9]. For this to work correctly, you must use the full, explicit syntax:process.env.NEXT_PUBLIC_VAR_NAME[8][3]. Do not attempt to destructureprocess.env(e.g.,const { NEXT_PUBLIC_VAR } = process.env) or use dynamic access (e.g.,process.env[key]), as these patterns bypass the build-time replacement mechanism and will returnundefinedin the browser bundle [3][9]. Similarly, accessingglobal.process.envinstead ofprocess.envis considered dynamic and will also fail to inline correctly [8]. Server-Only Variables Any environment variable defined in your.envfiles that does not start withNEXT_PUBLIC_is strictly server-only [1][10][11]. These variables are accessible in Node.js environments—such as API routes, Server Components, and middleware—but are completely stripped from the client-side JavaScript bundle [3][5][12]. This is the secure, default method for handling sensitive credentials [3][11]. Summary of Best Practices 1. Sensitive Secrets: Use standard environment variables (no prefix) and access them only on the server [5][7]. 2. Public Configuration: Use theNEXT_PUBLIC_prefix only for non-sensitive values like public API base URLs or feature flags [3][7]. 3. Avoid Destructuring: Always reference variables using the fullprocess.env.VARIABLE_NAMEsyntax [3][9]. 4. Startup Validation: Use a library like Zod to validate your environment variables at application startup, which helps catch missing or misconfigured variables immediately [6][5][12]. 5. No Runtime Updates: Remember thatNEXT_PUBLIC_values are frozen at build time; for runtime-configurable values, you must expose them through an API endpoint or another dynamic delivery mechanism [1][2].Citations:
🌐 Web query:
Next.js how are NEXT_PUBLIC_ variables exposed to browser client code💡 Result:
In Next.js, environment variables prefixed with NEXT_PUBLIC_ are exposed to the browser by being statically "inlined" into your JavaScript bundles during the build process [1][2]. When you run the build command (e.g., next build), the Next.js bundler (such as webpack or Turbopack) scans your code for any occurrences of process.env.NEXT_PUBLIC_VARIABLE_NAME and replaces these references with the actual string value defined in your environment at that time [1][3][4]. Key implications of this mechanism include: 1. Build-Time Freezing: Because these variables are hard-coded into your JavaScript bundles at build time, they are "frozen" [1][5]. If you change the value of a NEXT_PUBLIC_ variable in your environment (such as in your.env file or a hosting provider's dashboard) after the build is complete, your application will not reflect that change until you rebuild the project [1][3][5]. 2. Client-Side Exposure: Any variable prefixed with NEXT_PUBLIC_ is intentionally exposed to the browser [1][4]. Consequently, these values are visible to anyone who inspects the client-side JavaScript or the source code of your page [6][5]. You must never use this prefix for sensitive secrets, such as API private keys, database credentials, or internal configuration values [6][3][5]. 3. Default Behavior for Non-Prefixed Variables: Environment variables that do not use the NEXT_PUBLIC_ prefix are kept server-only [1][3]. If you attempt to access a non-prefixed environment variable (like process.env.DATABASE_URL) in client-side code, it will resolve to undefined [7][3][5]. 4. Strict Pattern Matching: The replacement process performs literal text matching [4]. It requires that you use the full expression, such as process.env.NEXT_PUBLIC_VAR, directly in your code [8][4]. Destructuring process.env or using dynamic keys will prevent the bundler from correctly identifying and replacing the variable, likely resulting in undefined at runtime [8][4]. For values that need to be dynamic or secret, the recommended approach is to keep those variables on the server and access them only through server-side code or by creating a dedicated API route that the client can call to fetch necessary configuration at runtime [1][6].
Citations:
Replace bare
NEXT_PUBLIC_*declarations withprocess.env.NEXT_PUBLIC_*to enable proper environment variable inlining.Next.js uses static analysis to replace
process.env.NEXT_PUBLIC_*references at build time. The current approach usingdeclare constbypasses this mechanism entirely, leaving these variables undefined at runtime and forcing fallback to'testnet'and the placeholder API key. Use the standard Next.js pattern:process.env.NEXT_PUBLIC_STELLAR_NETWORKandprocess.env.NEXT_PUBLIC_ACTA_API_KEY.Suggested fix
🤖 Prompt for AI Agents