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