@reown/appkit-common-react-native 0.0.0-feat-multi-social-20250714211631 → 0.0.0-feat-onramp-20250718185718

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 (74) hide show
  1. package/lib/commonjs/index.js +1 -62
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/utils/ConstantsUtil.js +1 -4
  4. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  5. package/lib/commonjs/utils/NumberUtil.js +11 -52
  6. package/lib/commonjs/utils/NumberUtil.js.map +1 -1
  7. package/lib/commonjs/utils/PresetsUtil.js +8 -34
  8. package/lib/commonjs/utils/PresetsUtil.js.map +1 -1
  9. package/lib/commonjs/utils/TypeUtil.js +0 -46
  10. package/lib/commonjs/utils/TypeUtil.js.map +1 -1
  11. package/lib/module/index.js +0 -5
  12. package/lib/module/index.js.map +1 -1
  13. package/lib/module/utils/ConstantsUtil.js +1 -4
  14. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  15. package/lib/module/utils/NumberUtil.js +11 -52
  16. package/lib/module/utils/NumberUtil.js.map +1 -1
  17. package/lib/module/utils/PresetsUtil.js +8 -34
  18. package/lib/module/utils/PresetsUtil.js.map +1 -1
  19. package/lib/module/utils/TypeUtil.js +0 -40
  20. package/lib/module/utils/TypeUtil.js.map +1 -1
  21. package/lib/typescript/index.d.ts +0 -5
  22. package/lib/typescript/index.d.ts.map +1 -1
  23. package/lib/typescript/utils/ConstantsUtil.d.ts +0 -3
  24. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  25. package/lib/typescript/utils/NumberUtil.d.ts +11 -39
  26. package/lib/typescript/utils/NumberUtil.d.ts.map +1 -1
  27. package/lib/typescript/utils/PresetsUtil.d.ts +3 -1
  28. package/lib/typescript/utils/PresetsUtil.d.ts.map +1 -1
  29. package/lib/typescript/utils/TypeUtil.d.ts +11 -291
  30. package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
  31. package/package.json +2 -2
  32. package/src/index.ts +0 -5
  33. package/src/utils/ConstantsUtil.ts +1 -4
  34. package/src/utils/NumberUtil.ts +11 -54
  35. package/src/utils/PresetsUtil.ts +10 -36
  36. package/src/utils/TypeUtil.ts +13 -375
  37. package/lib/commonjs/adapters/BlockchainAdapter.js +0 -79
  38. package/lib/commonjs/adapters/BlockchainAdapter.js.map +0 -1
  39. package/lib/commonjs/adapters/EvmAdapter.js +0 -267
  40. package/lib/commonjs/adapters/EvmAdapter.js.map +0 -1
  41. package/lib/commonjs/adapters/SolanaBaseAdapter.js +0 -12
  42. package/lib/commonjs/adapters/SolanaBaseAdapter.js.map +0 -1
  43. package/lib/commonjs/networks/bitcoin.js +0 -40
  44. package/lib/commonjs/networks/bitcoin.js.map +0 -1
  45. package/lib/commonjs/networks/solana.js +0 -78
  46. package/lib/commonjs/networks/solana.js.map +0 -1
  47. package/lib/module/adapters/BlockchainAdapter.js +0 -72
  48. package/lib/module/adapters/BlockchainAdapter.js.map +0 -1
  49. package/lib/module/adapters/EvmAdapter.js +0 -261
  50. package/lib/module/adapters/EvmAdapter.js.map +0 -1
  51. package/lib/module/adapters/SolanaBaseAdapter.js +0 -5
  52. package/lib/module/adapters/SolanaBaseAdapter.js.map +0 -1
  53. package/lib/module/networks/bitcoin.js +0 -34
  54. package/lib/module/networks/bitcoin.js.map +0 -1
  55. package/lib/module/networks/solana.js +0 -72
  56. package/lib/module/networks/solana.js.map +0 -1
  57. package/lib/typescript/adapters/BlockchainAdapter.d.ts +0 -27
  58. package/lib/typescript/adapters/BlockchainAdapter.d.ts.map +0 -1
  59. package/lib/typescript/adapters/EvmAdapter.d.ts +0 -55
  60. package/lib/typescript/adapters/EvmAdapter.d.ts.map +0 -1
  61. package/lib/typescript/adapters/SolanaBaseAdapter.d.ts +0 -4
  62. package/lib/typescript/adapters/SolanaBaseAdapter.d.ts.map +0 -1
  63. package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts +0 -2
  64. package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts.map +0 -1
  65. package/lib/typescript/networks/bitcoin.d.ts +0 -4
  66. package/lib/typescript/networks/bitcoin.d.ts.map +0 -1
  67. package/lib/typescript/networks/solana.d.ts +0 -5
  68. package/lib/typescript/networks/solana.d.ts.map +0 -1
  69. package/src/adapters/BlockchainAdapter.ts +0 -109
  70. package/src/adapters/EvmAdapter.ts +0 -298
  71. package/src/adapters/SolanaBaseAdapter.ts +0 -5
  72. package/src/adapters/__tests__/EvmAdapter.test.ts +0 -104
  73. package/src/networks/bitcoin.ts +0 -32
  74. package/src/networks/solana.ts +0 -44
