@meshsdk/react 1.1.12 → 1.5.28

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.
Files changed (73) hide show
  1. package/README.md +3 -3
  2. package/dist/index.css +718 -0
  3. package/package.json +30 -63
  4. package/.babelrc +0 -6
  5. package/.storybook/main.cjs +0 -18
  6. package/.storybook/preview-head.html +0 -3
  7. package/.storybook/preview.cjs +0 -9
  8. package/dist/components/CardanoWallet/CardanoWallet.d.ts +0 -6
  9. package/dist/components/CardanoWallet/WalletBalance.d.ts +0 -7
  10. package/dist/components/CardanoWallet/index.d.ts +0 -1
  11. package/dist/components/ChevronDown/ChevronDown.d.ts +0 -2
  12. package/dist/components/ChevronDown/index.d.ts +0 -1
  13. package/dist/components/MenuItem/CheckMark.d.ts +0 -2
  14. package/dist/components/MenuItem/MenuItem.d.ts +0 -7
  15. package/dist/components/MenuItem/index.d.ts +0 -1
  16. package/dist/components/MeshBadge/MeshBadge.d.ts +0 -4
  17. package/dist/components/MeshBadge/MeshLogo.d.ts +0 -2
  18. package/dist/components/MeshBadge/index.d.ts +0 -1
  19. package/dist/components/StakeButton/StakeButton.d.ts +0 -5
  20. package/dist/components/StakeButton/index.d.ts +0 -1
  21. package/dist/components/index.d.ts +0 -3
  22. package/dist/contexts/WalletContext.d.ts +0 -22
  23. package/dist/contexts/index.d.ts +0 -6
  24. package/dist/hooks/index.d.ts +0 -9
  25. package/dist/hooks/useAddress.d.ts +0 -1
  26. package/dist/hooks/useAssets.d.ts +0 -2
  27. package/dist/hooks/useLovelace.d.ts +0 -1
  28. package/dist/hooks/useNetwork.d.ts +0 -1
  29. package/dist/hooks/useRewardAddress.d.ts +0 -1
  30. package/dist/hooks/useWallet.d.ts +0 -9
  31. package/dist/hooks/useWalletList.d.ts +0 -2
  32. package/dist/hooks/useWalletSubmit.d.ts +0 -6
  33. package/dist/hooks/useWalletTx.d.ts +0 -6
  34. package/dist/index.d.ts +0 -4
  35. package/dist/react.cjs +0 -100
  36. package/dist/react.js +0 -2501
  37. package/dist/resolvers/index.d.ts +0 -1
  38. package/dist/resolvers/resolveMedia.d.ts +0 -1
  39. package/postcss.config.js +0 -6
  40. package/src/components/CardanoWallet/CardanoWallet.tsx +0 -153
  41. package/src/components/CardanoWallet/WalletBalance.tsx +0 -34
  42. package/src/components/CardanoWallet/index.ts +0 -1
  43. package/src/components/ChevronDown/ChevronDown.tsx +0 -20
  44. package/src/components/ChevronDown/index.ts +0 -1
  45. package/src/components/MenuItem/CheckMark.tsx +0 -13
  46. package/src/components/MenuItem/MenuItem.tsx +0 -41
  47. package/src/components/MenuItem/index.ts +0 -1
  48. package/src/components/MeshBadge/MeshBadge.tsx +0 -23
  49. package/src/components/MeshBadge/MeshLogo.tsx +0 -13
  50. package/src/components/MeshBadge/index.ts +0 -1
  51. package/src/components/StakeButton/StakeButton.tsx +0 -170
  52. package/src/components/StakeButton/index.ts +0 -1
  53. package/src/components/index.ts +0 -3
  54. package/src/contexts/WalletContext.tsx +0 -74
  55. package/src/contexts/index.tsx +0 -19
  56. package/src/hooks/index.ts +0 -9
  57. package/src/hooks/useAddress.ts +0 -23
  58. package/src/hooks/useAssets.ts +0 -21
  59. package/src/hooks/useLovelace.ts +0 -20
  60. package/src/hooks/useNetwork.ts +0 -20
  61. package/src/hooks/useRewardAddress.ts +0 -23
  62. package/src/hooks/useWallet.ts +0 -30
  63. package/src/hooks/useWalletList.ts +0 -13
  64. package/src/hooks/useWalletSubmit.ts +0 -38
  65. package/src/hooks/useWalletTx.ts +0 -29
  66. package/src/index.ts +0 -4
  67. package/src/resolvers/index.ts +0 -1
  68. package/src/resolvers/resolveMedia.ts +0 -34
  69. package/src/types/twin.d.ts +0 -29
  70. package/tailwind.config.cjs +0 -9
  71. package/tsconfig.json +0 -103
  72. package/vite.config.js +0 -43
  73. package/vite.config.js.timestamp-1713618771534.mjs +0 -49
