From 63faa74e2caa5527b7cdbcbfaabdd7e8e85944b5 Mon Sep 17 00:00:00 2001 From: shreerang6921 <68148922+shreerang6921@users.noreply.github.com> Date: Fri, 15 Mar 2024 13:50:57 +0530 Subject: [PATCH] Remove any type (#57) * Remove any type for requestEvent parameter * Handle review changes --- App.tsx | 3 ++- components/PairingModal.tsx | 2 +- components/SignRequest.tsx | 14 ++++++++++---- types.ts | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/App.tsx b/App.tsx index f90af3b..a9becb0 100644 --- a/App.tsx +++ b/App.tsx @@ -9,6 +9,7 @@ import { NativeStackNavigationProp, createNativeStackNavigator, } from '@react-navigation/native-stack'; +import { Web3WalletTypes } from '@walletconnect/web3wallet'; import SignMessage from './components/SignMessage'; import HomeScreen from './components/HomeScreen'; @@ -47,7 +48,7 @@ const App = (): React.JSX.Element => { ); const onSessionRequest = useCallback( - async (requestEvent: SignClientTypes.EventArguments['session_request']) => { + async (requestEvent: Web3WalletTypes.SessionRequest) => { const { topic, params } = requestEvent; const { request } = params; diff --git a/components/PairingModal.tsx b/components/PairingModal.tsx index b44959f..0248486 100644 --- a/components/PairingModal.tsx +++ b/components/PairingModal.tsx @@ -124,7 +124,7 @@ const PairingModal = ({ } const namespaceAccounts: string[] = []; - requiredNamespaces[key].chains!.map((chain: any) => { + requiredNamespaces[key].chains!.map((chain: string) => { currentAddresses.map(acc => namespaceAccounts.push(`${chain}:${acc}`), ); diff --git a/components/SignRequest.tsx b/components/SignRequest.tsx index bf5f7fe..b37efd9 100644 --- a/components/SignRequest.tsx +++ b/components/SignRequest.tsx @@ -39,11 +39,13 @@ const SignRequest = ({ route }: SignRequestProps) => { useNavigation>(); const isCosmosSignDirect = useMemo(() => { - const requestParams = route.params!.requestEvent - ? route.params!.requestEvent.params.request - : {}; + const requestParams = route.params!.requestEvent; - return requestParams.method === 'cosmos_signDirect'; + if (!requestParams) { + return false; + } + + return requestParams.params.request.method === 'cosmos_signDirect'; }, [route.params]); const retrieveData = async ( @@ -116,6 +118,10 @@ const SignRequest = ({ route }: SignRequestProps) => { throw new Error('account not found'); } + if (!requestEvent) { + throw new Error('Request event not found'); + } + const response = await approveWalletConnectRequest( requestEvent, account, diff --git a/types.ts b/types.ts index edbc1b4..998cb40 100644 --- a/types.ts +++ b/types.ts @@ -1,4 +1,5 @@ import { SignClientTypes, SessionTypes } from '@walletconnect/types'; +import { Web3WalletTypes } from '@walletconnect/web3wallet'; export type StackParamsList = { Laconic: undefined; @@ -8,8 +9,7 @@ export type StackParamsList = { network: string; address: string; message: string; - // TODO: remove any - requestEvent?: any; + requestEvent?: Web3WalletTypes.SessionRequest; requestSession?: any; } | undefined;