• 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

95.03
/apps/web/src/providers/connectionConfig/hooks.tsx
1
"use client";
1✔
2
import {
1✔
3
    find,
1✔
4
    identity,
1✔
5
    join,
1✔
6
    map,
1✔
7
    memoizeWith,
1✔
8
    pathOr,
1✔
9
    pipe,
1✔
10
    prop,
1✔
11
    propEq,
1✔
12
} from "ramda";
1✔
13
import { useContext } from "react";
1✔
14
import { Address, isAddress } from "viem";
1✔
15
import { ConnectionConfigContext } from "./connectionConfigContext";
1✔
16
import { Action, Connection, State, UseSelector } from "./types";
1✔
17

1✔
18
const useSelector: UseSelector = (predicate) => {
1✔
19
    const state = useConnectionConfigState();
32✔
20
    const result = predicate(state);
32✔
21

32✔
22
    return result;
32✔
23
};
32✔
24

1✔
25
const useConnectionConfigState = () => {
1✔
26
    const ctx = useContext(ConnectionConfigContext);
32✔
27
    return ctx.state;
32✔
28
};
32✔
29

1✔
30
const useConnectionConfigDispatcher = () => {
1✔
31
    const ctx = useContext(ConnectionConfigContext);
32✔
32
    return ctx.dispatch;
32✔
33
};
32✔
34

1✔
35
const useConnectionRepository = () => {
1✔
36
    const ctx = useContext(ConnectionConfigContext);
32✔
37
    return ctx.repository;
32✔
38
};
32✔
39

1✔
40
type ActionLifecycle = {
1✔
41
    onSuccess?: () => void;
1✔
42
    onFailure?: (reason?: any) => void;
1✔
43
    onFinished?: () => void;
1✔
44
};
1✔
45

1✔
46
const useConnectionConfigActions = () => {
1✔
47
    const dispatch = useConnectionConfigDispatcher();
32✔
48
    const repository = useConnectionRepository();
32✔
49
    const actions = {
32✔
50
        showConnectionModal(address?: Address) {
32✔
51
            const action: Action = { type: "SHOW_CONNECTION_MODAL" };
×
52
            if (address && isAddress(address)) {
×
53
                action.payload = { address };
×
54
            }
×
55
            dispatch(action);
×
56
        },
×
57
        hideConnectionModal() {
32✔
58
            dispatch({ type: "HIDE_CONNECTION_MODAL" });
×
59
        },
×
60
        addConnection(connection: Connection, opt?: ActionLifecycle) {
32✔
61
            repository
3✔
62
                .add(connection)
3✔
63
                .then(() => {
3✔
64
                    dispatch({
2✔
65
                        type: "ADD_CONNECTION",
2✔
66
                        payload: { connection },
2✔
67
                    });
2✔
68

2✔
69
                    opt?.onSuccess && opt?.onSuccess();
2✔
70
                })
3✔
71
                .catch((reason) => {
3✔
72
                    console.error(
1✔
73
                        `Problem trying to persist/add connection: ${reason}`,
1✔
74
                    );
1✔
75

1✔
76
                    opt?.onFailure && opt.onFailure(reason);
1✔
77
                })
3✔
78
                .finally(() => opt?.onFinished && opt.onFinished());
3✔
79
        },
3✔
80
        removeConnection(address: Address, opt?: ActionLifecycle) {
32✔
81
            repository
3✔
82
                .remove(address)
3✔
83
                .then(() => {
3✔
84
                    dispatch({
2✔
85
                        type: "REMOVE_CONNECTION",
2✔
86
                        payload: { address },
2✔
87
                    });
2✔
88

2✔
89
                    opt?.onSuccess && opt?.onSuccess();
2✔
90
                })
3✔
91
                .catch((reason) => {
3✔
92
                    console.error(
1✔
93
                        `Problem trying to remove connection: ${reason}`,
1✔
94
                    );
1✔
95

1✔
96
                    opt?.onFailure && opt?.onFailure(reason);
1✔
97
                })
3✔
98
                .finally(() => opt?.onFinished && opt.onFinished());
3✔
99
        },
3✔
100
    };
32✔
101

32✔
102
    return actions;
32✔
103
};
32✔
104

1✔
105
const keyGen: (connections: Connection[]) => string = pipe(
1✔
106
    map(prop("address")),
1✔
107
    join("/"),
1✔
108
);
1✔
109
const cache = memoizeWith(keyGen, identity<Connection[]>);
1✔
110

1✔
111
const getConnections: (state: State) => Connection[] = pipe(
1✔
112
    pathOr([], ["connections"]),
1✔
113
    cache,
1✔
114
);
1✔
115

1✔
116
const useConnectionConfig = () => {
1✔
117
    const connections = useSelector(getConnections);
32✔
118
    const {
32✔
119
        addConnection,
32✔
120
        removeConnection,
32✔
121
        hideConnectionModal,
32✔
122
        showConnectionModal,
32✔
123
    } = useConnectionConfigActions();
32✔
124
    const getConnection = (addr: Address) =>
32✔
125
        find(propEq(addr, "address"), connections);
4✔
126
    const hasConnection = (addr: Address) => getConnection(addr) !== undefined;
32✔
127
    const listConnections = () => connections;
32✔
128

32✔
129
    return {
32✔
130
        listConnections,
32✔
131
        getConnection,
32✔
132
        hasConnection,
32✔
133
        addConnection,
32✔
134
        removeConnection,
32✔
135
        hideConnectionModal,
32✔
136
        showConnectionModal,
32✔
137
    };
32✔
138
};
32✔
139

1✔
140
export { useConnectionConfig, useConnectionConfigActions };
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