All files / src/components/wallet flows.tsx

100% Statements 18/18
100% Branches 2/2
100% Functions 3/3
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388                                                                      11x   11x     11x                     11x 11x   11x     11x                                                                                                       11x                                                                         11x                                                   33x                                           11x                     66x                                                       11x                                                           11x               11x             11x               11x                                                                                           55x                                                                                                              
/**
 * Step data for the three wallet flows rendered by WalletFlow (PhoneFrame.tsx).
 *
 * REGISTER_STEPS and LOGIN_STEPS are d-you's own PID presentation flow, screen
 * by screen, with the strings of the 2026-09-16 mirror
 * (`Localizable.xcstrings`, keys `pid_presentation.*`, `overview.*`,
 * `tap_navigation.*`): the dashboard with the scanner, the relying-party
 * screen ("This service is requesting data:"), the consent screen ("These
 * data will be transferred:" with the Digital ID card), the Digital ID code
 * ("Enter Digital ID code to confirm"), and the result ("Data sent
 * successfully"). A returning login is the same presentation; it only starts
 * at the request, the dashboard already behind it.
 *
 * EHR_TRANSFER_STEPS is the ePA data-access authorization via GesundheitsID
 * (NOT an EUDI PID presentation; GesundheitsID is today's real ePA auth) in
 * the insurer's app, the gated config (fictional default; TK only behind
 * NEXT_PUBLIC_DEMO_TK). Illustrative; see docs/planning/eudi-wallet-flows-2026.md.
 *
 * The steps are data: their texts stay English here and follow the language
 * picker where they are shown (#782, ADR-070). A body's text goes through
 * <T area="patient">; a button label is translated by WalletFlow; the
 * patient area knows them all (__tests__/unit/lib/i18n-wallet.test.ts).
 */
import {
  CheckCircle2,
  Check,
  ShieldCheck,
  Info,
  Eye,
  Landmark,
} from "lucide-react";
import { DYOU, type WalletStep } from "@/components/wallet/PhoneFrame";
import { insurer } from "@/lib/journey-config";
import { T } from "@/lib/i18n/translate";
 
const ORG = "European Health Dataspace";
/** The purpose our registration certificate declares (the DCQL `purpose`). */
const PURPOSE = "Sign in to the Health Dataspace patient portal";
 
/** A d-you card: light container, hairline outline, radius 12. */
const card: React.CSSProperties = {
  background: DYOU.surfaceContainer,
  border: `1px solid ${DYOU.outlineVariant}`,
  borderRadius: 12,
};
 
/**
 * The claims the hub's request asks for (`pidQuery` in `lib/eudi-verifier.ts`),
 * labelled as `pid_presentation.data_consent.label_*`: the name, and the birth
 * date for the secure hash of ADR-067. No age: the hub does not ask for it.
 */
export const PID_CLAIMS = ["Given name(s)", "Family name", "Date of birth"];
const PID_CLAIM_TOTAL = 14;
 
const muted = { color: DYOU.onSurfaceVariant };
 
/** d-you's dashboard with a Digital ID in it: the Overview tab. */
const DASHBOARD: WalletStep = {
  ms: 2600,
  primary: "Scan QR code",
  layout: "dashboard",
  body: (
    <div style={{ color: DYOU.onSurface }}>
      <div
        className="rounded-2xl p-3.5 text-white mb-3 relative overflow-hidden"
        style={{ background: DYOU.pid }}
      >
        <p className="text-[13px] font-bold">
          <T area="patient">{"Digital ID"}</T>
        </p>
        <p className="text-[10px] opacity-90">
          <T area="patient">{"Federal Republic of Germany"}</T>
        </p>
        <Landmark
          size={46}
          strokeWidth={1}
          className="absolute -right-2 -bottom-3 opacity-30"
        />
        <div className="mt-6 flex items-center gap-1.5 text-[10px]">
          <ShieldCheck size={12} />{" "}
          <T area="patient">{"Valid · added with your ID card"}</T>
        </div>
      </div>
      <p
        className="text-[10px] font-semibold tracking-wide uppercase"
        style={muted}
      >
        <T area="patient">{"Last activity"}</T>
      </p>
      <div className="p-2.5 text-[11px] mt-1" style={card}>
        <p className="font-semibold">
          <T area="patient">{ORG}</T>
        </p>
        <p style={muted}>
          <T area="patient">
            {"Verified on 14 May · Credential and data shared"}
          </T>
        </p>
      </div>
      <p className="text-[10px] mt-3 text-center" style={muted}>
        <T area="patient">
          {"Scan the QR code on the website to identify yourself."}
        </T>
      </p>
    </div>
  ),
};
 
