Files
timmy-tower/artifacts/mobile/app/_layout.tsx
Alexander Whitestone 88d3c6d9d0
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s
feat(mobile): Nostr identity — Amber NIP-55 deep link + nsec fallback
Implements mobile Nostr identity management per issue #29.

Android — NIP-55 Amber integration:
- Opens com.greenart7c3.nostrsigner via `nostrsigner:` URI scheme to
  retrieve the user's public key without exposing it to the app.
- Listens for the `mobile://nostr-callback` deep link response and stores
  the resulting npub in Expo SecureStore.
- Falls back to Play Store install prompt when Amber is not installed.

iOS / manual fallback:
- NostrConnectModal accepts an nsec1 paste-in, validates bech32, derives
  the pubkey via nostr-tools getPublicKey, and stores the key only in
  Expo SecureStore — never in AsyncStorage, Redux, or logs.

Both platforms:
- Truncated npub and signer type (Amber / nsec) shown in Settings.
- "Disconnect Nostr" wipes all keys from SecureStore and resets state.
- Identity persists across restarts via SecureStore.

Supporting changes:
- NostrContext: new React context for identity lifecycle.
- NostrConnectModal: platform-aware bottom-sheet modal for connect flow.
- TimmyContext: added apiBaseUrl/setApiBaseUrl/isConnected; URL persisted
  in AsyncStorage and restored on mount; circular dep broken via refs.
- constants/colors: added field, textInverted, destructive, link colours.
- constants/storage-keys: added SERVER_URL_KEY.
- app.json: added Android intent filter for mobile://nostr-callback.
- package.json: added nostr-tools and expo-secure-store dependencies.

Fixes #29

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 22:30:40 -04:00

93 lines
2.8 KiB
TypeScript

import {
Inter_400Regular,
Inter_500Medium,
Inter_600SemiBold,
Inter_700Bold,
useFonts,
} from "@expo-google-fonts/inter";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Stack, router, useSegments } from "expo-router";
import * as SplashScreen from "expo-splash-screen";
import React, { useEffect, useState } from "react";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { KeyboardProvider } from "react-native-keyboard-controller";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { ErrorBoundary } from "@/components/ErrorBoundary";
import { TimmyProvider } from "@/context/TimmyContext";
import { NostrProvider } from "@/context/NostrContext";
import { ONBOARDING_COMPLETED_KEY } from "@/constants/storage-keys";
SplashScreen.preventAutoHideAsync();
const queryClient = new QueryClient();
function RootLayoutNav() {
const segments = useSegments();
const [onboardingChecked, setOnboardingChecked] = useState(false);
const [needsOnboarding, setNeedsOnboarding] = useState(false);
useEffect(() => {
AsyncStorage.getItem(ONBOARDING_COMPLETED_KEY).then((value) => {
setNeedsOnboarding(value !== "true");
setOnboardingChecked(true);
});
}, []);
useEffect(() => {
if (!onboardingChecked) return;
const inOnboarding = segments[0] === "onboarding";
if (needsOnboarding && !inOnboarding) {
router.replace("/onboarding");
} else if (!needsOnboarding && inOnboarding) {
router.replace("/(tabs)");
}
}, [onboardingChecked, needsOnboarding, segments]);
return (
<Stack screenOptions={{ headerBackTitle: "Back" }}>
<Stack.Screen name="onboarding" options={{ headerShown: false, animation: "none" }} />
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="settings" options={{ headerShown: false, presentation: "modal" }} />
</Stack>
);
}
export default function RootLayout() {
const [fontsLoaded, fontError] = useFonts({
Inter_400Regular,
Inter_500Medium,
Inter_600SemiBold,
Inter_700Bold,
});
useEffect(() => {
if (fontsLoaded || fontError) {
SplashScreen.hideAsync();
}
}, [fontsLoaded, fontError]);
if (!fontsLoaded && !fontError) return null;
return (
<SafeAreaProvider>
<ErrorBoundary>
<QueryClientProvider client={queryClient}>
<GestureHandlerRootView style={{ flex: 1 }}>
<KeyboardProvider>
<NostrProvider>
<TimmyProvider>
<RootLayoutNav />
</TimmyProvider>
</NostrProvider>
</KeyboardProvider>
</GestureHandlerRootView>
</QueryClientProvider>
</ErrorBoundary>
</SafeAreaProvider>
);
}