@@ -1 +0,0 @@
1
- export * from './resolveMedia';
@@ -1 +0,0 @@
1
- export declare const resolveMedia: (src: String, ipfsUrl?: string) => string | String;
package/postcss.config.js DELETED
@@ -1,6 +0,0 @@
1
- export default {
2
- plugins: {
3
- tailwindcss: {},
4
- autoprefixer: {},
5
- },
6
- }
@@ -1,153 +0,0 @@
1
- import tw, { styled } from 'twin.macro';
2
- import { useEffect, useState } from 'react';
3
- import { useWallet, useWalletList } from '@mesh/hooks';
4
- import { MenuItem } from '../MenuItem';
5
- import { WalletBalance } from './WalletBalance';
6
- // import { AppWallet } from '@meshsdk/core';
7
-
8
- const StyledMenuButton = tw.button`
9
- flex items-center justify-center
10
- font-normal text-lg
11
- border rounded-t-md
12
- w-60 px-4 py-2
13
- shadow-sm
14
- `;
15
-
16
- const StyledMenuList = styled.div(({ hidden }: { hidden: boolean }) => [
17
- tw`
18
- shadow-sm backdrop-blur
19
- border rounded-b-md
20
- absolute w-60
21
- text-center
22
- `,
23
- hidden && tw`hidden`,
24
- ]);
25
-
26
- export const CardanoWallet = ({
27
- label = 'Connect Wallet',
28
- onConnected = undefined,
29
- isDark = false,
30
- }: {
31
- label?: string;
32
- onConnected?: Function;
33
- isDark?: boolean;
34
- }) => {
35
- const [isDarkMode, setIsDarkMode] = useState(false);
36
-
37
- const wallets = useWalletList();
38
-
39
- const [hideMenuList, setHideMenuList] = useState(true);
40
-
41
- const { connect, connecting, connected, disconnect, name } = useWallet();
42
-
43
- useEffect(() => {
44
- if (connected && onConnected) {
45
- onConnected();
46
- }
47
- }, [connected]);
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
-
80
- return (
81
- <div
82
- style={{ width: 'fit-content' }}
83
- onMouseEnter={() => setHideMenuList(false)}
84
- onMouseLeave={() => setHideMenuList(true)}
85
- >
86
- <StyledMenuButton
87
- type="button"
88
- className="mr-wallet-button"
89
- style={{
90
- backgroundColor: isDarkMode ? '#1f1f1f' : '#fff',
91
- color: isDarkMode ? '#fff' : '#000',
92
- }}
93
- onClick={() => setHideMenuList(!hideMenuList)}
94
- >
95
- <WalletBalance
96
- name={name}
97
- connected={connected}
98
- connecting={connecting}
99
- label={label}
100
- />
101
- </StyledMenuButton>
102
- <StyledMenuList
103
- hidden={hideMenuList}
104
- className="mr-menu-list"
105
- style={{
106
- backgroundColor: isDarkMode ? '#1f1f1f' : '#fff',
107
- color: isDarkMode ? '#fff' : '#000',
108
- }}
109
- >
110
- {!connected && wallets.length > 0 ? (
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'}
131
- action={() => {
132
- connectLocalWallet();
133
- setHideMenuList(!hideMenuList);
134
- }}
135
- active={false}
136
- /> */}
137
- </>
138
- ) : wallets.length === 0 ? (
139
- <span>No Wallet Found</span>
140
- ) : (
141
- <>
142
- <MenuItem
143
- active={false}
144
- label="disconnect"
145
- action={disconnect}
146
- icon={undefined}
147
- />
148
- </>
149
- )}
150
- </StyledMenuList>
151
- </div>
152
- );
153
- };
@@ -1,34 +0,0 @@
1
- import tw from 'twin.macro';
2
- import { useLovelace, useWalletList } from '@mesh/hooks';
3
- import { ChevronDown } from '../ChevronDown';
4
-
5
- const StyledIcon = tw.img`
6
- h-6 m-2
7
- `;
8
-
9
- const StyledSmall = tw.span`
10
- text-xs
11
- `;
12
-
13
- export const WalletBalance = ({ connected, name, connecting, label }) => {
14
- const wallet = useWalletList().find((wallet) => wallet.name === name);
15
- const balance = useLovelace();
16
-
17
- return connected && balance && wallet?.icon ? (
18
- <>
19
- <StyledIcon src={wallet.icon} />₳{' '}
20
- {parseInt((parseInt(balance, 10) / 1_000_000).toString(), 10)}.
21
- <StyledSmall>{balance.substr(balance.length - 6)}</StyledSmall>
22
- </>
23
- ) : connected && wallet?.icon ? (
24
- <>
25
- <StyledIcon src={wallet.icon} />
26
- </>
27
- ) : connecting ? (
28
- <>Connecting...</>
29
- ) : (
30
- <>
31
- {label} <ChevronDown />
32
- </>
33
- );
34
- };
@@ -1 +0,0 @@
1
- export * from './CardanoWallet';
@@ -1,20 +0,0 @@
1
- import tw from 'twin.macro';
2
-
3
- const StyledChevronDown = tw.svg`h-6 m-2`;
4
-
5
- export const ChevronDown = () => (
6
- <StyledChevronDown
7
- fill="none"
8
- aria-hidden="true"
9
- viewBox="0 0 24 24"
10
- stroke="currentColor"
11
- xmlns="http://www.w3.org/2000/svg"
12
- >
13
- <path
14
- strokeLinecap="round"
15
- strokeLinejoin="round"
16
- strokeWidth="2"
17
- d="M19 9l-7 7-7-7"
18
- />
19
- </StyledChevronDown>
20
- );
@@ -1 +0,0 @@
1
- export * from './ChevronDown';
@@ -1,13 +0,0 @@
1
- import tw from 'twin.macro';
2
-
3
- const StyledCheckMark = tw.svg`h-6 m-2`;
4
-
5
- export const CheckMark = () => (
6
- <StyledCheckMark
7
- fill="currentColor"
8
- viewBox="0 0 512 512"
9
- xmlns="http://www.w3.org/2000/svg"
10
- >
11
- <path d="M470.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L192 338.7 425.4 105.4c12.5-12.5 32.8-12.5 45.3 0z" />
12
- </StyledCheckMark>
13
- );
@@ -1,41 +0,0 @@
1
- import tw from 'twin.macro';
2
- import { CheckMark } from './CheckMark';
3
-
4
- const StyledItem = tw.div`
5
- opacity-80 hover:opacity-100
6
- flex items-center
7
- cursor-pointer
8
- px-4 py-2
9
- `;
10
-
11
- const StyledIcon = tw.img`
12
- h-8 m-1 pr-2
13
- `;
14
-
15
- const StyledName = tw.span`
16
- font-normal
17
- text-xl
18
- `;
19
-
20
- const StyledActive = tw.span`
21
- ml-auto
22
- `;
23
-
24
- export const MenuItem = ({ icon, label, action, active }) => (
25
- <StyledItem onClick={action}>
26
- {icon && <StyledIcon src={icon} />}
27
- <StyledName className='mr-menu-item'>
28
- {label
29
- .split(' ')
30
- .map((word: string) => {
31
- return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
32
- })
33
- .join(' ')}
34
- </StyledName>
35
- {active && (
36
- <StyledActive>
37
- <CheckMark />
38
- </StyledActive>
39
- )}
40
- </StyledItem>
41
- );
@@ -1 +0,0 @@
1
- export * from './MenuItem';
@@ -1,23 +0,0 @@
1
- import tw from 'twin.macro';
2
- import { MeshLogo } from './MeshLogo';
3
-
4
- const StyledLink = tw.a`
5
- flex flex-col items-center max-w-fit p-1
6
- border border-current border-solid rounded-md
7
- font-semibold text-xl text-stone-700 no-underline
8
- `;
9
-
10
- export const MeshBadge = ({ dark = false }) => (
11
- <StyledLink
12
- style={{
13
- color: dark ? '#EEEEEE' : '#111111',
14
- backgroundColor: dark ? '#111111' : '#EEEEEE',
15
- }}
16
- href="https://meshjs.dev/"
17
- rel="noopener noreferrer"
18
- target="_blank"
19
- >
20
- <MeshLogo />
21
- Mesh
22
- </StyledLink>
23
- );
@@ -1,13 +0,0 @@
1
- import tw from 'twin.macro';
2
-
3
- const StyledLogo = tw.svg`h-16 p-2`;
4
-
5
- export const MeshLogo = () => (
6
- <StyledLogo
7
- fill="currentColor"
8
- viewBox="0 0 300 200"
9
- xmlns="http://www.w3.org/2000/svg"
10
- >
11
- <path d="m289 127-45-60-45-60c-.9-1.3-2.4-2-4-2s-3.1.7-4 2l-37 49.3c-2 2.7-6 2.7-8 0l-37-49.3c-.9-1.3-2.4-2-4-2s-3.1.7-4 2l-45 60-45 60c-1.3 1.8-1.3 4.2 0 6l45 60c.9 1.3 2.4 2 4 2s3.1-.7 4-2l37-49.3c2-2.7 6-2.7 8 0l37 49.3c.9 1.3 2.4 2 4 2s3.1-.7 4-2l37-49.3c2-2.7 6-2.7 8 0l37 49.3c.9 1.3 2.4 2 4 2s3.1-.7 4-2l45-60c1.3-1.8 1.3-4.2 0-6zm-90-103.3 32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0l-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0zm-90 0 32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0l-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0zm-53 152.6-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0l32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0zm90 0-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0l32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0zm90 0-32.5-43.3c-1.3-1.8-1.3-4.2 0-6l32.5-43.3c2-2.7 6-2.7 8 0l32.5 43.3c1.3 1.8 1.3 4.2 0 6l-32.5 43.3c-2 2.7-6 2.7-8 0z" />
12
- </StyledLogo>
13
- );
@@ -1 +0,0 @@
1
- export * from './MeshBadge';
@@ -1,170 +0,0 @@
1
- import tw, { styled } from 'twin.macro';
2
- import { useEffect, useState } from 'react';
3
- import {
4
- useRewardAddress,
5
- useWallet,
6
- useWalletList,
7
- useWalletTx,
8
- } from '@mesh/hooks';
9
- import { ChevronDown } from '../ChevronDown';
10
- import { MenuItem } from '../MenuItem';
11
- import type { AccountInfo } from '@meshsdk/core';
12
-
13
- const StyledMenuButton = tw.button`
14
- flex items-center justify-center
15
- font-normal text-lg
16
- border rounded-t-md
17
- w-60 px-4 py-2
18
- shadow-sm
19
- `;
20
-
21
- const StyledMenuList = styled.div(({ hidden }: { hidden: boolean }) => [
22
- tw`
23
- shadow-sm backdrop-blur
24
- border rounded-b-md
25
- absolute w-60
26
- text-center
27
- `,
28
- hidden && tw`hidden`,
29
- ]);
30
-
31
- export const StakeButton = ({ poolId, onCheck }) => {
32
- const wallets = useWalletList();
33
-
34
- const [hideMenuList, setHideMenuList] = useState(true);
35
-
36
- const { connect, connecting, connected, name } = useWallet();
37
-
38
- return (
39
- <div
40
- style={{ width: 'fit-content' }}
41
- onMouseEnter={() => setHideMenuList(false)}
42
- onMouseLeave={() => setHideMenuList(true)}
43
- >
44
- <StyledMenuButton
45
- type="button"
46
- onClick={() => setHideMenuList(!hideMenuList)}
47
- >
48
- {connected ? (
49
- <Delegate poolId={poolId} onCheck={onCheck} />
50
- ) : connecting ? (
51
- <>Connecting...</>
52
- ) : (
53
- <>
54
- Connect Wallet <ChevronDown />
55
- </>
56
- )}
57
- </StyledMenuButton>
58
- <StyledMenuList hidden={hideMenuList || connected}>
59
- {wallets.length > 0 ? (
60
- wallets.map((wallet, index) => (
61
- <MenuItem
62
- key={index}
63
- icon={wallet.icon}
64
- label={wallet.name}
65
- action={() => {
66
- connect(wallet.name);
67
- setHideMenuList(!hideMenuList);
68
- }}
69
- active={name === wallet.name}
70
- />
71
- ))
72
- ) : (
73
- <span>No Wallet Found</span>
74
- )}
75
- </StyledMenuList>
76
- </div>
77
- );
78
- };
79
-
80
- const Delegate = ({ poolId, onCheck }) => {
81
- const tx = useWalletTx();
82
- const { wallet } = useWallet();
83
- const rewardAddress = useRewardAddress();
84
- const [error, setError] = useState<unknown>();
85
- const [checking, setChecking] = useState(false);
86
- const [accountInfo, setAccountInfo] = useState<AccountInfo>();
87
- const [processing, setProcessing] = useState(false);
88
- const [done, setDone] = useState(false);
89
-
90
- const checkAccountStatus = async () => {
91
- try {
92
- setChecking(true);
93
-
94
- if (rewardAddress) {
95
- const info = await onCheck(rewardAddress);
96
- setAccountInfo(info);
97
- }
98
-
99
- setChecking(false);
100
- } catch (error) {
101
- setError(error);
102
- }
103
- };
104
-
105
- const registerAddress = async () => {
106
- setProcessing(true);
107
- setDone(false);
108
- try {
109
- if (rewardAddress) {
110
- const unsignedTx = await tx
111
- .registerStake(rewardAddress)
112
- .delegateStake(rewardAddress, poolId)
113
- .build();
114
-
115
- const signedTx = await wallet.signTx(unsignedTx);
116
- const txHash = await wallet.submitTx(signedTx);
117
- console.log('txHash', txHash);
118
- setDone(true);
119
- }
120
- } catch (error) {
121
- console.error('error', error);
122
- setError(error);
123
- }
124
- setProcessing(false);
125
- };
126
-
127
- const delegateStake = async () => {
128
- setProcessing(true);
129
- setDone(false);
130
- try {
131
- if (rewardAddress) {
132
- const unsignedTx = await tx
133
- .delegateStake(rewardAddress, poolId)
134
- .build();
135
-
136
- const signedTx = await wallet.signTx(unsignedTx);
137
- const txHash = await wallet.submitTx(signedTx);
138
- setDone(true);
139
- }
140
- } catch (error) {
141
- console.error('error', error);
142
- setError(error);
143
- }
144
- setProcessing(false);
145
- };
146
-
147
- useEffect(() => {
148
- checkAccountStatus();
149
- }, [rewardAddress]);
150
-
151
- if (checking) {
152
- return <span>Checking...</span>;
153
- }
154
- if (processing) {
155
- return <span>Loading...</span>;
156
- }
157
- if (done) {
158
- return <span>Stake Delegated</span>;
159
- }
160
-
161
- if (accountInfo?.active) {
162
- return accountInfo.poolId === poolId ? (
163
- <span>Stake Delegated</span>
164
- ) : (
165
- <span onClick={delegateStake}>Delegate Stake</span>
166
- );
167
- }
168
-
169
- return <span onClick={registerAddress}>Register Address</span>;
170
- };
@@ -1 +0,0 @@
1
- export * from './StakeButton';
@@ -1,3 +0,0 @@
1
- export * from './CardanoWallet';
2
- export * from './MeshBadge';
3
- export * from './StakeButton';
@@ -1,74 +0,0 @@
1
- import { createContext, useCallback, useState } from 'react';
2
- import { BrowserWallet } from '@meshsdk/core';
3
-
4
- interface WalletContext {
5
- hasConnectedWallet: boolean,
6
- connectedWalletInstance: BrowserWallet,
7
- connectedWalletName: string,
8
- connectingWallet: boolean,
9
- connectWallet?: (walletName: string) => Promise<void>,
10
- disconnect?: () => void,
11
- // setWallet?: () => void,
12
- error?: unknown,
13
- }
14
-
15
- const INITIAL_STATE = {
16
- walletName: '', walletInstance: {} as BrowserWallet,
17
- };
18
-
19
- export const useWalletStore = () => {
20
- const [error, setError] = useState<unknown>(undefined);
21
-
22
- const [connectingWallet, setConnectingWallet] =
23
- useState<boolean>(false);
24
-
25
- const [connectedWalletInstance, setConnectedWalletInstance] =
26
- useState<BrowserWallet>(INITIAL_STATE.walletInstance);
27
-
28
- const [connectedWalletName, setConnectedWalletName] =
29
- useState<string>(INITIAL_STATE.walletName);
30
-
31
- const connectWallet = useCallback(async (walletName: string) => {
32
- setConnectingWallet(true);
33
-
34
- try {
35
- const walletInstance = await BrowserWallet.enable(walletName);
36
- setConnectedWalletInstance(walletInstance);
37
- setConnectedWalletName(walletName);
38
- setError(undefined);
39
- } catch (error) {
40
- setError(error);
41
- console.error(error);
42
- }
43
-
44
- setConnectingWallet(false);
45
- }, []);
46
-
47
- const disconnect = useCallback(() => {
48
- setConnectedWalletName(INITIAL_STATE.walletName);
49
- setConnectedWalletInstance(INITIAL_STATE.walletInstance);
50
- }, []);
51
-
52
- // const setWallet = useCallback((wallet: AppWallet) => {
53
- // setConnectedWalletName(INITIAL_STATE.walletName);
54
- // setConnectedWalletInstance(wallet);
55
- // }, []);
56
-
57
- return {
58
- hasConnectedWallet: INITIAL_STATE.walletName !== connectedWalletName,
59
- connectedWalletInstance,
60
- connectedWalletName,
61
- connectingWallet,
62
- connectWallet,
63
- disconnect,
64
- // setWallet,
65
- error,
66
- };
67
- };
68
-
69
- export const WalletContext = createContext<WalletContext>({
70
- hasConnectedWallet: false,
71
- connectedWalletInstance: INITIAL_STATE.walletInstance,
72
- connectedWalletName: INITIAL_STATE.walletName,
73
- connectingWallet: false,
74
- });
@@ -1,19 +0,0 @@
1
- export { WalletContext } from './WalletContext';
2
-
3
- import { useWalletStore, WalletContext } from './WalletContext';
4
-
5
- interface Props {
6
- children: React.ReactNode;
7
- }
8
-
9
- export const MeshProvider: React.FC<Props> = (
10
- props: any,
11
- deprecatedLegacyContext?: any
12
- ) => {
13
- const store = useWalletStore();
14
- return (
15
- <WalletContext.Provider value={store}>
16
- <>{props.children}</>
17
- </WalletContext.Provider>
18
- );
19
- };
@@ -1,9 +0,0 @@
1
- export * from './useAddress';
2
- export * from './useAssets';
3
- export * from './useWalletList';
4
- export * from './useLovelace';
5
- export * from './useNetwork';
6
- export * from './useRewardAddress';
7
- export * from './useWallet';
8
- export * from './useWalletSubmit';
9
- export * from './useWalletTx';
@@ -1,23 +0,0 @@
1
- import { useContext, useEffect, useState } from 'react';
2
- import { WalletContext } from '@mesh/contexts';
3
-
4
- export const useAddress = (accountId = 0) => {
5
- const [address, setAddress] = useState<string>();
6
- const {
7
- hasConnectedWallet,
8
- connectedWalletName,
9
- connectedWalletInstance,
10
- } = useContext(WalletContext);
11
-
12
- useEffect(() => {
13
- if (hasConnectedWallet) {
14
- connectedWalletInstance.getUsedAddresses().then((addresses) => {
15
- if (addresses[accountId]) {
16
- setAddress(addresses[accountId]);
17
- }
18
- });
19
- }
20
- }, [accountId, connectedWalletName]);
21
-
22
- return address;
23
- };
@@ -1,21 +0,0 @@
1
- import { useContext, useEffect, useState } from 'react';
2
- import { WalletContext } from '@mesh/contexts';
3
- import type { Asset } from '@meshsdk/core';
4
-
5
- export const useAssets = () => {
6
- const [asstes, setAsstes] = useState<Asset[]>();
7
- const {
8
- hasConnectedWallet,
9
- connectedWalletName,
10
- connectedWalletInstance,
11
- } = useContext(WalletContext);
12
-
13
- useEffect(() => {
14
- if (hasConnectedWallet) {
15
- connectedWalletInstance.getAssets()
16
- .then(setAsstes);
17
- }
18
- }, [connectedWalletName]);
19
-
20
- return asstes;
21
- };
@@ -1,20 +0,0 @@
1
- import { useContext, useEffect, useState } from 'react';
2
- import { WalletContext } from '@mesh/contexts';
3
-
4
- export const useLovelace = () => {
5
- const [lovelace, setLovelace] = useState<string>();
6
- const {
7
- hasConnectedWallet,
8
- connectedWalletName,
9
- connectedWalletInstance,
10
- } = useContext(WalletContext);
11
-
12
- useEffect(() => {
13
- if (hasConnectedWallet) {
14
- connectedWalletInstance.getLovelace()
15
- .then(setLovelace);
16
- }
17
- }, [connectedWalletName]);
18
-
19
- return lovelace;
20
- };