Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support entry function without signer param #563

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/pages/Account/Tabs/ModulesTab/Contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ function Contract({address, isRead}: {address: string; isRead: boolean}) {
}

const fns = module.abi.exposed_functions.filter((fn) =>
isRead
? fn.is_view
: fn.is_entry && fn.params.length > 0 && fn.params[0] === "&signer",
isRead ? fn.is_view : fn.is_entry,
);
if (fns.length === 0) {
return acc;
Expand Down Expand Up @@ -294,15 +292,16 @@ function RunContractForm({
const {submitTransaction, transactionResponse, transactionInProcess} =
useSubmitTransaction();

const fnParams = removeSignerParam(fn);

const onSubmit: SubmitHandler<ContractFormType> = async (data) => {
logEvent("write_button_clicked", fn.name);
const payload: Types.TransactionPayload = {
type: "entry_function_payload",
function: `${module.address}::${module.name}::${fn.name}`,
type_arguments: data.typeArgs,
arguments: data.args.map((arg, i) => {
// use i+1 because the first argument is the signer
const type = fn.params[i + 1];
const type = fnParams[i];
if (type.includes("vector")) {
// when it's a vector<u8>, we support both hex and javascript array format
return type === "vector<u8>" && arg.trim().startsWith("0x")
Expand Down Expand Up @@ -633,6 +632,9 @@ function ContractForm({
},
});

const fnParams = removeSignerParam(fn);
const hasSigner = fnParams.length !== fn.params.length;

useEffect(() => {
setFormValid(isValid);
}, [isValid, setFormValid]);
Expand Down Expand Up @@ -668,7 +670,7 @@ function ContractForm({
)}
/>
))}
{fn.is_entry &&
{hasSigner &&
(account ? (
<TextField
key="args-signer"
Expand All @@ -680,7 +682,7 @@ function ContractForm({
) : (
<TextField label="signer" disabled fullWidth />
))}
{fn.params.slice(fn.is_entry ? 1 : 0).map((param, i) => {
{fnParams.map((param, i) => {
return (
<Controller
key={`args-${i}`}
Expand All @@ -706,4 +708,8 @@ function ContractForm({
);
}

function removeSignerParam(fn: Types.MoveFunction) {
return fn.params.filter((p) => p !== "signer" && p !== "&signer");
}

export default Contract;