Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
iuricmp committed Oct 17, 2024
1 parent 5a30f83 commit c0d7e6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
10 changes: 4 additions & 6 deletions mobile/redux/features/linkingSlice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MakeTxResponse } from "@gnolang/gnonative";
import { GnoNativeApi, MakeTxResponse } from "@gnolang/gnonative";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import * as Linking from 'expo-linking';
import { ThunkExtra } from "redux/redux-provider";
Expand Down Expand Up @@ -33,7 +33,7 @@ export const makeCallTxAndRedirectToSign = createAsyncThunk<MakeTxResponse, Make
const gasFee = "1000000ugnot";
const gasWanted = BigInt(10000000);

const res = await thunkAPI.dispatch(makeCallTx({ packagePath, fnc, args, gasFee, gasWanted, callerAddressBech32 })).unwrap();
const res = await makeCallTx({ packagePath, fnc, args, gasFee, gasWanted, callerAddressBech32 }, thunkAPI.extra.gnonative);

setTimeout(() => {
const params = [`tx=${encodeURIComponent(res.txJson)}`, `address=${callerAddressBech32}`, `client_name=dSocial`, `reason=Post a message`];
Expand All @@ -54,16 +54,14 @@ type MakeCallTxParams = {
callerAddressBech32: string,
};

export const makeCallTx = createAsyncThunk<MakeTxResponse, MakeCallTxParams, ThunkExtra>("tx/makeCallTx", async (props, thunkAPI) => {
export const makeCallTx = async (props : MakeCallTxParams, gnonative: GnoNativeApi) : Promise<MakeTxResponse> => {
const { packagePath, fnc, callerAddressBech32, gasFee, gasWanted, args } = props;

console.log("making a tx for: ", callerAddressBech32);

const gnonative = thunkAPI.extra.gnonative;
const address = await gnonative.addressFromBech32(callerAddressBech32);

return await gnonative.makeCallTx(packagePath, fnc, args, gasFee, gasWanted, address)
})
}

export const broadcastTxCommit = createAsyncThunk<void, string, ThunkExtra>("tx/broadcastTxCommit", async (signedTx, thunkAPI) => {
console.log("broadcasting tx: ", signedTx);
Expand Down
11 changes: 6 additions & 5 deletions mobile/redux/features/profileSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { makeCallTx } from "./linkingSlice";
import { Following } from "@gno/types";
import { ThunkExtra } from "redux/redux-provider";
import * as Linking from 'expo-linking';
import { set } from "date-fns";

const CLIENT_NAME_PARAM = 'client_name=dSocial';

export interface ProfileState {
following: Following[];
Expand Down Expand Up @@ -33,10 +34,10 @@ export const followAndRedirectToSign = createAsyncThunk<void, { address: string,
const gasWanted = BigInt(10000000);
const callerAddressBech32 = await gnonative.addressToBech32(callerAddress);

const res = await thunkAPI.dispatch(makeCallTx({ packagePath, fnc, args, gasFee, gasWanted, callerAddressBech32 })).unwrap();
const res = await makeCallTx({ packagePath, fnc, args, gasFee, gasWanted, callerAddressBech32 }, thunkAPI.extra.gnonative);

setTimeout(() => {
const params = [`tx=${encodeURIComponent(res.txJson)}`, `address=${callerAddressBech32}`, 'client_name=dSocial', 'reason=Follow a user', `callback=${encodeURIComponent('tech.berty.dsocial://account')}`];
const params = [`tx=${encodeURIComponent(res.txJson)}`, `address=${callerAddressBech32}`, CLIENT_NAME_PARAM, 'reason=Follow a user', `callback=${encodeURIComponent('tech.berty.dsocial://account')}`];
Linking.openURL('land.gno.gnokey://tosign?' + params.join('&'))
}, 500)
});
Expand All @@ -52,10 +53,10 @@ export const unfollowAndRedirectToSign = createAsyncThunk<void, { address: strin
const gasWanted = BigInt(10000000);
const callerAddressBech32 = await gnonative.addressToBech32(callerAddress);

const res = await thunkAPI.dispatch(makeCallTx({ packagePath, fnc, args, gasFee, gasWanted, callerAddressBech32 })).unwrap();
const res = await makeCallTx({ packagePath, fnc, args, gasFee, gasWanted, callerAddressBech32 }, thunkAPI.extra.gnonative);

setTimeout(() => {
const params = [`tx=${encodeURIComponent(res.txJson)}`, `address=${callerAddressBech32}`, 'client_name=dSocial', 'reason=Unfollow a user', `callback=${encodeURIComponent('tech.berty.dsocial://account')}`];
const params = [`tx=${encodeURIComponent(res.txJson)}`, `address=${callerAddressBech32}`, CLIENT_NAME_PARAM, 'reason=Unfollow a user', `callback=${encodeURIComponent('tech.berty.dsocial://account')}`];
Linking.openURL('land.gno.gnokey://tosign?' + params.join('&'))
}, 500)
});
Expand Down

0 comments on commit c0d7e6d

Please sign in to comment.