@fedimint/react 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -1,30 +1,73 @@
1
- # React + TypeScript + Vite
1
+ <p align="center">
2
+ <img src="../../docs/public/icon.png" alt="Fedimint Logo" width="300" />
3
+ <!-- Removes the border below the header tag -->
4
+ <div id="toc"><ul align="center" style="list-style: none;"><summary>
5
+ <h1><b>@fedimint/react</b></h1>
6
+ <p>Helpful React hooks for building with the Fedimint Web SDK.</p>
7
+ </summary></ul></div>
2
8
 
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
9
+ # @fedimint/react
4
10
 
5
- Currently, two official plugins are available:
11
+ ## Install
6
12
 
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
13
+ ```bash
14
+ pnpm install @fedimint/core-web @fedimint/react
15
+ ```
9
16
 
10
- ## Expanding the ESLint configuration
17
+ ## Usage
11
18
 
12
- If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
19
+ ```tsx
20
+ import { FedimintWalletProvider, setupFedimintWallet } from '@fedimint/react'
13
21
 
14
- - Configure the top-level `parserOptions` property like this:
22
+ setupFedimintWallet({
23
+ lazy: false,
24
+ debug: true,
25
+ })
15
26
 
16
- ```js
17
- export default {
18
- // other rules...
19
- parserOptions: {
20
- ecmaVersion: 'latest',
21
- sourceType: 'module',
22
- project: ['./tsconfig.json', './tsconfig.node.json'],
23
- tsconfigRootDir: __dirname,
24
- },
25
- }
26
- ```
27
+ // Wrap your app in the FedimintWalletProvider
28
+ <FedimintWalletProvider>
29
+ <App />
30
+ </FedimintWalletProvider>
31
+
32
+
33
+ // App.tsx
34
+
35
+
36
+ // Balance
37
+
38
+ import { useBalance } from '@fedimint/react'
39
+
40
+ const balance = useBalance()
41
+
42
+ // Wallet
27
43
 
28
- - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
29
- - Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
30
- - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
44
+ import { useOpenWallet } from '@fedimint/react'
45
+
46
+ const {
47
+ walletStatus, // 'open' | 'closed' | 'connecting' | 'failed'
48
+ openWallet, // () => Promise<boolean> - Returns true if wallet was opened successfully.
49
+ joinFederation, // () => Promise<boolean> - Returns true if joined federation successfully.
50
+ } = useOpenWallet()
51
+
52
+ // Receive Lightning
53
+
54
+ import { useReceiveLightning } from '@fedimint/react'
55
+
56
+ const {
57
+ generateInvoice, // (amount: number) => Promise<void>
58
+ bolt11, // string
59
+ invoiceStatus, // 'pending' | 'confirmed' | 'failed'
60
+ error, // Error | undefined
61
+ } = useReceiveLightning()
62
+
63
+ // Send Lightning
64
+
65
+ import { useSendLightning } from '@fedimint/react'
66
+
67
+ const {
68
+ payInvoice, // (bolt11: string) => Promise<void>
69
+ paymentStatus, // 'pending' | 'confirmed' | 'failed'
70
+ paymentError, // Error | undefined
71
+ } = useSendLightning()
72
+
73
+ ```
@@ -1,7 +1,6 @@
1
- import { useBalance } from './useBalance';
2
- import { useOpenWallet } from './useOpenWallet';
3
- import { useFedimintWallet } from './useFedimintWallet';
4
- import { useReceiveLightning } from './useReceiveLightning';
5
- import { useSendLightning } from './useSendLightning';
6
- export { useBalance, useOpenWallet, useFedimintWallet, useReceiveLightning, useSendLightning, };
1
+ export { useBalance } from './useBalance';
2
+ export { useOpenWallet } from './useOpenWallet';
3
+ export { useFedimintWallet } from './useFedimintWallet';
4
+ export { useReceiveLightning } from './useReceiveLightning';
5
+ export { useSendLightning } from './useSendLightning';
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EACL,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,37 @@
1
+ import { FedimintWallet } from '@fedimint/core-web'
2
+ import { createContext, createElement } from 'react'
3
+
4
+ let wallet: FedimintWallet
5
+
6
+ type FedimintWalletConfig = {
7
+ lazy?: boolean
8
+ debug?: boolean
9
+ }
10
+
11
+ export const setupFedimintWallet = (config: FedimintWalletConfig) => {
12
+ wallet = new FedimintWallet(!!config.lazy)
13
+ if (config.debug) {
14
+ wallet.setLogLevel('debug')
15
+ }
16
+ }
17
+
18
+ export const FedimintWalletContext = createContext<
19
+ { wallet: FedimintWallet } | undefined
20
+ >(undefined)
21
+
22
+ export type FedimintWalletProviderProps = {}
23
+
24
+ export const FedimintWalletProvider = (
25
+ parameters: React.PropsWithChildren<FedimintWalletProviderProps>,
26
+ ) => {
27
+ const { children } = parameters
28
+
29
+ if (!wallet)
30
+ throw new Error(
31
+ 'You must call setupFedimintWallet() first. See the getting started guide.',
32
+ )
33
+
34
+ const props = { value: { wallet } }
35
+
36
+ return createElement(FedimintWalletContext.Provider, props, children)
37
+ }
@@ -0,0 +1,7 @@
1
+ import {
2
+ FedimintWalletContext,
3
+ FedimintWalletProvider,
4
+ setupFedimintWallet,
5
+ } from './FedimintWalletContext'
6
+
7
+ export { FedimintWalletContext, FedimintWalletProvider, setupFedimintWallet }
@@ -0,0 +1,5 @@
1
+ export { useBalance } from './useBalance'
2
+ export { useOpenWallet } from './useOpenWallet'
3
+ export { useFedimintWallet } from './useFedimintWallet'
4
+ export { useReceiveLightning } from './useReceiveLightning'
5
+ export { useSendLightning } from './useSendLightning'
@@ -0,0 +1,22 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { useFedimintWallet, useOpenWallet } from '.'
3
+
4
+ export const useBalance = () => {
5
+ const wallet = useFedimintWallet()
6
+ const { walletStatus } = useOpenWallet()
7
+ const [balance, setBalance] = useState<number>()
8
+
9
+ useEffect(() => {
10
+ if (walletStatus !== 'open') return
11
+
12
+ const unsubscribe = wallet.balance.subscribeBalance((balance) => {
13
+ setBalance(balance)
14
+ })
15
+
16
+ return () => {
17
+ unsubscribe()
18
+ }
19
+ }, [walletStatus])
20
+
21
+ return balance
22
+ }
@@ -0,0 +1,12 @@
1
+ import { useContext } from 'react'
2
+ import { FedimintWalletContext } from '../contexts'
3
+
4
+ export const useFedimintWallet = () => {
5
+ const value = useContext(FedimintWalletContext)
6
+ if (!value?.wallet) {
7
+ throw new Error(
8
+ 'useFedimintWallet must be used within a FedimintWalletProvider',
9
+ )
10
+ }
11
+ return value.wallet
12
+ }
@@ -0,0 +1,42 @@
1
+ import { useCallback, useEffect, useState } from 'react'
2
+ import { useFedimintWallet } from '.'
3
+
4
+ type WalletStatus = 'open' | 'closed' | 'opening'
5
+
6
+ export const useOpenWallet = () => {
7
+ const wallet = useFedimintWallet()
8
+ const [walletStatus, setWalletStatus] = useState<WalletStatus>()
9
+
10
+ const openWallet = useCallback(() => {
11
+ if (walletStatus === 'open') return
12
+
13
+ setWalletStatus('opening')
14
+ wallet.open().then((res) => {
15
+ setWalletStatus(res ? 'open' : 'closed')
16
+ })
17
+ }, [wallet])
18
+
19
+ const joinFederation = useCallback(
20
+ async (invite: string) => {
21
+ if (walletStatus === 'open') return
22
+
23
+ setWalletStatus('opening')
24
+
25
+ const res = await wallet.joinFederation(invite)
26
+ setWalletStatus(res ? 'open' : 'closed')
27
+ },
28
+ [wallet],
29
+ )
30
+
31
+ useEffect(() => {
32
+ wallet.waitForOpen().then(() => {
33
+ setWalletStatus('open')
34
+ })
35
+
36
+ return () => {
37
+ setWalletStatus('closed')
38
+ }
39
+ }, [wallet])
40
+
41
+ return { walletStatus, openWallet, joinFederation }
42
+ }
@@ -0,0 +1,46 @@
1
+ import { useCallback, useEffect, useState } from 'react'
2
+ import { useFedimintWallet, useOpenWallet } from '.'
3
+ import { LnReceiveState, type CreateBolt11Response } from '@fedimint/core-web'
4
+
5
+ export const useReceiveLightning = () => {
6
+ const wallet = useFedimintWallet()
7
+ const { walletStatus } = useOpenWallet()
8
+ const [invoice, setInvoice] = useState<CreateBolt11Response>()
9
+ const [invoiceReceiveState, setInvoiceReceiveState] =
10
+ useState<LnReceiveState>()
11
+ const [error, setError] = useState<string>()
12
+
13
+ const generateInvoice = useCallback(
14
+ async (amount: number, description: string) => {
15
+ if (walletStatus !== 'open') throw new Error('Wallet is not open')
16
+ const response = await wallet.lightning.createInvoice(amount, description)
17
+ setInvoice(response)
18
+ return response.invoice
19
+ },
20
+ [wallet, walletStatus],
21
+ )
22
+
23
+ useEffect(() => {
24
+ if (walletStatus !== 'open' || !invoice) return
25
+ const unsubscribe = wallet.lightning.subscribeLnReceive(
26
+ invoice.operation_id,
27
+ (state) => {
28
+ setInvoiceReceiveState(state)
29
+ },
30
+ (error) => {
31
+ setError(error)
32
+ },
33
+ )
34
+
35
+ return () => {
36
+ unsubscribe()
37
+ }
38
+ }, [walletStatus, invoice])
39
+
40
+ return {
41
+ generateInvoice,
42
+ bolt11: invoice?.invoice,
43
+ invoiceStatus: invoiceReceiveState,
44
+ error,
45
+ }
46
+ }
@@ -0,0 +1,49 @@
1
+ import { useCallback, useEffect, useState } from 'react'
2
+ import { useFedimintWallet, useOpenWallet } from '.'
3
+ import {
4
+ type LnPayState,
5
+ type OutgoingLightningPayment,
6
+ } from '@fedimint/core-web'
7
+
8
+ export const useSendLightning = () => {
9
+ const wallet = useFedimintWallet()
10
+ const { walletStatus } = useOpenWallet()
11
+ const [payment, setPayment] = useState<OutgoingLightningPayment>()
12
+ const [paymentState, setPaymentState] = useState<LnPayState>()
13
+ const [error, setError] = useState<string>()
14
+
15
+ const payInvoice = useCallback(
16
+ async (bolt11: string) => {
17
+ if (walletStatus !== 'open') throw new Error('Wallet is not open')
18
+ const response = await wallet.lightning.payInvoice(bolt11)
19
+ setPayment(response)
20
+ return response
21
+ },
22
+ [wallet, walletStatus],
23
+ )
24
+
25
+ useEffect(() => {
26
+ if (walletStatus !== 'open' || !payment) return
27
+ const unsubscribe = wallet.lightning.subscribeLnPay(
28
+ // @ts-ignore
29
+ payment.payment_type.lightning,
30
+ (state) => {
31
+ setPaymentState(state)
32
+ },
33
+ (error) => {
34
+ setError(error)
35
+ },
36
+ )
37
+
38
+ return () => {
39
+ unsubscribe()
40
+ }
41
+ }, [walletStatus, payment])
42
+
43
+ return {
44
+ payInvoice,
45
+ payment,
46
+ paymentStatus: paymentState,
47
+ paymentError: error,
48
+ }
49
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './hooks'
2
+ export * from './contexts'
package/lib/init.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { FedimintWallet } from '@fedimint/core-web'
2
+
3
+ let wallet: FedimintWallet | undefined
4
+
5
+ export const initFedimintReact = (lazy: boolean = false) => {
6
+ if (!lazy) {
7
+ wallet = new FedimintWallet(lazy)
8
+ }
9
+
10
+ return {}
11
+ }
package/package.json CHANGED
@@ -1,21 +1,16 @@
1
1
  {
2
2
  "name": "@fedimint/react",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
7
- "src"
7
+ "lib"
8
8
  ],
9
- "main": "./dist/fedimint-react.js",
10
- "module": "./dist/fedimint-react.js",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/fedimint-react.js"
14
- }
15
- },
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
16
11
  "peerDependencies": {
17
12
  "react": "^18.3.1",
18
- "@fedimint/core-web": "0.0.8"
13
+ "@fedimint/core-web": "0.0.10"
19
14
  },