@@ -1,298 +0,0 @@
1
- import { BlockchainAdapter } from './BlockchainAdapter';
2
- import { NumberUtil } from '../utils/NumberUtil';
3
-
4
- // Type definitions for writeContract
5
- export interface WriteContractData {
6
- tokenAddress: `0x${string}`;
7
- receiverAddress: `0x${string}`;
8
- tokenAmount: bigint;
9
- fromAddress: `0x${string}`;
10
- method: 'transfer' | 'transferFrom' | 'approve';
11
- abi?: any; // Optional ABI for future extensibility
12
- spenderAddress?: `0x${string}`; // Required for transferFrom and approve
13
- }
14
-
15
- // Simple ABI encoder for ERC20 functions
16
- function encodeERC20Function(method: string, params: any[]): string {
17
- const functionSelectors = {
18
- transfer: '0xa9059cbb', // transfer(address,uint256)
19
- transferFrom: '0x23b872dd', // transferFrom(address,address,uint256)
20
- approve: '0x095ea7b3' // approve(address,uint256)
21
- };
22
-
23
- const selector = functionSelectors[method as keyof typeof functionSelectors];
24
- if (!selector) {
25
- throw new Error(`EVMAdapter:encodeERC20Function - unsupported method: ${method}`);
26
- }
27
-
28
- let encodedParams = '';
29
-
30
- switch (method) {
31
- case 'transfer':
32
- if (params.length !== 2) throw new Error('transfer requires 2 parameters: to, amount');
33
- const [to, amount] = params;
34
- encodedParams =
35
- to.toLowerCase().slice(2).padStart(64, '0') + amount.toString(16).padStart(64, '0');
36
- break;
37
-
38
- case 'transferFrom':
39
- if (params.length !== 3)
40
- throw new Error('transferFrom requires 3 parameters: from, to, amount');
41
- const [from, toTransferFrom, amountTransferFrom] = params;
42
- encodedParams =
43
- from.toLowerCase().slice(2).padStart(64, '0') +
44
- toTransferFrom.toLowerCase().slice(2).padStart(64, '0') +
45
- amountTransferFrom.toString(16).padStart(64, '0');
46
- break;
47
-
48
- case 'approve':
49
- if (params.length !== 2) throw new Error('approve requires 2 parameters: spender, amount');
50
- const [spender, amountApprove] = params;
51
- encodedParams =
52
- spender.toLowerCase().slice(2).padStart(64, '0') +
53
- amountApprove.toString(16).padStart(64, '0');
54
- break;
55
-
56
- default:
57
- throw new Error(`EVMAdapter:encodeERC20Function - unsupported method: ${method}`);
58
- }
59
-
60
- return selector + encodedParams;
61
- }
62
-
63
- export abstract class EVMAdapter extends BlockchainAdapter {
64
- override subscribeToEvents(): void {
65
- super.subscribeToEvents();
66
- const provider = this.getProvider();
67
- if (!provider) return;
68
-
69
- provider.on('reown_updateEmail', (info: any) => {
70
- // this.emit('updateEmail', email);
71
- //TODO: check this
72
- //eslint-disable-next-line no-console
73
- console.log('reown_updateEmail', info);
74
- });
75
- }
76
-
77
- async signMessage(address: string, message: string, chain?: string): Promise<string> {
78
- const provider = this.getProvider();
79
-
80
- if (!provider) {
81
- throw new Error('EVMAdapter:signMessage - provider is undefined');
82
- }
83
-
84
- const signature = await provider.request(
85
- {
86
- method: 'personal_sign',
87
- params: [message, address]
88
- },
89
- `eip155:${chain}`
90
- );
91
-
92
- return signature as string;
93
- }
94
- async estimateGas({ address, to, data, chainNamespace }: any): Promise<bigint> {
95
- const provider = this.getProvider();
96
-
97
- if (!provider) {
98
- throw new Error('EVMAdapter:estimateGas - provider is undefined');
99
- }
100
-
101
- if (!address) {
102
- throw new Error('EVMAdapter:estimateGas - from address is undefined');
103
- }
104
-
105
- if (chainNamespace && chainNamespace !== 'eip155') {
106
- throw new Error('EVMAdapter:estimateGas - chainNamespace is not eip155');
107
- }
108
-
109
- try {
110
- const txParams = {
111
- from: address,
112
- to,
113
- data,
114
- type: '0x0' // optional, legacy type
115
- };
116
-
117
- const estimatedGasHex = await provider.request({
118
- method: 'eth_estimateGas',
119
- params: [txParams]
120
- });
121
-
122
- return BigInt(estimatedGasHex as string);
123
- } catch (error) {
124
- throw new Error('EVMAdapter:estimateGas - eth_estimateGas RPC failed');
125
- }
126
- }
127
-
128
- async sendTransaction(data: any) {
129
- const { address } = data || {};
130
-
131
- if (!this.getProvider()) {
132
- throw new Error('EVMAdapter:sendTransaction - provider is undefined');
133
- }
134
-
135
- if (!address) {
136
- throw new Error('EVMAdapter:sendTransaction - address is undefined');
137
- }
138
-
139
- const txParams = {
140
- from: address,
141
- to: data.to,
142
- value: NumberUtil.convertNumericToHexString(data.value),
143
- gas: NumberUtil.convertNumericToHexString(data.gas),
144
- gasPrice: NumberUtil.convertNumericToHexString(data.gasPrice),
145
- data: data.data, // hex-encoded bytecode
146
- type: '0x0' // optional: legacy transaction type
147
- };
148
-
149
- const txHash = await this.getProvider().request({
150
- method: 'eth_sendTransaction',
151
- params: [txParams]
152
- });
153
-
154
- return txHash || null;
155
- }
156
-
157
- /**
158
- * Executes a write operation on an ERC20 smart contract.
159
- * This function is library-agnostic and uses only the provider for blockchain interactions.
160
- *
161
- * @param data - The contract interaction data
162
- * @param data.tokenAddress - The ERC20 token contract address
163
- * @param data.receiverAddress - The recipient address (required for transfer method)
164
- * @param data.tokenAmount - The amount of tokens to transfer/approve
165
- * @param data.fromAddress - The sender's address
166
- * @param data.method - The ERC20 method to call: 'transfer', 'transferFrom', or 'approve'
167
- * @param data.spenderAddress - The spender address (required for transferFrom and approve methods)
168
- * @param data.abi - Optional ABI for future extensibility
169
- *
170
- * @returns Promise resolving to the transaction block hash or null if failed
171
- *
172
- * @example
173
- * ```typescript
174
- * // Transfer tokens
175
- * const result = await adapter.writeContract({
176
- * tokenAddress: '0x1234567890123456789012345678901234567890',
177
- * receiverAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
178
- * tokenAmount: BigInt(1000000000000000000), // 1 token with 18 decimals
179
- * fromAddress: '0x1234567890123456789012345678901234567890',
180
- * method: 'transfer'
181
- * });
182
- *
183
- * // Approve tokens
184
- * const result = await adapter.writeContract({
185
- * tokenAddress: '0x1234567890123456789012345678901234567890',
186
- * receiverAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
187
- * tokenAmount: BigInt(1000000000000000000),
188
- * fromAddress: '0x1234567890123456789012345678901234567890',
189
- * method: 'approve',
190
- * spenderAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd'
191
- * });
192
- * ```
193
- */
194
- async writeContract(data: WriteContractData): Promise<`0x${string}` | null> {
195
- const { tokenAddress, receiverAddress, tokenAmount, method, fromAddress, spenderAddress } =
196
- data;
197
-
198
- if (!this.getProvider()) {
199
- throw new Error('EVMAdapter:writeContract - provider is undefined');
200
- }
201
-
202
- if (!fromAddress) {
203
- throw new Error('EVMAdapter:writeContract - fromAddress is undefined');
204
- }
205
-
206
- if (!tokenAddress) {
207
- throw new Error('EVMAdapter:writeContract - tokenAddress is undefined');
208
- }
209
-
210
- if (!tokenAmount) {
211
- throw new Error('EVMAdapter:writeContract - tokenAmount is undefined');
212
- }
213
-
214
- if (!method) {
215
- throw new Error('EVMAdapter:writeContract - method is undefined');
216
- }
217
-
218
- // Validate method-specific parameters
219
- if (method === 'transfer' && !receiverAddress) {
220
- throw new Error('EVMAdapter:writeContract - receiverAddress is required for transfer method');
221
- }
222
-
223
- if ((method === 'transferFrom' || method === 'approve') && !spenderAddress) {
224
- throw new Error(`EVMAdapter:writeContract - spenderAddress is required for ${method} method`);
225
- }
226
-
227
- // Encode the function call data based on method
228
- let encodedData: string;
229
-
230
- switch (method) {
231
- case 'transfer':
232
- encodedData = encodeERC20Function('transfer', [receiverAddress, tokenAmount]);
233
- break;
234
- case 'transferFrom':
235
- encodedData = encodeERC20Function('transferFrom', [
236
- fromAddress,
237
- receiverAddress,
238
- tokenAmount
239
- ]);
240
- break;
241
- case 'approve':
242
- encodedData = encodeERC20Function('approve', [spenderAddress, tokenAmount]);
243
- break;
244
- default:
245
- throw new Error(`EVMAdapter:writeContract - method '${method}' is not supported`);
246
- }
247
-
248
- // Create transaction parameters
249
- const txParams = {
250
- from: fromAddress,
251
- to: tokenAddress,
252
- data: encodedData,
253
- value: '0x0', // No ETH value for token operations
254
- type: '0x0' // legacy transaction type
255
- };
256
-
257
- try {
258
- // Send the transaction
259
- const txHash = await this.getProvider().request({
260
- method: 'eth_sendTransaction',
261
- params: [txParams]
262
- });
263
-
264
- // Wait for transaction receipt
265
- let receipt = null;
266
- let attempts = 0;
267
- const maxAttempts = 60; // 60 seconds timeout
268
-
269
- while (!receipt && attempts < maxAttempts) {
270
- receipt = (await this.getProvider().request({
271
- method: 'eth_getTransactionReceipt',
272
- params: [txHash]
273
- })) as { blockHash?: `0x${string}`; status?: string };
274
-
275
- if (!receipt) {
276
- await new Promise(r => setTimeout(r, 1000)); // wait 1s
277
- attempts++;
278
- }
279
- }
280
-
281
- if (!receipt) {
282
- throw new Error('EVMAdapter:writeContract - transaction timeout');
283
- }
284
-
285
- // Check if transaction was successful
286
- if (receipt.status === '0x0') {
287
- throw new Error('EVMAdapter:writeContract - transaction failed');
288
- }
289
-
290
- return receipt?.blockHash || null;
291
- } catch (error) {
292
- if (error instanceof Error) {
293
- throw new Error(`EVMAdapter:writeContract - ${error.message}`);
294
- }
295
- throw new Error('EVMAdapter:writeContract - unknown error occurred');
296
- }
297
- }
298
- }
@@ -1,5 +0,0 @@
1
- import { BlockchainAdapter } from './BlockchainAdapter';
2
-
3
- export abstract class SolanaBaseAdapter extends BlockchainAdapter {
4
- // solana logic
5
- }
@@ -1,104 +0,0 @@
1
- import { EVMAdapter } from '../EvmAdapter';
2
- import type { CaipAddress } from '../../utils/TypeUtil';
3
-
4
- // Mock implementation for testing
5
- class MockEVMAdapter extends EVMAdapter {
6
- private mockProvider: any;
7
-
8
- constructor() {
9
- super({ projectId: 'test', supportedNamespace: 'eip155' });
10
- this.mockProvider = {
11
- request: jest.fn(),
12
- on: jest.fn(),
13
- off: jest.fn()
14
- };
15
- }
16
-
17
- setMockProvider(provider: any) {
18
- this.mockProvider = provider;
19
- }
20
-
21
- override getProvider() {
22
- return this.mockProvider;
23
- }
24
-
25
- async disconnect(): Promise<void> {}
26
- getSupportedNamespace() {
27
- return 'eip155' as const;
28
- }
29
- async getBalance() {
30
- return { amount: '0', symbol: 'ETH' };
31
- }
32
- getAccounts(): CaipAddress[] | undefined {
33
- return ['eip155:1:0x1234567890123456789012345678901234567890'];
34
- }
35
- async switchNetwork() {}
36
- }
37
-
38
- describe('EVMAdapter', () => {
39
- let adapter: MockEVMAdapter;
40
-
41
- beforeEach(() => {
42
- adapter = new MockEVMAdapter();
43
- });
44
-
45
- describe('writeContract', () => {
46
- it('should encode transfer function correctly', async () => {
47
- const mockProvider = {
48
- request: jest
49
- .fn()
50
- .mockResolvedValueOnce('0x1234567890abcdef') // eth_sendTransaction
51
- .mockResolvedValueOnce({ blockHash: '0xabcdef1234567890', status: '0x1' }) // eth_getTransactionReceipt
52
- };
53
- adapter.setMockProvider(mockProvider);
54
-
55
- const result = await adapter.writeContract({
56
- tokenAddress: '0x1234567890123456789012345678901234567890',
57
- receiverAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
58
- tokenAmount: BigInt(1000000000000000000), // 1 token with 18 decimals
59
- fromAddress: '0x1234567890123456789012345678901234567890',
60
- method: 'transfer'
61
- });
62
-
63
- expect(result).toBe('0xabcdef1234567890');
64
- expect(mockProvider.request).toHaveBeenCalledWith({
65
- method: 'eth_sendTransaction',
66
- params: [
67
- {
68
- from: '0x1234567890123456789012345678901234567890',
69
- to: '0x1234567890123456789012345678901234567890',
70
- data: '0xa9059cbb000000000000000000000000abcdefabcdefabcdefabcdefabcdefabcdefabcd0000000000000000000000000000000000000000000000000de0b6b3a7640000',
71
- value: '0x0',
72
- type: '0x0'
73
- }
74
- ]
75
- });
76
- });
77
-
78
- it('should throw error for unsupported method', async () => {
79
- await expect(
80
- adapter.writeContract({
81
- tokenAddress: '0x1234567890123456789012345678901234567890',
82
- receiverAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
83
- tokenAmount: BigInt(1000000000000000000),
84
- fromAddress: '0x1234567890123456789012345678901234567890',
85
- method: 'unsupported' as any
86
- })
87
- ).rejects.toThrow("method 'unsupported' is not supported");
88
- });
89
-
90
- it('should throw error when provider is undefined', async () => {
91
- adapter.setMockProvider(undefined);
92
-
93
- await expect(
94
- adapter.writeContract({
95
- tokenAddress: '0x1234567890123456789012345678901234567890',
96
- receiverAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
97
- tokenAmount: BigInt(1000000000000000000),
98
- fromAddress: '0x1234567890123456789012345678901234567890',
99
- method: 'transfer'
100
- })
101
- ).rejects.toThrow('provider is undefined');
102
- });
103
- });
104
- });
@@ -1,32 +0,0 @@
1
- import type { AppKitNetwork } from '../utils/TypeUtil';
2
-
3
- export const bitcoin: AppKitNetwork = {
4
- id: '000000000019d6689c085ae165831e93',
5
- caipNetworkId: 'bip122:000000000019d6689c085ae165831e93',
6
- chainNamespace: 'bip122',
7
- name: 'Bitcoin',
8
- nativeCurrency: {
9
- name: 'Bitcoin',
10
- symbol: 'BTC',
11
- decimals: 8
12
- },
13
- rpcUrls: {
14
- default: { http: ['https://rpc.walletconnect.org/v1'] }
15
- }
16
- };
17
-
18
- export const bitcoinTestnet: AppKitNetwork = {
19
- id: '000000000933ea01ad0ee984209779ba',
20
- caipNetworkId: 'bip122:000000000933ea01ad0ee984209779ba',
21
- chainNamespace: 'bip122',
22
- name: 'Bitcoin Testnet',
23
- nativeCurrency: {
24
- name: 'Bitcoin',
25
- symbol: 'BTC',
26
- decimals: 8
27
- },
28
- rpcUrls: {
29
- default: { http: ['https://rpc.walletconnect.org/v1'] }
30
- },
31
- testnet: true
32
- };
@@ -1,44 +0,0 @@
1
- import type { AppKitNetwork } from '../utils/TypeUtil';
2
-
3
- export const solana: AppKitNetwork = {
4
- id: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
5
- name: 'Solana',
6
- nativeCurrency: { name: 'Solana', symbol: 'SOL', decimals: 9 },
7
- rpcUrls: {
8
- default: {
9
- http: ['https://rpc.walletconnect.org/v1']
10
- }
11
- },
12
- blockExplorers: { default: { name: 'Solscan', url: 'https://solscan.io' } },
13
- chainNamespace: 'solana',
14
- caipNetworkId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
15
- deprecatedCaipNetworkId: 'solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ',
16
- testnet: false
17
- };
18
-
19
- export const solanaDevnet: AppKitNetwork = {
20
- id: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
21
- name: 'Solana Devnet',
22
- nativeCurrency: { name: 'Solana', symbol: 'SOL', decimals: 9 },
23
- rpcUrls: {
24
- default: { http: ['https://rpc.walletconnect.org/v1'] }
25
- },
26
- blockExplorers: { default: { name: 'Solscan', url: 'https://solscan.io' } },
27
- chainNamespace: 'solana',
28
- caipNetworkId: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
29
- deprecatedCaipNetworkId: 'solana:8E9rvCKLFQia2Y35HXjjpWzj8weVo44K',
30
- testnet: true
31
- };
32
-
33
- export const solanaTestnet: AppKitNetwork = {
34
- id: '4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',
35
- name: 'Solana Testnet',
36
- nativeCurrency: { name: 'Solana', symbol: 'SOL', decimals: 9 },
37
- rpcUrls: {
38
- default: { http: ['https://rpc.walletconnect.org/v1'] }
39
- },
40
- blockExplorers: { default: { name: 'Solscan', url: 'https://solscan.io' } },
41
- chainNamespace: 'solana',
42
- caipNetworkId: 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',
43
- testnet: true
44
- };