@b3dotfun/sdk 0.0.51-alpha.0 → 0.0.51-alpha.1

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 (28) hide show
  1. package/dist/cjs/bondkit/bondkitToken.js +40 -6
  2. package/dist/cjs/bondkit/bondkitTokenFactory.js +16 -5
  3. package/dist/cjs/global-account/react/hooks/useAuthentication.js +6 -5
  4. package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  5. package/dist/cjs/global-account/react/hooks/useFirstEOA.js +1 -21
  6. package/dist/cjs/global-account/react/hooks/useSiwe.js +1 -0
  7. package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +4 -0
  8. package/dist/cjs/global-account/react/hooks/useTWAuth.js +33 -0
  9. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +3 -9
  10. package/dist/esm/bondkit/bondkitToken.js +40 -6
  11. package/dist/esm/bondkit/bondkitTokenFactory.js +16 -5
  12. package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -6
  13. package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  14. package/dist/esm/global-account/react/hooks/useFirstEOA.js +2 -22
  15. package/dist/esm/global-account/react/hooks/useSiwe.js +1 -0
  16. package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +4 -0
  17. package/dist/esm/global-account/react/hooks/useTWAuth.js +27 -0
  18. package/dist/esm/shared/constants/chains/b3Chain.d.ts +3 -9
  19. package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  20. package/dist/types/global-account/react/hooks/useTWAuth.d.ts +4 -0
  21. package/dist/types/shared/constants/chains/b3Chain.d.ts +3 -9
  22. package/package.json +5 -6
  23. package/src/bondkit/bondkitToken.ts +42 -8
  24. package/src/bondkit/bondkitTokenFactory.ts +16 -5
  25. package/src/global-account/react/hooks/useAuthentication.ts +8 -6
  26. package/src/global-account/react/hooks/useFirstEOA.tsx +2 -20
  27. package/src/global-account/react/hooks/useSiwe.tsx +1 -0
  28. package/src/global-account/react/hooks/useTWAuth.tsx +36 -0
@@ -44,9 +44,18 @@ class BondkitToken {
44
44
  this.contract = (0, viem_1.getContract)({
45
45
  address: this.contractAddress,
46
46
  abi: abis_1.BondkitTokenABI,
47
- client: this.walletClientInstance,
47
+ client: {
48
+ public: this.publicClient,
49
+ wallet: this.walletClientInstance,
50
+ },
48
51
  });
49
- this.contract.read.tradingToken().then(tradingToken => {
52
+ (0, viem_1.getContract)({
53
+ address: this.contractAddress,
54
+ abi: abis_1.BondkitTokenABI,
55
+ client: this.publicClient, // Use public client for read operations
56
+ })
57
+ .read.tradingToken()
58
+ .then(tradingToken => {
50
59
  this.tradingToken = tradingToken;
51
60
  });
52
61
  }
@@ -66,7 +75,10 @@ class BondkitToken {
66
75
  this.contract = (0, viem_1.getContract)({
67
76
  address: this.contractAddress,
68
77
  abi: abis_1.BondkitTokenABI,
69
- client: this.walletClientInstance,
78
+ client: {
79
+ public: this.publicClient,
80
+ wallet: this.walletClientInstance,
81
+ },
70
82
  });
71
83
  return true;
72
84
  }
@@ -113,7 +125,10 @@ class BondkitToken {
113
125
  this.contract = (0, viem_1.getContract)({
114
126
  address: this.contractAddress,
115
127
  abi: abis_1.BondkitTokenABI,
116
- client: this.walletClientInstance,
128
+ client: {
129
+ public: this.publicClient,
130
+ wallet: this.walletClientInstance,
131
+ },
117
132
  });
118
133
  return true;
119
134
  }
@@ -426,7 +441,10 @@ class BondkitToken {
426
441
  this.contract = (0, viem_1.getContract)({
427
442
  address: this.contractAddress,
428
443
  abi: abis_1.BondkitTokenABI,
429
- client: this.walletClientInstance,
444
+ client: {
445
+ public: this.publicClient,
446
+ wallet: this.walletClientInstance,
447
+ },
430
448
  });
431
449
  }
432
450
  }
@@ -436,6 +454,19 @@ class BondkitToken {
436
454
  throw new Error("Wallet key not set or client not connected for write operation.");
437
455
  }
438
456
  }
457
+ // Only attempt chain switching for browser wallet providers
458
+ // Private key users cannot switch chains programmatically
459
+ if (this.connectedProvider && this.walletClientInstance.account) {
460
+ const walletChainId = await this.walletClientInstance.getChainId();
461
+ if (walletChainId !== this.chain.id) {
462
+ try {
463
+ await this.walletClientInstance.switchChain({ id: this.chain.id });
464
+ }
465
+ catch (switchErr) {
466
+ throw new Error(`Please switch your wallet to ${this.chain.name} (${this.chain.id}).`);
467
+ }
468
+ }
469
+ }
439
470
  const accountToUse = this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey) : this.walletClientInstance.account;
