@sudobility/contracts 0.15.1 → 1.10.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.d.ts +2 -185
- package/artifacts/contracts/Mailer.sol/Mailer.dbg.json +1 -1
- package/artifacts/contracts/Mailer.sol/Mailer.json +2 -185
- 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 -128
- package/dist/evm/typechain-types/Mailer.d.ts.map +1 -1
- package/dist/evm/typechain-types/factories/Mailer__factory.d.ts +1 -145
- package/dist/evm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
- package/dist/evm/typechain-types/factories/Mailer__factory.js +1 -184
- 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 -128
- package/dist/unified/typechain-types/Mailer.d.ts.map +1 -1
- package/dist/unified/typechain-types/factories/Mailer__factory.d.ts +1 -145
- package/dist/unified/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
- package/dist/unified/typechain-types/factories/Mailer__factory.js +1 -184
- 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 -128
- package/dist/unified-esm/typechain-types/Mailer.d.ts.map +1 -1
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts +1 -145
- 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 -184
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.js.map +1 -1
- package/package.json +10 -17
- package/programs/mailer/src/lib.rs +145 -764
- package/programs/mailer/tests/integration_tests.rs +65 -586
- package/typechain-types/Mailer.ts +8 -215
- package/typechain-types/factories/Mailer__factory.ts +1 -184
- 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
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { getAddress } from "viem";
|
|
2
|
+
import { Mailer__factory } from "../../typechain-types/factories/Mailer__factory.js";
|
|
3
|
+
// Get ABI from typechain-generated factories
|
|
4
|
+
const MAILER_ABI = Mailer__factory.abi;
|
|
5
|
+
// Get bytecode from typechain-generated factories
|
|
6
|
+
const MAILER_BYTECODE = Mailer__factory.bytecode;
|
|
7
|
+
/**
|
|
8
|
+
* @class MailerClient
|
|
9
|
+
* @description High-level TypeScript client for the Mailer contract using viem
|
|
10
|
+
* @notice Provides easy-to-use methods for sending messages with USDC fees and revenue sharing
|
|
11
|
+
*
|
|
12
|
+
* ## Key Features:
|
|
13
|
+
* - **Delegation Management**: Delegate mail handling with rejection capability
|
|
14
|
+
* - **Priority Messages**: Full fee (0.1 USDC) with 90% revenue share to recipient
|
|
15
|
+
* - **Standard Messages**: 10% fee only (0.01 USDC) with no revenue share
|
|
16
|
+
* - **Revenue Claims**: 60-day claim period for priority message revenue shares
|
|
17
|
+
*
|
|
18
|
+
* ## Usage Examples:
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Connect to existing contract
|
|
21
|
+
* import { createPublicClient, createWalletClient, http } from 'viem';
|
|
22
|
+
* import { mainnet } from 'viem/chains';
|
|
23
|
+
*
|
|
24
|
+
* const publicClient = createPublicClient({
|
|
25
|
+
* chain: mainnet,
|
|
26
|
+
* transport: http()
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* const mailer = new MailerClient('CONTRACT_ADDRESS', publicClient);
|
|
30
|
+
*
|
|
31
|
+
* // Send message with revenue sharing to recipient
|
|
32
|
+
* const walletClient = createWalletClient({
|
|
33
|
+
* chain: mainnet,
|
|
34
|
+
* transport: http()
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* await mailer.send('0x...', 'Subject', 'Body', true, walletClient, account);
|
|
38
|
+
*
|
|
39
|
+
* // Claim your revenue share (as recipient)
|
|
40
|
+
* await mailer.claimRecipientShare(walletClient, account);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export class MailerClient {
|
|
44
|
+
/**
|
|
45
|
+
* @description Creates a new MailerClient instance
|
|
46
|
+
* @param contractAddress The deployed Mailer contract address
|
|
47
|
+
* @param publicClient Viem public client for reading blockchain state
|
|
48
|
+
*/
|
|
49
|
+
constructor(contractAddress, publicClient) {
|
|
50
|
+
this.contractAddress = getAddress(contractAddress);
|
|
51
|
+
this.publicClient = publicClient;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @description Deploy a new Mailer contract and return a client instance
|
|
55
|
+
* @param walletClient Viem wallet client with deployment permissions
|
|
56
|
+
* @param account Account to deploy from
|
|
57
|
+
* @param usdcTokenAddress Address of the USDC token contract
|
|
58
|
+
* @param ownerAddress Address that will own the deployed contract
|
|
59
|
+
* @returns Promise resolving to a MailerClient instance
|
|
60
|
+
*/
|
|
61
|
+
static async deploy(walletClient, publicClient, account, usdcTokenAddress, ownerAddress) {
|
|
62
|
+
const hash = await walletClient.deployContract({
|
|
63
|
+
abi: MAILER_ABI,
|
|
64
|
+
bytecode: MAILER_BYTECODE,
|
|
65
|
+
args: [getAddress(usdcTokenAddress), getAddress(ownerAddress)],
|
|
66
|
+
account,
|
|
67
|
+
chain: walletClient.chain,
|
|
68
|
+
});
|
|
69
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
70
|
+
if (!receipt.contractAddress) {
|
|
71
|
+
throw new Error("Contract deployment failed");
|
|
72
|
+
}
|
|
73
|
+
return new MailerClient(receipt.contractAddress, publicClient);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @description Send a message with optional revenue sharing
|
|
77
|
+
* @notice Two modes:
|
|
78
|
+
* - revenueShareToReceiver=true: Sender pays 0.1 USDC, recipient gets 90% claimable
|
|
79
|
+
* - revenueShareToReceiver=false: Sender pays 0.01 USDC only
|
|
80
|
+
* @param to Recipient address who receives the message and potential revenue share
|
|
81
|
+
* @param subject Message subject line
|
|
82
|
+
* @param body Message content
|
|
83
|
+
* @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
|
|
84
|
+
* @param resolveSenderToName If true, resolve sender address to name via off-chain service
|
|
85
|
+
* @param walletClient Viem wallet client for transaction
|
|
86
|
+
* @param account Account to send from
|
|
87
|
+
* @returns Promise resolving to transaction hash
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* // Send with revenue share to recipient
|
|
91
|
+
* const hash = await mailer.send('0x...', 'Subject', 'Priority message', true, false, walletClient, account);
|
|
92
|
+
* // Send standard message (no revenue share)
|
|
93
|
+
* const hash2 = await mailer.send('0x...', 'Subject', 'Standard message', false, false, walletClient, account);
|
|
94
|
+
* await publicClient.waitForTransactionReceipt({ hash });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
async send(to, subject, body, revenueShareToReceiver, resolveSenderToName = false, walletClient, account) {
|
|
98
|
+
return await walletClient.writeContract({
|
|
99
|
+
address: this.contractAddress,
|
|
100
|
+
abi: MAILER_ABI,
|
|
101
|
+
functionName: 'send',
|
|
102
|
+
args: [to, subject, body, revenueShareToReceiver, resolveSenderToName],
|
|
103
|
+
account,
|
|
104
|
+
chain: walletClient.chain,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @description Send a message using a pre-prepared mail ID with optional revenue sharing
|
|
109
|
+
* @notice Two modes:
|
|
110
|
+
* - revenueShareToReceiver=true: Sender pays 0.1 USDC, recipient gets 90% claimable
|
|
111
|
+
* - revenueShareToReceiver=false: Sender pays 0.01 USDC only
|
|
112
|
+
* @param to Recipient address who receives the message and potential revenue share
|
|
113
|
+
* @param mailId Pre-prepared message identifier
|
|
114
|
+
* @param revenueShareToReceiver If true, recipient gets 90% revenue share; if false, no revenue share
|
|
115
|
+
* @param resolveSenderToName If true, resolve sender address to name via off-chain service
|
|
116
|
+
* @param walletClient Viem wallet client for transaction
|
|
117
|
+
* @param account Account to send from
|
|
118
|
+
* @returns Promise resolving to transaction hash
|
|
119
|
+
*/
|
|
120
|
+
async sendPrepared(to, mailId, revenueShareToReceiver, resolveSenderToName = false, walletClient, account) {
|
|
121
|
+
return await walletClient.writeContract({
|
|
122
|
+
address: this.contractAddress,
|
|
123
|
+
abi: MAILER_ABI,
|
|
124
|
+
functionName: 'sendPrepared',
|
|
125
|
+
args: [to, mailId, revenueShareToReceiver, resolveSenderToName],
|
|
126
|
+
account,
|
|
127
|
+
chain: walletClient.chain,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async getSendFee() {
|
|
131
|
+
return await this.publicClient.readContract({
|
|
132
|
+
address: this.contractAddress,
|
|
133
|
+
abi: MAILER_ABI,
|
|
134
|
+
functionName: 'sendFee',
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async getUsdcToken() {
|
|
139
|
+
return await this.publicClient.readContract({
|
|
140
|
+
address: this.contractAddress,
|
|
141
|
+
abi: MAILER_ABI,
|
|
142
|
+
functionName: 'usdcToken',
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
getAddress() {
|
|
147
|
+
return this.contractAddress;
|
|
148
|
+
}
|
|
149
|
+
async claimRecipientShare(walletClient, account) {
|
|
150
|
+
return await walletClient.writeContract({
|
|
151
|
+
address: this.contractAddress,
|
|
152
|
+
abi: MAILER_ABI,
|
|
153
|
+
functionName: 'claimRecipientShare',
|
|
154
|
+
account,
|
|
155
|
+
chain: walletClient.chain,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async claimOwnerShare(walletClient, account) {
|
|
159
|
+
return await walletClient.writeContract({
|
|
160
|
+
address: this.contractAddress,
|
|
161
|
+
abi: MAILER_ABI,
|
|
162
|
+
functionName: 'claimOwnerShare',
|
|
163
|
+
account,
|
|
164
|
+
chain: walletClient.chain,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
async claimExpiredShares(recipient, walletClient, account) {
|
|
168
|
+
return await walletClient.writeContract({
|
|
169
|
+
address: this.contractAddress,
|
|
170
|
+
abi: MAILER_ABI,
|
|
171
|
+
functionName: 'claimExpiredShares',
|
|
172
|
+
args: [getAddress(recipient)],
|
|
173
|
+
account,
|
|
174
|
+
chain: walletClient.chain,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
async getRecipientClaimable(recipient) {
|
|
178
|
+
const result = await this.publicClient.readContract({
|
|
179
|
+
address: this.contractAddress,
|
|
180
|
+
abi: MAILER_ABI,
|
|
181
|
+
functionName: 'getRecipientClaimable',
|
|
182
|
+
args: [getAddress(recipient)],
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
+
});
|
|
185
|
+
return {
|
|
186
|
+
amount: result[0],
|
|
187
|
+
expiresAt: result[1],
|
|
188
|
+
isExpired: result[2]
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
async getOwnerClaimable() {
|
|
192
|
+
return await this.publicClient.readContract({
|
|
193
|
+
address: this.contractAddress,
|
|
194
|
+
abi: MAILER_ABI,
|
|
195
|
+
functionName: 'getOwnerClaimable'
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// Delegation functionality
|
|
200
|
+
/**
|
|
201
|
+
* Delegate mail handling to another address
|
|
202
|
+
* @param delegate Address to delegate to (or 0x0 to clear delegation)
|
|
203
|
+
* @param walletClient Connected wallet client
|
|
204
|
+
* @param account Account to send transaction from
|
|
205
|
+
* @returns Transaction hash
|
|
206
|
+
*/
|
|
207
|
+
async delegateTo(delegate, walletClient, account) {
|
|
208
|
+
return await walletClient.writeContract({
|
|
209
|
+
address: this.contractAddress,
|
|
210
|
+
abi: MAILER_ABI,
|
|
211
|
+
functionName: 'delegateTo',
|
|
212
|
+
args: [getAddress(delegate)],
|
|
213
|
+
account,
|
|
214
|
+
chain: walletClient.chain,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Reject a delegation made to you by another address
|
|
219
|
+
* @param delegatingAddress Address that delegated to you
|
|
220
|
+
* @param walletClient Connected wallet client
|
|
221
|
+
* @param account Account to send transaction from
|
|
222
|
+
* @returns Transaction hash
|
|
223
|
+
*/
|
|
224
|
+
async rejectDelegation(delegatingAddress, walletClient, account) {
|
|
225
|
+
return await walletClient.writeContract({
|
|
226
|
+
address: this.contractAddress,
|
|
227
|
+
abi: MAILER_ABI,
|
|
228
|
+
functionName: 'rejectDelegation',
|
|
229
|
+
args: [getAddress(delegatingAddress)],
|
|
230
|
+
account,
|
|
231
|
+
chain: walletClient.chain,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Get current delegation fee in USDC (6 decimals)
|
|
236
|
+
* @returns Delegation fee amount
|
|
237
|
+
*/
|
|
238
|
+
async getDelegationFee() {
|
|
239
|
+
return await this.publicClient.readContract({
|
|
240
|
+
address: this.contractAddress,
|
|
241
|
+
abi: MAILER_ABI,
|
|
242
|
+
functionName: 'getDelegationFee',
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Update delegation fee (owner only)
|
|
248
|
+
* @param newFee New fee amount in USDC (6 decimals)
|
|
249
|
+
* @param walletClient Connected wallet client
|
|
250
|
+
* @param account Account to send transaction from
|
|
251
|
+
* @returns Transaction hash
|
|
252
|
+
*/
|
|
253
|
+
async setDelegationFee(newFee, walletClient, account) {
|
|
254
|
+
return await walletClient.writeContract({
|
|
255
|
+
address: this.contractAddress,
|
|
256
|
+
abi: MAILER_ABI,
|
|
257
|
+
functionName: 'setDelegationFee',
|
|
258
|
+
args: [newFee],
|
|
259
|
+
account,
|
|
260
|
+
chain: walletClient.chain,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* @description Send a message to an email address (no wallet known)
|
|
265
|
+
* @notice Charges only 10% owner fee since recipient wallet is unknown
|
|
266
|
+
* @param toEmail Email address of the recipient
|
|
267
|
+
* @param subject Message subject line
|
|
268
|
+
* @param body Message content
|
|
269
|
+
* @param walletClient Viem wallet client for transaction
|
|
270
|
+
* @param account Account to send from
|
|
271
|
+
* @returns Promise resolving to transaction hash
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* // Send to email address
|
|
275
|
+
* const hash = await mailer.sendToEmailAddress('user@example.com', 'Subject', 'Body', walletClient, account);
|
|
276
|
+
* await publicClient.waitForTransactionReceipt({ hash });
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
async sendToEmailAddress(toEmail, subject, body, walletClient, account) {
|
|
280
|
+
return await walletClient.writeContract({
|
|
281
|
+
address: this.contractAddress,
|
|
282
|
+
abi: MAILER_ABI,
|
|
283
|
+
functionName: 'sendToEmailAddress',
|
|
284
|
+
args: [toEmail, subject, body],
|
|
285
|
+
account,
|
|
286
|
+
chain: walletClient.chain,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @description Send a pre-prepared message to an email address (no wallet known)
|
|
291
|
+
* @notice Charges only 10% owner fee since recipient wallet is unknown
|
|
292
|
+
* @param toEmail Email address of the recipient
|
|
293
|
+
* @param mailId Pre-prepared message identifier
|
|
294
|
+
* @param walletClient Viem wallet client for transaction
|
|
295
|
+
* @param account Account to send from
|
|
296
|
+
* @returns Promise resolving to transaction hash
|
|
297
|
+
*/
|
|
298
|
+
async sendPreparedToEmailAddress(toEmail, mailId, walletClient, account) {
|
|
299
|
+
return await walletClient.writeContract({
|
|
300
|
+
address: this.contractAddress,
|
|
301
|
+
abi: MAILER_ABI,
|
|
302
|
+
functionName: 'sendPreparedToEmailAddress',
|
|
303
|
+
args: [toEmail, mailId],
|
|
304
|
+
account,
|
|
305
|
+
chain: walletClient.chain,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Set the send fee (owner only)
|
|
310
|
+
* @param newFee New fee amount in USDC (6 decimals)
|
|
311
|
+
* @param walletClient Viem wallet client for transaction
|
|
312
|
+
* @param account Account to send from (must be owner)
|
|
313
|
+
* @returns Promise resolving to transaction hash
|
|
314
|
+
*/
|
|
315
|
+
async setFee(newFee, walletClient, account) {
|
|
316
|
+
return await walletClient.writeContract({
|
|
317
|
+
address: this.contractAddress,
|
|
318
|
+
abi: MAILER_ABI,
|
|
319
|
+
functionName: 'setFee',
|
|
320
|
+
args: [newFee],
|
|
321
|
+
account,
|
|
322
|
+
chain: walletClient.chain,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Get the current send fee
|
|
327
|
+
* @returns Current send fee in USDC (6 decimals)
|
|
328
|
+
*/
|
|
329
|
+
async getFee() {
|
|
330
|
+
return await this.publicClient.readContract({
|
|
331
|
+
address: this.contractAddress,
|
|
332
|
+
abi: MAILER_ABI,
|
|
333
|
+
functionName: 'getFee',
|
|
334
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Pause the contract and distribute all claimable funds (owner only)
|
|
339
|
+
* @param walletClient Viem wallet client for transaction
|
|
340
|
+
* @param account Account to send from (must be owner)
|
|
341
|
+
* @returns Promise resolving to transaction hash
|
|
342
|
+
*/
|
|
343
|
+
async pause(walletClient, account) {
|
|
344
|
+
return await walletClient.writeContract({
|
|
345
|
+
address: this.contractAddress,
|
|
346
|
+
abi: MAILER_ABI,
|
|
347
|
+
functionName: 'pause',
|
|
348
|
+
account,
|
|
349
|
+
chain: walletClient.chain,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Unpause the contract (owner only)
|
|
354
|
+
* @param walletClient Viem wallet client for transaction
|
|
355
|
+
* @param account Account to send from (must be owner)
|
|
356
|
+
* @returns Promise resolving to transaction hash
|
|
357
|
+
*/
|
|
358
|
+
async unpause(walletClient, account) {
|
|
359
|
+
return await walletClient.writeContract({
|
|
360
|
+
address: this.contractAddress,
|
|
361
|
+
abi: MAILER_ABI,
|
|
362
|
+
functionName: 'unpause',
|
|
363
|
+
account,
|
|
364
|
+
chain: walletClient.chain,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Emergency unpause without fund distribution (owner only)
|
|
369
|
+
* @param walletClient Viem wallet client for transaction
|
|
370
|
+
* @param account Account to send from (must be owner)
|
|
371
|
+
* @returns Promise resolving to transaction hash
|
|
372
|
+
*/
|
|
373
|
+
async emergencyUnpause(walletClient, account) {
|
|
374
|
+
return await walletClient.writeContract({
|
|
375
|
+
address: this.contractAddress,
|
|
376
|
+
abi: MAILER_ABI,
|
|
377
|
+
functionName: 'emergencyUnpause',
|
|
378
|
+
account,
|
|
379
|
+
chain: walletClient.chain,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Check if contract is currently paused
|
|
384
|
+
* @returns True if contract is paused, false otherwise
|
|
385
|
+
*/
|
|
386
|
+
async isPaused() {
|
|
387
|
+
return await this.publicClient.readContract({
|
|
388
|
+
address: this.contractAddress,
|
|
389
|
+
abi: MAILER_ABI,
|
|
390
|
+
functionName: 'isPaused',
|
|
391
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Distribute a specific recipient's claimable funds during pause
|
|
396
|
+
* Anyone can call this function when contract is paused
|
|
397
|
+
* @param recipient Address to distribute funds for
|
|
398
|
+
* @param walletClient Viem wallet client for transaction
|
|
399
|
+
* @param account Account to send from
|
|
400
|
+
* @returns Promise resolving to transaction hash
|
|
401
|
+
*/
|
|
402
|
+
async distributeClaimableFunds(recipient, walletClient, account) {
|
|
403
|
+
return await walletClient.writeContract({
|
|
404
|
+
address: this.contractAddress,
|
|
405
|
+
abi: MAILER_ABI,
|
|
406
|
+
functionName: 'distributeClaimableFunds',
|
|
407
|
+
args: [getAddress(recipient)],
|
|
408
|
+
account,
|
|
409
|
+
chain: walletClient.chain,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
//# sourceMappingURL=mailer-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailer-client.js","sourceRoot":"","sources":["../../../../src/evm/mailer-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,UAAU,EACX,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAErF,6CAA6C;AAC7C,MAAM,UAAU,GAAG,eAAe,CAAC,GAAG,CAAC;AAEvC,kDAAkD;AAClD,MAAM,eAAe,GAAG,eAAe,CAAC,QAAyB,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,OAAO,YAAY;IAIvB;;;;OAIG;IACH,YAAY,eAAuB,EAAE,YAA0B;QAC7D,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,YAA0B,EAC1B,YAA0B,EAC1B,OAA0B,EAC1B,gBAAwB,EACxB,YAAoB;QAEpB,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,cAAc,CAAC;YAC7C,GAAG,EAAE,UAAU;YACf,QAAQ,EAAE,eAAe;YACzB,IAAI,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE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AC7B,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,SAAS;YACvB,OAAO;YACP,KAAK,EAAE,YAAY,CAAC,KAAK;SAC1B,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,gBAAgB,CACpB,YAA0B,EAC1B,OAA0B;QAE1B,OAAO,MAAM,YAAY,CAAC,aAAa,CAAC;YACtC,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,kBAAkB;YAChC,OAAO;YACP,KAAK,EAAE,YAAY,CAAC,KAAK;SAC1B,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;YAC1C,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,UAAU;YACxB,8DAA8D;SACxD,CAAY,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,wBAAwB,CAC5B,SAAiB,EACjB,YAA0B,EAC1B,OAA0B;QAE1B,OAAO,MAAM,YAAY,CAAC,aAAa,CAAC;YACtC,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,0BAA0B;YACxC,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YAC7B,OAAO;YACP,KAAK,EAAE,YAAY,CAAC,KAAK;SAC1B,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { OnchainMailerClient } from '../../unified/onchain-mailer-client';
|
|
4
|
-
import type {
|
|
5
|
-
import type { Wallet } from '../../unified/types';
|
|
6
|
-
/**
|
|
7
|
-
* Context for Mailer client and configuration
|
|
8
|
-
*/
|
|
9
|
-
interface MailerContextValue {
|
|
10
|
-
client: OnchainMailerClient;
|
|
11
|
-
wallet: Wallet;
|
|
12
|
-
chainInfo: ChainInfo;
|
|
13
|
-
}
|
|
4
|
+
import type { ChainConfig } from '../../unified/types';
|
|
14
5
|
/**
|
|
15
6
|
* Props for MailerProvider
|
|
16
7
|
*/
|
|
@@ -18,9 +9,9 @@ export interface MailerProviderProps {
|
|
|
18
9
|
/** Child components */
|
|
19
10
|
children: ReactNode;
|
|
20
11
|
/** Wallet instance (EVM or Solana) */
|
|
21
|
-
wallet:
|
|
22
|
-
/** Chain
|
|
23
|
-
|
|
12
|
+
wallet: any;
|
|
13
|
+
/** Chain configuration */
|
|
14
|
+
config: ChainConfig;
|
|
24
15
|
/** Optional React Query client (creates default if not provided) */
|
|
25
16
|
queryClient?: QueryClient;
|
|
26
17
|
}
|
|
@@ -33,14 +24,22 @@ export interface MailerProviderProps {
|
|
|
33
24
|
* @example
|
|
34
25
|
* ```tsx
|
|
35
26
|
* import { MailerProvider } from '@johnqh/mail_box_contracts/react';
|
|
36
|
-
* import { getChainInfo } from '@sudobility/configs';
|
|
37
27
|
*
|
|
38
28
|
* function App() {
|
|
39
29
|
* const wallet = useWallet(); // Your wallet hook
|
|
40
|
-
* const
|
|
30
|
+
* const config = {
|
|
31
|
+
* evm: {
|
|
32
|
+
* rpc: 'https://eth-mainnet.g.alchemy.com/v2/YOUR-KEY',
|
|
33
|
+
* chainId: 1,
|
|
34
|
+
* contracts: {
|
|
35
|
+
* mailer: '0x123...',
|
|
36
|
+
* usdc: '0x456...'
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* };
|
|
41
40
|
*
|
|
42
41
|
* return (
|
|
43
|
-
* <MailerProvider wallet={wallet}
|
|
42
|
+
* <MailerProvider wallet={wallet} config={config}>
|
|
44
43
|
* <YourApp />
|
|
45
44
|
* </MailerProvider>
|
|
46
45
|
* );
|
|
@@ -63,7 +62,7 @@ export interface MailerProviderProps {
|
|
|
63
62
|
* return (
|
|
64
63
|
* <MailerProvider
|
|
65
64
|
* wallet={wallet}
|
|
66
|
-
*
|
|
65
|
+
* config={config}
|
|
67
66
|
* queryClient={customQueryClient}
|
|
68
67
|
* >
|
|
69
68
|
* <YourApp />
|
|
@@ -72,9 +71,9 @@ export interface MailerProviderProps {
|
|
|
72
71
|
* }
|
|
73
72
|
* ```
|
|
74
73
|
*/
|
|
75
|
-
export declare function MailerProvider({ children, wallet,
|
|
74
|
+
export declare function MailerProvider({ children, wallet, config, queryClient }: MailerProviderProps): React.JSX.Element;
|
|
76
75
|
/**
|
|
77
|
-
* Hook to access the
|
|
76
|
+
* Hook to access the OnchainMailerClient instance
|
|
78
77
|
*
|
|
79
78
|
* Must be used within a MailerProvider component.
|
|
80
79
|
*
|
|
@@ -83,11 +82,11 @@ export declare function MailerProvider({ children, wallet, chainInfo, queryClien
|
|
|
83
82
|
* @example
|
|
84
83
|
* ```tsx
|
|
85
84
|
* function MyComponent() {
|
|
86
|
-
* const
|
|
85
|
+
* const client = useMailerClient();
|
|
87
86
|
*
|
|
88
87
|
* const handleDirectCall = async () => {
|
|
89
88
|
* // Direct API call (not recommended, use hooks instead)
|
|
90
|
-
* const fee = await client.getSendFee(
|
|
89
|
+
* const fee = await client.getSendFee();
|
|
91
90
|
* console.log('Fee:', fee);
|
|
92
91
|
* };
|
|
93
92
|
*
|
|
@@ -95,11 +94,6 @@ export declare function MailerProvider({ children, wallet, chainInfo, queryClien
|
|
|
95
94
|
* }
|
|
96
95
|
* ```
|
|
97
96
|
*/
|
|
98
|
-
export declare function useMailerContext(): MailerContextValue;
|
|
99
|
-
/**
|
|
100
|
-
* Hook to access the OnchainMailerClient instance
|
|
101
|
-
* @deprecated Use useMailerContext() instead to get client, wallet, and chainInfo
|
|
102
|
-
*/
|
|
103
97
|
export declare function useMailerClient(): OnchainMailerClient;
|
|
104
98
|
/**
|
|
105
99
|
* Re-export QueryClientProvider for convenience
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailerProvider.d.ts","sourceRoot":"","sources":["../../../../../src/react/context/MailerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"MailerProvider.d.ts","sourceRoot":"","sources":["../../../../../src/react/context/MailerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAOvD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uBAAuB;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,sCAAsC;IAEtC,MAAM,EAAE,GAAG,CAAC;IACZ,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,oEAAoE;IACpE,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,mBAAmB,qBAgB5F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,IAAI,mBAAmB,CAQrD;AAED;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React, { createContext, useContext } from 'react';
|
|
2
2
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
3
3
|
import { OnchainMailerClient } from '../../unified/onchain-mailer-client.js';
|
|
4
|
+
/**
|
|
5
|
+
* Context for OnchainMailerClient
|
|
6
|
+
*/
|
|
4
7
|
const MailerClientContext = createContext(null);
|
|
5
8
|
/**
|
|
6
9
|
* Default React Query client with sensible defaults for blockchain queries
|
|
@@ -27,14 +30,22 @@ const defaultQueryClient = new QueryClient({
|
|
|
27
30
|
* @example
|
|
28
31
|
* ```tsx
|
|
29
32
|
* import { MailerProvider } from '@johnqh/mail_box_contracts/react';
|
|
30
|
-
* import { getChainInfo } from '@sudobility/configs';
|
|
31
33
|
*
|
|
32
34
|
* function App() {
|
|
33
35
|
* const wallet = useWallet(); // Your wallet hook
|
|
34
|
-
* const
|
|
36
|
+
* const config = {
|
|
37
|
+
* evm: {
|
|
38
|
+
* rpc: 'https://eth-mainnet.g.alchemy.com/v2/YOUR-KEY',
|
|
39
|
+
* chainId: 1,
|
|
40
|
+
* contracts: {
|
|
41
|
+
* mailer: '0x123...',
|
|
42
|
+
* usdc: '0x456...'
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* };
|
|
35
46
|
*
|
|
36
47
|
* return (
|
|
37
|
-
* <MailerProvider wallet={wallet}
|
|
48
|
+
* <MailerProvider wallet={wallet} config={config}>
|
|
38
49
|
* <YourApp />
|
|
39
50
|
* </MailerProvider>
|
|
40
51
|
* );
|
|
@@ -57,7 +68,7 @@ const defaultQueryClient = new QueryClient({
|
|
|
57
68
|
* return (
|
|
58
69
|
* <MailerProvider
|
|
59
70
|
* wallet={wallet}
|
|
60
|
-
*
|
|
71
|
+
* config={config}
|
|
61
72
|
* queryClient={customQueryClient}
|
|
62
73
|
* >
|
|
63
74
|
* <YourApp />
|
|
@@ -66,17 +77,15 @@ const defaultQueryClient = new QueryClient({
|
|
|
66
77
|
* }
|
|
67
78
|
* ```
|
|
68
79
|
*/
|
|
69
|
-
export function MailerProvider({ children, wallet,
|
|
70
|
-
// Create OnchainMailerClient instance
|
|
71
|
-
const client = React.useMemo(() => new OnchainMailerClient(), []);
|
|
72
|
-
// Create context value with client, wallet, and chainInfo
|
|
73
|
-
const contextValue = React.useMemo(() => ({ client, wallet, chainInfo }), [client, wallet, chainInfo]);
|
|
80
|
+
export function MailerProvider({ children, wallet, config, queryClient }) {
|
|
81
|
+
// Create OnchainMailerClient instance
|
|
82
|
+
const client = React.useMemo(() => new OnchainMailerClient(wallet, config), [wallet, config]);
|
|
74
83
|
const qc = queryClient || defaultQueryClient;
|
|
75
84
|
return (React.createElement(QueryClientProvider, { client: qc },
|
|
76
|
-
React.createElement(MailerClientContext.Provider, { value:
|
|
85
|
+
React.createElement(MailerClientContext.Provider, { value: client }, children)));
|
|
77
86
|
}
|
|
78
87
|
/**
|
|
79
|
-
* Hook to access the
|
|
88
|
+
* Hook to access the OnchainMailerClient instance
|
|
80
89
|
*
|
|
81
90
|
* Must be used within a MailerProvider component.
|
|
82
91
|
*
|
|
@@ -85,11 +94,11 @@ export function MailerProvider({ children, wallet, chainInfo, queryClient }) {
|
|
|
85
94
|
* @example
|
|
86
95
|
* ```tsx
|
|
87
96
|
* function MyComponent() {
|
|
88
|
-
* const
|
|
97
|
+
* const client = useMailerClient();
|
|
89
98
|
*
|
|
90
99
|
* const handleDirectCall = async () => {
|
|
91
100
|
* // Direct API call (not recommended, use hooks instead)
|
|
92
|
-
* const fee = await client.getSendFee(
|
|
101
|
+
* const fee = await client.getSendFee();
|
|
93
102
|
* console.log('Fee:', fee);
|
|
94
103
|
* };
|
|
95
104
|
*
|
|
@@ -97,19 +106,11 @@ export function MailerProvider({ children, wallet, chainInfo, queryClient }) {
|
|
|
97
106
|
* }
|
|
98
107
|
* ```
|
|
99
108
|
*/
|
|
100
|
-
export function useMailerContext() {
|
|
101
|
-
const context = useContext(MailerClientContext);
|
|
102
|
-
if (!context) {
|
|
103
|
-
throw new Error('useMailerContext must be used within a MailerProvider');
|
|
104
|
-
}
|
|
105
|
-
return context;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Hook to access the OnchainMailerClient instance
|
|
109
|
-
* @deprecated Use useMailerContext() instead to get client, wallet, and chainInfo
|
|
110
|
-
*/
|
|
111
109
|
export function useMailerClient() {
|
|
112
|
-
const
|
|
110
|
+
const client = useContext(MailerClientContext);
|
|
111
|
+
if (!client) {
|
|
112
|
+
throw new Error('useMailerClient must be used within a MailerProvider');
|
|
113
|
+
}
|
|
113
114
|
return client;
|
|
114
115
|
}
|
|
115
116
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailerProvider.js","sourceRoot":"","sources":["../../../../../src/react/context/MailerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAa,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"MailerProvider.js","sourceRoot":"","sources":["../../../../../src/react/context/MailerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAa,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAG1E;;GAEG;AACH,MAAM,mBAAmB,GAAG,aAAa,CAA6B,IAAI,CAAC,CAAC;AAiB5E;;GAEG;AACH,MAAM,kBAAkB,GAAG,IAAI,WAAW,CAAC;IACzC,cAAc,EAAE;QACd,OAAO,EAAE;YACP,KAAK,EAAE,CAAC;YACR,UAAU,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,YAAY,EAAE,KAAK,C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