@fedimint/react 0.2.0 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"useOpenWallet.d.ts","sourceRoot":"","sources":["../../lib/hooks/useOpenWallet.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa;;;6BAqBP,MAAM;CAaxB,CAAA"}
1
+ {"version":3,"file":"useOpenWallet.d.ts","sourceRoot":"","sources":["../../lib/hooks/useOpenWallet.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa;;;6BA0BP,MAAM;CAaxB,CAAA"}
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { useState as r, useEffect as m, createContext as y, useMemo as F, createElement as I, useContext as W, useCallback as w } from "react";
1
+ import { useState as r, useEffect as h, createContext as y, useMemo as F, createElement as I, useContext as W, useCallback as w } from "react";
2
2
  import { WalletDirector as P } from "@fedimint/core";
3
3
  const R = () => {
4
4
  const e = g(), { walletStatus: t } = E(), [n, o] = r();
5
- return m(() => {
5
+ return h(() => {
6
6
  if (t !== "open") return;
7
7
  const a = e.balance.subscribeBalance((c) => {
8
8
  o(c);
@@ -31,7 +31,7 @@ const O = (e) => {
31
31
  }),
32
32
  [t]
33
33
  );
34
- return m(() => {
34
+ return h(() => {
35
35
  b.waitForOpen().then(() => {
36
36
  n("open");
37
37
  });
@@ -47,13 +47,15 @@ const O = (e) => {
47
47
  "useOpenWallet must be used within a FedimintWalletProvider"
48
48
  );
49
49
  const { wallet: t, walletStatus: n, setWalletStatus: o } = e, a = w(() => {
50
- n !== "open" && (o("opening"), t.open().then((l) => {
51
- o(l ? "open" : "closed");
50
+ n !== "open" && (o("opening"), t.open().then(() => {
51
+ o("open");
52
+ }).catch(() => {
53
+ o("closed");
52
54
  }));
53
55
  }, [t]), c = w(
54
- async (l) => {
55
- n !== "open" && (o("opening"), await t.joinFederation(l).then((u) => {
56
- o(u ? "open" : "closed");
56
+ async (u) => {
57
+ n !== "open" && (o("opening"), await t.joinFederation(u).then((l) => {
58
+ o(l ? "open" : "closed");
57
59
  }));
58
60
  },
59
61
  [t]
@@ -67,7 +69,7 @@ const O = (e) => {
67
69
  );
68
70
  return e.wallet;
69
71
  }, N = () => {
70
- const e = g(), { walletStatus: t } = E(), [n, o] = r(), [a, c] = r(), [l, u] = r(), p = w(
72
+ const e = g(), { walletStatus: t } = E(), [n, o] = r(), [a, c] = r(), [u, l] = r(), p = w(
71
73
  async (i, s) => {
72
74
  if (t !== "open") throw new Error("Wallet is not open");
73
75
  const d = await e.lightning.createInvoice(i, s);
@@ -75,7 +77,7 @@ const O = (e) => {
75
77
  },
76
78
  [e, t]
77
79
  );
78
- return m(() => {
80
+ return h(() => {
79
81
  if (t !== "open" || !n) return;
80
82
  const i = e.lightning.subscribeLnReceive(
81
83
  n.operation_id,
@@ -83,7 +85,7 @@ const O = (e) => {
83
85
  c(s);
84
86
  },
85
87
  (s) => {
86
- u(s);
88
+ l(s);
87
89
  }
88
90
  );
89
91
  return () => {
@@ -93,10 +95,10 @@ const O = (e) => {
93
95
  generateInvoice: p,
94
96
  bolt11: n == null ? void 0 : n.invoice,
95
97
  invoiceStatus: a,
96
- error: l
98
+ error: u
97
99
  };
98
100
  }, B = () => {
99
- const e = g(), { walletStatus: t } = E(), [n, o] = r(), [a, c] = r(), [l, u] = r(), p = w(
101
+ const e = g(), { walletStatus: t } = E(), [n, o] = r(), [a, c] = r(), [u, l] = r(), p = w(
100
102
  async (i) => {
101
103
  if (t !== "open") throw new Error("Wallet is not open");
102
104
  const s = await e.lightning.payInvoice(i);
@@ -104,7 +106,7 @@ const O = (e) => {
104
106
  },
105
107
  [e, t]
106
108
  );
107
- return m(() => {
109
+ return h(() => {
108
110
  if (t !== "open" || !n) return;
109
111
  const i = e.lightning.subscribeLnPay(
110
112
  // @ts-ignore
@@ -113,7 +115,7 @@ const O = (e) => {
113
115
  c(s);
114
116
  },
115
117
  (s) => {
116
- u(s);
118
+ l(s);
117
119
  }
118
120
  );
119
121
  return () => {
@@ -123,19 +125,19 @@ const O = (e) => {
123
125
  payInvoice: p,
124
126
  payment: n,
125
127
  paymentStatus: a,
126
- paymentError: l
128
+ paymentError: u
127
129
  };
128
130
  }, _ = () => {
129
- const e = g(), { walletStatus: t } = E(), [n, o] = r(), [a, c] = r(), [l, u] = r(), [p, i] = r();
130
- return m(() => {
131
+ const e = g(), { walletStatus: t } = E(), [n, o] = r(), [a, c] = r(), [u, l] = r(), [p, i] = r();
132
+ return h(() => {
131
133
  if (!n) return;
132
134
  const d = e.mint.subscribeSpendNotes(
133
135
  n,
134
- (h) => {
135
- u(h);
136
+ (m) => {
137
+ l(m);
136
138
  },
137
- (h) => {
138
- u("Error"), i(h);
139
+ (m) => {
140
+ l("Error"), i(m);
139
141
  }
140
142
  );
141
143
  return () => {
@@ -143,23 +145,23 @@ const O = (e) => {
143
145
  };
144
146
  }, [n]), {
145
147
  spendEcash: w(
146
- async (d, h) => {
148
+ async (d, m) => {
147
149
  if (t !== "open") throw new Error("Wallet is not open");
148
150
  const S = await e.mint.spendNotes(
149
151
  d * 1e3,
150
- h
152
+ m
151
153
  );
152
154
  return o(S.operation_id), c(S.notes), S.notes;
153
155
  },
154
156
  [e, t]
155
157
  ),
156
158
  notes: a,
157
- state: l,
159
+ state: u,
158
160
  error: p
159
161
  };
160
162
  }, j = () => {
161
- const e = g(), { walletStatus: t } = E(), [n, o] = r(), [a, c] = r(), [l, u] = r();
162
- return m(() => {
163
+ const e = g(), { walletStatus: t } = E(), [n, o] = r(), [a, c] = r(), [u, l] = r();
164
+ return h(() => {
163
165
  if (!n) return;
164
166
  const i = e.mint.subscribeReissueExternalNotes(
165
167
  n,
@@ -167,7 +169,7 @@ const O = (e) => {
167
169
  c(s);
168
170
  },
169
171
  (s) => {
170
- u(s);
172
+ l(s);
171
173
  }
172
174
  );
173
175
  return () => {
@@ -181,13 +183,13 @@ const O = (e) => {
181
183
  const s = await e.mint.redeemEcash(i);
182
184
  o(s);
183
185
  } catch (s) {
184
- c("Error"), u(s);
186
+ c("Error"), l(s);
185
187
  }
186
188
  },
187
189
  [e, t]
188
190
  ),
189
191
  state: a,
190
- error: l
192
+ error: u
191
193
  };
192
194
  };
193
195
  export {
@@ -16,9 +16,14 @@ export const useOpenWallet = () => {
16
16
  if (walletStatus === 'open') return
17
17
 
18
18
  setWalletStatus('opening')
19
- wallet.open().then((res) => {
20
- setWalletStatus(res ? 'open' : 'closed')
21
- })
19
+ wallet
20
+ .open()
21
+ .then(() => {
22
+ setWalletStatus('open')
23
+ })
24
+ .catch(() => {
25
+ setWalletStatus('closed')
26
+ })
22
27
  }, [wallet])
23
28
 
24
29
  const joinFederation = useCallback(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedimint/react",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -9,28 +9,22 @@
9
9
  "main": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
11
11
  "peerDependencies": {
12
- "react": "^18.3.1",
13
- "@fedimint/core": "0.1.1"
12
+ "react": ">=19.2.0",
13
+ "@fedimint/core": "0.1.3"
14
14
  },
15
15
  "devDependencies": {
16
- "@types/react": ">=19.1.4",
17
- "@types/react-dom": "^18.3.7",
18
- "@typescript-eslint/eslint-plugin": "^7.18.0",
19
- "@typescript-eslint/parser": "^7.18.0",
20
- "@vitejs/plugin-react": "^4.4.1",
21
- "eslint": "^9.27.0",
22
- "eslint-plugin-react-hooks": "^4.6.2",
23
- "eslint-plugin-react-refresh": "^0.4.20",
24
- "react-dom": ">=19.1.0",
25
- "typescript": "^5.8.3",
26
- "vite": "^5.4.20",
16
+ "@types/react": ">=19.2.2",
17
+ "@types/react-dom": ">=19.2.1",
18
+ "@vitejs/plugin-react": "^4.7.0",
19
+ "react-dom": ">=19.2.0",
20
+ "typescript": "^5.9.3",
21
+ "vite": "^6.3.6",
27
22
  "vite-plugin-dts": "^4.5.4",
28
- "vite-plugin-wasm": "^3.4.1"
23
+ "vite-plugin-wasm": "^3.5.0"
29
24
  },
30
25
  "scripts": {
31
26
  "dev": "vite",
32
27
  "build": "tsc --p ./tsconfig.build.json && vite build",
33
- "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
34
28
  "preview": "vite preview"
35
29
  }
36
30
  }