@b3dotfun/sdk 0.0.40-alpha.4 → 0.0.40-alpha.6

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.
Files changed (38) hide show
  1. package/dist/cjs/bondkit/bondkitToken.d.ts +36 -1
  2. package/dist/cjs/bondkit/bondkitToken.js +266 -0
  3. package/dist/cjs/bondkit/constants.d.ts +4 -0
  4. package/dist/cjs/bondkit/constants.js +6 -1
  5. package/dist/cjs/bondkit/index.d.ts +1 -0
  6. package/dist/cjs/bondkit/index.js +4 -1
  7. package/dist/cjs/bondkit/swapService.d.ts +43 -0
  8. package/dist/cjs/bondkit/swapService.js +373 -0
  9. package/dist/cjs/bondkit/types.d.ts +10 -4
  10. package/dist/cjs/bondkit/types.js +4 -5
  11. package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +63 -3
  12. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
  13. package/dist/esm/bondkit/bondkitToken.d.ts +36 -1
  14. package/dist/esm/bondkit/bondkitToken.js +266 -0
  15. package/dist/esm/bondkit/constants.d.ts +4 -0
  16. package/dist/esm/bondkit/constants.js +5 -0
  17. package/dist/esm/bondkit/index.d.ts +1 -0
  18. package/dist/esm/bondkit/index.js +2 -0
  19. package/dist/esm/bondkit/swapService.d.ts +43 -0
  20. package/dist/esm/bondkit/swapService.js +369 -0
  21. package/dist/esm/bondkit/types.d.ts +10 -4
  22. package/dist/esm/bondkit/types.js +4 -5
  23. package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +65 -5
  24. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
  25. package/dist/styles/index.css +1 -1
  26. package/dist/types/bondkit/bondkitToken.d.ts +36 -1
  27. package/dist/types/bondkit/constants.d.ts +4 -0
  28. package/dist/types/bondkit/index.d.ts +1 -0
  29. package/dist/types/bondkit/swapService.d.ts +43 -0
  30. package/dist/types/bondkit/types.d.ts +10 -4
  31. package/package.json +1 -1
  32. package/src/bondkit/bondkitToken.ts +321 -1
  33. package/src/bondkit/constants.ts +7 -0
  34. package/src/bondkit/index.ts +3 -0
  35. package/src/bondkit/swapService.ts +461 -0
  36. package/src/bondkit/types.ts +12 -5
  37. package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +106 -32
  38. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +60 -5
@@ -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
- Inactive = 0,// Assuming mapping from ABI, verify actual enum values if specified elsewhere
53
- BondingPhase = 1,
54
- DexPhase = 2,
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 (used in BondkitToken ABI)
4
+ // Enum for Status (matches contract Status enum exactly)
5
5
  var TokenStatus;
6
6
  (function (TokenStatus) {
7
- TokenStatus[TokenStatus["Inactive"] = 0] = "Inactive";
8
- TokenStatus[TokenStatus["BondingPhase"] = 1] = "BondingPhase";
9
- TokenStatus[TokenStatus["DexPhase"] = 2] = "DexPhase";
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 = {}));
@@ -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", "siwe"].includes(profile.type))
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", "siwe"].includes(profile.type))
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))), 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 }), 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") }))] }))] }));
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
  }
@@ -10,6 +10,7 @@ const react_1 = require("../../../../global-account/react");
10
10
  const SignOutIcon_1 = require("../../../../global-account/react/components/icons/SignOutIcon");
11
11
  const formatNumber_1 = require("../../../../shared/utils/formatNumber");
12
12
  const thirdweb_1 = require("../../../../shared/utils/thirdweb");
13
+ const truncateAddress_1 = require("../../../../shared/utils/truncateAddress");
13
14
  const lucide_react_1 = require("lucide-react");
14
15
  const react_2 = require("react");
15
16
  const sonner_1 = require("sonner");
@@ -18,6 +19,21 @@ const viem_1 = require("viem");
18
19
  const profileDisplay_1 = require("../../utils/profileDisplay");
19
20
  const AccountAssets_1 = require("../AccountAssets/AccountAssets");
20
21
  const ContentTokens_1 = require("./ContentTokens");