/** `RPInfoView`: who asks, for what, and whether to go on. */
const RP_INFO: WalletStep = {
  ms: 3200,
  primary: "Next",
  secondary: "Reject",
  header: "close",
  body: (
    <div style={{ color: DYOU.onSurface }}>
      <h4 className="text-[19px] leading-tight font-normal">
        <T area="patient">{"This service is requesting data:"}</T>
      </h4>
      <p className="text-[14px] font-medium mt-3">
        <T area="patient">{ORG}</T>
      </p>
      <p
        className="text-[10px] font-semibold tracking-wide uppercase mt-3"
        style={muted}
      >
        <T area="patient">{"Purpose"}</T>
      </p>
      <p className="text-[12px] mt-0.5" style={muted}>
        <T area="patient">{PURPOSE}</T>
      </p>
      <p className="text-[12px] mt-4" style={muted}>
        <T area="patient">
          {"Do you want to share your data with this service?"}
        </T>
      </p>
      <p className="text-[12px] mt-2" style={muted}>
        <T area="patient">
          {"In the next step, you'll see which data will be sent."}
        </T>
      </p>
    </div>
  ),
};
 
/** `ConsentView`: the Digital ID card with the claims to be sent. */
const CONSENT: WalletStep = {
  ms: 3600,
  primary: "Next",
  secondary: "Reject",
  body: (
    <div style={{ color: DYOU.onSurface }}>
      <h4 className="text-[19px] leading-tight font-normal mb-3">
        <T area="patient">{"These data will be transferred:"}</T>
      </h4>
      <div className="overflow-hidden" style={card}>
        <div
          className="flex items-center justify-between text-white px-3 py-2.5"
          style={{ background: DYOU.pid }}
        >
          <p className="text-[12px] font-bold">
            <T
              area="patient"
              vars={{ n: PID_CLAIMS.length, total: PID_CLAIM_TOTAL }}
            >
              {"{n} out of {total} from Digital ID"}
            </T>
          </p>
          <Info size={14} />
        </div>
        <div className="grid grid-cols-2 gap-x-2 gap-y-2 p-3 text-[11px]">
          {PID_CLAIMS.map((c) => (
            <div key={c} className="flex items-center gap-1.5">
              <Check
                size={12}
                className="shrink-0"
                style={{ color: DYOU.primaryOutline }}
              />
              <T area="patient">{c}</T>
            </div>
          ))}
        </div>
      </div>
      <div
        className="mt-3 flex items-center justify-center gap-1.5 rounded-full text-[11px] font-semibold py-2"
        style={{ border: `1.5px solid ${DYOU.onSurface}` }}
      >
        <Eye size={13} /> <T area="patient">{"Show details"}</T>
      </div>
    </div>
  ),
};
 
/** The Digital ID code (wallet PIN) that confirms the transfer. */
const DIGITAL_ID_CODE: WalletStep = {
  ms: 2200,
  primary: "Transfer data",
  secondary: "Forgot Digital ID code",
  body: (
    <div style={{ color: DYOU.onSurface }}>
      <h4 className="text-[19px] leading-tight font-normal">
        <T area="patient">{"Enter Digital ID code to confirm"}</T>
      </h4>
      <div className="flex items-center justify-center gap-1.5 mt-8">
        {[0, 1, 2, 3, 4, 5].map((i) => (
          <span
            key={i}
            className="w-6 h-8 rounded-md"
            style={{
              background: DYOU.surfaceContainer,
              border: `1.5px solid ${
                i === 0 ? DYOU.primaryOutline : DYOU.outlineVariant
              }`,
            }}
          />
        ))}
        <span
          className="grid place-items-center w-8 h-8 rounded-full ml-1"
          style={{ border: `1px solid ${DYOU.outlineVariant}` }}
        >
          <Eye size={13} />
        </span>
      </div>
      <p className="text-[10px] mt-6 text-center" style={muted}>
        <T area="patient">
          {"Your 6-digit code, set when you added your ID to d-you."}
        </T>
      </p>
    </div>
  ),
};
 
/** `DocumentSuccessView` for a presentation. */
const SENT: WalletStep = {
  ms: 2600,
  primary: "Close",
  layout: "final",
  body: (
    <div className="text-center pt-6" style={{ color: DYOU.onSurface }}>
      <div
        className="mx-auto mb-4 grid place-items-center w-16 h-16 rounded-full"
        style={{ background: DYOU.primaryContainer }}
      >
        <CheckCircle2
          size={34}
          strokeWidth={1.75}
          style={{ color: DYOU.onSuccess }}
        />
      </div>
      <h4 className="text-[19px] leading-tight font-normal">
        <T area="patient">{"Data sent successfully"}</T>
      </h4>
      <p className="text-[12px] mt-3 px-1" style={muted}>
        <T area="patient">
          {
            "Go back to the service where you started the identification to finish the process."
          }
        </T>
      </p>
    </div>
  ),
};
 
