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

cartesi / rollups-explorer / 7459483902

09 Jan 2024 09:59AM UTC coverage: 95.485%. First build
7459483902

Pull #98

github

nevendyulgerov
feat: Add coveralls badge
Pull Request #98: #97 Add build steps for generating and uploading test coverage

344 of 421 branches covered (0.0%)

Branch coverage included in aggregate %.

4858 of 5027 relevant lines covered (96.64%)

14.43 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) {
285!
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;
285✔
43
};
285✔
44

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

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

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

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

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

95✔
83
    return (
95✔
84
        <Stack gap={5}>
95✔
85
            <Center>
95✔
86
                {isLoading && <Text size="xs">Check wallet...</Text>}
95!
87
                {isMining && <Text size="xs">Waiting for confirmation...</Text>}
95!
88
                {isSuccess && (
95!
89
                    <Group gap={5}>
×
90
                        <TbCheck color={successColor} />
×
91
                        <Text size="xs" c={successColor}>
×
92
                            {confirmationMessage}
×
93
                        </Text>
×
94
                    </Group>
×
95
                )}
95✔
96
                {isError && (
95!
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
                )}
95✔
116
            </Center>
95✔
117
            <Collapse in={showError}>
95✔
118
                <Code block variant="transparent" c={errorColor}>
95✔
119
                    {errorMessage}
95✔
120
                </Code>
95✔
121
            </Collapse>
95✔
122
            {(isLoading || isMining) && (
95!
123
                <Progress value={100} striped animated size="sm" />
×
124
            )}
95✔
125
            {isSuccess && (
95!
126
                <Progress value={100} size="sm" color={successColor} />
×
127
            )}
95✔
128
            {isError && <Progress value={100} size="sm" color={errorColor} />}
95!
129
        </Stack>
95✔
130
    );
95✔
131
};
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