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

cartesi / rollups-explorer / 10497914455

21 Aug 2024 09:40PM UTC coverage: 93.39% (-0.4%) from 93.766%
10497914455

Pull #232

github

nevendyulgerov
test(apps/web): Add unit tests
Pull Request #232: #229 Add import and export for specifications

1210 of 1432 branches covered (84.5%)

Branch coverage included in aggregate %.

486 of 569 new or added lines in 8 files covered. (85.41%)

50 existing lines in 10 files now uncovered.

12863 of 13637 relevant lines covered (94.32%)

45.58 hits per line

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

81.07
/apps/web/src/components/sendTransaction.tsx
1
"use client";
1✔
2
import {
1✔
3
    AddressRelayForm,
1✔
4
    ERC1155DepositForm,
1✔
5
    ERC20DepositForm,
1✔
6
    ERC721DepositForm,
1✔
7
    EtherDepositForm,
1✔
8
    RawInputForm,
1✔
9
    TransactionFormSuccessData,
1✔
10
} from "@cartesi/rollups-explorer-ui";
1✔
11
import { Select } from "@mantine/core";
1✔
12
import { useDebouncedValue } from "@mantine/hooks";
1✔
13
import { notifications } from "@mantine/notifications";
1✔
14
import { FC, useCallback, useState } from "react";
1✔
15
import { useSearchApplications } from "../hooks/useSearchApplications";
1✔
16
import { useSearchMultiTokens } from "../hooks/useSearchMultiTokens";
1✔
17
import { useSearchTokens } from "../hooks/useSearchTokens";
1✔
18
import { BlockExplorerLink } from "./BlockExplorerLink";
1✔
19

1✔
20
export type DepositType =
1✔
21
    | "ether"
1✔
22
    | "erc20"
1✔
23
    | "erc721"
1✔
24
    | "erc1155"
1✔
25
    | "erc1155Batch"
1✔
26
    | "relay"
1✔
27
    | "input";
1✔
28

1✔
29
interface DepositProps {
1✔
30
    initialDepositType?: DepositType;
1✔
31
}
1✔
32

1✔
33
const DEBOUNCE_TIME = 400 as const;
1✔
34

