Skip to content

Commit ee98955

Browse files
committed
Fix autocomplete in exec and act commands
1 parent e7db30d commit ee98955

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

packages/evmcrispr/src/modules/aragonos/commands/act.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { AbiFunction } from "viem";
12
import { isAddress } from "viem";
23

34
import type { AbiBinding, ICommand } from "../../../types";
@@ -12,7 +13,6 @@ import {
1213
checkArgsLength,
1314
encodeAction,
1415
fetchAbi,
15-
getFunctionFragment,
1616
insideNodeLine,
1717
interpretNodeSync,
1818
tryAndCacheNotFound,
@@ -85,16 +85,18 @@ export const act: ICommand<AragonOS> = {
8585
if (!abi) {
8686
return [];
8787
}
88-
8988
const functions = abi
9089
// Only consider functions that change state
9190
.filter(
92-
(item) =>
91+
(item): item is AbiFunction =>
9392
item.type === "function" &&
9493
(item.stateMutability === "nonpayable" ||
9594
item.stateMutability === "payable"),
9695
)
97-
.map(getFunctionFragment);
96+
.map(
97+
(func: AbiFunction) =>
98+
`${func.name}(${func.inputs.map((input) => input.type).join(",")})`,
99+
);
98100
return functions;
99101
}
100102
default: {

packages/evmcrispr/src/modules/std/commands/exec.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { AbiFunction } from "viem";
12
import { getAbiItem, isAddress } from "viem";
23

34
import { BindingsSpace } from "../../../types";
@@ -145,7 +146,7 @@ export const exec: ICommand<Std> = {
145146
nodeArgs[0].type === "HelperFunctionExpression" &&
146147
(nodeArgs[0] as HelperFunctionNode).name === "token"
147148
? erc20ABI
148-
: (function () {
149+
: (() => {
149150
const targetAddress = interpretNodeSync(
150151
nodeArgs[0],
151152
bindingsManager,
@@ -162,12 +163,15 @@ export const exec: ICommand<Std> = {
162163
const functions = abi
163164
// Only consider functions that change state
164165
.filter(
165-
(item) =>
166+
(item): item is AbiFunction =>
166167
item.type === "function" &&
167168
(item.stateMutability === "nonpayable" ||
168169
item.stateMutability === "payable"),
169170
)
170-
.map(getFunctionFragment);
171+
.map(
172+
(func: AbiFunction) =>
173+
`${func.name}(${func.inputs.map((input) => input.type).join(",")})`,
174+
);
171175
return functions;
172176
}
173177
default: {

packages/evmcrispr/src/utils/web3.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const SIGNATURE_REGEX =
1010
export const toDecimals = (amount: number | string, decimals = 18): bigint => {
1111
const [integer, decimal] = String(amount).split(".");
1212
return BigInt(
13-
(integer != "0" ? integer : "") + (decimal || "").padEnd(decimals, "0") ||
13+
(integer !== "0" ? integer : "") + (decimal || "").padEnd(decimals, "0") ||
1414
"0",
1515
);
1616
};
@@ -22,7 +22,6 @@ export function addressesEqual(first: Address, second: Address): boolean {
2222
export function getFunctionFragment(func: AbiItem | undefined) {
2323
if (func?.type === "function") {
2424
return `function ${func.name}(${func.inputs.map((input) => input.type).join(", ")})${func.outputs.length > 0 ? ` returns (${func.outputs.map((output) => output.type).join(", ")})` : ""}`;
25-
} else {
26-
throw new Error(`invalid function`);
2725
}
26+
throw new Error("invalid function");
2827
}

0 commit comments

Comments
 (0)