22
+ // Helper function to check if a string is a wallet address and format it
23
+ const formatProfileTitle = (title) => {
24
+ // Check if title looks like an Ethereum address (0x followed by 40 hex characters)
25
+ const isEthereumAddress = /^0x[a-fA-F0-9]{40}$/.test(title);
26
+ if (isEthereumAddress) {
27
+ return {
28
+ displayTitle: (0, truncateAddress_1.truncateAddress)(title),
29
+ isAddress: true,
30
+ };
31
+ }
32
+ return {
33
+ displayTitle: title,
34
+ isAddress: false,
35
+ };
36
+ };
21
37
  const BalanceContent_1 = require("./BalanceContent");
22
38
  function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit, chain, partnerId, showSwap, showDeposit, }) {
23
39
  const [revokingSignerId, setRevokingSignerId] = (0, react_2.useState)(null);
@@ -117,7 +133,7 @@ function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit, chain
117
133
  }
118
134
  };
119
135
  const profiles = profilesRaw
120
- .filter((profile) => !["custom_auth_endpoint", "siwe"].includes(profile.type))
136
+ .filter((profile) => !["custom_auth_endpoint"].includes(profile.type))
121
137
  .map((profile) => ({
122
138
  ...(0, profileDisplay_1.getProfileDisplayInfo)(profile),
123
139
  originalProfile: profile,
@@ -152,7 +168,24 @@ function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit, chain
152
168
  },
153
169
  });
154
170
  };
