From b3fe51ab1dc2b6c987d3bc17eed075d2e8bf4d19 Mon Sep 17 00:00:00 2001 From: Iuri Pereira <689440+iuricmp@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:04:19 +0100 Subject: [PATCH] chore: posting with gnokey key --- mobile/app/post/index.tsx | 29 +++++++-------------------- mobile/redux/features/linkingSlice.ts | 8 +------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/mobile/app/post/index.tsx b/mobile/app/post/index.tsx index f23e2e1..5f0b354 100644 --- a/mobile/app/post/index.tsx +++ b/mobile/app/post/index.tsx @@ -7,7 +7,6 @@ import { Stack, useNavigation, useRouter } from "expo-router"; import { useEffect, useState } from "react"; import { KeyboardAvoidingView, Platform } from "react-native"; import { broadcastTxCommit, hasParam, makeCallTxAndRedirect, selectAccount, selectQueryParams, selectQueryParamsAddress, useAppDispatch, useAppSelector } from "@gno/redux"; -import * as Linking from 'expo-linking'; export default function Search() { const [postContent, setPostContent] = useState(""); @@ -19,13 +18,11 @@ export default function Search() { const dispatch = useAppDispatch(); const account = useAppSelector(selectAccount); - // address from the url to be used in the makeCallTx - const bech32 = useAppSelector(selectQueryParamsAddress); - const queryParams = useAppSelector(selectQueryParams); + // hook to handle the signed tx from the Gnokey and broadcast it useEffect(() => { - if ( queryParams && hasParam("tx", queryParams)) { + if (queryParams && hasParam("tx", queryParams)) { const signedTx = decodeURIComponent(queryParams.tx as string) console.log("signedTx: ", signedTx); @@ -40,19 +37,9 @@ export default function Search() { } finally { setLoading(false); } - } + } }, [queryParams]); - useEffect(() => { - (async () => { - if (bech32 && typeof bech32 == 'string' && postContent) { - const argsTx = await dispatch(makeCallTxAndRedirect({ bech32, postContent })).unwrap(); - - console.log("Opening Gnokey to sign the transaction, argsTx: ", argsTx.txJson); - } - })() - }, [bech32]); - useEffect(() => { const unsubscribe = navigation.addListener("focus", async () => { setPostContent(""); @@ -61,11 +48,9 @@ export default function Search() { return unsubscribe; }, [navigation]); - const requestAddress = async () => { - console.log("requesting address for GnokeyMobile"); - // await dispatch(requestAddressForGnokeyMobile()).unwrap(); - const callback = encodeURIComponent('tech.berty.dsocial://post'); - Linking.openURL(`land.gno.gnokey://toselect?callback=${callback}`); + const onPressPost = async () => { + if (!account || !account.bech32) throw new Error("No active account: " + JSON.stringify(account)); + await dispatch(makeCallTxAndRedirect({ bech32: account.bech32, postContent })).unwrap(); } return ( @@ -90,7 +75,7 @@ export default function Search() { style={{ height: 200 }} /> - + diff --git a/mobile/redux/features/linkingSlice.ts b/mobile/redux/features/linkingSlice.ts index a631f3e..2441121 100644 --- a/mobile/redux/features/linkingSlice.ts +++ b/mobile/redux/features/linkingSlice.ts @@ -27,12 +27,6 @@ export const requestLoginForGnokeyMobile = createAsyncThunk("tx/request return await Linking.openURL(`land.gno.gnokey://tologin?callback=${callback}`); }) -export const requestAddressForGnokeyMobile = createAsyncThunk("tx/requestAddressForGnokeyMobile", async () => { - console.log("requesting address for GnokeyMobile"); - const callback = encodeURIComponent('tech.berty.dsocial://post'); - return await Linking.openURL(`land.gno.gnokey://toselect?callback=${callback}`); -}); - export const makeCallTxAndRedirect = createAsyncThunk("tx/makeCallTx", async ({ bech32, postContent }, thunkAPI) => { console.log("making a tx to: ", bech32); @@ -96,7 +90,7 @@ export const linkingSlice = createSlice({ selectPath: (state: State) => state.path, selectQueryParams: (state: State) => state.queryParams, selectLinkingParsedURL: (state: State) => state.linkingParsedURl, - selectQueryParamsAddress: (state: State) => state.linkingParsedURl?.queryParams?.address, + selectQueryParamsAddress: (state: State) => state.linkingParsedURl?.queryParams?.address as string | undefined, }, });