@sudobility/contracts 1.12.0 → 1.13.0

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 (128) hide show
  1. package/dist/evm/src/evm/{mailer-client.d.ts → evm-mailer-client.d.ts} +146 -50
  2. package/dist/evm/src/evm/evm-mailer-client.d.ts.map +1 -0
  3. package/dist/evm/src/evm/evm-mailer-client.js +924 -0
  4. package/dist/evm/src/evm/evm-mailer-client.js.map +1 -0
  5. package/dist/evm/src/evm/index.d.ts +1 -1
  6. package/dist/evm/src/evm/index.d.ts.map +1 -1
  7. package/dist/evm/src/evm/index.js +4 -4
  8. package/dist/evm/src/evm/index.js.map +1 -1
  9. package/dist/solana/solana/index.d.ts +1 -1
  10. package/dist/solana/solana/index.d.ts.map +1 -1
  11. package/dist/solana/solana/index.js +4 -3
  12. package/dist/solana/solana/index.js.map +1 -1
  13. package/dist/solana/solana/solana-mailer-client.d.ts +209 -0
  14. package/dist/solana/solana/solana-mailer-client.d.ts.map +1 -0
  15. package/dist/solana/solana/solana-mailer-client.js +1004 -0
  16. package/dist/solana/solana/solana-mailer-client.js.map +1 -0
  17. package/dist/solana/solana/types.d.ts +3 -2
  18. package/dist/solana/solana/types.d.ts.map +1 -1
  19. package/dist/solana/solana/types.js.map +1 -1
  20. package/dist/{unified-esm/src/evm/mailer-client.d.ts → unified/src/evm/evm-mailer-client.d.ts} +146 -50
  21. package/dist/unified/src/evm/evm-mailer-client.d.ts.map +1 -0
  22. package/dist/unified/src/evm/evm-mailer-client.js +924 -0
  23. package/dist/unified/src/evm/evm-mailer-client.js.map +1 -0
  24. package/dist/unified/src/evm/index.d.ts +1 -1
  25. package/dist/unified/src/evm/index.d.ts.map +1 -1
  26. package/dist/unified/src/evm/index.js +4 -4
  27. package/dist/unified/src/evm/index.js.map +1 -1
  28. package/dist/unified/src/react/context/MailerProvider.d.ts +26 -20
  29. package/dist/unified/src/react/context/MailerProvider.d.ts.map +1 -1
  30. package/dist/unified/src/react/context/MailerProvider.js +26 -26
  31. package/dist/unified/src/react/context/MailerProvider.js.map +1 -1
  32. package/dist/unified/src/react/hooks/useMailerMutations.d.ts +225 -192
  33. package/dist/unified/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  34. package/dist/unified/src/react/hooks/useMailerMutations.js +263 -266
  35. package/dist/unified/src/react/hooks/useMailerMutations.js.map +1 -1
  36. package/dist/unified/src/react/hooks/useMailerQueries.d.ts +117 -63
  37. package/dist/unified/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  38. package/dist/unified/src/react/hooks/useMailerQueries.js +239 -104
  39. package/dist/unified/src/react/hooks/useMailerQueries.js.map +1 -1
  40. package/dist/unified/src/react/index.d.ts +5 -3
  41. package/dist/unified/src/react/index.d.ts.map +1 -1
  42. package/dist/unified/src/react/index.js +41 -26
  43. package/dist/unified/src/react/index.js.map +1 -1
  44. package/dist/unified/src/solana/index.d.ts +1 -1
  45. package/dist/unified/src/solana/index.d.ts.map +1 -1
  46. package/dist/unified/src/solana/index.js +4 -3
  47. package/dist/unified/src/solana/index.js.map +1 -1
  48. package/dist/unified/src/solana/solana-mailer-client.d.ts +209 -0
  49. package/dist/unified/src/solana/solana-mailer-client.d.ts.map +1 -0
  50. package/dist/unified/src/solana/solana-mailer-client.js +1004 -0
  51. package/dist/unified/src/solana/solana-mailer-client.js.map +1 -0
  52. package/dist/unified/src/solana/types.d.ts +3 -2
  53. package/dist/unified/src/solana/types.d.ts.map +1 -1
  54. package/dist/unified/src/solana/types.js.map +1 -1
  55. package/dist/unified/src/unified/index.d.ts +1 -1
  56. package/dist/unified/src/unified/index.d.ts.map +1 -1
  57. package/dist/unified/src/unified/onchain-mailer-client.d.ts +187 -268
  58. package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
  59. package/dist/unified/src/unified/onchain-mailer-client.js +539 -1614
  60. package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
  61. package/dist/unified/src/unified/types.d.ts +23 -6
  62. package/dist/unified/src/unified/types.d.ts.map +1 -1
  63. package/dist/{unified/src/evm/mailer-client.d.ts → unified-esm/src/evm/evm-mailer-client.d.ts} +146 -50
  64. package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +1 -0
  65. package/dist/unified-esm/src/evm/evm-mailer-client.js +920 -0
  66. package/dist/unified-esm/src/evm/evm-mailer-client.js.map +1 -0
  67. package/dist/unified-esm/src/evm/index.d.ts +1 -1
  68. package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
  69. package/dist/unified-esm/src/evm/index.js +2 -2
  70. package/dist/unified-esm/src/evm/index.js.map +1 -1
  71. package/dist/unified-esm/src/react/context/MailerProvider.d.ts +26 -20
  72. package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +1 -1
  73. package/dist/unified-esm/src/react/context/MailerProvider.js +25 -26
  74. package/dist/unified-esm/src/react/context/MailerProvider.js.map +1 -1
  75. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +225 -192
  76. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  77. package/dist/unified-esm/src/react/hooks/useMailerMutations.js +254 -262
  78. package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +1 -1
  79. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +117 -63
  80. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  81. package/dist/unified-esm/src/react/hooks/useMailerQueries.js +232 -102
  82. package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +1 -1
  83. package/dist/unified-esm/src/react/index.d.ts +5 -3
  84. package/dist/unified-esm/src/react/index.d.ts.map +1 -1
  85. package/dist/unified-esm/src/react/index.js +9 -5
  86. package/dist/unified-esm/src/react/index.js.map +1 -1
  87. package/dist/unified-esm/src/solana/index.d.ts +1 -1
  88. package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
  89. package/dist/unified-esm/src/solana/index.js +2 -1
  90. package/dist/unified-esm/src/solana/index.js.map +1 -1
  91. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +209 -0
  92. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +1 -0
  93. package/dist/unified-esm/src/solana/solana-mailer-client.js +1000 -0
  94. package/dist/unified-esm/src/solana/solana-mailer-client.js.map +1 -0
  95. package/dist/unified-esm/src/solana/types.d.ts +3 -2
  96. package/dist/unified-esm/src/solana/types.d.ts.map +1 -1
  97. package/dist/unified-esm/src/solana/types.js.map +1 -1
  98. package/dist/unified-esm/src/unified/index.d.ts +1 -1
  99. package/dist/unified-esm/src/unified/index.d.ts.map +1 -1
  100. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +187 -268
  101. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +1 -1
  102. package/dist/unified-esm/src/unified/onchain-mailer-client.js +539 -1614
  103. package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +1 -1
  104. package/dist/unified-esm/src/unified/types.d.ts +23 -6
  105. package/dist/unified-esm/src/unified/types.d.ts.map +1 -1
  106. package/package.json +5 -4
  107. package/programs/mailer/Cargo.toml +1 -1
  108. package/dist/evm/src/evm/mailer-client.d.ts.map +0 -1
  109. package/dist/evm/src/evm/mailer-client.js +0 -619
  110. package/dist/evm/src/evm/mailer-client.js.map +0 -1
  111. package/dist/solana/solana/mailer-client.d.ts +0 -282
  112. package/dist/solana/solana/mailer-client.d.ts.map +0 -1
  113. package/dist/solana/solana/mailer-client.js +0 -989
  114. package/dist/solana/solana/mailer-client.js.map +0 -1
  115. package/dist/unified/src/evm/mailer-client.d.ts.map +0 -1
  116. package/dist/unified/src/evm/mailer-client.js +0 -619
  117. package/dist/unified/src/evm/mailer-client.js.map +0 -1
  118. package/dist/unified/src/solana/mailer-client.d.ts +0 -282
  119. package/dist/unified/src/solana/mailer-client.d.ts.map +0 -1
  120. package/dist/unified/src/solana/mailer-client.js +0 -989
  121. package/dist/unified/src/solana/mailer-client.js.map +0 -1
  122. package/dist/unified-esm/src/evm/mailer-client.d.ts.map +0 -1
  123. package/dist/unified-esm/src/evm/mailer-client.js +0 -615
  124. package/dist/unified-esm/src/evm/mailer-client.js.map +0 -1
  125. package/dist/unified-esm/src/solana/mailer-client.d.ts +0 -282
  126. package/dist/unified-esm/src/solana/mailer-client.d.ts.map +0 -1
  127. package/dist/unified-esm/src/solana/mailer-client.js +0 -985
  128. package/dist/unified-esm/src/solana/mailer-client.js.map +0 -1
