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

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/anyspend/types/chain.d.ts +1 -0
  2. package/dist/cjs/anyspend/utils/chain.js +56 -47
  3. package/dist/cjs/bondkit/bondkitToken.js +40 -6
  4. package/dist/cjs/bondkit/bondkitTokenFactory.js +16 -5
  5. package/dist/cjs/global-account/react/hooks/useAuthentication.js +6 -5
  6. package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  7. package/dist/cjs/global-account/react/hooks/useFirstEOA.js +1 -21
  8. package/dist/cjs/global-account/react/hooks/useSiwe.js +1 -0
  9. package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +4 -0
  10. package/dist/cjs/global-account/react/hooks/useTWAuth.js +33 -0
  11. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +3 -9
  12. package/dist/cjs/shared/utils/simplehash.d.ts +1 -1
  13. package/dist/esm/anyspend/types/chain.d.ts +1 -0
  14. package/dist/esm/anyspend/utils/chain.js +57 -48
  15. package/dist/esm/bondkit/bondkitToken.js +40 -6
  16. package/dist/esm/bondkit/bondkitTokenFactory.js +16 -5
  17. package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -6
  18. package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  19. package/dist/esm/global-account/react/hooks/useFirstEOA.js +2 -22
  20. package/dist/esm/global-account/react/hooks/useSiwe.js +1 -0
  21. package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +4 -0
  22. package/dist/esm/global-account/react/hooks/useTWAuth.js +27 -0
  23. package/dist/esm/shared/constants/chains/b3Chain.d.ts +3 -9
  24. package/dist/esm/shared/utils/simplehash.d.ts +1 -1
  25. package/dist/types/anyspend/types/chain.d.ts +1 -0
  26. package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  27. package/dist/types/global-account/react/hooks/useTWAuth.d.ts +4 -0
  28. package/dist/types/shared/constants/chains/b3Chain.d.ts +3 -9
  29. package/dist/types/shared/utils/simplehash.d.ts +1 -1
  30. package/package.json +5 -6
  31. package/src/anyspend/types/chain.ts +1 -0
  32. package/src/anyspend/utils/chain.ts +49 -53
  33. package/src/bondkit/bondkitToken.ts +42 -8
  34. package/src/bondkit/bondkitTokenFactory.ts +16 -5
  35. package/src/global-account/react/hooks/useAuthentication.ts +8 -6
  36. package/src/global-account/react/hooks/useFirstEOA.tsx +2 -20
  37. package/src/global-account/react/hooks/useSiwe.tsx +1 -0
  38. package/src/global-account/react/hooks/useTWAuth.tsx +36 -0
@@ -0,0 +1,4 @@
1
+ import { Wallet } from "thirdweb/wallets";
2
+ export declare function useTWAuth(): {
3
+ authenticate: (wallet: Wallet, partnerId: string) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
4
+ };
@@ -12,7 +12,6 @@ export declare const b3Mainnet: {
12
12
  readonly url: "https://explorer.b3.fun";
13
13
  };
14
14
  };
