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

cartesi / rollups-explorer / 8976881860

06 May 2024 10:58PM UTC 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

88.15
/apps/web/src/components/inputs/inputRow.tsx
1
"use client";
1✔
2
import { erc20PortalAddress, etherPortalAddress } from "@cartesi/rollups-wagmi";
1✔
3
import {
1✔
4
    ActionIcon,
1✔
5
    Badge,
1✔
6
    Box,
1✔
7
    Collapse,
1✔
8
    Group,
1✔
9
    Paper,
1✔
10
    Table,
1✔
11
    Text,
1✔
12
} from "@mantine/core";
1✔
13
import { useDisclosure } from "@mantine/hooks";
1✔
14
import prettyMilliseconds from "pretty-ms";
1✔
15
import { FC } from "react";
1✔
16
import { TbArrowRight, TbFileText, TbX } from "react-icons/tb";
1✔
17
import { Address as AddressType, formatUnits, getAddress } from "viem";
1✔
18
import { InputItemFragment } from "../../graphql/explorer/operations";
1✔
19
import Address from "../address";
1✔
20
import InputDetailsView from "./inputDetailsView";
1✔
21

1✔
22
export type InputRowProps = {
1✔
23
    input: InputItemFragment;
1✔
24
    timeType: string;
1✔
25
    keepDataColVisible: boolean;
1✔
26
};
1✔
27

1✔
28
export type MethodResolver = (
1✔
29
    input: InputItemFragment,
1✔
30
) => string | undefined | false;
1✔
31

1✔
32
const etherDepositResolver: MethodResolver = (input) =>
1✔
33
    getAddress(input.msgSender) === etherPortalAddress && "depositEther";
6!
34
const erc20PortalResolver: MethodResolver = (input) =>
1✔
35
    getAddress(input.msgSender) === erc20PortalAddress && "depositERC20Tokens";
6!
36

1✔
37
const resolvers: MethodResolver[] = [etherDepositResolver, erc20PortalResolver];
1✔
38
const methodResolver: MethodResolver = (input) => {
1✔
39
    for (const resolver of resolvers) {
6✔
40
        const method = resolver(input);
12✔
41
        if (method) return method;
12!
42
    }
12✔
43
    return undefined;
6✔
44
};
6✔
45

