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

cartesi / rollups-explorer / 10559884974

26 Aug 2024 12:37PM CUT coverage: 93.391% (-0.4%) from 93.766%
10559884974

Pull #232

github

nevendyulgerov
fix(apps/web): Temporary disable swc minification
Pull Request #232: #229 Add import and export for specifications

1210 of 1432 branches covered (84.5%)

Branch coverage included in aggregate %.

487 of 570 new or added lines in 8 files covered. (85.44%)

50 existing lines in 10 files now uncovered.

12864 of 13638 relevant lines covered (94.32%)

45.58 hits per line

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

97.62
/packages/ui/src/AddressRelayForm.tsx
1
import {
1✔
2
    useSimulateDAppAddressRelayRelayDAppAddress,
1✔
3
    useWriteDAppAddressRelayRelayDAppAddress,
1✔
4
} from "@cartesi/rollups-wagmi";
1✔
5
import {
1✔
6
    Alert,
1✔
7
    Autocomplete,
1✔
8
    Button,
1✔
9
    Collapse,
1✔
10
    Group,
1✔
11
    Loader,
1✔
12
    Stack,
1✔
13
} from "@mantine/core";
1✔
14
import { useForm } from "@mantine/form";
1✔
15
import { is } from "ramda";
1✔
16
import { FC, useEffect } from "react";
1✔
17
import { TbAlertCircle, TbCheck } from "react-icons/tb";
1✔
18
import { BaseError, getAddress, isAddress, zeroAddress } from "viem";
1✔
19
import { useWaitForTransactionReceipt } from "wagmi";
1✔
20
import { TransactionFormSuccessData } from "./DepositFormTypes";
1✔
21
import { TransactionProgress } from "./TransactionProgress";
1✔
22
import { transactionState } from "./TransactionState";
1✔
23
import useUndeployedApplication from "./hooks/useUndeployedApplication";
1✔
24

1✔
25
export interface AddressRelayFormProps {
1✔
26
    applications: string[];
1✔
27
    isLoadingApplications: boolean;
1✔
28
    onSearchApplications: (applicationId: string) => void;
1✔
29
    onSuccess?: (receipt: TransactionFormSuccessData) => void;
1✔
30
}
1✔
31

1✔
32
export const AddressRelayForm: FC<AddressRelayFormProps> = (props) => {
1✔
33
    const {
21✔
34
        applications,
21✔
35
        isLoadingApplications,
21✔
36
        onSearchApplications,
21✔
37
        onSuccess,
21✔
38
    } = props;
21✔
39
    const form = useForm({
21✔
40
        validateInputOnChange: true,
21✔
41
        initialValues: {
21✔
42
            application: "",
21✔
43
        },
21✔
44
        validate: {
21✔
45
            application: (value) =>
21✔
46
                value !== "" && isAddress(value)
27✔
47
                    ? null
16✔
48
                    : "Invalid application address",
11✔
49
        },
21✔
50
        transformValues: (values) => ({
21✔
51
            address: isAddress(values.application)
21✔
52
                ? getAddress(values.application)
11✔
53
                : zeroAddress,
10✔
54
        }),
21✔
55
    });
21✔
56
    const { address } = form.getTransformedValues();
21✔
57
    const prepare = useSimulateDAppAddressRelayRelayDAppAddress({
21✔
58
        args: [address],
21✔
59
        query: {
21✔
60
            enabled: address !== zeroAddress,
21✔
61
        },
21✔
62
    });
21✔
63

21✔
64
    const execute = useWriteDAppAddressRelayRelayDAppAddress();
21✔
65
    const wait = useWaitForTransactionReceipt({
21✔
66
        hash: execute.data,
21✔
67
    });
21✔
68

21✔
69
    const { loading, disabled } = transactionState(
21✔
70
        prepare,
21✔
71
        execute,
21✔
72
        wait,
21✔
73
        true,
21✔
74
    );
21✔
75
    const canSubmit = form.isValid();
21✔
76
    const isUndeployedApp = useUndeployedApplication(address, applications);
21✔
77

21✔
78
    useEffect(() => {
21✔
79
        if (wait.isSuccess) {
15✔
80
            if (is(Function, onSuccess))
1✔
81
                onSuccess({ receipt: wait.data, type: "ADDRESS-RELAY" });
1✔
82
            form.reset();
1✔
83
            execute.reset();
1✔
84
        }
1✔
85
    }, [wait.isSuccess, wait.data, form, execute, onSuccess]);
21✔
86

21✔
87
    return (
21✔
88
        <form data-testid="address-relay-form">
21✔
89
            <Stack>
21✔
90
                <Autocomplete
21✔
91
                    label="Application"
21✔
92
                    data-testid="application"
21✔
93
                    description="The application address to relay."
21✔
94
                    placeholder="0x"
21✔
95
                    data={applications}
21✔
96
                    withAsterisk
21✔
97
                    rightSection={
21✔
98
                        (prepare.isLoading || isLoadingApplications) && (
21!
UNCOV
99
                            <Loader size="xs" />
×
100
                        )
21✔
101
                    }
21✔
102
                    {...form.getInputProps("application")}
21✔
103
                    error={
21✔
104
                        form.errors.application ||
21✔
105
                        (prepare.error as BaseError)?.shortMessage
19!
106
                    }
21✔
107
                    onChange={(nextValue) => {
21✔
108
                        form.setFieldValue("application", nextValue);
6✔
109
                        onSearchApplications(nextValue);
6✔
110
                    }}
6✔
111
                />
21✔
112

21✔
113
                {!form.errors.application && isUndeployedApp && (
21✔
114
                    <Alert
1✔
115
                        variant="light"
1✔
116
                        color="yellow"
1✔
117
                        icon={<TbAlertCircle />}
1✔
118
                    >
1✔
119
                        This is an undeployed application.
1✔
120
                    </Alert>
1✔
121
                )}
21✔
122

21✔
123
                <Collapse in={!execute.isIdle || execute.isError}>
21✔
124
                    <TransactionProgress
21✔
125
                        prepare={prepare}
21✔
126
                        execute={execute}
21✔
127
                        wait={wait}
21✔
128
                        defaultErrorMessage={execute.error?.message}
21!
129
                    />
21✔
130
                </Collapse>
21✔
131

21✔
132
                <Group justify="right">
21✔
133
                    <Button
21✔
134
                        variant="filled"
21✔
135
                        disabled={disabled || !canSubmit}
21✔
136
                        leftSection={<TbCheck />}
21✔
137
                        loading={loading}
21✔
138
                        onClick={() =>
21✔
139
                            execute.writeContract(prepare.data!.request)
1✔
140
                        }
21✔
141
                    >
21✔
142
                        Send
21✔
143
                    </Button>
21✔
144
                </Group>
21✔
145
            </Stack>
21✔
146
        </form>
21✔
147
    );
21✔
148
};
21✔
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