@agg-build/hooks 1.0.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 +403 -0
- package/dist/chunk-CDPQERUC.mjs +3601 -0
- package/dist/deposit.d.mts +184 -0
- package/dist/deposit.d.ts +184 -0
- package/dist/deposit.js +1563 -0
- package/dist/deposit.mjs +628 -0
- package/dist/index.d.mts +4640 -0
- package/dist/index.d.ts +4640 -0
- package/dist/index.js +5568 -0
- package/dist/index.mjs +2010 -0
- package/dist/use-sync-balances-D1Jdkck9.d.mts +246 -0
- package/dist/use-sync-balances-D1Jdkck9.d.ts +246 -0
- package/package.json +102 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
export { U as UseDepositAddressesOptions, a as UseSyncBalancesOptions, u as useDepositAddresses, b as useSyncBalances } from './use-sync-balances-D1Jdkck9.mjs';
|
|
2
|
+
import '@tanstack/react-query';
|
|
3
|
+
import '@agg-build/sdk';
|
|
4
|
+
|
|
5
|
+
type SupportedChain = {
|
|
6
|
+
chainId: number;
|
|
7
|
+
name: string;
|
|
8
|
+
tokens: Array<{
|
|
9
|
+
symbol: string;
|
|
10
|
+
address: string;
|
|
11
|
+
decimals: number;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
declare function normalizeWalletError(error: unknown, supportedChains: SupportedChain[] | undefined): {
|
|
15
|
+
message: string;
|
|
16
|
+
tone: "warning" | "error";
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface UseWalletTokenBalanceParams {
|
|
20
|
+
isOpen?: boolean;
|
|
21
|
+
chainId: number | undefined;
|
|
22
|
+
tokenAddress: string | undefined;
|
|
23
|
+
decimals: number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Explicit Solana wallet address (base58) fallback — used when the
|
|
26
|
+
* wallet-adapter and Phantom injected provider haven't hydrated yet.
|
|
27
|
+
*/
|
|
28
|
+
svmAddress?: string;
|
|
29
|
+
}
|
|
30
|
+
interface UseWalletTokenBalanceResult {
|
|
31
|
+
balance: number;
|
|
32
|
+
isLoading: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reads the connected wallet's on-chain balance for a given token on a given chain.
|
|
36
|
+
* Dispatches to wagmi (EVM) or @solana/web3.js (SVM) based on chainId.
|
|
37
|
+
*/
|
|
38
|
+
declare function useWalletTokenBalance({ isOpen, chainId, tokenAddress, decimals, svmAddress, }: UseWalletTokenBalanceParams): UseWalletTokenBalanceResult;
|
|
39
|
+
|
|
40
|
+
interface UseWalletSendTokenParams {
|
|
41
|
+
chainId: number;
|
|
42
|
+
token: {
|
|
43
|
+
symbol: string;
|
|
44
|
+
address?: string;
|
|
45
|
+
decimals: number;
|
|
46
|
+
};
|
|
47
|
+
to: string;
|
|
48
|
+
amount: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Dual-chain sendToken implementation:
|
|
52
|
+
* - EVM: uses wagmi writeContract to call ERC-20 transfer
|
|
53
|
+
* - SVM: uses wallet-adapter (or injected Phantom) to submit an SPL TransferChecked tx
|
|
54
|
+
*
|
|
55
|
+
* Matches the `WalletActions.sendToken` signature so it can be passed into
|
|
56
|
+
* `AggProvider` config directly, or composed inside `useDepositFlow`.
|
|
57
|
+
*/
|
|
58
|
+
declare function useWalletSendToken(): (params: UseWalletSendTokenParams) => Promise<{
|
|
59
|
+
txId: string;
|
|
60
|
+
}>;
|
|
61
|
+
|
|
62
|
+
type WalletTransactionStatus = "submitted" | "confirming" | "settled" | "error";
|
|
63
|
+
interface UseWalletTransactionStatusParams {
|
|
64
|
+
chainId: number | undefined;
|
|
65
|
+
txId: string | null;
|
|
66
|
+
}
|
|
67
|
+
interface UseWalletTransactionStatusResult {
|
|
68
|
+
status: WalletTransactionStatus | null;
|
|
69
|
+
gasFee: string;
|
|
70
|
+
}
|
|
71
|
+
declare function useWalletTransactionStatus({ chainId, txId, }: UseWalletTransactionStatusParams): UseWalletTransactionStatusResult;
|
|
72
|
+
|
|
73
|
+
type CardProviderOption = {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
quote: string;
|
|
77
|
+
fee: string;
|
|
78
|
+
badge?: "best" | "low-kyc";
|
|
79
|
+
};
|
|
80
|
+
type CardPurchaseSummary = {
|
|
81
|
+
amountReceived: string;
|
|
82
|
+
network: string;
|
|
83
|
+
fees: string;
|
|
84
|
+
};
|
|
85
|
+
type WalletDepositConfirmParams = {
|
|
86
|
+
address: string;
|
|
87
|
+
amount: string;
|
|
88
|
+
chainId: number;
|
|
89
|
+
token: string;
|
|
90
|
+
};
|
|
91
|
+
type DepositSelectOption = {
|
|
92
|
+
value: string;
|
|
93
|
+
label: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Subset of `DepositModalProps` populated by {@link useDepositFlow}. Callers
|
|
97
|
+
* spread this onto `<DepositModal>`; any prop the caller passes explicitly
|
|
98
|
+
* overrides the orchestrator. Typed loosely here so `@agg-build/hooks`
|
|
99
|
+
* doesn't take a build-time dependency on `@agg-build/ui`.
|
|
100
|
+
*/
|
|
101
|
+
interface UseDepositFlowResult {
|
|
102
|
+
open: boolean;
|
|
103
|
+
onOpenChange: (open: boolean) => void;
|
|
104
|
+
pendingCardPurchaseSummary: CardPurchaseSummary | null;
|
|
105
|
+
walletFlow: {
|
|
106
|
+
balance: number;
|
|
107
|
+
walletLabel: string;
|
|
108
|
+
walletBalance: number;
|
|
109
|
+
isWalletBalanceLoading: boolean;
|
|
110
|
+
amount: string;
|
|
111
|
+
formErrorMessage?: string;
|
|
112
|
+
formErrorTone: "warning" | "error";
|
|
113
|
+
transactionStatus: WalletTransactionStatus | undefined;
|
|
114
|
+
transactionErrorMessage?: string;
|
|
115
|
+
successSummary: {
|
|
116
|
+
fromWallet: string;
|
|
117
|
+
gasFee: string;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
onWalletAmountChange: (amount: string) => void;
|
|
121
|
+
onWalletMax: () => void;
|
|
122
|
+
onConfirmWalletDeposit: (params: WalletDepositConfirmParams) => Promise<void>;
|
|
123
|
+
onWalletNetworkChange: (chainId: string) => void;
|
|
124
|
+
onWalletTokenChange: (tokenSymbol: string) => void;
|
|
125
|
+
initialWalletChainId: string | undefined;
|
|
126
|
+
/** External wallet kind, when only one is connected. Lets the modal filter
|
|
127
|
+
* wallet-flow network options to chains compatible with that wallet.
|
|
128
|
+
* `undefined` when neither or both are connected — modal shows all chains. */
|
|
129
|
+
connectedWalletKind?: "evm" | "solana";
|
|
130
|
+
sendCryptoConfig: {
|
|
131
|
+
minDeposit: string;
|
|
132
|
+
feeEstimate: string;
|
|
133
|
+
eta: string;
|
|
134
|
+
};
|
|
135
|
+
onDoneSendCrypto: () => void;
|
|
136
|
+
cardFlow: {
|
|
137
|
+
amount: string;
|
|
138
|
+
currency: string;
|
|
139
|
+
tokenOptions: DepositSelectOption[];
|
|
140
|
+
selectedToken: string;
|
|
141
|
+
selectedNetwork: string;
|
|
142
|
+
providers: CardProviderOption[];
|
|
143
|
+
purchaseSummary: CardPurchaseSummary;
|
|
144
|
+
minAmount: number;
|
|
145
|
+
};
|
|
146
|
+
onCardAmountChange: (amount: string) => void;
|
|
147
|
+
onCardNetworkChange: (network: string) => void;
|
|
148
|
+
onDoneCardPurchase: () => void;
|
|
149
|
+
cardRedirectUrl: string | undefined;
|
|
150
|
+
onGetCardQuotes: (params: {
|
|
151
|
+
sourceAmount: string;
|
|
152
|
+
sourceCurrencyCode: string;
|
|
153
|
+
destinationCurrencyCode: string;
|
|
154
|
+
}) => Promise<CardProviderOption[]>;
|
|
155
|
+
onCreateCardSession: (params: {
|
|
156
|
+
serviceProvider: string;
|
|
157
|
+
sourceAmount: string;
|
|
158
|
+
sourceCurrencyCode: string;
|
|
159
|
+
destinationCurrencyCode: string;
|
|
160
|
+
walletAddress: string;
|
|
161
|
+
redirectUrl?: string;
|
|
162
|
+
}) => Promise<{
|
|
163
|
+
id: string;
|
|
164
|
+
widgetUrl: string;
|
|
165
|
+
serviceProviderWidgetUrl: string;
|
|
166
|
+
}>;
|
|
167
|
+
}
|
|
168
|
+
interface UseDepositFlowOptions {
|
|
169
|
+
open: boolean;
|
|
170
|
+
onOpenChange: (open: boolean) => void;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Orchestrator hook that encapsulates all wallet + card deposit state and
|
|
174
|
+
* glue previously hand-wired inside partner apps. Spread the return value
|
|
175
|
+
* onto `<DepositModal>` to get the full plug-and-play deposit experience.
|
|
176
|
+
*
|
|
177
|
+
* Requires wagmi + @solana/wallet-adapter-react providers in the React tree.
|
|
178
|
+
*/
|
|
179
|
+
declare function useDepositFlow(options: UseDepositFlowOptions): UseDepositFlowResult;
|
|
180
|
+
|
|
181
|
+
declare const DEFAULT_SOLANA_RPC_ENDPOINT = "https://solana-rpc.publicnode.com";
|
|
182
|
+
declare const SVM_CHAIN_IDS: ReadonlySet<number>;
|
|
183
|
+
|
|
184
|
+
export { DEFAULT_SOLANA_RPC_ENDPOINT, SVM_CHAIN_IDS, type UseDepositFlowOptions, type UseDepositFlowResult, type UseWalletSendTokenParams, type UseWalletTokenBalanceParams, type UseWalletTokenBalanceResult, type UseWalletTransactionStatusParams, type UseWalletTransactionStatusResult, type WalletTransactionStatus, normalizeWalletError, useDepositFlow, useWalletSendToken, useWalletTokenBalance, useWalletTransactionStatus };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
export { U as UseDepositAddressesOptions, a as UseSyncBalancesOptions, u as useDepositAddresses, b as useSyncBalances } from './use-sync-balances-D1Jdkck9.js';
|
|
2
|
+
import '@tanstack/react-query';
|
|
3
|
+
import '@agg-build/sdk';
|
|
4
|
+
|
|
5
|
+
type SupportedChain = {
|
|
6
|
+
chainId: number;
|
|
7
|
+
name: string;
|
|
8
|
+
tokens: Array<{
|
|
9
|
+
symbol: string;
|
|
10
|
+
address: string;
|
|
11
|
+
decimals: number;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
declare function normalizeWalletError(error: unknown, supportedChains: SupportedChain[] | undefined): {
|
|
15
|
+
message: string;
|
|
16
|
+
tone: "warning" | "error";
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface UseWalletTokenBalanceParams {
|
|
20
|
+
isOpen?: boolean;
|
|
21
|
+
chainId: number | undefined;
|
|
22
|
+
tokenAddress: string | undefined;
|
|
23
|
+
decimals: number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Explicit Solana wallet address (base58) fallback — used when the
|
|
26
|
+
* wallet-adapter and Phantom injected provider haven't hydrated yet.
|
|
27
|
+
*/
|
|
28
|
+
svmAddress?: string;
|
|
29
|
+
}
|
|
30
|
+
interface UseWalletTokenBalanceResult {
|
|
31
|
+
balance: number;
|
|
32
|
+
isLoading: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reads the connected wallet's on-chain balance for a given token on a given chain.
|
|
36
|
+
* Dispatches to wagmi (EVM) or @solana/web3.js (SVM) based on chainId.
|
|
37
|
+
*/
|
|
38
|
+
declare function useWalletTokenBalance({ isOpen, chainId, tokenAddress, decimals, svmAddress, }: UseWalletTokenBalanceParams): UseWalletTokenBalanceResult;
|
|
39
|
+
|
|
40
|
+
interface UseWalletSendTokenParams {
|
|
41
|
+
chainId: number;
|
|
42
|
+
token: {
|
|
43
|
+
symbol: string;
|
|
44
|
+
address?: string;
|
|
45
|
+
decimals: number;
|
|
46
|
+
};
|
|
47
|
+
to: string;
|
|
48
|
+
amount: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Dual-chain sendToken implementation:
|
|
52
|
+
* - EVM: uses wagmi writeContract to call ERC-20 transfer
|
|
53
|
+
* - SVM: uses wallet-adapter (or injected Phantom) to submit an SPL TransferChecked tx
|
|
54
|
+
*
|
|
55
|
+
* Matches the `WalletActions.sendToken` signature so it can be passed into
|
|
56
|
+
* `AggProvider` config directly, or composed inside `useDepositFlow`.
|
|
57
|
+
*/
|
|
58
|
+
declare function useWalletSendToken(): (params: UseWalletSendTokenParams) => Promise<{
|
|
59
|
+
txId: string;
|
|
60
|
+
}>;
|
|
61
|
+
|
|
62
|
+
type WalletTransactionStatus = "submitted" | "confirming" | "settled" | "error";
|
|
63
|
+
interface UseWalletTransactionStatusParams {
|
|
64
|
+
chainId: number | undefined;
|
|
65
|
+
txId: string | null;
|
|
66
|
+
}
|
|
67
|
+
interface UseWalletTransactionStatusResult {
|
|
68
|
+
status: WalletTransactionStatus | null;
|
|
69
|
+
gasFee: string;
|
|
70
|
+
}
|
|
71
|
+
declare function useWalletTransactionStatus({ chainId, txId, }: UseWalletTransactionStatusParams): UseWalletTransactionStatusResult;
|
|
72
|
+
|
|
73
|
+
type CardProviderOption = {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
quote: string;
|
|
77
|
+
fee: string;
|
|
78
|
+
badge?: "best" | "low-kyc";
|
|
79
|
+
};
|
|
80
|
+
type CardPurchaseSummary = {
|
|
81
|
+
amountReceived: string;
|
|
82
|
+
network: string;
|
|
83
|
+
fees: string;
|
|
84
|
+
};
|
|
85
|
+
type WalletDepositConfirmParams = {
|
|
86
|
+
address: string;
|
|
87
|
+
amount: string;
|
|
88
|
+
chainId: number;
|
|
89
|
+
token: string;
|
|
90
|
+
};
|
|
91
|
+
type DepositSelectOption = {
|
|
92
|
+
value: string;
|
|
93
|
+
label: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Subset of `DepositModalProps` populated by {@link useDepositFlow}. Callers
|
|
97
|
+
* spread this onto `<DepositModal>`; any prop the caller passes explicitly
|
|
98
|
+
* overrides the orchestrator. Typed loosely here so `@agg-build/hooks`
|
|
99
|
+
* doesn't take a build-time dependency on `@agg-build/ui`.
|
|
100
|
+
*/
|
|
101
|
+
interface UseDepositFlowResult {
|
|
102
|
+
open: boolean;
|
|
103
|
+
onOpenChange: (open: boolean) => void;
|
|
104
|
+
pendingCardPurchaseSummary: CardPurchaseSummary | null;
|
|
105
|
+
walletFlow: {
|
|
106
|
+
balance: number;
|
|
107
|
+
walletLabel: string;
|
|
108
|
+
walletBalance: number;
|
|
109
|
+
isWalletBalanceLoading: boolean;
|
|
110
|
+
amount: string;
|
|
111
|
+
formErrorMessage?: string;
|
|
112
|
+
formErrorTone: "warning" | "error";
|
|
113
|
+
transactionStatus: WalletTransactionStatus | undefined;
|
|
114
|
+
transactionErrorMessage?: string;
|
|
115
|
+
successSummary: {
|
|
116
|
+
fromWallet: string;
|
|
117
|
+
gasFee: string;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
onWalletAmountChange: (amount: string) => void;
|
|
121
|
+
onWalletMax: () => void;
|
|
122
|
+
onConfirmWalletDeposit: (params: WalletDepositConfirmParams) => Promise<void>;
|
|
123
|
+
onWalletNetworkChange: (chainId: string) => void;
|
|
124
|
+
onWalletTokenChange: (tokenSymbol: string) => void;
|
|
125
|
+
initialWalletChainId: string | undefined;
|
|
126
|
+
/** External wallet kind, when only one is connected. Lets the modal filter
|
|
127
|
+
* wallet-flow network options to chains compatible with that wallet.
|
|
128
|
+
* `undefined` when neither or both are connected — modal shows all chains. */
|
|
129
|
+
connectedWalletKind?: "evm" | "solana";
|
|
130
|
+
sendCryptoConfig: {
|
|
131
|
+
minDeposit: string;
|
|
132
|
+
feeEstimate: string;
|
|
133
|
+
eta: string;
|
|
134
|
+
};
|
|
135
|
+
onDoneSendCrypto: () => void;
|
|
136
|
+
cardFlow: {
|
|
137
|
+
amount: string;
|
|
138
|
+
currency: string;
|
|
139
|
+
tokenOptions: DepositSelectOption[];
|
|
140
|
+
selectedToken: string;
|
|
141
|
+
selectedNetwork: string;
|
|
142
|
+
providers: CardProviderOption[];
|
|
143
|
+
purchaseSummary: CardPurchaseSummary;
|
|
144
|
+
minAmount: number;
|
|
145
|
+
};
|
|
146
|
+
onCardAmountChange: (amount: string) => void;
|
|
147
|
+
onCardNetworkChange: (network: string) => void;
|
|
148
|
+
onDoneCardPurchase: () => void;
|
|
149
|
+
cardRedirectUrl: string | undefined;
|
|
150
|
+
onGetCardQuotes: (params: {
|
|
151
|
+
sourceAmount: string;
|
|
152
|
+
sourceCurrencyCode: string;
|
|
153
|
+
destinationCurrencyCode: string;
|
|
154
|
+
}) => Promise<CardProviderOption[]>;
|
|
155
|
+
onCreateCardSession: (params: {
|
|
156
|
+
serviceProvider: string;
|
|
157
|
+
sourceAmount: string;
|
|
158
|
+
sourceCurrencyCode: string;
|
|
159
|
+
destinationCurrencyCode: string;
|
|
160
|
+
walletAddress: string;
|
|
161
|
+
redirectUrl?: string;
|
|
162
|
+
}) => Promise<{
|
|
163
|
+
id: string;
|
|
164
|
+
widgetUrl: string;
|
|
165
|
+
serviceProviderWidgetUrl: string;
|
|
166
|
+
}>;
|
|
167
|
+
}
|
|
168
|
+
interface UseDepositFlowOptions {
|
|
169
|
+
open: boolean;
|
|
170
|
+
onOpenChange: (open: boolean) => void;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Orchestrator hook that encapsulates all wallet + card deposit state and
|
|
174
|
+
* glue previously hand-wired inside partner apps. Spread the return value
|
|
175
|
+
* onto `<DepositModal>` to get the full plug-and-play deposit experience.
|
|
176
|
+
*
|
|
177
|
+
* Requires wagmi + @solana/wallet-adapter-react providers in the React tree.
|
|
178
|
+
*/
|
|
179
|
+
declare function useDepositFlow(options: UseDepositFlowOptions): UseDepositFlowResult;
|
|
180
|
+
|
|
181
|
+
declare const DEFAULT_SOLANA_RPC_ENDPOINT = "https://solana-rpc.publicnode.com";
|
|
182
|
+
declare const SVM_CHAIN_IDS: ReadonlySet<number>;
|
|
183
|
+
|
|
184
|
+
export { DEFAULT_SOLANA_RPC_ENDPOINT, SVM_CHAIN_IDS, type UseDepositFlowOptions, type UseDepositFlowResult, type UseWalletSendTokenParams, type UseWalletTokenBalanceParams, type UseWalletTokenBalanceResult, type UseWalletTransactionStatusParams, type UseWalletTransactionStatusResult, type WalletTransactionStatus, normalizeWalletError, useDepositFlow, useWalletSendToken, useWalletTokenBalance, useWalletTransactionStatus };
|