1✔
46
const InputRow: FC<InputRowProps> = ({
1✔
47
    input,
6✔
48
    timeType,
6✔
49
    keepDataColVisible,
6✔
50
}) => {
6✔
51
    const [opened, { toggle }] = useDisclosure(false);
6✔
52
    const from = input.msgSender as AddressType;
6✔
53
    const to = input.application.id as AddressType;
6✔
54

6✔
55
    const erc20Deposit = (input: InputItemFragment) =>
6✔
56
        input.erc20Deposit ? (
6!
57
            <Text size="xs">
×
58
                {formatUnits(
×
59
                    input.erc20Deposit.amount,
×
60
                    input.erc20Deposit.token.decimals,
×
61
                )}{" "}
×
62
                {input.erc20Deposit.token.symbol}
×
63
            </Text>
×
64
        ) : (
6✔
65
            <></>
6✔
66
        );
6✔
67

6✔
68
    const method = (
6✔
69
        <Badge variant="default" style={{ textTransform: "none" }}>
6✔
70
            {methodResolver(input) ?? "?"}
6✔
71
        </Badge>
6✔
72
    );
6✔
73
    return (
6✔
74
        <>
6✔
75
            <Table.Tr>
6✔
76
                <Table.Td>
6✔
77
                    <Box
6✔
78
                        display="flex"
6✔
79
                        w="max-content"
6✔
80
                        style={{
6✔
81
                            alignItems: "center",
6✔
82
                            justifyContent: "center",
6✔
83
                        }}
6✔
84
                    >
6✔
85
                        {input.erc20Deposit ? (
6!
86
                            <Group>
×
87
                                <Address
×
88
                                    value={
×
89
                                        input.erc20Deposit.from as AddressType
×
90
                                    }
×
91
                                    icon
×
92
                                    shorten
×
93
                                />
×
94
                                <TbArrowRight />
×
95
                                <Address value={from} icon shorten />
×
96
                            </Group>
×
97
                        ) : (
6✔
98
                            <Address value={from} icon shorten />
6✔
99
                        )}
6✔
100
                    </Box>
6✔
101
                </Table.Td>
6✔
102
                <Table.Td>
6✔
103
                    <Box
6✔
104
                        display="flex"
6✔
105
                        w="max-content"
6✔
106
                        style={{
6✔
107
                            alignItems: "center",
6✔
108
                            justifyContent: "center",
6✔
109
                        }}
6✔
110
                    >
6✔
111
                        <Group justify="right">
6✔
112
                            {erc20Deposit(input)}
6✔
113
                            <TbArrowRight />
6✔
114
                        </Group>
6✔
115
                    </Box>
6✔
116
                </Table.Td>
6✔
117
                <Table.Td>
6✔
118
                    <Box
6✔
119
                        display="flex"
6✔
120
                        w="max-content"
6✔
121
                        style={{
6✔
122
                            alignItems: "center",
6✔
123
                            justifyContent: "center",
6✔
124
                        }}
6✔
125
                    >
6✔
126
                        <Address
6✔
127
                            value={to}
6✔
128
                            icon
6✔
129
                            href={`/applications/${to}`}
6✔
130
                            shorten
6✔
131
                        />
6✔
132
                    </Box>
6✔
133
                </Table.Td>
6✔
134
                <Table.Td>{method}</Table.Td>
6✔
135
                <Table.Td>
6✔
136
                    <Text>{input.index}</Text>
6✔
137
                </Table.Td>
6✔
138
                <Table.Td>
6✔
139
                    <Box
6✔
140
                        display="flex"
6✔
141
                        w="max-content"
6✔
142
                        style={{
6✔
143
                            alignItems: "center",
6✔
144
                            justifyContent: "center",
6✔
145
                        }}
6✔
146
                    >
6✔
147
                        <Text>
6✔
148
                            {timeType === "age"
6✔
149
                                ? `${prettyMilliseconds(
4✔
150
                                      Date.now() - input.timestamp * 1000,
4✔
151
                                      {
4✔
152
                                          unitCount: 2,
4✔
153
                                          secondsDecimalDigits: 0,
4✔
154
                                          verbose: true,
4✔
155
                                      },
4✔
156
                                  )} ago`
4✔
157
                                : new Date(
2✔
158
                                      input.timestamp * 1000,
2✔
159
                                  ).toISOString()}
2✔
160
                        </Text>
6✔
161
                    </Box>
6✔
162
                </Table.Td>
6✔
163
                <Table.Td
6✔
164
                    pos={keepDataColVisible ? "initial" : "sticky"}
6✔
165
                    top={0}
6✔
166
                    right={0}
6✔
167
                    p={0}
6✔
168
                >
6✔
169
                    <Paper
6✔
170
                        shadow={keepDataColVisible ? undefined : "xl"}
6✔
171
                        radius={0}
6✔
172
                        p="var(--table-vertical-spacing) var(--table-horizontal-spacing, var(--mantine-spacing-xs))"
6✔
173
                    >
6✔
174
                        <ActionIcon variant="default" onClick={toggle}>
6✔
175
                            {opened ? <TbX /> : <TbFileText />}
6!
176
                        </ActionIcon>
6✔
177
                    </Paper>
6✔
178
                </Table.Td>
6✔
179
            </Table.Tr>
6✔
180
            <Table.Tr></Table.Tr>
6✔
181
            <Table.Tr>
6✔
182
                <Table.Td colSpan={8} p={0}>
6✔
183
                    <Collapse in={opened}>
6✔
184
                        {opened && <InputDetailsView input={input} />}
6!
185
                    </Collapse>
6✔
186
                </Table.Td>
6✔
187
            </Table.Tr>
6✔
188
        </>
6✔
189
    );
6✔
190
};
6✔
191

1✔
192
export default InputRow;
1✔
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