440
471
  if (!accountToUse)
441
472
  throw new Error("Account for transaction could not be determined.");
@@ -530,7 +561,10 @@ class BondkitToken {
530
561
  const tradingTokenContract = (0, viem_1.getContract)({
531
562
  address: this.tradingToken,
532
563
  abi: viem_1.erc20Abi,
533
- client: this.walletClientInstance,
564
+ client: {
565
+ public: this.publicClient,
566
+ wallet: this.walletClientInstance,
567
+ },
534
568
  });
535
569
  const currentAllowance = await tradingTokenContract.read.allowance([
536
570
  this.walletClientInstance.account?.address,
@@ -31,7 +31,10 @@ class BondkitTokenFactory {
31
31
  this.contract = (0, viem_1.getContract)({
32
32
  address: this.contractAddress,
33
33
  abi: abis_1.BondkitTokenFactoryABI,
34
- client: this.walletClientInstance,
34
+ client: {
35
+ public: this.publicClient,
36
+ wallet: this.walletClientInstance,
37
+ },
35
38
  });
36
39
  }
37
40
  connect(provider) {
@@ -46,7 +49,10 @@ class BondkitTokenFactory {
46
49
  this.contract = (0, viem_1.getContract)({
47
50
  address: this.contractAddress,
48
51
  abi: abis_1.BondkitTokenFactoryABI,
49
- client: this.walletClientInstance,
52
+ client: {
53
+ public: this.publicClient,
54
+ wallet: this.walletClientInstance,
55
+ },
50
56
  });
51
57
  this.publicClient = (0, viem_1.createPublicClient)({
52
58
  chain: this.chain,
@@ -95,7 +101,10 @@ class BondkitTokenFactory {
95
101
  this.contract = (0, viem_1.getContract)({
96
102
  address: this.contractAddress,
97
103
  abi: abis_1.BondkitTokenFactoryABI,
98
- client: this.walletClientInstance,
104
+ client: {
105
+ public: this.publicClient,
106
+ wallet: this.walletClientInstance,
107
+ },
99
108
  });
100
109
  return true;
101
110
  }
@@ -126,7 +135,10 @@ class BondkitTokenFactory {
126
135
  this.contract = (0, viem_1.getContract)({
127
136
  address: this.contractAddress,
128
137
  abi: abis_1.BondkitTokenFactoryABI,
129
- client: this.walletClientInstance,
138
+ client: {
139
+ public: this.publicClient,
140
+ wallet: this.walletClientInstance,
141
+ },
130
142
  });
131
143
  }
132
144
  }
@@ -164,7 +176,6 @@ class BondkitTokenFactory {
164
176
  account: accountToUse,
165
177
  chain: this.chain,
166
178
  });
167
- console.log("hash", hash);
168
179
  const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
169
180
  for (const log of receipt.logs) {
170
181
  try {
@@ -16,6 +16,7 @@ const react_3 = require("thirdweb/react");
16
16
  const wallets_1 = require("thirdweb/wallets");
17
17
  const in_app_1 = require("thirdweb/wallets/in-app");
18
18
  const wagmi_1 = require("wagmi");
19
+ const useTWAuth_1 = require("./useTWAuth");
19
20
  const useUserQuery_1 = require("./useUserQuery");
20
21
  const useWagmiConfig_1 = require("./useWagmiConfig");
21
22
  const debug = (0, debug_1.debugB3React)("useAuthentication");
@@ -33,7 +34,7 @@ function useAuthentication(partnerId) {
33
34
  const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
34
35
  const setActiveWallet = (0, react_3.useSetActiveWallet)();
35
36
  const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
36
- const { authenticate } = (0, react_1.useSiwe)();
37
+ const { authenticate } = (0, useTWAuth_1.useTWAuth)();
37
38
  const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
38
39
  const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
39
40
  const wagmiConfig = (0, useWagmiConfig_1.useWagmiConfig)(partnerId);
@@ -106,10 +107,10 @@ function useAuthentication(partnerId) {
106
107
  }, [wallets, syncWagmi]);
107
108
  const authenticateUser = (0, react_2.useCallback)(async (wallet) => {
108
109
  setHasStartedConnecting(true);
109
- const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
110
- if (!account) {
111
- throw new Error("No account found during auto-connect");
110
+ if (!wallet) {
111
+ throw new Error("No wallet found during auto-connect");
112
112
  }
113
+ const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
113
114
  if (!account) {
114
115
  throw new Error("No account found during auto-connect");
115
116
  }
@@ -127,7 +128,7 @@ function useAuthentication(partnerId) {
127
128
  catch (error) {
128
129
  // If re-authentication fails, try fresh authentication
129
130
  debug("Re-authentication failed, attempting fresh authentication");
130
- const userAuth = await authenticate(account, partnerId);
131
+ const userAuth = await authenticate(wallet, partnerId);
131
132
  setUser(userAuth.user);
132
133
  setIsAuthenticated(true);
133
134
  setIsAuthenticating(false);