@meshsdk/react 1.1.12 → 1.6.0-alpha.11
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/.eslintrc.js +3 -0
- package/README.md +3 -3
- package/package.json +28 -64
- package/postcss.config.js +5 -2
- package/src/{components/MenuItem/CheckMark.tsx → cardano-wallet/checkmark.tsx} +3 -6
- package/src/{components/ChevronDown/ChevronDown.tsx → cardano-wallet/chevron-down.tsx} +3 -6
- package/src/cardano-wallet/index.tsx +106 -0
- package/src/cardano-wallet/menu-item.tsx +28 -0
- package/src/cardano-wallet/wallet-balance.tsx +36 -0
- package/src/common/button.tsx +22 -0
- package/src/contexts/{WalletContext.tsx → WalletContext.ts} +16 -14
- package/src/contexts/index.tsx +3 -6
- package/src/hooks/index.ts +9 -9
- package/src/hooks/useAddress.ts +5 -7
- package/src/hooks/useAssets.ts +10 -12
- package/src/hooks/useLovelace.ts +6 -9
- package/src/hooks/useNetwork.ts +6 -9
- package/src/hooks/useRewardAddress.ts +5 -7
- package/src/hooks/useWallet.ts +4 -3
- package/src/hooks/useWalletList.ts +4 -3
- package/src/hooks/useWalletSubmit.ts +6 -4
- package/src/hooks/useWalletTx.ts +27 -24
- package/src/index.ts +5 -4
- package/src/mesh-badge/index.tsx +17 -0
- package/src/{components/MeshBadge/MeshLogo.tsx → mesh-badge/mesh-logo.tsx} +3 -6
- package/src/stake-button/index.tsx +152 -0
- package/src/styles.css +3 -0
- package/tailwind.config.ts +11 -0
- package/tsconfig.json +4 -99
- package/.babelrc +0 -6
- package/.storybook/main.cjs +0 -18
- package/.storybook/preview-head.html +0 -3
- package/.storybook/preview.cjs +0 -9
- package/dist/components/CardanoWallet/CardanoWallet.d.ts +0 -6
- package/dist/components/CardanoWallet/WalletBalance.d.ts +0 -7
- package/dist/components/CardanoWallet/index.d.ts +0 -1
- package/dist/components/ChevronDown/ChevronDown.d.ts +0 -2
- package/dist/components/ChevronDown/index.d.ts +0 -1
- package/dist/components/MenuItem/CheckMark.d.ts +0 -2
- package/dist/components/MenuItem/MenuItem.d.ts +0 -7
- package/dist/components/MenuItem/index.d.ts +0 -1
- package/dist/components/MeshBadge/MeshBadge.d.ts +0 -4
- package/dist/components/MeshBadge/MeshLogo.d.ts +0 -2
- package/dist/components/MeshBadge/index.d.ts +0 -1
- package/dist/components/StakeButton/StakeButton.d.ts +0 -5
- package/dist/components/StakeButton/index.d.ts +0 -1
- package/dist/components/index.d.ts +0 -3
- package/dist/contexts/WalletContext.d.ts +0 -22
- package/dist/contexts/index.d.ts +0 -6
- package/dist/hooks/index.d.ts +0 -9
- package/dist/hooks/useAddress.d.ts +0 -1
- package/dist/hooks/useAssets.d.ts +0 -2
- package/dist/hooks/useLovelace.d.ts +0 -1
- package/dist/hooks/useNetwork.d.ts +0 -1
- package/dist/hooks/useRewardAddress.d.ts +0 -1
- package/dist/hooks/useWallet.d.ts +0 -9
- package/dist/hooks/useWalletList.d.ts +0 -2
- package/dist/hooks/useWalletSubmit.d.ts +0 -6
- package/dist/hooks/useWalletTx.d.ts +0 -6
- package/dist/index.d.ts +0 -4
- package/dist/react.cjs +0 -100
- package/dist/react.js +0 -2501
- package/dist/resolvers/index.d.ts +0 -1
- package/dist/resolvers/resolveMedia.d.ts +0 -1
- package/src/components/CardanoWallet/CardanoWallet.tsx +0 -153
- package/src/components/CardanoWallet/WalletBalance.tsx +0 -34
- package/src/components/CardanoWallet/index.ts +0 -1
- package/src/components/ChevronDown/index.ts +0 -1
- package/src/components/MenuItem/MenuItem.tsx +0 -41
- package/src/components/MenuItem/index.ts +0 -1
- package/src/components/MeshBadge/MeshBadge.tsx +0 -23
- package/src/components/MeshBadge/index.ts +0 -1
- package/src/components/StakeButton/StakeButton.tsx +0 -170
- package/src/components/StakeButton/index.ts +0 -1
- package/src/components/index.ts +0 -3
- package/src/resolvers/index.ts +0 -1
- package/src/resolvers/resolveMedia.ts +0 -34
- package/src/types/twin.d.ts +0 -29
- package/tailwind.config.cjs +0 -9
- package/vite.config.js +0 -43
- package/vite.config.js.timestamp-1713618771534.mjs +0 -49
package/.eslintrc.js
ADDED
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
# mesh-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React component library - [meshjs.dev/react](https://meshjs.dev/react)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[meshjs.dev](https://meshjs.dev/)
|
package/package.json
CHANGED
|
@@ -1,72 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/react",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
"version": "1.1.12",
|
|
7
|
-
"license": "Apache-2.0",
|
|
8
|
-
"type": "module",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/MeshJS/mesh.git"
|
|
12
|
-
},
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/MeshJS/mesh/issues"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"blockchain",
|
|
18
|
-
"cardano",
|
|
19
|
-
"react"
|
|
3
|
+
"version": "1.6.0-alpha.11",
|
|
4
|
+
"sideEffects": [
|
|
5
|
+
"**/*.css"
|
|
20
6
|
],
|
|
21
|
-
"main": "dist/react.cjs",
|
|
22
|
-
"module": "dist/react.js",
|
|
23
|
-
"typings": "dist/index.d.ts",
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "vite build",
|
|
26
|
-
"dev": "start-storybook -p 6006"
|
|
27
|
-
},
|
|
28
7
|
"exports": {
|
|
29
|
-
".":
|
|
30
|
-
|
|
31
|
-
"import": "./dist/react.js",
|
|
32
|
-
"require": "./dist/react.cjs"
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"babelMacros": {
|
|
36
|
-
"twin": {
|
|
37
|
-
"config": "./tailwind.config.cjs",
|
|
38
|
-
"preset": "styled-components"
|
|
39
|
-
}
|
|
8
|
+
"./styles.css": "./dist/index.css",
|
|
9
|
+
".": "./src/index.ts"
|
|
40
10
|
},
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"@storybook/builder-vite": "0.2.5",
|
|
50
|
-
"@storybook/react": "6.5.13",
|
|
51
|
-
"@storybook/testing-library": "0.0.13",
|
|
52
|
-
"@types/styled-components": "5.1.26",
|
|
53
|
-
"@vitejs/plugin-react": "2.2.0",
|
|
54
|
-
"autoprefixer": "10.4.12",
|
|
55
|
-
"babel-loader": "8.2.5",
|
|
56
|
-
"babel-plugin-macros": "3.1.0",
|
|
57
|
-
"babel-plugin-styled-components": "2.0.7",
|
|
58
|
-
"postcss": "8.4.18",
|
|
59
|
-
"rollup": "3.2.3",
|
|
60
|
-
"tailwindcss": "3.2.1",
|
|
61
|
-
"twin.macro": "3.0.0-rc.5",
|
|
62
|
-
"vite": "3.1.4"
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build:mesh": "tailwindcss -i ./src/styles.css -o ./dist/index.css",
|
|
14
|
+
"lint": "eslint",
|
|
15
|
+
"dev": "tailwindcss -i ./src/styles.css -o ./dist/index.css --watch",
|
|
16
|
+
"type-check": "tsc --noEmit",
|
|
17
|
+
"clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
|
|
18
|
+
"format": "prettier --check . --ignore-path ../../.gitignore"
|
|
63
19
|
},
|
|
64
20
|
"peerDependencies": {
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
|
|
21
|
+
"react": "^18.2.0",
|
|
22
|
+
"@meshsdk/transaction": "*"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@meshsdk/eslint-config": "*",
|
|
26
|
+
"@meshsdk/tailwind-config": "*",
|
|
27
|
+
"@meshsdk/typescript-config": "*",
|
|
28
|
+
"@types/react": "^18.2.61",
|
|
29
|
+
"autoprefixer": "^10.4.18",
|
|
30
|
+
"postcss": "^8.4.35",
|
|
31
|
+
"react": "^18.2.0",
|
|
32
|
+
"tailwindcss": "^3.4.1",
|
|
33
|
+
"typescript": "latest"
|
|
68
34
|
},
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
}
|
|
35
|
+
"prettier": "@meshsdk/prettier-config"
|
|
36
|
+
}
|
package/postcss.config.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import tw from 'twin.macro';
|
|
2
|
-
|
|
3
|
-
const StyledCheckMark = tw.svg`h-6 m-2`;
|
|
4
|
-
|
|
5
1
|
export const CheckMark = () => (
|
|
6
|
-
<
|
|
2
|
+
<svg
|
|
3
|
+
className="ui-m-2 ui-h-6"
|
|
7
4
|
fill="currentColor"
|
|
8
5
|
viewBox="0 0 512 512"
|
|
9
6
|
xmlns="http://www.w3.org/2000/svg"
|
|
10
7
|
>
|
|
11
8
|
<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
|
-
</
|
|
9
|
+
</svg>
|
|
13
10
|
);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import tw from 'twin.macro';
|
|
2
|
-
|
|
3
|
-
const StyledChevronDown = tw.svg`h-6 m-2`;
|
|
4
|
-
|
|
5
1
|
export const ChevronDown = () => (
|
|
6
|
-
<
|
|
2
|
+
<svg
|
|
3
|
+
className="ui-m-2 ui-h-6"
|
|
7
4
|
fill="none"
|
|
8
5
|
aria-hidden="true"
|
|
9
6
|
viewBox="0 0 24 24"
|
|
@@ -16,5 +13,5 @@ export const ChevronDown = () => (
|
|
|
16
13
|
strokeWidth="2"
|
|
17
14
|
d="M19 9l-7 7-7-7"
|
|
18
15
|
/>
|
|
19
|
-
</
|
|
16
|
+
</svg>
|
|
20
17
|
);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { Wallet } from "@meshsdk/common";
|
|
4
|
+
import { BrowserWallet } from "@meshsdk/core";
|
|
5
|
+
|
|
6
|
+
import Button from "../common/button";
|
|
7
|
+
import { useWallet } from "../hooks";
|
|
8
|
+
import { MenuItem } from "./menu-item";
|
|
9
|
+
import { WalletBalance } from "./wallet-balance";
|
|
10
|
+
|
|
11
|
+
interface ButtonProps {
|
|
12
|
+
label?: string;
|
|
13
|
+
onConnected?: Function;
|
|
14
|
+
isDark?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const CardanoWallet = ({
|
|
18
|
+
label = "Connect Wallet",
|
|
19
|
+
onConnected = undefined,
|
|
20
|
+
isDark = false,
|
|
21
|
+
}: ButtonProps) => {
|
|
22
|
+
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
23
|
+
const [hideMenuList, setHideMenuList] = useState(true);
|
|
24
|
+
const [wallets, setWallets] = useState<Wallet[]>([]);
|
|
25
|
+
|
|
26
|
+
const { connect, connecting, connected, disconnect, name } = useWallet();
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (connected && onConnected) {
|
|
30
|
+
onConnected();
|
|
31
|
+
}
|
|
32
|
+
}, [connected]);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
setWallets(BrowserWallet.getInstalledWallets());
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
setIsDarkMode(isDark);
|
|
40
|
+
}, [isDark]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
className="w-fit"
|
|
45
|
+
onMouseEnter={() => setHideMenuList(false)}
|
|
46
|
+
onMouseLeave={() => setHideMenuList(true)}
|
|
47
|
+
>
|
|
48
|
+
<Button
|
|
49
|
+
isDarkMode={isDarkMode}
|
|
50
|
+
hideMenuList={hideMenuList}
|
|
51
|
+
setHideMenuList={setHideMenuList}
|
|
52
|
+
>
|
|
53
|
+
<WalletBalance
|
|
54
|
+
connected={connected}
|
|
55
|
+
connecting={connecting}
|
|
56
|
+
label={label}
|
|
57
|
+
wallet={wallets.find((wallet) => wallet.name === name)}
|
|
58
|
+
/>
|
|
59
|
+
</Button>
|
|
60
|
+
<div
|
|
61
|
+
className={`ui-mr-menu-list ui-absolute ui-w-60 ui-rounded-b-md ui-border ui-text-center ui-shadow-sm ui-backdrop-blur ${hideMenuList && "ui-hidden"} ${isDarkMode ? `ui-bg-neutral-950 ui-text-neutral-50` : `ui-bg-neutral-50 ui-text-neutral-950`}`}
|
|
62
|
+
>
|
|
63
|
+
{!connected && wallets.length > 0 ? (
|
|
64
|
+
<>
|
|
65
|
+
{wallets.map((wallet, index) => (
|
|
66
|
+
<MenuItem
|
|
67
|
+
key={index}
|
|
68
|
+
icon={wallet.icon}
|
|
69
|
+
label={wallet.name}
|
|
70
|
+
action={() => {
|
|
71
|
+
connect(wallet.name);
|
|
72
|
+
setHideMenuList(!hideMenuList);
|
|
73
|
+
}}
|
|
74
|
+
active={name === wallet.name}
|
|
75
|
+
/>
|
|
76
|
+
))}
|
|
77
|
+
{/* <MenuItem
|
|
78
|
+
icon={
|
|
79
|
+
isDarkMode
|
|
80
|
+
? `https://meshjs.dev/logo-mesh/white/logo-mesh-white-128x128.png`
|
|
81
|
+
: `https://meshjs.dev/logo-mesh/black/logo-mesh-black-128x128.png`
|
|
82
|
+
}
|
|
83
|
+
label={'Local'}
|
|
84
|
+
action={() => {
|
|
85
|
+
connectLocalWallet();
|
|
86
|
+
setHideMenuList(!hideMenuList);
|
|
87
|
+
}}
|
|
88
|
+
active={false}
|
|
89
|
+
/> */}
|
|
90
|
+
</>
|
|
91
|
+
) : wallets.length === 0 ? (
|
|
92
|
+
<span>No Wallet Found</span>
|
|
93
|
+
) : (
|
|
94
|
+
<>
|
|
95
|
+
<MenuItem
|
|
96
|
+
active={false}
|
|
97
|
+
label="disconnect"
|
|
98
|
+
action={disconnect}
|
|
99
|
+
icon={undefined}
|
|
100
|
+
/>
|
|
101
|
+
</>
|
|
102
|
+
)}
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function MenuItem({
|
|
2
|
+
icon,
|
|
3
|
+
label,
|
|
4
|
+
action,
|
|
5
|
+
active,
|
|
6
|
+
}: {
|
|
7
|
+
icon?: string;
|
|
8
|
+
label: string;
|
|
9
|
+
action: () => void;
|
|
10
|
+
active: boolean;
|
|
11
|
+
}) {
|
|
12
|
+
return (
|
|
13
|
+
<div
|
|
14
|
+
className="ui-flex ui-cursor-pointer ui-items-center ui-px-4 ui-py-2 ui-opacity-80 hover:ui-opacity-100 ui-h-16"
|
|
15
|
+
onClick={action}
|
|
16
|
+
>
|
|
17
|
+
{icon && <img className="ui-pr-2 m-1 h-8" src={icon} />}
|
|
18
|
+
<span className="ui-mr-menu-item ui-text-xl ui-font-normal">
|
|
19
|
+
{label
|
|
20
|
+
.split(" ")
|
|
21
|
+
.map((word: string) => {
|
|
22
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
23
|
+
})
|
|
24
|
+
.join(" ")}
|
|
25
|
+
</span>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Wallet } from "@meshsdk/common";
|
|
2
|
+
import { useLovelace } from "@meshsdk/react";
|
|
3
|
+
|
|
4
|
+
import { ChevronDown } from "./chevron-down";
|
|
5
|
+
|
|
6
|
+
export const WalletBalance = ({
|
|
7
|
+
connected,
|
|
8
|
+
connecting,
|
|
9
|
+
label,
|
|
10
|
+
wallet,
|
|
11
|
+
}: {
|
|
12
|
+
connected: boolean;
|
|
13
|
+
connecting: boolean;
|
|
14
|
+
label: string;
|
|
15
|
+
wallet: Wallet | undefined;
|
|
16
|
+
}) => {
|
|
17
|
+
const lovelace = useLovelace();
|
|
18
|
+
|
|
19
|
+
return connected && lovelace && wallet?.icon ? (
|
|
20
|
+
<>
|
|
21
|
+
<img className="ui-m-2 ui-h-6" src={wallet.icon} />₳{" "}
|
|
22
|
+
{parseInt((parseInt(lovelace, 10) / 1_000_000).toString(), 10)}.
|
|
23
|
+
<span className="text-xs">{lovelace.substring(lovelace.length - 6)}</span>
|
|
24
|
+
</>
|
|
25
|
+
) : connected && wallet?.icon ? (
|
|
26
|
+
<>
|
|
27
|
+
<img className="ui-m-2 ui-h-6" src={wallet.icon} />
|
|
28
|
+
</>
|
|
29
|
+
) : connecting ? (
|
|
30
|
+
<>Connecting...</>
|
|
31
|
+
) : (
|
|
32
|
+
<>
|
|
33
|
+
{label} <ChevronDown />
|
|
34
|
+
</>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
export default function Button({
|
|
4
|
+
children,
|
|
5
|
+
isDarkMode = false,
|
|
6
|
+
hideMenuList = false,
|
|
7
|
+
setHideMenuList,
|
|
8
|
+
}: {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
isDarkMode?: boolean;
|
|
11
|
+
hideMenuList?: boolean;
|
|
12
|
+
setHideMenuList?: (hideMenuList: boolean) => void;
|
|
13
|
+
}) {
|
|
14
|
+
return (
|
|
15
|
+
<button
|
|
16
|
+
className={`ui-mr-menu-list ui-flex ui-w-60 ui-items-center ui-justify-center ui-rounded-t-md ui-border ui-px-4 ui-py-2 ui-text-lg ui-font-normal ui-shadow-sm ${isDarkMode ? `ui-bg-neutral-950 ui-text-neutral-50` : `ui-bg-neutral-50 ui-text-neutral-950`}`}
|
|
17
|
+
onClick={() => setHideMenuList && setHideMenuList(!hideMenuList)}
|
|
18
|
+
>
|
|
19
|
+
{children}
|
|
20
|
+
</button>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
import { createContext, useCallback, useState } from
|
|
2
|
-
|
|
1
|
+
import { createContext, useCallback, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { BrowserWallet } from "@meshsdk/wallet";
|
|
3
4
|
|
|
4
5
|
interface WalletContext {
|
|
5
|
-
hasConnectedWallet: boolean
|
|
6
|
-
connectedWalletInstance: BrowserWallet
|
|
7
|
-
connectedWalletName: string
|
|
8
|
-
connectingWallet: boolean
|
|
9
|
-
connectWallet?: (walletName: string) => Promise<void
|
|
10
|
-
disconnect?: () => void
|
|
6
|
+
hasConnectedWallet: boolean;
|
|
7
|
+
connectedWalletInstance: BrowserWallet;
|
|
8
|
+
connectedWalletName: string;
|
|
9
|
+
connectingWallet: boolean;
|
|
10
|
+
connectWallet?: (walletName: string) => Promise<void>;
|
|
11
|
+
disconnect?: () => void;
|
|
11
12
|
// setWallet?: () => void,
|
|
12
|
-
error?: unknown
|
|
13
|
+
error?: unknown;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const INITIAL_STATE = {
|
|
16
|
-
walletName:
|
|
17
|
+
walletName: "",
|
|
18
|
+
walletInstance: {} as BrowserWallet,
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export const useWalletStore = () => {
|
|
20
22
|
const [error, setError] = useState<unknown>(undefined);
|
|
21
23
|
|
|
22
|
-
const [connectingWallet, setConnectingWallet] =
|
|
23
|
-
useState<boolean>(false);
|
|
24
|
+
const [connectingWallet, setConnectingWallet] = useState<boolean>(false);
|
|
24
25
|
|
|
25
26
|
const [connectedWalletInstance, setConnectedWalletInstance] =
|
|
26
27
|
useState<BrowserWallet>(INITIAL_STATE.walletInstance);
|
|
27
28
|
|
|
28
|
-
const [connectedWalletName, setConnectedWalletName] =
|
|
29
|
-
|
|
29
|
+
const [connectedWalletName, setConnectedWalletName] = useState<string>(
|
|
30
|
+
INITIAL_STATE.walletName,
|
|
31
|
+
);
|
|
30
32
|
|
|
31
33
|
const connectWallet = useCallback(async (walletName: string) => {
|
|
32
34
|
setConnectingWallet(true);
|
package/src/contexts/index.tsx
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { useWalletStore, WalletContext } from "./WalletContext";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export { WalletContext } from "./WalletContext";
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
6
|
children: React.ReactNode;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const MeshProvider: React.FC<Props> = (
|
|
10
|
-
props: any,
|
|
11
|
-
deprecatedLegacyContext?: any
|
|
12
|
-
) => {
|
|
9
|
+
export const MeshProvider: React.FC<Props> = (props: any) => {
|
|
13
10
|
const store = useWalletStore();
|
|
14
11
|
return (
|
|
15
12
|
<WalletContext.Provider value={store}>
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
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";
|
package/src/hooks/useAddress.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { useContext, useEffect, useState } from
|
|
2
|
-
|
|
1
|
+
import { useContext, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { WalletContext } from "../contexts";
|
|
3
4
|
|
|
4
5
|
export const useAddress = (accountId = 0) => {
|
|
5
6
|
const [address, setAddress] = useState<string>();
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
connectedWalletName,
|
|
9
|
-
connectedWalletInstance,
|
|
10
|
-
} = useContext(WalletContext);
|
|
7
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } =
|
|
8
|
+
useContext(WalletContext);
|
|
11
9
|
|
|
12
10
|
useEffect(() => {
|
|
13
11
|
if (hasConnectedWallet) {
|
package/src/hooks/useAssets.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { useContext, useEffect, useState } from
|
|
2
|
-
|
|
3
|
-
import type { Asset } from
|
|
1
|
+
import { useContext, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import type { Asset } from "@meshsdk/common";
|
|
4
|
+
|
|
5
|
+
import { WalletContext } from "../contexts";
|
|
4
6
|
|
|
5
7
|
export const useAssets = () => {
|
|
6
|
-
const [
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
connectedWalletName,
|
|
10
|
-
connectedWalletInstance,
|
|
11
|
-
} = useContext(WalletContext);
|
|
8
|
+
const [assets, setAssets] = useState<Asset[]>();
|
|
9
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } =
|
|
10
|
+
useContext(WalletContext);
|
|
12
11
|
|
|
13
12
|
useEffect(() => {
|
|
14
13
|
if (hasConnectedWallet) {
|
|
15
|
-
connectedWalletInstance.getAssets()
|
|
16
|
-
.then(setAsstes);
|
|
14
|
+
connectedWalletInstance.getAssets().then(setAssets);
|
|
17
15
|
}
|
|
18
16
|
}, [connectedWalletName]);
|
|
19
17
|
|
|
20
|
-
return
|
|
18
|
+
return assets;
|
|
21
19
|
};
|
package/src/hooks/useLovelace.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { useContext, useEffect, useState } from
|
|
2
|
-
|
|
1
|
+
import { useContext, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { WalletContext } from "../contexts";
|
|
3
4
|
|
|
4
5
|
export const useLovelace = () => {
|
|
5
6
|
const [lovelace, setLovelace] = useState<string>();
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
connectedWalletName,
|
|
9
|
-
connectedWalletInstance,
|
|
10
|
-
} = useContext(WalletContext);
|
|
7
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } =
|
|
8
|
+
useContext(WalletContext);
|
|
11
9
|
|
|
12
10
|
useEffect(() => {
|
|
13
11
|
if (hasConnectedWallet) {
|
|
14
|
-
connectedWalletInstance.getLovelace()
|
|
15
|
-
.then(setLovelace);
|
|
12
|
+
connectedWalletInstance.getLovelace().then(setLovelace);
|
|
16
13
|
}
|
|
17
14
|
}, [connectedWalletName]);
|
|
18
15
|
|
package/src/hooks/useNetwork.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { useContext, useEffect, useState } from
|
|
2
|
-
|
|
1
|
+
import { useContext, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { WalletContext } from "../contexts";
|
|
3
4
|
|
|
4
5
|
export const useNetwork = () => {
|
|
5
6
|
const [networkId, setNetworkId] = useState<number>();
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
connectedWalletName,
|
|
9
|
-
connectedWalletInstance,
|
|
10
|
-
} = useContext(WalletContext);
|
|
7
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } =
|
|
8
|
+
useContext(WalletContext);
|
|
11
9
|
|
|
12
10
|
useEffect(() => {
|
|
13
11
|
if (hasConnectedWallet) {
|
|
14
|
-
connectedWalletInstance.getNetworkId()
|
|
15
|
-
.then(setNetworkId);
|
|
12
|
+
connectedWalletInstance.getNetworkId().then(setNetworkId);
|
|
16
13
|
}
|
|
17
14
|
}, [connectedWalletName]);
|
|
18
15
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { useContext, useEffect, useState } from
|
|
2
|
-
|
|
1
|
+
import { useContext, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { WalletContext } from "../contexts";
|
|
3
4
|
|
|
4
5
|
export const useRewardAddress = (accountId = 0) => {
|
|
5
6
|
const [rewardAddress, setRewardAddress] = useState<string>();
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
connectedWalletName,
|
|
9
|
-
connectedWalletInstance,
|
|
10
|
-
} = useContext(WalletContext);
|
|
7
|
+
const { hasConnectedWallet, connectedWalletName, connectedWalletInstance } =
|
|
8
|
+
useContext(WalletContext);
|
|
11
9
|
|
|
12
10
|
useEffect(() => {
|
|
13
11
|
if (hasConnectedWallet) {
|
package/src/hooks/useWallet.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
|
|
3
|
+
import { WalletContext } from "../contexts";
|
|
3
4
|
|
|
4
5
|
export const useWallet = () => {
|
|
5
6
|
const {
|
|
@@ -14,7 +15,7 @@ export const useWallet = () => {
|
|
|
14
15
|
|
|
15
16
|
if (connectWallet === undefined || disconnect === undefined) {
|
|
16
17
|
throw new Error(
|
|
17
|
-
|
|
18
|
+
"Can't call useWallet outside of the WalletProvider context",
|
|
18
19
|
);
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { useEffect, useState } from
|
|
2
|
-
|
|
3
|
-
import type { Wallet } from
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import type { Wallet } from "@meshsdk/common";
|
|
4
|
+
import { BrowserWallet } from "@meshsdk/wallet";
|
|
4
5
|
|
|
5
6
|
export const useWalletList = () => {
|
|
6
7
|
const [wallets, setWallets] = useState<Wallet[]>([]);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useCallback, useContext, useState } from
|
|
2
|
-
|
|
1
|
+
import { useCallback, useContext, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { WalletContext } from "../contexts";
|
|
3
4
|
|
|
4
5
|
export const useWalletSubmit = () => {
|
|
5
6
|
const [error, setError] = useState<unknown>();
|
|
@@ -20,7 +21,7 @@ export const useWalletSubmit = () => {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
throw new Error(
|
|
23
|
-
|
|
24
|
+
"Please make sure to connect a wallet before calling useWalletSubmit",
|
|
24
25
|
);
|
|
25
26
|
} catch (error) {
|
|
26
27
|
setError(error);
|
|
@@ -31,7 +32,8 @@ export const useWalletSubmit = () => {
|
|
|
31
32
|
}, []);
|
|
32
33
|
|
|
33
34
|
return {
|
|
34
|
-
error,
|
|
35
|
+
error,
|
|
36
|
+
result,
|
|
35
37
|
submitting,
|
|
36
38
|
submitTx,
|
|
37
39
|
};
|