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

cartesi / rollups-explorer / 11826960107

13 Nov 2024 10:31PM CUT coverage: 85.956% (-0.6%) from 86.605%
11826960107

Pull #256

github

nevendyulgerov
test(apps/web): Tweak layout for tuple inputs
Pull Request #256: #251 Add ABI encoding for raw input form

1368 of 1630 branches covered (83.93%)

Branch coverage included in aggregate %.

793 of 984 new or added lines in 13 files covered. (80.59%)

9465 of 10973 relevant lines covered (86.26%)

47.16 hits per line

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

93.75
/packages/ui/src/GenericInputForm/AbiParameter.tsx
1
import { useFormContext } from "./context";
1✔
2
import { Button, TextInput } from "@mantine/core";
1✔
3
import { useCallback } from "react";
1✔
4
import { AbiFunction } from "viem";
5
import {
6
    generateAbiParamFormSpecification,
7
    generateInitialValues,
8
} from "./utils";
1✔
9
import { AbiInputParam } from "./types";
10
import { isArray } from "ramda-adjunct";
1✔
11

12
export const AbiParameter = () => {
1✔
13
    const form = useFormContext();
17✔
14
    const { abiParam, savedAbiParam } = form.getTransformedValues();
17✔
15

16
    const addABIParam = useCallback(() => {
17✔
17
        form.setFieldValue("savedAbiParam", abiParam);
2✔
18

19
        const selectedSpecification =
2✔
20
            generateAbiParamFormSpecification(abiParam);
2✔
21

22
        if (selectedSpecification) {
2✔
23
            form.setFieldValue("specificationId", selectedSpecification.id);
2✔
24
        }
2✔
25

26
        const nextAbiFunction = (
2✔
27
            selectedSpecification?.abi as AbiFunction[]
2✔
28
        )[0];
2✔
29

30
        if (nextAbiFunction) {
2✔
31
            const emptyFunctionParams: AbiInputParam[] = [];
2✔
32
            (nextAbiFunction.inputs as AbiInputParam[]).forEach((input) => {
2✔
33
                generateInitialValues(input, emptyFunctionParams);
4✔
34
            });
2✔
35

36
            const prevAbiFunctionParams =
2✔
37
                form.getInputProps("abiFunctionParams");
2✔
38

39
            if (isArray(prevAbiFunctionParams.value)) {
2✔
40
                prevAbiFunctionParams.value.forEach((_, index) => {
2✔
NEW
41
                    form.setFieldError(
×
NEW
42
                        `abiFunctionParams.${index}.value`,
×
NEW
43
                        null,
×
NEW
44
                    );
×
45
                });
2✔
46
            }
2✔
47

48
            form.setFieldValue("abiFunctionParams", emptyFunctionParams);
2✔
49
        }
2✔
50
        // eslint-disable-next-line react-hooks/exhaustive-deps -- 'form' is not added on purpose because it has unstable reference
51
    }, [abiParam]);
17✔
52

53
    return (
17✔
54
        <TextInput
17✔
55
            label="ABI Parameter"
17✔
56
            description="Human readable ABI format"
17✔
57
            placeholder="address to, uint256 amount, bool succ"
17✔
58
            rightSectionWidth="lg"
17✔
59
            rightSection={
17✔
60
                <Button
17✔
61
                    data-testid="abi-parameter-add-button"
17✔
62
                    onClick={addABIParam}
17✔
63
                    disabled={
17✔
64
                        !!form.errors.abiParam || abiParam === savedAbiParam
17✔
65
                    }
66
                >
17✔
67
                    Save
68
                </Button>
17✔
69
            }
70
            data-testid="abi-parameter-input"
17✔
71
            {...form.getInputProps("abiParam")}
17✔
72
            onChange={(event) => {
17✔
73
                const nextValue = event.target.value;
3✔
74
                form.setFieldValue("abiParam", nextValue);
3✔
75
                form.validateField("abiParam");
3✔
76
            }}
3✔
77
        />
17✔
78
    );
79
};
17✔
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