@helium/helium-react-hooks 0.0.8

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 (75) hide show
  1. package/LICENSE +203 -0
  2. package/lib/cjs/contexts/accountContext.js +47 -0
  3. package/lib/cjs/contexts/accountContext.js.map +1 -0
  4. package/lib/cjs/hooks/useAccount.js +151 -0
  5. package/lib/cjs/hooks/useAccount.js.map +1 -0
  6. package/lib/cjs/hooks/useAccountFetchCache.js +14 -0
  7. package/lib/cjs/hooks/useAccountFetchCache.js.map +1 -0
  8. package/lib/cjs/hooks/useAssociatedTokenAccount.js +34 -0
  9. package/lib/cjs/hooks/useAssociatedTokenAccount.js.map +1 -0
  10. package/lib/cjs/hooks/useAssociatedTokenAddress.js +26 -0
  11. package/lib/cjs/hooks/useAssociatedTokenAddress.js.map +1 -0
  12. package/lib/cjs/hooks/useIdlAccount.js +24 -0
  13. package/lib/cjs/hooks/useIdlAccount.js.map +1 -0
  14. package/lib/cjs/hooks/useInterval.js +20 -0
  15. package/lib/cjs/hooks/useInterval.js.map +1 -0
  16. package/lib/cjs/hooks/useMint.js +20 -0
  17. package/lib/cjs/hooks/useMint.js.map +1 -0
  18. package/lib/cjs/hooks/useOwnedAmount.js +28 -0
  19. package/lib/cjs/hooks/useOwnedAmount.js.map +1 -0
  20. package/lib/cjs/hooks/useSolOwnedAmount.js +13 -0
  21. package/lib/cjs/hooks/useSolOwnedAmount.js.map +1 -0
  22. package/lib/cjs/hooks/useTokenAccount.js +13 -0
  23. package/lib/cjs/hooks/useTokenAccount.js.map +1 -0
  24. package/lib/cjs/index.js +27 -0
  25. package/lib/cjs/index.js.map +1 -0
  26. package/lib/esm/src/contexts/accountContext.js +20 -0
  27. package/lib/esm/src/contexts/accountContext.js.map +1 -0
  28. package/lib/esm/src/hooks/useAccount.js +147 -0
  29. package/lib/esm/src/hooks/useAccount.js.map +1 -0
  30. package/lib/esm/src/hooks/useAccountFetchCache.js +10 -0
  31. package/lib/esm/src/hooks/useAccountFetchCache.js.map +1 -0
  32. package/lib/esm/src/hooks/useAssociatedTokenAccount.js +30 -0
  33. package/lib/esm/src/hooks/useAssociatedTokenAccount.js.map +1 -0
  34. package/lib/esm/src/hooks/useAssociatedTokenAddress.js +13 -0
  35. package/lib/esm/src/hooks/useAssociatedTokenAddress.js.map +1 -0
  36. package/lib/esm/src/hooks/useIdlAccount.js +20 -0
  37. package/lib/esm/src/hooks/useIdlAccount.js.map +1 -0
  38. package/lib/esm/src/hooks/useInterval.js +16 -0
  39. package/lib/esm/src/hooks/useInterval.js.map +1 -0
  40. package/lib/esm/src/hooks/useMint.js +17 -0
  41. package/lib/esm/src/hooks/useMint.js.map +1 -0
  42. package/lib/esm/src/hooks/useOwnedAmount.js +24 -0
  43. package/lib/esm/src/hooks/useOwnedAmount.js.map +1 -0
  44. package/lib/esm/src/hooks/useSolOwnedAmount.js +9 -0
  45. package/lib/esm/src/hooks/useSolOwnedAmount.js.map +1 -0
  46. package/lib/esm/src/hooks/useTokenAccount.js +9 -0
  47. package/lib/esm/src/hooks/useTokenAccount.js.map +1 -0
  48. package/lib/esm/src/index.js +12 -0
  49. package/lib/esm/src/index.js.map +1 -0
  50. package/lib/esm/tsconfig.esm.tsbuildinfo +1 -0
  51. package/lib/types/src/contexts/accountContext.d.ts +12 -0
  52. package/lib/types/src/contexts/accountContext.d.ts.map +1 -0
  53. package/lib/types/src/hooks/useAccount.d.ts +24 -0
  54. package/lib/types/src/hooks/useAccount.d.ts.map +1 -0
  55. package/lib/types/src/hooks/useAccountFetchCache.d.ts +6 -0
  56. package/lib/types/src/hooks/useAccountFetchCache.d.ts.map +1 -0
  57. package/lib/types/src/hooks/useAssociatedTokenAccount.d.ts +16 -0
  58. package/lib/types/src/hooks/useAssociatedTokenAccount.d.ts.map +1 -0
  59. package/lib/types/src/hooks/useAssociatedTokenAddress.d.ts +8 -0
  60. package/lib/types/src/hooks/useAssociatedTokenAddress.d.ts.map +1 -0
  61. package/lib/types/src/hooks/useIdlAccount.d.ts +5 -0
  62. package/lib/types/src/hooks/useIdlAccount.d.ts.map +1 -0
  63. package/lib/types/src/hooks/useInterval.d.ts +2 -0
  64. package/lib/types/src/hooks/useInterval.d.ts.map +1 -0
  65. package/lib/types/src/hooks/useMint.d.ts +5 -0
  66. package/lib/types/src/hooks/useMint.d.ts.map +1 -0
  67. package/lib/types/src/hooks/useOwnedAmount.d.ts +7 -0
  68. package/lib/types/src/hooks/useOwnedAmount.d.ts.map +1 -0
  69. package/lib/types/src/hooks/useSolOwnedAmount.d.ts +6 -0
  70. package/lib/types/src/hooks/useSolOwnedAmount.d.ts.map +1 -0
  71. package/lib/types/src/hooks/useTokenAccount.d.ts +5 -0
  72. package/lib/types/src/hooks/useTokenAccount.d.ts.map +1 -0
  73. package/lib/types/src/index.d.ts +14 -0
  74. package/lib/types/src/index.d.ts.map +1 -0
  75. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Helium Systems, Inc.
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AccountProvider = exports.AccountContext = void 0;
27
+ const spl_utils_1 = require("@helium/spl-utils");
28
+ const react_1 = __importStar(require("react"));
29
+ exports.AccountContext = (0, react_1.createContext)(undefined);
30
+ const AccountProvider = ({ children, commitment = "confirmed", extendConnection = true, connection }) => {
31
+ const [cache, setCache] = (0, react_1.useState)();
32
+ (0, react_1.useEffect)(() => {
33
+ if (connection) {
34
+ cache === null || cache === void 0 ? void 0 : cache.close();
35
+ setCache(new spl_utils_1.AccountFetchCache({
36
+ connection,
37
+ delay: 50,
38
+ commitment,
39
+ extendConnection,
40
+ }));
41
+ }
42
+ }, [connection]);
43
+ return (react_1.default.createElement(exports.AccountContext.Provider, { value: cache }, children));
44
+ return null;
45
+ };
46
+ exports.AccountProvider = AccountProvider;
47
+ //# sourceMappingURL=accountContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountContext.js","sourceRoot":"","sources":["../../../src/contexts/accountContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAAsD;AACtD,+CAMe;AASF,QAAA,cAAc,GAAG,IAAA,qBAAa,EACzC,SAAS,CACV,CAAC;AAEK,MAAM,eAAe,GAA8B,CAAC,EACzD,QAAQ,EACR,UAAU,GAAG,WAAW,EACxB,gBAAgB,GAAG,IAAI,EACvB,UAAU,EACX,EAAE,EAAE;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,GAAqB,CAAC;IACxD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,UAAU,EAAE;YACd,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,EAAE,CAAC;YAEf,QAAQ,CACN,IAAI,6BAAiB,CAAC;gBACpB,UAAU;gBACV,KAAK,EAAE,EAAE;gBACT,UAAU;gBACV,gBAAgB;aACjB,CAAC,CACH,CAAC;SACH;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,CACL,8BAAC,sBAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,QAAQ,CAA2B,CAC5E,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA3BW,QAAA,eAAe,mBA2B1B"}
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAccount = void 0;
4
+ const react_1 = require("react");
5
+ const useAccountFetchCache_1 = require("./useAccountFetchCache");
6
+ /**
7
+ * Generic hook to get a cached, auto updating, deserialized form of any Solana account. Massively saves on RPC usage by using
8
+ * the spl-utils accountFetchCache.
9
+ *
10
+ * @param key
11
+ * @param parser
12
+ * @param isStatic
13
+ * @returns
14
+ */
15
+ function useAccount(key, parser, isStatic = false // Set if the accounts data will never change, optimisation to lower websocket usage.
16
+ ) {
17
+ const cache = (0, useAccountFetchCache_1.useAccountFetchCache)();
18
+ const [state, setState] = (0, react_1.useState)({
19
+ loading: true,
20
+ });
21
+ const parsedAccountBaseParser = (pubkey, data) => {
22
+ try {
23
+ const info = parser(pubkey, data);
24
+ return {
25
+ pubkey,
26
+ account: data,
27
+ info,
28
+ };
29
+ }
30
+ catch (e) {
31
+ console.error("Error while parsing", e);
32
+ return {
33
+ pubkey,
34
+ account: data,
35
+ info: undefined,
36
+ };
37
+ }
38
+ };
39
+ const id = typeof key === "string" ? key : key === null || key === void 0 ? void 0 : key.toBase58();
40
+ (0, react_1.useEffect)(() => {
41
+ // Occassionally, dispose can get called while the cache promise is still going.
42
+ // In that case, we want to dispose immediately.
43
+ let shouldDisposeImmediately = false;
44
+ let disposeWatch = () => {
45
+ shouldDisposeImmediately = true;
46
+ };
47
+ if (!id || !cache) {
48
+ setState({ loading: false });
49
+ return;
50
+ }
51
+ else {
52
+ setState({ loading: true });
53
+ }
54
+ let prevInfo = state.info;
55
+ cache
56
+ .searchAndWatch(id, parser ? parsedAccountBaseParser : undefined, isStatic)
57
+ .then(([acc, dispose]) => {
58
+ if (shouldDisposeImmediately) {
59
+ dispose();
60
+ shouldDisposeImmediately = false;
61
+ }
62
+ disposeWatch = dispose;
63
+ if (acc) {
64
+ try {
65
+ const nextInfo = mergePublicKeys(prevInfo, (parser && parser(acc.pubkey, acc.account)));
66
+ prevInfo = nextInfo;
67
+ setState({
68
+ loading: false,
69
+ info: nextInfo,
70
+ account: acc.account,
71
+ });
72
+ }
73
+ catch (e) {
74
+ console.error("Error while parsing", e);
75
+ setState({
76
+ loading: false,
77
+ info: undefined,
78
+ account: acc.account,
79
+ });
80
+ }
81
+ }
82
+ else {
83
+ setState({ loading: false });
84
+ }
85
+ })
86
+ .catch((e) => {
87
+ console.error(e);
88
+ setState({ loading: false });
89
+ });
90
+ const disposeEmitter = cache.emitter.onCache((e) => {
91
+ const event = e;
92
+ if (event.id === id) {
93
+ cache
94
+ .search(id, parser ? parsedAccountBaseParser : undefined)
95
+ .then((acc) => {
96
+ if (acc && acc.account != state.account) {
97
+ try {
98
+ setState({
99
+ loading: false,
100
+ info: mergePublicKeys(state.info, parser && parser(acc.pubkey, acc.account)),
101
+ account: acc.account,
102
+ });
103
+ }
104
+ catch (e) {
105
+ console.error("Error while parsing", e);
106
+ setState({
107
+ loading: false,
108
+ info: undefined,
109
+ account: acc.account,
110
+ });
111
+ }
112
+ }
113
+ });
114
+ }
115
+ });
116
+ return () => {
117
+ disposeEmitter();
118
+ setTimeout(disposeWatch, 30 * 1000); // Keep cached accounts around for 30s in case a rerender is causing reuse
119
+ };
120
+ }, [cache, id, !parser]); // only trigger on change to parser if it wasn't defined before.
121
+ return state;
122
+ }
123
+ exports.useAccount = useAccount;
124
+ function isPureObject(input) {
125
+ return (null !== input &&
126
+ typeof input === "object" &&
127
+ Object.getPrototypeOf(input).isPrototypeOf(Object));
128
+ }
129
+ /**
130
+ * Updates to a solana account will contain new PublicKeys that are
131
+ * actually the same, just a new JS object. This will cause a lot of useMemo
132
+ * to fail.
133
+ */
134
+ function mergePublicKeys(arg0, arg1) {
135
+ if (!isPureObject(arg1) || !arg1 || !arg0) {
136
+ return arg1;
137
+ }
138
+ return Object.entries(arg1).reduce((acc, [key, value]) => {
139
+ if (arg1[key] &&
140
+ arg1[key].equals &&
141
+ arg0[key] &&
142
+ arg1[key].equals(arg0[key])) {
143
+ acc[key] = arg0[key];
144
+ }
145
+ else {
146
+ acc[key] = value;
147
+ }
148
+ return acc;
149
+ }, {});
150
+ }
151
+ //# sourceMappingURL=useAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccount.js","sourceRoot":"","sources":["../../../src/hooks/useAccount.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAE5C,iEAA8D;AAe9D;;;;;;;;GAQG;AACH,SAAgB,UAAU,CACxB,GAAiC,EACjC,MAA8B,EAC9B,WAAoB,KAAK,CAAC,qFAAqF;;IAE/G,MAAM,KAAK,GAAG,IAAA,2CAAoB,GAAE,CAAC;IACrC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAqB;QACrD,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,MAAM,uBAAuB,GAAG,CAC9B,MAAiB,EACjB,IAAyB,EACN,EAAE;QACrB,IAAI;YACF,MAAM,IAAI,GAAG,MAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACnC,OAAO;gBACL,MAAM;gBACN,OAAO,EAAE,IAAI;gBACb,IAAI;aACL,CAAC;SACH;QAAC,OAAO,CAAM,EAAE;YACf,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC,CAAC;YACxC,OAAO;gBACL,MAAM;gBACN,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,SAAS;aAChB,CAAC;SACH;IACH,CAAC,CAAC;IAEF,MAAM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CAAC,GAAG,KAAK,CAAC;SAClB;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAyB,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAccountFetchCache = void 0;
4
+ const react_1 = require("react");
5
+ const accountContext_1 = require("../contexts/accountContext");
6
+ /**
7
+ * Get the account fetch cache to save on rcp calls. Generally, you want to use {@link useAccount}
8
+ * @returns
9
+ */
10
+ const useAccountFetchCache = () => {
11
+ return (0, react_1.useContext)(accountContext_1.AccountContext);
12
+ };
13
+ exports.useAccountFetchCache = useAccountFetchCache;
14
+ //# sourceMappingURL=useAccountFetchCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccountFetchCache.js","sourceRoot":"","sources":["../../../src/hooks/useAccountFetchCache.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,+DAA4D;AAE5D;;;GAGG;AACI,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,OAAO,IAAA,kBAAU,EAAC,+BAAc,CAAC,CAAC;AACpC,CAAC,CAAC;AAFW,QAAA,oBAAoB,wBAE/B"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAssociatedTokenAccount = void 0;
4
+ const react_1 = require("react");
5
+ const useAssociatedTokenAddress_1 = require("./useAssociatedTokenAddress");
6
+ const useTokenAccount_1 = require("./useTokenAccount");
7
+ /**
8
+ * Get the associcated token account for this wallet, or the account itself is this address is already an ata
9
+ *
10
+ * @param walletOrAta
11
+ * @param mint
12
+ * @returns
13
+ */
14
+ function useAssociatedTokenAccount(walletOrAta, mint) {
15
+ const { result: associatedTokenAddress, loading: loading } = (0, useAssociatedTokenAddress_1.useAssociatedTokenAddress)(walletOrAta, mint);
16
+ const { info: associatedAccount, loading: loading2 } = (0, useTokenAccount_1.useTokenAccount)(associatedTokenAddress);
17
+ const { info: account, loading: loading3 } = (0, useTokenAccount_1.useTokenAccount)(associatedTokenAddress || undefined);
18
+ const result = (0, react_1.useMemo)(() => {
19
+ if ((account === null || account === void 0 ? void 0 : account.mint) === mint) {
20
+ // The passed value is the ata
21
+ return account;
22
+ }
23
+ else {
24
+ return associatedAccount;
25
+ }
26
+ }, [associatedAccount, account, mint]);
27
+ return {
28
+ associatedAccount: result,
29
+ loading: loading || loading2 || loading3,
30
+ associatedAccountKey: associatedTokenAddress,
31
+ };
32
+ }
33
+ exports.useAssociatedTokenAccount = useAssociatedTokenAccount;
34
+ //# sourceMappingURL=useAssociatedTokenAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAssociatedTokenAccount.js","sourceRoot":"","sources":["../../../src/hooks/useAssociatedTokenAccount.ts"],"names":[],"mappings":";;;AAEA,iCAAgC;AAChC,2EAAwE;AACxE,uDAAoD;AAQpD;;;;;;GAMG;AACH,SAAgB,yBAAyB,CACvC,WAAyC,EACzC,IAAkC;IAElC,MAAM,EAAE,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO,EAAE,GACxD,IAAA,qDAAyB,EAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAC/C,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,IAAA,iCAAe,EACpE,sBAAsB,CACvB,CAAC;IACF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,IAAA,iCAAe,EAC1D,sBAAsB,IAAI,SAAS,CACpC,CAAC;IAEF,MAAM,MAAM,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAC1B,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,IAAI,EAAE;YAC1B,8BAA8B;YAC9B,OAAO,OAAO,CAAC;SAChB;aAAM;YACL,OAAO,iBAAiB,CAAC;SAC1B;IACH,CAAC,EAAE,CAAC,iBAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAEvC,OAAO;QACL,iBAAiB,EAAE,MAAM;QACzB,OAAO,EAAE,OAAO,IAAI,QAAQ,IAAI,QAAQ;QACxC,oBAAoB,EAAE,sBAAsB;KAC7C,CAAC;AACJ,CAAC;AA3BD,8DA2BC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.useAssociatedTokenAddress = void 0;
13
+ const spl_token_1 = require("@solana/spl-token");
14
+ const react_async_hook_1 = require("react-async-hook");
15
+ const fetch = (wallet, mint) => __awaiter(void 0, void 0, void 0, function* () {
16
+ if (!wallet || !mint) {
17
+ return undefined;
18
+ }
19
+ return (0, spl_token_1.getAssociatedTokenAddress)(mint, wallet, true);
20
+ });
21
+ function useAssociatedTokenAddress(wallet, mint) {
22
+ const { result, loading } = (0, react_async_hook_1.useAsync)(fetch, [wallet, mint]);
23
+ return { result, loading };
24
+ }
25
+ exports.useAssociatedTokenAddress = useAssociatedTokenAddress;
26
+ //# sourceMappingURL=useAssociatedTokenAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAssociatedTokenAddress.js","sourceRoot":"","sources":["../../../src/hooks/useAssociatedTokenAddress.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAE2B;AAE3B,uDAA4C;AAM5C,MAAM,KAAK,GAAG,CACZ,MAAoC,EACpC,IAAkC,EACF,EAAE;IAClC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE;QACpB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,IAAA,qCAAyB,EAC9B,IAAI,EACJ,MAAM,EACN,IAAI,CACL,CAAC;AACJ,CAAC,CAAA,CAAC;AAEF,SAAgB,yBAAyB,CACvC,MAAoC,EACpC,IAAkC;IAElC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,2BAAQ,EAAC,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAE5D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC7B,CAAC;AAPD,8DAOC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useIdlAccount = void 0;
4
+ const useAccount_1 = require("./useAccount");
5
+ const anchor_1 = require("@project-serum/anchor");
6
+ const react_1 = require("react");
7
+ function useIdlAccount(key, idl, type) {
8
+ const parser = (0, react_1.useMemo)(() => {
9
+ return (pubkey, data) => {
10
+ try {
11
+ const coder = new anchor_1.BorshAccountsCoder(idl);
12
+ const decoded = coder.decode(type, data.data);
13
+ decoded.pubkey = pubkey;
14
+ return decoded;
15
+ }
16
+ catch (e) {
17
+ console.error(e);
18
+ }
19
+ };
20
+ }, [idl, type]);
21
+ return (0, useAccount_1.useAccount)(key, parser);
22
+ }
23
+ exports.useIdlAccount = useIdlAccount;
24
+ //# sourceMappingURL=useIdlAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIdlAccount.js","sourceRoot":"","sources":["../../../src/hooks/useIdlAccount.ts"],"names":[],"mappings":";;;AAAA,6CAA2D;AAC3D,kDAA6E;AAE7E,iCAAgC;AAGhC,SAAgB,aAAa,CAC3B,GAAc,EACd,GAAQ,EACR,IAAO;IAEP,MAAM,MAAM,GAA4C,IAAA,eAAO,EAAC,GAAG,EAAE;QACnE,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;YACtB,IAAI;gBACF,MAAM,KAAK,GAAG,IAAI,2BAAkB,CAAC,GAAG,CAAC,CAAC;gBAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC9C,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;gBACxB,OAAO,OAAO,CAAC;aAChB;YAAC,OAAO,CAAM,EAAE;gBACf,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAClB;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAChB,OAAO,IAAA,uBAAU,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC;AAlBD,sCAkBC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useInterval = void 0;
4
+ const react_1 = require("react");
5
+ function useInterval(callback, delay, deps = []) {
6
+ const savedCallbackRef = (0, react_1.useRef)();
7
+ (0, react_1.useEffect)(() => {
8
+ savedCallbackRef.current = callback;
9
+ }, [callback]);
10
+ (0, react_1.useEffect)(() => {
11
+ const handler = (...args) => savedCallbackRef.current(...args);
12
+ if (delay !== null) {
13
+ handler();
14
+ const intervalId = setInterval(handler, delay);
15
+ return () => clearInterval(intervalId);
16
+ }
17
+ }, [delay, ...deps]);
18
+ }
19
+ exports.useInterval = useInterval;
20
+ //# sourceMappingURL=useInterval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../../../src/hooks/useInterval.ts"],"names":[],"mappings":";;;AAAA,iCAA0C;AAE1C,SAAgB,WAAW,CACzB,QAAkC,EAClC,KAAoB,EACpB,OAAc,EAAE;IAEhB,MAAM,gBAAgB,GAAG,IAAA,cAAM,GAA4B,CAAC;IAE5D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,gBAAgB,CAAC,OAAO,GAAG,QAAQ,CAAC;IACtC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;QAEvE,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,OAAO,EAAE,CAAC;YACV,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC/C,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;SACxC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;AACvB,CAAC;AApBD,kCAoBC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMint = exports.MintParser = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ const useAccount_1 = require("./useAccount");
6
+ const MintParser = (pubKey, info) => {
7
+ const data = (0, spl_token_1.unpackMint)(pubKey, info);
8
+ const details = {
9
+ pubkey: pubKey,
10
+ account: Object.assign({}, info),
11
+ info: data,
12
+ };
13
+ return details;
14
+ };
15
+ exports.MintParser = MintParser;
16
+ function useMint(key) {
17
+ return (0, useAccount_1.useAccount)(key, exports.MintParser);
18
+ }
19
+ exports.useMint = useMint;
20
+ //# sourceMappingURL=useMint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMint.js","sourceRoot":"","sources":["../../../src/hooks/useMint.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAE/C,6CAA6D;AAEtD,MAAM,UAAU,GAAG,CAAC,MAAiB,EAAE,IAAyB,EAAE,EAAE;IACzE,MAAM,IAAI,GAAG,IAAA,sBAAU,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEtC,MAAM,OAAO,GAAG;QACd,MAAM,EAAE,MAAM;QACd,OAAO,oBACF,IAAI,CACR;QACD,IAAI,EAAE,IAAI;KACU,CAAC;IAEvB,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAZW,QAAA,UAAU,cAYrB;AAEF,SAAgB,OAAO,CAAC,GAAiC;IACvD,OAAO,IAAA,uBAAU,EAAC,GAAG,EAAE,kBAAU,CAAC,CAAC;AACrC,CAAC;AAFD,0BAEC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useOwnedAmount = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ const react_1 = require("react");
6
+ const useAssociatedTokenAccount_1 = require("./useAssociatedTokenAccount");
7
+ const useMint_1 = require("./useMint");
8
+ const useSolOwnedAmount_1 = require("./useSolOwnedAmount");
9
+ function useOwnedAmount(wallet, mint) {
10
+ const { amount: solOwnedAmount } = (0, useSolOwnedAmount_1.useSolOwnedAmount)(wallet || undefined);
11
+ const { associatedAccount, loading: loadingAssoc } = (0, useAssociatedTokenAccount_1.useAssociatedTokenAccount)(wallet, mint);
12
+ const { info: mintAcc, loading: loadingMint } = (0, useMint_1.useMint)(mint);
13
+ const amount = (0, react_1.useMemo)(() => {
14
+ if (mint === null || mint === void 0 ? void 0 : mint.equals(spl_token_1.NATIVE_MINT)) {
15
+ return solOwnedAmount;
16
+ }
17
+ else if (associatedAccount) {
18
+ return associatedAccount.amount;
19
+ }
20
+ }, [solOwnedAmount, associatedAccount === null || associatedAccount === void 0 ? void 0 : associatedAccount.amount]);
21
+ return {
22
+ loading: loadingAssoc || loadingMint,
23
+ amount,
24
+ decimals: mintAcc === null || mintAcc === void 0 ? void 0 : mintAcc.info.decimals,
25
+ };
26
+ }
27
+ exports.useOwnedAmount = useOwnedAmount;
28
+ //# sourceMappingURL=useOwnedAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOwnedAmount.js","sourceRoot":"","sources":["../../../src/hooks/useOwnedAmount.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAEhD,iCAAgC;AAChC,2EAAwE;AACxE,uCAAoC;AACpC,2DAAwD;AAExD,SAAgB,cAAc,CAC5B,MAAoC,EACpC,IAAkC;IAElC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,qCAAiB,EAAC,MAAM,IAAI,SAAS,CAAC,CAAC;IAC1E,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,YAAY,EAAE,GAChD,IAAA,qDAAyB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC1C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAA,iBAAO,EAAC,IAAI,CAAC,CAAC;IAE9D,MAAM,MAAM,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAC1B,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CAAC,uBAAW,CAAC,EAAE;YAC7B,OAAO,cAAc,CAAA;SACtB;aAAM,IAAI,iBAAiB,EAAE;YAC5B,OAAO,iBAAiB,CAAC,MAAM,CAAA;SAChC;IACH,CAAC,EAAE,CAAC,cAAc,EAAE,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAM,CAAC,CAAC,CAAC;IAChD,OAAO;QACL,OAAO,EAAE,YAAY,IAAI,WAAW;QACpC,MAAM;QACN,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,QAAQ;KACjC,CAAC;AACJ,CAAC;AArBD,wCAqBC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSolOwnedAmount = void 0;
4
+ const useAccount_1 = require("./useAccount");
5
+ function useSolOwnedAmount(ownerPublicKey) {
6
+ const { info: lamports, loading } = (0, useAccount_1.useAccount)(ownerPublicKey, (_, account) => BigInt(account.lamports));
7
+ return {
8
+ amount: lamports,
9
+ loading,
10
+ };
11
+ }
12
+ exports.useSolOwnedAmount = useSolOwnedAmount;
13
+ //# sourceMappingURL=useSolOwnedAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSolOwnedAmount.js","sourceRoot":"","sources":["../../../src/hooks/useSolOwnedAmount.ts"],"names":[],"mappings":";;;AAEA,6CAA0C;AAE1C,SAAgB,iBAAiB,CAAC,cAA0B;IAI1D,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAA,uBAAU,EAC5C,cAAc,EACd,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CACzC,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,QAAQ;QAChB,OAAO;KACR,CAAC;AACJ,CAAC;AAbD,8CAaC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTokenAccount = void 0;
4
+ const useAccount_1 = require("./useAccount");
5
+ const spl_token_1 = require("@solana/spl-token");
6
+ const parser = (pubkey, acct) => {
7
+ return (0, spl_token_1.unpackAccount)(pubkey, acct);
8
+ };
9
+ function useTokenAccount(address) {
10
+ return (0, useAccount_1.useAccount)(address, parser);
11
+ }
12
+ exports.useTokenAccount = useTokenAccount;
13
+ //# sourceMappingURL=useTokenAccount.js.map