@@ -1,400 +1,392 @@
1
1
  import { useMutation, useQueryClient } from '@tanstack/react-query';
2
- import { useMailerClient } from '../context/MailerProvider.js';
3
2
  import { mailerQueryKeys } from './useMailerQueries.js';
4
3
  /**
5
- * Hook to send a message
4
+ * Hook for message-related operations
6
5
  *
7
6
  * @example
8
7
  * ```tsx
9
- * function SendMessageForm() {
10
- * const sendMessage = useSendMessage();
8
+ * function MessageSender() {
9
+ * const client = useMailerClient(); // Get client from context or create it
10
+ * const { sendMessage, sendPrepared } = useMessaging(client, wallet, chainInfo);
11
11
  *
12
12
  * const handleSend = () => {
13
13
  * sendMessage.mutate({
14
14
  * subject: 'Hello',
15
15
  * body: 'World!',
16
- * priority: true,
17
- * resolveSenderToName: false
16
+ * priority: true
18
17
  * });
19
18
  * };
20
19
  *
21
20
  * return (
22
21
  * <button onClick={handleSend} disabled={sendMessage.isPending}>
23
- * {sendMessage.isPending ? 'Sending...' : 'Send Message'}
22
+ * Send Message
24
23
  * </button>
25
24
  * );
26
25
  * }
27
26
  * ```
28
27
  */
