diff --git a/apps/mobile/src/features/chats/KinLevelsScreen.tsx b/apps/mobile/src/features/chats/KinLevelsScreen.tsx
index a46b4d2f7bd40..b19609b7c495a 100644
--- a/apps/mobile/src/features/chats/KinLevelsScreen.tsx
+++ b/apps/mobile/src/features/chats/KinLevelsScreen.tsx
@@ -25,6 +25,7 @@ import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
import { appAtomRegistry } from "../../state/atom-registry";
import { useAtomCommand } from "../../state/use-atom-command";
import { kinClient } from "./state/kinClient";
+import { KinApprovalCard } from "./widgets/KinApprovalCard";
import { kinChatTitle, kinDirectory } from "@t3tools/client-runtime/kin/kinScreenState";
import { useKinHostAt } from "./state/useKinHost";
import {
@@ -170,7 +171,7 @@ function KinLevelsBody(props: {
text:
change.kind === "lower"
? `Lowered to ${change.level}.`
- : `Raise to ${change.level} requested. It applies once you sign the approval.`,
+ : `Raise to ${change.level} requested. Approve it below with Face ID.`,
error: false,
});
};
@@ -272,6 +273,16 @@ function KinLevelsBody(props: {
))}
)}
+ {result.value.pendingRaises
+ .filter((raise) => raise.state === "awaiting_approval")
+ .map((raise) => (
+
+ ))}
{view.chats.length === 0 ? null : (
diff --git a/apps/mobile/src/features/chats/KinWaitingScreen.tsx b/apps/mobile/src/features/chats/KinWaitingScreen.tsx
index 91305afbe699a..d47aa20f3c4a1 100644
--- a/apps/mobile/src/features/chats/KinWaitingScreen.tsx
+++ b/apps/mobile/src/features/chats/KinWaitingScreen.tsx
@@ -1,5 +1,8 @@
import { useNavigation } from "@react-navigation/native";
+import { kinApprovalActionIdOf } from "@t3tools/contracts";
+import { View } from "react-native";
+import { Button } from "../../components/ui/Button";
import { EmptyState } from "../../components/ui/EmptyState";
import { ListRow } from "../../components/ui/ListRow";
import { ListSection } from "../../components/ui/ListSection";
@@ -11,8 +14,9 @@ import {
kinWaitingRowView,
} from "@t3tools/client-runtime/kin/kinScreenState";
import { useKinInbox } from "./state/useKinInbox";
+import { KinApprovalCard } from "./widgets/KinApprovalCard";
-/** Placeholder Waiting on you until the native cards land: one row per item, oldest first. */
+/** Waiting on you, oldest first: approvals as their full cards, everything else as a row. */
export function KinWaitingScreen() {
const navigation = useNavigation();
const { host, state, retry } = useKinInbox();
@@ -30,28 +34,59 @@ export function KinWaitingScreen() {
/>
);
}
+ const openChat = (item: (typeof view.waiting)[number]) =>
+ navigation.navigate("KinChat", {
+ environmentId: ready.environmentId,
+ orgId: item.orgId,
+ chatId: item.chatId,
+ });
+ const approvals = view.waiting.flatMap((item) => {
+ const actionId =
+ item.reason === "approval" && item.widgetId !== null
+ ? kinApprovalActionIdOf(item.widgetId)
+ : null;
+ return actionId === null ? [] : [{ item, actionId }];
+ });
+ const rest = view.waiting.filter(
+ (item) => !approvals.some((approval) => approval.item.waitingId === item.waitingId),
+ );
return (
-
- {view.waiting.map((item) => {
- const row = kinWaitingRowView(item, ready.inbox.value.chats, agentNames);
- return (
-
- navigation.navigate("KinChat", {
- environmentId: ready.environmentId,
- orgId: item.orgId,
- chatId: item.chatId,
- })
- }
+ <>
+ {approvals.map(({ item, actionId }) => (
+
+
- );
- })}
-
+
+
+
+ ))}
+ {rest.length === 0 ? null : (
+
+ {rest.map((item) => {
+ const row = kinWaitingRowView(item, ready.inbox.value.chats, agentNames);
+ return (
+ openChat(item)}
+ />
+ );
+ })}
+
+ )}
+ >
);
}}
diff --git a/apps/mobile/src/features/chats/approvals/KinApprovalsScreen.tsx b/apps/mobile/src/features/chats/approvals/KinApprovalsScreen.tsx
new file mode 100644
index 0000000000000..967f1dd97b80c
--- /dev/null
+++ b/apps/mobile/src/features/chats/approvals/KinApprovalsScreen.tsx
@@ -0,0 +1,273 @@
+import { useAtomValue } from "@effect/atom-react";
+import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
+import { EnvironmentId, KinOrgId } from "@t3tools/contracts";
+import * as Option from "effect/Option";
+import * as Device from "expo-device";
+import * as Schema from "effect/Schema";
+import { useState, type ReactNode } from "react";
+import { Alert, View } from "react-native";
+
+import { AppActivityIndicator } from "../../../components/ui/AppActivityIndicator";
+import { AppBar } from "../../../components/ui/AppBar";
+import { AppText as Text } from "../../../components/ui/AppText";
+import { Button } from "../../../components/ui/Button";
+import { EmptyState } from "../../../components/ui/EmptyState";
+import { ErrorBanner } from "../../../components/ui/ErrorBanner";
+import { ScreenContent } from "../../../components/ui/ScreenContent";
+import { ScreenScrollView } from "../../../components/ui/ScreenScrollView";
+import { kinClient } from "../state/kinClient";
+import { KinApprovalCard } from "../widgets/KinApprovalCard";
+import { useEnrolApproverKey, useKinApproverKey } from "./useKinApproverKey";
+
+type KinApprovalsParams = { readonly environmentId: string; readonly orgId: string };
+
+const decodeEnvironmentId = Schema.decodeUnknownOption(EnvironmentId);
+const decodeOrgId = Schema.decodeUnknownOption(KinOrgId);
+
+const HARDWARE: Record = {
+ secure_enclave: "Secure Enclave",
+ strongbox: "StrongBox",
+ tee: "secure hardware",
+ software: "software",
+};
+
+/** Sets up this phone to approve Kin's requests: one hardware key, behind Face ID every time. */
+export function KinApprovalsScreen({ route }: StaticScreenProps) {
+ const navigation = useNavigation();
+ const environmentId = Option.getOrNull(decodeEnvironmentId(route.params.environmentId));
+ const orgId = Option.getOrNull(decodeOrgId(route.params.orgId));
+ return (
+
+ navigation.goBack()} />
+
+
+ {environmentId === null || orgId === null ? (
+
+ ) : (
+
+ )}
+
+
+
+ );
+}
+
+function ApprovalsBody(props: { readonly environmentId: EnvironmentId; readonly orgId: KinOrgId }) {
+ const { environmentId, orgId } = props;
+ const { status, refresh } = useKinApproverKey(environmentId, orgId);
+ const enrol = useEnrolApproverKey();
+ const canChallenge = useAtomValue(kinClient.keyChallenge.permissionAtom(environmentId));
+ const canRegister = useAtomValue(kinClient.registerKey.permissionAtom(environmentId));
+ const canEnrol = canChallenge && canRegister;
+ const [working, setWorking] = useState(false);
+ const [problem, setProblem] = useState<{
+ readonly text: string;
+ readonly keyExists: boolean;
+ } | null>(null);
+
+ const start = async (replace: boolean) => {
+ if (working || !canEnrol) return;
+ setWorking(true);
+ setProblem(null);
+ const result = await enrol({ environmentId, orgId, replace });
+ setWorking(false);
+ if (result !== null && !result.ok) setProblem(result);
+ };
+ const confirmReplace = () =>
+ Alert.alert(
+ "Replace this phone's key?",
+ "Kin stops accepting approvals from the old key. You confirm the new one like the first.",
+ [
+ { text: "Cancel", style: "cancel" },
+ { text: "Replace key", style: "destructive", onPress: () => void start(true) },
+ ],
+ );
+
+ if (status._tag === "loading")
+ return (
+
+
+
+ );
+ if (status._tag === "unreadable")
+ return (
+
+
+
+
+
+
+ );
+
+ const section = (title: string, lines: ReadonlyArray, extra?: ReactNode) => (
+
+
+ {title}
+
+ {lines.map((line) => (
+
+ {line}
+
+ ))}
+ {extra}
+
+ );
+ const problemLine =
+ problem === null ? null : (
+
+ {problem.text}
+
+ );
+ const actions = (primary: ReactNode) => (
+ {primary}
+ );
+ const cantEnrolLine = canEnrol ? null : (
+
+ This device can't set up approvals. Pair it again from the Kin host.
+
+ );
+ const remake = (label: string) =>
+ actions(
+ ,
+ );
+ const keyLine = (thumbprint: string) => (
+
+ {`Key ${thumbprint}`}
+
+ );
+ const codeLine = (code: string) => (
+
+ {`${code.slice(0, 3)} ${code.slice(3)}`}
+
+ );
+
+ switch (status._tag) {
+ case "none":
+ // Simulators refuse biometric Secure Enclave keys (LocalAuthentication -1020).
+ if (!Device.isDevice)
+ return section("This simulator can't approve", [
+ "Approval keys need the secure hardware and Face ID of a real phone. Set up approvals on your iPhone.",
+ ]);
+ return section(
+ "Approve from this phone",
+ [
+ "Kin asks before it merges a pull request or raises a lead's level. You approve with Face ID, and the phone signs exactly what the card shows.",
+ "The key stays in this phone's secure hardware and never leaves it.",
+ ],
+ <>
+ {problemLine}
+ {cantEnrolLine}
+ {actions(
+ problem?.keyExists === true || status.staleKey ? (
+
+ ) : (
+