@reown/appkit-common-react-native 0.0.0-feat-onramp-20250602154313 → 0.0.0-feat-multichain-phantom-20250606183519
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 +79 -0
- package/lib/commonjs/adapters/BlockchainAdapter.js.map +1 -0
- package/lib/commonjs/adapters/EvmAdapter.js +83 -0
- package/lib/commonjs/adapters/EvmAdapter.js.map +1 -0
- package/lib/commonjs/adapters/SolanaBaseAdapter.js +12 -0
- package/lib/commonjs/adapters/SolanaBaseAdapter.js.map +1 -0
- package/lib/commonjs/index.js +62 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/networks/bitcoin.js +40 -0
- package/lib/commonjs/networks/bitcoin.js.map +1 -0
- package/lib/commonjs/networks/solana.js +78 -0
- package/lib/commonjs/networks/solana.js.map +1 -0
- package/lib/commonjs/utils/ConstantsUtil.js +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/NumberUtil.js +52 -11
- package/lib/commonjs/utils/NumberUtil.js.map +1 -1
- package/lib/commonjs/utils/PresetsUtil.js +34 -3
- package/lib/commonjs/utils/PresetsUtil.js.map +1 -1
- package/lib/commonjs/utils/TypeUtil.js +34 -0
- package/lib/commonjs/utils/TypeUtil.js.map +1 -1
- package/lib/module/adapters/BlockchainAdapter.js +72 -0
- package/lib/module/adapters/BlockchainAdapter.js.map +1 -0
- package/lib/module/adapters/EvmAdapter.js +76 -0
- package/lib/module/adapters/EvmAdapter.js.map +1 -0
- package/lib/module/adapters/SolanaBaseAdapter.js +5 -0
- package/lib/module/adapters/SolanaBaseAdapter.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/networks/bitcoin.js +34 -0
- package/lib/module/networks/bitcoin.js.map +1 -0
- package/lib/module/networks/solana.js +72 -0
- package/lib/module/networks/solana.js.map +1 -0
- package/lib/module/utils/ConstantsUtil.js +1 -1
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/NumberUtil.js +52 -11
- package/lib/module/utils/NumberUtil.js.map +1 -1
- package/lib/module/utils/PresetsUtil.js +34 -3
- package/lib/module/utils/PresetsUtil.js.map +1 -1
- package/lib/module/utils/TypeUtil.js +28 -0
- package/lib/module/utils/TypeUtil.js.map +1 -1
- package/lib/typescript/adapters/BlockchainAdapter.d.ts +27 -0
- package/lib/typescript/adapters/BlockchainAdapter.d.ts.map +1 -0
- package/lib/typescript/adapters/EvmAdapter.d.ts +6 -0
- package/lib/typescript/adapters/EvmAdapter.d.ts.map +1 -0
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts +4 -0
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/networks/bitcoin.d.ts +4 -0
- package/lib/typescript/networks/bitcoin.d.ts.map +1 -0
- package/lib/typescript/networks/solana.d.ts +5 -0
- package/lib/typescript/networks/solana.d.ts.map +1 -0
- package/lib/typescript/utils/NumberUtil.d.ts +39 -11
- package/lib/typescript/utils/NumberUtil.d.ts.map +1 -1
- package/lib/typescript/utils/PresetsUtil.d.ts +1 -1
- package/lib/typescript/utils/PresetsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +193 -1
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/BlockchainAdapter.ts +109 -0
- package/src/adapters/EvmAdapter.ts +79 -0
- package/src/adapters/SolanaBaseAdapter.ts +5 -0
- package/src/index.ts +5 -0
- package/src/networks/bitcoin.ts +32 -0
- package/src/networks/solana.ts +44 -0
- package/src/utils/ConstantsUtil.ts +1 -1
- package/src/utils/NumberUtil.ts +54 -11
- package/src/utils/PresetsUtil.ts +36 -3
- package/src/utils/TypeUtil.ts +240 -1
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
};
|
package/src/utils/NumberUtil.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import * as BigNumber from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
export const NumberUtil = {
|
|
4
|
+
/**
|
|
5
|
+
* Creates a BigNumber instance from a given value.
|
|
6
|
+
* If the value is a string, commas are removed before conversion.
|
|
7
|
+
* @param value - The input value (string, number, or BigNumber) to convert to a BigNumber.
|
|
8
|
+
* @returns A BigNumber instance.
|
|
9
|
+
*/
|
|
4
10
|
bigNumber(value: BigNumber.BigNumber.Value) {
|
|
5
11
|
if (typeof value === 'string') {
|
|
6
12
|
return new BigNumber.BigNumber(value.replace(/,/g, ''));
|
|
@@ -10,10 +16,11 @@ export const NumberUtil = {
|
|
|
10
16
|
},
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @param
|
|
16
|
-
* @
|
|
19
|
+
* Multiplies two numbers using BigNumber for precision, especially with decimals.
|
|
20
|
+
* Handles undefined inputs by returning BigNumber(0).
|
|
21
|
+
* @param a - The first multiplicand (string, number, or BigNumber). Commas are removed if it's a string.
|
|
22
|
+
* @param b - The second multiplicand (string, number, or BigNumber). Commas are removed if it's a string.
|
|
23
|
+
* @returns The product as a BigNumber instance, or BigNumber(0) if either input is undefined.
|
|
17
24
|
*/
|
|
18
25
|
multiply(a: BigNumber.BigNumber.Value | undefined, b: BigNumber.BigNumber.Value | undefined) {
|
|
19
26
|
if (a === undefined || b === undefined) {
|
|
@@ -26,6 +33,13 @@ export const NumberUtil = {
|
|
|
26
33
|
return aBigNumber.multipliedBy(bBigNumber);
|
|
27
34
|
},
|
|
28
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Rounds a number to a specified number of decimal places if its string representation meets a certain length threshold.
|
|
38
|
+
* @param number - The number to potentially round.
|
|
39
|
+
* @param threshold - The minimum string length of the number to trigger rounding.
|
|
40
|
+
* @param fixed - The number of decimal places to round to.
|
|
41
|
+
* @returns The rounded number (as a string if rounded, otherwise the original number) or the original number.
|
|
42
|
+
*/
|
|
29
43
|
roundNumber(number: number, threshold: number, fixed: number) {
|
|
30
44
|
const roundedNumber =
|
|
31
45
|
number.toString().length >= threshold ? Number(number).toFixed(fixed) : number;
|
|
@@ -33,6 +47,12 @@ export const NumberUtil = {
|
|
|
33
47
|
return roundedNumber;
|
|
34
48
|
},
|
|
35
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Calculates the next multiple of ten greater than or equal to the given amount.
|
|
52
|
+
* Defaults to 10 if no amount is provided or if the calculated multiple is less than 10.
|
|
53
|
+
* @param amount - The number for which to find the next multiple of ten. Optional.
|
|
54
|
+
* @returns The next multiple of ten, at least 10.
|
|
55
|
+
*/
|
|
36
56
|
nextMultipleOfTen(amount?: number) {
|
|
37
57
|
if (!amount) return 10;
|
|
38
58
|
|
|
@@ -40,10 +60,10 @@ export const NumberUtil = {
|
|
|
40
60
|
},
|
|
41
61
|
|
|
42
62
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param value - The value to format
|
|
45
|
-
* @param decimals - number of
|
|
46
|
-
* @returns
|
|
63
|
+
* Formats a number or string to a human-readable string with a specified number of decimal places, using US locale formatting.
|
|
64
|
+
* @param value - The value to format (string, number, or undefined). If undefined, returns '0.00'.
|
|
65
|
+
* @param decimals - The number of decimal places to display. Defaults to 2.
|
|
66
|
+
* @returns A locale-formatted string representation of the number.
|
|
47
67
|
*/
|
|
48
68
|
formatNumberToLocalString(value: string | number | undefined, decimals = 2) {
|
|
49
69
|
if (value === undefined) {
|
|
@@ -62,10 +82,11 @@ export const NumberUtil = {
|
|
|
62
82
|
minimumFractionDigits: decimals
|
|
63
83
|
});
|
|
64
84
|
},
|
|
85
|
+
|
|
65
86
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param value - The formatted string to parse
|
|
68
|
-
* @returns
|
|
87
|
+
* Parses a locale-formatted numeric string (e.g., with commas) back into a number.
|
|
88
|
+
* @param value - The formatted string to parse. If undefined, returns 0.
|
|
89
|
+
* @returns The parsed number, or 0 if the input is undefined.
|
|
69
90
|
*/
|
|
70
91
|
parseLocalStringToNumber(value: string | undefined) {
|
|
71
92
|
if (value === undefined) {
|
|
@@ -74,5 +95,27 @@ export const NumberUtil = {
|
|
|
74
95
|
|
|
75
96
|
// Remove any commas used as thousand separators and parse the float
|
|
76
97
|
return parseFloat(value.replace(/,/gu, ''));
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Converts a numeric value (BigInt, number, or string representation of a number) to a 0x-prefixed hexadecimal string.
|
|
102
|
+
* This is often required for Ethereum RPC parameters like value, gas, gasPrice.
|
|
103
|
+
* @param value - The value to convert. Can be BigInt, number, or a string (decimal or hex).
|
|
104
|
+
* @returns A 0x-prefixed hexadecimal string, or undefined if the input is undefined or null.
|
|
105
|
+
* @throws Error if the value cannot be converted to BigInt.
|
|
106
|
+
*/
|
|
107
|
+
convertNumericToHexString: (value: any): string | undefined => {
|
|
108
|
+
if (value === undefined || value === null) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
// This handles BigInt, number, or string representation of a number (decimal or hex)
|
|
113
|
+
const bigIntValue = BigInt(value);
|
|
114
|
+
// Ethereum RPC spec requires "0x0" for zero, and other values to be 0x-prefixed hex.
|
|
115
|
+
|
|
116
|
+
return '0x' + bigIntValue.toString(16);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new Error(`NumberUtil: Invalid parameter, cannot convert to hex: ${value}`);
|
|
119
|
+
}
|
|
77
120
|
}
|
|
78
121
|
};
|
package/src/utils/PresetsUtil.ts
CHANGED
|
@@ -7,11 +7,11 @@ export const PresetsUtil = {
|
|
|
7
7
|
'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa'
|
|
8
8
|
} as Record<string, string>,
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
NetworkImageIds: {
|
|
11
11
|
// Ethereum
|
|
12
12
|
1: 'ba0ba0cd-17c6-4806-ad93-f9d174f17900',
|
|
13
13
|
// Arbitrum
|
|
14
|
-
42161: '
|
|
14
|
+
42161: '3bff954d-5cb0-47a0-9a23-d20192e74600',
|
|
15
15
|
// Avalanche
|
|
16
16
|
43114: '30c46e53-e989-45fb-4549-be3bd4eb3b00',
|
|
17
17
|
// Binance Smart Chain
|
|
@@ -22,6 +22,20 @@ export const PresetsUtil = {
|
|
|
22
22
|
10: 'ab9c186a-c52f-464b-2906-ca59d760a400',
|
|
23
23
|
// Polygon
|
|
24
24
|
137: '41d04d42-da3b-4453-8506-668cc0727900',
|
|
25
|
+
// Mantle
|
|
26
|
+
5000: 'e86fae9b-b770-4eea-e520-150e12c81100',
|
|
27
|
+
// Hedera Mainnet
|
|
28
|
+
295: '6a97d510-cac8-4e58-c7ce-e8681b044c00',
|
|
29
|
+
// Sepolia
|
|
30
|
+
11_155_111: 'e909ea0a-f92a-4512-c8fc-748044ea6800',
|
|
31
|
+
// Base Sepolia
|
|
32
|
+
84532: 'a18a7ecd-e307-4360-4746-283182228e00',
|
|
33
|
+
// Unichain Sepolia
|
|
34
|
+
1301: '4eeea7ef-0014-4649-5d1d-07271a80f600',
|
|
35
|
+
// Unichain Mainnet
|
|
36
|
+
130: '2257980a-3463-48c6-cbac-a42d2a956e00',
|
|
37
|
+
// Monad Testnet
|
|
38
|
+
10_143: '0a728e83-bacb-46db-7844-948f05434900',
|
|
25
39
|
// Gnosis
|
|
26
40
|
100: '02b53f6a-e3d4-479e-1cb4-21178987d100',
|
|
27
41
|
// EVMos
|
|
@@ -45,7 +59,26 @@ export const PresetsUtil = {
|
|
|
45
59
|
// Base
|
|
46
60
|
8453: '7289c336-3981-4081-c5f4-efc26ac64a00',
|
|
47
61
|
// Aurora
|
|
48
|
-
1313161554: '3ff73439-a619-4894-9262-4470c773a100'
|
|
62
|
+
1313161554: '3ff73439-a619-4894-9262-4470c773a100',
|
|
63
|
+
// Ronin Mainnet
|
|
64
|
+
2020: 'b8101fc0-9c19-4b6f-ec65-f6dfff106e00',
|
|
65
|
+
// Saigon Testnet (a.k.a. Ronin)
|
|
66
|
+
2021: 'b8101fc0-9c19-4b6f-ec65-f6dfff106e00',
|
|
67
|
+
// Berachain Mainnet
|
|
68
|
+
80094: 'e329c2c9-59b0-4a02-83e4-212ff3779900',
|
|
69
|
+
// Abstract Mainnet
|
|
70
|
+
2741: 'fc2427d1-5af9-4a9c-8da5-6f94627cd900',
|
|
71
|
+
|
|
72
|
+
// Solana networks
|
|
73
|
+
/// Mainnet
|
|
74
|
+
'5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'a1b58899-f671-4276-6a5e-56ca5bd59700',
|
|
75
|
+
/// Testnet
|
|
76
|
+
'4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z': 'a1b58899-f671-4276-6a5e-56ca5bd59700',
|
|
77
|
+
|
|
78
|
+
// Bitcoin
|
|
79
|
+
'000000000019d6689c085ae165831e93': '0b4838db-0161-4ffe-022d-532bf03dba00',
|
|
80
|
+
// Bitcoin Testnet
|
|
81
|
+
'000000000933ea01ad0ee984209779ba': '39354064-d79b-420b-065d-f980c4b78200'
|
|
49
82
|
} as Record<string, string>,
|
|
50
83
|
|
|
51
84
|
ConnectorNamesMap: {
|
package/src/utils/TypeUtil.ts
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
export type CaipAddress = `${string}:${string}:${string}`;
|
|
4
|
+
|
|
5
|
+
export type CaipNetworkId = `${string}:${string}`;
|
|
6
|
+
|
|
7
|
+
export type ChainNamespace = 'eip155' | 'solana' | 'polkadot' | 'bip122';
|
|
8
|
+
|
|
9
|
+
export type Network = {
|
|
10
|
+
// Core viem/chain properties
|
|
11
|
+
id: number | string;
|
|
12
|
+
name: string;
|
|
13
|
+
nativeCurrency: { name: string; symbol: string; decimals: number };
|
|
14
|
+
rpcUrls: {
|
|
15
|
+
default: { http: readonly string[] };
|
|
16
|
+
[key: string]: { http: readonly string[] } | undefined;
|
|
17
|
+
};
|
|
18
|
+
blockExplorers?: {
|
|
19
|
+
default: { name: string; url: string };
|
|
20
|
+
[key: string]: { name: string; url: string } | undefined;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// AppKit specific / CAIP properties (Optional in type, but needed in practice)
|
|
24
|
+
chainNamespace?: ChainNamespace; // e.g., 'eip155'
|
|
25
|
+
caipNetworkId?: CaipNetworkId; // e.g., 'eip155:1'
|
|
26
|
+
testnet?: boolean;
|
|
27
|
+
deprecatedCaipNetworkId?: CaipNetworkId; // for Solana deprecated id
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type AppKitNetwork = Network & {
|
|
31
|
+
chainNamespace: ChainNamespace; // e.g., 'eip155'
|
|
32
|
+
caipNetworkId: CaipNetworkId; // e.g., 'eip155:1'
|
|
33
|
+
testnet?: boolean;
|
|
34
|
+
deprecatedCaipNetworkId?: CaipNetworkId; // for Solana deprecated id
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export interface CaipNetwork {
|
|
38
|
+
id: CaipNetworkId;
|
|
39
|
+
name?: string;
|
|
40
|
+
imageId?: string;
|
|
41
|
+
imageUrl?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
1
44
|
export interface Balance {
|
|
2
45
|
name: string;
|
|
3
46
|
symbol: string;
|
|
4
47
|
chainId: string;
|
|
5
|
-
address?:
|
|
48
|
+
address?: CaipAddress;
|
|
6
49
|
value?: number;
|
|
7
50
|
price: number;
|
|
8
51
|
quantity: BalanceQuantity;
|
|
@@ -94,4 +137,200 @@ export interface ThemeVariables {
|
|
|
94
137
|
accent?: string;
|
|
95
138
|
}
|
|
96
139
|
|
|
140
|
+
export interface Token {
|
|
141
|
+
address: string;
|
|
142
|
+
image?: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type Tokens = Record<CaipNetworkId, Token>;
|
|
146
|
+
|
|
97
147
|
export type ConnectorType = 'WALLET_CONNECT' | 'COINBASE' | 'AUTH' | 'EXTERNAL';
|
|
148
|
+
|
|
149
|
+
export type Metadata = {
|
|
150
|
+
name: string;
|
|
151
|
+
description: string;
|
|
152
|
+
url: string;
|
|
153
|
+
icons: string[];
|
|
154
|
+
redirect?: {
|
|
155
|
+
native?: string;
|
|
156
|
+
universal?: string;
|
|
157
|
+
linkMode?: boolean;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//********** Adapter Event Payloads **********//
|
|
162
|
+
export type AccountsChangedEvent = {
|
|
163
|
+
accounts: string[];
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export type ChainChangedEvent = {
|
|
167
|
+
chainId: string;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export type DisconnectEvent = {};
|
|
171
|
+
|
|
172
|
+
export type BalanceChangedEvent = {
|
|
173
|
+
address: CaipAddress;
|
|
174
|
+
balance: {
|
|
175
|
+
amount: string;
|
|
176
|
+
symbol: string;
|
|
177
|
+
contractAddress?: ContractAddress;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
//********** Adapter Event Map **********//
|
|
182
|
+
export interface AdapterEvents {
|
|
183
|
+
accountsChanged: (event: AccountsChangedEvent) => void;
|
|
184
|
+
chainChanged: (event: ChainChangedEvent) => void;
|
|
185
|
+
disconnect: (event: DisconnectEvent) => void;
|
|
186
|
+
balanceChanged: (event: BalanceChangedEvent) => void;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface GetBalanceParams {
|
|
190
|
+
address?: CaipAddress;
|
|
191
|
+
network?: AppKitNetwork;
|
|
192
|
+
tokens?: Tokens;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
type ContractAddress = CaipAddress;
|
|
196
|
+
|
|
197
|
+
export interface GetBalanceResponse {
|
|
198
|
+
amount: string;
|
|
199
|
+
symbol: string;
|
|
200
|
+
contractAddress?: ContractAddress;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//********** Connector Types **********//
|
|
204
|
+
interface BaseNamespace {
|
|
205
|
+
chains?: CaipNetworkId[];
|
|
206
|
+
accounts: CaipAddress[];
|
|
207
|
+
methods: string[];
|
|
208
|
+
events: string[];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type Namespace = BaseNamespace;
|
|
212
|
+
|
|
213
|
+
export type Namespaces = Record<string, Namespace>;
|
|
214
|
+
|
|
215
|
+
export type ProposalNamespaces = Record<
|
|
216
|
+
string,
|
|
217
|
+
Omit<Namespace, 'accounts'> &
|
|
218
|
+
Required<Pick<Namespace, 'chains'>> & { rpcMap: Record<string, string> }
|
|
219
|
+
>;
|
|
220
|
+
|
|
221
|
+
export type ConnectOptions = {
|
|
222
|
+
namespaces?: ProposalNamespaces;
|
|
223
|
+
defaultChain?: CaipNetworkId;
|
|
224
|
+
universalLink?: string;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export type ConnectorInitOptions = {
|
|
228
|
+
storage: Storage;
|
|
229
|
+
metadata: Metadata;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
export abstract class WalletConnector extends EventEmitter {
|
|
233
|
+
public type: New_ConnectorType;
|
|
234
|
+
protected provider?: Provider;
|
|
235
|
+
protected namespaces?: Namespaces;
|
|
236
|
+
protected wallet?: WalletInfo;
|
|
237
|
+
protected storage?: Storage;
|
|
238
|
+
protected metadata?: Metadata;
|
|
239
|
+
|
|
240
|
+
constructor({ type }: { type: New_ConnectorType }) {
|
|
241
|
+
super();
|
|
242
|
+
this.type = type;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public async init(ops: ConnectorInitOptions) {
|
|
246
|
+
this.storage = ops.storage;
|
|
247
|
+
this.metadata = ops.metadata;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public setProvider(provider: Provider) {
|
|
251
|
+
this.provider = provider;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
abstract connect(opts: ConnectOptions): Promise<Namespaces | undefined>;
|
|
255
|
+
abstract disconnect(): Promise<void>;
|
|
256
|
+
abstract getProvider(): Provider;
|
|
257
|
+
abstract getNamespaces(): Namespaces;
|
|
258
|
+
abstract getChainId(namespace: ChainNamespace): CaipNetworkId | undefined;
|
|
259
|
+
abstract getWalletInfo(): WalletInfo | undefined;
|
|
260
|
+
abstract switchNetwork(network: AppKitNetwork): Promise<void>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
//********** Provider Types **********//
|
|
264
|
+
|
|
265
|
+
export interface Provider {
|
|
266
|
+
connect<T>(params?: any): Promise<T>;
|
|
267
|
+
disconnect(): Promise<void>;
|
|
268
|
+
request<T = unknown>(
|
|
269
|
+
args: RequestArguments,
|
|
270
|
+
chain?: string | undefined,
|
|
271
|
+
expiry?: number | undefined
|
|
272
|
+
): Promise<T>;
|
|
273
|
+
on(event: string, listener: (args?: any) => void): any;
|
|
274
|
+
off(event: string, listener: (args?: any) => void): any;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface RequestArguments {
|
|
278
|
+
method: string;
|
|
279
|
+
params?: unknown[] | Record<string, unknown> | object | undefined;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
//TODO: rename this and remove the old one ConnectorType
|
|
283
|
+
export type New_ConnectorType = 'walletconnect' | 'coinbase' | 'auth' | 'phantom';
|
|
284
|
+
|
|
285
|
+
//********** Others **********//
|
|
286
|
+
|
|
287
|
+
export interface ConnectionResponse {
|
|
288
|
+
accounts: string[];
|
|
289
|
+
chainId: string;
|
|
290
|
+
[key: string]: any;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface WalletInfo {
|
|
294
|
+
name?: string;
|
|
295
|
+
icon?: string;
|
|
296
|
+
description?: string;
|
|
297
|
+
url?: string;
|
|
298
|
+
icons?: string[];
|
|
299
|
+
redirect?: {
|
|
300
|
+
native?: string;
|
|
301
|
+
universal?: string;
|
|
302
|
+
linkMode?: boolean;
|
|
303
|
+
};
|
|
304
|
+
[key: string]: unknown;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface Storage {
|
|
308
|
+
/**
|
|
309
|
+
* Returns all keys in storage.
|
|
310
|
+
*/
|
|
311
|
+
getKeys(): Promise<string[]>;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Returns all key-value entries in storage.
|
|
315
|
+
*/
|
|
316
|
+
getEntries<T = any>(): Promise<[string, T][]>;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Get an item from storage for a given key.
|
|
320
|
+
* @param key The key to retrieve.
|
|
321
|
+
*/
|
|
322
|
+
getItem<T = any>(key: string): Promise<T | undefined>;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Set an item in storage for a given key.
|
|
326
|
+
* @param key The key to set.
|
|
327
|
+
* @param value The value to set.
|
|
328
|
+
*/
|
|
329
|
+
setItem<T = any>(key: string, value: T): Promise<void>;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Remove an item from storage for a given key.
|
|
333
|
+
* @param key The key to remove.
|
|
334
|
+
*/
|
|
335
|
+
removeItem(key: string): Promise<void>;
|
|
336
|
+
}
|