@b3dotfun/sdk 0.0.41-test.0 → 0.0.42-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/AnySpend.js +11 -2
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +33 -11
- package/dist/cjs/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +0 -1
- package/dist/cjs/anyspend/react/components/AnyspendSignatureMint.js +1 -2
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +1 -1
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +2 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +4 -1
- package/dist/cjs/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/cjs/anyspend/react/components/common/PointsBadge.js +7 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +5 -3
- package/dist/cjs/anyspend/services/anyspend.d.ts +1 -1
- package/dist/cjs/anyspend/services/anyspend.js +2 -0
- package/dist/cjs/anyspend/types/api.d.ts +41 -1
- package/dist/cjs/anyspend/utils/orderPayload.js +3 -0
- package/dist/cjs/bondkit/components/TradingView.js +3 -4
- package/dist/cjs/bondkit/swapService.js +3 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +19 -15
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/index.js +3 -1
- package/dist/cjs/global-account/react/hooks/useAccountAssets.js +5 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +1 -1
- package/dist/cjs/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/cjs/global-account/react/hooks/useGlobalAccount.js +32 -0
- package/dist/cjs/global-account/react/hooks/useQueryB3.js +5 -2
- package/dist/cjs/global-account/react/hooks/useQueryBSMNT.js +5 -2
- package/dist/cjs/global-account/react/hooks/useTokenBalancesByChain.js +7 -1
- package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +2 -2
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +1 -2
- package/dist/cjs/shared/utils/fetchBalances.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +1 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +11 -2
- package/dist/esm/anyspend/react/components/AnySpendBondKit.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +33 -11
- package/dist/esm/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +0 -1
- package/dist/esm/anyspend/react/components/AnyspendSignatureMint.js +1 -2
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +1 -1
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +2 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +4 -1
- package/dist/esm/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/esm/anyspend/react/components/common/PointsBadge.js +4 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +5 -3
- package/dist/esm/anyspend/services/anyspend.d.ts +1 -1
- package/dist/esm/anyspend/services/anyspend.js +2 -0
- package/dist/esm/anyspend/types/api.d.ts +41 -1
- package/dist/esm/anyspend/utils/orderPayload.js +3 -0
- package/dist/esm/bondkit/components/TradingView.js +3 -4
- package/dist/esm/bondkit/swapService.js +5 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -15
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/index.js +1 -0
- package/dist/esm/global-account/react/hooks/useAccountAssets.js +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +1 -1
- package/dist/esm/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/esm/global-account/react/hooks/useGlobalAccount.js +29 -0
- package/dist/esm/global-account/react/hooks/useQueryB3.js +5 -2
- package/dist/esm/global-account/react/hooks/useQueryBSMNT.js +5 -2
- package/dist/esm/global-account/react/hooks/useTokenBalancesByChain.js +4 -1
- package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +2 -2
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +2 -3
- package/dist/esm/shared/utils/fetchBalances.d.ts +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/types/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/types/anyspend/services/anyspend.d.ts +1 -1
- package/dist/types/anyspend/types/api.d.ts +41 -1
- package/dist/types/global-account/react/hooks/index.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/types/shared/utils/fetchBalances.d.ts +1 -1
- package/package.json +1 -2
- package/src/anyspend/react/components/AnySpend.tsx +14 -1
- package/src/anyspend/react/components/AnySpendBondKit.tsx +0 -1
- package/src/anyspend/react/components/AnySpendBuySpin.tsx +0 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +63 -13
- package/src/anyspend/react/components/AnySpendNFT.tsx +3 -0
- package/src/anyspend/react/components/AnySpendStakeB3.tsx +0 -1
- package/src/anyspend/react/components/AnyspendSignatureMint.tsx +1 -2
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +1 -1
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +6 -8
- package/src/anyspend/react/components/common/PanelOnramp.tsx +10 -10
- package/src/anyspend/react/components/common/PointsBadge.tsx +20 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +5 -3
- package/src/anyspend/react/hooks/useAnyspendOrderAndTransactions.ts +1 -1
- package/src/anyspend/react/hooks/useCoinbaseOnrampOptions.ts +1 -1
- package/src/anyspend/services/anyspend.ts +3 -1
- package/src/anyspend/types/api.ts +41 -1
- package/src/anyspend/utils/orderPayload.ts +3 -0
- package/src/bondkit/components/TradingView.tsx +3 -5
- package/src/bondkit/swapService.ts +10 -7
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +21 -20
- package/src/global-account/react/hooks/index.ts +1 -0
- package/src/global-account/react/hooks/useAccountAssets.ts +4 -3
- package/src/global-account/react/hooks/useAuthentication.ts +1 -1
- package/src/global-account/react/hooks/useGlobalAccount.tsx +36 -0
- package/src/global-account/react/hooks/useOneBalance.tsx +1 -1
- package/src/global-account/react/hooks/useQueryB3.ts +22 -15
- package/src/global-account/react/hooks/useQueryBSMNT.ts +22 -15
- package/src/global-account/react/hooks/useTokenBalancesByChain.tsx +4 -1
- package/src/global-account/react/hooks/useTokenFromUrl.tsx +2 -2
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +2 -3
- package/src/shared/utils/fetchBalances.ts +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { Address, Hex,
|
|
1
|
+
import type { Address, Hex, PublicClient, WalletClient } from "viem";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
formatUnits,
|
|
3
|
+
createPublicClient,
|
|
5
4
|
encodeAbiParameters,
|
|
6
|
-
|
|
5
|
+
formatUnits,
|
|
7
6
|
getContract,
|
|
8
|
-
createPublicClient,
|
|
9
7
|
http,
|
|
8
|
+
parseAbiParameters,
|
|
9
|
+
parseUnits,
|
|
10
10
|
} from "viem";
|
|
11
11
|
import { base } from "viem/chains";
|
|
12
|
-
import {
|
|
12
|
+
import { BaseMainnetRpcUrl, Permit2Address, QuoterAddress, UniversalRouterAddress } from "./constants";
|
|
13
13
|
import type { SwapQuote } from "./types";
|
|
14
14
|
|
|
15
15
|
// Minimal ABIs needed for swap functionality
|
|
@@ -230,7 +230,10 @@ export class BondkitSwapService {
|
|
|
230
230
|
*/
|
|
231
231
|
private async getV4Config(): Promise<V4PoolConfig> {
|
|
232
232
|
await this.initializeV4Config();
|
|
233
|
-
|
|
233
|
+
if (!this.v4Config) {
|
|
234
|
+
throw new Error("Failed to initialize V4 configuration");
|
|
235
|
+
}
|
|
236
|
+
return this.v4Config;
|
|
234
237
|
}
|
|
235
238
|
|
|
236
239
|
/**
|
|
@@ -6,11 +6,9 @@ import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
|
6
6
|
import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
|
|
7
7
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
8
8
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
9
|
-
import { farcasterMiniApp as miniAppConnector } from "@farcaster/miniapp-wagmi-connector";
|
|
10
9
|
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
11
10
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
12
11
|
import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
|
|
13
|
-
|
|
14
12
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
15
13
|
import { Toaster } from "sonner";
|
|
16
14
|
import {
|
|
@@ -90,31 +88,34 @@ export function B3Provider({
|
|
|
90
88
|
};
|
|
91
89
|
}, [partnerId]);
|
|
92
90
|
|
|
91
|
+
// Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
|
|
92
|
+
// when parent component passes new object references with same content
|
|
93
|
+
const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
|
|
94
|
+
|
|
93
95
|
/**
|
|
94
96
|
* Creates wagmi config with optional custom RPC URLs
|
|
95
97
|
* @param rpcUrls - Optional mapping of chain IDs to RPC URLs
|
|
96
98
|
*/
|
|
97
|
-
const wagmiConfig = useMemo(
|
|
98
|
-
()
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
);
|
|
99
|
+
const wagmiConfig = useMemo(() => {
|
|
100
|
+
const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
|
|
101
|
+
|
|
102
|
+
return createConfig({
|
|
103
|
+
chains: [supportedChains[0], ...supportedChains.slice(1)],
|
|
104
|
+
transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
|
|
105
|
+
connectors: [
|
|
106
|
+
inAppWalletConnector({
|
|
107
|
+
...(ecocystemConfig || {}),
|
|
108
|
+
client,
|
|
109
|
+
}),
|
|
110
|
+
// injected(),
|
|
111
|
+
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
}, [ecocystemConfig, rpcUrlsString]);
|
|
114
115
|
|
|
115
116
|
return (
|
|
116
117
|
<ThirdwebProvider>
|
|
117
|
-
<WagmiProvider config={wagmiConfig}
|
|
118
|
+
<WagmiProvider config={wagmiConfig}>
|
|
118
119
|
<QueryClientProvider client={queryClient}>
|
|
119
120
|
<TooltipProvider>
|
|
120
121
|
<InnerProvider
|
|
@@ -14,6 +14,7 @@ export { useExchangeRate } from "./useExchangeRate";
|
|
|
14
14
|
export { useFirstEOA } from "./useFirstEOA";
|
|
15
15
|
export { useGetAllTWSigners, type TWSignerWithMetadata } from "./useGetAllTWSigners";
|
|
16
16
|
export { useGetGeo } from "./useGetGeo";
|
|
17
|
+
export { useGlobalAccount } from "./useGlobalAccount";
|
|
17
18
|
export { useHandleConnectWithPrivy } from "./useHandleConnectWithPrivy";
|
|
18
19
|
export { useHasMounted } from "./useHasMounted";
|
|
19
20
|
export { useIsMobile } from "./useIsMobile";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { fetchSimpleHashData } from "@b3dotfun/sdk/shared/utils/simplehash";
|
|
2
2
|
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import invariant from "invariant";
|
|
3
4
|
|
|
4
|
-
async function fetchAccountAssets(address: string) {
|
|
5
|
-
|
|
5
|
+
async function fetchAccountAssets(address: string | undefined) {
|
|
6
|
+
invariant(address, "Address is required");
|
|
6
7
|
|
|
7
8
|
const [nftResponse] = await Promise.all([
|
|
8
9
|
fetchSimpleHashData(`/v0/nfts/owners`, {
|
|
@@ -27,7 +28,7 @@ async function fetchAccountAssets(address: string) {
|
|
|
27
28
|
export function useAccountAssets(address?: string) {
|
|
28
29
|
return useQuery({
|
|
29
30
|
queryKey: ["accountAssets", address],
|
|
30
|
-
queryFn: () => fetchAccountAssets(address
|
|
31
|
+
queryFn: () => fetchAccountAssets(address),
|
|
31
32
|
enabled: Boolean(address),
|
|
32
33
|
staleTime: 30 * 1000, // Consider data fresh for 30 seconds
|
|
33
34
|
gcTime: 5 * 60 * 1000, // Keep unused data in cache for 5 minutes
|
|
@@ -100,7 +100,7 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
100
100
|
setIsAuthenticating(false);
|
|
101
101
|
}
|
|
102
102
|
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
103
|
-
}, [useAutoConnectLoading]);
|
|
103
|
+
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
104
104
|
|
|
105
105
|
// Ensure isAuthenticating stays true until we're fully ready
|
|
106
106
|
useEffect(() => {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
+
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { useConnectedWallets, useWalletInfo } from "thirdweb/react";
|
|
5
|
+
import { Wallet } from "thirdweb/wallets";
|
|
6
|
+
|
|
7
|
+
const debug = debugB3React("useGlobalAccount");
|
|
8
|
+
|
|
9
|
+
export function useGlobalAccount() {
|
|
10
|
+
const wallets = useConnectedWallets();
|
|
11
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
12
|
+
const [globalAccount, setGlobalAccount] = useState<Wallet | undefined>(undefined);
|
|
13
|
+
const [address, setAddress] = useState<string | undefined>(undefined);
|
|
14
|
+
const walletInfo = useWalletInfo(globalAccount?.id);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!isConnected) {
|
|
18
|
+
debug("Not connected");
|
|
19
|
+
setGlobalAccount(undefined);
|
|
20
|
+
setAddress(undefined);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const globalAccountWallet = wallets.find(wallet => wallet.id.startsWith("ecosystem."));
|
|
25
|
+
|
|
26
|
+
const account = globalAccountWallet?.getAccount();
|
|
27
|
+
setGlobalAccount(globalAccountWallet);
|
|
28
|
+
setAddress(account?.address);
|
|
29
|
+
}, [isConnected, wallets]);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
account: globalAccount,
|
|
33
|
+
address,
|
|
34
|
+
info: walletInfo,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -30,7 +30,7 @@ export const useOneBalance = (bypassCache = false) => {
|
|
|
30
30
|
|
|
31
31
|
const { data, isLoading, refetch } = useQuery({
|
|
32
32
|
queryKey: ["balances", address, `testnet-${sprinterTestnet}`],
|
|
33
|
-
queryFn: () => fetchBalances(address
|
|
33
|
+
queryFn: () => fetchBalances(address, sprinterTestnet),
|
|
34
34
|
enabled: !!address,
|
|
35
35
|
staleTime: 1000 * 60 * 1, // 1 minute
|
|
36
36
|
gcTime: 1000 * 60 * 5, // 5 minutes (renamed from cacheTime in v5)
|
|
@@ -47,26 +47,33 @@ export function useQueryB3<
|
|
|
47
47
|
const [error, setError] = useState<Error | null>(null);
|
|
48
48
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
49
49
|
|
|
50
|
-
const runQuery = useCallback(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const runQuery = useCallback(
|
|
51
|
+
async (queryParams: ParamsType<T, M>) => {
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
try {
|
|
54
|
+
// Cast the service to avoid TypeScript issues with dynamic services
|
|
55
|
+
const serviceInstance = app.service(service) as any;
|
|
56
|
+
const result = await serviceInstance[method](queryParams);
|
|
57
|
+
setData(result); // Now `data` is correctly typed!
|
|
58
|
+
return result;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
setError(err instanceof Error ? err : new Error("An error occurred"));
|
|
61
|
+
} finally {
|
|
62
|
+
setIsLoading(false);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[service, method],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Serialize params for stable comparison
|
|
69
|
+
const paramsJson = JSON.stringify(params);
|
|
64
70
|
|
|
65
71
|
useEffect(() => {
|
|
66
72
|
if (fetchInitially) {
|
|
67
73
|
runQuery(params);
|
|
68
74
|
}
|
|
69
|
-
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
}, [runQuery, fetchInitially, paramsJson]);
|
|
70
77
|
|
|
71
78
|
return { data, error, isLoading, runQuery };
|
|
72
79
|
}
|
|
@@ -47,26 +47,33 @@ export function useQueryBSMNT<
|
|
|
47
47
|
const [error, setError] = useState<Error | null>(null);
|
|
48
48
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
49
49
|
|
|
50
|
-
const runQuery = useCallback(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const runQuery = useCallback(
|
|
51
|
+
async (queryParams: ParamsType<T, M>) => {
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
try {
|
|
54
|
+
// Cast the service to avoid TypeScript issues with dynamic services
|
|
55
|
+
const serviceInstance = app.service(service) as any;
|
|
56
|
+
const result = await serviceInstance[method](queryParams);
|
|
57
|
+
setData(result); // Now `data` is correctly typed!
|
|
58
|
+
return result;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
setError(err instanceof Error ? err : new Error("An error occurred"));
|
|
61
|
+
} finally {
|
|
62
|
+
setIsLoading(false);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[service, method],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Serialize params for stable comparison
|
|
69
|
+
const paramsJson = JSON.stringify(params);
|
|
64
70
|
|
|
65
71
|
useEffect(() => {
|
|
66
72
|
if (fetchInitially) {
|
|
67
73
|
runQuery(params);
|
|
68
74
|
}
|
|
69
|
-
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
}, [runQuery, fetchInitially, paramsJson]);
|
|
70
77
|
|
|
71
78
|
return { data, error, isLoading, runQuery };
|
|
72
79
|
}
|
|
@@ -7,6 +7,7 @@ import { viemToThirdwebChain } from "@b3dotfun/sdk/shared/constants/chains/b3Cha
|
|
|
7
7
|
import { getChainById } from "@b3dotfun/sdk/shared/utils/chains";
|
|
8
8
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
9
9
|
import { getWalletBalance } from "thirdweb/wallets";
|
|
10
|
+
import invariant from "invariant";
|
|
10
11
|
|
|
11
12
|
type GetWalletBalanceResult = {
|
|
12
13
|
value: bigint;
|
|
@@ -51,10 +52,12 @@ export function useTokenBalancesByChain({
|
|
|
51
52
|
// Fetch native token balances
|
|
52
53
|
Promise.all(
|
|
53
54
|
chainIds.map(async chainId => {
|
|
55
|
+
const chain = getChainById(chainId);
|
|
56
|
+
invariant(chain, "Chain is required");
|
|
54
57
|
const walletBalance = await getWalletBalance({
|
|
55
58
|
address,
|
|
56
59
|
client,
|
|
57
|
-
chain: viemToThirdwebChain(
|
|
60
|
+
chain: viemToThirdwebChain(chain),
|
|
58
61
|
});
|
|
59
62
|
|
|
60
63
|
return {
|
|
@@ -69,7 +69,7 @@ export function useTokenFromUrl({ defaultToken, prefix }: UseTokenFromUrlOptions
|
|
|
69
69
|
|
|
70
70
|
const { data: tokenInfo, isError } = useQuery({
|
|
71
71
|
queryKey: ["tokenInfo", network, currencyParam],
|
|
72
|
-
queryFn: () => fetchTokenInfo(network, currencyParam
|
|
72
|
+
queryFn: () => fetchTokenInfo(network, currencyParam || ""),
|
|
73
73
|
enabled: shouldFetchToken,
|
|
74
74
|
staleTime: Infinity,
|
|
75
75
|
gcTime: Infinity,
|
|
@@ -84,7 +84,7 @@ export function useTokenFromUrl({ defaultToken, prefix }: UseTokenFromUrlOptions
|
|
|
84
84
|
if (isError || !tokenInfo) {
|
|
85
85
|
return {
|
|
86
86
|
...defaultToken,
|
|
87
|
-
address: currencyParam
|
|
87
|
+
address: currencyParam || "",
|
|
88
88
|
chainId: Number(chainIdParam),
|
|
89
89
|
};
|
|
90
90
|
}
|
|
@@ -8,7 +8,7 @@ import { toast } from "sonner";
|
|
|
8
8
|
import { prepareTransaction, sendTransaction as twSendTransaction } from "thirdweb";
|
|
9
9
|
import { useActiveWallet } from "thirdweb/react";
|
|
10
10
|
import { isAddress } from "viem";
|
|
11
|
-
import { useSwitchChain
|
|
11
|
+
import { useSwitchChain } from "wagmi";
|
|
12
12
|
import { useB3 } from "../components";
|
|
13
13
|
import { useAccountWallet } from "./useAccountWallet";
|
|
14
14
|
|
|
@@ -27,7 +27,6 @@ const partnerId = String(
|
|
|
27
27
|
invariant(partnerId, "Partner ID is required");
|
|
28
28
|
|
|
29
29
|
export function useUnifiedChainSwitchAndExecute() {
|
|
30
|
-
const { data: walletClient } = useWalletClient();
|
|
31
30
|
const { switchChainAsync } = useSwitchChain();
|
|
32
31
|
const [isSwitchingOrExecuting, setIsSwitchingOrExecuting] = useState(false);
|
|
33
32
|
const activeWallet = useActiveWallet();
|
|
@@ -122,7 +121,7 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
122
121
|
setIsSwitchingOrExecuting(false);
|
|
123
122
|
}
|
|
124
123
|
},
|
|
125
|
-
[
|
|
124
|
+
[connectedEOAWallet, activeWallet, switchChainAsync],
|
|
126
125
|
);
|
|
127
126
|
|
|
128
127
|
// Handle AA wallet transaction (no chain switch needed for AA)
|
|
@@ -19,7 +19,7 @@ export interface AssetBalance {
|
|
|
19
19
|
chainBalances: ChainBalance[];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const fetchBalances = async (address: string, testnet?: boolean): Promise<AssetBalance[]> => {
|
|
22
|
+
export const fetchBalances = async (address: string | undefined, testnet?: boolean): Promise<AssetBalance[]> => {
|
|
23
23
|
if (!address) return [];
|
|
24
24
|
|
|
25
25
|
const assetsResponse = await fetch(`${getSprinterBaseUrl(testnet)}/assets/fungible`);
|