@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.
- package/README.md +133 -0
- package/package.json +57 -0
- package/src/NativeSDK.ts +164 -0
- package/src/OuterJoynProvider.tsx +828 -0
- package/src/OuterJoynSDK.ts +261 -0
- package/src/OuterJoynSheet.tsx +218 -0
- package/src/PromotionsView.tsx +76 -0
- package/src/components/BalanceSummary.tsx +267 -0
- package/src/components/CheckoutPointsApply.tsx +787 -0
- package/src/components/LoyaltyBanner.tsx +281 -0
- package/src/components/LoyaltyProfileSection.tsx +273 -0
- package/src/components/PostCheckoutSavePrompt.tsx +369 -0
- package/src/components/index.ts +30 -0
- package/src/core/ErrorBoundary.tsx +51 -0
- package/src/core/analytics.ts +264 -0
- package/src/core/api-client.ts +253 -0
- package/src/core/colors.ts +20 -0
- package/src/core/event-stream.ts +229 -0
- package/src/core/i18n.ts +666 -0
- package/src/core/offline.ts +148 -0
- package/src/core/types.ts +214 -0
- package/src/core/version.ts +2 -0
- package/src/html.ts +154 -0
- package/src/index.ts +102 -0
- package/src/screens/AccountScreen.tsx +701 -0
- package/src/screens/ConnectScreen.tsx +1499 -0
- package/src/screens/ExchangeScreen.tsx +706 -0
- package/src/screens/RedeemScreen.tsx +683 -0
- package/src/screens/index.ts +21 -0
- package/src/types.ts +116 -0
- package/src/useOuterJoyn.ts +45 -0
- package/src/widgets.tsx +226 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExchangeScreen -- Points exchange between partner brands.
|
|
3
|
+
*
|
|
4
|
+
* State machine: amount -> confirm -> processing -> success | error
|
|
5
|
+
*
|
|
6
|
+
* Ported from the web PointsExchangeWidget with native RN UI:
|
|
7
|
+
* source/target program selectors, amount input + slider, rate preview,
|
|
8
|
+
* confirm step, processing spinner, success/error outcomes.
|
|
9
|
+
*
|
|
10
|
+
* @module @outerjoyn/react-native/screens/ExchangeScreen
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
14
|
+
import {
|
|
15
|
+
View,
|
|
16
|
+
Text,
|
|
17
|
+
Image,
|
|
18
|
+
Modal,
|
|
19
|
+
Pressable,
|
|
20
|
+
TextInput,
|
|
21
|
+
ActivityIndicator,
|
|
22
|
+
ScrollView,
|
|
23
|
+
StyleSheet,
|
|
24
|
+
FlatList,
|
|
25
|
+
} from 'react-native';
|
|
26
|
+
import Slider from '@react-native-community/slider';
|
|
27
|
+
import { useOuterJoyn } from '../useOuterJoyn';
|
|
28
|
+
import { APIClient, SDKError } from '../core/api-client';
|
|
29
|
+
import type { LinkedProgram } from '../core/types';
|
|
30
|
+
|
|
31
|
+
// =============================================================================
|
|
32
|
+
// Types
|
|
33
|
+
// =============================================================================
|
|
34
|
+
|
|
35
|
+
export interface ExchangeScreenProps {
|
|
36
|
+
/** Controls modal visibility */
|
|
37
|
+
visible: boolean;
|
|
38
|
+
/** Called after a successful exchange */
|
|
39
|
+
onSuccess?: (result: ExchangeResult) => void;
|
|
40
|
+
/** Called when user dismisses the screen */
|
|
41
|
+
onClose?: () => void;
|
|
42
|
+
/** Called on error */
|
|
43
|
+
onError?: (error: Error) => void;
|
|
44
|
+
/** Override session token (otherwise read from context) */
|
|
45
|
+
sessionToken?: string;
|
|
46
|
+
/** Override API base URL */
|
|
47
|
+
apiBaseUrl?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface ExchangeResult {
|
|
51
|
+
transactionId: string;
|
|
52
|
+
sourceAmount: number;
|
|
53
|
+
targetAmount: number;
|
|
54
|
+
sourceCurrency: string;
|
|
55
|
+
targetCurrency: string;
|
|
56
|
+
status: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface RateInfo {
|
|
60
|
+
rate: number;
|
|
61
|
+
sourceValueAmount: number;
|
|
62
|
+
targetValueAmount: number;
|
|
63
|
+
fee: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const OJ_LOGO_URL = 'https://app.outerjoyn.com/outerjoyn-logo.png';
|
|
67
|
+
|
|
68
|
+
type Step = 'amount' | 'confirm' | 'processing' | 'success' | 'error';
|
|
69
|
+
|
|
70
|
+
// =============================================================================
|
|
71
|
+
// Demo data
|
|
72
|
+
// =============================================================================
|
|
73
|
+
|
|
74
|
+
const DEMO_PROGRAMS: LinkedProgram[] = [
|
|
75
|
+
{
|
|
76
|
+
id: '1',
|
|
77
|
+
brandName: 'SkyMiles',
|
|
78
|
+
membershipId: 'SM-001',
|
|
79
|
+
pointsBalance: 25000,
|
|
80
|
+
currencyName: 'SkyMiles',
|
|
81
|
+
currencyCode: 'SKY',
|
|
82
|
+
iconColor: '#0032A0',
|
|
83
|
+
conversionRate: 1.0,
|
|
84
|
+
memberCurrencyId: 1,
|
|
85
|
+
currencyId: 101,
|
|
86
|
+
pointValueAmount: 1,
|
|
87
|
+
brandLogoUrl: null,
|
|
88
|
+
brandColor: '#0032A0',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: '2',
|
|
92
|
+
brandName: 'Glow Points',
|
|
93
|
+
membershipId: 'GP-001',
|
|
94
|
+
pointsBalance: 10000,
|
|
95
|
+
currencyName: 'Glow Points',
|
|
96
|
+
currencyCode: 'GLOW',
|
|
97
|
+
iconColor: '#E91E8C',
|
|
98
|
+
conversionRate: 0.8,
|
|
99
|
+
memberCurrencyId: 2,
|
|
100
|
+
currencyId: 102,
|
|
101
|
+
pointValueAmount: 1,
|
|
102
|
+
brandLogoUrl: null,
|
|
103
|
+
brandColor: '#E91E8C',
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
// =============================================================================
|
|
108
|
+
// Component
|
|
109
|
+
// =============================================================================
|
|
110
|
+
|
|
111
|
+
/** Points exchange screen with source/target selectors, amount input, and rate preview. */
|
|
112
|
+
export function ExchangeScreen({
|
|
113
|
+
visible,
|
|
114
|
+
onSuccess,
|
|
115
|
+
onClose,
|
|
116
|
+
onError,
|
|
117
|
+
sessionToken: propToken,
|
|
118
|
+
apiBaseUrl: propBaseUrl,
|
|
119
|
+
}: ExchangeScreenProps) {
|
|
120
|
+
// Context — use shared apiClient from provider (fix #11)
|
|
121
|
+
const ctx = useOuterJoyn();
|
|
122
|
+
const { t } = ctx;
|
|
123
|
+
const token = propToken ?? ctx.sessionToken;
|
|
124
|
+
const programs = ctx.linkedPrograms.length > 0 ? ctx.linkedPrograms : DEMO_PROGRAMS;
|
|
125
|
+
const isDemo = ctx.demoMode || programs === DEMO_PROGRAMS;
|
|
126
|
+
|
|
127
|
+
// Use shared API client from context, fall back to creating one (fix #11)
|
|
128
|
+
const clientRef = useRef<APIClient | null>(null);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (ctx.apiClient) {
|
|
131
|
+
clientRef.current = ctx.apiClient;
|
|
132
|
+
} else if (token) {
|
|
133
|
+
clientRef.current = new APIClient(token, propBaseUrl ?? ctx.apiBaseUrl ?? 'https://api.outerjoyn.com');
|
|
134
|
+
}
|
|
135
|
+
}, [token, propBaseUrl, ctx.apiClient, ctx.apiBaseUrl]);
|
|
136
|
+
|
|
137
|
+
// State
|
|
138
|
+
const [step, setStep] = useState<Step>('amount');
|
|
139
|
+
const [source, setSource] = useState<LinkedProgram | null>(null);
|
|
140
|
+
const [target, setTarget] = useState<LinkedProgram | null>(null);
|
|
141
|
+
const [amount, setAmount] = useState('');
|
|
142
|
+
const [rate, setRate] = useState<RateInfo | null>(null);
|
|
143
|
+
const [result, setResult] = useState<ExchangeResult | null>(null);
|
|
144
|
+
const [error, setError] = useState<string | null>(null);
|
|
145
|
+
const [showSourcePicker, setShowSourcePicker] = useState(false);
|
|
146
|
+
const [showTargetPicker, setShowTargetPicker] = useState(false);
|
|
147
|
+
|
|
148
|
+
// Initialize defaults
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (visible && programs.length >= 2) {
|
|
151
|
+
if (!source) setSource(programs[0]);
|
|
152
|
+
if (!target) setTarget(programs[1]);
|
|
153
|
+
}
|
|
154
|
+
}, [visible, programs]);
|
|
155
|
+
|
|
156
|
+
// Reset on close
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!visible) {
|
|
159
|
+
setStep('amount');
|
|
160
|
+
setAmount('');
|
|
161
|
+
setRate(null);
|
|
162
|
+
setResult(null);
|
|
163
|
+
setError(null);
|
|
164
|
+
}
|
|
165
|
+
}, [visible]);
|
|
166
|
+
|
|
167
|
+
// Compute rate when source/target/amount change
|
|
168
|
+
const amountNum = parseInt(amount, 10) || 0;
|
|
169
|
+
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (!source || !target || amountNum <= 0) {
|
|
172
|
+
setRate(null);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// In demo mode or when API unavailable, compute locally
|
|
176
|
+
const r = target.conversionRate / source.conversionRate;
|
|
177
|
+
const targetAmount = Math.floor(amountNum * r);
|
|
178
|
+
setRate({
|
|
179
|
+
rate: r,
|
|
180
|
+
sourceValueAmount: amountNum * source.pointValueAmount,
|
|
181
|
+
targetValueAmount: targetAmount * target.pointValueAmount,
|
|
182
|
+
fee: 0,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
if (!isDemo && clientRef.current) {
|
|
186
|
+
clientRef.current
|
|
187
|
+
.get<any>('/api/sdk/exchange/rate', {
|
|
188
|
+
source_currency_id: String(source.currencyId),
|
|
189
|
+
target_currency_id: String(target.currencyId),
|
|
190
|
+
amount: String(amountNum),
|
|
191
|
+
})
|
|
192
|
+
.then((data) => {
|
|
193
|
+
setRate({
|
|
194
|
+
rate: data.rate ?? r,
|
|
195
|
+
sourceValueAmount: data.source_value_cents ?? amountNum * source.pointValueAmount,
|
|
196
|
+
targetValueAmount: data.target_value_cents ?? targetAmount * target.pointValueAmount,
|
|
197
|
+
fee: data.fee ?? 0,
|
|
198
|
+
});
|
|
199
|
+
})
|
|
200
|
+
.catch(() => {
|
|
201
|
+
// Keep local estimate
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}, [source, target, amountNum, isDemo]);
|
|
205
|
+
|
|
206
|
+
const targetAmount = rate ? Math.floor(amountNum * rate.rate) : 0;
|
|
207
|
+
const maxAmount = source?.pointsBalance ?? 0;
|
|
208
|
+
const canProceed = amountNum > 0 && amountNum <= maxAmount && source && target && source.id !== target.id;
|
|
209
|
+
|
|
210
|
+
// Handlers
|
|
211
|
+
const handleConfirm = useCallback(() => setStep('confirm'), []);
|
|
212
|
+
|
|
213
|
+
const handleExecute = useCallback(async () => {
|
|
214
|
+
if (!source || !target) return;
|
|
215
|
+
setStep('processing');
|
|
216
|
+
try {
|
|
217
|
+
if (isDemo) {
|
|
218
|
+
// Simulate processing
|
|
219
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
220
|
+
const res: ExchangeResult = {
|
|
221
|
+
transactionId: `demo-${Date.now()}`,
|
|
222
|
+
sourceAmount: amountNum,
|
|
223
|
+
targetAmount,
|
|
224
|
+
sourceCurrency: source.currencyName,
|
|
225
|
+
targetCurrency: target.currencyName,
|
|
226
|
+
status: 'completed',
|
|
227
|
+
};
|
|
228
|
+
setResult(res);
|
|
229
|
+
setStep('success');
|
|
230
|
+
onSuccess?.(res);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Fix #8: add idempotency_key to mutation POST
|
|
235
|
+
if (!clientRef.current) {
|
|
236
|
+
throw new Error('API client not available');
|
|
237
|
+
}
|
|
238
|
+
const data = await clientRef.current.post<any>('/api/sdk/exchange', {
|
|
239
|
+
source_currency_id: source.currencyId,
|
|
240
|
+
target_currency_id: target.currencyId,
|
|
241
|
+
amount: amountNum,
|
|
242
|
+
idempotency_key: Date.now() + '_' + Math.random().toString(36).slice(2),
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const res: ExchangeResult = {
|
|
246
|
+
transactionId: data.transaction_id ?? data.id ?? '',
|
|
247
|
+
sourceAmount: amountNum,
|
|
248
|
+
targetAmount: data.target_amount ?? targetAmount,
|
|
249
|
+
sourceCurrency: source.currencyName,
|
|
250
|
+
targetCurrency: target.currencyName,
|
|
251
|
+
status: data.status ?? 'completed',
|
|
252
|
+
};
|
|
253
|
+
setResult(res);
|
|
254
|
+
setStep('success');
|
|
255
|
+
onSuccess?.(res);
|
|
256
|
+
ctx.refreshBalances();
|
|
257
|
+
} catch (e: any) {
|
|
258
|
+
setError(e.message ?? 'Exchange failed');
|
|
259
|
+
setStep('error');
|
|
260
|
+
onError?.(e);
|
|
261
|
+
}
|
|
262
|
+
}, [source, target, amountNum, targetAmount, isDemo, onSuccess, onError]);
|
|
263
|
+
|
|
264
|
+
const handleRetry = useCallback(() => {
|
|
265
|
+
setError(null);
|
|
266
|
+
setStep('amount');
|
|
267
|
+
}, []);
|
|
268
|
+
|
|
269
|
+
const handleUseMax = useCallback(() => {
|
|
270
|
+
setAmount(String(maxAmount));
|
|
271
|
+
}, [maxAmount]);
|
|
272
|
+
|
|
273
|
+
const handleSliderChange = useCallback(
|
|
274
|
+
(value: number) => {
|
|
275
|
+
setAmount(String(Math.round(value)));
|
|
276
|
+
},
|
|
277
|
+
[],
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
// Format helpers
|
|
282
|
+
const fmt = (n: number) => n.toLocaleString();
|
|
283
|
+
const fmtDollar = (cents: number) => `$${(cents / 100).toFixed(2)}`;
|
|
284
|
+
|
|
285
|
+
// Program picker
|
|
286
|
+
const renderPicker = (
|
|
287
|
+
selected: LinkedProgram | null,
|
|
288
|
+
onSelect: (p: LinkedProgram) => void,
|
|
289
|
+
exclude: string | null,
|
|
290
|
+
showPicker: boolean,
|
|
291
|
+
setShowPicker: (v: boolean) => void,
|
|
292
|
+
label: string,
|
|
293
|
+
) => (
|
|
294
|
+
<View style={styles.pickerContainer}>
|
|
295
|
+
<Text style={styles.pickerLabel}>{label}</Text>
|
|
296
|
+
<Pressable style={styles.pickerButton} onPress={() => setShowPicker(!showPicker)}>
|
|
297
|
+
{selected?.brandLogoUrl ? (
|
|
298
|
+
<Image source={{ uri: selected.brandLogoUrl }} style={{ width: 20, height: 20, borderRadius: 10, marginRight: 10 }} resizeMode="contain" />
|
|
299
|
+
) : (
|
|
300
|
+
<View style={[styles.brandDot, { backgroundColor: selected?.brandColor ?? selected?.iconColor ?? COLORS.primary }]} />
|
|
301
|
+
)}
|
|
302
|
+
<Text style={styles.pickerButtonText}>{selected?.brandName ?? 'Select program'}</Text>
|
|
303
|
+
{selected && <Text style={styles.pickerBalance}>{fmt(selected.pointsBalance)} pts</Text>}
|
|
304
|
+
<Text style={styles.chevron}>{showPicker ? '\u25B2' : '\u25BC'}</Text>
|
|
305
|
+
</Pressable>
|
|
306
|
+
{showPicker && (
|
|
307
|
+
<View style={styles.pickerDropdown}>
|
|
308
|
+
{programs
|
|
309
|
+
.filter((p) => p.id !== exclude)
|
|
310
|
+
.map((p) => (
|
|
311
|
+
<Pressable
|
|
312
|
+
key={p.id}
|
|
313
|
+
style={styles.pickerItem}
|
|
314
|
+
onPress={() => {
|
|
315
|
+
onSelect(p);
|
|
316
|
+
setShowPicker(false);
|
|
317
|
+
}}
|
|
318
|
+
>
|
|
319
|
+
{p.brandLogoUrl ? (
|
|
320
|
+
<Image source={{ uri: p.brandLogoUrl }} style={{ width: 20, height: 20, borderRadius: 10, marginRight: 10 }} resizeMode="contain" />
|
|
321
|
+
) : (
|
|
322
|
+
<View style={[styles.brandDot, { backgroundColor: p.brandColor ?? p.iconColor ?? COLORS.primary }]} />
|
|
323
|
+
)}
|
|
324
|
+
<Text style={styles.pickerItemText}>{p.brandName}</Text>
|
|
325
|
+
<Text style={styles.pickerItemBalance}>{fmt(p.pointsBalance)}</Text>
|
|
326
|
+
</Pressable>
|
|
327
|
+
))}
|
|
328
|
+
</View>
|
|
329
|
+
)}
|
|
330
|
+
</View>
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
// =========================================================================
|
|
334
|
+
// Render steps
|
|
335
|
+
// =========================================================================
|
|
336
|
+
|
|
337
|
+
const renderAmount = () => (
|
|
338
|
+
<ScrollView style={styles.content} keyboardShouldPersistTaps="handled">
|
|
339
|
+
{/* Source */}
|
|
340
|
+
{renderPicker(source, setSource, target?.id ?? null, showSourcePicker, setShowSourcePicker, t('exchange.from'))}
|
|
341
|
+
|
|
342
|
+
{/* Arrow */}
|
|
343
|
+
<View style={styles.arrowContainer}>
|
|
344
|
+
<Text style={styles.arrow}>{'\u2193'}</Text>
|
|
345
|
+
</View>
|
|
346
|
+
|
|
347
|
+
{/* Target */}
|
|
348
|
+
{renderPicker(target, setTarget, source?.id ?? null, showTargetPicker, setShowTargetPicker, t('exchange.to'))}
|
|
349
|
+
|
|
350
|
+
{/* Amount */}
|
|
351
|
+
<View style={styles.amountSection}>
|
|
352
|
+
<Text style={styles.amountLabel}>Amount</Text>
|
|
353
|
+
<View style={styles.amountRow}>
|
|
354
|
+
<TextInput
|
|
355
|
+
style={styles.amountInput}
|
|
356
|
+
keyboardType="number-pad"
|
|
357
|
+
placeholder="0"
|
|
358
|
+
placeholderTextColor={COLORS.muted}
|
|
359
|
+
value={amount}
|
|
360
|
+
onChangeText={(v) => setAmount(v.replace(/[^0-9]/g, ''))}
|
|
361
|
+
/>
|
|
362
|
+
<Pressable style={styles.maxButton} onPress={handleUseMax}>
|
|
363
|
+
<Text style={styles.maxButtonText}>{t('pay.use_max')}</Text>
|
|
364
|
+
</Pressable>
|
|
365
|
+
</View>
|
|
366
|
+
|
|
367
|
+
{/* Slider */}
|
|
368
|
+
{maxAmount > 0 && (
|
|
369
|
+
<View style={styles.sliderContainer}>
|
|
370
|
+
<Slider
|
|
371
|
+
style={styles.slider}
|
|
372
|
+
minimumValue={0}
|
|
373
|
+
maximumValue={maxAmount}
|
|
374
|
+
step={Math.max(1, Math.floor(maxAmount / 100))}
|
|
375
|
+
value={amountNum}
|
|
376
|
+
onValueChange={(val: number) => handleSliderChange(val)}
|
|
377
|
+
minimumTrackTintColor={source?.brandColor ?? source?.iconColor ?? COLORS.primary}
|
|
378
|
+
maximumTrackTintColor="#E5E7EB"
|
|
379
|
+
thumbTintColor={source?.brandColor ?? source?.iconColor ?? COLORS.primary}
|
|
380
|
+
/>
|
|
381
|
+
<View style={styles.sliderLabels}>
|
|
382
|
+
<Text style={styles.sliderLabel}>0</Text>
|
|
383
|
+
<Text style={styles.sliderLabel}>{fmt(maxAmount)}</Text>
|
|
384
|
+
</View>
|
|
385
|
+
</View>
|
|
386
|
+
)}
|
|
387
|
+
</View>
|
|
388
|
+
|
|
389
|
+
{/* Rate preview */}
|
|
390
|
+
{rate && amountNum > 0 && source && target && (
|
|
391
|
+
<View style={styles.ratePreview}>
|
|
392
|
+
<Text style={styles.rateText}>
|
|
393
|
+
{fmt(amountNum)} {source.currencyName} {'\u2192'} {fmt(targetAmount)} {target.currencyName}
|
|
394
|
+
</Text>
|
|
395
|
+
<Text style={styles.rateSubtext}>
|
|
396
|
+
{rate.rate.toFixed(2)}x rate {'\u00B7'} {fmtDollar(rate.sourceValueAmount)} {'\u2192'} {fmtDollar(rate.targetValueAmount)}
|
|
397
|
+
</Text>
|
|
398
|
+
</View>
|
|
399
|
+
)}
|
|
400
|
+
|
|
401
|
+
{/* Confirm button */}
|
|
402
|
+
<Pressable
|
|
403
|
+
style={[styles.primaryButton, !canProceed && styles.disabledButton]}
|
|
404
|
+
disabled={!canProceed}
|
|
405
|
+
onPress={handleConfirm}
|
|
406
|
+
>
|
|
407
|
+
<Text style={styles.primaryButtonText}>{t('exchange.confirm')}</Text>
|
|
408
|
+
</Pressable>
|
|
409
|
+
</ScrollView>
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
const renderConfirm = () => (
|
|
413
|
+
<View style={styles.content}>
|
|
414
|
+
<Text style={styles.stepTitle}>{t('exchange.confirm')}</Text>
|
|
415
|
+
|
|
416
|
+
<View style={styles.confirmCard}>
|
|
417
|
+
<Text style={styles.confirmLabel}>{t('exchange.from')}</Text>
|
|
418
|
+
<Text style={styles.confirmValue}>
|
|
419
|
+
{fmt(amountNum)} {source?.currencyName}
|
|
420
|
+
</Text>
|
|
421
|
+
<Text style={styles.confirmDollar}>{fmtDollar(rate?.sourceValueAmount ?? 0)}</Text>
|
|
422
|
+
</View>
|
|
423
|
+
|
|
424
|
+
<View style={styles.arrowContainer}>
|
|
425
|
+
<Text style={styles.arrow}>{'\u2193'}</Text>
|
|
426
|
+
</View>
|
|
427
|
+
|
|
428
|
+
<View style={styles.confirmCard}>
|
|
429
|
+
<Text style={styles.confirmLabel}>{t('exchange.to')}</Text>
|
|
430
|
+
<Text style={styles.confirmValue}>
|
|
431
|
+
{fmt(targetAmount)} {target?.currencyName}
|
|
432
|
+
</Text>
|
|
433
|
+
<Text style={styles.confirmDollar}>{fmtDollar(rate?.targetValueAmount ?? 0)}</Text>
|
|
434
|
+
</View>
|
|
435
|
+
|
|
436
|
+
<Pressable style={styles.primaryButton} onPress={handleExecute}>
|
|
437
|
+
<Text style={styles.primaryButtonText}>{t('exchange.confirm')}</Text>
|
|
438
|
+
</Pressable>
|
|
439
|
+
<Pressable style={styles.secondaryButton} onPress={() => setStep('amount')}>
|
|
440
|
+
<Text style={styles.secondaryButtonText}>{t('common.cancel')}</Text>
|
|
441
|
+
</Pressable>
|
|
442
|
+
</View>
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
const renderProcessing = () => (
|
|
446
|
+
<View style={styles.centeredContent}>
|
|
447
|
+
<ActivityIndicator size="large" color={COLORS.primary} />
|
|
448
|
+
<Text style={styles.processingText}>{t('common.loading')}</Text>
|
|
449
|
+
</View>
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
const renderSuccess = () => (
|
|
453
|
+
<View style={styles.centeredContent}>
|
|
454
|
+
<View style={styles.checkCircle}>
|
|
455
|
+
<Text style={styles.checkMark}>{'\u2713'}</Text>
|
|
456
|
+
</View>
|
|
457
|
+
<Text style={styles.successTitle}>{t('exchange.success')}</Text>
|
|
458
|
+
<Text style={styles.successDetail}>
|
|
459
|
+
{fmt(result?.sourceAmount ?? 0)} {result?.sourceCurrency} {'\u2192'}{' '}
|
|
460
|
+
{fmt(result?.targetAmount ?? 0)} {result?.targetCurrency}
|
|
461
|
+
</Text>
|
|
462
|
+
<Pressable style={styles.primaryButton} onPress={onClose}>
|
|
463
|
+
<Text style={styles.primaryButtonText}>{t('common.done')}</Text>
|
|
464
|
+
</Pressable>
|
|
465
|
+
</View>
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
const renderError = () => (
|
|
469
|
+
<View style={styles.centeredContent}>
|
|
470
|
+
<View style={styles.errorCircle}>
|
|
471
|
+
<Text style={styles.errorMark}>!</Text>
|
|
472
|
+
</View>
|
|
473
|
+
<Text style={styles.errorTitle}>{t('common.error')}</Text>
|
|
474
|
+
<Text style={styles.errorDetail}>{error ?? t('common.error')}</Text>
|
|
475
|
+
<Pressable style={styles.primaryButton} onPress={handleRetry}>
|
|
476
|
+
<Text style={styles.primaryButtonText}>{t('common.retry')}</Text>
|
|
477
|
+
</Pressable>
|
|
478
|
+
<Pressable style={styles.secondaryButton} onPress={onClose}>
|
|
479
|
+
<Text style={styles.secondaryButtonText}>{t('common.close')}</Text>
|
|
480
|
+
</Pressable>
|
|
481
|
+
</View>
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
const stepMap: Record<Step, () => React.ReactNode> = {
|
|
485
|
+
amount: renderAmount,
|
|
486
|
+
confirm: renderConfirm,
|
|
487
|
+
processing: renderProcessing,
|
|
488
|
+
success: renderSuccess,
|
|
489
|
+
error: renderError,
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
return (
|
|
493
|
+
<Modal visible={visible} animationType="slide" presentationStyle="pageSheet" onRequestClose={onClose}>
|
|
494
|
+
<View style={styles.container}>
|
|
495
|
+
{/* Header */}
|
|
496
|
+
<View style={styles.header}>
|
|
497
|
+
<Text style={styles.headerTitle}>{t('exchange.title')}</Text>
|
|
498
|
+
<Pressable onPress={onClose} hitSlop={12}>
|
|
499
|
+
<Text style={styles.closeButton}>{'\u2715'}</Text>
|
|
500
|
+
</Pressable>
|
|
501
|
+
</View>
|
|
502
|
+
|
|
503
|
+
{stepMap[step]()}
|
|
504
|
+
|
|
505
|
+
{/* Footer */}
|
|
506
|
+
<View style={styles.poweredByRow}>
|
|
507
|
+
<Text style={styles.poweredByText}>Powered by</Text>
|
|
508
|
+
<Image
|
|
509
|
+
source={{ uri: OJ_LOGO_URL }}
|
|
510
|
+
style={styles.poweredByLogo}
|
|
511
|
+
resizeMode="contain"
|
|
512
|
+
/>
|
|
513
|
+
</View>
|
|
514
|
+
</View>
|
|
515
|
+
</Modal>
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// =============================================================================
|
|
520
|
+
// Colors
|
|
521
|
+
// =============================================================================
|
|
522
|
+
|
|
523
|
+
const COLORS = {
|
|
524
|
+
primary: '#0c90eb',
|
|
525
|
+
navy: '#0D1B4C',
|
|
526
|
+
accent: '#3B82F6',
|
|
527
|
+
bg: '#FFFFFF',
|
|
528
|
+
surface: '#F8FAFC',
|
|
529
|
+
border: '#E2E8F0',
|
|
530
|
+
text: '#0F172A',
|
|
531
|
+
muted: '#94A3B8',
|
|
532
|
+
success: '#10B981',
|
|
533
|
+
error: '#EF4444',
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
// =============================================================================
|
|
537
|
+
// Styles
|
|
538
|
+
// =============================================================================
|
|
539
|
+
|
|
540
|
+
const styles = StyleSheet.create({
|
|
541
|
+
container: { flex: 1, backgroundColor: COLORS.bg },
|
|
542
|
+
header: {
|
|
543
|
+
flexDirection: 'row',
|
|
544
|
+
justifyContent: 'space-between',
|
|
545
|
+
alignItems: 'center',
|
|
546
|
+
paddingHorizontal: 20,
|
|
547
|
+
paddingVertical: 16,
|
|
548
|
+
borderBottomWidth: 1,
|
|
549
|
+
borderBottomColor: COLORS.border,
|
|
550
|
+
backgroundColor: COLORS.navy,
|
|
551
|
+
},
|
|
552
|
+
headerTitle: { fontSize: 18, fontWeight: '700', color: '#FFFFFF' },
|
|
553
|
+
closeButton: { fontSize: 20, color: '#FFFFFF', fontWeight: '600' },
|
|
554
|
+
content: { flex: 1, padding: 20 },
|
|
555
|
+
centeredContent: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20 },
|
|
556
|
+
poweredByRow: {
|
|
557
|
+
flexDirection: 'row',
|
|
558
|
+
alignItems: 'center',
|
|
559
|
+
justifyContent: 'center',
|
|
560
|
+
gap: 6,
|
|
561
|
+
paddingVertical: 16,
|
|
562
|
+
opacity: 0.5,
|
|
563
|
+
borderTopWidth: 1,
|
|
564
|
+
borderTopColor: COLORS.border,
|
|
565
|
+
},
|
|
566
|
+
poweredByText: { fontSize: 11, color: '#9CA3AF' },
|
|
567
|
+
poweredByLogo: { width: 80, height: 16 },
|
|
568
|
+
|
|
569
|
+
// Picker
|
|
570
|
+
pickerContainer: { marginBottom: 8 },
|
|
571
|
+
pickerLabel: { fontSize: 13, fontWeight: '600', color: COLORS.muted, marginBottom: 6, textTransform: 'uppercase' },
|
|
572
|
+
pickerButton: {
|
|
573
|
+
flexDirection: 'row',
|
|
574
|
+
alignItems: 'center',
|
|
575
|
+
borderWidth: 1,
|
|
576
|
+
borderColor: COLORS.border,
|
|
577
|
+
borderRadius: 12,
|
|
578
|
+
padding: 14,
|
|
579
|
+
backgroundColor: COLORS.surface,
|
|
580
|
+
},
|
|
581
|
+
brandDot: { width: 10, height: 10, borderRadius: 5, marginRight: 10 },
|
|
582
|
+
pickerButtonText: { flex: 1, fontSize: 16, fontWeight: '600', color: COLORS.text },
|
|
583
|
+
pickerBalance: { fontSize: 14, color: COLORS.muted, marginRight: 8 },
|
|
584
|
+
chevron: { fontSize: 10, color: COLORS.muted },
|
|
585
|
+
pickerDropdown: {
|
|
586
|
+
marginTop: 4,
|
|
587
|
+
borderWidth: 1,
|
|
588
|
+
borderColor: COLORS.border,
|
|
589
|
+
borderRadius: 10,
|
|
590
|
+
backgroundColor: COLORS.bg,
|
|
591
|
+
overflow: 'hidden',
|
|
592
|
+
},
|
|
593
|
+
pickerItem: {
|
|
594
|
+
flexDirection: 'row',
|
|
595
|
+
alignItems: 'center',
|
|
596
|
+
padding: 14,
|
|
597
|
+
borderBottomWidth: 1,
|
|
598
|
+
borderBottomColor: COLORS.border,
|
|
599
|
+
},
|
|
600
|
+
pickerItemText: { flex: 1, fontSize: 15, color: COLORS.text },
|
|
601
|
+
pickerItemBalance: { fontSize: 14, color: COLORS.muted },
|
|
602
|
+
|
|
603
|
+
// Arrow
|
|
604
|
+
arrowContainer: { alignItems: 'center', paddingVertical: 6 },
|
|
605
|
+
arrow: { fontSize: 24, color: COLORS.primary, fontWeight: '700' },
|
|
606
|
+
|
|
607
|
+
// Amount
|
|
608
|
+
amountSection: { marginTop: 16 },
|
|
609
|
+
amountLabel: { fontSize: 13, fontWeight: '600', color: COLORS.muted, textTransform: 'uppercase', marginBottom: 6 },
|
|
610
|
+
amountRow: { flexDirection: 'row', alignItems: 'center' },
|
|
611
|
+
amountInput: {
|
|
612
|
+
flex: 1,
|
|
613
|
+
borderWidth: 1,
|
|
614
|
+
borderColor: COLORS.border,
|
|
615
|
+
borderRadius: 12,
|
|
616
|
+
padding: 14,
|
|
617
|
+
fontSize: 20,
|
|
618
|
+
fontWeight: '700',
|
|
619
|
+
color: COLORS.text,
|
|
620
|
+
backgroundColor: COLORS.surface,
|
|
621
|
+
},
|
|
622
|
+
maxButton: {
|
|
623
|
+
marginLeft: 10,
|
|
624
|
+
paddingHorizontal: 16,
|
|
625
|
+
paddingVertical: 14,
|
|
626
|
+
borderRadius: 12,
|
|
627
|
+
backgroundColor: COLORS.primary + '18',
|
|
628
|
+
},
|
|
629
|
+
maxButtonText: { fontSize: 14, fontWeight: '700', color: COLORS.primary },
|
|
630
|
+
|
|
631
|
+
// Slider
|
|
632
|
+
sliderContainer: { marginTop: 12 },
|
|
633
|
+
slider: { width: '100%', height: 36 },
|
|
634
|
+
sliderLabels: { flexDirection: 'row', justifyContent: 'space-between', marginTop: 2 },
|
|
635
|
+
sliderLabel: { fontSize: 12, color: COLORS.muted },
|
|
636
|
+
|
|
637
|
+
// Rate preview
|
|
638
|
+
ratePreview: {
|
|
639
|
+
marginTop: 20,
|
|
640
|
+
padding: 14,
|
|
641
|
+
borderRadius: 12,
|
|
642
|
+
backgroundColor: COLORS.primary + '0D',
|
|
643
|
+
borderWidth: 1,
|
|
644
|
+
borderColor: COLORS.primary + '33',
|
|
645
|
+
},
|
|
646
|
+
rateText: { fontSize: 15, fontWeight: '600', color: COLORS.text },
|
|
647
|
+
rateSubtext: { fontSize: 13, color: COLORS.muted, marginTop: 4 },
|
|
648
|
+
|
|
649
|
+
// Buttons
|
|
650
|
+
primaryButton: {
|
|
651
|
+
marginTop: 24,
|
|
652
|
+
paddingVertical: 16,
|
|
653
|
+
borderRadius: 14,
|
|
654
|
+
backgroundColor: COLORS.primary,
|
|
655
|
+
alignItems: 'center',
|
|
656
|
+
},
|
|
657
|
+
primaryButtonText: { fontSize: 16, fontWeight: '700', color: '#FFFFFF' },
|
|
658
|
+
disabledButton: { opacity: 0.4 },
|
|
659
|
+
secondaryButton: { marginTop: 12, paddingVertical: 14, alignItems: 'center' },
|
|
660
|
+
secondaryButtonText: { fontSize: 15, fontWeight: '600', color: COLORS.muted },
|
|
661
|
+
|
|
662
|
+
// Confirm
|
|
663
|
+
stepTitle: { fontSize: 20, fontWeight: '700', color: COLORS.text, marginBottom: 20, textAlign: 'center' },
|
|
664
|
+
confirmCard: {
|
|
665
|
+
padding: 16,
|
|
666
|
+
borderRadius: 12,
|
|
667
|
+
backgroundColor: COLORS.surface,
|
|
668
|
+
borderWidth: 1,
|
|
669
|
+
borderColor: COLORS.border,
|
|
670
|
+
alignItems: 'center',
|
|
671
|
+
},
|
|
672
|
+
confirmLabel: { fontSize: 13, color: COLORS.muted, marginBottom: 4 },
|
|
673
|
+
confirmValue: { fontSize: 22, fontWeight: '700', color: COLORS.text },
|
|
674
|
+
confirmDollar: { fontSize: 14, color: COLORS.muted, marginTop: 2 },
|
|
675
|
+
|
|
676
|
+
// Processing
|
|
677
|
+
processingText: { fontSize: 16, color: COLORS.muted, marginTop: 16 },
|
|
678
|
+
|
|
679
|
+
// Success
|
|
680
|
+
checkCircle: {
|
|
681
|
+
width: 64,
|
|
682
|
+
height: 64,
|
|
683
|
+
borderRadius: 32,
|
|
684
|
+
backgroundColor: COLORS.success + '1A',
|
|
685
|
+
justifyContent: 'center',
|
|
686
|
+
alignItems: 'center',
|
|
687
|
+
marginBottom: 16,
|
|
688
|
+
},
|
|
689
|
+
checkMark: { fontSize: 32, color: COLORS.success, fontWeight: '700' },
|
|
690
|
+
successTitle: { fontSize: 22, fontWeight: '700', color: COLORS.text, marginBottom: 8 },
|
|
691
|
+
successDetail: { fontSize: 15, color: COLORS.muted, textAlign: 'center' },
|
|
692
|
+
|
|
693
|
+
// Error
|
|
694
|
+
errorCircle: {
|
|
695
|
+
width: 64,
|
|
696
|
+
height: 64,
|
|
697
|
+
borderRadius: 32,
|
|
698
|
+
backgroundColor: COLORS.error + '1A',
|
|
699
|
+
justifyContent: 'center',
|
|
700
|
+
alignItems: 'center',
|
|
701
|
+
marginBottom: 16,
|
|
702
|
+
},
|
|
703
|
+
errorMark: { fontSize: 32, color: COLORS.error, fontWeight: '700' },
|
|
704
|
+
errorTitle: { fontSize: 22, fontWeight: '700', color: COLORS.text, marginBottom: 8 },
|
|
705
|
+
errorDetail: { fontSize: 15, color: COLORS.muted, textAlign: 'center', marginBottom: 8 },
|
|
706
|
+
});
|