@meshsdk/react 1.1.8 → 1.1.10-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "React Hooks & Components you need for building dApps on Cardano.",
|
|
4
4
|
"homepage": "https://meshjs.dev",
|
|
5
5
|
"author": "MeshJS",
|
|
6
|
-
"version": "1.1.
|
|
6
|
+
"version": "1.1.10-beta.1",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"repository": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vite": "3.1.4"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@meshsdk/core": "1.5.
|
|
65
|
+
"@meshsdk/core": "1.5.11-beta.3",
|
|
66
66
|
"react-dom": "17.x || 18.x",
|
|
67
67
|
"react": "17.x || 18.x"
|
|
68
68
|
},
|
|
@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';
|
|
|
3
3
|
import { useWallet, useWalletList } from '@mesh/hooks';
|
|
4
4
|
import { MenuItem } from '../MenuItem';
|
|
5
5
|
import { WalletBalance } from './WalletBalance';
|
|
6
|
+
// import { AppWallet } from '@meshsdk/core';
|
|
6
7
|
|
|
7
8
|
const StyledMenuButton = tw.button`
|
|
8
9
|
flex items-center justify-center
|
|
@@ -24,11 +25,15 @@ const StyledMenuList = styled.div(({ hidden }: { hidden: boolean }) => [
|
|
|
24
25
|
|
|
25
26
|
export const CardanoWallet = ({
|
|
26
27
|
label = 'Connect Wallet',
|
|
27
|
-
onConnected = undefined
|
|
28
|
+
onConnected = undefined,
|
|
29
|
+
isDark = false,
|
|
28
30
|
}: {
|
|
29
|
-
label?: string
|
|
30
|
-
onConnected?: Function
|
|
31
|
+
label?: string;
|
|
32
|
+
onConnected?: Function;
|
|
33
|
+
isDark?: boolean;
|
|
31
34
|
}) => {
|
|
35
|
+
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
36
|
+
|
|
32
37
|
const wallets = useWalletList();
|
|
33
38
|
|
|
34
39
|
const [hideMenuList, setHideMenuList] = useState(true);
|
|
@@ -41,6 +46,37 @@ export const CardanoWallet = ({
|
|
|
41
46
|
}
|
|
42
47
|
}, [connected]);
|
|
43
48
|
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
setIsDarkMode(isDark);
|
|
51
|
+
}, [isDark]);
|
|
52
|
+
|
|
53
|
+
// async function connectLocalWallet() {
|
|
54
|
+
// // check if local has wallet
|
|
55
|
+
|
|
56
|
+
// // if yes, connect to it
|
|
57
|
+
|
|
58
|
+
// // if no, create a new wallet
|
|
59
|
+
// const mnemonic = AppWallet.brew();
|
|
60
|
+
// console.log('mnemonic', mnemonic);
|
|
61
|
+
|
|
62
|
+
// // have to create wallet without provider,
|
|
63
|
+
// // so we can get wallet address,
|
|
64
|
+
// // get keys with wallet info,
|
|
65
|
+
// // add koios provider later
|
|
66
|
+
|
|
67
|
+
// // const wallet = new AppWallet({
|
|
68
|
+
// // networkId: 0,
|
|
69
|
+
// // fetcher: blockchainProvider, // ?? keys? api to get keys, and use koios
|
|
70
|
+
// // submitter: blockchainProvider,
|
|
71
|
+
// // key: {
|
|
72
|
+
// // type: 'mnemonic',
|
|
73
|
+
// // words: mnemonic,
|
|
74
|
+
// // },
|
|
75
|
+
// // });
|
|
76
|
+
|
|
77
|
+
// // save `wallet` to `WalletContext`, so we can use it at `useWallet()`
|
|
78
|
+
// }
|
|
79
|
+
|
|
44
80
|
return (
|
|
45
81
|
<div
|
|
46
82
|
style={{ width: 'fit-content' }}
|
|
@@ -50,6 +86,10 @@ export const CardanoWallet = ({
|
|
|
50
86
|
<StyledMenuButton
|
|
51
87
|
type="button"
|
|
52
88
|
className="mr-wallet-button"
|
|
89
|
+
style={{
|
|
90
|
+
backgroundColor: isDarkMode ? '#1f1f1f' : '#fff',
|
|
91
|
+
color: isDarkMode ? '#fff' : '#000',
|
|
92
|
+
}}
|
|
53
93
|
onClick={() => setHideMenuList(!hideMenuList)}
|
|
54
94
|
>
|
|
55
95
|
<WalletBalance
|
|
@@ -62,20 +102,39 @@ export const CardanoWallet = ({
|
|
|
62
102
|
<StyledMenuList
|
|
63
103
|
hidden={hideMenuList}
|
|
64
104
|
className="mr-menu-list"
|
|
105
|
+
style={{
|
|
106
|
+
backgroundColor: isDarkMode ? '#1f1f1f' : '#fff',
|
|
107
|
+
color: isDarkMode ? '#fff' : '#000',
|
|
108
|
+
}}
|
|
65
109
|
>
|
|
66
110
|
{!connected && wallets.length > 0 ? (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
111
|
+
<>
|
|
112
|
+
{wallets.map((wallet, index) => (
|
|
113
|
+
<MenuItem
|
|
114
|
+
key={index}
|
|
115
|
+
icon={wallet.icon}
|
|
116
|
+
label={wallet.name}
|
|
117
|
+
action={() => {
|
|
118
|
+
connect(wallet.name);
|
|
119
|
+
setHideMenuList(!hideMenuList);
|
|
120
|
+
}}
|
|
121
|
+
active={name === wallet.name}
|
|
122
|
+
/>
|
|
123
|
+
))}
|
|
124
|
+
{/* <MenuItem
|
|
125
|
+
icon={
|
|
126
|
+
isDarkMode
|
|
127
|
+
? `https://meshjs.dev/logo-mesh/white/logo-mesh-white-128x128.png`
|
|
128
|
+
: `https://meshjs.dev/logo-mesh/black/logo-mesh-black-128x128.png`
|
|
129
|
+
}
|
|
130
|
+
label={'Local'}
|
|
72
131
|
action={() => {
|
|
73
|
-
|
|
132
|
+
connectLocalWallet();
|
|
74
133
|
setHideMenuList(!hideMenuList);
|
|
75
134
|
}}
|
|
76
|
-
active={
|
|
77
|
-
/>
|
|
78
|
-
|
|
135
|
+
active={false}
|
|
136
|
+
/> */}
|
|
137
|
+
</>
|
|
79
138
|
) : wallets.length === 0 ? (
|
|
80
139
|
<span>No Wallet Found</span>
|
|
81
140
|
) : (
|
|
@@ -8,6 +8,7 @@ interface WalletContext {
|
|
|
8
8
|
connectingWallet: boolean,
|
|
9
9
|
connectWallet?: (walletName: string) => Promise<void>,
|
|
10
10
|
disconnect?: () => void,
|
|
11
|
+
// setWallet?: () => void,
|
|
11
12
|
error?: unknown,
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -48,6 +49,11 @@ export const useWalletStore = () => {
|
|
|
48
49
|
setConnectedWalletInstance(INITIAL_STATE.walletInstance);
|
|
49
50
|
}, []);
|
|
50
51
|
|
|
52
|
+
// const setWallet = useCallback((wallet: AppWallet) => {
|
|
53
|
+
// setConnectedWalletName(INITIAL_STATE.walletName);
|
|
54
|
+
// setConnectedWalletInstance(wallet);
|
|
55
|
+
// }, []);
|
|
56
|
+
|
|
51
57
|
return {
|
|
52
58
|
hasConnectedWallet: INITIAL_STATE.walletName !== connectedWalletName,
|
|
53
59
|
connectedWalletInstance,
|
|
@@ -55,6 +61,7 @@ export const useWalletStore = () => {
|
|
|
55
61
|
connectingWallet,
|
|
56
62
|
connectWallet,
|
|
57
63
|
disconnect,
|
|
64
|
+
// setWallet,
|
|
58
65
|
error,
|
|
59
66
|
};
|
|
60
67
|
};
|
package/src/contexts/index.tsx
CHANGED
|
@@ -2,9 +2,12 @@ export { WalletContext } from './WalletContext';
|
|
|
2
2
|
|
|
3
3
|
import { useWalletStore, WalletContext } from './WalletContext';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
interface Props {
|
|
6
|
+
children: React.ReactNode
|
|
7
|
+
}
|
|
7
8
|
|
|
9
|
+
export const MeshProvider: React.FC<Props> = ({children}): JSX.Element => {
|
|
10
|
+
const store = useWalletStore();
|
|
8
11
|
return (
|
|
9
12
|
<WalletContext.Provider value={store}>
|
|
10
13
|
{children}
|