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

cartesi / rollups-explorer / 12807291327

16 Jan 2025 10:49AM UTC coverage: 86.104% (+0.001%) from 86.103%
12807291327

push

github

nevendyulgerov
chore(packages/ui): Remove inline imports for wagmi and @cartesi/rollups-wagmi from the generic form test suite

1389 of 1658 branches covered (83.78%)

Branch coverage included in aggregate %.

9628 of 11137 relevant lines covered (86.45%)

49.89 hits per line

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

96.09
/packages/ui/src/GenericInputForm/useGenericInputForm.ts
1
import { useForm } from "./context";
1✔
2
import {
3
    validateAbiFunctionName,
4
    validateAbiFunctionParamValue,
5
    validateAbiMethod,
6
    validateAbiParam,
7
    validateApplication,
8
    validateHexInput,
9
    validateHumanAbi,
10
    validateSpecificationId,
11
} from "./validations";
1✔
12
import { AbiFunction, getAddress, Hex, isAddress, zeroAddress } from "viem";
1✔
13
import { FormSpecification, GenericFormAbiFunction } from "./types";
14
import {
15
    augmentInputsWithIds,
16
    generateAbiParamFormSpecification,
17
    generateHumanAbiFormSpecification,
18
} from "./utils";
1✔
19
import { initialValues } from "./initialValues";
1✔
20
import { v4 as uuidv4 } from "uuid";
1✔
21
import { useRef } from "react";
1✔
22
import { equals, omit } from "ramda";
1✔
23

24
export const useGenericInputForm = (specifications: FormSpecification[]) => {
1✔
25
    const lastSelectedSpecification = useRef<FormSpecification | undefined>(
111✔
26
        undefined,
111✔
27
    );
111✔
28
    const lastSelectedSpecificationWithIds = useRef<
111✔
29
        FormSpecification | undefined
30
    >(undefined);
111✔
31

32
    return useForm({
111✔
33
        validateInputOnBlur: true,
111✔
34
        initialValues: {
111✔
35
            ...initialValues,
111✔
36
            abiMethod: specifications.length > 0 ? "existing" : "new",
111!
37
        },
111✔
38
        validate: {
111✔
39
            application: validateApplication,
111✔
40
            rawInput: validateHexInput,
111✔
41
            abiMethod: validateAbiMethod,
111✔
42
            humanAbi: validateHumanAbi,
111✔
43
            abiParam: validateAbiParam,
111✔
44
            specificationId: validateSpecificationId,
111✔
45
            abiFunctionName: validateAbiFunctionName,
111✔
46
            abiFunctionParams: {
111✔
47
                value: validateAbiFunctionParamValue,
111✔
48
            },
111✔
49
        },
111✔
50
        transformValues: (values) => {
111✔
51
            let selectedSpecification =
318✔
52
                values.abiMethod === "existing"
318✔
53
                    ? specifications.find(
140✔
54
                          (s) => s.id === values.specificationId,
140✔
55
                      )
140✔
56
                    : values.specificationMode === "json_abi"
178✔
57
                    ? generateHumanAbiFormSpecification(values.humanAbi)
83✔
58
                    : generateAbiParamFormSpecification(values.savedAbiParam);
95✔
59

60
            if (
318✔
61
                selectedSpecification &&
318✔
62
                !equals(
170✔
63
                    omit(["id"], selectedSpecification),
170✔
64
                    omit(
170✔
65
                        ["id"],
170✔
66
                        (lastSelectedSpecification.current ??
170✔
67
                            {}) as FormSpecification,
6✔
68
                    ),
170✔
69
                )
170✔
70
            ) {
318✔
71
                lastSelectedSpecification.current = {
6✔
72
                    ...selectedSpecification,
6✔
73
                };
6✔
74

75
                const selectedSpecificationWithIds = {
6✔
76
                    ...selectedSpecification,
6✔
77
                    abi: selectedSpecification.abi.map((abiFunction) => {
6✔
78
                        const nextAbiFunction = {
6✔
79
                            ...abiFunction,
6✔
80
                        } as GenericFormAbiFunction;
6✔
81

82
                        nextAbiFunction.inputs = nextAbiFunction.inputs.map(
6✔
83
                            (input) => {
6✔
84
                                const nextInput = { ...input, id: uuidv4() };
12✔
85

86
                                if (nextInput.type === "tuple") {
12!
87
                                    nextInput.components =
×
88
                                        augmentInputsWithIds(nextInput);
×
89
                                }
×
90

91
                                return nextInput;
12✔
92
                            },
12✔
93
                        );
6✔
94

95
                        return nextAbiFunction;
6✔
96
                    }),
6✔
97
                };
6✔
98

99
                selectedSpecification = { ...selectedSpecificationWithIds };
6✔
100
                lastSelectedSpecificationWithIds.current = {
6✔
101
                    ...selectedSpecificationWithIds,
6✔
102
                };
6✔
103
            } else if (lastSelectedSpecificationWithIds.current) {
318✔
104
                selectedSpecification = {
164✔
105
                    ...lastSelectedSpecificationWithIds.current,
164✔
106
                };
164✔
107
            }
164✔
108

109
            const abiFunction = (
318✔
110
                (selectedSpecification?.abi as AbiFunction[]) ?? []
318✔
111
            ).find(
318✔
112
                (abiFunction) => abiFunction.name === values.abiFunctionName,
318✔
113
            ) as GenericFormAbiFunction;
318✔
114

115
            return {
318✔
116
                mode: values.mode,
318✔
117
                address: isAddress(values.application)
318✔
118
                    ? getAddress(values.application)
226✔
119
                    : zeroAddress,
92✔
120
                rawInput: values.rawInput as Hex,
318✔
121
                abiMethod: values.abiMethod,
318✔
122
                specificationMode: values.specificationMode,
318✔
123
                humanAbi: values.humanAbi,
318✔
124
                abiParam: values.abiParam,
318✔
125
                savedAbiParam: values.savedAbiParam,
318✔
126
                specificationId: values.specificationId,
318✔
127
                abiFunctionName: values.abiFunctionName,
318✔
128
                selectedSpecification,
318✔
129
                abiFunction,
318✔
130
            };
318✔
131
        },
318✔
132
    });
111✔
133
};
111✔
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

© 2026 Coveralls, Inc