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

cartesi / rollups-explorer / 7917870316

15 Feb 2024 02:57PM UTC coverage: 94.399% (-0.7%) from 95.056%
7917870316

Pull #96

github

nevendyulgerov
chore(apps/web): Remove commented code
Pull Request #96: #72 Add ERC-721 Deposit form

388 of 493 branches covered (78.7%)

Branch coverage included in aggregate %.

5528 of 5774 relevant lines covered (95.74%)

15.69 hits per line

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

68.06
/packages/ui/src/TransactionProgress.tsx
1
"use client";
1✔
2
import {
1✔
3
    Center,
1✔
4
    Code,
1✔
5
    Collapse,
1✔
6
    Group,
1✔
7
    Progress,
1✔
8
    Stack,
1✔
9
    Text,
1✔
10
    useMantineTheme,
1✔
11
} from "@mantine/core";
1✔
12
import { useDisclosure } from "@mantine/hooks";
1✔
13
import { FC } from "react";
1✔
14
import {
1✔
15
    TbCheck,
1✔
16
    TbChevronDown,
1✔
17
    TbChevronUp,
1✔
18
    TbExclamationCircle,
1✔
19
} from "react-icons/tb";
1✔
20
import { BaseError } from "viem";
1✔
21
import { TransactionStageStatus } from "./TransactionStatus";
1✔
22

1✔
23
export type TransactionProgressProps = {
1✔
24
    prepare: TransactionStageStatus;
1✔
25
    execute: TransactionStageStatus;
1✔
26
    wait: TransactionStageStatus;
1✔
27
    confirmationMessage?: string;
1✔
28
    defaultErrorMessage?: string;
1✔
29
};
1✔
30

1✔
31
const getShortErrorMessage = (error: Error | null): string | undefined => {
1✔
32
    if (error != null) {
459!
33
        if (error instanceof BaseError) {
×
34
            return error.shortMessage;
×
35
        }
×
36
        if (error.cause instanceof BaseError) {
×
37
            return error.cause.shortMessage;
×
38
        }
×
39
        const be = error as BaseError;
×
40
        return be.shortMessage;
×
41
    }
×
42
    return undefined;
459✔
43
};
459✔
44

1✔
45
const getErrorMessage = (error: Error | null): string | undefined => {
1✔
46
    if (error != null) {
459!
47
        return error.message;
×
48
    }
×
49
    return undefined;
459✔
50
};
459✔
51

1✔
52
export const TransactionProgress: FC<TransactionProgressProps> = ({
1✔
53
    prepare,
153✔
54
    execute,
153✔
55
    wait,
153✔
56
    confirmationMessage,
153✔
57
    defaultErrorMessage,
153✔
58
}) => {
153✔
59
    const theme = useMantineTheme();
153✔
60
    const successColor = theme.colors.teal[5];
153✔
61
    const errorColor = theme.colors.red[5];
153✔
62

153✔
63
    // customizable confirmation message
153✔
64
    confirmationMessage = confirmationMessage || "Transaction confirmed";
153✔
65

153✔
66
    // customizable default error message
153✔
67
    defaultErrorMessage = defaultErrorMessage || "Transaction failed";
153✔
68

153✔
69
    const [showError, { toggle: toggleError }] = useDisclosure(false);
153✔
70
    const isSuccess = wait.status == "success";
153✔
71
    const isError = !!prepare.error || !!execute.error || !!wait.error;
153✔
72
    const isMining = wait.status == "loading";
153✔
73
    const shortErrorMessage =
153✔
74
        getShortErrorMessage(prepare.error) ||
153✔
75
        getShortErrorMessage(execute.error) ||
153✔
76
        getShortErrorMessage(wait.error);
153✔
77
    const errorMessage =
153✔
78
        getErrorMessage(prepare.error) ||
153✔
79
        getErrorMessage(execute.error) ||
153✔
80
        getErrorMessage(wait.error);
153✔
81
    const isLoading = execute.status == "loading";
153✔
82

153✔
83
    return (
153✔
84
        <Stack gap={5}>
153✔
85
            <Center>
153✔
86
                {isLoading && <Text size="xs">Check wallet...</Text>}
153!
87
                {isMining && <Text size="xs">Waiting for confirmation...</Text>}
153!
88
                {isSuccess && (
153!
89
                    <Group gap={5}>
×
90
                        <TbCheck color={successColor} />
×
91
                        <Text size="xs" c={successColor}>
×
92
                            {confirmationMessage}
×
93
                        </Text>
×
94
                    </Group>
×
95
                )}
153✔
96
                {isError && (
153!
97
                    <Group gap={5}>
×
98
                        <TbExclamationCircle color={errorColor} />
×
99
                        <Text size="xs" c={errorColor}>
×
100
                            {shortErrorMessage || defaultErrorMessage}
×
101
                        </Text>
×
102
                        {errorMessage &&
×
103
                            (showError ? (
×
104
                                <TbChevronUp
×
105
                                    color={errorColor}
×
106
                                    onClick={toggleError}
×
107
                                />
×
108
                            ) : (
×
109
                                <TbChevronDown
×
110
                                    color={errorColor}
×
111
                                    onClick={toggleError}
×
112
                                />
×
113
                            ))}
×
114
                    </Group>
×
115
                )}
153✔
116
            </Center>
153✔
117
            <Collapse in={showError}>
153✔
118
                <Code block variant="transparent" c={errorColor}>
153✔
119
                    {errorMessage}
153✔
120
                </Code>
153✔
121
            </Collapse>
153✔
122
            {(isLoading || isMining) && (
153!
123
                <Progress value={100} striped animated size="sm" />
×
124
            )}
153✔
125
            {isSuccess && (
153!
126
                <Progress value={100} size="sm" color={successColor} />
×
127
            )}
153✔
128
            {isError && <Progress value={100} size="sm" color={errorColor} />}
153!
129
        </Stack>
153✔
130
    );
153✔
131
};
153✔
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