• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cartesi / rollups-explorer / 11325739702

14 Oct 2024 10:31AM UTC coverage: 84.669% (-1.7%) from 86.415%
11325739702

Pull #256

github

nevendyulgerov
chore(apps/web): Cleanup
Pull Request #256: #251 Add ABI encoding for raw input form

1303 of 1566 branches covered (83.21%)

Branch coverage included in aggregate %.

709 of 901 new or added lines in 13 files covered. (78.69%)

145 existing lines in 1 file now uncovered.

9174 of 10808 relevant lines covered (84.88%)

46.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.44
/packages/ui/src/GenericInputForm/AbiFunctionName.tsx
1
import { useFormContext } from "./context";
1✔
2
import { Alert, Combobox, Input, InputBase, useCombobox } from "@mantine/core";
1✔
3
import { AbiFunction } from "viem";
4
import { useCallback } from "react";
1✔
5
import { FunctionSignature } from "./FunctionSignature";
1✔
6
import { TbAlertCircle } from "react-icons/tb";
1✔
7

8
export const AbiFunctionName = () => {
1✔
9
    const form = useFormContext();
65✔
10
    const { abiMethod, abiFunction, selectedSpecification, specificationMode } =
65✔
11
        form.getTransformedValues();
65✔
12
    const combobox = useCombobox({
65✔
13
        onDropdownClose: () => combobox.resetSelectedOption(),
65✔
14
    });
65✔
15
    const specificationFunctions = (
65✔
16
        (selectedSpecification?.abi as AbiFunction[]) ?? []
65✔
17
    ).filter((item) => item.type === "function");
65✔
18

19
    const onChangeAbiFunctionName = useCallback(
65✔
20
        (abiFunctionName: string) => {
65✔
21
            combobox.closeDropdown();
4✔
22

23
            form.setFieldValue("abiFunctionName", abiFunctionName);
4✔
24

25
            const nextAbiFunction = (
4✔
26
                (selectedSpecification?.abi as AbiFunction[]) ?? []
4!
27
            ).find((abiFunction) => abiFunction.name === abiFunctionName);
4✔
28

29
            if (nextAbiFunction) {
4✔
30
                const emptyFunctionParams = nextAbiFunction.inputs.map(
4✔
31
                    (input) => ({
4✔
32
                        ...input,
8✔
33
                        value: "",
8✔
34
                    }),
8✔
35
                );
4✔
36

37
                form.setFieldValue("abiFunctionParams", emptyFunctionParams);
4✔
38
            }
4✔
39
        },
4✔
40
        [combobox, form, selectedSpecification],
65✔
41
    );
65✔
42

43
    return (
65✔
44
        <>
65✔
45
            {(abiMethod === "existing" || specificationMode === "json_abi") &&
65✔
46
                selectedSpecification && (
48✔
47
                    <>
32✔
48
                        {specificationFunctions.length > 0 ? (
32✔
49
                            <Combobox
32✔
50
                                store={combobox}
32✔
51
                                onOptionSubmit={onChangeAbiFunctionName}
32✔
52
                            >
53
                                <Combobox.Target>
32✔
54
                                    <InputBase
32✔
55
                                        component="button"
32✔
56
                                        type="button"
32✔
57
                                        pointer
32✔
58
                                        label="ABI Function"
32✔
59
                                        description="Available ABI functions"
32✔
60
                                        rightSection={<Combobox.Chevron />}
32✔
61
                                        rightSectionPointerEvents="none"
32✔
62
                                        withAsterisk
32✔
63
                                        {...form.getInputProps(
32✔
64
                                            "abiFunctionName",
32✔
65
                                        )}
32✔
66
                                        onClick={() =>
32✔
67
                                            combobox.toggleDropdown()
6✔
68
                                        }
69
                                    >
70
                                        {abiFunction ? (
32✔
71
                                            <FunctionSignature
20✔
72
                                                abiFunction={abiFunction}
20✔
73
                                            />
20✔
74
                                        ) : (
75
                                            <Input.Placeholder>
12✔
76
                                                Select function
77
                                            </Input.Placeholder>
12✔
78
                                        )}
79
                                    </InputBase>
32✔
80
                                </Combobox.Target>
32✔
81

82
                                <Combobox.Dropdown>
32✔
83
                                    <Combobox.Options>
32✔
84
                                        {specificationFunctions.map(
32✔
85
                                            (abiFunction) => {
32✔
86
                                                const params =
32✔
87
                                                    abiFunction.inputs
32✔
88
                                                        .map(
32✔
89
                                                            (input) =>
32✔
90
                                                                `${input.type} ${input.name}`,
64✔
91
                                                        )
32✔
92
                                                        .join(", ");
32✔
93

94
                                                return (
32✔
95
                                                    <Combobox.Option
32✔
96
                                                        key={`${abiFunction.name}-${params}`}
32✔
97
                                                        value={abiFunction.name}
32✔
98
                                                    >
99
                                                        <FunctionSignature
32✔
100
                                                            abiFunction={
32✔
101
                                                                abiFunction
32✔
102
                                                            }
103
                                                        />
32✔
104
                                                    </Combobox.Option>
32✔
105
                                                );
106
                                            },
32✔
107
                                        )}
32✔
108
                                    </Combobox.Options>
32✔
109
                                </Combobox.Dropdown>
32✔
110
                            </Combobox>
32!
111
                        ) : (
NEW
112
                            <Alert
×
NEW
113
                                variant="light"
×
NEW
114
                                color="blue"
×
NEW
115
                                icon={<TbAlertCircle />}
×
NEW
116
                                data-testid="no-functions-alert"
×
NEW
117
                            >
×
118
                                No ABI functions available for this
119
                                specification.
NEW
120
                            </Alert>
×
121
                        )}
122
                    </>
32✔
123
                )}
124
        </>
65✔
125
    );
126
};
65✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc