Skip to content

Commit 479f678

Browse files
committed
fix: OrderDetails hydration fallback and remove debug instrumentation
- Pass providerCode and walletAddress from BuildQuote to OrderDetails so it can fetch the order from the API when not yet in state - Add hydration effect in OrderDetails that calls refreshOrder when order is missing but fallback params are available - Show loading spinner and error states during hydration - Remove all debug instrumentation (rampsDebugLog) from BuildQuote, OrderDetails, and Checkout Made-with: Cursor
1 parent 93003e7 commit 479f678

File tree

3 files changed

+82
-133
lines changed

3 files changed

+82
-133
lines changed

app/components/UI/Ramp/Views/BuildQuote/BuildQuote.tsx

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ import TruncatedError from '../../components/TruncatedError';
6767
import { PROVIDER_LINKS } from '../../Aggregator/types';
6868
import InAppBrowser from 'react-native-inappbrowser-reborn';
6969
import Device from '../../../../../util/device';
70-
import { rampsDebugLog } from '../../debug/rampsDebugLogger';
71-
7270
export interface BuildQuoteParams {
7371
assetId?: string;
7472
nativeFlowError?: string;
@@ -527,18 +525,6 @@ function BuildQuote() {
527525
);
528526
const providerCode = normalizeProviderCode(selectedQuote.provider);
529527

530-
// #region agent log
531-
rampsDebugLog({
532-
location: 'BuildQuote.tsx:handleContinuePress',
533-
message: 'handleContinuePress START',
534-
data: {
535-
providerCode,
536-
isCustomAction,
537-
hasBuyURL: Boolean(selectedQuote.quote?.buyURL),
538-
},
539-
});
540-
// #endregion
541-
542528
// TODO: remove all [Ramp][Debug] logging after PayPal redirect is verified
543529
Logger.log('[Ramp][Debug] === handleContinuePress START ===');
544530
Logger.log('[Ramp][Debug] provider:', selectedQuote.provider);
@@ -587,18 +573,6 @@ function BuildQuote() {
587573

588574
Logger.log('[Ramp][Debug] calling getBuyWidgetData...');
589575
const buyWidget = await getBuyWidgetData(quoteForWidget);
590-
// #region agent log
591-
rampsDebugLog({
592-
location: 'BuildQuote.tsx:getBuyWidgetData',
593-
message: 'getBuyWidgetData result',
594-
data: {
595-
hasUrl: Boolean(buyWidget?.url),
596-
url: buyWidget?.url?.slice(0, 80),
597-
browser: buyWidget?.browser,
598-
orderId: buyWidget?.orderId,
599-
},
600-
});
601-
// #endregion
602576
Logger.log(
603577
'[Ramp][Debug] getBuyWidgetData result:',
604578
JSON.stringify(buyWidget),
@@ -625,18 +599,6 @@ function BuildQuote() {
625599
Logger.log('[Ramp][Debug] effectiveWallet:', effectiveWallet);
626600

627601
if (effectiveOrderId && effectiveWallet) {
628-
// #region agent log
629-
rampsDebugLog({
630-
location: 'BuildQuote.tsx:addPrecreatedOrder',
631-
message: 'addPrecreatedOrder before external browser',
632-
data: {
633-
orderId: effectiveOrderId,
634-
providerCode,
635-
walletAddress: effectiveWallet,
636-
chainId: network,
637-
},
638-
});
639-
// #endregion
640602
Logger.log('[Ramp][Debug] calling addPrecreatedOrder...');
641603
addPrecreatedOrder({
642604
orderId: effectiveOrderId,
@@ -670,17 +632,6 @@ function BuildQuote() {
670632
buyWidget.url,
671633
deeplinkRedirectUrl,
672634
);
673-
// #region agent log
674-
rampsDebugLog({
675-
location: 'BuildQuote.tsx:InAppBrowser.openAuth',
676-
message: 'InAppBrowser returned',
677-
data: {
678-
resultType: result.type,
679-
hasUrl: Boolean(result.url),
680-
url: result.url?.slice(0, 100),
681-
},
682-
});
683-
// #endregion
684635
Logger.log(
685636
'[Ramp][Debug] InAppBrowser result:',
686637
JSON.stringify(result),
@@ -703,13 +654,6 @@ function BuildQuote() {
703654
const orderCode = effectiveOrderId.includes('/orders/')
704655
? effectiveOrderId.split('/orders/')[1]
705656
: effectiveOrderId;
706-
// #region agent log
707-
rampsDebugLog({
708-
location: 'BuildQuote.tsx:navigateToOrderDetails',
709-
message: 'navigating to RAMPS_ORDER_DETAILS after PayPal return',
710-
data: { orderCode, effectiveOrderId },
711-
});
712-
// #endregion
713657
Logger.log(
714658
'[Ramp][Debug] navigating to RAMPS_ORDER_DETAILS with orderCode:',
715659
orderCode,
@@ -725,6 +669,8 @@ function BuildQuote() {
725669
params: {
726670
orderId: orderCode,
727671
showCloseButton: true,
672+
providerCode,
673+
walletAddress: effectiveWallet || undefined,
728674
},
729675
},
730676
],

app/components/UI/Ramp/Views/Checkout/Checkout.tsx

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ import {
4343
getCheckoutCallback,
4444
removeCheckoutCallback,
4545
} from '../../utils/checkoutCallbackRegistry';
46-
import { rampsDebugLog } from '../../debug/rampsDebugLogger';
47-
4846
interface CheckoutParams {
4947
url: string;
5048
providerName: string;
@@ -176,18 +174,6 @@ const Checkout = () => {
176174
const canRegister =
177175
effectiveOrderId && providerCode && walletAddress && network;
178176
if (!canRegister) return;
179-
// #region agent log
180-
rampsDebugLog({
181-
location: 'Checkout.tsx:addPrecreatedOrder',
182-
message: 'addPrecreatedOrder (WebView flow)',
183-
data: {
184-
orderId: effectiveOrderId,
185-
providerCode,
186-
walletAddress,
187-
network,
188-
},
189-
});
190-
// #endregion
191177
addPrecreatedOrder({
192178
orderId: effectiveOrderId,
193179
providerCode: normalizeProviderCode(providerCode),
@@ -214,18 +200,6 @@ const Checkout = () => {
214200
}
215201
isRedirectionHandledRef.current = true;
216202

217-
// #region agent log
218-
rampsDebugLog({
219-
location: 'Checkout.tsx:handleNavigationStateChange',
220-
message: 'callback URL detected',
221-
data: {
222-
url: navState.url?.slice(0, 120),
223-
providerCode,
224-
walletAddress,
225-
},
226-
});
227-
// #endregion
228-
229203
try {
230204
const parsedUrl = parseUrl(navState.url);
231205
if (Object.keys(parsedUrl.query).length === 0) {
@@ -244,18 +218,6 @@ const Checkout = () => {
244218
walletAddress,
245219
);
246220

247-
// #region agent log
248-
rampsDebugLog({
249-
location: 'Checkout.tsx:getOrderFromCallback',
250-
message: 'getOrderFromCallback result',
251-
data: {
252-
hasOrder: Boolean(rampsOrder),
253-
providerOrderId: rampsOrder?.providerOrderId,
254-
status: rampsOrder?.status,
255-
},
256-
});
257-
// #endregion
258-
259221
if (!rampsOrder) {
260222
throw new Error('Order could not be retrieved from callback');
261223
}

app/components/UI/Ramp/Views/OrderDetails/OrderDetails.tsx

Lines changed: 80 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ import { useRampsOrders } from '../../hooks/useRampsOrders';
3535
import { useAnalytics } from '../../../../hooks/useAnalytics/useAnalytics';
3636
import { MetaMetricsEvents } from '../../../../../core/Analytics';
3737
import { RampsOrderDetailsSelectorsIDs } from './OrderDetails.testIds';
38-
import { rampsDebugLog } from '../../debug/rampsDebugLogger';
39-
4038
interface RampsOrderDetailsParams {
4139
orderId: string;
4240
showCloseButton?: boolean;
41+
/** Optional: needed when order is not yet in controller state (e.g. race after PayPal return). */
42+
providerCode?: string;
43+
/** Optional: needed with providerCode to fetch order from API when not in state. */
44+
walletAddress?: string;
4345
}
4446

4547
export const createRampsOrderDetailsNavDetails =
@@ -74,23 +76,9 @@ const OrderDetails = () => {
7476
const order = getOrderById(params.orderId);
7577
const isPending = order ? PENDING_STATUSES.has(order.status) : false;
7678

77-
// #region agent log
78-
useEffect(() => {
79-
rampsDebugLog({
80-
location: 'OrderDetails.tsx:mount',
81-
message: 'OrderDetails mounted',
82-
data: {
83-
orderId: params.orderId,
84-
hasOrder: Boolean(order),
85-
status: order?.status,
86-
isPending,
87-
},
88-
});
89-
}, [params.orderId, order, isPending]);
90-
// #endregion
91-
9279
const [isLoading, setIsLoading] = useState(isPending);
9380
const [error, setError] = useState<string | null>(null);
81+
const [hydrationAttempted, setHydrationAttempted] = useState(false);
9482
const theme = useTheme();
9583
const { colors } = theme;
9684
const navigation = useNavigation();
@@ -139,32 +127,11 @@ const OrderDetails = () => {
139127
setError(null);
140128
setIsRefreshing(true);
141129
const providerCode = normalizeProviderCode(order.provider?.id ?? '');
142-
// #region agent log
143-
rampsDebugLog({
144-
location: 'OrderDetails.tsx:handleOnRefresh',
145-
message: 'refreshing order',
146-
data: {
147-
providerOrderId: order.providerOrderId,
148-
providerCode,
149-
currentStatus: order.status,
150-
},
151-
});
152-
// #endregion
153-
const updatedOrder = await refreshOrder(
130+
await refreshOrder(
154131
providerCode,
155132
order.providerOrderId,
156133
order.walletAddress,
157134
);
158-
// #region agent log
159-
rampsDebugLog({
160-
location: 'OrderDetails.tsx:handleOnRefresh',
161-
message: 'refresh complete',
162-
data: {
163-
providerOrderId: order.providerOrderId,
164-
newStatus: updatedOrder?.status,
165-
},
166-
});
167-
// #endregion
168135
} catch (fetchError) {
169136
Logger.error(fetchError as Error, {
170137
message: 'FiatOrders::RampsOrderDetails error while refreshing order',
@@ -190,7 +157,81 @@ const OrderDetails = () => {
190157
// eslint-disable-next-line react-hooks/exhaustive-deps
191158
}, []);
192159

160+
// When order is missing but we have providerCode/wallet (e.g. race after PayPal return),
161+
// fetch from API to hydrate controller state.
162+
useEffect(() => {
163+
if (
164+
order ||
165+
hydrationAttempted ||
166+
!params.providerCode ||
167+
!params.walletAddress ||
168+
!params.orderId
169+
) {
170+
return;
171+
}
172+
setHydrationAttempted(true);
173+
setIsLoading(true);
174+
const providerCode = normalizeProviderCode(params.providerCode);
175+
refreshOrder(providerCode, params.orderId, params.walletAddress)
176+
.then(() => {
177+
setIsLoading(false);
178+
})
179+
.catch((err) => {
180+
setError(
181+
err instanceof Error
182+
? err.message
183+
: strings('ramps_order_details.error_message'),
184+
);
185+
setIsLoading(false);
186+
});
187+
}, [
188+
order,
189+
hydrationAttempted,
190+
params.providerCode,
191+
params.walletAddress,
192+
params.orderId,
193+
refreshOrder,
194+
]);
195+
193196
if (!order) {
197+
if (isLoading) {
198+
return (
199+
<ScreenLayout>
200+
<ScreenLayout.Body>
201+
<ScreenLayout.Content>
202+
<ActivityIndicator />
203+
</ScreenLayout.Content>
204+
</ScreenLayout.Body>
205+
</ScreenLayout>
206+
);
207+
}
208+
if (error && hydrationAttempted) {
209+
return (
210+
<ScreenLayout>
211+
<ScreenLayout.Body>
212+
<Box twClassName="flex-1 items-center justify-center px-16 py-16">
213+
<Icon
214+
name={IconName.Danger}
215+
size={IconSize.Xl}
216+
twClassName="text-error-default mb-2"
217+
/>
218+
<Text
219+
variant={TextVariant.HeadingSm}
220+
fontWeight={FontWeight.Bold}
221+
>
222+
{strings('ramps_order_details.error_title')}
223+
</Text>
224+
<Text
225+
variant={TextVariant.BodyMd}
226+
twClassName="text-alternative text-center mb-8"
227+
>
228+
{error}
229+
</Text>
230+
</Box>
231+
</ScreenLayout.Body>
232+
</ScreenLayout>
233+
);
234+
}
194235
return <ScreenLayout />;
195236
}
196237

0 commit comments

Comments
 (0)