Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"react-dom": "19.2.7"
},
"devDependencies": {
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "7.0.0",
"@testing-library/react": "16.3.2",
"@types/react": "^19.2",
Expand Down
43 changes: 40 additions & 3 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from "@sharibo/client";
import { config, configError } from "./config";
import { useI18n } from "./i18n";
import { usePoliteLiveRegion } from "./usePoliteLiveRegion";
import {
friendbotFund as fundWithFriendbot,
FriendbotRetryableError,
Expand Down Expand Up @@ -64,7 +65,7 @@ const CIRCLE_SIZE = 5;
const STROOPS_PER_XLM = 10_000_000n;
const README_URL = "https://github.com/crackedstudio/sharibo#honest-limitations";

const isTestnet = NETWORK.networkPassphrase.includes("Test SDF Network");
const isTestnet = Boolean(NETWORK.networkPassphrase?.includes("Test SDF Network"));
const BANNER_TEXT = isTestnet ? "Stellar testnet — no real funds" : "";

function TestnetBanner() {
Expand Down Expand Up @@ -347,6 +348,28 @@ function MemberRing({ members, revealed }: { members: { funded: boolean }[]; rev
);
}

function LanguageSwitcher({ className }: { className?: string }) {
const { locale, locales, setLocale, t } = useI18n();

return (
<div className={`language-switcher ${className ?? ""}`.trim()}>
<label htmlFor="language-select">{t("lang.label")}</label>
<select
id="language-select"
value={locale}
onChange={(e) => setLocale(e.target.value)}
aria-label={t("lang.label")}
>
{locales.map((code) => (
<option key={code} value={code}>
{t(`lang.${code}`)}
</option>
))}
</select>
</div>
);
}

function EnvSetupScreen({ errors }: { errors: string[] }) {
const { t } = useI18n();

Expand Down Expand Up @@ -455,8 +478,22 @@ export default function App() {
// just left — it keeps living on-chain even though the UI has moved on.
const [previousCircleId, setPreviousCircleId] = useState<bigint | null>(null);

// Track the most recently completed circle so we can show a "lives on-chain" link
// after a reset. Stored as { id, explorerUrl } so the fineprint is self-contained.
const [resumePrompt, setResumePrompt] = useState<any>(null);

useEffect(() => {
const saved = typeof sessionStorage !== "undefined" ? sessionStorage.getItem("sharibo_demo_state") : null;
if (saved) {
try {
const parsed = JSON.parse(saved, reviver);
if (parsed && parsed.circleId) {
setResumePrompt(parsed);
}
} catch {
sessionStorage.removeItem("sharibo_demo_state");
}
}
}, []);

const [prevCircle, setPrevCircle] = useState<{ id: string; explorerUrl: string } | null>(null);

const contribution = BigInt(contributionXlm) * STROOPS_PER_XLM;
Expand Down
20 changes: 14 additions & 6 deletions app/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, useMemo, useState, type ReactNode } from "react";
import { createContext, createElement, useContext, useMemo, useState, type ReactNode } from "react";

type Dictionary = Record<string, string>;

Expand Down Expand Up @@ -82,13 +82,21 @@ export function I18nProvider({ children }: { children: ReactNode }) {
};
}, [locale]);

return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;
return createElement(I18nContext.Provider, { value }, children);
}

export function useI18n(): I18nContextValue {
const ctx = useContext(I18nContext);
if (!ctx) {
throw new Error("useI18n must be used inside I18nProvider");
}
return ctx;
if (ctx) return ctx;
const fallback = dictionaries[fallbackLocale] ?? {};
const t = (key: string, vars?: Record<string, string | number>): string => {
const template = fallback[key] ?? key;
return interpolate(template, vars);
};
return {
locale: fallbackLocale ?? "en",
locales: localeCodes,
setLocale: () => {},
t,
};
}
5 changes: 4 additions & 1 deletion app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App.js";
import { ErrorBoundary } from "./ErrorBoundary.js";
import { I18nProvider } from "./i18n.js";
import "./style.css";

createRoot(document.getElementById("root")!).render(
<StrictMode>
<ErrorBoundary>
<App />
<I18nProvider>
<App />
</I18nProvider>
</ErrorBoundary>
</StrictMode>,
);
6 changes: 6 additions & 0 deletions app/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@ export default defineConfig({
// globally before every test file.
setupFiles: ["./src/setupTests.ts"],
globals: true,
env: {
VITE_SHARIBO_CONTRACT_ID: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
VITE_STELLAR_RPC_URL: "https://soroban-testnet.stellar.org",
VITE_STELLAR_NETWORK_PASSPHRASE: "Test SDF Network ; September 2015",
VITE_TEST_TOKEN_CONTRACT_ID: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
},
},
});
Loading