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

cartesi / rollups-explorer / 11726651411

07 Nov 2024 03:57PM CUT coverage: 86.104% (-0.5%) from 86.605%
11726651411

Pull #256

github

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

1366 of 1627 branches covered (83.96%)

Branch coverage included in aggregate %.

756 of 920 new or added lines in 13 files covered. (82.17%)

9428 of 10909 relevant lines covered (86.42%)

47.35 hits per line

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

92.37
/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
import { generateInitialValues } from "./utils";
1✔
8
import { AbiInputParam } from "./types";
9

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

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

25
            form.setFieldValue("abiFunctionName", abiFunctionName);
4✔
26

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

31
            if (nextAbiFunction) {
4✔
32
                const emptyFunctionParams: AbiInputParam[] = [];
4✔
33
                (nextAbiFunction.inputs as AbiInputParam[]).forEach((input) => {
4✔
34
                    generateInitialValues(input, emptyFunctionParams);
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