Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-bags-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": minor
---

prevent retry button from redirecting to wallet page in receive flow
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from "react";
import { View } from "react-native";

const ReanimatedSwipeable = ({ children, renderRightActions, ...props }) => {
return <View {...props}>{children}</View>;
};
const ReanimatedSwipeable = React.forwardRef(({ children, renderRightActions, ...props }, ref) => {
return (
<View ref={ref} {...props}>
{children}
</View>
);
});

ReanimatedSwipeable.displayName = "ReanimatedSwipeable";

export default ReanimatedSwipeable;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type AddAccountContextType = `${AddAccountContexts}`;
type CommonParams = {
context?: AddAccountContextType;
onCloseNavigation?: () => void;
// Number of navigators to pop when closing the flow (calculated at entry point)
navigationDepth?: number;
currency: CryptoOrTokenCurrency;
sourceScreenName?: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function ScanDeviceAccounts() {
onModalHide,
onPressAccount,
quitFlow,
restartSubscription,
handleRetry,
scannedAccounts,
scanning,
sections,
Expand Down Expand Up @@ -187,7 +187,7 @@ function ScanDeviceAccounts() {
(!scanning && scannedAccounts.length === 0)
}
canDone={!scanning && cantCreateAccount && noImportableAccounts}
onRetry={restartSubscription}
onRetry={handleRetry}
onStop={stopSubscription}
onDone={quitFlow}
onContinue={importAccounts}
Expand All @@ -201,10 +201,10 @@ function ScanDeviceAccounts() {
onModalHide={onModalHide}
footerButtons={
<>
<CancelButton containerStyle={styles.button} onPress={onCancel} />
<CancelButton containerStyle={styles.button} onPress={onCancel} outline />
<RetryButton
containerStyle={[styles.button, styles.buttonRight]}
onPress={restartSubscription}
onPress={handleRetry}
/>
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function useScanDeviceAccountsViewModel({
const [onlyNewAccounts, setOnlyNewAccounts] = useState(true);
const [showAllCreatedAccounts, setShowAllCreatedAccounts] = useState(false);
const [selectedIds, setSelectedIds] = useState<string[]>([]);
const [cancelled, setCancelled] = useState(false);
const cancelledRef = useRef(false);
const scanSubscription = useRef<Subscription | null>(null);
const [isAddingAccounts, setIsAddinAccounts] = useState<boolean>(false);
const dispatch = useDispatch();
Expand All @@ -58,6 +58,7 @@ export default function useScanDeviceAccountsViewModel({
inline,
returnToSwap,
onCloseNavigation,
navigationDepth,
context,
} = route.params || {};

Expand Down Expand Up @@ -103,14 +104,27 @@ export default function useScanDeviceAccountsViewModel({
},
});
}, [blacklistedTokenIds, currency, deviceId]);

const restartSubscription = useCallback(() => {
setScanning(true);
setScannedAccounts([]);
setSelectedIds([]);
setError(null);
setCancelled(false);
cancelledRef.current = false;
startSubscription();
}, [startSubscription]);

const handleRetry = useCallback(() => {
// In inline flows (e.g., Receive), navigate back to device selection
// to allow user to reconnect/unlock device instead of retrying on same screen
if (inline && error) {
// Simply go back to SelectDevice which is already in the stack
navigation.goBack();
return;
}

restartSubscription();
}, [inline, error, navigation, restartSubscription]);
const stopSubscription = useCallback(
(syncUI = true) => {
if (scanSubscription.current) {
Expand Down Expand Up @@ -169,6 +183,16 @@ export default function useScanDeviceAccountsViewModel({
},
[selectedIds],
);

// Close inline flow: drawer + navigation
const closeInlineFlow = useCallback(() => {
if (onCloseNavigation) {
onCloseNavigation();
}
const parent = navigation.getParent<StackNavigatorNavigation<BaseNavigatorStackParamList>>();
parent?.pop(navigationDepth ?? 2);
}, [navigation, onCloseNavigation, navigationDepth]);

const importAccounts = useCallback(() => {
const accountsToAdd = scannedAccounts.filter(a => selectedIds.includes(a.id));
if (currency.id.includes("canton_network")) {
Expand All @@ -191,7 +215,8 @@ export default function useScanDeviceAccountsViewModel({
const { onSuccess } = route.params;

if (inline) {
navigation.goBack();
closeInlineFlow();

if (onSuccess) {
onSuccess({
scannedAccounts,
Expand Down Expand Up @@ -227,19 +252,27 @@ export default function useScanDeviceAccountsViewModel({
scannedAccounts,
selectedIds,
dispatch,
closeInlineFlow,
analyticsMetadata?.AccountsFound?.onContinue,
analyticsMetadata?.AccountsFound?.onAccountsAdded,
]);

const onCancel = useCallback(() => {
setError(null);
setCancelled(true);
cancelledRef.current = true;
}, []);

const onModalHide = useCallback(() => {
if (cancelled) {
navigation.getParent<StackNavigatorNavigation<BaseNavigatorStackParamList>>().pop();
// Use ref to avoid stale closure issue with cancelled state
if (cancelledRef.current) {
if (inline) {
closeInlineFlow();
} else {
navigation.getParent<StackNavigatorNavigation<BaseNavigatorStackParamList>>()?.pop();
}
}
}, [cancelled, navigation]);
}, [inline, closeInlineFlow, navigation]);

const viewAllCreatedAccounts = useCallback(() => setShowAllCreatedAccounts(true), []);

const onAccountNameChange = useCallback(
Expand Down Expand Up @@ -350,7 +383,7 @@ export default function useScanDeviceAccountsViewModel({
onModalHide,
onPressAccount,
quitFlow,
restartSubscription,
handleRetry,
scannedAccounts,
scanning,
sections: sanitizedSections,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,20 @@ export default function useSelectDeviceViewModel(
(meta: AppResult) => {
setDevice(null);

const { inline } = route.params;
const params = {
...route.params,
...meta,
context,
sourceScreenName: ScreenName.SelectDevice,
};
if (inline) {
navigation.replace(NavigatorName.AddAccounts, {
screen: ScreenName.ScanDeviceAccounts,
params,
});
} else
navigation.navigate(NavigatorName.AddAccounts, {
screen: ScreenName.ScanDeviceAccounts,
params,
});

// Always use navigate instead of replace to keep SelectDevice in the stack.
// This allows retry navigation when device errors occur (e.g., device locked).
// Previously, inline flows used replace which prevented retry navigation.
navigation.navigate(NavigatorName.AddAccounts, {
screen: ScreenName.ScanDeviceAccounts,
params,
});
},
[navigation, route, context],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type CommonParams = {
context?: AddAccountContextType;
onSuccess?: (res?: { scannedAccounts: Account[]; selected: Account[] }) => void;
onCloseNavigation?: () => void;
navigationDepth?: number;
sourceScreenName?: string;
};

Expand Down
Loading
Loading