Skip to content

Commit

Permalink
Fix: Automatic WC redirect back to browser is broken on iOS 17 (#5127)
Browse files Browse the repository at this point in the history
* add WALLET_CONNECT_REDIRECT_SHEET navigation on connection

* fix: lint picked up merging filepaths together issue

* fix ios 16 regression

* revert: pbx file

* revert: pbx file

* revert: pbx file

* sign

* fix: guard minimizer.goBack functionality to Android only

* fix: sign window not closing and not showing sign txn redirect sheet
  • Loading branch information
walmat authored Oct 20, 2023
1 parent 9edef6b commit 2cf2600
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/redux/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface RequestData {
sessionRequestEvent: SignClientTypes.EventArguments['session_request'];
address: string;
chainId: number;
onComplete(): void;
onComplete(type: string): void;
};
}

Expand Down
20 changes: 12 additions & 8 deletions src/redux/walletconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Routes from '@/navigation/routesNames';
import { ethereumUtils, watchingAlert } from '@/utils';
import { getFCMToken } from '@/notifications/tokens';
import { logger, RainbowError } from '@/logger';
import { IS_DEV, IS_TEST } from '@/env';
import { IS_DEV, IS_IOS, IS_TEST } from '@/env';
import { RainbowNetworks } from '@/networks';

// -- Variables --------------------------------------- //
Expand Down Expand Up @@ -261,15 +261,19 @@ export const walletConnectRemovePendingRedirect = (
} else if (type !== 'timedOut') {
if (type === 'sign' || type === 'transaction') {
showRedirectSheetThreshold += BIOMETRICS_ANIMATION_DELAY;
setTimeout(() => {
Minimizer.goBack();
}, BIOMETRICS_ANIMATION_DELAY);
if (!IS_IOS) {
setTimeout(() => {
Minimizer.goBack();
}, BIOMETRICS_ANIMATION_DELAY);
}
} else if (type === 'sign-canceled' || type === 'transaction-canceled') {
setTimeout(() => {
Minimizer.goBack();
}, 300);
if (!IS_IOS) {
setTimeout(() => {
Minimizer.goBack();
}, 300);
}
} else {
!IS_TEST && Minimizer.goBack();
!IS_TEST && !IS_IOS && Minimizer.goBack();
}
// If it's still active after showRedirectSheetThreshold
// We need to show the redirect sheet cause the redirect
Expand Down
15 changes: 9 additions & 6 deletions src/screens/TransactionConfirmationScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import { handleSessionRequestResponse } from '@/walletConnect';
import { isAddress } from '@ethersproject/address';
import { logger, RainbowError } from '@/logger';
import { getNetworkObj } from '@/networks';
import { IS_IOS } from '@/env';

const springConfig = {
damping: 500,
Expand Down Expand Up @@ -419,20 +420,21 @@ export default function TransactionConfirmationScreen() {
if (!isMessageRequest) {
stopPollingGasFees();
}

let type = method === SEND_TRANSACTION ? 'transaction' : 'sign';
if (canceled) {
type = `${type}-canceled`;
}

if (pendingRedirect) {
InteractionManager.runAfterInteractions(() => {
let type = method === SEND_TRANSACTION ? 'transaction' : 'sign';

if (canceled) {
type = `${type}-canceled`;
}
dispatch(walletConnectRemovePendingRedirect(type, dappScheme));
});
}

if (walletConnectV2RequestValues?.onComplete) {
InteractionManager.runAfterInteractions(() => {
walletConnectV2RequestValues.onComplete();
walletConnectV2RequestValues.onComplete(type);
});
}
},
Expand Down Expand Up @@ -819,6 +821,7 @@ export default function TransactionConfirmationScreen() {
}
dispatch(removeRequest(requestId));
}

closeScreen(false);
// When the tx is sent from a different wallet,
// we need to switch to that wallet before saving the tx
Expand Down
8 changes: 7 additions & 1 deletion src/screens/WalletConnectApprovalSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { AssetType } from '@/entities';
import { RainbowNetworks, getNetworkObj } from '@/networks';
import { handleReviewPromptAction } from '@/utils/reviewAlert';
import { ReviewPromptAction } from '@/storage/schema';
import { IS_IOS } from '@/env';

const LoadingSpinner = styled(android ? Spinner : ActivityIndicator).attrs(
({ theme: { colors } }) => ({
Expand Down Expand Up @@ -355,12 +356,17 @@ export default function WalletConnectApprovalSheet() {
const handleConnect = useCallback(() => {
handled.current = true;
goBack();
if (IS_IOS) {
navigate(Routes.WALLET_CONNECT_REDIRECT_SHEET, {
type: 'connect',
});
}
handleSuccess(true);

setTimeout(() => {
handleReviewPromptAction(ReviewPromptAction.DappConnections);
}, 500);
}, [handleSuccess, goBack]);
}, [handleSuccess, goBack, navigate]);

const handleCancel = useCallback(() => {
handled.current = true;
Expand Down
15 changes: 12 additions & 3 deletions src/walletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
import { saveLocalRequests } from '@/handlers/localstorage/walletconnectRequests';
import { events } from '@/handlers/appEvents';
import { getFCMToken } from '@/notifications/tokens';
import { IS_DEV, IS_ANDROID } from '@/env';
import { IS_DEV, IS_ANDROID, IS_IOS } from '@/env';
import { loadWallet } from '@/model/wallet';
import * as portal from '@/screens/Portal';
import * as explain from '@/screens/Explain';
Expand Down Expand Up @@ -93,7 +93,10 @@ export function maybeGoBackAndClearHasPendingRedirect({
InteractionManager.runAfterInteractions(() => {
setTimeout(() => {
setHasPendingDeeplinkPendingRedirect(false);
Minimizer.goBack();

if (!IS_IOS) {
Minimizer.goBack();
}
}, delay);
});
}
Expand Down Expand Up @@ -774,7 +777,13 @@ export async function onSessionRequest(
// @ts-ignore we assign address above
address, // required by screen
chainId, // required by screen
onComplete() {
onComplete(type: string) {
if (IS_IOS) {
Navigation.handleAction(Routes.WALLET_CONNECT_REDIRECT_SHEET, {
type,
});
}

maybeGoBackAndClearHasPendingRedirect({ delay: 300 });
},
},
Expand Down

0 comments on commit 2cf2600

Please sign in to comment.