Skip to content

Commit

Permalink
fix: go back behavior on wallet connect session deny
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-mazz committed Mar 14, 2024
1 parent 0bf7b0a commit 8d758d5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/hooks/uriactions/useHandleUriAction.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {
GenericActionUri,
GenericActionsTypes,
GenericActionUri,
SendTokensActionUri,
UriAction,
UriActionType,
Expand Down Expand Up @@ -121,7 +121,7 @@ const useHandleWalletConnectPairAction = () => {
text: t('initializing new session'),
});
const pairResult = await pair(action.uri);
hideModal();
hideModal(true);
if (pairResult.isErr()) {
showModal(ErrorModal, {
text: pairResult.error.message,
Expand Down
23 changes: 14 additions & 9 deletions src/hooks/useReturnToCurrentScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ const useReturnToCurrentScreen = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return useCallback(() => {
const canNavigate =
startingScreenNavigateParams !== undefined &&
navigator.getState().routes.find((r) => r.key === startingScreenNavigateParams.key) !==
undefined;
if (canNavigate) {
navigator.navigate(startingScreenNavigateParams);
}
}, [navigator, startingScreenNavigateParams]);
return useCallback(
(fallbackToGoBack?: boolean) => {
const canNavigate =
startingScreenNavigateParams !== undefined &&
navigator.getState().routes.find((r) => r.key === startingScreenNavigateParams.key) !==
undefined;
if (canNavigate) {
navigator.navigate(startingScreenNavigateParams);
} else if (fallbackToGoBack) {
navigator.goBack();
}
},
[navigator, startingScreenNavigateParams],
);
};

export default useReturnToCurrentScreen;
27 changes: 16 additions & 11 deletions src/screens/WalletConnectSessionProposal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { DPMImages } from 'types/images';
import { walletConnectIconUriToImageSource } from 'lib/WalletConnectUtils';
import FastImage from 'react-native-fast-image';
import useResetToHomeScreen from 'hooks/navigation/useResetToHomeScreen';
import useOnBackAction from 'hooks/useOnBackAction';
import useStyles from './useStyles';

export interface WalletConnectSessionProposalParams {
Expand Down Expand Up @@ -79,16 +80,20 @@ const WalletConnectSessionProposal: FC<NavProps> = (props) => {
[openModal, t],
);

const onDeny = useCallback(async () => {
setRejecting(true);
const rejectResult = await rejectSession(proposal);
if (rejectResult.isOk()) {
navigation.goBack();
} else {
showErrorModal(rejectResult.error.message);
}
setRejecting(false);
}, [navigation, proposal, rejectSession, showErrorModal]);
const onDeny = useCallback(
async (noNavigation?: boolean) => {
setRejecting(true);
await rejectSession(proposal);
if (noNavigation !== true) {
navigation.goBack();
}
setRejecting(false);
},
[navigation, proposal, rejectSession],
);
useOnBackAction(() => {
onDeny(true);
}, [onDeny]);

const onGrant = useCallback(async () => {
setAuthorizing(true);
Expand Down Expand Up @@ -128,7 +133,7 @@ const WalletConnectSessionProposal: FC<NavProps> = (props) => {
<Button
style={styles.denyButton}
mode="contained"
onPress={onDeny}
onPress={() => onDeny()}
accent
loading={rejecting}
disabled={authorizing || rejecting}
Expand Down

0 comments on commit 8d758d5

Please sign in to comment.