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

cartesi / rollups-explorer / 10317825307

09 Aug 2024 10:34AM UTC coverage: 93.674% (-0.05%) from 93.722%
10317825307

Pull #223

github

nevendyulgerov
chore(packages/ui): Revert change
Pull Request #223: #220 Upgrade mantine packages

1147 of 1362 branches covered (84.21%)

Branch coverage included in aggregate %.

18 of 18 new or added lines in 4 files covered. (100.0%)

9 existing lines in 1 file now uncovered.

12403 of 13103 relevant lines covered (94.66%)

39.54 hits per line

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

90.91
/apps/web/src/components/specification/form/fields/HumanReadableABI.tsx
1
import { CodeHighlight } from "@mantine/code-highlight";
1✔
2
import { Accordion, Stack, Textarea, Title } from "@mantine/core";
1✔
3
import { createFormActions, useForm } from "@mantine/form";
1✔
4
import { isNotNil } from "ramda";
1✔
5
import { isBlank, isFunction } from "ramda-adjunct";
1✔
6
import { FC, ReactNode, useEffect } from "react";
1✔
7
import { Abi, parseAbi } from "viem";
1✔
8
import LabelWithTooltip from "../../../labelWithTooltip";
1✔
9
import { prepareSignatures, stringifyContent } from "../../utils";
1✔
10

1✔
11
const placeholder = `function balanceOf(address owner) view returns (uint256) \nevent Transfer(address indexed from, address indexed to, uint256 amount)`;
1✔
12
interface Props {
1✔
13
    abi?: Abi;
1✔
14
    onAbiChange: (abi: Abi) => void;
1✔
15
    error?: string | ReactNode;
1✔
16
}
1✔
17

1✔
18
const abiTipMessage =
1✔
19
    "Define the signature without wrapping it on quotes nor adding comma at the end to separate. Just hit enter and keep defining your signatures";
1✔
20

1✔
21
interface FormValues {
1✔
22
    humanABIEntry: string;
1✔
23
}
1✔
24

1✔
25
interface FormTransformedValues {
1✔
26
    generatedAbi?: Abi;
1✔
27
    readableList?: string[];
1✔
28
}
1✔
29

1✔
30
type FormTransform = (v: FormValues) => FormTransformedValues;
1✔
31

1✔
32
export const humanReadableABIFormActions = createFormActions<FormValues>(
1✔
33
    "human-readable-abi-form",
1✔
34
);
1✔
35

1✔
36
export const HumanReadableABI: FC<Props> = ({ onAbiChange, error }) => {
1✔
37
    const form = useForm<FormValues, FormTransform>({
95✔
38
        name: "human-readable-abi-form",
95✔
39
        validateInputOnBlur: true,
95✔
40
        initialValues: {
95✔
41
            humanABIEntry: "",
95✔
42
        },
95✔
43
        validate: {
95✔
44
            humanABIEntry: (value) => {
95✔
UNCOV
45
                if (isBlank(value))
×
UNCOV
46
                    return "The ABI signature definition is required!";
×
UNCOV
47
                const items = prepareSignatures(value);
×
UNCOV
48

×
UNCOV
49
                try {
×
UNCOV
50
                    parseAbi(items);
×
UNCOV
51
                } catch (error: any) {
×
52
                    return error.message;
×
53
                }
×
UNCOV
54
                return null;
×
UNCOV
55
            },
×
56
        },
95✔
57
        transformValues: (values) => {
95✔
58
            if (isBlank(values.humanABIEntry)) return {};
95✔
59

20✔
60
            const readableList = prepareSignatures(values.humanABIEntry);
20✔
61
            let generatedAbi;
20✔
62
            try {
20✔
63
                generatedAbi = parseAbi(readableList);
20✔
64
            } catch (error: any) {}
95!
65

20✔
66
            return {
20✔
67
                generatedAbi,
20✔
68
                readableList,
20✔
69
            };
20✔
70
        },
95✔
71
    });
95✔
72

95✔
73
    const { generatedAbi, readableList } = form.getTransformedValues();
95✔
74
    const key = JSON.stringify(readableList);
95✔
75
    const displayAccordion = isNotNil(generatedAbi) || isNotNil(readableList);
95✔
76

95✔
77
    useEffect(() => {
95✔
78
        if (isFunction(onAbiChange)) onAbiChange(generatedAbi ?? []);
30✔
79
        // eslint-disable-next-line react-hooks/exhaustive-deps
30✔
80
    }, [onAbiChange, key]);
95✔
81

95✔
82
    return (
95✔
83
        <Stack>
95✔
84
            <Textarea
95✔
85
                data-testid="human-readable-abi-input"
95✔
86
                resize="vertical"
95✔
87
                label={
95✔
88
                    <LabelWithTooltip
95✔
89
                        label="ABI"
95✔
90
                        tooltipLabel={abiTipMessage}
95✔
91
                    />
95✔
92
                }
95✔
93
                description="Define signatures in Human readable format"
95✔
94
                placeholder={placeholder}
95✔
95
                rows={5}
95✔
96
                {...form.getInputProps("humanABIEntry")}
95✔
97
                error={error || form.errors.humanABIEntry}
95✔
98
            />
95✔
99

95✔
100
            {displayAccordion && (
95✔
101
                <Accordion variant="contained" chevronPosition="right" py="sm">
20✔
102
                    <Accordion.Item
20✔
103
                        data-testid="abi-signatures-item"
20✔
104
                        key="abi-signatures-item"
20✔
105
                        value="abi-signatures-item"
20✔
106
                    >
20✔
107
                        <Accordion.Control>
20✔
108
                            <Title order={4}>ABI Signatures</Title>
20✔
109
                        </Accordion.Control>
20✔
110

20✔
111
                        <Accordion.Panel>
20✔
112
                            <CodeHighlight
20✔
113
                                withCopyButton={false}
20✔
114
                                language="solidity"
20✔
115
                                code={stringifyContent(readableList ?? [])}
20!
116
                            />
20✔
117
                        </Accordion.Panel>
20✔
118
                    </Accordion.Item>
20✔
119

20✔
120
                    <Accordion.Item
20✔
121
                        data-testid="json-abi-generated-item"
20✔
122
                        key="abi-generated-json-item"
20✔
123
                        value="abi-generated-json-item"
20✔
124
                    >
20✔
125
                        <Accordion.Control>
20✔
126
                            <Title order={4}>JSON ABI Generated</Title>
20✔
127
                        </Accordion.Control>
20✔
128

20✔
129
                        <Accordion.Panel>
20✔
130
                            <CodeHighlight
20✔
131
                                withCopyButton={false}
20✔
132
                                language="JSON"
20✔
133
                                code={stringifyContent(generatedAbi ?? [])}
20!
134
                            />
20✔
135
                        </Accordion.Panel>
20✔
136
                    </Accordion.Item>
20✔
137
                </Accordion>
20✔
138
            )}
95✔
139
        </Stack>
95✔
140
    );
95✔
141
};
95✔
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