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

cartesi / rollups-explorer / 8976881860

06 May 2024 10:58PM CUT coverage: 95.576%. Remained the same
8976881860

Pull #161

github

dandheedge
chore(packages/decoder): fix prettier path
Pull Request #161: #156 Voucher content decoding

499 of 600 branches covered (83.17%)

Branch coverage included in aggregate %.

6457 of 6678 relevant lines covered (96.69%)

21.18 hits per line

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

90.13
/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 {
1✔
22
    TransactionStageStatus,
1✔
23
    TransactionWaitStatus,
1✔
24
} from "./TransactionStatus";
1✔
25

1✔
26
export type TransactionProgressProps = {
1✔
27
    prepare: TransactionStageStatus;
1✔
28
    execute: TransactionStageStatus;
1✔
29
    wait: TransactionWaitStatus;
1✔
30
    confirmationMessage?: string;
1✔
31
    defaultErrorMessage?: string;
1✔
32
};
1✔
33

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

1✔
48
const getErrorMessage = (error: Error | null): string | undefined => {
1✔
49
    if (error != null) {
930✔
50
        return error.message;
4✔
51
    }
4✔
52
    return undefined;
926✔
53
};
926✔
54

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

310✔
66
    // customizable confirmation message
310✔
67
    confirmationMessage = confirmationMessage || "Transaction confirmed";
310✔
68

310✔
69
    // customizable default error message
310✔
70
    defaultErrorMessage = defaultErrorMessage || "Transaction failed";
310✔
71

310✔
72
    const [showError, { toggle: toggleError }] = useDisclosure(false);
310✔
73
    const isSuccess = wait.status == "success";
310✔
74
    const isError = !!prepare.error || !!execute.error || !!wait.error;
310✔
75
    const isMining = wait.fetchStatus === "fetching";
310✔
76
    const shortErrorMessage =
310✔
77
        getShortErrorMessage(prepare.error) ||
310✔
78
        getShortErrorMessage(execute.error) ||
310✔
79
        getShortErrorMessage(wait.error);
310✔
80
    const errorMessage =
310✔
81
        getErrorMessage(prepare.error) ||
310✔
82
        getErrorMessage(execute.error) ||
310✔
83
        getErrorMessage(wait.error);
310✔
84
    const isLoading = execute.status === "pending";
310✔
85

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