20
15
  "devDependencies": {
21
16
  "@types/react": ">=18.3.11",
package/src/App.css DELETED
@@ -1,53 +0,0 @@
1
- #root {
2
- max-width: 1280px;
3
- margin: 0 auto;
4
- padding: 2rem;
5
- text-align: center;
6
- }
7
-
8
- .App {
9
- display: flex;
10
- flex-direction: column;
11
- align-items: center;
12
- }
13
-
14
- .card {
15
- display: flex;
16
- flex-direction: column;
17
- align-items: center;
18
- width: 100%;
19
- padding: 2em;
20
- border-style: solid;
21
- border-width: 1px;
22
- border-color: #ccc;
23
- border-radius: 1em;
24
- }
25
-
26
- .section {
27
- display: flex;
28
- flex-direction: column;
29
- margin-bottom: 3rem;
30
- width: 100%;
31
- display: flex;
32
- align-items: center;
33
- justify-content: center;
34
- width: 100%;
35
- border-bottom: 1px solid #ccc;
36
- gap: 0.5rem;
37
- }
38
-
39
- .row {
40
- display: flex;
41
- flex-direction: row;
42
- align-items: center;
43
- justify-content: space-between;
44
- width: 100%;
45
- max-width: 500px;
46
- gap: 0.5rem;
47
- }
48
-
49
- .truncate {
50
- white-space: nowrap;
51
- overflow: hidden;
52
- text-overflow: ellipsis;
53
- }
package/src/App.tsx DELETED
@@ -1,17 +0,0 @@
1
- import React from 'react'
2
- import './App.css'
3
- import HooksDemo from './components/HooksDemo'
4
- // @ts-ignore
5
- import reactImage from './assets/react.svg'
6
-
7
- function App() {
8
- return (
9
- <div className="App">
10
- <img height={200} src={reactImage} />
11
- <h2>Fedimint Web SDK - React</h2>
12
- <HooksDemo />
13
- </div>
14
- )
15
- }
16
-
17
- export default App
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
@@ -1,127 +0,0 @@
1
- import React, { useState } from 'react'
2
- import {
3
- useBalance,
4
- useReceiveLightning,
5
- useOpenWallet,
6
- useSendLightning,
7
- } from '../../lib'
8
-
9
- const TEST_FEDERATION_INVITE =
10
- 'fed11qgqzc2nhwden5te0vejkg6tdd9h8gepwvejkg6tdd9h8garhduhx6at5d9h8jmn9wshxxmmd9uqqzgxg6s3evnr6m9zdxr6hxkdkukexpcs3mn7mj3g5pc5dfh63l4tj6g9zk4er'
11
-
12
- function HooksDemo() {
13
- const balance = useBalance()
14
- const { walletStatus, openWallet, joinFederation } = useOpenWallet()
15
- const [bolt11Input, setBolt11Input] = useState<string>()
16
- const isOpen = walletStatus === 'open'
17
- const { generateInvoice, bolt11, invoiceStatus, error } =
18
- useReceiveLightning()
19
- const { payInvoice, payment, paymentStatus, paymentError } =
20
- useSendLightning()
21
-
22
- return (
23
- <>
24
- <div className="card">
25
- <h2>Hooks</h2>
26
- <div className="section">
27
- <b>useOpenWallet()</b>
28
- <div className="row">
29
- <b>walletStatus</b>
30
- <p>{walletStatus}</p>
31
- </div>
32
- <div className="row">
33
- <b>openWallet()</b>
34
- <button disabled={isOpen} onClick={openWallet}>
35
- Open Wallet
36
- </button>
37
- </div>
38
- <div className="row">
39
- <b>joinFederation(invite)</b>
40
- <button
41
- disabled={isOpen}
42
- onClick={() => joinFederation(TEST_FEDERATION_INVITE)}
43
- >
44
- Join Federation
45
- </button>
46
- </div>
47
- </div>
48
- <div className="section">
49
- <div className="row">
50
- <b>useBalance</b>
51
- <p>{balance ? `${balance / 1000} sats` : 'no balance'}</p>
52
- </div>
53
- </div>
54
- <div className="section">
55
- <b>useLightningInvoice()</b>
56
- <div className="row">
57
- <b>generateInvoice(1000, '1000 msats')</b>
58
- <button
59
- disabled={!isOpen}
60
- onClick={() =>
61
- generateInvoice(1_000, 'invoice from fedimint web sdk')
62
- }
63
- >
64
- Generate Invoice
65
- </button>
66
- </div>
67
- <div className="row">
68
- <b>bolt11</b>
69
- <p className="truncate">
70
- {bolt11 ? bolt11 : 'no invoice generated'}
71
- </p>
72
- </div>
73
- <div className="row">
74
- <b>invoiceStatus</b>
75
- <p>
76
- {typeof invoiceStatus === 'string'
77
- ? invoiceStatus
78
- : typeof invoiceStatus === 'object'
79
- ? Object.keys(invoiceStatus)[0]
80
- : 'no invoice status'}
81
- </p>
82
- </div>
83
- <div className="row">
84
- <b>error</b>
85
- <p>{error}</p>
86
- </div>
87
- </div>
88
- <div className="section">
89
- <b>useSendLightning()</b>
90
- <div className="row">
91
- <b>bolt11</b>
92
- <input
93
- type="text"
94
- value={bolt11Input}
95
- onChange={(e) => setBolt11Input(e.target.value)}
96
- />
97
- </div>
98
- <div className="row">
99
- <b>payInvoice(bolt11)</b>
100
- <button
101
- disabled={!isOpen || !bolt11Input}
102
- onClick={() => bolt11Input && payInvoice(bolt11Input)}
103
- >
104
- Pay Invoice
105
- </button>
106
- </div>
107
- <div className="row">
108
- <b>paymentStatus</b>
109
- <p>
110
- {typeof paymentStatus === 'string'
111
- ? paymentStatus
112
- : typeof paymentStatus === 'object'
113
- ? Object.keys(paymentStatus)[0]
114
- : 'no payment status'}
115
- </p>
116
- </div>
117
- <div className="row">
118
- <b>paymentError</b>
119
- <p>{paymentError}</p>
120
- </div>
121
- </div>
122
- </div>
123
- </>
124
- )
125
- }
126
-
127
- export default HooksDemo
package/src/index.css DELETED
@@ -1,54 +0,0 @@
1
- :root {
2
- font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
- line-height: 1.5;
4
- font-weight: 400;
5
-
6
- color-scheme: light dark;
7
- color: rgba(255, 255, 255, 0.87);
8
- background-color: #242424;
9
-
10
- font-synthesis: none;
11
- text-rendering: optimizeLegibility;
12
- -webkit-font-smoothing: antialiased;
13
- -moz-osx-font-smoothing: grayscale;
14
- }
15
-
16
- a {
17
- font-weight: 500;
18
- color: #646cff;
19
- text-decoration: inherit;
20
- }
21
- a:hover {
22
- color: #535bf2;
23
- }
24
-
25
- body {
26
- margin: 0;
27
- display: flex;
28
- min-width: 320px;
29
- min-height: 100vh;
30
- }
31
-
32
- h1 {
33
- font-size: 3.2em;
34
- line-height: 1.1;
35
- }
36
-
37
- button {
38
- border-radius: 8px;
39
- border: 1px solid transparent;
40
- padding: 0.6em 1.2em;
41
- font-size: 1em;
42
- font-weight: 500;
43
- font-family: inherit;
44
- background-color: #1a1a1a;
45
- cursor: pointer;
46
- transition: border-color 0.25s;
47
- }
48
- button:hover {
49
- border-color: #646cff;
50
- }
51
- button:focus,
52
- button:focus-visible {
53
- outline: 4px auto -webkit-focus-ring-color;
54
- }
package/src/main.tsx DELETED
@@ -1,18 +0,0 @@
1
- import React from 'react'
2
- import ReactDOM from 'react-dom/client'
3
- import App from './App.tsx'
4
- import './index.css'
5
- import { FedimintWalletProvider, setupFedimintWallet } from '../lib/contexts'
6
-
7
- setupFedimintWallet({
8
- lazy: false,
9
- debug: true,
10
- })
11
-
12
- ReactDOM.createRoot(document.getElementById('root')!).render(
13
- <React.StrictMode>
14
- <FedimintWalletProvider>
15
- <App />
16
- </FedimintWalletProvider>
17
- </React.StrictMode>,
18
- )
@@ -1,4 +0,0 @@
1
- declare module '*.svg' {
2
- const content: string
3
- export default content
4
- }
package/src/vite-env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />
File without changes