@sanketsaagar/polygon-kit 0.1.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/LICENSE +21 -0
- package/README.md +522 -0
- package/dist/index.d.mts +186 -0
- package/dist/index.d.ts +186 -0
- package/dist/index.js +703 -0
- package/dist/index.mjs +652 -0
- package/package.json +70 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Address, Hash } from 'viem';
|
|
4
|
+
import { Connector } from 'wagmi';
|
|
5
|
+
|
|
6
|
+
interface PolygonKitConfig {
|
|
7
|
+
projectId?: string;
|
|
8
|
+
rpcUrl?: string;
|
|
9
|
+
chains?: Chain[];
|
|
10
|
+
appName?: string;
|
|
11
|
+
appDescription?: string;
|
|
12
|
+
appUrl?: string;
|
|
13
|
+
appIcons?: string[];
|
|
14
|
+
}
|
|
15
|
+
interface Chain {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
network: string;
|
|
19
|
+
nativeCurrency: {
|
|
20
|
+
name: string;
|
|
21
|
+
symbol: string;
|
|
22
|
+
decimals: number;
|
|
23
|
+
};
|
|
24
|
+
rpcUrls: {
|
|
25
|
+
default: {
|
|
26
|
+
http: string[];
|
|
27
|
+
};
|
|
28
|
+
public: {
|
|
29
|
+
http: string[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
blockExplorers: {
|
|
33
|
+
default: {
|
|
34
|
+
name: string;
|
|
35
|
+
url: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface WalletProps {
|
|
40
|
+
children?: ReactNode;
|
|
41
|
+
className?: string;
|
|
42
|
+
}
|
|
43
|
+
interface ConnectWalletProps {
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
className?: string;
|
|
46
|
+
onConnect?: (address: Address) => void;
|
|
47
|
+
onDisconnect?: () => void;
|
|
48
|
+
}
|
|
49
|
+
interface WalletDropdownProps {
|
|
50
|
+
children?: ReactNode;
|
|
51
|
+
className?: string;
|
|
52
|
+
}
|
|
53
|
+
interface IdentityProps {
|
|
54
|
+
address: Address;
|
|
55
|
+
className?: string;
|
|
56
|
+
showAvatar?: boolean;
|
|
57
|
+
showAddress?: boolean;
|
|
58
|
+
showBalance?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface AvatarProps {
|
|
61
|
+
address: Address;
|
|
62
|
+
className?: string;
|
|
63
|
+
size?: number;
|
|
64
|
+
}
|
|
65
|
+
interface NameProps {
|
|
66
|
+
address: Address;
|
|
67
|
+
className?: string;
|
|
68
|
+
}
|
|
69
|
+
interface TransactionProps {
|
|
70
|
+
children?: ReactNode;
|
|
71
|
+
className?: string;
|
|
72
|
+
chainId?: number;
|
|
73
|
+
onSuccess?: (hash: string) => void;
|
|
74
|
+
onError?: (error: Error) => void;
|
|
75
|
+
}
|
|
76
|
+
interface TransactionButtonProps {
|
|
77
|
+
text?: string;
|
|
78
|
+
className?: string;
|
|
79
|
+
disabled?: boolean;
|
|
80
|
+
calls?: TransactionCall[];
|
|
81
|
+
onSuccess?: (hash: string) => void;
|
|
82
|
+
onError?: (error: Error) => void;
|
|
83
|
+
}
|
|
84
|
+
interface TransactionCall {
|
|
85
|
+
to: Address;
|
|
86
|
+
data?: `0x${string}`;
|
|
87
|
+
value?: bigint;
|
|
88
|
+
}
|
|
89
|
+
interface TokenProps {
|
|
90
|
+
address: Address;
|
|
91
|
+
amount?: string;
|
|
92
|
+
symbol?: string;
|
|
93
|
+
className?: string;
|
|
94
|
+
}
|
|
95
|
+
interface TokenBalanceProps {
|
|
96
|
+
address: Address;
|
|
97
|
+
token?: Address;
|
|
98
|
+
className?: string;
|
|
99
|
+
}
|
|
100
|
+
interface SwapProps {
|
|
101
|
+
className?: string;
|
|
102
|
+
onSuccess?: (hash: string) => void;
|
|
103
|
+
onError?: (error: Error) => void;
|
|
104
|
+
}
|
|
105
|
+
type ThemeMode = 'light' | 'dark' | 'auto';
|
|
106
|
+
interface PolygonKitProviderProps {
|
|
107
|
+
children: ReactNode;
|
|
108
|
+
config?: PolygonKitConfig;
|
|
109
|
+
theme?: ThemeMode;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
declare function PolygonKitProvider({ children, config: userConfig, }: PolygonKitProviderProps): react_jsx_runtime.JSX.Element;
|
|
113
|
+
|
|
114
|
+
declare function Wallet({ children, className }: WalletProps): react_jsx_runtime.JSX.Element;
|
|
115
|
+
|
|
116
|
+
declare function ConnectWallet({ children, className, onConnect, onDisconnect: onDisconnectCallback, }: ConnectWalletProps): react_jsx_runtime.JSX.Element;
|
|
117
|
+
|
|
118
|
+
declare function WalletDropdown({ children, className }: WalletDropdownProps): react_jsx_runtime.JSX.Element | null;
|
|
119
|
+
|
|
120
|
+
declare function Identity({ address, className, showAvatar, showAddress, showBalance, }: IdentityProps): react_jsx_runtime.JSX.Element;
|
|
121
|
+
|
|
122
|
+
declare function Avatar({ address, className, size }: AvatarProps): react_jsx_runtime.JSX.Element;
|
|
123
|
+
|
|
124
|
+
declare function Name({ address, className }: NameProps): react_jsx_runtime.JSX.Element;
|
|
125
|
+
|
|
126
|
+
declare function Transaction({ children, className, chainId, }: TransactionProps): react_jsx_runtime.JSX.Element;
|
|
127
|
+
|
|
128
|
+
declare function TransactionButton({ text, className, disabled, calls, onSuccess, onError, }: TransactionButtonProps): react_jsx_runtime.JSX.Element;
|
|
129
|
+
|
|
130
|
+
interface TransactionStatusProps {
|
|
131
|
+
hash: Hash;
|
|
132
|
+
className?: string;
|
|
133
|
+
}
|
|
134
|
+
declare function TransactionStatus({ hash, className }: TransactionStatusProps): react_jsx_runtime.JSX.Element;
|
|
135
|
+
|
|
136
|
+
declare function Token({ amount, symbol, className }: TokenProps): react_jsx_runtime.JSX.Element;
|
|
137
|
+
|
|
138
|
+
declare function TokenBalance({ address, token, className }: TokenBalanceProps): react_jsx_runtime.JSX.Element;
|
|
139
|
+
|
|
140
|
+
declare function Swap({ className, onSuccess, onError }: SwapProps): react_jsx_runtime.JSX.Element;
|
|
141
|
+
|
|
142
|
+
interface UsePolygonKitReturn {
|
|
143
|
+
address: Address | undefined;
|
|
144
|
+
isConnected: boolean;
|
|
145
|
+
chain: any;
|
|
146
|
+
balance: any;
|
|
147
|
+
connect: () => void;
|
|
148
|
+
disconnect: () => void;
|
|
149
|
+
connectors: readonly Connector[];
|
|
150
|
+
}
|
|
151
|
+
declare function usePolygonKit(): UsePolygonKitReturn;
|
|
152
|
+
|
|
153
|
+
interface UsePolygonBalanceReturn {
|
|
154
|
+
balance: bigint | undefined;
|
|
155
|
+
formatted: string;
|
|
156
|
+
symbol: string | undefined;
|
|
157
|
+
decimals: number | undefined;
|
|
158
|
+
isLoading: boolean;
|
|
159
|
+
isError: boolean;
|
|
160
|
+
refetch: () => void;
|
|
161
|
+
}
|
|
162
|
+
declare function usePolygonBalance(address?: Address, token?: Address): UsePolygonBalanceReturn;
|
|
163
|
+
|
|
164
|
+
interface UsePolygonTransactionReturn {
|
|
165
|
+
send: (to: Address, value?: bigint, data?: `0x${string}`) => void;
|
|
166
|
+
hash: Hash | undefined;
|
|
167
|
+
isPending: boolean;
|
|
168
|
+
isConfirming: boolean;
|
|
169
|
+
isSuccess: boolean;
|
|
170
|
+
isError: boolean;
|
|
171
|
+
error: Error | null;
|
|
172
|
+
}
|
|
173
|
+
declare function usePolygonTransaction(): UsePolygonTransactionReturn;
|
|
174
|
+
|
|
175
|
+
declare function shortenAddress(address: Address, chars?: number): string;
|
|
176
|
+
declare function formatBalance(balance: bigint, decimals?: number, displayDecimals?: number): string;
|
|
177
|
+
declare function parseTokenAmount(amount: string, decimals?: number): bigint;
|
|
178
|
+
declare function truncateText(text: string, maxLength: number): string;
|
|
179
|
+
|
|
180
|
+
declare const polygon: Chain;
|
|
181
|
+
declare const polygonMumbai: Chain;
|
|
182
|
+
declare const polygonAmoy: Chain;
|
|
183
|
+
declare const polygonZkEVM: Chain;
|
|
184
|
+
declare const defaultChains: Chain[];
|
|
185
|
+
|
|
186
|
+
export { Avatar, type AvatarProps, type Chain, ConnectWallet, type ConnectWalletProps, Identity, type IdentityProps, Name, type NameProps, type PolygonKitConfig, PolygonKitProvider, type PolygonKitProviderProps, Swap, type SwapProps, type ThemeMode, Token, TokenBalance, type TokenBalanceProps, type TokenProps, Transaction, TransactionButton, type TransactionButtonProps, type TransactionCall, type TransactionProps, TransactionStatus, Wallet, WalletDropdown, type WalletDropdownProps, type WalletProps, defaultChains, formatBalance, parseTokenAmount, polygon, polygonAmoy, polygonMumbai, polygonZkEVM, shortenAddress, truncateText, usePolygonBalance, usePolygonKit, usePolygonTransaction };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Address, Hash } from 'viem';
|
|
4
|
+
import { Connector } from 'wagmi';
|
|
5
|
+
|
|
6
|
+
interface PolygonKitConfig {
|
|
7
|
+
projectId?: string;
|
|
8
|
+
rpcUrl?: string;
|
|
9
|
+
chains?: Chain[];
|
|
10
|
+
appName?: string;
|
|
11
|
+
appDescription?: string;
|
|
12
|
+
appUrl?: string;
|
|
13
|
+
appIcons?: string[];
|
|
14
|
+
}
|
|
15
|
+
interface Chain {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
network: string;
|
|
19
|
+
nativeCurrency: {
|
|
20
|
+
name: string;
|
|
21
|
+
symbol: string;
|
|
22
|
+
decimals: number;
|
|
23
|
+
};
|
|
24
|
+
rpcUrls: {
|
|
25
|
+
default: {
|
|
26
|
+
http: string[];
|
|
27
|
+
};
|
|
28
|
+
public: {
|
|
29
|
+
http: string[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
blockExplorers: {
|
|
33
|
+
default: {
|
|
34
|
+
name: string;
|
|
35
|
+
url: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface WalletProps {
|
|
40
|
+
children?: ReactNode;
|
|
41
|
+
className?: string;
|
|
42
|
+
}
|
|
43
|
+
interface ConnectWalletProps {
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
className?: string;
|
|
46
|
+
onConnect?: (address: Address) => void;
|
|
47
|
+
onDisconnect?: () => void;
|
|
48
|
+
}
|
|
49
|
+
interface WalletDropdownProps {
|
|
50
|
+
children?: ReactNode;
|
|
51
|
+
className?: string;
|
|
52
|
+
}
|
|
53
|
+
interface IdentityProps {
|
|
54
|
+
address: Address;
|
|
55
|
+
className?: string;
|
|
56
|
+
showAvatar?: boolean;
|
|
57
|
+
showAddress?: boolean;
|
|
58
|
+
showBalance?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface AvatarProps {
|
|
61
|
+
address: Address;
|
|
62
|
+
className?: string;
|
|
63
|
+
size?: number;
|
|
64
|
+
}
|
|
65
|
+
interface NameProps {
|
|
66
|
+
address: Address;
|
|
67
|
+
className?: string;
|
|
68
|
+
}
|
|
69
|
+
interface TransactionProps {
|
|
70
|
+
children?: ReactNode;
|
|
71
|
+
className?: string;
|
|
72
|
+
chainId?: number;
|
|
73
|
+
onSuccess?: (hash: string) => void;
|
|
74
|
+
onError?: (error: Error) => void;
|
|
75
|
+
}
|
|
76
|
+
interface TransactionButtonProps {
|
|
77
|
+
text?: string;
|
|
78
|
+
className?: string;
|
|
79
|
+
disabled?: boolean;
|
|
80
|
+
calls?: TransactionCall[];
|
|
81
|
+
onSuccess?: (hash: string) => void;
|
|
82
|
+
onError?: (error: Error) => void;
|
|
83
|
+
}
|
|
84
|
+
interface TransactionCall {
|
|
85
|
+
to: Address;
|
|
86
|
+
data?: `0x${string}`;
|
|
87
|
+
value?: bigint;
|
|
88
|
+
}
|
|
89
|
+
interface TokenProps {
|
|
90
|
+
address: Address;
|
|
91
|
+
amount?: string;
|
|
92
|
+
symbol?: string;
|
|
93
|
+
className?: string;
|
|
94
|
+
}
|
|
95
|
+
interface TokenBalanceProps {
|
|
96
|
+
address: Address;
|
|
97
|
+
token?: Address;
|
|
98
|
+
className?: string;
|
|
99
|
+
}
|
|
100
|
+
interface SwapProps {
|
|
101
|
+
className?: string;
|
|
102
|
+
onSuccess?: (hash: string) => void;
|
|
103
|
+
onError?: (error: Error) => void;
|
|
104
|
+
}
|
|
105
|
+
type ThemeMode = 'light' | 'dark' | 'auto';
|
|
106
|
+
interface PolygonKitProviderProps {
|
|
107
|
+
children: ReactNode;
|
|
108
|
+
config?: PolygonKitConfig;
|
|
109
|
+
theme?: ThemeMode;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
declare function PolygonKitProvider({ children, config: userConfig, }: PolygonKitProviderProps): react_jsx_runtime.JSX.Element;
|
|
113
|
+
|
|
114
|
+
declare function Wallet({ children, className }: WalletProps): react_jsx_runtime.JSX.Element;
|
|
115
|
+
|
|
116
|
+
declare function ConnectWallet({ children, className, onConnect, onDisconnect: onDisconnectCallback, }: ConnectWalletProps): react_jsx_runtime.JSX.Element;
|
|
117
|
+
|
|
118
|
+
declare function WalletDropdown({ children, className }: WalletDropdownProps): react_jsx_runtime.JSX.Element | null;
|
|
119
|
+
|
|
120
|
+
declare function Identity({ address, className, showAvatar, showAddress, showBalance, }: IdentityProps): react_jsx_runtime.JSX.Element;
|
|
121
|
+
|
|
122
|
+
declare function Avatar({ address, className, size }: AvatarProps): react_jsx_runtime.JSX.Element;
|
|
123
|
+
|
|
124
|
+
declare function Name({ address, className }: NameProps): react_jsx_runtime.JSX.Element;
|
|
125
|
+
|
|
126
|
+
declare function Transaction({ children, className, chainId, }: TransactionProps): react_jsx_runtime.JSX.Element;
|
|
127
|
+
|
|
128
|
+
declare function TransactionButton({ text, className, disabled, calls, onSuccess, onError, }: TransactionButtonProps): react_jsx_runtime.JSX.Element;
|
|
129
|
+
|
|
130
|
+
interface TransactionStatusProps {
|
|
131
|
+
hash: Hash;
|
|
132
|
+
className?: string;
|
|
133
|
+
}
|
|
134
|
+
declare function TransactionStatus({ hash, className }: TransactionStatusProps): react_jsx_runtime.JSX.Element;
|
|
135
|
+
|
|
136
|
+
declare function Token({ amount, symbol, className }: TokenProps): react_jsx_runtime.JSX.Element;
|
|
137
|
+
|
|
138
|
+
declare function TokenBalance({ address, token, className }: TokenBalanceProps): react_jsx_runtime.JSX.Element;
|
|
139
|
+
|
|
140
|
+
declare function Swap({ className, onSuccess, onError }: SwapProps): react_jsx_runtime.JSX.Element;
|
|
141
|
+
|
|
142
|
+
interface UsePolygonKitReturn {
|
|
143
|
+
address: Address | undefined;
|
|
144
|
+
isConnected: boolean;
|
|
145
|
+
chain: any;
|
|
146
|
+
balance: any;
|
|
147
|
+
connect: () => void;
|
|
148
|
+
disconnect: () => void;
|
|
149
|
+
connectors: readonly Connector[];
|
|
150
|
+
}
|
|
151
|
+
declare function usePolygonKit(): UsePolygonKitReturn;
|
|
152
|
+
|
|
153
|
+
interface UsePolygonBalanceReturn {
|
|
154
|
+
balance: bigint | undefined;
|
|
155
|
+
formatted: string;
|
|
156
|
+
symbol: string | undefined;
|
|
157
|
+
decimals: number | undefined;
|
|
158
|
+
isLoading: boolean;
|
|
159
|
+
isError: boolean;
|
|
160
|
+
refetch: () => void;
|
|
161
|
+
}
|
|
162
|
+
declare function usePolygonBalance(address?: Address, token?: Address): UsePolygonBalanceReturn;
|
|
163
|
+
|
|
164
|
+
interface UsePolygonTransactionReturn {
|
|
165
|
+
send: (to: Address, value?: bigint, data?: `0x${string}`) => void;
|
|
166
|
+
hash: Hash | undefined;
|
|
167
|
+
isPending: boolean;
|
|
168
|
+
isConfirming: boolean;
|
|
169
|
+
isSuccess: boolean;
|
|
170
|
+
isError: boolean;
|
|
171
|
+
error: Error | null;
|
|
172
|
+
}
|
|
173
|
+
declare function usePolygonTransaction(): UsePolygonTransactionReturn;
|
|
174
|
+
|
|
175
|
+
declare function shortenAddress(address: Address, chars?: number): string;
|
|
176
|
+
declare function formatBalance(balance: bigint, decimals?: number, displayDecimals?: number): string;
|
|
177
|
+
declare function parseTokenAmount(amount: string, decimals?: number): bigint;
|
|
178
|
+
declare function truncateText(text: string, maxLength: number): string;
|
|
179
|
+
|
|
180
|
+
declare const polygon: Chain;
|
|
181
|
+
declare const polygonMumbai: Chain;
|
|
182
|
+
declare const polygonAmoy: Chain;
|
|
183
|
+
declare const polygonZkEVM: Chain;
|
|
184
|
+
declare const defaultChains: Chain[];
|
|
185
|
+
|
|
186
|
+
export { Avatar, type AvatarProps, type Chain, ConnectWallet, type ConnectWalletProps, Identity, type IdentityProps, Name, type NameProps, type PolygonKitConfig, PolygonKitProvider, type PolygonKitProviderProps, Swap, type SwapProps, type ThemeMode, Token, TokenBalance, type TokenBalanceProps, type TokenProps, Transaction, TransactionButton, type TransactionButtonProps, type TransactionCall, type TransactionProps, TransactionStatus, Wallet, WalletDropdown, type WalletDropdownProps, type WalletProps, defaultChains, formatBalance, parseTokenAmount, polygon, polygonAmoy, polygonMumbai, polygonZkEVM, shortenAddress, truncateText, usePolygonBalance, usePolygonKit, usePolygonTransaction };
|