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

cartesi / rollups-explorer / 10368365441

13 Aug 2024 10:50AM UTC coverage: 93.766% (+0.04%) from 93.725%
10368365441

push

github

web-flow
#227 Upgrade testing-library packages (#231)

1148 of 1365 branches covered (84.1%)

Branch coverage included in aggregate %.

12435 of 13121 relevant lines covered (94.77%)

39.71 hits per line

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

97.59
/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 { FC, useEffect } from "react";
1✔
16
import { TbAlertCircle, TbCheck } from "react-icons/tb";
1✔
17
import { BaseError, getAddress, isAddress, zeroAddress } from "viem";
1✔
18
import { useWaitForTransactionReceipt } from "wagmi";
1✔
19
import { TransactionFormSuccessData } from "./DepositFormTypes";
1✔
20
import { TransactionProgress } from "./TransactionProgress";
1✔
21
import { transactionState } from "./TransactionState";
1✔
22
import useUndeployedApplication from "./hooks/useUndeployedApplication";
1✔
23

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

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

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

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

17✔
77
    useEffect(() => {
17✔
78
        if (wait.isSuccess) {
17✔
79
            onSuccess({ receipt: wait.data, type: "ADDRESS-RELAY" });
2✔
80
            form.reset();
2✔
81
            execute.reset();
2✔
82
        }
2✔
83
    }, [wait, form, execute, onSuccess]);
17✔
84

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

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

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

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

© 2026 Coveralls, Inc