-
Notifications
You must be signed in to change notification settings - Fork 3
/
useWallet.js
35 lines (29 loc) · 907 Bytes
/
useWallet.js
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
import React, { useContext } from "react";
import { useEffect, useState } from "react";
import { createContext } from "react";
import { connectWallet } from "./utils/interact";
const WalletContext = createContext({});
const WalletProvider = ({ children }) => {
const [walletAddress, setWallet] = useState("");
const [status, setStatus] = useState("");
useEffect(() => {
const connectWalletPressed = async () => {
const walletResponse = await connectWallet();
setStatus(walletResponse.status);
setWallet(walletResponse.address);
};
console.log(walletAddress);
connectWalletPressed();
}, []);
return (
<WalletContext.Provider
value={{ walletAddress, setStatus, setWallet, connectWallet }}
>
{children}
</WalletContext.Provider>
);
};
export default WalletProvider;
export function useWallet() {
return useContext(WalletContext);
}