@outerjoyn/react-native 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1499 @@
1
+ /**
2
+ * ConnectScreen — React Native port of the web ConnectWidget.
3
+ *
4
+ * Pure RN implementation of the Plaid-style account linking flow:
5
+ * 1. Search/browse available loyalty programs (institutions)
6
+ * 2. Select a program and review consent/permissions
7
+ * 3. OAuth authorization via system browser (Linking.openURL)
8
+ * 4. Processing spinner while awaiting deep link callback
9
+ * 5. Success confirmation with onSuccess callback
10
+ *
11
+ * State machine: loading -> search -> consent -> processing -> success | error
12
+ *
13
+ * OAuth flow (RN-specific):
14
+ * - Opens system browser via Linking.openURL() (no window.open)
15
+ * - Listens for deep link callback via Linking.addEventListener
16
+ * - Parses callback URL for public_token or error params
17
+ * - Falls back to simulated OAuth when backend mobile redirect is not yet wired
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * <ConnectScreen
22
+ * visible={showConnect}
23
+ * onSuccess={(result) => console.log('Linked!', result)}
24
+ * onClose={() => setShowConnect(false)}
25
+ * />
26
+ * ```
27
+ */
28
+
29
+ import React, { useState, useEffect, useCallback, useRef, useContext } from 'react';
30
+ import {
31
+ View,
32
+ Text,
33
+ TextInput,
34
+ Modal,
35
+ Pressable,
36
+ FlatList,
37
+ Image,
38
+ ActivityIndicator,
39
+ StyleSheet,
40
+ Linking,
41
+ Platform,
42
+ Alert,
43
+ } from 'react-native';
44
+ import * as WebBrowser from 'expo-web-browser';
45
+ import { OuterJoynContext } from '../OuterJoynProvider';
46
+ import { APIClient } from '../core/api-client';
47
+
48
+ const OJ_LOGO_URL = 'https://app.outerjoyn.com/outerjoyn-logo.png';
49
+
50
+ // =============================================================================
51
+ // Types
52
+ // =============================================================================
53
+
54
+ /** Institution (loyalty program) returned by the connect API */
55
+ interface Institution {
56
+ institution_id: string;
57
+ name: string;
58
+ logo_url: string | null;
59
+ oauth_supported: boolean;
60
+ products: string[];
61
+ category?: string;
62
+ is_active?: boolean;
63
+ }
64
+
65
+ /** Info about an already-linked institution */
66
+ interface LinkedInstitution {
67
+ institution_id: string;
68
+ linked_at: string;
69
+ scopes?: string[];
70
+ }
71
+
72
+ /** Consent scope describing a permission granted during account linking */
73
+ interface ConsentScope {
74
+ id: string;
75
+ description: string;
76
+ }
77
+
78
+ /** Result passed to onSuccess callback */
79
+ export interface ConnectResult {
80
+ member_partner_link_id: string;
81
+ member_id: string;
82
+ institution: Institution;
83
+ }
84
+
85
+ /** Props for ConnectScreen */
86
+ export interface ConnectScreenProps {
87
+ /** Whether the modal is visible */
88
+ visible: boolean;
89
+ /** Called when account linking succeeds */
90
+ onSuccess?: (result: ConnectResult) => void;
91
+ /** Called when user closes the screen */
92
+ onClose?: () => void;
93
+ /** Called on error */
94
+ onError?: (error: Error) => void;
95
+ /** Override session token (reads from OuterJoynProvider context if omitted) */
96
+ sessionToken?: string;
97
+ /** Override API base URL (reads from context if omitted) */
98
+ apiBaseUrl?: string;
99
+ /** Pre-select a specific institution by ID */
100
+ preselectedInstitutionId?: string;
101
+ }
102
+
103
+ type Step = 'loading' | 'search' | 'consent' | 'processing' | 'success' | 'error';
104
+
105
+ // =============================================================================
106
+ // Constants
107
+ // =============================================================================
108
+
109
+ const DEFAULT_API_BASE = 'https://api.outerjoyn.com';
110
+ const DEEP_LINK_SCHEME = 'outerjoyn://connect/callback';
111
+
112
+ const LOGO_TOKEN = 'pk_VAZ6tvAVQHCDwKeaNRVyjQ';
113
+
114
+ const DEFAULT_SCOPES: ConsentScope[] = [
115
+ { id: 'balance', description: 'View your points balance' },
116
+ { id: 'redeem', description: 'Redeem points for purchases' },
117
+ { id: 'tier', description: 'View your membership tier' },
118
+ { id: 'transactions', description: 'Transaction history' },
119
+ ];
120
+
121
+ // Demo institutions use real brand_id values from the Brand table so the
122
+ // hosted OAuth authorize endpoint receives a valid numeric institution_id.
123
+ const DEMO_INSTITUTIONS: Institution[] = [
124
+ { institution_id: '53055657', name: 'Delta SkyMiles', logo_url: `https://img.logo.dev/delta.com?token=${LOGO_TOKEN}`, oauth_supported: true, products: ['loyalty'], category: 'Airline' },
125
+ { institution_id: '53055658', name: 'Marriott Bonvoy', logo_url: `https://img.logo.dev/marriott.com?token=${LOGO_TOKEN}`, oauth_supported: true, products: ['loyalty'], category: 'Hotel' },
126
+ { institution_id: '53055659', name: 'Amex Membership Rewards', logo_url: `https://img.logo.dev/americanexpress.com?token=${LOGO_TOKEN}`, oauth_supported: true, products: ['loyalty'], category: 'Credit Card' },
127
+ { institution_id: '53055660', name: 'United MileagePlus', logo_url: `https://img.logo.dev/united.com?token=${LOGO_TOKEN}`, oauth_supported: true, products: ['loyalty'], category: 'Airline' },
128
+ { institution_id: '53055661', name: 'Hilton Honors', logo_url: `https://img.logo.dev/hilton.com?token=${LOGO_TOKEN}`, oauth_supported: true, products: ['loyalty'], category: 'Hotel' },
129
+ { institution_id: '11849876', name: 'Coffee Points Co', logo_url: `https://img.logo.dev/starbucks.com?token=${LOGO_TOKEN}`, oauth_supported: true, products: ['loyalty'], category: 'Coffee' },
130
+ { institution_id: '53808587', name: 'Luxury Hotels Inc', logo_url: `https://img.logo.dev/fourseasons.com?token=${LOGO_TOKEN}`, oauth_supported: true, products: ['loyalty'], category: 'Hotel' },
131
+ { institution_id: '24229420', name: 'LoyaltyPlus', logo_url: `https://img.logo.dev/shopify.com?token=${LOGO_TOKEN}`, oauth_supported: true, products: ['loyalty'], category: 'Retail' },
132
+ ];
133
+
134
+ // =============================================================================
135
+ // Brand Colors
136
+ // =============================================================================
137
+
138
+ const C = {
139
+ primary: '#0c90eb',
140
+ navy: '#0D1B4C',
141
+ accent: '#3B82F6',
142
+ success: '#10b981',
143
+ successBg: '#ecfdf5',
144
+ error: '#ef4444',
145
+ errorBg: '#fef2f2',
146
+ bg: '#ffffff',
147
+ bgSecondary: '#f8fafc',
148
+ border: '#e2e8f0',
149
+ text: '#0f172a',
150
+ textSecondary: '#64748b',
151
+ textTertiary: '#94a3b8',
152
+ overlay: 'rgba(15,23,42,0.6)',
153
+ };
154
+
155
+ // =============================================================================
156
+ // Component
157
+ // =============================================================================
158
+
159
+ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
160
+ visible,
161
+ onSuccess,
162
+ onClose,
163
+ onError,
164
+ sessionToken: tokenProp,
165
+ apiBaseUrl: baseUrlProp,
166
+ preselectedInstitutionId,
167
+ }) => {
168
+ // Try to read from OuterJoynProvider context (optional — works standalone too)
169
+ const ctx = useContext(OuterJoynContext);
170
+ const sessionToken = tokenProp || (ctx as any)?.sessionToken || '';
171
+ const apiBaseUrl = (baseUrlProp || DEFAULT_API_BASE).replace(/\/+$/, '');
172
+ const isDemoMode = !sessionToken;
173
+ const t = (ctx as any)?.t ?? ((key: string) => key);
174
+
175
+ // -------------------------------------------------------------------------
176
+ // State
177
+ // -------------------------------------------------------------------------
178
+
179
+ const [step, setStep] = useState<Step>('loading');
180
+ const [search, setSearch] = useState('');
181
+ const [institutions, setInstitutions] = useState<Institution[]>([]);
182
+ const [linkedInstitutions, setLinkedInstitutions] = useState<LinkedInstitution[]>([]);
183
+ // Track recently disconnected names so they don't show as "Connected"
184
+ // even if the provider context hasn't caught up yet.
185
+ const [disconnectedNames, setDisconnectedNames] = useState<Set<string>>(new Set());
186
+ const [selectedInstitution, setSelectedInstitution] = useState<Institution | null>(null);
187
+ const [dynamicScopes, setDynamicScopes] = useState<ConsentScope[] | null>(null);
188
+ const [errorMessage, setErrorMessage] = useState('');
189
+ const [connectToken, setConnectToken] = useState<string | null>(null);
190
+ const [consentRequired, setConsentRequired] = useState(false);
191
+ const [consentGranting, setConsentGranting] = useState(false);
192
+
193
+ const deepLinkSub = useRef<any>(null);
194
+ const oauthTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
195
+ const apiClient = useRef<APIClient | null>(null);
196
+
197
+ // Resolve API client synchronously — avoids race between apiClient useEffect
198
+ // and loadData useEffect that caused "No Programs Available" on first open.
199
+ function getApiClient(): APIClient | null {
200
+ if ((ctx as any)?.apiClient) {
201
+ apiClient.current = (ctx as any).apiClient;
202
+ return apiClient.current;
203
+ }
204
+ if (sessionToken) {
205
+ // Always create/update — APIClient is lightweight and sessionToken may change
206
+ apiClient.current = new APIClient(sessionToken, apiBaseUrl);
207
+ return apiClient.current;
208
+ }
209
+ apiClient.current = null;
210
+ return null;
211
+ }
212
+
213
+ // -------------------------------------------------------------------------
214
+ // Derived
215
+ // -------------------------------------------------------------------------
216
+
217
+ // Merge local linked state with provider's linkedPrograms + portablePrograms
218
+ const providerLinked = ((ctx as any)?.linkedPrograms ?? []) as Array<{ brandName?: string; id?: string }>;
219
+ const portableLinked = ((ctx as any)?.portablePrograms ?? []) as Array<{ brandName?: string; id?: string }>;
220
+ const allProviderLinked = [...providerLinked, ...portableLinked];
221
+ const linkedIds = new Set<string>([
222
+ ...linkedInstitutions
223
+ .filter((li) => !disconnectedNames.has(li.institution_id))
224
+ .map((li) => li.institution_id),
225
+ ...allProviderLinked
226
+ .filter((p) => !disconnectedNames.has(p.brandName?.toLowerCase() ?? ''))
227
+ .map((p) => p.brandName?.toLowerCase().replace(/\s+/g, '-'))
228
+ .filter(Boolean) as string[],
229
+ ]);
230
+ // Also try matching institution names against provider linked brand names
231
+ const providerLinkedNames = new Set(
232
+ allProviderLinked
233
+ .filter((p) => !disconnectedNames.has(p.brandName?.toLowerCase() ?? ''))
234
+ .map((p) => p.brandName?.toLowerCase()).filter(Boolean),
235
+ );
236
+ // Track which names are portable (linked via Joyn Wallet, not this app)
237
+ const portableNames = new Set(
238
+ portableLinked
239
+ .filter((p) => !disconnectedNames.has(p.brandName?.toLowerCase() ?? ''))
240
+ .map((p) => p.brandName?.toLowerCase()).filter(Boolean),
241
+ );
242
+
243
+ const filteredInstitutions = search.trim()
244
+ ? institutions.filter((i) => i.name.toLowerCase().includes(search.toLowerCase()))
245
+ : institutions;
246
+
247
+ const scopes = dynamicScopes || DEFAULT_SCOPES;
248
+
249
+ // -------------------------------------------------------------------------
250
+ // Data Fetching
251
+ // -------------------------------------------------------------------------
252
+
253
+ const loadData = useCallback(async () => {
254
+ setStep('loading');
255
+ setSearch('');
256
+ setSelectedInstitution(null);
257
+ setDisconnectedNames(new Set());
258
+ setErrorMessage('');
259
+
260
+ if (isDemoMode) {
261
+ setInstitutions(DEMO_INSTITUTIONS);
262
+ setLinkedInstitutions([]);
263
+ setStep('search');
264
+ if (preselectedInstitutionId) {
265
+ const match = DEMO_INSTITUTIONS.find((i) => i.institution_id === preselectedInstitutionId);
266
+ if (match) {
267
+ setSelectedInstitution(match);
268
+ setStep('consent');
269
+ }
270
+ }
271
+ return;
272
+ }
273
+
274
+ try {
275
+ // Fetch institutions and linked accounts in parallel.
276
+ // Retry once after 500ms if apiClient isn't available yet
277
+ // (provider may still be initializing on first mount).
278
+ let client = getApiClient();
279
+ if (!client) {
280
+ await new Promise((r) => setTimeout(r, 500));
281
+ client = getApiClient();
282
+ }
283
+ if (!client) {
284
+ setInstitutions([]);
285
+ setLinkedInstitutions([]);
286
+ setStep('search');
287
+ return;
288
+ }
289
+
290
+ const [instData, acctData, portableData] = await Promise.all([
291
+ client.get<{ institutions: Institution[] }>('/api/sdk/institutions').catch(() => null),
292
+ client.get<{ connected_brands?: any[] }>('/api/sdk/account').catch(() => null),
293
+ client.get<{ consent_status?: string; consumer_identity_id?: string }>('/api/sdk/portable-programs').catch(() => null),
294
+ ]);
295
+
296
+ // Check if link portability consent is needed
297
+ if (portableData?.consent_status === 'required') {
298
+ setConsentRequired(true);
299
+ }
300
+
301
+ const list = (instData?.institutions || []).filter((i) => i.is_active !== false);
302
+ setInstitutions(list);
303
+
304
+ if (acctData?.connected_brands) {
305
+ setLinkedInstitutions(
306
+ acctData.connected_brands.map((cb: any) => ({
307
+ institution_id: String(cb.brand_id),
308
+ linked_at: cb.linked_at || '',
309
+ scopes: cb.scopes || [],
310
+ })),
311
+ );
312
+ }
313
+
314
+ setStep('search');
315
+
316
+ const activeList = list;
317
+ if (preselectedInstitutionId) {
318
+ const match = activeList.find((i) => i.institution_id === preselectedInstitutionId);
319
+ if (match) {
320
+ setSelectedInstitution(match);
321
+ setStep('consent');
322
+ }
323
+ }
324
+ } catch (err: any) {
325
+ console.warn('[OuterJoyn] ConnectScreen loadData failed:', err.message);
326
+ setInstitutions([]);
327
+ setLinkedInstitutions([]);
328
+ setStep('search');
329
+ }
330
+ }, [isDemoMode, preselectedInstitutionId, apiBaseUrl, sessionToken, onError]);
331
+
332
+ // Load data when modal becomes visible
333
+ useEffect(() => {
334
+ if (visible) {
335
+ loadData();
336
+ }
337
+ }, [visible, loadData]);
338
+
339
+ // -------------------------------------------------------------------------
340
+ // Institution Selection + Dynamic Scopes
341
+ // -------------------------------------------------------------------------
342
+
343
+ const handleSelectInstitution = useCallback(
344
+ async (institution: Institution) => {
345
+ setSelectedInstitution(institution);
346
+ setDynamicScopes(null);
347
+
348
+ const isAlreadyLinked = linkedIds.has(institution.institution_id)
349
+ || providerLinkedNames.has(institution.name.toLowerCase());
350
+
351
+ // Already linked → show manage view (disconnect / re-link)
352
+ if (isAlreadyLinked) {
353
+ setStep('consent');
354
+ return;
355
+ }
356
+
357
+ // For real (non-demo) mode, skip the SDK consent step —
358
+ // the wallet-web consent page handles auth + consent in one flow.
359
+ if (!isDemoMode) {
360
+ setStep('processing');
361
+ initiateConnectForInstitution(institution);
362
+ return;
363
+ }
364
+
365
+ // Demo mode shows the SDK consent step
366
+ setStep('consent');
367
+ },
368
+ [isDemoMode, linkedIds, providerLinkedNames],
369
+ );
370
+
371
+ // -------------------------------------------------------------------------
372
+ // OAuth Flow
373
+ // -------------------------------------------------------------------------
374
+
375
+ /** Core OAuth flow — takes the institution directly so it can be
376
+ * called from both the consent step (demo) and directly from
377
+ * institution selection (real mode, skipping duplicate consent). */
378
+ const initiateConnectForInstitution = useCallback(async (institution: Institution) => {
379
+ try {
380
+ const client = getApiClient();
381
+ if (!client) {
382
+ throw new Error('API client not available');
383
+ }
384
+ const tokenData = await client.post<{ connect_token: string }>(
385
+ '/api/sdk/sessions/connect',
386
+ );
387
+ setConnectToken(tokenData.connect_token);
388
+
389
+ const oauthUrl =
390
+ `${apiBaseUrl}/api/sdk/oauth/authorize?` +
391
+ `connect_token=${encodeURIComponent(tokenData.connect_token)}` +
392
+ `&institution_id=${encodeURIComponent(institution.institution_id)}` +
393
+ `&platform=mobile` +
394
+ `&redirect_uri=${encodeURIComponent(DEEP_LINK_SCHEME)}`;
395
+
396
+ // In-app auth session (Plaid-style) — opens Safari sheet inside
397
+ // the app, automatically intercepts the redirect URI deep link.
398
+ const result = await WebBrowser.openAuthSessionAsync(
399
+ oauthUrl,
400
+ DEEP_LINK_SCHEME,
401
+ { showInRecents: false },
402
+ );
403
+
404
+ if (result.type === 'success' && result.url) {
405
+ handleDeepLink(result.url, institution);
406
+ } else if (result.type === 'cancel') {
407
+ setStep('search');
408
+ } else {
409
+ setErrorMessage('Authorization was not completed.');
410
+ setStep('error');
411
+ }
412
+ } catch (err: any) {
413
+ console.warn('[OuterJoyn] OAuth init failed:', err?.message ?? err);
414
+ const message =
415
+ err?.message ??
416
+ 'Could not start the authorization flow. Please try again or contact support.';
417
+ setErrorMessage(message);
418
+ setStep('error');
419
+ onError?.(new Error(message));
420
+ }
421
+ }, [apiBaseUrl, onError]);
422
+
423
+ /** Called from the SDK consent step (demo mode only) */
424
+ const initiateConnect = useCallback(async () => {
425
+ if (!selectedInstitution) return;
426
+ setStep('processing');
427
+
428
+ if (isDemoMode) {
429
+ setTimeout(() => {
430
+ setLinkedInstitutions((prev) => [
431
+ ...prev,
432
+ { institution_id: selectedInstitution.institution_id, linked_at: new Date().toISOString() },
433
+ ]);
434
+ setStep('success');
435
+ onSuccess?.({
436
+ member_partner_link_id: String(Date.now()),
437
+ member_id: 'demo',
438
+ institution: selectedInstitution,
439
+ });
440
+ }, 2000);
441
+ return;
442
+ }
443
+
444
+ await initiateConnectForInstitution(selectedInstitution);
445
+ }, [selectedInstitution, isDemoMode, onSuccess, initiateConnectForInstitution]);
446
+
447
+ /** Parse deep link callback URL for OAuth result */
448
+ const handleDeepLink = useCallback(
449
+ (url: string, institution: Institution) => {
450
+ if (!url.startsWith('outerjoyn://connect/callback')) return;
451
+
452
+ // Clean up listener and timeout
453
+ if (deepLinkSub.current) {
454
+ deepLinkSub.current.remove();
455
+ deepLinkSub.current = null;
456
+ }
457
+ if (oauthTimeoutRef.current) {
458
+ clearTimeout(oauthTimeoutRef.current);
459
+ oauthTimeoutRef.current = null;
460
+ }
461
+
462
+ try {
463
+ const params = new URL(url).searchParams;
464
+ // The hosted OAuth callback returns status=success with a
465
+ // one-time auth code and the new link_id. The legacy v1
466
+ // callback returned public_token + member_partner_link_id.
467
+ // We accept both shapes for compatibility.
468
+ const status = params.get('status');
469
+ const error = params.get('error');
470
+ const code = params.get('code'); // hosted OAuth auth code
471
+ const linkId =
472
+ params.get('link_id') || params.get('member_partner_link_id');
473
+ const publicToken = params.get('public_token'); // legacy
474
+
475
+ if (error || status === 'error') {
476
+ setErrorMessage(error ?? 'Authorization failed');
477
+ setStep('error');
478
+ onError?.(new Error(error ?? 'Authorization failed'));
479
+ return;
480
+ }
481
+
482
+ if (status === 'success' || publicToken || linkId) {
483
+ setLinkedInstitutions((prev) => [
484
+ ...prev,
485
+ { institution_id: institution.institution_id, linked_at: new Date().toISOString() },
486
+ ]);
487
+ setStep('success');
488
+
489
+ // Refresh provider data so linked programs + balances update
490
+ const refreshFn = (ctx as any)?.refreshBalances;
491
+ if (typeof refreshFn === 'function') {
492
+ refreshFn().catch(() => {});
493
+ }
494
+
495
+ onSuccess?.({
496
+ member_partner_link_id: linkId ?? code ?? String(Date.now()),
497
+ member_id: params.get('member_id') ?? '0',
498
+ institution,
499
+ });
500
+ } else {
501
+ setErrorMessage('No authorization response received');
502
+ setStep('error');
503
+ }
504
+ } catch (err: any) {
505
+ setErrorMessage('Failed to parse authorization response');
506
+ setStep('error');
507
+ onError?.(new Error('Failed to parse authorization response'));
508
+ }
509
+ },
510
+ [onSuccess, onError],
511
+ );
512
+
513
+ // Cleanup deep link listener and OAuth timeout on unmount
514
+ useEffect(() => {
515
+ return () => {
516
+ if (deepLinkSub.current) {
517
+ deepLinkSub.current.remove();
518
+ deepLinkSub.current = null;
519
+ }
520
+ if (oauthTimeoutRef.current) {
521
+ clearTimeout(oauthTimeoutRef.current);
522
+ oauthTimeoutRef.current = null;
523
+ }
524
+ };
525
+ }, []);
526
+
527
+ // -------------------------------------------------------------------------
528
+ // Navigation
529
+ // -------------------------------------------------------------------------
530
+
531
+ const handleBack = useCallback(() => {
532
+ setSelectedInstitution(null);
533
+ setDynamicScopes(null);
534
+ setErrorMessage('');
535
+ setStep('search');
536
+ }, []);
537
+
538
+ const handleClose = useCallback(() => {
539
+ if (deepLinkSub.current) {
540
+ deepLinkSub.current.remove();
541
+ deepLinkSub.current = null;
542
+ }
543
+ if (oauthTimeoutRef.current) {
544
+ clearTimeout(oauthTimeoutRef.current);
545
+ oauthTimeoutRef.current = null;
546
+ }
547
+ onClose?.();
548
+ }, [onClose]);
549
+
550
+ // -------------------------------------------------------------------------
551
+ // Render: Loading
552
+ // -------------------------------------------------------------------------
553
+
554
+ const renderLoading = () => (
555
+ <View style={s.centerContainer}>
556
+ <ActivityIndicator size="large" color={C.primary} />
557
+ <Text style={s.loadingText}>{t('common.loading')}</Text>
558
+ </View>
559
+ );
560
+
561
+ // -------------------------------------------------------------------------
562
+ // Render: Search
563
+ // -------------------------------------------------------------------------
564
+
565
+ const renderInstitutionItem = ({ item }: { item: Institution }) => {
566
+ const isLinked = linkedIds.has(item.institution_id) || providerLinkedNames.has(item.name.toLowerCase());
567
+ const isPortable = portableNames.has(item.name.toLowerCase());
568
+ return (
569
+ <Pressable
570
+ style={[s.institutionRow, isLinked && s.institutionRowLinked]}
571
+ onPress={() => handleSelectInstitution(item)}
572
+ >
573
+ {item.logo_url ? (
574
+ <Image source={{ uri: item.logo_url }} style={s.institutionLogo} resizeMode="contain" />
575
+ ) : (
576
+ <View style={[s.institutionLogoFallback, { backgroundColor: C.primary }]}>
577
+ <Text style={s.logoFallbackText}>{item.name.charAt(0).toUpperCase()}</Text>
578
+ </View>
579
+ )}
580
+ <View style={s.institutionInfo}>
581
+ <Text style={s.institutionName} numberOfLines={1}>
582
+ {item.name}
583
+ </Text>
584
+ {isPortable ? (
585
+ <Text style={s.institutionCategory}>Linked via Joyn Wallet</Text>
586
+ ) : item.category ? (
587
+ <Text style={s.institutionCategory}>{item.category}</Text>
588
+ ) : null}
589
+ </View>
590
+ {isLinked ? (
591
+ <View style={s.linkedBadge}>
592
+ <Text style={s.linkedBadgeCheck}>{'\u2713'}</Text>
593
+ <Text style={s.linkedBadgeText}>{isPortable ? 'Portable' : t('connect.connected')}</Text>
594
+ </View>
595
+ ) : (
596
+ <Text style={s.chevron}>{'\u203A'}</Text>
597
+ )}
598
+ </Pressable>
599
+ );
600
+ };
601
+
602
+ const renderSearch = () => (
603
+ <View style={s.flex1}>
604
+ {/* Header */}
605
+ <View style={s.header}>
606
+ <View style={s.flex1}>
607
+ <Text style={s.headerTitle}>{t('connect.title')}</Text>
608
+ <Text style={s.headerSubtitle}>{t('connect.link_loyalty')}</Text>
609
+ </View>
610
+ <Pressable style={s.closeBtn} onPress={handleClose} hitSlop={8}>
611
+ <Text style={s.closeBtnText}>{'\u2715'}</Text>
612
+ </Pressable>
613
+ </View>
614
+
615
+ {/* Search Input */}
616
+ <View style={s.searchWrapper}>
617
+ <Text style={s.searchIcon}>{'\uD83D\uDD0D'}</Text>
618
+ <TextInput
619
+ style={s.searchInput}
620
+ placeholder={t('connect.search')}
621
+ placeholderTextColor={C.textTertiary}
622
+ value={search}
623
+ onChangeText={setSearch}
624
+ autoCorrect={false}
625
+ returnKeyType="search"
626
+ />
627
+ </View>
628
+
629
+ {/* Consent banner — shown when consumer has a ConsumerIdentity but hasn't
630
+ granted link_portability_consent. Granting enables cross-BU program sharing. */}
631
+ {consentRequired && !consentGranting && (
632
+ <View style={s.consentBanner}>
633
+ <Text style={s.consentBannerText}>
634
+ Share your linked programs across partner apps? Use your points without re-linking.
635
+ </Text>
636
+ <Pressable
637
+ style={s.consentBannerBtn}
638
+ onPress={async () => {
639
+ setConsentGranting(true);
640
+ try {
641
+ if (apiClient.current) {
642
+ // Route through Express (not direct CRUD) — SDK session tokens
643
+ // can't authenticate against the Go CRUD API key middleware.
644
+ await apiClient.current.post('/api/sdk/portable-programs/consent');
645
+ setConsentRequired(false);
646
+ // Refresh provider to pick up portable programs
647
+ const refreshFn = (ctx as any)?.refreshBalances;
648
+ if (typeof refreshFn === 'function') refreshFn().catch(() => {});
649
+ }
650
+ } catch {
651
+ // Non-fatal
652
+ }
653
+ setConsentGranting(false);
654
+ }}
655
+ >
656
+ <Text style={s.consentBannerBtnText}>Allow</Text>
657
+ </Pressable>
658
+ </View>
659
+ )}
660
+
661
+ {/* Institution List */}
662
+ <FlatList
663
+ data={filteredInstitutions}
664
+ keyExtractor={(item) => item.institution_id}
665
+ renderItem={renderInstitutionItem}
666
+ contentContainerStyle={s.listContent}
667
+ showsVerticalScrollIndicator={false}
668
+ keyboardShouldPersistTaps="handled"
669
+ ListEmptyComponent={
670
+ <View style={s.emptyState}>
671
+ <Text style={s.emptyText}>
672
+ {search ? `No programs found for "${search}"` : 'No programs available'}
673
+ </Text>
674
+ </View>
675
+ }
676
+ ListFooterComponent={
677
+ <View style={s.footer}>
678
+ <Text style={s.footerText}>Powered by</Text>
679
+ <Image
680
+ source={{ uri: OJ_LOGO_URL }}
681
+ style={s.footerLogo}
682
+ resizeMode="contain"
683
+ onError={() => {/* Logo failed to load — text fallback is visible */}}
684
+ />
685
+ </View>
686
+ }
687
+ />
688
+ </View>
689
+ );
690
+
691
+ // -------------------------------------------------------------------------
692
+ // Render: Consent
693
+ // -------------------------------------------------------------------------
694
+
695
+ const renderConsent = () => {
696
+ if (!selectedInstitution) return null;
697
+ const isLinked = linkedIds.has(selectedInstitution.institution_id)
698
+ || providerLinkedNames.has(selectedInstitution.name.toLowerCase());
699
+
700
+ // Linked programs get a completely different manage view
701
+ if (isLinked) return renderManageConnection();
702
+
703
+ // Unlinked: standard consent (demo mode only — real mode skips to OAuth)
704
+ return (
705
+ <View style={s.flex1}>
706
+ <View style={s.consentHeader}>
707
+ {selectedInstitution.logo_url ? (
708
+ <Image source={{ uri: selectedInstitution.logo_url }} style={s.consentLogo} resizeMode="contain" />
709
+ ) : (
710
+ <View style={[s.consentLogoFallback, { backgroundColor: C.primary }]}>
711
+ <Text style={s.consentLogoFallbackText}>
712
+ {selectedInstitution.name.charAt(0).toUpperCase()}
713
+ </Text>
714
+ </View>
715
+ )}
716
+ <Text style={s.consentBrandName}>{selectedInstitution.name}</Text>
717
+ <Text style={s.consentTitle}>{t('connect.authorize_access')}</Text>
718
+ </View>
719
+
720
+ <View style={s.consentBody}>
721
+ <Text style={s.consentPermLabel}>This will allow access to:</Text>
722
+ {scopes.map((scope) => (
723
+ <View key={scope.id} style={s.consentPermRow}>
724
+ <View style={s.permCheckCircle}>
725
+ <Text style={s.permCheckMark}>{'\u2713'}</Text>
726
+ </View>
727
+ <Text style={s.consentPermText}>{scope.description}</Text>
728
+ </View>
729
+ ))}
730
+ </View>
731
+
732
+ <View style={s.consentActions}>
733
+ <Pressable style={s.authorizeBtn} onPress={initiateConnect}>
734
+ <Text style={s.authorizeBtnText}>{t('connect.authorize')}</Text>
735
+ </Pressable>
736
+ <Pressable style={s.denyBtn} onPress={handleBack}>
737
+ <Text style={s.denyBtnText}>{t('connect.deny')}</Text>
738
+ </Pressable>
739
+ </View>
740
+
741
+ <View style={s.securityFooter}>
742
+ <View style={s.securityRow}>
743
+ <Text style={s.securityLock}>{'\uD83D\uDD12'}</Text>
744
+ <Text style={s.securityLabel}>Secured by</Text>
745
+ <Image source={{ uri: OJ_LOGO_URL }} style={s.securityLogo} resizeMode="contain" />
746
+ </View>
747
+ </View>
748
+ </View>
749
+ );
750
+ };
751
+
752
+ // -------------------------------------------------------------------------
753
+ // Render: Manage Connection (linked programs)
754
+ // -------------------------------------------------------------------------
755
+
756
+ const renderManageConnection = () => {
757
+ if (!selectedInstitution) return null;
758
+
759
+ // Find linked date from local or provider state
760
+ const localLink = linkedInstitutions.find(
761
+ (li) => li.institution_id === selectedInstitution.institution_id,
762
+ );
763
+ const linkedDate = localLink?.linked_at
764
+ ? new Date(localLink.linked_at).toLocaleDateString('en-US', {
765
+ month: 'short', day: 'numeric', year: 'numeric',
766
+ })
767
+ : 'Recently';
768
+
769
+ return (
770
+ <View style={s.flex1}>
771
+ {/* Header with status badge */}
772
+ <View style={[s.consentHeader, s.consentHeaderLinked]}>
773
+ {selectedInstitution.logo_url ? (
774
+ <Image source={{ uri: selectedInstitution.logo_url }} style={s.consentLogo} resizeMode="contain" />
775
+ ) : (
776
+ <View style={[s.consentLogoFallback, { backgroundColor: C.success }]}>
777
+ <Text style={s.consentLogoFallbackText}>
778
+ {selectedInstitution.name.charAt(0).toUpperCase()}
779
+ </Text>
780
+ </View>
781
+ )}
782
+ <Text style={s.consentBrandName}>{selectedInstitution.name}</Text>
783
+ <View style={s.connectedStatusBadge}>
784
+ <Text style={s.connectedStatusCheck}>{'\u2713'}</Text>
785
+ <Text style={s.connectedStatusText}>Connected</Text>
786
+ </View>
787
+ <Text style={s.connectedDate}>Linked {linkedDate}</Text>
788
+ </View>
789
+
790
+ {/* Data rights */}
791
+ <View style={s.consentBody}>
792
+ <Text style={s.consentPermLabel}>Data being shared</Text>
793
+ {scopes.map((scope) => (
794
+ <View key={scope.id} style={[s.consentPermRow, s.consentPermRowLinked]}>
795
+ <View style={[s.permCheckCircle, s.permCheckCircleLinked]}>
796
+ <Text style={[s.permCheckMark, s.permCheckMarkLinked]}>{'\u2713'}</Text>
797
+ </View>
798
+ <Text style={s.consentPermText}>{scope.description}</Text>
799
+ </View>
800
+ ))}
801
+ </View>
802
+
803
+ {/* Actions */}
804
+ <View style={s.consentActions}>
805
+ <Pressable
806
+ style={[s.authorizeBtn, { backgroundColor: C.primary }]}
807
+ onPress={() => {
808
+ setStep('processing');
809
+ initiateConnectForInstitution(selectedInstitution);
810
+ }}
811
+ >
812
+ <Text style={s.authorizeBtnText}>Refresh Connection</Text>
813
+ </Pressable>
814
+ <Pressable
815
+ style={[s.denyBtn, { borderColor: C.error }]}
816
+ onPress={() => {
817
+ Alert.alert(
818
+ t('account.unlink'),
819
+ t('connect.remove_confirm', { program: selectedInstitution.name }),
820
+ [
821
+ { text: t('common.cancel'), style: 'cancel' },
822
+ {
823
+ text: t('account.unlink'),
824
+ style: 'destructive',
825
+ onPress: async () => {
826
+ // Find the provider match to get partnership_id —
827
+ // partnership_id is the only reliable disconnect path.
828
+ const providerMatch = allProviderLinked.find(
829
+ (p: any) => p.brandName?.toLowerCase() === selectedInstitution.name.toLowerCase(),
830
+ ) as any;
831
+
832
+ const client = getApiClient();
833
+ if (client) {
834
+ try {
835
+ await client.post('/api/sdk/sessions/connect/disconnect', {
836
+ ...(providerMatch?.partnershipId
837
+ ? { partnership_id: providerMatch.partnershipId }
838
+ : { institution_id: selectedInstitution.institution_id }),
839
+ });
840
+ } catch (err) {
841
+ console.warn('[OuterJoyn] Disconnect API failed:', (err as Error)?.message);
842
+ }
843
+ } else {
844
+ console.warn('[OuterJoyn] Disconnect skipped — no API client available');
845
+ }
846
+
847
+ // Remove from provider state so balance UI updates
848
+ const unlinkFn = (ctx as any)?.unlinkProgram;
849
+ if (typeof unlinkFn === 'function' && providerMatch?.id) {
850
+ unlinkFn(providerMatch.id);
851
+ }
852
+
853
+ // Refresh provider balances and wait for it to settle
854
+ const refreshFn = (ctx as any)?.refreshBalances;
855
+ if (typeof refreshFn === 'function') {
856
+ try { await refreshFn(); } catch { /* non-fatal */ }
857
+ }
858
+
859
+ // Mark as disconnected so derived linked checks
860
+ // exclude it even if provider context is stale.
861
+ const disconnectedName = selectedInstitution.name.toLowerCase();
862
+ setDisconnectedNames((prev) => new Set(prev).add(disconnectedName));
863
+ setLinkedInstitutions((prev) =>
864
+ prev.filter((li) => li.institution_id !== selectedInstitution.institution_id),
865
+ );
866
+ setSelectedInstitution(null);
867
+ setStep('search');
868
+ },
869
+ },
870
+ ],
871
+ );
872
+ }}
873
+ >
874
+ <Text style={[s.denyBtnText, { color: C.error }]}>{t('account.unlink')}</Text>
875
+ </Pressable>
876
+ <Pressable style={s.denyBtn} onPress={handleBack}>
877
+ <Text style={s.denyBtnText}>Back</Text>
878
+ </Pressable>
879
+ </View>
880
+
881
+ <View style={s.securityFooter}>
882
+ <View style={s.securityRow}>
883
+ <Text style={s.securityLock}>{'\uD83D\uDD12'}</Text>
884
+ <Text style={s.securityLabel}>Secured by</Text>
885
+ <Image source={{ uri: OJ_LOGO_URL }} style={s.securityLogo} resizeMode="contain" />
886
+ </View>
887
+ </View>
888
+ </View>
889
+ );
890
+ };
891
+
892
+ // -------------------------------------------------------------------------
893
+ // Render: Processing
894
+ // -------------------------------------------------------------------------
895
+
896
+ const renderProcessing = () => (
897
+ <View style={s.centerContainer}>
898
+ <ActivityIndicator size="large" color={C.primary} />
899
+ <Text style={s.processingTitle}>{t('common.loading')}</Text>
900
+ <Text style={s.processingDesc}>
901
+ {isDemoMode
902
+ ? 'Simulating authorization...'
903
+ : 'Complete the sign-in in your browser.\nThis screen will update automatically.'}
904
+ </Text>
905
+ </View>
906
+ );
907
+
908
+ // -------------------------------------------------------------------------
909
+ // Render: Success
910
+ // -------------------------------------------------------------------------
911
+
912
+ const renderSuccess = () => (
913
+ <View style={s.centerContainer}>
914
+ <View style={s.successIconCircle}>
915
+ <Text style={s.successCheck}>{'\u2713'}</Text>
916
+ </View>
917
+ <Text style={s.successTitle}>{t('connect.success')}</Text>
918
+ <Text style={s.successDesc}>
919
+ {t('connect.success_desc', { program: selectedInstitution?.name || 'program' })}
920
+ </Text>
921
+ <Pressable style={s.doneBtn} onPress={handleClose}>
922
+ <Text style={s.doneBtnText}>{t('common.done')}</Text>
923
+ </Pressable>
924
+ </View>
925
+ );
926
+
927
+ // -------------------------------------------------------------------------
928
+ // Render: Error
929
+ // -------------------------------------------------------------------------
930
+
931
+ const renderError = () => (
932
+ <View style={s.centerContainer}>
933
+ <View style={s.errorIconCircle}>
934
+ <Text style={s.errorExclaim}>!</Text>
935
+ </View>
936
+ <Text style={s.errorTitle}>{t('common.error')}</Text>
937
+ <Text style={s.errorDesc}>{errorMessage || t('common.error')}</Text>
938
+ <Pressable style={s.retryBtn} onPress={handleBack}>
939
+ <Text style={s.retryBtnText}>{t('common.retry')}</Text>
940
+ </Pressable>
941
+ <Pressable style={s.closeBtnSecondary} onPress={handleClose}>
942
+ <Text style={s.closeBtnSecondaryText}>{t('common.close')}</Text>
943
+ </Pressable>
944
+ </View>
945
+ );
946
+
947
+ // -------------------------------------------------------------------------
948
+ // Main Render
949
+ // -------------------------------------------------------------------------
950
+
951
+ const renderContent = () => {
952
+ switch (step) {
953
+ case 'loading':
954
+ return renderLoading();
955
+ case 'search':
956
+ return renderSearch();
957
+ case 'consent':
958
+ return renderConsent();
959
+ case 'processing':
960
+ return renderProcessing();
961
+ case 'success':
962
+ return renderSuccess();
963
+ case 'error':
964
+ return renderError();
965
+ default:
966
+ return null;
967
+ }
968
+ };
969
+
970
+ return (
971
+ <Modal
972
+ visible={visible}
973
+ animationType="slide"
974
+ presentationStyle="pageSheet"
975
+ onRequestClose={handleClose}
976
+ >
977
+ <View style={s.container}>{renderContent()}</View>
978
+ </Modal>
979
+ );
980
+ };
981
+
982
+ // =============================================================================
983
+ // Styles
984
+ // =============================================================================
985
+
986
+ const s = StyleSheet.create({
987
+ container: {
988
+ flex: 1,
989
+ backgroundColor: C.bg,
990
+ },
991
+ flex1: {
992
+ flex: 1,
993
+ },
994
+
995
+ // -- Header --
996
+ header: {
997
+ flexDirection: 'row',
998
+ alignItems: 'center',
999
+ paddingHorizontal: 20,
1000
+ paddingTop: Platform.OS === 'ios' ? 56 : 16,
1001
+ paddingBottom: 12,
1002
+ borderBottomWidth: 1,
1003
+ borderBottomColor: C.border,
1004
+ backgroundColor: C.bg,
1005
+ },
1006
+ headerTitle: {
1007
+ fontSize: 18,
1008
+ fontWeight: '700',
1009
+ color: C.text,
1010
+ },
1011
+ headerSubtitle: {
1012
+ fontSize: 12,
1013
+ color: C.textSecondary,
1014
+ marginTop: 2,
1015
+ },
1016
+ closeBtn: {
1017
+ width: 36,
1018
+ height: 36,
1019
+ borderRadius: 18,
1020
+ backgroundColor: C.bgSecondary,
1021
+ alignItems: 'center',
1022
+ justifyContent: 'center',
1023
+ },
1024
+ closeBtnText: {
1025
+ fontSize: 16,
1026
+ color: C.textSecondary,
1027
+ fontWeight: '600',
1028
+ },
1029
+
1030
+ // -- Search --
1031
+ searchWrapper: {
1032
+ flexDirection: 'row',
1033
+ alignItems: 'center',
1034
+ marginHorizontal: 20,
1035
+ marginTop: 16,
1036
+ marginBottom: 12,
1037
+ paddingHorizontal: 14,
1038
+ height: 48,
1039
+ backgroundColor: '#F1F5F9',
1040
+ borderRadius: 12,
1041
+ borderWidth: 1,
1042
+ borderColor: C.border,
1043
+ },
1044
+ searchIcon: {
1045
+ fontSize: 16,
1046
+ marginRight: 10,
1047
+ color: C.textSecondary,
1048
+ },
1049
+ searchInput: {
1050
+ flex: 1,
1051
+ fontSize: 15,
1052
+ color: C.text,
1053
+ paddingVertical: 0,
1054
+ },
1055
+
1056
+ // -- Institution List --
1057
+ listContent: {
1058
+ paddingHorizontal: 20,
1059
+ paddingTop: 8,
1060
+ paddingBottom: 24,
1061
+ },
1062
+ institutionRow: {
1063
+ flexDirection: 'row',
1064
+ alignItems: 'center',
1065
+ padding: 14,
1066
+ marginBottom: 8,
1067
+ borderRadius: 12,
1068
+ borderWidth: 1,
1069
+ borderColor: C.border,
1070
+ backgroundColor: C.bg,
1071
+ },
1072
+ institutionRowLinked: {
1073
+ borderColor: `${C.success}60`,
1074
+ backgroundColor: `${C.success}06`,
1075
+ },
1076
+ institutionLogo: {
1077
+ width: 44,
1078
+ height: 44,
1079
+ borderRadius: 10,
1080
+ backgroundColor: C.bgSecondary,
1081
+ },
1082
+ institutionLogoFallback: {
1083
+ width: 44,
1084
+ height: 44,
1085
+ borderRadius: 10,
1086
+ alignItems: 'center',
1087
+ justifyContent: 'center',
1088
+ },
1089
+ logoFallbackText: {
1090
+ fontSize: 18,
1091
+ fontWeight: '700',
1092
+ color: '#ffffff',
1093
+ },
1094
+ institutionInfo: {
1095
+ flex: 1,
1096
+ marginLeft: 12,
1097
+ },
1098
+ institutionName: {
1099
+ fontSize: 15,
1100
+ fontWeight: '600',
1101
+ color: C.text,
1102
+ },
1103
+ institutionCategory: {
1104
+ fontSize: 12,
1105
+ color: C.textSecondary,
1106
+ marginTop: 2,
1107
+ },
1108
+ chevron: {
1109
+ fontSize: 22,
1110
+ color: C.textTertiary,
1111
+ fontWeight: '300',
1112
+ marginLeft: 8,
1113
+ },
1114
+ linkedBadge: {
1115
+ flexDirection: 'row',
1116
+ alignItems: 'center',
1117
+ paddingHorizontal: 8,
1118
+ paddingVertical: 4,
1119
+ borderRadius: 6,
1120
+ backgroundColor: C.successBg,
1121
+ marginLeft: 8,
1122
+ },
1123
+ linkedBadgeCheck: {
1124
+ fontSize: 10,
1125
+ color: C.success,
1126
+ fontWeight: '700',
1127
+ marginRight: 4,
1128
+ },
1129
+ linkedBadgeText: {
1130
+ fontSize: 11,
1131
+ color: C.success,
1132
+ fontWeight: '600',
1133
+ },
1134
+ emptyState: {
1135
+ alignItems: 'center',
1136
+ paddingVertical: 40,
1137
+ },
1138
+ emptyText: {
1139
+ fontSize: 14,
1140
+ color: C.textSecondary,
1141
+ },
1142
+ footer: {
1143
+ flexDirection: 'row',
1144
+ alignItems: 'center',
1145
+ justifyContent: 'center',
1146
+ gap: 6,
1147
+ paddingVertical: 16,
1148
+ opacity: 0.5,
1149
+ },
1150
+ footerText: {
1151
+ fontSize: 11,
1152
+ color: '#9CA3AF',
1153
+ },
1154
+ footerLogo: {
1155
+ width: 80,
1156
+ height: 16,
1157
+ },
1158
+
1159
+ // -- Consent --
1160
+ consentHeader: {
1161
+ alignItems: 'center',
1162
+ paddingTop: Platform.OS === 'ios' ? 56 : 24,
1163
+ paddingBottom: 20,
1164
+ paddingHorizontal: 24,
1165
+ borderBottomWidth: 1,
1166
+ borderBottomColor: C.border,
1167
+ backgroundColor: `${C.primary}08`,
1168
+ },
1169
+ consentHeaderLinked: {
1170
+ backgroundColor: `${C.success}08`,
1171
+ },
1172
+ consentLogo: {
1173
+ width: 56,
1174
+ height: 56,
1175
+ borderRadius: 14,
1176
+ backgroundColor: C.bgSecondary,
1177
+ marginBottom: 12,
1178
+ },
1179
+ consentLogoFallback: {
1180
+ width: 56,
1181
+ height: 56,
1182
+ borderRadius: 14,
1183
+ alignItems: 'center',
1184
+ justifyContent: 'center',
1185
+ marginBottom: 12,
1186
+ },
1187
+ connectedStatusBadge: {
1188
+ flexDirection: 'row',
1189
+ alignItems: 'center',
1190
+ backgroundColor: C.successBg,
1191
+ paddingHorizontal: 12,
1192
+ paddingVertical: 5,
1193
+ borderRadius: 20,
1194
+ marginTop: 4,
1195
+ marginBottom: 2,
1196
+ },
1197
+ connectedStatusCheck: {
1198
+ fontSize: 12,
1199
+ color: C.success,
1200
+ fontWeight: '700',
1201
+ marginRight: 5,
1202
+ },
1203
+ connectedStatusText: {
1204
+ fontSize: 13,
1205
+ color: C.success,
1206
+ fontWeight: '600',
1207
+ },
1208
+ connectedDate: {
1209
+ fontSize: 12,
1210
+ color: C.textSecondary,
1211
+ marginTop: 2,
1212
+ },
1213
+ consentLogoFallbackText: {
1214
+ fontSize: 24,
1215
+ fontWeight: '700',
1216
+ color: '#ffffff',
1217
+ },
1218
+ consentBrandName: {
1219
+ fontSize: 17,
1220
+ fontWeight: '700',
1221
+ color: C.text,
1222
+ marginBottom: 4,
1223
+ },
1224
+ consentTitle: {
1225
+ fontSize: 20,
1226
+ fontWeight: '800',
1227
+ color: C.navy,
1228
+ },
1229
+ consentBody: {
1230
+ paddingHorizontal: 24,
1231
+ paddingTop: 20,
1232
+ flex: 1,
1233
+ },
1234
+ consentPermLabel: {
1235
+ fontSize: 11,
1236
+ fontWeight: '700',
1237
+ color: C.textSecondary,
1238
+ textTransform: 'uppercase',
1239
+ letterSpacing: 0.5,
1240
+ marginBottom: 12,
1241
+ },
1242
+ consentPermRow: {
1243
+ flexDirection: 'row',
1244
+ alignItems: 'center',
1245
+ paddingVertical: 10,
1246
+ paddingHorizontal: 12,
1247
+ marginBottom: 6,
1248
+ borderRadius: 10,
1249
+ backgroundColor: C.bgSecondary,
1250
+ },
1251
+ consentPermRowLinked: {
1252
+ backgroundColor: C.successBg,
1253
+ },
1254
+ permCheckCircle: {
1255
+ width: 22,
1256
+ height: 22,
1257
+ borderRadius: 11,
1258
+ backgroundColor: `${C.primary}15`,
1259
+ alignItems: 'center',
1260
+ justifyContent: 'center',
1261
+ marginRight: 10,
1262
+ },
1263
+ permCheckCircleLinked: {
1264
+ backgroundColor: `${C.success}20`,
1265
+ },
1266
+ permCheckMark: {
1267
+ fontSize: 12,
1268
+ fontWeight: '700',
1269
+ color: C.primary,
1270
+ },
1271
+ permCheckMarkLinked: {
1272
+ color: C.success,
1273
+ },
1274
+ consentPermText: {
1275
+ fontSize: 14,
1276
+ color: C.text,
1277
+ },
1278
+
1279
+ // -- Consent Actions --
1280
+ consentActions: {
1281
+ paddingHorizontal: 24,
1282
+ paddingTop: 20,
1283
+ paddingBottom: 12,
1284
+ },
1285
+ authorizeBtn: {
1286
+ backgroundColor: C.success,
1287
+ paddingVertical: 14,
1288
+ borderRadius: 12,
1289
+ alignItems: 'center',
1290
+ marginBottom: 10,
1291
+ },
1292
+ reconnectBtn: {
1293
+ backgroundColor: C.primary,
1294
+ },
1295
+ authorizeBtnText: {
1296
+ color: '#ffffff',
1297
+ fontSize: 16,
1298
+ fontWeight: '700',
1299
+ },
1300
+ denyBtn: {
1301
+ paddingVertical: 12,
1302
+ borderRadius: 12,
1303
+ alignItems: 'center',
1304
+ backgroundColor: C.bgSecondary,
1305
+ borderWidth: 1,
1306
+ borderColor: C.border,
1307
+ },
1308
+ denyBtnText: {
1309
+ color: C.textSecondary,
1310
+ fontSize: 15,
1311
+ fontWeight: '500',
1312
+ },
1313
+
1314
+ // -- Security Footer --
1315
+ securityFooter: {
1316
+ alignItems: 'center',
1317
+ paddingVertical: 14,
1318
+ paddingHorizontal: 24,
1319
+ borderTopWidth: 1,
1320
+ borderTopColor: C.border,
1321
+ backgroundColor: '#f0fdf4',
1322
+ },
1323
+ securityText: {
1324
+ fontSize: 11,
1325
+ color: '#15803d',
1326
+ textAlign: 'center',
1327
+ },
1328
+ securityRow: {
1329
+ flexDirection: 'row',
1330
+ alignItems: 'center',
1331
+ gap: 5,
1332
+ },
1333
+ securityLock: {
1334
+ fontSize: 12,
1335
+ },
1336
+ securityLabel: {
1337
+ fontSize: 11,
1338
+ color: '#15803d',
1339
+ fontWeight: '500',
1340
+ },
1341
+ securityLogo: {
1342
+ width: 72,
1343
+ height: 14,
1344
+ },
1345
+
1346
+ // -- Center States (loading, processing, success, error) --
1347
+ centerContainer: {
1348
+ flex: 1,
1349
+ alignItems: 'center',
1350
+ justifyContent: 'center',
1351
+ paddingHorizontal: 32,
1352
+ },
1353
+ loadingText: {
1354
+ marginTop: 16,
1355
+ fontSize: 14,
1356
+ color: C.textSecondary,
1357
+ },
1358
+
1359
+ // Processing
1360
+ processingTitle: {
1361
+ marginTop: 20,
1362
+ fontSize: 18,
1363
+ fontWeight: '600',
1364
+ color: C.text,
1365
+ },
1366
+ processingDesc: {
1367
+ marginTop: 8,
1368
+ fontSize: 14,
1369
+ color: C.textSecondary,
1370
+ textAlign: 'center',
1371
+ lineHeight: 20,
1372
+ },
1373
+
1374
+ // Success
1375
+ successIconCircle: {
1376
+ width: 72,
1377
+ height: 72,
1378
+ borderRadius: 36,
1379
+ backgroundColor: C.successBg,
1380
+ alignItems: 'center',
1381
+ justifyContent: 'center',
1382
+ marginBottom: 20,
1383
+ },
1384
+ successCheck: {
1385
+ fontSize: 32,
1386
+ color: C.success,
1387
+ fontWeight: '700',
1388
+ },
1389
+ successTitle: {
1390
+ fontSize: 22,
1391
+ fontWeight: '700',
1392
+ color: C.text,
1393
+ marginBottom: 8,
1394
+ },
1395
+ successDesc: {
1396
+ fontSize: 15,
1397
+ color: C.textSecondary,
1398
+ textAlign: 'center',
1399
+ lineHeight: 22,
1400
+ marginBottom: 32,
1401
+ },
1402
+ doneBtn: {
1403
+ backgroundColor: C.primary,
1404
+ paddingVertical: 14,
1405
+ paddingHorizontal: 48,
1406
+ borderRadius: 12,
1407
+ alignItems: 'center',
1408
+ width: '100%',
1409
+ },
1410
+ doneBtnText: {
1411
+ color: '#ffffff',
1412
+ fontSize: 16,
1413
+ fontWeight: '700',
1414
+ },
1415
+
1416
+ // Error
1417
+ errorIconCircle: {
1418
+ width: 72,
1419
+ height: 72,
1420
+ borderRadius: 36,
1421
+ backgroundColor: C.errorBg,
1422
+ alignItems: 'center',
1423
+ justifyContent: 'center',
1424
+ marginBottom: 20,
1425
+ },
1426
+ errorExclaim: {
1427
+ fontSize: 32,
1428
+ color: C.error,
1429
+ fontWeight: '700',
1430
+ },
1431
+ errorTitle: {
1432
+ fontSize: 22,
1433
+ fontWeight: '700',
1434
+ color: C.text,
1435
+ marginBottom: 8,
1436
+ },
1437
+ errorDesc: {
1438
+ fontSize: 15,
1439
+ color: C.textSecondary,
1440
+ textAlign: 'center',
1441
+ lineHeight: 22,
1442
+ marginBottom: 32,
1443
+ },
1444
+ retryBtn: {
1445
+ backgroundColor: C.primary,
1446
+ paddingVertical: 14,
1447
+ paddingHorizontal: 48,
1448
+ borderRadius: 12,
1449
+ alignItems: 'center',
1450
+ width: '100%',
1451
+ marginBottom: 10,
1452
+ },
1453
+ retryBtnText: {
1454
+ color: '#ffffff',
1455
+ fontSize: 16,
1456
+ fontWeight: '700',
1457
+ },
1458
+ closeBtnSecondary: {
1459
+ paddingVertical: 12,
1460
+ alignItems: 'center',
1461
+ width: '100%',
1462
+ },
1463
+ closeBtnSecondaryText: {
1464
+ color: C.textSecondary,
1465
+ fontSize: 15,
1466
+ fontWeight: '500',
1467
+ },
1468
+ consentBanner: {
1469
+ flexDirection: 'row',
1470
+ alignItems: 'center',
1471
+ marginHorizontal: 16,
1472
+ marginBottom: 8,
1473
+ padding: 12,
1474
+ borderRadius: 10,
1475
+ backgroundColor: '#EFF6FF',
1476
+ borderWidth: 1,
1477
+ borderColor: '#BFDBFE',
1478
+ },
1479
+ consentBannerText: {
1480
+ flex: 1,
1481
+ fontSize: 12,
1482
+ color: '#1E40AF',
1483
+ lineHeight: 16,
1484
+ },
1485
+ consentBannerBtn: {
1486
+ marginLeft: 8,
1487
+ paddingHorizontal: 12,
1488
+ paddingVertical: 6,
1489
+ borderRadius: 6,
1490
+ backgroundColor: '#3B82F6',
1491
+ },
1492
+ consentBannerBtnText: {
1493
+ color: '#FFFFFF',
1494
+ fontSize: 12,
1495
+ fontWeight: '600',
1496
+ },
1497
+ });
1498
+
1499
+ export default ConnectScreen;