@reown/appkit-common-react-native 2.0.0-alpha.1 → 2.0.0-alpha.2
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/lib/commonjs/adapters/BlockchainAdapter.js +3 -1
- package/lib/commonjs/adapters/BlockchainAdapter.js.map +1 -1
- package/lib/commonjs/adapters/EvmAdapter.js +137 -16
- package/lib/commonjs/adapters/EvmAdapter.js.map +1 -1
- package/lib/commonjs/adapters/SolanaBaseAdapter.js +1 -3
- package/lib/commonjs/adapters/SolanaBaseAdapter.js.map +1 -1
- package/lib/commonjs/contracts/erc20.js.map +1 -1
- package/lib/commonjs/contracts/usdt.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/networks/bitcoin.js.map +1 -1
- package/lib/commonjs/networks/solana.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ConstantsUtil.js +31 -5
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/ContractUtil.js.map +1 -1
- package/lib/commonjs/utils/DateUtil.js.map +1 -1
- package/lib/commonjs/utils/ErrorUtil.js +2 -2
- package/lib/commonjs/utils/ErrorUtil.js.map +1 -1
- package/lib/commonjs/utils/NamesUtil.js.map +1 -1
- package/lib/commonjs/utils/NetworkUtil.js.map +1 -1
- package/lib/commonjs/utils/NumberUtil.js +1 -2
- package/lib/commonjs/utils/NumberUtil.js.map +1 -1
- package/lib/commonjs/utils/PresetsUtil.js +0 -18
- package/lib/commonjs/utils/PresetsUtil.js.map +1 -1
- package/lib/commonjs/utils/StringUtil.js +7 -0
- package/lib/commonjs/utils/StringUtil.js.map +1 -1
- package/lib/commonjs/utils/TypeUtil.js +10 -2
- package/lib/commonjs/utils/TypeUtil.js.map +1 -1
- package/lib/module/adapters/BlockchainAdapter.js +5 -1
- package/lib/module/adapters/BlockchainAdapter.js.map +1 -1
- package/lib/module/adapters/EvmAdapter.js +140 -16
- package/lib/module/adapters/EvmAdapter.js.map +1 -1
- package/lib/module/adapters/SolanaBaseAdapter.js +3 -3
- package/lib/module/adapters/SolanaBaseAdapter.js.map +1 -1
- package/lib/module/contracts/erc20.js +2 -0
- package/lib/module/contracts/erc20.js.map +1 -1
- package/lib/module/contracts/usdt.js +2 -0
- package/lib/module/contracts/usdt.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/networks/bitcoin.js +2 -0
- package/lib/module/networks/bitcoin.js.map +1 -1
- package/lib/module/networks/solana.js +2 -0
- package/lib/module/networks/solana.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +33 -5
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/ContractUtil.js +2 -0
- package/lib/module/utils/ContractUtil.js.map +1 -1
- package/lib/module/utils/DateUtil.js +2 -0
- package/lib/module/utils/DateUtil.js.map +1 -1
- package/lib/module/utils/ErrorUtil.js +4 -2
- package/lib/module/utils/ErrorUtil.js.map +1 -1
- package/lib/module/utils/NamesUtil.js +2 -0
- package/lib/module/utils/NamesUtil.js.map +1 -1
- package/lib/module/utils/NetworkUtil.js +2 -0
- package/lib/module/utils/NetworkUtil.js.map +1 -1
- package/lib/module/utils/NumberUtil.js +2 -0
- package/lib/module/utils/NumberUtil.js.map +1 -1
- package/lib/module/utils/PresetsUtil.js +2 -18
- package/lib/module/utils/PresetsUtil.js.map +1 -1
- package/lib/module/utils/StringUtil.js +9 -0
- package/lib/module/utils/StringUtil.js.map +1 -1
- package/lib/module/utils/TypeUtil.js +12 -2
- package/lib/module/utils/TypeUtil.js.map +1 -1
- package/lib/typescript/adapters/BlockchainAdapter.d.ts +3 -5
- package/lib/typescript/adapters/BlockchainAdapter.d.ts.map +1 -1
- package/lib/typescript/adapters/EvmAdapter.d.ts +22 -1
- package/lib/typescript/adapters/EvmAdapter.d.ts.map +1 -1
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts +2 -0
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts.map +1 -1
- package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts +2 -0
- package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts.map +1 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts +27 -3
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/PresetsUtil.d.ts +0 -5
- package/lib/typescript/utils/PresetsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/StringUtil.d.ts +1 -0
- package/lib/typescript/utils/StringUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +145 -27
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +7 -17
- package/src/adapters/BlockchainAdapter.ts +5 -7
- package/src/adapters/EvmAdapter.ts +198 -18
- package/src/adapters/SolanaBaseAdapter.ts +2 -1
- package/src/adapters/__tests__/EvmAdapter.test.ts +126 -0
- package/src/utils/ConstantsUtil.ts +33 -6
- package/src/utils/ErrorUtil.ts +2 -2
- package/src/utils/PresetsUtil.ts +0 -25
- package/src/utils/StringUtil.ts +7 -0
- package/src/utils/TypeUtil.ts +191 -34
|
@@ -1,7 +1,105 @@
|
|
|
1
1
|
import { BlockchainAdapter } from './BlockchainAdapter';
|
|
2
2
|
import { NumberUtil } from '../utils/NumberUtil';
|
|
3
|
+
import type { AppKitNetwork } from '../utils/TypeUtil';
|
|
4
|
+
|
|
5
|
+
// Type definitions for writeContract
|
|
6
|
+
export interface WriteContractData {
|
|
7
|
+
tokenAddress: `0x${string}`;
|
|
8
|
+
receiverAddress: `0x${string}`;
|
|
9
|
+
tokenAmount: bigint;
|
|
10
|
+
fromAddress: `0x${string}`;
|
|
11
|
+
method: 'transfer' | 'transferFrom' | 'approve';
|
|
12
|
+
abi?: any; // Optional ABI for future extensibility
|
|
13
|
+
spenderAddress?: `0x${string}`; // Required for transferFrom and approve
|
|
14
|
+
network: AppKitNetwork;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface SendTransactionData {
|
|
18
|
+
address: `0x${string}`;
|
|
19
|
+
network: AppKitNetwork;
|
|
20
|
+
to: `0x${string}`;
|
|
21
|
+
value: string;
|
|
22
|
+
data: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Simple ABI encoder for ERC20 functions
|
|
26
|
+
function encodeERC20Function(method: string, params: any[]): string {
|
|
27
|
+
const functionSelectors = {
|
|
28
|
+
transfer: '0xa9059cbb', // transfer(address,uint256)
|
|
29
|
+
transferFrom: '0x23b872dd', // transferFrom(address,address,uint256)
|
|
30
|
+
approve: '0x095ea7b3' // approve(address,uint256)
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const selector = functionSelectors[method as keyof typeof functionSelectors];
|
|
34
|
+
if (!selector) {
|
|
35
|
+
throw new Error(`EVMAdapter:encodeERC20Function - unsupported method: ${method}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let encodedParams = '';
|
|
39
|
+
|
|
40
|
+
switch (method) {
|
|
41
|
+
case 'transfer':
|
|
42
|
+
if (params.length !== 2) throw new Error('transfer requires 2 parameters: to, amount');
|
|
43
|
+
const [to, amount] = params;
|
|
44
|
+
encodedParams =
|
|
45
|
+
to.toLowerCase().slice(2).padStart(64, '0') + amount.toString(16).padStart(64, '0');
|
|
46
|
+
break;
|
|
47
|
+
|
|
48
|
+
case 'transferFrom':
|
|
49
|
+
if (params.length !== 3)
|
|
50
|
+
throw new Error('transferFrom requires 3 parameters: from, to, amount');
|
|
51
|
+
const [from, toTransferFrom, amountTransferFrom] = params;
|
|
52
|
+
encodedParams =
|
|
53
|
+
from.toLowerCase().slice(2).padStart(64, '0') +
|
|
54
|
+
toTransferFrom.toLowerCase().slice(2).padStart(64, '0') +
|
|
55
|
+
amountTransferFrom.toString(16).padStart(64, '0');
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 'approve':
|
|
59
|
+
if (params.length !== 2) throw new Error('approve requires 2 parameters: spender, amount');
|
|
60
|
+
const [spender, amountApprove] = params;
|
|
61
|
+
encodedParams =
|
|
62
|
+
spender.toLowerCase().slice(2).padStart(64, '0') +
|
|
63
|
+
amountApprove.toString(16).padStart(64, '0');
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`EVMAdapter:encodeERC20Function - unsupported method: ${method}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return selector + encodedParams;
|
|
71
|
+
}
|
|
3
72
|
|
|
4
73
|
export abstract class EVMAdapter extends BlockchainAdapter {
|
|
74
|
+
override subscribeToEvents(): void {
|
|
75
|
+
super.subscribeToEvents();
|
|
76
|
+
const provider = this.getProvider();
|
|
77
|
+
if (!provider) return;
|
|
78
|
+
|
|
79
|
+
// provider.on('reown_updateEmail', (info: any) => {
|
|
80
|
+
// // this.emit('updateEmail', email);
|
|
81
|
+
// //TODO: check this
|
|
82
|
+
// // console.log('reown_updateEmail', info);
|
|
83
|
+
// });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async signMessage(address: string, message: string, chain?: string): Promise<string> {
|
|
87
|
+
const provider = this.getProvider();
|
|
88
|
+
|
|
89
|
+
if (!provider) {
|
|
90
|
+
throw new Error('EVMAdapter:signMessage - provider is undefined');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const signature = await provider.request(
|
|
94
|
+
{
|
|
95
|
+
method: 'personal_sign',
|
|
96
|
+
params: [message, address]
|
|
97
|
+
},
|
|
98
|
+
`eip155:${chain}`
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return signature as string;
|
|
102
|
+
}
|
|
5
103
|
async estimateGas({ address, to, data, chainNamespace }: any): Promise<bigint> {
|
|
6
104
|
const provider = this.getProvider();
|
|
7
105
|
|
|
@@ -36,8 +134,8 @@ export abstract class EVMAdapter extends BlockchainAdapter {
|
|
|
36
134
|
}
|
|
37
135
|
}
|
|
38
136
|
|
|
39
|
-
async sendTransaction(data:
|
|
40
|
-
const { address } = data || {};
|
|
137
|
+
async sendTransaction(data: SendTransactionData): Promise<`0x${string}` | null> {
|
|
138
|
+
const { address, network } = data || {};
|
|
41
139
|
|
|
42
140
|
if (!this.getProvider()) {
|
|
43
141
|
throw new Error('EVMAdapter:sendTransaction - provider is undefined');
|
|
@@ -47,33 +145,115 @@ export abstract class EVMAdapter extends BlockchainAdapter {
|
|
|
47
145
|
throw new Error('EVMAdapter:sendTransaction - address is undefined');
|
|
48
146
|
}
|
|
49
147
|
|
|
148
|
+
if (!network) {
|
|
149
|
+
throw new Error('EVMAdapter:sendTransaction - network is undefined');
|
|
150
|
+
}
|
|
151
|
+
|
|
50
152
|
const txParams = {
|
|
51
153
|
from: address,
|
|
52
154
|
to: data.to,
|
|
53
155
|
value: NumberUtil.convertNumericToHexString(data.value),
|
|
54
|
-
gas: NumberUtil.convertNumericToHexString(data.gas),
|
|
55
|
-
gasPrice: NumberUtil.convertNumericToHexString(data.gasPrice),
|
|
56
156
|
data: data.data, // hex-encoded bytecode
|
|
57
157
|
type: '0x0' // optional: legacy transaction type
|
|
58
158
|
};
|
|
59
159
|
|
|
60
|
-
const txHash = await this.getProvider().request(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
160
|
+
const txHash = await this.getProvider().request(
|
|
161
|
+
{
|
|
162
|
+
method: 'eth_sendTransaction',
|
|
163
|
+
params: [txParams]
|
|
164
|
+
},
|
|
165
|
+
network.caipNetworkId
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
return txHash as `0x${string}` | null;
|
|
169
|
+
}
|
|
64
170
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
171
|
+
async writeContract(data: WriteContractData): Promise<`0x${string}` | null> {
|
|
172
|
+
const {
|
|
173
|
+
tokenAddress,
|
|
174
|
+
receiverAddress,
|
|
175
|
+
tokenAmount,
|
|
176
|
+
method,
|
|
177
|
+
fromAddress,
|
|
178
|
+
spenderAddress,
|
|
179
|
+
network
|
|
180
|
+
} = data;
|
|
71
181
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
182
|
+
if (!this.getProvider()) {
|
|
183
|
+
throw new Error('EVMAdapter:writeContract - provider is undefined');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (!fromAddress) {
|
|
187
|
+
throw new Error('EVMAdapter:writeContract - fromAddress is undefined');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!tokenAddress) {
|
|
191
|
+
throw new Error('EVMAdapter:writeContract - tokenAddress is undefined');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!tokenAmount) {
|
|
195
|
+
throw new Error('EVMAdapter:writeContract - tokenAmount is undefined');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!method) {
|
|
199
|
+
throw new Error('EVMAdapter:writeContract - method is undefined');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Validate method-specific parameters
|
|
203
|
+
if (method === 'transfer' && !receiverAddress) {
|
|
204
|
+
throw new Error('EVMAdapter:writeContract - receiverAddress is required for transfer method');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if ((method === 'transferFrom' || method === 'approve') && !spenderAddress) {
|
|
208
|
+
throw new Error(`EVMAdapter:writeContract - spenderAddress is required for ${method} method`);
|
|
75
209
|
}
|
|
76
210
|
|
|
77
|
-
|
|
211
|
+
// Encode the function call data based on method
|
|
212
|
+
let encodedData: string;
|
|
213
|
+
|
|
214
|
+
switch (method) {
|
|
215
|
+
case 'transfer':
|
|
216
|
+
encodedData = encodeERC20Function('transfer', [receiverAddress, tokenAmount]);
|
|
217
|
+
break;
|
|
218
|
+
case 'transferFrom':
|
|
219
|
+
encodedData = encodeERC20Function('transferFrom', [
|
|
220
|
+
fromAddress,
|
|
221
|
+
receiverAddress,
|
|
222
|
+
tokenAmount
|
|
223
|
+
]);
|
|
224
|
+
break;
|
|
225
|
+
case 'approve':
|
|
226
|
+
encodedData = encodeERC20Function('approve', [spenderAddress, tokenAmount]);
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
throw new Error(`EVMAdapter:writeContract - method '${method}' is not supported`);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Create transaction parameters
|
|
233
|
+
const txParams = {
|
|
234
|
+
from: fromAddress,
|
|
235
|
+
to: tokenAddress,
|
|
236
|
+
data: encodedData,
|
|
237
|
+
value: '0x0', // No ETH value for token operations
|
|
238
|
+
type: '0x0' // legacy transaction type
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
// Send the transaction
|
|
243
|
+
const txHash = await this.getProvider().request(
|
|
244
|
+
{
|
|
245
|
+
method: 'eth_sendTransaction',
|
|
246
|
+
params: [txParams]
|
|
247
|
+
},
|
|
248
|
+
network.caipNetworkId
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return txHash as `0x${string}` | null;
|
|
252
|
+
} catch (error) {
|
|
253
|
+
if (error instanceof Error) {
|
|
254
|
+
throw new Error(`EVMAdapter:writeContract - ${error.message}`);
|
|
255
|
+
}
|
|
256
|
+
throw new Error('EVMAdapter:writeContract - unknown error occurred');
|
|
257
|
+
}
|
|
78
258
|
}
|
|
79
259
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BlockchainAdapter } from './BlockchainAdapter';
|
|
2
2
|
|
|
3
3
|
export abstract class SolanaBaseAdapter extends BlockchainAdapter {
|
|
4
|
-
|
|
4
|
+
abstract signTransaction(data: any): Promise<string | null>;
|
|
5
|
+
abstract sendTransaction(data: any): Promise<string | null>;
|
|
5
6
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { EVMAdapter } from '../EvmAdapter';
|
|
2
|
+
import type { AppKitNetwork, CaipAddress } from '../../utils/TypeUtil';
|
|
3
|
+
|
|
4
|
+
const network: AppKitNetwork = {
|
|
5
|
+
id: 1,
|
|
6
|
+
name: 'Ethereum',
|
|
7
|
+
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
8
|
+
rpcUrls: {
|
|
9
|
+
default: {
|
|
10
|
+
http: ['https://eth.merkle.io']
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
blockExplorers: {
|
|
14
|
+
default: {
|
|
15
|
+
name: 'Etherscan',
|
|
16
|
+
url: 'https://etherscan.io'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
chainNamespace: 'eip155',
|
|
20
|
+
caipNetworkId: 'eip155:1'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Mock implementation for testing
|
|
24
|
+
class MockEVMAdapter extends EVMAdapter {
|
|
25
|
+
private mockProvider: any;
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
super({ projectId: 'test', supportedNamespace: 'eip155', adapterType: 'ethers' });
|
|
29
|
+
this.mockProvider = {
|
|
30
|
+
request: jest.fn(),
|
|
31
|
+
on: jest.fn(),
|
|
32
|
+
off: jest.fn()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setMockProvider(provider: any) {
|
|
37
|
+
this.mockProvider = provider;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override getProvider() {
|
|
41
|
+
return this.mockProvider;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async disconnect(): Promise<void> {}
|
|
45
|
+
getSupportedNamespace() {
|
|
46
|
+
return 'eip155' as const;
|
|
47
|
+
}
|
|
48
|
+
async getBalance() {
|
|
49
|
+
return { amount: '0', symbol: 'ETH' };
|
|
50
|
+
}
|
|
51
|
+
getAccounts(): CaipAddress[] | undefined {
|
|
52
|
+
return ['eip155:1:0x1234567890123456789012345678901234567890'];
|
|
53
|
+
}
|
|
54
|
+
async switchNetwork() {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe('EVMAdapter', () => {
|
|
58
|
+
let adapter: MockEVMAdapter;
|
|
59
|
+
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
adapter = new MockEVMAdapter();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('writeContract', () => {
|
|
65
|
+
it('should encode transfer function correctly', async () => {
|
|
66
|
+
const mockProvider = {
|
|
67
|
+
request: jest.fn().mockResolvedValueOnce('0x1234567890abcdef') // eth_sendTransaction
|
|
68
|
+
};
|
|
69
|
+
adapter.setMockProvider(mockProvider);
|
|
70
|
+
|
|
71
|
+
const result = await adapter.writeContract({
|
|
72
|
+
tokenAddress: '0x1234567890123456789012345678901234567890',
|
|
73
|
+
receiverAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
|
74
|
+
tokenAmount: BigInt(1000000000000000000), // 1 token with 18 decimals
|
|
75
|
+
fromAddress: '0x1234567890123456789012345678901234567890',
|
|
76
|
+
method: 'transfer',
|
|
77
|
+
network
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(result).toBe('0x1234567890abcdef');
|
|
81
|
+
expect(mockProvider.request).toHaveBeenCalledWith(
|
|
82
|
+
{
|
|
83
|
+
method: 'eth_sendTransaction',
|
|
84
|
+
params: [
|
|
85
|
+
{
|
|
86
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
87
|
+
to: '0x1234567890123456789012345678901234567890',
|
|
88
|
+
data: '0xa9059cbb000000000000000000000000abcdefabcdefabcdefabcdefabcdefabcdefabcd0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
|
89
|
+
value: '0x0',
|
|
90
|
+
type: '0x0'
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
'eip155:1'
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should throw error for unsupported method', async () => {
|
|
99
|
+
await expect(
|
|
100
|
+
adapter.writeContract({
|
|
101
|
+
tokenAddress: '0x1234567890123456789012345678901234567890',
|
|
102
|
+
receiverAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
|
103
|
+
tokenAmount: BigInt(1000000000000000000),
|
|
104
|
+
fromAddress: '0x1234567890123456789012345678901234567890',
|
|
105
|
+
method: 'unsupported' as any,
|
|
106
|
+
network
|
|
107
|
+
})
|
|
108
|
+
).rejects.toThrow("method 'unsupported' is not supported");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should throw error when provider is undefined', async () => {
|
|
112
|
+
adapter.setMockProvider(undefined);
|
|
113
|
+
|
|
114
|
+
await expect(
|
|
115
|
+
adapter.writeContract({
|
|
116
|
+
tokenAddress: '0x1234567890123456789012345678901234567890',
|
|
117
|
+
receiverAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
|
118
|
+
tokenAmount: BigInt(1000000000000000000),
|
|
119
|
+
fromAddress: '0x1234567890123456789012345678901234567890',
|
|
120
|
+
method: 'transfer',
|
|
121
|
+
network
|
|
122
|
+
})
|
|
123
|
+
).rejects.toThrow('provider is undefined');
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const ConstantsUtil = {
|
|
2
|
-
VERSION: '2.0.0-alpha.
|
|
2
|
+
VERSION: '2.0.0-alpha.2',
|
|
3
3
|
|
|
4
4
|
EIP155: 'eip155',
|
|
5
5
|
ADD_CHAIN_METHOD: 'wallet_addEthereumChain',
|
|
@@ -11,12 +11,14 @@ export const ConstantsUtil = {
|
|
|
11
11
|
BLOCKCHAIN_API_RPC_URL_STAGING: 'https://staging.rpc.walletconnect.org',
|
|
12
12
|
PULSE_API_URL: 'https://pulse.walletconnect.org',
|
|
13
13
|
API_URL: 'https://api.web3modal.org',
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
AUTH_CONNECTOR_ID: 'appKitAuth',
|
|
14
|
+
WEB_WALLET_URL: 'https://web-wallet.walletconnect.org',
|
|
15
|
+
SECURE_SITE_DASHBOARD: `https://secure.reown.com/dashboard`,
|
|
16
|
+
SECURE_SITE_ICON: `https://secure.reown.com/images/favicon.png`,
|
|
18
17
|
|
|
19
18
|
COINBASE_EXPLORER_ID: 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa',
|
|
19
|
+
PHANTOM_EXPLORER_ID: 'a797aa35c0fadbfc1a53e7f675162ed5226968b44a19ee3d24385c64d1d3c393',
|
|
20
|
+
|
|
21
|
+
WALLET_CONNECT_IMAGE_ID: 'ef1a1fcf-7fe8-4d69-bd6d-fda1345b4400',
|
|
20
22
|
|
|
21
23
|
USDT_CONTRACT_ADDRESSES: [
|
|
22
24
|
// Mainnet
|
|
@@ -33,5 +35,30 @@ export const ConstantsUtil = {
|
|
|
33
35
|
'0x55d398326f99059fF775485246999027B3197955',
|
|
34
36
|
// Arbitrum
|
|
35
37
|
'0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9'
|
|
36
|
-
]
|
|
38
|
+
],
|
|
39
|
+
|
|
40
|
+
PHANTOM_CUSTOM_WALLET: {
|
|
41
|
+
id: 'a797aa35c0fadbfc1a53e7f675162ed5226968b44a19ee3d24385c64d1d3c393',
|
|
42
|
+
name: 'Phantom Wallet',
|
|
43
|
+
image_id: 'b6ec7b81-bb4f-427d-e290-7631e6e50d00',
|
|
44
|
+
mobile_link: 'phantom://'
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// Storage Keys
|
|
48
|
+
STORAGE_KEYS: {
|
|
49
|
+
WC_DEEPLINK: 'WALLETCONNECT_DEEPLINK_CHOICE', //dont change this one
|
|
50
|
+
RECENT_WALLET: '@appkit/recent_wallet',
|
|
51
|
+
CONNECTED_WALLET_IMAGE_URL: '@appkit/connected_wallet_image_url',
|
|
52
|
+
CONNECTED_CONNECTORS: '@appkit/connected_connectors',
|
|
53
|
+
CONNECTED_SOCIAL: '@appkit/connected_social',
|
|
54
|
+
ONRAMP_PREFERRED_COUNTRY: '@appkit/onramp_preferred_country',
|
|
55
|
+
ONRAMP_COUNTRIES: '@appkit/onramp_countries',
|
|
56
|
+
ONRAMP_SERVICE_PROVIDERS: '@appkit/onramp_service_providers',
|
|
57
|
+
ONRAMP_FIAT_LIMITS: '@appkit/onramp_fiat_limits',
|
|
58
|
+
ONRAMP_FIAT_CURRENCIES: '@appkit/onramp_fiat_currencies',
|
|
59
|
+
ONRAMP_PREFERRED_FIAT_CURRENCY: '@appkit/onramp_preferred_fiat_currency',
|
|
60
|
+
ONRAMP_COUNTRIES_DEFAULTS: '@appkit/onramp_countries_defaults',
|
|
61
|
+
ACTIVE_NAMESPACE: '@appkit/active_namespace',
|
|
62
|
+
COINBASE_CONNECTOR_SESSION: '@appkit/coinbase_connector/session'
|
|
63
|
+
}
|
|
37
64
|
};
|
package/src/utils/ErrorUtil.ts
CHANGED
|
@@ -16,12 +16,12 @@ export const ErrorUtil = {
|
|
|
16
16
|
ALERT_ERRORS: {
|
|
17
17
|
INVALID_APP_CONFIGURATION: {
|
|
18
18
|
shortMessage: 'Invalid App Configuration',
|
|
19
|
-
longMessage: `Bundle ID not found on Allowlist - Please verify that your bundle ID is allowed at https://
|
|
19
|
+
longMessage: `Bundle ID not found on Allowlist - Please verify that your bundle ID is allowed at https://dashboard.reown.com`
|
|
20
20
|
},
|
|
21
21
|
SOCIALS_TIMEOUT: {
|
|
22
22
|
shortMessage: 'Invalid App Configuration',
|
|
23
23
|
longMessage:
|
|
24
|
-
'There was an issue loading the embedded wallet. Please verify that your bundle ID is allowed at https://
|
|
24
|
+
'There was an issue loading the embedded wallet. Please verify that your bundle ID is allowed at https://dashboard.reown.com'
|
|
25
25
|
},
|
|
26
26
|
JWT_TOKEN_NOT_VALID: {
|
|
27
27
|
shortMessage: 'Session Expired',
|
package/src/utils/PresetsUtil.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type { ConnectorType } from './TypeUtil';
|
|
2
|
-
import { ConstantsUtil } from './ConstantsUtil';
|
|
3
|
-
|
|
4
1
|
export const PresetsUtil = {
|
|
5
|
-
ConnectorExplorerIds: {
|
|
6
|
-
[ConstantsUtil.COINBASE_CONNECTOR_ID]:
|
|
7
|
-
'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa'
|
|
8
|
-
} as Record<string, string>,
|
|
9
|
-
|
|
10
2
|
NetworkImageIds: {
|
|
11
3
|
// Ethereum
|
|
12
4
|
1: 'ba0ba0cd-17c6-4806-ad93-f9d174f17900',
|
|
@@ -81,23 +73,6 @@ export const PresetsUtil = {
|
|
|
81
73
|
'000000000933ea01ad0ee984209779ba': '39354064-d79b-420b-065d-f980c4b78200'
|
|
82
74
|
} as Record<string, string>,
|
|
83
75
|
|
|
84
|
-
ConnectorNamesMap: {
|
|
85
|
-
[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'WalletConnect',
|
|
86
|
-
[ConstantsUtil.COINBASE_CONNECTOR_ID]: 'Coinbase Wallet',
|
|
87
|
-
[ConstantsUtil.AUTH_CONNECTOR_ID]: 'AppKit Universal Wallet'
|
|
88
|
-
} as Record<string, string>,
|
|
89
|
-
|
|
90
|
-
ConnectorImageIds: {
|
|
91
|
-
[ConstantsUtil.COINBASE_CONNECTOR_ID]: '0c2840c3-5b04-4c44-9661-fbd4b49e1800',
|
|
92
|
-
[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'ef1a1fcf-7fe8-4d69-bd6d-fda1345b4400'
|
|
93
|
-
} as Record<string, string>,
|
|
94
|
-
|
|
95
|
-
ConnectorTypesMap: {
|
|
96
|
-
[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'WALLET_CONNECT',
|
|
97
|
-
[ConstantsUtil.COINBASE_CONNECTOR_ID]: 'COINBASE',
|
|
98
|
-
[ConstantsUtil.AUTH_CONNECTOR_ID]: 'AUTH'
|
|
99
|
-
} as Record<string, ConnectorType>,
|
|
100
|
-
|
|
101
76
|
RpcChainIds: [
|
|
102
77
|
// Ethereum
|
|
103
78
|
1,
|
package/src/utils/StringUtil.ts
CHANGED
|
@@ -5,5 +5,12 @@ export const StringUtil = {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
|
|
8
|
+
},
|
|
9
|
+
hexToString(hexValue: string) {
|
|
10
|
+
// Remove 0x prefix if present
|
|
11
|
+
const cleanHex = hexValue.startsWith('0x') ? hexValue.slice(2) : hexValue;
|
|
12
|
+
// Convert hex to decimal number, then to string
|
|
13
|
+
|
|
14
|
+
return parseInt(cleanHex, 16).toString();
|
|
8
15
|
}
|
|
9
16
|
};
|