29
- export function useSendMessage(options) {
30
- const client = useMailerClient();
28
+ export function useMessaging(client, connectedWallet, chainInfo, options) {
31
29
  const queryClient = useQueryClient();
32
- return useMutation({
33
- mutationFn: async ({ subject, body, priority = false, resolveSenderToName = false }) => client.sendMessage(subject, body, priority, resolveSenderToName),
30
+ const sendMessage = useMutation({
31
+ mutationFn: async ({ subject, body, priority = false, resolveSenderToName = false }) => client.sendMessage(connectedWallet, chainInfo, subject, body, { priority, resolveSenderToName }),
34
32
  onSuccess: () => {
35
- // Invalidate claimable amounts as sending affects balances
36
33
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount() });
37
34
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
38
35
  },
39
- ...options,
36
+ ...options?.sendMessage,
40
37
  });
41
- }
42
- /**
43
- * Hook to send a prepared message
44
- *
45
- * @example
46
- * ```tsx
47
- * function SendPreparedButton() {
48
- * const sendPrepared = useSendPrepared();
49
- *
50
- * return (
51
- * <button
52
- * onClick={() => sendPrepared.mutate({
53
- * to: '0x123...',
54
- * mailId: 'template-001',
55
- * priority: true
56
- * })}
57
- * disabled={sendPrepared.isPending}
58
- * >
59
- * Send Prepared
60
- * </button>
61
- * );
62
- * }
63
- * ```
64
- */
65
- export function useSendPrepared(options) {
66
- const client = useMailerClient();
67
- const queryClient = useQueryClient();
68
- return useMutation({
69
- mutationFn: async ({ to, mailId, priority = false, resolveSenderToName = false }) => client.sendPrepared(to, mailId, priority, resolveSenderToName),
38
+ const sendPrepared = useMutation({
39
+ mutationFn: async ({ to, mailId, priority = false, resolveSenderToName = false }) => client.sendPrepared(connectedWallet, chainInfo, to, mailId, { priority, resolveSenderToName }),
70
40
  onSuccess: () => {
71
41
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount() });
72
42
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
73
43
  },
74
- ...options,
44
+ ...options?.sendPrepared,
75
45
  });
46
+ return {
47
+ sendMessage,
48
+ sendPrepared,
49
+ };
76
50
  }
77
51
  /**
78
- * Hook to send message to email address
52
+ * Hook for claim-related operations
79
53
  *
80
54
  * @example
81
55
  * ```tsx
82
- * function SendToEmailForm() {
83
- * const sendToEmail = useSendToEmail();
56
+ * function ClaimPanel() {
57
+ * const { claimRevenue, claimOwnerShare, claimExpiredShares } = useClaims(client, wallet, chainInfo);
84
58
  *
85
59
  * return (
86
- * <button
87
- * onClick={() => sendToEmail.mutate({
88
- * toEmail: 'user@example.com',
89
- * subject: 'Hello',
90
- * body: 'Welcome!'
91
- * })}
92
- * >
93
- * Send to Email
94
- * </button>
60
+ * <div>
61
+ * <button onClick={() => claimRevenue.mutate()}>
62
+ * Claim Revenue
63
+ * </button>
64
+ * <button onClick={() => claimOwnerShare.mutate()}>
65
+ * Claim Owner Share
66
+ * </button>
67
+ * </div>
95
68
  * );
96
69
  * }
97
70
  * ```
98
71
  */
99
- export function useSendToEmail(options) {
100
- const client = useMailerClient();
101
- const queryClient = useQueryClient();
102
- return useMutation({
103
- mutationFn: async ({ toEmail, subject, body }) => client.sendToEmail(toEmail, subject, body),
104
- onSuccess: () => {
105
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
106
- },
107
- ...options,
108
- });
109
- }
110
- /**
111
- * Hook to send prepared message to email address
112
- */
113
- export function useSendPreparedToEmail(options) {
114
- const client = useMailerClient();
72
+ export function useClaims(client, connectedWallet, chainInfo, options) {
115
73
  const queryClient = useQueryClient();
116
- return useMutation({
117
- mutationFn: async ({ toEmail, mailId }) => client.sendPreparedToEmail(toEmail, mailId),
74
+ const claimRevenue = useMutation({
75
+ mutationFn: () => client.claimRevenue(connectedWallet, chainInfo),
118
76
  onSuccess: () => {
119
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
120
- },
121
- ...options,
122
- });
123
- }
124
- /**
125
- * Hook to claim revenue share
126
- *
127
- * @example
128
- * ```tsx
129
- * function ClaimButton() {
130
- * const { data: claimable } = useGetClaimableAmount();
131
- * const claimRevenue = useClaimRevenue();
132
- *
133
- * if (!claimable || claimable === 0n) return null;
134
- *
135
- * return (
136
- * <button
137
- * onClick={() => claimRevenue.mutate()}
138
- * disabled={claimRevenue.isPending}
139
- * >
140
- * Claim {Number(claimable) / 1_000_000} USDC
141
- * </button>
142
- * );
143
- * }
144
- * ```
145
- */
146
- export function useClaimRevenue(options) {
147
- const client = useMailerClient();
148
- const queryClient = useQueryClient();
149
- return useMutation({
150
- mutationFn: () => client.claimRevenue(),
151
- onSuccess: () => {
152
- // Invalidate claimable amount after successful claim
153
77
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount() });
154
78
  },
155
- ...options,
79
+ ...options?.claimRevenue,
156
80
  });
157
- }
158
- /**
159
- * Hook to claim owner share (owner only)
160
- *
161
- * @example
162
- * ```tsx
163
- * function OwnerClaimButton() {
164
- * const { data: ownerClaimable } = useGetOwnerClaimable();
165
- * const claimOwner = useClaimOwnerShare();
166
- *
167
- * return (
168
- * <button onClick={() => claimOwner.mutate()}>
169
- * Claim Owner Fees: {Number(ownerClaimable) / 1_000_000} USDC
170
- * </button>
171
- * );
172
- * }
173
- * ```
174
- */
175
- export function useClaimOwnerShare(options) {
176
- const client = useMailerClient();
177
- const queryClient = useQueryClient();
178
- return useMutation({
179
- mutationFn: () => client.claimOwnerShare(),
81
+ const claimOwnerShare = useMutation({
82
+ mutationFn: () => client.claimOwnerShare(connectedWallet, chainInfo),
180
83
  onSuccess: () => {
181
84
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
182
85
  },
183
- ...options,
86
+ ...options?.claimOwnerShare,
184
87
  });
185
- }
186
- /**
187
- * Hook to reclaim expired recipient shares (owner only)
188
- */
189
- export function useClaimExpiredShares(options) {
190
- const client = useMailerClient();
191
- const queryClient = useQueryClient();
192
- return useMutation({
193
- mutationFn: async ({ recipient }) => client.claimExpiredShares(recipient),
88
+ const claimExpiredShares = useMutation({
89
+ mutationFn: async ({ recipient }) => client.claimExpiredShares(connectedWallet, chainInfo, recipient),
194
90
  onSuccess: (_, variables) => {
195
91
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount(variables.recipient) });
196
92
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
197
93
  },
198
- ...options,
94
+ ...options?.claimExpiredShares,
199
95
  });
96
+ return {
97
+ claimRevenue,
98
+ claimOwnerShare,
99
+ claimExpiredShares,
100
+ };
200
101
  }
201
102
  /**
202
- * Hook to delegate to another address
103
+ * Hook for delegation-related operations
203
104
  *
204
105
  * @example
205
106
  * ```tsx
206
- * function DelegateButton() {
207
- * const delegate = useDelegateTo();
107
+ * function DelegationManager() {
108
+ * const { delegateTo, rejectDelegation } = useDelegation(client, wallet, chainInfo);
208
109
  *
209
110
  * return (
210
- * <button
211
- * onClick={() => delegate.mutate({ delegate: '0xABC...' })}
212
- * disabled={delegate.isPending}
213
- * >
214
- * Delegate
215
- * </button>
111
+ * <>
112
+ * <button onClick={() => delegateTo.mutate({ delegate: '0xABC...' })}>
113
+ * Delegate
114
+ * </button>
115
+ * <button onClick={() => rejectDelegation.mutate({ delegatorAddress: '0xDEF...' })}>
116
+ * Reject Delegation
117
+ * </button>
118
+ * </>
216
119
  * );
217
120
  * }
218
121
  * ```
219
122
  */
220
- export function useDelegateTo(options) {
221
- const client = useMailerClient();
123
+ export function useDelegation(client, connectedWallet, chainInfo, options) {
222
124
  const queryClient = useQueryClient();
223
- return useMutation({
224
- mutationFn: async ({ delegate }) => client.delegateTo(delegate),
125
+ const delegateTo = useMutation({
126
+ mutationFn: async ({ delegate }) => client.delegateTo(connectedWallet, chainInfo, delegate),
225
127
  onSuccess: () => {
226
128
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegation() });
227
129
  },
228
- ...options,
130
+ ...options?.delegateTo,
229
131
  });
230
- }
231
- /**
232
- * Hook to reject a delegation made to you
233
- *
234
- * @example
235
- * ```tsx
236
- * function RejectDelegationButton({ delegatorAddress }: { delegatorAddress: string }) {
237
- * const rejectDelegation = useRejectDelegation();
238
- *
239
- * return (
240
- * <button
241
- * onClick={() => rejectDelegation.mutate({ delegatorAddress })}
242
- * >
243
- * Reject Delegation
244
- * </button>
245
- * );
246
- * }
247
- * ```
248
- */
249
- export function useRejectDelegation(options) {
250
- const client = useMailerClient();
251
- const queryClient = useQueryClient();
252
- return useMutation({
253
- mutationFn: async ({ delegatorAddress }) => client.rejectDelegation(delegatorAddress),
132
+ const rejectDelegation = useMutation({
133
+ mutationFn: async ({ delegatorAddress }) => client.rejectDelegation(connectedWallet, chainInfo, delegatorAddress),
254
134
  onSuccess: () => {
255
135
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegation() });
256
136
  },
257
- ...options,
137
+ ...options?.rejectDelegation,
258
138
  });
139
+ return {
140
+ delegateTo,
141
+ rejectDelegation,
142
+ };
259
143
  }
260
144
  /**
261
- * Hook to set send fee (owner only)
145
+ * Hook for permission-related operations (EVM only)
262
146
  *
263
147
  * @example
264
148
  * ```tsx
265
- * function SetFeeForm() {
266
- * const setFee = useSetFee();
149
+ * function PermissionManager() {
150
+ * const { setPermission, removePermission } = usePermissions(client, wallet, chainInfo);
267
151
  *
268
152
  * return (
269
- * <button onClick={() => setFee.mutate({ newFee: 200000n })}>
270
- * Update Fee to 0.2 USDC
271
- * </button>
153
+ * <>
154
+ * <button onClick={() => setPermission.mutate({ contractAddress: '0xABC...' })}>
155
+ * Grant Permission
156
+ * </button>
157
+ * <button onClick={() => removePermission.mutate({ contractAddress: '0xABC...' })}>
158
+ * Revoke Permission
159
+ * </button>
160
+ * </>
272
161
  * );
273
162
  * }
274
163
  * ```
275
164
  */
276
- export function useSetFee(options) {
277
- const client = useMailerClient();
165
+ export function usePermissions(client, connectedWallet, chainInfo, options) {
278
166
  const queryClient = useQueryClient();
279
- return useMutation({
280
- mutationFn: async ({ newFee }) => client.setFee(newFee),
167
+ const setPermission = useMutation({
168
+ mutationFn: async ({ contractAddress }) => client.setPermission(connectedWallet, chainInfo, contractAddress),
281
169
  onSuccess: () => {
282
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.sendFee() });
170
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.permissions() });
283
171
  },
284
- ...options,
172
+ ...options?.setPermission,
285
173
  });
286
- }
287
- /**
288
- * Hook to set delegation fee (owner only)
289
- */
290
- export function useSetDelegationFee(options) {
291
- const client = useMailerClient();
292
- const queryClient = useQueryClient();
293
- return useMutation({
294
- mutationFn: async ({ newFee }) => client.setDelegationFee(newFee),
174
+ const removePermission = useMutation({
175
+ mutationFn: async ({ contractAddress }) => client.removePermission(connectedWallet, chainInfo, contractAddress),
295
176
  onSuccess: () => {
296
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegationFee() });
177
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.permissions() });
297
178
  },
298
- ...options,
179
+ ...options?.removePermission,
299
180
  });
181
+ return {
182
+ setPermission,
183
+ removePermission,
184
+ };
300
185
  }
301
186
  /**
302
- * Hook to pause the contract (owner only)
187
+ * Hook for contract control operations (owner only)
303
188
  *
304
189
  * @example
305
190
  * ```tsx
306
- * function PauseButton() {
307
- * const pause = usePause();
191
+ * function ContractControls() {
192
+ * const { pause, unpause, emergencyUnpause } = useContractControl(client, wallet, chainInfo);
308
193
  *
309
194
  * return (
310
- * <button
311
- * onClick={() => pause.mutate()}
312
- * disabled={pause.isPending}
313
- * >
314
- * Pause Contract
315
- * </button>
195
+ * <>
196
+ * <button onClick={() => pause.mutate()}>Pause</button>
197
+ * <button onClick={() => unpause.mutate()}>Unpause</button>
198
+ * <button onClick={() => emergencyUnpause.mutate()}>Emergency Unpause</button>
199
+ * </>
316
200
  * );
317
201
  * }
318
202
  * ```
319
203
  */
320
- export function usePause(options) {
321
- const client = useMailerClient();
204
+ export function useContractControl(client, connectedWallet, chainInfo, options) {
322
205
  const queryClient = useQueryClient();
323
- return useMutation({
324
- mutationFn: () => client.pause(),
206
+ const pause = useMutation({
207
+ mutationFn: () => client.pause(connectedWallet, chainInfo),
325
208
  onSuccess: () => {
326
209
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
327
210
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
328
211
  },
329
- ...options,
212
+ ...options?.pause,
330
213
  });
331
- }
332
- /**
333
- * Hook to unpause the contract (owner only)
334
- *
335
- * @example
336
- * ```tsx
337
- * function UnpauseButton() {
338
- * const unpause = useUnpause();
339
- *
340
- * return (
341
- * <button onClick={() => unpause.mutate()}>
342
- * Unpause Contract
343
- * </button>
344
- * );
345
- * }
346
- * ```
347
- */
348
- export function useUnpause(options) {
349
- const client = useMailerClient();
350
- const queryClient = useQueryClient();
351
- return useMutation({
352
- mutationFn: () => client.unpause(),
214
+ const unpause = useMutation({
215
+ mutationFn: () => client.unpause(connectedWallet, chainInfo),
353
216
  onSuccess: () => {
354
217
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
355
218
  },
356
- ...options,
219
+ ...options?.unpause,
357
220
  });
358
- }
359
- /**
360
- * Hook to emergency unpause (owner only)
361
- */
362
- export function useEmergencyUnpause(options) {
363
- const client = useMailerClient();
364
- const queryClient = useQueryClient();
365
- return useMutation({
366
- mutationFn: () => client.emergencyUnpause(),
221
+ const emergencyUnpause = useMutation({
222
+ mutationFn: () => client.emergencyUnpause(connectedWallet, chainInfo),
367
223
  onSuccess: () => {
368
224
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
369
225
  },
370
- ...options,
226
+ ...options?.emergencyUnpause,
371
227
  });
228
+ return {
229
+ pause,
230
+ unpause,
231
+ emergencyUnpause,
232
+ };
372
233
  }
373
234
  /**
374
- * Hook to distribute claimable funds (anyone can call when paused)
235
+ * Hook for owner-specific operations
375
236
  *
376
237
  * @example
377
238
  * ```tsx
378
- * function DistributeFundsButton({ recipient }: { recipient: string }) {
379
- * const distribute = useDistributeClaimableFunds();
239
+ * function OwnerPanel() {
240
+ * const { setFees, distributeClaimableFunds } = useOwnerOperations(client, wallet, chainInfo);
380
241
  *
381
242
  * return (
382
- * <button onClick={() => distribute.mutate({ recipient })}>
383
- * Distribute Funds to {recipient}
384
- * </button>
243
+ * <>
244
+ * <button onClick={() => setFees.mutate({ sendFee: 200000n, delegationFee: 10000000n })}>
245
+ * Update Fees
246
+ * </button>
247
+ * <button onClick={() => distributeClaimableFunds.mutate({ recipient: '0xABC...' })}>
248
+ * Distribute Funds
249
+ * </button>
250
+ * </>
385
251
  * );
386
252
  * }
387
253
  * ```
388
254
  */
389
- export function useDistributeClaimableFunds(options) {
390
- const client = useMailerClient();
255
+ export function useOwnerOperations(client, connectedWallet, chainInfo, options) {
391
256
  const queryClient = useQueryClient();
392
- return useMutation({
393
- mutationFn: async ({ recipient }) => client.distributeClaimableFunds(recipient),
257
+ const setFees = useMutation({
258
+ mutationFn: async ({ sendFee, delegationFee }) => client.setFees(connectedWallet, chainInfo, sendFee, delegationFee),
259
+ onSuccess: () => {
260
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.sendFee() });
261
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegationFee() });
262
+ },
263
+ ...options?.setFees,
264
+ });
265
+ const distributeClaimableFunds = useMutation({
266
+ mutationFn: async ({ recipient }) => client.distributeClaimableFunds(connectedWallet, chainInfo, recipient),
394
267
  onSuccess: (_, variables) => {
395
268
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount(variables.recipient) });
396
269
  },
397
- ...options,
270
+ ...options?.distributeClaimableFunds,
398
271
  });
272
+ return {
273
+ setFees,
274
+ distributeClaimableFunds,
275
+ };
276
+ }
277
+ // ========== Legacy individual hooks for backward compatibility ==========
278
+ // These use context for convenience but the grouped hooks above are preferred
279
+ import { useMailerContext } from '../context/MailerProvider.js';
280
+ /**
281
+ * @deprecated Use useMessaging() instead
282
+ */
283
+ export function useSendMessage(options) {
284
+ const { client, wallet, chainInfo } = useMailerContext();
285
+ const { sendMessage } = useMessaging(client, wallet, chainInfo, { sendMessage: options });
286
+ return sendMessage;
287
+ }
288
+ /**
289
+ * @deprecated Use useMessaging() instead
290
+ */
291
+ export function useSendPrepared(options) {
292
+ const { client, wallet, chainInfo } = useMailerContext();
293
+ const { sendPrepared } = useMessaging(client, wallet, chainInfo, { sendPrepared: options });
294
+ return sendPrepared;
295
+ }
296
+ /**
297
+ * @deprecated Use useClaims() instead
298
+ */
299
+ export function useClaimRevenue(options) {
300
+ const { client, wallet, chainInfo } = useMailerContext();
301
+ const { claimRevenue } = useClaims(client, wallet, chainInfo, { claimRevenue: options });
302
+ return claimRevenue;
303
+ }
304
+ /**
305
+ * @deprecated Use useClaims() instead
306
+ */
307
+ export function useClaimOwnerShare(options) {
308
+ const { client, wallet, chainInfo } = useMailerContext();
309
+ const { claimOwnerShare } = useClaims(client, wallet, chainInfo, { claimOwnerShare: options });
310
+ return claimOwnerShare;
311
+ }
312
+ /**
313
+ * @deprecated Use useClaims() instead
314
+ */
315
+ export function useClaimExpiredShares(options) {
316
+ const { client, wallet, chainInfo } = useMailerContext();
317
+ const { claimExpiredShares } = useClaims(client, wallet, chainInfo, { claimExpiredShares: options });
318
+ return claimExpiredShares;
319
+ }
320
+ /**
321
+ * @deprecated Use useDelegation() instead
322
+ */
323
+ export function useDelegateTo(options) {
324
+ const { client, wallet, chainInfo } = useMailerContext();
325
+ const { delegateTo } = useDelegation(client, wallet, chainInfo, { delegateTo: options });
326
+ return delegateTo;
327
+ }
328
+ /**
329
+ * @deprecated Use useDelegation() instead
330
+ */
331
+ export function useRejectDelegation(options) {
332
+ const { client, wallet, chainInfo } = useMailerContext();
333
+ const { rejectDelegation } = useDelegation(client, wallet, chainInfo, { rejectDelegation: options });
334
+ return rejectDelegation;
335
+ }
336
+ /**
337
+ * @deprecated Use usePermissions() instead
338
+ */
339
+ export function useSetPermission(options) {
340
+ const { client, wallet, chainInfo } = useMailerContext();
341
+ const { setPermission } = usePermissions(client, wallet, chainInfo, { setPermission: options });
342
+ return setPermission;
343
+ }
344
+ /**
345
+ * @deprecated Use usePermissions() instead
346
+ */
347
+ export function useRemovePermission(options) {
348
+ const { client, wallet, chainInfo } = useMailerContext();
349
+ const { removePermission } = usePermissions(client, wallet, chainInfo, { removePermission: options });
350
+ return removePermission;
351
+ }
352
+ /**
353
+ * @deprecated Use useOwnerOperations() instead
354
+ */
355
+ export function useSetFees(options) {
356
+ const { client, wallet, chainInfo } = useMailerContext();
357
+ const { setFees } = useOwnerOperations(client, wallet, chainInfo, { setFees: options });
358
+ return setFees;
359
+ }
360
+ /**
361
+ * @deprecated Use useContractControl() instead
362
+ */
363
+ export function usePause(options) {
364
+ const { client, wallet, chainInfo } = useMailerContext();
365
+ const { pause } = useContractControl(client, wallet, chainInfo, { pause: options });
366
+ return pause;
367
+ }
368
+ /**
369
+ * @deprecated Use useContractControl() instead
370
+ */
371
+ export function useUnpause(options) {
372
+ const { client, wallet, chainInfo } = useMailerContext();
373
+ const { unpause } = useContractControl(client, wallet, chainInfo, { unpause: options });
374
+ return unpause;
375
+ }
376
+ /**
377
+ * @deprecated Use useContractControl() instead
378
+ */
379
+ export function useEmergencyUnpause(options) {
380
+ const { client, wallet, chainInfo } = useMailerContext();
381
+ const { emergencyUnpause } = useContractControl(client, wallet, chainInfo, { emergencyUnpause: options });
382
+ return emergencyUnpause;
383
+ }
384
+ /**
385
+ * @deprecated Use useOwnerOperations() instead
386
+ */
387
+ export function useDistributeClaimableFunds(options) {
388
+ const { client, wallet, chainInfo } = useMailerContext();
389
+ const { distributeClaimableFunds } = useOwnerOperations(client, wallet, chainInfo, { distributeClaimableFunds: options });
390
+ return distributeClaimableFunds;
399
391
  }
400
392
  //# sourceMappingURL=useMailerMutations.js.map