export const REGISTER_STEPS: WalletStep[] = [
  DASHBOARD,
  RP_INFO,
  CONSENT,
  DIGITAL_ID_CODE,
  SENT,
];
 
export const LOGIN_STEPS: WalletStep[] = [
  RP_INFO,
  CONSENT,
  DIGITAL_ID_CODE,
  SENT,
];
 
export const EHR_CATEGORIES = [
  "Medications",
  "Lab results",
  "Diagnoses & findings",
  "Doctor's letters",
  "Vaccinations",
];
 
export const EHR_TRANSFER_STEPS: WalletStep[] = [
  {
    ms: 3000,
    primary: "Authenticate",
    accent: insurer.brand,
    body: (
      <div className="text-center">
        <div
          className="mx-auto mb-3 grid place-items-center w-14 h-14 rounded-full"
          style={{ background: `${insurer.brand}1a` }}
        >
          <ShieldCheck size={26} style={{ color: insurer.brand }} />
        </div>
        <h4 className="font-bold text-gray-900 text-[15px] leading-tight">
          <T area="patient">{"Connect your health record"}</T>
        </h4>
        <p className="text-[11px] font-semibold text-gray-700 mt-1 mb-3">
          {insurer.name}
        </p>
        <div className="rounded-xl bg-gray-50 border border-gray-200 p-2.5 text-left text-[11px] text-gray-600">
          <T area="patient" tags={{ b: <strong className="text-gray-800" /> }}>
            {
              "The EHDS portal requests access to your <b>ePA</b> (elektronische Patientenakte)."
            }
          </T>
        </div>
        <p className="text-[10px] text-gray-400 mt-2">
          <T area="patient">{"Authenticate with GesundheitsID"}</T>
        </p>
      </div>
    ),
  },
  {
    ms: 3800,
    primary: "Allow access",
    accent: insurer.brand,
    body: (
      <div>
        <h4 className="font-bold text-gray-900 text-[15px] mb-0.5">
          <T area="patient">{"Choose what to share"}</T>
        </h4>
        <p className="text-[10px] text-gray-400 mb-2">
          <T area="patient">{"To: European Health Dataspace portal"}</T>
        </p>
        <div className="space-y-1 text-[11px] text-gray-700">
          {EHR_CATEGORIES.map((c) => (
            <div
              key={c}
              className="flex items-center gap-2 rounded-lg bg-gray-50 border border-gray-200 px-2.5 py-1.5"
            >
              <Check size={13} className="text-emerald-600 shrink-0" />
              <T area="patient">{c}</T>
            </div>
          ))}
        </div>
        <p className="text-[10px] text-gray-400 mt-2 text-center">
          <T area="patient">{"Until I revoke · withdraw any time"}</T>
        </p>
      </div>
    ),
  },
  {
    ms: 2200,
    primary: "Authorising…",
    accent: insurer.brand,
    auto: true,
    body: (
      <div className="text-center pt-8">
        <div className="mx-auto mb-3 w-10 h-10 rounded-full border-2 border-gray-200 border-t-gray-700 animate-spin" />
        <h4 className="font-bold text-gray-900 text-[15px]">
          <T area="patient">{"Authorising via GesundheitsID"}</T>
        </h4>
        <p className="text-[11px] text-gray-500 mt-1">
          <T area="patient">{"Secure authentication…"}</T>
        </p>
      </div>
    ),
  },
  {
    ms: 2600,
    primary: "Done",
    accent: insurer.brand,
    body: (
      <div className="text-center pt-4">
        <div className="mx-auto mb-3 grid place-items-center w-16 h-16 rounded-full bg-emerald-50">
          <CheckCircle2 size={36} className="text-emerald-600" />
        </div>
        <h4 className="font-bold text-gray-900 text-[18px]">
          <T area="patient">{"Transferred"}</T>
        </h4>
        <p className="text-[11px] text-gray-500 mt-1.5 px-2">
          <T area="patient" vars={{ insurer: insurer.short }}>
            {
              "Your ePA is now in the EHDS portal as FHIR R4. End-to-end encrypted: {insurer} cannot read it. Withdraw consent any time."
            }
          </T>
        </p>
      </div>
    ),
  },
];