Skip to content

Commit 50bc6fb

Browse files
author
StellarSplit
committed
fix: lazy-init client, ES2020 target, sodium-native webpack exclusion, dynamic verify page
1 parent 7220c6e commit 50bc6fb

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

next.config.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {};
2+
const nextConfig = {
3+
webpack: (config, { isServer }) => {
4+
if (!isServer) {
5+
// sodium-native is a Node.js native module — exclude from browser bundle
6+
config.resolve.fallback = {
7+
...config.resolve.fallback,
8+
fs: false,
9+
net: false,
10+
tls: false,
11+
};
12+
}
13+
// Exclude sodium-native from webpack entirely
14+
config.externals = [
15+
...(Array.isArray(config.externals) ? config.externals : []),
16+
"sodium-native",
17+
];
18+
return config;
19+
},
20+
};
21+
322
module.exports = nextConfig;

src/app/verify/[id]/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { unstable_noStore as noStore } from "next/cache";
12
import { splitClient } from "@/lib/stellar";
23
import { formatAmount } from "@stellar-split/sdk";
34
import PaymentProgress from "@/components/PaymentProgress";
@@ -6,11 +7,15 @@ interface Props {
67
params: { id: string };
78
}
89

10+
// Force dynamic rendering — this page fetches live on-chain data
11+
export const dynamic = "force-dynamic";
12+
913
/**
1014
* Public verification page — verifies an invoice on-chain via Stellar RPC.
1115
* No wallet connection required.
1216
*/
1317
export default async function VerifyPage({ params }: Props) {
18+
noStore();
1419
const { id } = params;
1520

1621
let invoice;

src/lib/stellar.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
/**
2-
* Initialises the StellarSplitClient singleton from environment variables.
3-
* Import `splitClient` wherever you need to call the contract.
2+
* Lazy-initialised StellarSplitClient.
3+
* The client is only constructed on first use, not at module load time.
4+
* This prevents build-time errors when env vars are placeholders.
45
*/
56

67
import { StellarSplitClient } from "@stellar-split/sdk";
78
import { NETWORK_PASSPHRASE } from "./freighter";
89

9-
const rpcUrl = process.env.NEXT_PUBLIC_RPC_URL!;
10-
const contractId = process.env.NEXT_PUBLIC_CONTRACT_ID!;
10+
let _client: StellarSplitClient | null = null;
1111

12-
if (!rpcUrl || !contractId) {
13-
throw new Error(
14-
"Missing NEXT_PUBLIC_RPC_URL or NEXT_PUBLIC_CONTRACT_ID environment variables."
15-
);
12+
export function getSplitClient(): StellarSplitClient {
13+
if (!_client) {
14+
const rpcUrl = process.env.NEXT_PUBLIC_RPC_URL ?? "https://soroban-testnet.stellar.org";
15+
const contractId = process.env.NEXT_PUBLIC_CONTRACT_ID ?? "";
16+
_client = new StellarSplitClient({ rpcUrl, networkPassphrase: NETWORK_PASSPHRASE, contractId });
17+
}
18+
return _client;
1619
}
1720

18-
export const splitClient = new StellarSplitClient({
19-
rpcUrl,
20-
networkPassphrase: NETWORK_PASSPHRASE,
21-
contractId,
21+
// Convenience re-export for components that use it directly
22+
export const splitClient = new Proxy({} as StellarSplitClient, {
23+
get(_target, prop) {
24+
return (getSplitClient() as never)[prop as keyof StellarSplitClient];
25+
},
2226
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2017",
3+
"target": "ES2020",
44
"lib": ["dom", "dom.iterable", "esnext"],
55
"allowJs": true,
66
"skipLibCheck": true,

0 commit comments

Comments
 (0)