-
Notifications
You must be signed in to change notification settings - Fork 282
/
useMobileRegistry.ts
39 lines (33 loc) · 991 Bytes
/
useMobileRegistry.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as React from "react";
import { WalletService } from "../types";
type State = {
readonly data: readonly WalletService[]; // TODO
readonly error?: Error;
readonly loading: boolean;
};
const defaultState: State = Object.freeze({
data: [],
error: undefined,
loading: true,
});
export default function useMobileRegistry(): State {
const [state, setState] = React.useState<State>(defaultState);
React.useEffect(() => {
(async () => {
try {
const result = await fetch("https://registry.walletconnect.org/data/wallets.json");
const data = await result.json();
setState({
data: Object.values(data) as readonly WalletService[],
error: undefined,
loading: false,
});
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
setState({ ...defaultState, error: error as any, loading: false });
}
})();
}, [setState]);
return state;
}