@b3dotfun/sdk 0.0.40-alpha.1 → 0.0.40-alpha.10
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/dist/cjs/anyspend/react/components/AnySpend.js +1 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +1 -1
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +38 -36
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -4
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +7 -6
- package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.js +21 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +12 -5
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +5 -3
- package/dist/cjs/anyspend/react/providers/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/providers/index.js +3 -0
- package/dist/cjs/anyspend/types/api.d.ts +10 -0
- package/dist/cjs/bondkit/bondkitToken.d.ts +37 -2
- package/dist/cjs/bondkit/bondkitToken.js +268 -2
- package/dist/cjs/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/cjs/bondkit/bondkitTokenFactory.js +2 -2
- package/dist/cjs/bondkit/config.d.ts +1 -1
- package/dist/cjs/bondkit/config.js +5 -2
- package/dist/cjs/bondkit/constants.d.ts +4 -0
- package/dist/cjs/bondkit/constants.js +6 -1
- package/dist/cjs/bondkit/index.d.ts +1 -0
- package/dist/cjs/bondkit/index.js +4 -1
- package/dist/cjs/bondkit/swapService.d.ts +43 -0
- package/dist/cjs/bondkit/swapService.js +373 -0
- package/dist/cjs/bondkit/types.d.ts +10 -4
- package/dist/cjs/bondkit/types.js +4 -5
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +35 -9
- package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +63 -3
- package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +4 -3
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +1 -2
- package/dist/esm/anyspend/react/components/AnySpend.js +1 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +1 -1
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +38 -36
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +1 -4
- package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +7 -6
- package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.js +17 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +12 -5
- package/dist/esm/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/esm/anyspend/react/providers/AnyspendProvider.js +5 -3
- package/dist/esm/anyspend/react/providers/index.d.ts +1 -0
- package/dist/esm/anyspend/react/providers/index.js +1 -0
- package/dist/esm/anyspend/types/api.d.ts +10 -0
- package/dist/esm/bondkit/bondkitToken.d.ts +37 -2
- package/dist/esm/bondkit/bondkitToken.js +268 -2
- package/dist/esm/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/esm/bondkit/bondkitTokenFactory.js +2 -2
- package/dist/esm/bondkit/config.d.ts +1 -1
- package/dist/esm/bondkit/config.js +5 -2
- package/dist/esm/bondkit/constants.d.ts +4 -0
- package/dist/esm/bondkit/constants.js +5 -0
- package/dist/esm/bondkit/index.d.ts +1 -0
- package/dist/esm/bondkit/index.js +2 -0
- package/dist/esm/bondkit/swapService.d.ts +43 -0
- package/dist/esm/bondkit/swapService.js +369 -0
- package/dist/esm/bondkit/types.d.ts +10 -4
- package/dist/esm/bondkit/types.js +4 -5
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +36 -9
- package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +65 -5
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +1 -2
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
- package/dist/types/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -0
- package/dist/types/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/types/anyspend/react/providers/index.d.ts +1 -0
- package/dist/types/anyspend/types/api.d.ts +10 -0
- package/dist/types/bondkit/bondkitToken.d.ts +37 -2
- package/dist/types/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/types/bondkit/config.d.ts +1 -1
- package/dist/types/bondkit/constants.d.ts +4 -0
- package/dist/types/bondkit/index.d.ts +1 -0
- package/dist/types/bondkit/swapService.d.ts +43 -0
- package/dist/types/bondkit/types.d.ts +10 -4
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
- package/package.json +6 -5
- package/src/anyspend/react/components/AnySpend.tsx +1 -0
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +1 -0
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +55 -45
- package/src/anyspend/react/components/common/OrderDetails.tsx +2 -5
- package/src/anyspend/react/components/common/PanelOnramp.tsx +21 -15
- package/src/anyspend/react/contexts/FeatureFlagsContext.tsx +34 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +12 -5
- package/src/anyspend/react/providers/AnyspendProvider.tsx +11 -6
- package/src/anyspend/react/providers/index.ts +1 -0
- package/src/anyspend/types/api.ts +10 -0
- package/src/anyspend/types/api_req_res.ts +6 -10
- package/src/bondkit/bondkitToken.ts +323 -3
- package/src/bondkit/bondkitTokenFactory.ts +2 -2
- package/src/bondkit/config.ts +5 -2
- package/src/bondkit/constants.ts +7 -0
- package/src/bondkit/index.ts +3 -0
- package/src/bondkit/swapService.ts +461 -0
- package/src/bondkit/types.ts +12 -5
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +51 -15
- package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +106 -32
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +60 -5
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +4 -2
- package/src/global-account/react/hooks/useAuthentication.ts +1 -2
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BondkitSwapService = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const chains_1 = require("viem/chains");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
// Minimal ABIs needed for swap functionality
|
|
8
|
+
const UNIVERSAL_ROUTER_ABI = [
|
|
9
|
+
{
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: "commands", type: "bytes" },
|
|
12
|
+
{ name: "inputs", type: "bytes[]" },
|
|
13
|
+
{ name: "deadline", type: "uint256" },
|
|
14
|
+
],
|
|
15
|
+
name: "execute",
|
|
16
|
+
outputs: [],
|
|
17
|
+
stateMutability: "payable",
|
|
18
|
+
type: "function",
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
const QUOTER_ABI = [
|
|
22
|
+
{
|
|
23
|
+
inputs: [
|
|
24
|
+
{
|
|
25
|
+
components: [
|
|
26
|
+
{
|
|
27
|
+
components: [
|
|
28
|
+
{ internalType: "Currency", name: "currency0", type: "address" },
|
|
29
|
+
{ internalType: "Currency", name: "currency1", type: "address" },
|
|
30
|
+
{ internalType: "uint24", name: "fee", type: "uint24" },
|
|
31
|
+
{ internalType: "int24", name: "tickSpacing", type: "int24" },
|
|
32
|
+
{ internalType: "contract IHooks", name: "hooks", type: "address" },
|
|
33
|
+
],
|
|
34
|
+
internalType: "struct PoolKey",
|
|
35
|
+
name: "poolKey",
|
|
36
|
+
type: "tuple",
|
|
37
|
+
},
|
|
38
|
+
{ internalType: "bool", name: "zeroForOne", type: "bool" },
|
|
39
|
+
{ internalType: "uint128", name: "exactAmount", type: "uint128" },
|
|
40
|
+
{ internalType: "bytes", name: "hookData", type: "bytes" },
|
|
41
|
+
],
|
|
42
|
+
internalType: "struct IV4Quoter.QuoteExactSingleParams",
|
|
43
|
+
name: "params",
|
|
44
|
+
type: "tuple",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
name: "quoteExactInputSingle",
|
|
48
|
+
outputs: [
|
|
49
|
+
{ internalType: "uint256", name: "amountOut", type: "uint256" },
|
|
50
|
+
{ internalType: "uint256", name: "gasEstimate", type: "uint256" },
|
|
51
|
+
],
|
|
52
|
+
stateMutability: "nonpayable",
|
|
53
|
+
type: "function",
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
const ERC20_ABI = [
|
|
57
|
+
{
|
|
58
|
+
inputs: [
|
|
59
|
+
{ name: "spender", type: "address" },
|
|
60
|
+
{ name: "amount", type: "uint256" },
|
|
61
|
+
],
|
|
62
|
+
name: "approve",
|
|
63
|
+
outputs: [{ name: "", type: "bool" }],
|
|
64
|
+
stateMutability: "nonpayable",
|
|
65
|
+
type: "function",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
inputs: [
|
|
69
|
+
{ name: "owner", type: "address" },
|
|
70
|
+
{ name: "spender", type: "address" },
|
|
71
|
+
],
|
|
72
|
+
name: "allowance",
|
|
73
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
74
|
+
stateMutability: "view",
|
|
75
|
+
type: "function",
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
const PERMIT2_ABI = [
|
|
79
|
+
{
|
|
80
|
+
inputs: [
|
|
81
|
+
{ name: "token", type: "address" },
|
|
82
|
+
{ name: "spender", type: "address" },
|
|
83
|
+
{ name: "amount", type: "uint160" },
|
|
84
|
+
{ name: "expiration", type: "uint48" },
|
|
85
|
+
],
|
|
86
|
+
name: "approve",
|
|
87
|
+
outputs: [],
|
|
88
|
+
stateMutability: "nonpayable",
|
|
89
|
+
type: "function",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
inputs: [
|
|
93
|
+
{ name: "owner", type: "address" },
|
|
94
|
+
{ name: "token", type: "address" },
|
|
95
|
+
{ name: "spender", type: "address" },
|
|
96
|
+
],
|
|
97
|
+
name: "allowance",
|
|
98
|
+
outputs: [
|
|
99
|
+
{ name: "amount", type: "uint160" },
|
|
100
|
+
{ name: "expiration", type: "uint48" },
|
|
101
|
+
{ name: "nonce", type: "uint48" },
|
|
102
|
+
],
|
|
103
|
+
stateMutability: "view",
|
|
104
|
+
type: "function",
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
const TOKEN_V4_CONFIG_ABI = [
|
|
108
|
+
{
|
|
109
|
+
inputs: [],
|
|
110
|
+
name: "v4Hook",
|
|
111
|
+
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
112
|
+
stateMutability: "view",
|
|
113
|
+
type: "function",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
inputs: [],
|
|
117
|
+
name: "v4PoolFee",
|
|
118
|
+
outputs: [{ internalType: "uint24", name: "", type: "uint24" }],
|
|
119
|
+
stateMutability: "view",
|
|
120
|
+
type: "function",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
inputs: [],
|
|
124
|
+
name: "v4TickSpacing",
|
|
125
|
+
outputs: [{ internalType: "int24", name: "", type: "int24" }],
|
|
126
|
+
stateMutability: "view",
|
|
127
|
+
type: "function",
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
// Command and action constants
|
|
131
|
+
const COMMANDS = {
|
|
132
|
+
V4_SWAP: "0x10",
|
|
133
|
+
};
|
|
134
|
+
const V4_ACTIONS = {
|
|
135
|
+
SWAP_EXACT_IN_SINGLE: 6,
|
|
136
|
+
TAKE_ALL: 15,
|
|
137
|
+
SETTLE_ALL: 12,
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Internal swap service for handling Uniswap V4 swaps between trading token and bondkit token
|
|
141
|
+
*/
|
|
142
|
+
class BondkitSwapService {
|
|
143
|
+
constructor(bondkitTokenAddress) {
|
|
144
|
+
this.v4Config = null;
|
|
145
|
+
this.configInitialized = false;
|
|
146
|
+
this.bondkitTokenAddress = bondkitTokenAddress;
|
|
147
|
+
this.publicClient = (0, viem_1.createPublicClient)({
|
|
148
|
+
chain: chains_1.base,
|
|
149
|
+
transport: (0, viem_1.http)(constants_1.BaseMainnetRpcUrl),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Initialize V4 pool configuration from bondkit token contract
|
|
154
|
+
*/
|
|
155
|
+
async initializeV4Config() {
|
|
156
|
+
if (this.configInitialized) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const tokenContract = (0, viem_1.getContract)({
|
|
161
|
+
address: this.bondkitTokenAddress,
|
|
162
|
+
abi: TOKEN_V4_CONFIG_ABI,
|
|
163
|
+
client: this.publicClient,
|
|
164
|
+
});
|
|
165
|
+
const [hook, fee, tickSpacing] = await Promise.all([
|
|
166
|
+
tokenContract.read.v4Hook(),
|
|
167
|
+
tokenContract.read.v4PoolFee(),
|
|
168
|
+
tokenContract.read.v4TickSpacing(),
|
|
169
|
+
]);
|
|
170
|
+
this.v4Config = {
|
|
171
|
+
hook: hook,
|
|
172
|
+
fee: Number(fee),
|
|
173
|
+
tickSpacing: Number(tickSpacing),
|
|
174
|
+
};
|
|
175
|
+
this.configInitialized = true;
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
console.warn("Failed to initialize V4 configuration:", error);
|
|
179
|
+
// Use fallback configuration
|
|
180
|
+
this.v4Config = {
|
|
181
|
+
hook: "0xB36f4A2FB18b745ef8eD31452781a463d2B3f0cC",
|
|
182
|
+
fee: 30000,
|
|
183
|
+
tickSpacing: 60,
|
|
184
|
+
};
|
|
185
|
+
this.configInitialized = true;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get V4 pool configuration
|
|
190
|
+
*/
|
|
191
|
+
async getV4Config() {
|
|
192
|
+
await this.initializeV4Config();
|
|
193
|
+
return this.v4Config;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Handle token approvals for swap
|
|
197
|
+
*/
|
|
198
|
+
async handleTokenApprovals(tokenAddress, amountIn, walletClient, deadline) {
|
|
199
|
+
// Skip approvals for ETH
|
|
200
|
+
if (tokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const userAddress = walletClient.account?.address;
|
|
204
|
+
if (!userAddress) {
|
|
205
|
+
throw new Error("No user address found");
|
|
206
|
+
}
|
|
207
|
+
const erc20Contract = (0, viem_1.getContract)({
|
|
208
|
+
address: tokenAddress,
|
|
209
|
+
abi: ERC20_ABI,
|
|
210
|
+
client: walletClient,
|
|
211
|
+
});
|
|
212
|
+
const permit2Contract = (0, viem_1.getContract)({
|
|
213
|
+
address: constants_1.Permit2Address,
|
|
214
|
+
abi: PERMIT2_ABI,
|
|
215
|
+
client: walletClient,
|
|
216
|
+
});
|
|
217
|
+
// Check ERC20 allowance to Permit2
|
|
218
|
+
const currentAllowance = (await erc20Contract.read.allowance([userAddress, constants_1.Permit2Address]));
|
|
219
|
+
const requiredAmount = BigInt(amountIn);
|
|
220
|
+
if (currentAllowance < requiredAmount) {
|
|
221
|
+
await erc20Contract.write.approve([constants_1.Permit2Address, BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")], {
|
|
222
|
+
account: userAddress,
|
|
223
|
+
chain: chains_1.base,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
// Check Permit2 allowance for Universal Router
|
|
227
|
+
const permit2Allowance = (await permit2Contract.read.allowance([
|
|
228
|
+
userAddress,
|
|
229
|
+
tokenAddress,
|
|
230
|
+
constants_1.UniversalRouterAddress,
|
|
231
|
+
]));
|
|
232
|
+
const [currentPermit2Amount, expiration] = permit2Allowance;
|
|
233
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
234
|
+
const isExpired = expiration <= currentTime;
|
|
235
|
+
if (currentPermit2Amount < requiredAmount || isExpired) {
|
|
236
|
+
await permit2Contract.write.approve([tokenAddress, constants_1.UniversalRouterAddress, BigInt("0xffffffffffffffffffffffffffffffffffffff"), Number(deadline)], {
|
|
237
|
+
account: userAddress,
|
|
238
|
+
chain: chains_1.base,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get swap quote
|
|
244
|
+
*/
|
|
245
|
+
async getSwapQuote(params) {
|
|
246
|
+
try {
|
|
247
|
+
const { tokenIn, tokenOut, amountIn, tokenInDecimals, tokenOutDecimals, slippageTolerance } = params;
|
|
248
|
+
const v4Config = await this.getV4Config();
|
|
249
|
+
const amountInWei = (0, viem_1.parseUnits)(amountIn, tokenInDecimals);
|
|
250
|
+
// Determine token order for pool
|
|
251
|
+
const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
|
|
252
|
+
const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
|
|
253
|
+
const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
|
|
254
|
+
const poolKey = {
|
|
255
|
+
currency0: currency0,
|
|
256
|
+
currency1: currency1,
|
|
257
|
+
fee: v4Config.fee,
|
|
258
|
+
tickSpacing: v4Config.tickSpacing,
|
|
259
|
+
hooks: v4Config.hook,
|
|
260
|
+
};
|
|
261
|
+
const quoteParams = {
|
|
262
|
+
poolKey,
|
|
263
|
+
zeroForOne,
|
|
264
|
+
exactAmount: BigInt(amountInWei.toString()),
|
|
265
|
+
hookData: "0x",
|
|
266
|
+
};
|
|
267
|
+
const { result } = await this.publicClient.simulateContract({
|
|
268
|
+
address: constants_1.QuoterAddress,
|
|
269
|
+
abi: QUOTER_ABI,
|
|
270
|
+
functionName: "quoteExactInputSingle",
|
|
271
|
+
args: [quoteParams],
|
|
272
|
+
});
|
|
273
|
+
const [amountOut] = result;
|
|
274
|
+
const amountOutRaw = (0, viem_1.formatUnits)(amountOut, tokenOutDecimals);
|
|
275
|
+
const amountOutFormatted = parseFloat(amountOutRaw).toFixed(Math.min(6, tokenOutDecimals));
|
|
276
|
+
// Calculate minimum amount out with slippage
|
|
277
|
+
const slippageMultiplier = (100 - slippageTolerance) / 100;
|
|
278
|
+
const amountOutMinRaw = parseFloat(amountOutFormatted) * slippageMultiplier;
|
|
279
|
+
const amountOutMin = amountOutMinRaw.toFixed(tokenOutDecimals);
|
|
280
|
+
// Simple execution price calculation
|
|
281
|
+
const rate = parseFloat(amountOutFormatted) / parseFloat(amountIn);
|
|
282
|
+
const executionPrice = `1 = ${rate.toFixed(6)}`;
|
|
283
|
+
return {
|
|
284
|
+
amountOut: amountOutFormatted,
|
|
285
|
+
amountOutMin,
|
|
286
|
+
priceImpact: "0.0", // Simplified
|
|
287
|
+
executionPrice,
|
|
288
|
+
fee: (v4Config.fee / 10000).toString(),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
console.warn("Error getting swap quote:", error);
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Execute swap transaction
|
|
298
|
+
*/
|
|
299
|
+
async executeSwap(params, walletClient) {
|
|
300
|
+
try {
|
|
301
|
+
const { tokenIn, tokenOut, amountIn, tokenInDecimals, tokenOutDecimals, deadline } = params;
|
|
302
|
+
const swapDeadline = deadline || Math.floor(Date.now() / 1000) + 3600;
|
|
303
|
+
if (!walletClient.account) {
|
|
304
|
+
throw new Error("Wallet client must have an account");
|
|
305
|
+
}
|
|
306
|
+
const amountInWei = (0, viem_1.parseUnits)(amountIn, tokenInDecimals);
|
|
307
|
+
// Handle token approvals
|
|
308
|
+
await this.handleTokenApprovals(tokenIn, amountInWei.toString(), walletClient, swapDeadline);
|
|
309
|
+
// Get quote for minimum amount out
|
|
310
|
+
const quote = await this.getSwapQuote(params);
|
|
311
|
+
if (!quote) {
|
|
312
|
+
throw new Error("Unable to get swap quote");
|
|
313
|
+
}
|
|
314
|
+
const amountOutMinimum = (0, viem_1.parseUnits)(quote.amountOutMin, tokenOutDecimals);
|
|
315
|
+
const v4Config = await this.getV4Config();
|
|
316
|
+
// Determine token order
|
|
317
|
+
const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
|
|
318
|
+
const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
|
|
319
|
+
const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
|
|
320
|
+
const poolKey = [currency0, currency1, v4Config.fee, v4Config.tickSpacing, v4Config.hook];
|
|
321
|
+
// Encode V4 actions
|
|
322
|
+
const actions = [
|
|
323
|
+
{
|
|
324
|
+
type: V4_ACTIONS.SWAP_EXACT_IN_SINGLE,
|
|
325
|
+
params: [poolKey, zeroForOne, amountInWei, amountOutMinimum, "0x"],
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
type: V4_ACTIONS.TAKE_ALL,
|
|
329
|
+
params: [(zeroForOne ? currency1 : currency0), BigInt(0)],
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
type: V4_ACTIONS.SETTLE_ALL,
|
|
333
|
+
params: [(zeroForOne ? currency0 : currency1), amountInWei],
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
// Encode actions
|
|
337
|
+
const actionTypes = actions.map(action => action.type);
|
|
338
|
+
const actionsBytes = ("0x" + actionTypes.map(type => type.toString(16).padStart(2, "0")).join(""));
|
|
339
|
+
const actionParams = actions.map(action => {
|
|
340
|
+
switch (action.type) {
|
|
341
|
+
case V4_ACTIONS.SWAP_EXACT_IN_SINGLE:
|
|
342
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)("((address,address,uint24,int24,address),bool,uint128,uint128,bytes)"), [action.params]);
|
|
343
|
+
case V4_ACTIONS.TAKE_ALL:
|
|
344
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)("address,uint256"), action.params);
|
|
345
|
+
case V4_ACTIONS.SETTLE_ALL:
|
|
346
|
+
return (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)("address,uint256"), action.params);
|
|
347
|
+
default:
|
|
348
|
+
return "0x00";
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
const v4SwapInput = (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)("bytes,bytes[]"), [actionsBytes, actionParams]);
|
|
352
|
+
const commands = COMMANDS.V4_SWAP;
|
|
353
|
+
const inputs = [v4SwapInput];
|
|
354
|
+
// Execute swap
|
|
355
|
+
const universalRouter = (0, viem_1.getContract)({
|
|
356
|
+
address: constants_1.UniversalRouterAddress,
|
|
357
|
+
abi: UNIVERSAL_ROUTER_ABI,
|
|
358
|
+
client: walletClient,
|
|
359
|
+
});
|
|
360
|
+
const txHash = await universalRouter.write.execute([commands, inputs, BigInt(swapDeadline)], {
|
|
361
|
+
account: walletClient.account,
|
|
362
|
+
chain: chains_1.base,
|
|
363
|
+
value: tokenIn === "0x0000000000000000000000000000000000000000" ? amountInWei : BigInt(0),
|
|
364
|
+
});
|
|
365
|
+
return txHash;
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
console.warn("Error executing swap:", error);
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
exports.BondkitSwapService = BondkitSwapService;
|
|
@@ -49,10 +49,9 @@ export type DexMigrationEventArgs = {
|
|
|
49
49
|
ethForFeeRecipient: bigint;
|
|
50
50
|
};
|
|
51
51
|
export declare enum TokenStatus {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Migrated = 3
|
|
52
|
+
Uninitialized = 0,
|
|
53
|
+
Bonding = 1,
|
|
54
|
+
Dex = 2
|
|
56
55
|
}
|
|
57
56
|
export interface GetTransactionHistoryOptions {
|
|
58
57
|
userAddress?: Address;
|
|
@@ -80,3 +79,10 @@ export interface TransactionResponse {
|
|
|
80
79
|
skip: number;
|
|
81
80
|
data: Transaction[];
|
|
82
81
|
}
|
|
82
|
+
export interface SwapQuote {
|
|
83
|
+
amountOut: string;
|
|
84
|
+
amountOutMin: string;
|
|
85
|
+
priceImpact: string;
|
|
86
|
+
executionPrice: string;
|
|
87
|
+
fee: string;
|
|
88
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenStatus = void 0;
|
|
4
|
-
// Enum for Status (
|
|
4
|
+
// Enum for Status (matches contract Status enum exactly)
|
|
5
5
|
var TokenStatus;
|
|
6
6
|
(function (TokenStatus) {
|
|
7
|
-
TokenStatus[TokenStatus["
|
|
8
|
-
TokenStatus[TokenStatus["
|
|
9
|
-
TokenStatus[TokenStatus["
|
|
10
|
-
TokenStatus[TokenStatus["Migrated"] = 3] = "Migrated";
|
|
7
|
+
TokenStatus[TokenStatus["Uninitialized"] = 0] = "Uninitialized";
|
|
8
|
+
TokenStatus[TokenStatus["Bonding"] = 1] = "Bonding";
|
|
9
|
+
TokenStatus[TokenStatus["Dex"] = 2] = "Dex";
|
|
11
10
|
})(TokenStatus || (exports.TokenStatus = TokenStatus = {}));
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
2
|
+
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
2
3
|
import { Account } from "thirdweb/wallets";
|
|
3
4
|
import { ClientType } from "../../../client-manager";
|
|
4
5
|
import { B3ContextType } from "./types";
|
|
5
|
-
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
6
|
-
export declare const wagmiConfig: import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], any, readonly import("wagmi").CreateConnectorFn[]>;
|
|
7
6
|
/**
|
|
8
7
|
* Main B3Provider component
|
|
9
8
|
*/
|
|
10
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, }: {
|
|
9
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, }: {
|
|
11
10
|
theme: "light" | "dark";
|
|
12
11
|
children: React.ReactNode;
|
|
13
12
|
accountOverride?: Account;
|
|
@@ -19,6 +18,8 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
19
18
|
style?: React.CSSProperties;
|
|
20
19
|
};
|
|
21
20
|
clientType?: ClientType;
|
|
21
|
+
rpcUrls?: Record<number, string>;
|
|
22
|
+
partnerId?: string;
|
|
22
23
|
}): import("react/jsx-runtime").JSX.Element;
|
|
23
24
|
/**
|
|
24
25
|
* Inner provider component that provides the actual B3Context
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wagmiConfig = void 0;
|
|
4
3
|
exports.B3Provider = B3Provider;
|
|
5
4
|
exports.InnerProvider = InnerProvider;
|
|
6
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
6
|
const react_1 = require("../../../../global-account/react");
|
|
8
7
|
const analytics_1 = require("../../../../global-account/utils/analytics");
|
|
8
|
+
const constants_1 = require("../../../../shared/constants");
|
|
9
9
|
const supported_1 = require("../../../../shared/constants/chains/supported");
|
|
10
|
+
const debug_1 = require("../../../../shared/utils/debug");
|
|
11
|
+
const thirdweb_1 = require("../../../../shared/utils/thirdweb");
|
|
12
|
+
require("@reservoir0x/relay-kit-ui/styles.css");
|
|
10
13
|
const react_query_1 = require("@tanstack/react-query");
|
|
14
|
+
const wagmi_adapter_1 = require("@thirdweb-dev/wagmi-adapter");
|
|
11
15
|
const react_2 = require("react");
|
|
12
16
|
const sonner_1 = require("sonner");
|
|
13
17
|
const react_3 = require("thirdweb/react");
|
|
@@ -15,7 +19,7 @@ const wagmi_1 = require("wagmi");
|
|
|
15
19
|
const client_manager_1 = require("../../../client-manager");
|
|
16
20
|
const StyleRoot_1 = require("../StyleRoot");
|
|
17
21
|
const types_1 = require("./types");
|
|
18
|
-
|
|
22
|
+
const debug = (0, debug_1.debugB3React)("B3Provider");
|
|
19
23
|
/**
|
|
20
24
|
* Default permissions configuration for B3 provider
|
|
21
25
|
*/
|
|
@@ -25,16 +29,12 @@ const DEFAULT_PERMISSIONS = {
|
|
|
25
29
|
startDate: new Date(),
|
|
26
30
|
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
|
|
27
31
|
};
|
|
28
|
-
exports.wagmiConfig = (0, wagmi_1.createConfig)({
|
|
29
|
-
chains: [supported_1.supportedChains[0], ...supported_1.supportedChains.slice(1)],
|
|
30
|
-
transports: Object.fromEntries(supported_1.supportedChains.map(chain => [chain.id, (0, wagmi_1.http)()])),
|
|
31
|
-
});
|
|
32
32
|
// Create queryClient instance
|
|
33
33
|
const queryClient = new react_query_1.QueryClient();
|
|
34
34
|
/**
|
|
35
35
|
* Main B3Provider component
|
|
36
36
|
*/
|
|
37
|
-
function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", }) {
|
|
37
|
+
function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", rpcUrls, partnerId, }) {
|
|
38
38
|
// Initialize Google Analytics on mount
|
|
39
39
|
(0, react_2.useEffect)(() => {
|
|
40
40
|
(0, analytics_1.loadGA4Script)();
|
|
@@ -43,7 +43,32 @@ function B3Provider({ theme = "light", children, accountOverride, environment, a
|
|
|
43
43
|
(0, react_2.useEffect)(() => {
|
|
44
44
|
(0, client_manager_1.setClientType)(clientType);
|
|
45
45
|
}, [clientType]);
|
|
46
|
-
|
|
46
|
+
const ecocystemConfig = (0, react_2.useMemo)(() => {
|
|
47
|
+
if (!partnerId)
|
|
48
|
+
return undefined;
|
|
49
|
+
return {
|
|
50
|
+
ecosystemId: constants_1.ecosystemWalletId,
|
|
51
|
+
partnerId: partnerId,
|
|
52
|
+
client: thirdweb_1.client,
|
|
53
|
+
};
|
|
54
|
+
}, [partnerId]);
|
|
55
|
+
/**
|
|
56
|
+
* Creates wagmi config with optional custom RPC URLs
|
|
57
|
+
* @param rpcUrls - Optional mapping of chain IDs to RPC URLs
|
|
58
|
+
*/
|
|
59
|
+
const wagmiConfig = (0, react_2.useMemo)(() => (0, wagmi_1.createConfig)({
|
|
60
|
+
chains: [supported_1.supportedChains[0], ...supported_1.supportedChains.slice(1)],
|
|
61
|
+
transports: Object.fromEntries(supported_1.supportedChains.map(chain => [chain.id, (0, wagmi_1.http)(rpcUrls?.[chain.id])])),
|
|
62
|
+
connectors: [
|
|
63
|
+
(0, wagmi_adapter_1.inAppWalletConnector)({
|
|
64
|
+
...(ecocystemConfig || {}),
|
|
65
|
+
client: thirdweb_1.client,
|
|
66
|
+
}),
|
|
67
|
+
// injected(),
|
|
68
|
+
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
69
|
+
],
|
|
70
|
+
}), [partnerId]);
|
|
71
|
+
return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, children: (0, jsx_runtime_1.jsxs)(react_1.RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, (0, jsx_runtime_1.jsx)(StyleRoot_1.StyleRoot, { id: "b3-root" }), (0, jsx_runtime_1.jsx)(sonner_1.Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
|
|
47
72
|
}
|
|
48
73
|
/**
|
|
49
74
|
* Inner provider component that provides the actual B3Context
|
|
@@ -54,6 +79,7 @@ function InnerProvider({ children, accountOverride, environment, defaultPermissi
|
|
|
54
79
|
const wallets = (0, react_3.useConnectedWallets)();
|
|
55
80
|
const setActiveWallet = (0, react_3.useSetActiveWallet)();
|
|
56
81
|
const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
|
|
82
|
+
debug("@@wallets", wallets);
|
|
57
83
|
const [user, setUser] = (0, react_2.useState)(() => {
|
|
58
84
|
// Try to restore user from localStorage on initialization
|
|
59
85
|
if (typeof window !== "undefined") {
|
|
@@ -84,7 +110,7 @@ function InnerProvider({ children, accountOverride, environment, defaultPermissi
|
|
|
84
110
|
const setWallet = (0, react_2.useCallback)((wallet) => {
|
|
85
111
|
setManuallySelectedWallet(wallet);
|
|
86
112
|
const account = wallet.getAccount();
|
|
87
|
-
|
|
113
|
+
debug("@@setWallet", wallet.id, account?.address);
|
|
88
114
|
setActiveWallet(wallet);
|
|
89
115
|
}, [setManuallySelectedWallet, setActiveWallet]);
|
|
90
116
|
(0, react_2.useEffect)(() => {
|
|
@@ -7,12 +7,14 @@ exports.LinkAccount = LinkAccount;
|
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
const app_1 = __importDefault(require("../../../../global-account/app"));
|
|
9
9
|
const constants_1 = require("../../../../shared/constants");
|
|
10
|
+
const b3Chain_1 = require("../../../../shared/constants/chains/b3Chain");
|
|
10
11
|
const thirdweb_1 = require("../../../../shared/utils/thirdweb");
|
|
11
12
|
const lucide_react_1 = require("lucide-react");
|
|
12
13
|
const react_1 = require("react");
|
|
13
14
|
const sonner_1 = require("sonner");
|
|
14
15
|
const react_2 = require("thirdweb/react");
|
|
15
16
|
const wallets_1 = require("thirdweb/wallets");
|
|
17
|
+
const __1 = require("../..");
|
|
16
18
|
const useModalStore_1 = require("../../stores/useModalStore");
|
|
17
19
|
const profileDisplay_1 = require("../../utils/profileDisplay");
|
|
18
20
|
const useB3_1 = require("../B3Provider/useB3");
|
|
@@ -36,6 +38,38 @@ const AUTH_METHODS = [
|
|
|
36
38
|
icon: (0, jsx_runtime_1.jsx)(FarcasterIcon_1.FarcasterIcon, { className: "size-6" }),
|
|
37
39
|
},
|
|
38
40
|
];
|
|
41
|
+
const WALLET_METHODS = [
|
|
42
|
+
{
|
|
43
|
+
id: "wallet",
|
|
44
|
+
label: "Wallet",
|
|
45
|
+
enabled: true,
|
|
46
|
+
icon: (0, jsx_runtime_1.jsx)(lucide_react_1.WalletIcon, { className: "size-6" }),
|
|
47
|
+
walletType: "com.coinbase.wallet",
|
|
48
|
+
},
|
|
49
|
+
{ id: "wallet", label: "Wallet", enabled: true, icon: (0, jsx_runtime_1.jsx)(lucide_react_1.WalletIcon, { className: "size-6" }), walletType: "io.metamask" },
|
|
50
|
+
{
|
|
51
|
+
id: "wallet",
|
|
52
|
+
label: "Wallet",
|
|
53
|
+
enabled: true,
|
|
54
|
+
icon: (0, jsx_runtime_1.jsx)(lucide_react_1.WalletIcon, { className: "size-6" }),
|
|
55
|
+
walletType: "me.rainbow",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "wallet",
|
|
59
|
+
label: "Wallet",
|
|
60
|
+
enabled: true,
|
|
61
|
+
icon: (0, jsx_runtime_1.jsx)(lucide_react_1.WalletIcon, { className: "size-6" }),
|
|
62
|
+
walletType: "app.phantom",
|
|
63
|
+
},
|
|
64
|
+
{ id: "wallet", label: "Wallet", enabled: true, icon: (0, jsx_runtime_1.jsx)(lucide_react_1.WalletIcon, { className: "size-6" }), walletType: "io.rabby" },
|
|
65
|
+
{
|
|
66
|
+
id: "wallet",
|
|
67
|
+
label: "Wallet",
|
|
68
|
+
enabled: true,
|
|
69
|
+
icon: (0, jsx_runtime_1.jsx)(lucide_react_1.WalletIcon, { className: "size-6" }),
|
|
70
|
+
walletType: "walletConnect",
|
|
71
|
+
},
|
|
72
|
+
];
|
|
39
73
|
function LinkAccount({ onSuccess: onSuccessCallback, onError, onClose, chain, partnerId, className, }) {
|
|
40
74
|
const { isLinking, linkingMethod, setLinkingState, navigateBack, setB3ModalContentType } = (0, useModalStore_1.useModalStore)();
|
|
41
75
|
const [selectedMethod, setSelectedMethod] = (0, react_1.useState)(null);
|
|
@@ -47,12 +81,12 @@ function LinkAccount({ onSuccess: onSuccessCallback, onError, onClose, chain, pa
|
|
|
47
81
|
const { data: profilesRaw = [] } = (0, react_2.useProfiles)({ client: thirdweb_1.client });
|
|
48
82
|
// Get connected auth methods
|
|
49
83
|
const connectedAuthMethods = profilesRaw
|
|
50
|
-
.filter((profile) => !["custom_auth_endpoint"
|
|
84
|
+
.filter((profile) => !["custom_auth_endpoint"].includes(profile.type))
|
|
51
85
|
.map((profile) => profile.type);
|
|
52
86
|
// Filter available auth methods
|
|
53
87
|
const availableAuthMethods = AUTH_METHODS.filter(method => !connectedAuthMethods.includes(method.id) && method.enabled);
|
|
54
88
|
const profiles = profilesRaw
|
|
55
|
-
.filter((profile) => !["custom_auth_endpoint"
|
|
89
|
+
.filter((profile) => !["custom_auth_endpoint"].includes(profile.type))
|
|
56
90
|
.map((profile) => ({
|
|
57
91
|
...(0, profileDisplay_1.getProfileDisplayInfo)(profile),
|
|
58
92
|
originalProfile: profile,
|
|
@@ -182,6 +216,26 @@ function LinkAccount({ onSuccess: onSuccessCallback, onError, onClose, chain, pa
|
|
|
182
216
|
onError?.(error);
|
|
183
217
|
}
|
|
184
218
|
};
|
|
219
|
+
const handleLinkWallet = async (walletType) => {
|
|
220
|
+
setLinkingState(true, "wallet");
|
|
221
|
+
console.log("selectedMethod", walletType);
|
|
222
|
+
try {
|
|
223
|
+
if (!walletType) {
|
|
224
|
+
throw new Error("Wallet type not found");
|
|
225
|
+
}
|
|
226
|
+
await linkProfile({
|
|
227
|
+
client: thirdweb_1.client,
|
|
228
|
+
strategy: "wallet",
|
|
229
|
+
wallet: (0, wallets_1.createWallet)(walletType),
|
|
230
|
+
chain: b3Chain_1.thirdwebB3Mainnet,
|
|
231
|
+
}, mutationOptions);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
console.error("Error linking account:", error);
|
|
235
|
+
setError(error instanceof Error ? error.message : "Failed to link account");
|
|
236
|
+
onError?.(error);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
185
239
|
const handleSocialLink = async (strategy) => {
|
|
186
240
|
try {
|
|
187
241
|
console.log("handleSocialLink", strategy);
|
|
@@ -262,5 +316,11 @@ function LinkAccount({ onSuccess: onSuccessCallback, onError, onClose, chain, pa
|
|
|
262
316
|
else {
|
|
263
317
|
handleSocialLink(method.id);
|
|
264
318
|
}
|
|
265
|
-
}, disabled: linkingMethod === method.id, children: isLinking && linkingMethod === method.id ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-5 w-5 animate-spin" })) : ((0, jsx_runtime_1.jsxs)("div", { className: "b3-link-account-method-content flex items-center gap-4", children: [(0, jsx_runtime_1.jsx)("div", { className: "b3-link-account-method-icon flex items-center justify-center rounded-full", children: method.icon }), (0, jsx_runtime_1.jsx)("span", { className: "b3-link-account-method-label font-medium", children: method.label })] })) }, method.id))),
|
|
319
|
+
}, disabled: linkingMethod === method.id, children: isLinking && linkingMethod === method.id ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-5 w-5 animate-spin" })) : ((0, jsx_runtime_1.jsxs)("div", { className: "b3-link-account-method-content flex items-center gap-4", children: [(0, jsx_runtime_1.jsx)("div", { className: "b3-link-account-method-icon flex items-center justify-center rounded-full", children: method.icon }), (0, jsx_runtime_1.jsx)("span", { className: "b3-link-account-method-label font-medium", children: method.label })] })) }, method.id))), WALLET_METHODS.map(method => {
|
|
320
|
+
if (!method.walletType) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
return ((0, jsx_runtime_1.jsx)(__1.WalletRow, { walletId: method.walletType, onClick: () => handleLinkWallet(method.walletType), isLoading: isLinking }, method.walletType));
|
|
324
|
+
}), availableAuthMethods.length === 0 && ((0, jsx_runtime_1.jsx)("div", { className: "text-b3-foreground-muted py-8 text-center", children: "All available authentication methods have been connected" }))] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "b3-link-account-form space-y-4", children: [selectedMethod === "email" && ((0, jsx_runtime_1.jsxs)("div", { className: "space-y-2", children: [(0, jsx_runtime_1.jsx)("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Email Address" }), (0, jsx_runtime_1.jsx)("input", { type: "email", placeholder: "Enter your email", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: email, onChange: e => setEmail(e.target.value), disabled: otpSent || (isLinking && linkingMethod === "email") })] })), selectedMethod === "phone" && ((0, jsx_runtime_1.jsxs)("div", { className: "space-y-2", children: [(0, jsx_runtime_1.jsx)("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Phone Number" }), (0, jsx_runtime_1.jsx)("input", { type: "tel", placeholder: "Enter your phone number", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: phone, onChange: e => setPhone(e.target.value), disabled: otpSent || (isLinking && linkingMethod === "phone") }), (0, jsx_runtime_1.jsx)("p", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Include country code (e.g., +1 for US)" })] })), error && (0, jsx_runtime_1.jsx)("div", { className: "text-b3-negative font-neue-montreal-medium py-2 text-sm", children: error }), (selectedMethod === "email" || selectedMethod === "phone") &&
|
|
325
|
+
(otpSent ? ((0, jsx_runtime_1.jsxs)("div", { className: "space-y-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "space-y-2", children: [(0, jsx_runtime_1.jsx)("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Verification Code" }), (0, jsx_runtime_1.jsx)("input", { type: "text", placeholder: "Enter verification code", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: otp, onChange: e => setOtp(e.target.value) })] }), (0, jsx_runtime_1.jsx)(button_1.Button, { className: "bg-b3-primary-blue hover:bg-b3-primary-blue/90 font-neue-montreal-semibold h-12 w-full text-white", onClick: handleLinkAccount, children: "Link Account" })] })) : ((0, jsx_runtime_1.jsx)(button_1.Button, { className: "bg-b3-primary-blue hover:bg-b3-primary-blue/90 font-neue-montreal-semibold h-12 w-full text-white", onClick: handleSendOTP, disabled: (!email && !phone) || (isLinking && linkingMethod === selectedMethod), children: isLinking && linkingMethod === selectedMethod ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "animate-spin" })) : ("Send Verification Code") })))] }))] }));
|
|
266
326
|
}
|