1✔
35
const SendTransaction: FC<DepositProps> = ({
1✔
36
    initialDepositType = "ether",
14✔
37
}) => {
14✔
38
    const [depositType, setDepositType] =
14✔
39
        useState<DepositType>(initialDepositType);
14✔
40
    const [applicationId, setApplicationId] = useState<string>("");
14✔
41
    const [multiTokenId, setMultiTokenId] = useState<string>("");
14✔
42
    const [tokenId, setTokenId] = useState<string>("");
14✔
43
    const [debouncedApplicationId] = useDebouncedValue(
14✔
44
        applicationId,
14✔
45
        DEBOUNCE_TIME,
14✔
46
    );
14✔
47
    const [debouncedTokenId] = useDebouncedValue(tokenId, DEBOUNCE_TIME);
14✔
48
    const [debouncedMultiTokenId] = useDebouncedValue(
14✔
49
        multiTokenId,
14✔
50
        DEBOUNCE_TIME,
14✔
51
    );
14✔
52
    const { applications, fetching } = useSearchApplications({
14✔
53
        address: debouncedApplicationId,
14✔
54
    });
14✔
55
    const { tokens } = useSearchTokens({
14✔
56
        address: debouncedTokenId,
14✔
57
    });
14✔
58
    const { multiTokens } = useSearchMultiTokens({
14✔
59
        address: debouncedMultiTokenId,
14✔
60
    });
14✔
61

14✔
62
    const onDepositErc721 = useCallback(() => {
14✔
UNCOV
63
        notifications.show({
×
64
            message: "Token was deposited successfully",
×
65
            color: "green",
×
66
            withBorder: true,
×
67
        });
×
68
    }, []);
14✔
69

14✔
70
    const onSuccess = useCallback(
14✔
71
        ({ receipt, type }: TransactionFormSuccessData) => {
14✔
72
            const message = receipt?.transactionHash
×
73
                ? {
×
74
                      message: (
×
75
                          <BlockExplorerLink
×
76
                              value={receipt.transactionHash.toString()}
×
77
                              type="tx"
×
78
                          />
×
79
                      ),
×
80
                      title: `${type} transaction completed`,
×
81
                  }
×
82
                : { message: `${type} transaction completed.` };
×
83

×
84
            notifications.show({
×
85
                withCloseButton: true,
×
UNCOV
86
                autoClose: false,
×
UNCOV
87
                color: "green",
×
UNCOV
88
                ...message,
×
UNCOV
89
            });
×
UNCOV
90

×
UNCOV
91
            setMultiTokenId("");
×
UNCOV
92
            setApplicationId("");
×
UNCOV
93
        },
×
94
        [],
14✔
95
    );
14✔
96

14✔
97
    return (
14✔
98
        <>
14✔
99
            <Select
14✔
100
                label="Type"
14✔
101
                placeholder="Select transaction type"
14✔
102
                mb={16}
14✔
103
                allowDeselect={false}
14✔
104
                data={[
14✔
105
                    {
14✔
106
                        group: "Deposit",
14✔
107
                        items: [
14✔
108
                            { value: "ether", label: "Ether Deposit" },
14✔
109
                            { value: "erc20", label: "ERC-20 Deposit" },
14✔
110
                            { value: "erc721", label: "ERC-721 Deposit" },
14✔
111
                            { value: "erc1155", label: "ERC-1155 Deposit" },
14✔
112
                            {
14✔
113
                                value: "erc1155Batch",
14✔
114
                                label: "ERC-1155 Batch Deposit",
14✔
115
                            },
14✔
116
                        ],
14✔
117
                    },
14✔
118
                    {
14✔
119
                        group: "Relay",
14✔
120
                        items: [
14✔
121
                            { value: "relay", label: "Application Address" },
14✔
122
                        ],
14✔
123
                    },
14✔
124
                    {
14✔
125
                        group: "Other",
14✔
126
                        items: [{ value: "input", label: "Raw Input" }],
14✔
127
                    },
14✔
128
                ]}
14✔
129
                value={depositType}
14✔
130
                onChange={(nextValue) => {
14✔
UNCOV
131
                    setDepositType(nextValue as DepositType);
×
UNCOV
132
                    setApplicationId("");
×
UNCOV
133
                }}
×
134
            />
14✔
135

14✔
136
            {depositType === "ether" ? (
14✔
137
                <EtherDepositForm
1✔
138
                    applications={applications}
1✔
139
                    isLoadingApplications={fetching}
1✔
140
                    onSearchApplications={setApplicationId}
1✔
141
                />
1✔
142
            ) : depositType === "erc20" ? (
13✔
143
                <ERC20DepositForm
9✔
144
                    tokens={tokens}
9✔
145
                    applications={applications}
9✔
146
                    isLoadingApplications={fetching}
9✔
147
                    onSearchApplications={setApplicationId}
9✔
148
                    onSearchTokens={setTokenId}
9✔
149
                />
9✔
150
            ) : depositType === "erc721" ? (
4✔
151
                <ERC721DepositForm
1✔
152
                    applications={applications}
1✔
153
                    isLoadingApplications={fetching}
1✔
154
                    onSearchApplications={setApplicationId}
1✔
155
                    onDeposit={onDepositErc721}
1✔
156
                />
1✔
157
            ) : depositType === "input" ? (
3✔
158
                <RawInputForm
1✔
159
                    applications={applications}
1✔
160
                    isLoadingApplications={fetching}
1✔
161
                    onSearchApplications={setApplicationId}
1✔
162
                />
1✔
163
            ) : depositType === "erc1155" ? (
2✔
164
                <ERC1155DepositForm
1✔
165
                    mode="single"
1✔
166
                    tokens={multiTokens}
1✔
167
                    applications={applications}
1✔
168
                    isLoadingApplications={fetching}
1✔
169
                    onSearchApplications={setApplicationId}
1✔
170
                    onSearchTokens={setMultiTokenId}
1✔
171
                    onSuccess={onSuccess}
1✔
172
                />
1✔
173
            ) : depositType === "erc1155Batch" ? (
1✔
174
                <ERC1155DepositForm
1✔
175
                    mode="batch"
1✔
176
                    tokens={multiTokens}
1✔
177
                    applications={applications}
1✔
178
                    isLoadingApplications={fetching}
1✔
179
                    onSearchApplications={setApplicationId}
1✔
180
                    onSearchTokens={setMultiTokenId}
1✔
181
                    onSuccess={onSuccess}
1✔
182
                />
1!
183
            ) : depositType === "relay" ? (
×
184
                <AddressRelayForm
×
185
                    applications={applications}
×
UNCOV
186
                    isLoadingApplications={fetching}
×
UNCOV
187
                    onSearchApplications={setApplicationId}
×
UNCOV
188
                    onSuccess={onSuccess}
×
UNCOV
189
                />
×
UNCOV
190
            ) : null}
×
191
        </>
14✔
192
    );
14✔
193
};
14✔
194
export default SendTransaction;
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