From 271d7e17110672a160de71a468da1b26b2f12e4a Mon Sep 17 00:00:00 2001
From: ignaciosantise <25931366+ignaciosantise@users.noreply.github.com>
Date: Thu, 18 Jul 2024 14:41:52 -0300
Subject: [PATCH] chore: changed redirection for linkmode
---
.../rn_cli_wallet/android/app/build.gradle | 2 +-
.../src/modals/SessionAuthenticateModal.tsx | 14 +++++------
.../src/modals/SessionProposalModal.tsx | 13 +++++-----
.../modals/SessionSendTransactionModal.tsx | 6 ++++-
.../src/modals/SessionSignModal.tsx | 6 ++++-
.../src/modals/SessionSignTypedDataModal.tsx | 6 ++++-
wallets/rn_cli_wallet/src/screens/App.tsx | 11 ++++++---
.../src/screens/Connections/index.tsx | 2 +-
.../rn_cli_wallet/src/utils/LinkingUtils.ts | 24 ++++++++++++-------
9 files changed, 53 insertions(+), 31 deletions(-)
diff --git a/wallets/rn_cli_wallet/android/app/build.gradle b/wallets/rn_cli_wallet/android/app/build.gradle
index dd23191f..d5a74c34 100644
--- a/wallets/rn_cli_wallet/android/app/build.gradle
+++ b/wallets/rn_cli_wallet/android/app/build.gradle
@@ -87,7 +87,7 @@ android {
applicationId "com.walletconnect.web3wallet.rnsample"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
- versionCode 24
+ versionCode 25
versionName "1.0"
resValue "string", "build_config_package", "com.walletconnect.web3wallet.rnsample"
}
diff --git a/wallets/rn_cli_wallet/src/modals/SessionAuthenticateModal.tsx b/wallets/rn_cli_wallet/src/modals/SessionAuthenticateModal.tsx
index a9614247..2ee669b6 100644
--- a/wallets/rn_cli_wallet/src/modals/SessionAuthenticateModal.tsx
+++ b/wallets/rn_cli_wallet/src/modals/SessionAuthenticateModal.tsx
@@ -22,9 +22,9 @@ import {Message} from '@/components/Modal/Message';
export default function SessionAuthenticateModal() {
const Theme = useTheme();
- const data = useSnapshot(ModalStore.state);
- const authRequest = data?.data
- ?.authRequest as SignClientTypes.EventArguments['session_authenticate'];
+ const {data} = useSnapshot(ModalStore.state);
+ const authRequest =
+ data?.authRequest as SignClientTypes.EventArguments['session_authenticate'];
const {account} = useSnapshot(SettingsStore.state);
const [messages, setMessages] = useState<
@@ -81,10 +81,10 @@ export default function SessionAuthenticateModal() {
Object.values(web3wallet.getActiveSessions()),
);
- handleRedirect(
- authRequest.params.requester?.metadata?.redirect,
- web3wallet.metadata.redirect,
- );
+ handleRedirect({
+ peerRedirect: authRequest.params.requester?.metadata?.redirect,
+ isLinkMode: SettingsStore.state.isCurrentRequestLinkMode,
+ });
} catch (e) {
console.log((e as Error).message, 'error');
return;
diff --git a/wallets/rn_cli_wallet/src/modals/SessionProposalModal.tsx b/wallets/rn_cli_wallet/src/modals/SessionProposalModal.tsx
index eb3f63aa..4142c630 100644
--- a/wallets/rn_cli_wallet/src/modals/SessionProposalModal.tsx
+++ b/wallets/rn_cli_wallet/src/modals/SessionProposalModal.tsx
@@ -23,9 +23,9 @@ import {RequestModal} from './RequestModal';
export default function SessionProposalModal() {
const Theme = useTheme();
// Get proposal data and wallet address from store
- const data = useSnapshot(ModalStore.state);
- const proposal = data?.data
- ?.proposal as SignClientTypes.EventArguments['session_proposal'];
+ const {data} = useSnapshot(ModalStore.state);
+ const proposal =
+ data?.proposal as SignClientTypes.EventArguments['session_proposal'];
const [isLoadingApprove, setIsLoadingApprove] = useState(false);
const [isLoadingReject, setIsLoadingReject] = useState(false);
@@ -109,10 +109,9 @@ export default function SessionProposalModal() {
Object.values(web3wallet.getActiveSessions()),
);
- handleRedirect(
- session.peer.metadata.redirect,
- web3wallet.metadata.redirect,
- );
+ handleRedirect({
+ peerRedirect: session.peer.metadata.redirect,
+ });
} catch (e) {
console.log((e as Error).message, 'error');
return;
diff --git a/wallets/rn_cli_wallet/src/modals/SessionSendTransactionModal.tsx b/wallets/rn_cli_wallet/src/modals/SessionSendTransactionModal.tsx
index b5a67650..f6357cc7 100644
--- a/wallets/rn_cli_wallet/src/modals/SessionSendTransactionModal.tsx
+++ b/wallets/rn_cli_wallet/src/modals/SessionSendTransactionModal.tsx
@@ -15,6 +15,7 @@ import ModalStore from '@/store/ModalStore';
import {RequestModal} from '@/modals/RequestModal';
import {Chains} from '@/components/Modal/Chains';
import {PresetsUtil} from '@/utils/PresetsUtil';
+import SettingsStore from '@/store/SettingsStore';
export default function SessionSendTransactionModal() {
const {data} = useSnapshot(ModalStore.state);
@@ -45,7 +46,10 @@ export default function SessionSendTransactionModal() {
topic,
response,
});
- handleRedirect(peerMetadata?.redirect, web3wallet.metadata.redirect);
+ handleRedirect({
+ peerRedirect: peerMetadata?.redirect,
+ isLinkMode: SettingsStore.state.isCurrentRequestLinkMode,
+ });
} catch (e) {
console.log((e as Error).message, 'error');
return;
diff --git a/wallets/rn_cli_wallet/src/modals/SessionSignModal.tsx b/wallets/rn_cli_wallet/src/modals/SessionSignModal.tsx
index 63f282e2..0ace6bbb 100644
--- a/wallets/rn_cli_wallet/src/modals/SessionSignModal.tsx
+++ b/wallets/rn_cli_wallet/src/modals/SessionSignModal.tsx
@@ -16,6 +16,7 @@ import ModalStore from '@/store/ModalStore';
import {RequestModal} from './RequestModal';
import {Chains} from '@/components/Modal/Chains';
import {PresetsUtil} from '@/utils/PresetsUtil';
+import SettingsStore from '@/store/SettingsStore';
export default function SessionSignModal() {
// Get request and wallet data from store
@@ -46,7 +47,10 @@ export default function SessionSignModal() {
response,
});
- handleRedirect(peerMetadata?.redirect, web3wallet.metadata.redirect);
+ handleRedirect({
+ peerRedirect: peerMetadata?.redirect,
+ isLinkMode: SettingsStore.state.isCurrentRequestLinkMode,
+ });
} catch (e) {
console.log((e as Error).message, 'error');
return;
diff --git a/wallets/rn_cli_wallet/src/modals/SessionSignTypedDataModal.tsx b/wallets/rn_cli_wallet/src/modals/SessionSignTypedDataModal.tsx
index 13777040..60a2275e 100644
--- a/wallets/rn_cli_wallet/src/modals/SessionSignTypedDataModal.tsx
+++ b/wallets/rn_cli_wallet/src/modals/SessionSignTypedDataModal.tsx
@@ -16,6 +16,7 @@ import ModalStore from '@/store/ModalStore';
import {RequestModal} from './RequestModal';
import {Chains} from '@/components/Modal/Chains';
import {PresetsUtil} from '@/utils/PresetsUtil';
+import SettingsStore from '@/store/SettingsStore';
export default function SessionSignTypedDataModal() {
// Get request and wallet data from store
@@ -45,7 +46,10 @@ export default function SessionSignTypedDataModal() {
topic,
response,
});
- handleRedirect(peerMetadata?.redirect, web3wallet.metadata.redirect);
+ handleRedirect({
+ peerRedirect: peerMetadata?.redirect,
+ isLinkMode: SettingsStore.state.isCurrentRequestLinkMode,
+ });
} catch (e) {
console.log((e as Error).message, 'error');
return;
diff --git a/wallets/rn_cli_wallet/src/screens/App.tsx b/wallets/rn_cli_wallet/src/screens/App.tsx
index 5a55fd49..70a6887c 100644
--- a/wallets/rn_cli_wallet/src/screens/App.tsx
+++ b/wallets/rn_cli_wallet/src/screens/App.tsx
@@ -73,9 +73,11 @@ const App = () => {
const deeplinkHandler = useCallback(
({url}: {url: string}) => {
- if (url.includes('wc_ev')) {
+ const isLinkMode = url.includes('wc_ev');
+ SettingsStore.setCurrentRequestLinkMode(isLinkMode);
+
+ if (isLinkMode) {
ModalStore.open('LoadingModal', {loadingMessage: 'Loading request...'});
- SettingsStore.setCurrentRequestLinkMode(true);
} else if (url.includes('wc?uri=')) {
const uri = url.split('wc?uri=')[1];
pair(decodeURIComponent(uri));
@@ -121,7 +123,10 @@ const App = () => {
barStyle={scheme === 'light' ? 'dark-content' : 'light-content'}
/>
-
+
);
};
diff --git a/wallets/rn_cli_wallet/src/screens/Connections/index.tsx b/wallets/rn_cli_wallet/src/screens/Connections/index.tsx
index d791ad72..d98c3883 100644
--- a/wallets/rn_cli_wallet/src/screens/Connections/index.tsx
+++ b/wallets/rn_cli_wallet/src/screens/Connections/index.tsx
@@ -7,7 +7,6 @@ import {CopyURIDialog} from '@/components/CopyURIDialog';
import {ConnectionsStackScreenProps} from '@/utils/TypesUtil';
import ModalStore from '@/store/ModalStore';
import SettingsStore from '@/store/SettingsStore';
-import { useSnapshot } from 'valtio';
type Props = ConnectionsStackScreenProps<'Connections'>;
@@ -35,6 +34,7 @@ export default function Connections({route}: Props) {
try {
setCopyDialogVisible(false);
+ SettingsStore.setCurrentRequestLinkMode(false);
await web3wallet.pair({uri});
} catch (error: any) {
ModalStore.open('LoadingModal', {
diff --git a/wallets/rn_cli_wallet/src/utils/LinkingUtils.ts b/wallets/rn_cli_wallet/src/utils/LinkingUtils.ts
index b9c2a0b5..b010b365 100644
--- a/wallets/rn_cli_wallet/src/utils/LinkingUtils.ts
+++ b/wallets/rn_cli_wallet/src/utils/LinkingUtils.ts
@@ -7,15 +7,18 @@ interface redirect {
linkMode?: boolean;
}
-export const handleRedirect = (
- peerRedirect?: redirect,
- selfRedirect?: redirect,
-) => {
+interface Props {
+ peerRedirect?: redirect;
+ isLinkMode?: boolean;
+}
+
+export const handleRedirect = ({peerRedirect, isLinkMode}: Props) => {
try {
- if (peerRedirect?.linkMode && selfRedirect?.linkMode) {
+ if (isLinkMode) {
Toast.show({
type: 'success',
- text1: 'Redirecting to the dapp...',
+ text1: 'Success!',
+ text2: 'Redirecting to the dapp...',
});
return;
}
@@ -28,7 +31,8 @@ export const handleRedirect = (
} else {
Toast.show({
type: 'success',
- text1: 'Go back to the dapp',
+ text1: 'Success!',
+ text2: 'Please go back to the dapp',
});
}
});
@@ -37,14 +41,16 @@ export const handleRedirect = (
} else {
Toast.show({
type: 'success',
- text1: 'Go back to the dapp',
+ text1: 'Success!',
+ text2: 'Please go back to the dapp',
});
}
} catch (error) {
console.log(error);
Toast.show({
type: 'success',
- text1: 'Go back to the dapp',
+ text1: 'Success!',
+ text2: 'Please go back to the dapp',
});
}
};