Skip to content

Commit

Permalink
chore: changed redirection for linkmode
Browse files Browse the repository at this point in the history
  • Loading branch information
ignaciosantise committed Jul 18, 2024
1 parent c4e4e88 commit 271d7e1
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion wallets/rn_cli_wallet/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
14 changes: 7 additions & 7 deletions wallets/rn_cli_wallet/src/modals/SessionAuthenticateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions wallets/rn_cli_wallet/src/modals/SessionProposalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion wallets/rn_cli_wallet/src/modals/SessionSignModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions wallets/rn_cli_wallet/src/screens/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -121,7 +123,10 @@ const App = () => {
barStyle={scheme === 'light' ? 'dark-content' : 'light-content'}
/>
<RootStackNavigator />
<Toast position="top" topOffset={Platform.select({ ios: 80, android: 0 })} />
<Toast
position="top"
topOffset={Platform.select({ios: 80, android: 0})}
/>
</NavigationContainer>
);
};
Expand Down
2 changes: 1 addition & 1 deletion wallets/rn_cli_wallet/src/screens/Connections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'>;

Expand Down Expand Up @@ -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', {
Expand Down
24 changes: 15 additions & 9 deletions wallets/rn_cli_wallet/src/utils/LinkingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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',
});
}
});
Expand All @@ -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',
});
}
};

0 comments on commit 271d7e1

Please sign in to comment.