155
- return ((0, jsx_runtime_1.jsxs)("div", { className: "linked-accounts-settings space-y-8", children: [(0, jsx_runtime_1.jsxs)("div", { className: "linked-accounts-section space-y-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "linked-accounts-header flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("h3", { className: "text-b3-grey font-neue-montreal-semibold linked-accounts-settings-title text-xl", children: "Linked Accounts" }), (0, jsx_runtime_1.jsxs)(react_1.Button, { className: "linked-accounts-settings-button linked-accounts-link-button bg-b3-primary-wash hover:bg-b3-primary-wash/70 flex items-center gap-2 rounded-full px-4 py-2", onClick: handleOpenLinkModal, disabled: isLinking, children: [isLinking ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "linked-accounts-link-loading text-b3-primary-blue animate-spin", size: 16 })) : ((0, jsx_runtime_1.jsx)(lucide_react_1.LinkIcon, { size: 16, className: "linked-accounts-link-icon text-b3-primary-blue" })), (0, jsx_runtime_1.jsx)("span", { className: "linked-accounts-link-text text-b3-grey font-neue-montreal-semibold", children: isLinking ? "Linking..." : "Link New Account" })] })] }), isLoadingProfiles ? ((0, jsx_runtime_1.jsx)("div", { className: "linked-accounts-loading flex justify-center py-8", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "text-b3-grey animate-spin" }) })) : profiles.length > 0 ? ((0, jsx_runtime_1.jsx)("div", { className: "linked-accounts-list space-y-4", children: profiles.map(profile => ((0, jsx_runtime_1.jsxs)("div", { className: "linked-account-item bg-b3-line flex items-center justify-between rounded-xl p-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "linked-account-info flex items-center gap-3", children: [profile.imageUrl ? ((0, jsx_runtime_1.jsx)("img", { src: profile.imageUrl, alt: profile.title, className: "linked-account-avatar linked-account-avatar-image size-10 rounded-full" })) : ((0, jsx_runtime_1.jsx)("div", { className: "linked-account-avatar linked-account-avatar-placeholder bg-b3-primary-wash flex h-10 w-10 items-center justify-center rounded-full", children: (0, jsx_runtime_1.jsx)("span", { className: "linked-account-initial text-b3-grey font-neue-montreal-semibold text-sm uppercase", children: profile.initial }) })), (0, jsx_runtime_1.jsxs)("div", { className: "linked-account-details", children: [(0, jsx_runtime_1.jsxs)("div", { className: "linked-account-title-row flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "linked-account-title text-b3-grey font-neue-montreal-semibold", children: profile.title }), (0, jsx_runtime_1.jsx)("span", { className: "linked-account-type text-b3-foreground-muted font-neue-montreal-medium bg-b3-primary-wash rounded px-2 py-0.5 text-xs", children: profile.type.toUpperCase() })] }), (0, jsx_runtime_1.jsx)("div", { className: "linked-account-subtitle text-b3-foreground-muted font-neue-montreal-medium text-sm", children: profile.subtitle })] })] }), (0, jsx_runtime_1.jsx)(react_1.Button, { variant: "ghost", size: "icon", className: "linked-account-unlink-button text-b3-grey hover:text-b3-negative", onClick: () => handleUnlink(profile), disabled: unlinkingAccountId === profile.title || isUnlinking, children: unlinkingAccountId === profile.title || isUnlinking ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "linked-account-unlink-loading animate-spin" })) : ((0, jsx_runtime_1.jsx)(lucide_react_1.UnlinkIcon, { size: 16, className: "linked-account-unlink-icon" })) })] }, profile.title))) })) : ((0, jsx_runtime_1.jsx)("div", { className: "linked-accounts-empty text-b3-foreground-muted py-8 text-center", children: "No linked accounts found" }))] }), showReferralInfo && (
171
+ console.log("@@profiles", profiles);
172
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "linked-accounts-settings space-y-8", children: [(0, jsx_runtime_1.jsxs)("div", { className: "linked-accounts-section space-y-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "linked-accounts-header flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("h3", { className: "text-b3-grey font-neue-montreal-semibold linked-accounts-settings-title text-xl", children: "Linked Accounts" }), (0, jsx_runtime_1.jsxs)(react_1.Button, { className: "linked-accounts-settings-button linked-accounts-link-button bg-b3-primary-wash hover:bg-b3-primary-wash/70 flex items-center gap-2 rounded-full px-4 py-2", onClick: handleOpenLinkModal, disabled: isLinking, children: [isLinking ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "linked-accounts-link-loading text-b3-primary-blue animate-spin", size: 16 })) : ((0, jsx_runtime_1.jsx)(lucide_react_1.LinkIcon, { size: 16, className: "linked-accounts-link-icon text-b3-primary-blue" })), (0, jsx_runtime_1.jsx)("span", { className: "linked-accounts-link-text text-b3-grey font-neue-montreal-semibold", children: isLinking ? "Linking..." : "Link New Account" })] })] }), isLoadingProfiles ? ((0, jsx_runtime_1.jsx)("div", { className: "linked-accounts-loading flex justify-center py-8", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "text-b3-grey animate-spin" }) })) : profiles.length > 0 ? ((0, jsx_runtime_1.jsx)("div", { className: "linked-accounts-list space-y-4", children: profiles.map(profile => ((0, jsx_runtime_1.jsxs)("div", { className: "linked-account-item bg-b3-line group flex items-center justify-between rounded-xl p-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "linked-account-info flex items-center gap-3", children: [profile.imageUrl ? ((0, jsx_runtime_1.jsx)("img", { src: profile.imageUrl, alt: profile.title, className: "linked-account-avatar linked-account-avatar-image size-10 rounded-full" })) : ((0, jsx_runtime_1.jsx)("div", { className: "linked-account-avatar linked-account-avatar-placeholder bg-b3-primary-wash flex h-10 w-10 items-center justify-center rounded-full", children: (0, jsx_runtime_1.jsx)("span", { className: "linked-account-initial text-b3-grey font-neue-montreal-semibold text-sm uppercase", children: profile.initial }) })), (0, jsx_runtime_1.jsxs)("div", { className: "linked-account-details", children: [(0, jsx_runtime_1.jsxs)("div", { className: "linked-account-title-row flex items-center gap-2", children: [(() => {
173
+ const { displayTitle, isAddress } = formatProfileTitle(profile.title);
174
+ const handleCopyAddress = async (e) => {
175
+ e.stopPropagation();
176
+ try {
177
+ await navigator.clipboard.writeText(profile.title);
178
+ sonner_1.toast.success("Address copied to clipboard!");
179
+ }
180
+ catch (error) {
181
+ sonner_1.toast.error("Failed to copy address");
182
+ }
183
+ };
184
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-1", children: [(0, jsx_runtime_1.jsx)("span", { className: `linked-account-title text-b3-grey font-neue-montreal-semibold ${isAddress
185
+ ? "font-mono text-sm" // Use monospace font for addresses
186
+ : "break-words" // Use break-words for emails/names (better than break-all)
187
+ }`, title: isAddress ? profile.title : undefined, children: displayTitle }), isAddress && ((0, jsx_runtime_1.jsx)("button", { onClick: handleCopyAddress, className: "linked-account-copy-button ml-1 rounded p-1 opacity-0 transition-opacity hover:bg-gray-100 group-hover:opacity-100", title: "Copy full address", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Copy, { size: 12, className: "text-gray-500 hover:text-gray-700" }) }))] }));
188
+ })(), (0, jsx_runtime_1.jsx)("span", { className: "linked-account-type text-b3-foreground-muted font-neue-montreal-medium bg-b3-primary-wash rounded px-2 py-0.5 text-xs", children: profile.type.toUpperCase() })] }), (0, jsx_runtime_1.jsx)("div", { className: "linked-account-subtitle text-b3-foreground-muted font-neue-montreal-medium text-sm", children: profile.subtitle })] })] }), (0, jsx_runtime_1.jsx)(react_1.Button, { variant: "ghost", size: "icon", className: "linked-account-unlink-button text-b3-grey hover:text-b3-negative", onClick: () => handleUnlink(profile), disabled: unlinkingAccountId === profile.title || isUnlinking, children: unlinkingAccountId === profile.title || isUnlinking ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "linked-account-unlink-loading animate-spin" })) : ((0, jsx_runtime_1.jsx)(lucide_react_1.UnlinkIcon, { size: 16, className: "linked-account-unlink-icon" })) })] }, profile.title))) })) : ((0, jsx_runtime_1.jsx)("div", { className: "linked-accounts-empty text-b3-foreground-muted py-8 text-center", children: "No linked accounts found" }))] }), showReferralInfo && (
156
189
  /* Referral Section */
157
190
  (0, jsx_runtime_1.jsxs)("div", { className: "referrals-section space-y-4", children: [(0, jsx_runtime_1.jsx)("h3", { className: "referrals-title text-b3-grey font-neue-montreal-semibold text-xl", children: "Referrals" }), (0, jsx_runtime_1.jsxs)("div", { className: "referral-code-container bg-b3-line rounded-xl p-4", children: [isEditingCode && ((0, jsx_runtime_1.jsxs)("div", { className: "referral-code-header-editing", children: [(0, jsx_runtime_1.jsx)("div", { className: "referral-code-title text-b3-grey font-neue-montreal-semibold", children: "Your Referral Code" }), (0, jsx_runtime_1.jsx)("div", { className: "referral-code-description text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Share this code with friends to earn rewards" })] })), (0, jsx_runtime_1.jsxs)("div", { className: "referral-code-content flex items-center justify-between", children: [!isEditingCode && ((0, jsx_runtime_1.jsxs)("div", { className: "referral-code-header", children: [(0, jsx_runtime_1.jsx)("div", { className: "referral-code-title text-b3-grey font-neue-montreal-semibold", children: "Your Referral Code" }), (0, jsx_runtime_1.jsx)("div", { className: "referral-code-description text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Share this code with friends to earn rewards" })] })), (0, jsx_runtime_1.jsx)("div", { className: "referral-code-actions flex items-center gap-2", children: isEditingCode ? ((0, jsx_runtime_1.jsxs)("div", { className: "referral-code-edit-form flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("input", { type: "text", value: newReferralCode, onChange: e => setNewReferralCode(e.target.value), className: "referral-code-input rounded-lg border border-gray-200 bg-white px-3 py-1.5 text-sm", placeholder: "Enter new code", ref: referallCodeRef }), (0, jsx_runtime_1.jsx)(react_1.Button, { size: "sm", className: "referral-code-save-button", onClick: handleUpdateReferralCode, disabled: isUpdatingCode || !newReferralCode, children: isUpdatingCode ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "referral-code-save-loading h-4 w-4 animate-spin" })) : ("Save") }), (0, jsx_runtime_1.jsx)(react_1.Button, { size: "sm", variant: "ghost", className: "referral-code-cancel-button", onClick: () => {
158
191
  setIsEditingCode(false);