15
- blockTime?: number | undefined | undefined;
16
15
  contracts?: {
17
16
  [x: string]: import("viem").ChainContract | {
18
17
  [sourceId: number]: import("viem").ChainContract | undefined;
@@ -20,7 +19,7 @@ export declare const b3Mainnet: {
20
19
  ensRegistry?: import("viem").ChainContract | undefined;
21
20
  ensUniversalResolver?: import("viem").ChainContract | undefined;
22
21
  multicall3?: import("viem").ChainContract | undefined;
23
- erc6492Verifier?: import("viem").ChainContract | undefined;
22
+ universalSignatureVerifier?: import("viem").ChainContract | undefined;
24
23
  } | undefined;
25
24
  ensTlds?: readonly string[] | undefined;
26
25
  id: 8333;
@@ -30,7 +29,6 @@ export declare const b3Mainnet: {
30
29
  readonly symbol: "ETH";
31
30
  readonly decimals: 18;
32
31
  };
33
- experimental_preconfirmationTime?: number | undefined | undefined;
34
32
  rpcUrls: {
35
33
  readonly default: {
36
34
  readonly http: readonly ["https://mainnet-rpc.b3.fun"];
@@ -58,7 +56,6 @@ export declare const getViemChainConfig: (config: ChainNetworks) => {
58
56
  readonly url: string;
59
57
  };
60
58
  };
61
- blockTime?: number | undefined | undefined;
62
59
  contracts?: {
63
60
  [x: string]: import("viem").ChainContract | {
64
61
  [sourceId: number]: import("viem").ChainContract | undefined;
@@ -66,7 +63,7 @@ export declare const getViemChainConfig: (config: ChainNetworks) => {
66
63
  ensRegistry?: import("viem").ChainContract | undefined;
67
64
  ensUniversalResolver?: import("viem").ChainContract | undefined;
68
65
  multicall3?: import("viem").ChainContract | undefined;
69
- erc6492Verifier?: import("viem").ChainContract | undefined;
66
+ universalSignatureVerifier?: import("viem").ChainContract | undefined;
70
67
  } | undefined;
71
68
  ensTlds?: readonly string[] | undefined;
72
69
  id: number;
@@ -76,7 +73,6 @@ export declare const getViemChainConfig: (config: ChainNetworks) => {
76
73
  name: string;
77
74
  decimals: number;
78
75
  };
79
- experimental_preconfirmationTime?: number | undefined | undefined;
80
76
  rpcUrls: {
81
77
  readonly default: {
82
78
  readonly http: readonly [string];
@@ -107,7 +103,6 @@ export declare const b3Chain: Chain | {
107
103
  readonly url: "https://explorer.b3.fun";
108
104
  };
109
105
  };
110
- blockTime?: number | undefined | undefined;
111
106
  contracts?: {
112
107
  [x: string]: import("viem").ChainContract | {
113
108
  [sourceId: number]: import("viem").ChainContract | undefined;
@@ -115,7 +110,7 @@ export declare const b3Chain: Chain | {
115
110
  ensRegistry?: import("viem").ChainContract | undefined;
116
111
  ensUniversalResolver?: import("viem").ChainContract | undefined;
117
112
  multicall3?: import("viem").ChainContract | undefined;
118
- erc6492Verifier?: import("viem").ChainContract | undefined;
113
+ universalSignatureVerifier?: import("viem").ChainContract | undefined;
119
114
  } | undefined;
120
115
  ensTlds?: readonly string[] | undefined;
121
116
  id: 8333;
@@ -125,7 +120,6 @@ export declare const b3Chain: Chain | {
125
120
  readonly symbol: "ETH";
126
121
  readonly decimals: 18;
127
122
  };
128
- experimental_preconfirmationTime?: number | undefined | undefined;
129
123
  rpcUrls: {
130
124
  readonly default: {
131
125
  readonly http: readonly ["https://mainnet-rpc.b3.fun"];
@@ -1,6 +1,6 @@
1
1
  import * as SimpleHashTypes from "@b3dotfun/sdk/global-account/types/simplehash.types";
2
2
  export * from "@b3dotfun/sdk/global-account/types/simplehash.types";
3
- export declare const simpleHashChainToChainId: (chain: string) => 8453 | 8333 | 84532 | 1993 | null;
3
+ export declare const simpleHashChainToChainId: (chain: string) => 8453 | 8333 | 1993 | 84532 | null;
4
4
  export declare const simpleHashChainToChainName: (chain: number) => "base" | "b3" | "b3-sepolia" | "base-sepolia" | null;
5
5
  type SimpleHashRoute = `/v0/nfts/${string}/${string}/${string}` | `/v0/nfts/${string}` | `/v0/nfts/collections/${string}/${string}` | `/v0/nfts/transfers/${string}/${string}` | `/v0/fungibles/assets` | `/v0/native_tokens/balances` | string;
6
6
  type RouteReturnType<T extends SimpleHashRoute> = T extends `/v0/nfts/collections/${string}/${string}` ? SimpleHashTypes.SimpleHashNFTResponse : T extends `/v0/nfts/transfers/${string}/${string}` ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.51-alpha.0",
3
+ "version": "0.0.51-alpha.2",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -301,7 +301,7 @@
301
301
  "@solana/web3.js": "^1.98.2",
302
302
  "@stripe/react-stripe-js": "^3.7.0",
303
303
  "@stripe/stripe-js": "^7.3.1",
304
- "@thirdweb-dev/wagmi-adapter": "0.2.165",
304
+ "@thirdweb-dev/wagmi-adapter": "0.2.159",
305
305
  "@web3icons/react": "3.16.0",
306
306
  "big.js": "^7.0.1",
307
307
  "class-variance-authority": "0.7.0",
@@ -374,11 +374,10 @@
374
374
  "react": "^18.0.0 || ^19.0.0",
375
375
  "react-dom": "^18.0.0 || ^19.0.0",
376
376
  "react-native-mmkv": "^3.2.0",
377
- "thirdweb": "5.108.14",
377
+ "thirdweb": "5.108.9",
378
378
  "three": "^0.175.0",
379
- "viem": "2.37.9",
380
- "wagmi": "2.16.9",
381
- "@wagmi/core": "2.20.3"
379
+ "viem": "^2.28.1",
380
+ "wagmi": "^2.14.15"
382
381
  },
383
382
  "peerDependenciesMeta": {
384
383
  "@react-three/postprocessing": {
@@ -22,6 +22,7 @@ export interface IEVMChain extends IBaseChain {
22
22
  type: ChainType.EVM;
23
23
  viem: Chain;
24
24
  pollingInterval: number;
25
+ wethAddress: string;
25
26
  zapperEnum?: string;
26
27
  }
27
28
 
@@ -13,20 +13,7 @@ import {
13
13
  Transport,
14
14
  WalletClient,
15
15
  } from "viem";
16
- import {
17
- abstract,
18
- arbitrum,
19
- avalanche,
20
- b3,
21
- b3Sepolia,
22
- base,
23
- baseSepolia,
24
- bsc,
25
- mainnet,
26
- optimism,
27
- polygon,
28
- sepolia,
29
- } from "viem/chains";
16
+ import { abstract, arbitrum, avalanche, b3, base, bsc, mainnet, optimism, polygon } from "viem/chains";
30
17
  import { ChainType, IBaseChain, IEVMChain, ISolanaChain } from "../types/chain";
31
18
  import { getAvaxToken, getBnbToken, getEthToken, getPolToken, getSolanaToken } from "./token";
32
19
 
@@ -59,6 +46,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
59
46
  pollingInterval: 4000, // 4 seconds for Ethereum mainnet
60
47
  zapperEnum: "ETHEREUM_MAINNET",
61
48
  coingeckoName: "eth",
49
+ wethAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
62
50
  },
63
51
  [arbitrum.id]: {
64
52
  id: arbitrum.id,
@@ -76,6 +64,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
76
64
  pollingInterval: 500, // 500ms for Arbitrum's fast blocks
77
65
  zapperEnum: "ARBITRUM_MAINNET",
78
66
  coingeckoName: "arbitrum",
67
+ wethAddress: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
79
68
  },
80
69
  [base.id]: {
81
70
  id: base.id,
@@ -93,6 +82,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
93
82
  pollingInterval: 1000, // 1 second for Base
94
83
  zapperEnum: "BASE_MAINNET",
95
84
  coingeckoName: "base",
85
+ wethAddress: "0x4200000000000000000000000000000000000006",
96
86
  },
97
87
  [optimism.id]: {
98
88
  id: optimism.id,
@@ -110,6 +100,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
110
100
  pollingInterval: 1000, // 1 second for Optimism
111
101
  zapperEnum: "OPTIMISM_MAINNET",
112
102
  coingeckoName: "optimism",
103
+ wethAddress: "0x4200000000000000000000000000000000000006",
113
104
  },
114
105
  [polygon.id]: {
115
106
  id: polygon.id,
@@ -127,6 +118,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
127
118
  pollingInterval: 1000, // 1 second for Polygon
128
119
  zapperEnum: "POLYGON_MAINNET",
129
120
  coingeckoName: "polygon_pos",
121
+ wethAddress: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
130
122
  },
131
123
  [avalanche.id]: {
132
124
  id: avalanche.id,
@@ -141,6 +133,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
141
133
  pollingInterval: 1000, // 1 second for Avalanche
142
134
  zapperEnum: "AVALANCHE_MAINNET",
143
135
  coingeckoName: "avax",
136
+ wethAddress: "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",
144
137
  },
145
138
  [bsc.id]: {
146
139
  id: bsc.id,
@@ -155,6 +148,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
155
148
  pollingInterval: 1000, // 1 second for BSC
156
149
  zapperEnum: "BSC_MAINNET",
157
150
  coingeckoName: "bsc",
151
+ wethAddress: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
158
152
  },
159
153
  [b3.id]: {
160
154
  id: b3.id,
@@ -172,6 +166,7 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
172
166
  pollingInterval: 1000, // 1 second for B3
173
167
  zapperEnum: "B3_MAINNET",
174
168
  coingeckoName: "b3",
169
+ wethAddress: "0x4200000000000000000000000000000000000006",
175
170
  },
176
171
  [abstract.id]: {
177
172
  id: abstract.id,
@@ -189,49 +184,50 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
189
184
  pollingInterval: 3000, // 3 seconds for Abstract
190
185
  zapperEnum: "ABSTRACT_MAINNET",
191
186
  coingeckoName: "abstract",
187
+ wethAddress: "0x3439153eb7af838ad19d56e1571fbd09333c2809",
192
188
  },
193
189
  };
194
190
 
195
191
  export const EVM_TESTNET: Record<number, IEVMChain> = {
196
- [sepolia.id]: {
197
- id: sepolia.id,
198
- name: sepolia.name,
199
- logoUrl: "https://assets.relay.link/icons/square/1/light.png",
200
- type: ChainType.EVM,
201
- nativeRequired: parseEther("0.00001"),
202
- canDepositNative: true,
203
- defaultToken: getEthToken(sepolia.id),
204
- nativeToken: getEthToken(sepolia.id),
205
- viem: sepolia,
206
- pollingInterval: 1000, // 1 second for Sepolia
207
- coingeckoName: "sepolia-testnet",
208
- },
209
- [baseSepolia.id]: {
210
- id: baseSepolia.id,
211
- name: baseSepolia.name,
212
- logoUrl: "https://assets.relay.link/icons/square/8453/light.png",
213
- type: ChainType.EVM,
214
- nativeRequired: parseEther("0.00001"),
215
- canDepositNative: true,
216
- defaultToken: getEthToken(baseSepolia.id),
217
- nativeToken: getEthToken(baseSepolia.id),
218
- viem: baseSepolia,
219
- pollingInterval: 1000, // 1 second for Base Sepolia
220
- coingeckoName: null,
221
- },
222
- [b3Sepolia.id]: {
223
- id: b3Sepolia.id,
224
- name: b3Sepolia.name,
225
- logoUrl: "https://assets.relay.link/icons/square/8333/light.png",
226
- type: ChainType.EVM,
227
- nativeRequired: parseEther("0.00001"),
228
- canDepositNative: true,
229
- defaultToken: getEthToken(b3Sepolia.id),
230
- nativeToken: getEthToken(b3Sepolia.id),
231
- viem: b3Sepolia,
232
- pollingInterval: 1000, // 1 second for B3 Sepolia
233
- coingeckoName: null,
234
- },
192
+ // [sepolia.id]: {
193
+ // id: sepolia.id,
194
+ // name: sepolia.name,
195
+ // logoUrl: "https://assets.relay.link/icons/square/1/light.png",
196
+ // type: ChainType.EVM,
197
+ // nativeRequired: parseEther("0.00001"),
198
+ // canDepositNative: true,
199
+ // defaultToken: getEthToken(sepolia.id),
200
+ // nativeToken: getEthToken(sepolia.id),
201
+ // viem: sepolia,
202
+ // pollingInterval: 1000, // 1 second for Sepolia
203
+ // coingeckoName: "sepolia-testnet",
204
+ // },
205
+ // [baseSepolia.id]: {
206
+ // id: baseSepolia.id,
207
+ // name: baseSepolia.name,
208
+ // logoUrl: "https://assets.relay.link/icons/square/8453/light.png",
209
+ // type: ChainType.EVM,
210
+ // nativeRequired: parseEther("0.00001"),
211
+ // canDepositNative: true,
212
+ // defaultToken: getEthToken(baseSepolia.id),
213
+ // nativeToken: getEthToken(baseSepolia.id),
214
+ // viem: baseSepolia,
215
+ // pollingInterval: 1000, // 1 second for Base Sepolia
216
+ // coingeckoName: null,
217
+ // },
218
+ // [b3Sepolia.id]: {
219
+ // id: b3Sepolia.id,
220
+ // name: b3Sepolia.name,
221
+ // logoUrl: "https://assets.relay.link/icons/square/8333/light.png",
222
+ // type: ChainType.EVM,
223
+ // nativeRequired: parseEther("0.00001"),
224
+ // canDepositNative: true,
225
+ // defaultToken: getEthToken(b3Sepolia.id),
226
+ // nativeToken: getEthToken(b3Sepolia.id),
227
+ // viem: b3Sepolia,
228
+ // pollingInterval: 1000, // 1 second for B3 Sepolia
229
+ // coingeckoName: null,
230
+ // },
235
231
  // [b4testnet.id]: {
236
232
  // id: b4testnet.id,
237
233
  // logoUrl: "https://cdn.b3.fun/b4-logo.png",
@@ -91,12 +91,21 @@ export class BondkitToken {
91
91
  this.contract = getContract({
92
92
  address: this.contractAddress,
93
93
  abi: BondkitTokenABI,
94
- client: this.walletClientInstance,
94
+ client: {
95
+ public: this.publicClient,
96
+ wallet: this.walletClientInstance,
97
+ },
95
98
  });
96
99
 
97
- this.contract.read.tradingToken().then(tradingToken => {
98
- this.tradingToken = tradingToken as Address;
99
- });
100
+ getContract({
101
+ address: this.contractAddress,
102
+ abi: BondkitTokenABI,
103
+ client: this.publicClient, // Use public client for read operations
104
+ })
105
+ .read.tradingToken()
106
+ .then(tradingToken => {
107
+ this.tradingToken = tradingToken as Address;
108
+ });
100
109
  }
101
110
 
102
111
  public connect(provider?: EIP1193Provider): boolean {
@@ -119,7 +128,10 @@ export class BondkitToken {
119
128
  this.contract = getContract({
120
129
  address: this.contractAddress,
121
130
  abi: BondkitTokenABI,
122
- client: this.walletClientInstance,
131
+ client: {
132
+ public: this.publicClient,
133
+ wallet: this.walletClientInstance,
134
+ },
123
135
  });
124
136
  return true;
125
137
  } catch (error) {
@@ -167,7 +179,10 @@ export class BondkitToken {
167
179
  this.contract = getContract({
168
180
  address: this.contractAddress,
169
181
  abi: BondkitTokenABI,
170
- client: this.walletClientInstance,
182
+ client: {
183
+ public: this.publicClient,
184
+ wallet: this.walletClientInstance,
185
+ },
171
186
  });
172
187
 
173
188
  return true;
@@ -505,7 +520,10 @@ export class BondkitToken {
505
520
  this.contract = getContract({
506
521
  address: this.contractAddress,
507
522
  abi: BondkitTokenABI,
508
- client: this.walletClientInstance,
523
+ client: {
524
+ public: this.publicClient,
525
+ wallet: this.walletClientInstance,
526
+ },
509
527
  });
510
528
  }
511
529
  } catch (_) {}
@@ -514,6 +532,19 @@ export class BondkitToken {
514
532
  throw new Error("Wallet key not set or client not connected for write operation.");
515
533
  }
516
534
  }
535
+
536
+ // Only attempt chain switching for browser wallet providers
537
+ // Private key users cannot switch chains programmatically
538
+ if (this.connectedProvider && this.walletClientInstance.account) {
539
+ const walletChainId = await this.walletClientInstance.getChainId();
540
+ if (walletChainId !== this.chain.id) {
541
+ try {
542
+ await this.walletClientInstance.switchChain({ id: this.chain.id });
543
+ } catch (switchErr) {
544
+ throw new Error(`Please switch your wallet to ${this.chain.name} (${this.chain.id}).`);
545
+ }
546
+ }
547
+ }
517
548
  const accountToUse = this.walletKey ? privateKeyToAccount(this.walletKey) : this.walletClientInstance.account;
518
549
  if (!accountToUse) throw new Error("Account for transaction could not be determined.");
519
550
 
@@ -624,7 +655,10 @@ export class BondkitToken {
624
655
  const tradingTokenContract = getContract({
625
656
  address: this.tradingToken as Address,
626
657
  abi: erc20Abi,
627
- client: this.walletClientInstance,
658
+ client: {
659
+ public: this.publicClient,
660
+ wallet: this.walletClientInstance,
661
+ },
628
662
  });
629
663
 
630
664
  const currentAllowance = await tradingTokenContract.read.allowance([
@@ -56,7 +56,10 @@ export class BondkitTokenFactory {
56
56
  this.contract = getContract({
57
57
  address: this.contractAddress,
58
58
  abi: BondkitTokenFactoryABI,
59
- client: this.walletClientInstance,
59
+ client: {
60
+ public: this.publicClient,
61
+ wallet: this.walletClientInstance,
62
+ },
60
63
  });
61
64
  }
62
65
 
@@ -75,7 +78,10 @@ export class BondkitTokenFactory {
75
78
  this.contract = getContract({
76
79
  address: this.contractAddress,
77
80
  abi: BondkitTokenFactoryABI,
78
- client: this.walletClientInstance,
81
+ client: {
82
+ public: this.publicClient,
83
+ wallet: this.walletClientInstance,
84
+ },
79
85
  });
80
86
 
81
87
  this.publicClient = createPublicClient({
@@ -127,7 +133,10 @@ export class BondkitTokenFactory {
127
133
  this.contract = getContract({
128
134
  address: this.contractAddress,
129
135
  abi: BondkitTokenFactoryABI,
130
- client: this.walletClientInstance,
136
+ client: {
137
+ public: this.publicClient,
138
+ wallet: this.walletClientInstance,
139
+ },
131
140
  });
132
141
 
133
142
  return true;
@@ -157,7 +166,10 @@ export class BondkitTokenFactory {
157
166
  this.contract = getContract({
158
167
  address: this.contractAddress,
159
168
  abi: BondkitTokenFactoryABI,
160
- client: this.walletClientInstance,
169
+ client: {
170
+ public: this.publicClient,
171
+ wallet: this.walletClientInstance,
172
+ },
161
173
  });
162
174
  }
163
175
  } catch (_) {}
@@ -201,7 +213,6 @@ export class BondkitTokenFactory {
201
213
  chain: this.chain,
202
214
  });
203
215
 
204
- console.log("hash", hash);
205
216
  const receipt: TransactionReceipt = await this.publicClient.waitForTransactionReceipt({ hash });
206
217
 
207
218
  for (const log of receipt.logs) {
@@ -1,6 +1,6 @@
1
1
  import app from "@b3dotfun/sdk/global-account/app";
2
2
  import { authenticateWithB3JWT } from "@b3dotfun/sdk/global-account/bsmnt";
3
- import { useAuthStore, useSiwe } from "@b3dotfun/sdk/global-account/react";
3
+ import { useAuthStore } from "@b3dotfun/sdk/global-account/react";
4
4
  import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
5
5
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
6
6
  import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
@@ -17,6 +17,7 @@ import {
17
17
  import { Wallet, ecosystemWallet } from "thirdweb/wallets";
18
18
  import { preAuthenticate } from "thirdweb/wallets/in-app";
19
19
  import { useAccount, useConnect, useSwitchAccount } from "wagmi";
20
+ import { useTWAuth } from "./useTWAuth";
20
21
  import { useUserQuery } from "./useUserQuery";
21
22
  import { useWagmiConfig } from "./useWagmiConfig";
22
23
 
@@ -36,7 +37,7 @@ export function useAuthentication(partnerId: string) {
36
37
  const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
37
38
  const setActiveWallet = useSetActiveWallet();
38
39
  const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
39
- const { authenticate } = useSiwe();
40
+ const { authenticate } = useTWAuth();
40
41
  const { user, setUser } = useUserQuery();
41
42
  const useAutoConnectLoadingPrevious = useRef(false);
42
43
  const wagmiConfig = useWagmiConfig(partnerId);
@@ -119,10 +120,11 @@ export function useAuthentication(partnerId: string) {
119
120
  async (wallet?: Wallet) => {
120
121
  setHasStartedConnecting(true);
121
122
 
122
- const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
123
- if (!account) {
124
- throw new Error("No account found during auto-connect");
123
+ if (!wallet) {
124
+ throw new Error("No wallet found during auto-connect");
125
125
  }
126
+
127
+ const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
126
128
  if (!account) {
127
129
  throw new Error("No account found during auto-connect");
128
130
  }
@@ -141,7 +143,7 @@ export function useAuthentication(partnerId: string) {
141
143
  } catch (error) {
142
144
  // If re-authentication fails, try fresh authentication
143
145
  debug("Re-authentication failed, attempting fresh authentication");
144
- const userAuth = await authenticate(account, partnerId);
146
+ const userAuth = await authenticate(wallet, partnerId);
145
147
  setUser(userAuth.user);
146
148
  setIsAuthenticated(true);
147
149
  setIsAuthenticating(false);
@@ -1,14 +1,12 @@
1
1
  import { useAuthStore } from "@b3dotfun/sdk/global-account/react";
2
2
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
3
- import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
4
- import { useEffect, useMemo, useState } from "react";
5
- import { viemAdapter } from "thirdweb/adapters/viem";
3
+ import { useEffect, useState } from "react";
6
4
  import { useConnectedWallets, useWalletInfo } from "thirdweb/react";
7
5
  import { Wallet } from "thirdweb/wallets";
8
6
 
9
7
  const debug = debugB3React("useFirstEOA");
10
8
 
11
- export function useFirstEOA(chain?: { id: number; name: string; rpc: string }) {
9
+ export function useFirstEOA() {
12
10
  const wallets = useConnectedWallets();
13
11
  const isConnected = useAuthStore(state => state.isConnected);
14
12
  const [firstEOA, setFirstEOA] = useState<Wallet | undefined>(undefined);
@@ -41,25 +39,9 @@ export function useFirstEOA(chain?: { id: number; name: string; rpc: string }) {
41
39
  autoSelectFirstEOAWallet();
42
40
  }, [isConnected, wallets]);
43
41
 
44
- const walletClient = useMemo(() => {
45
- if (!firstEOA) return undefined;
46
- if (!chain) return undefined;
47
- try {
48
- const viemClientWallet = viemAdapter.wallet.toViem({
49
- client,
50
- chain,
51
- wallet: firstEOA,
52
- });
53
- return viemClientWallet;
54
- } catch (err) {
55
- console.error("Error setting wallet client", err);
56
- }
57
- }, [firstEOA, chain]);
58
-
59
42
  return {
60
43
  account: firstEOA,
61
44
  address,
62
45
  info: walletInfo,
63
- walletClient,
64
46
  };
65
47
  }
@@ -9,6 +9,7 @@ export function useSiwe() {
9
9
 
10
10
  const authenticate = useCallback(
11
11
  async (account: Account, partnerId: string) => {
12
+ console.warn("@@useSiwe is deprecated, use useTWAuth instead");
12
13
  if (!account || !account.signMessage) throw new Error("Account not found");
13
14
 
14
15
  console.log("@@useAuthenticate:referralCode", referralCode);
@@ -0,0 +1,36 @@
1
+ import app from "@b3dotfun/sdk/global-account/app";
2
+ import debug from "@b3dotfun/sdk/shared/utils/debug";
3
+ import { useCallback } from "react";
4
+ import { Wallet } from "thirdweb/wallets";
5
+ import { useSearchParam } from "./useSearchParamsSSR";
6
+
7
+ export function useTWAuth() {
8
+ const referralCode = useSearchParam("referralCode");
9
+
10
+ const authenticate = useCallback(
11
+ async (wallet: Wallet, partnerId: string) => {
12
+ if (!wallet || !wallet?.getAuthToken?.()) throw new Error("Wallet not found");
13
+
14
+ const authToken = wallet.getAuthToken();
15
+ debug("@@useTWSignIn:authToken", authToken);
16
+ debug("@@useTWSignIn:referralCode", referralCode);
17
+
18
+ // authenticate
19
+ const response = await app.authenticate({
20
+ strategy: "thirdweb-jwt",
21
+ accessToken: authToken,
22
+ // http://localhost:5173/?referralCode=GIO2
23
+ referralCode,
24
+ partnerId: partnerId,
25
+ });
26
+ debug("@@useTWSignIn:response", response);
27
+
28
+ return response;
29
+ },
30
+ [referralCode],
31
+ );
32
+
33
+ return {
34
+ authenticate,
35
+ };
36
+ }