@b3dotfun/sdk 0.0.64 → 0.0.65-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.
- package/dist/cjs/anyspend/react/components/AnySpend.js +37 -23
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +22 -9
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +7 -11
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +1 -5
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +0 -4
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +15 -9
- package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
- package/dist/cjs/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/cjs/anyspend/react/hooks/useCryptoPaymentMethodState.js +51 -0
- package/dist/cjs/anyspend/utils/index.d.ts +0 -1
- package/dist/cjs/anyspend/utils/index.js +0 -1
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +4 -7
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +0 -11
- package/dist/cjs/global-account/react/hooks/useGlobalAccount.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/useGlobalAccount.js +3 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +37 -23
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +22 -9
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +8 -12
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +2 -6
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +1 -5
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +15 -9
- package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
- package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.js +48 -0
- package/dist/esm/anyspend/utils/index.d.ts +0 -1
- package/dist/esm/anyspend/utils/index.js +0 -1
- package/dist/esm/global-account/react/components/B3DynamicModal.js +5 -8
- package/dist/esm/global-account/react/hooks/useAuthentication.js +0 -11
- package/dist/esm/global-account/react/hooks/useGlobalAccount.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/useGlobalAccount.js +3 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/types/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/types/anyspend/utils/index.d.ts +0 -1
- package/dist/types/global-account/react/hooks/useGlobalAccount.d.ts +1 -0
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +49 -28
- package/src/anyspend/react/components/AnySpendCustom.tsx +28 -15
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +9 -12
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +2 -6
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +1 -6
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +23 -11
- package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +20 -12
- package/src/anyspend/react/hooks/useCryptoPaymentMethodState.ts +71 -0
- package/src/anyspend/utils/index.ts +0 -1
- package/src/global-account/react/components/B3DynamicModal.tsx +5 -9
- package/src/global-account/react/hooks/useAuthentication.ts +0 -12
- package/src/global-account/react/hooks/useGlobalAccount.tsx +3 -1
- package/dist/cjs/anyspend/utils/accountStore.d.ts +0 -7
- package/dist/cjs/anyspend/utils/accountStore.js +0 -8
- package/dist/esm/anyspend/utils/accountStore.d.ts +0 -7
- package/dist/esm/anyspend/utils/accountStore.js +0 -5
- package/dist/types/anyspend/utils/accountStore.d.ts +0 -7
- package/src/anyspend/utils/accountStore.ts +0 -12
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
3
|
+
|
|
4
|
+
interface UseCryptoPaymentMethodStateResult {
|
|
5
|
+
/** Auto-selected payment method based on balance */
|
|
6
|
+
cryptoPaymentMethod: CryptoPaymentMethodType;
|
|
7
|
+
/** Function to update the auto-selected payment method */
|
|
8
|
+
setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
9
|
+
/** User explicitly selected payment method (NONE means no explicit selection) */
|
|
10
|
+
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
11
|
+
/** Function to update the user-selected payment method */
|
|
12
|
+
setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
13
|
+
/** Effective payment method (user selection takes priority over auto-selection) */
|
|
14
|
+
effectiveCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
15
|
+
/** Reset both payment method states to NONE */
|
|
16
|
+
resetPaymentMethods: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Custom hook to manage crypto payment method state with dual-state system:
|
|
21
|
+
*
|
|
22
|
+
* - `cryptoPaymentMethod`: Auto-selected based on wallet availability and balance
|
|
23
|
+
* - `selectedCryptoPaymentMethod`: Explicitly selected by user
|
|
24
|
+
* - `effectiveCryptoPaymentMethod`: User selection takes priority over auto-selection
|
|
25
|
+
*
|
|
26
|
+
* This allows automatic payment method suggestions while respecting explicit user choices.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* const {
|
|
31
|
+
* cryptoPaymentMethod,
|
|
32
|
+
* setCryptoPaymentMethod,
|
|
33
|
+
* selectedCryptoPaymentMethod,
|
|
34
|
+
* setSelectedCryptoPaymentMethod,
|
|
35
|
+
* effectiveCryptoPaymentMethod,
|
|
36
|
+
* resetPaymentMethods
|
|
37
|
+
* } = useCryptoPaymentMethodState();
|
|
38
|
+
*
|
|
39
|
+
* // Use effectiveCryptoPaymentMethod for display
|
|
40
|
+
* // Use setSelectedCryptoPaymentMethod when user explicitly selects
|
|
41
|
+
* // Call resetPaymentMethods when switching tabs or going back
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function useCryptoPaymentMethodState(): UseCryptoPaymentMethodStateResult {
|
|
45
|
+
// cryptoPaymentMethod: auto-selected based on balance
|
|
46
|
+
const [cryptoPaymentMethod, setCryptoPaymentMethod] = useState<CryptoPaymentMethodType>(CryptoPaymentMethodType.NONE);
|
|
47
|
+
|
|
48
|
+
// selectedCryptoPaymentMethod: explicitly selected by user (NONE means no explicit selection)
|
|
49
|
+
const [selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod] = useState<CryptoPaymentMethodType>(
|
|
50
|
+
CryptoPaymentMethodType.NONE,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// The effective payment method (user selection takes priority over auto-selection)
|
|
54
|
+
const effectiveCryptoPaymentMethod =
|
|
55
|
+
selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE ? selectedCryptoPaymentMethod : cryptoPaymentMethod;
|
|
56
|
+
|
|
57
|
+
// Helper function to reset both states
|
|
58
|
+
const resetPaymentMethods = () => {
|
|
59
|
+
setCryptoPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
60
|
+
setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
cryptoPaymentMethod,
|
|
65
|
+
setCryptoPaymentMethod,
|
|
66
|
+
selectedCryptoPaymentMethod,
|
|
67
|
+
setSelectedCryptoPaymentMethod,
|
|
68
|
+
effectiveCryptoPaymentMethod,
|
|
69
|
+
resetPaymentMethods,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -12,8 +12,7 @@ import {
|
|
|
12
12
|
import { AnySpendDepositHype } from "@b3dotfun/sdk/anyspend/react/components/AnyspendDepositHype";
|
|
13
13
|
import { AnySpendStakeUpside } from "@b3dotfun/sdk/anyspend/react/components/AnySpendStakeUpside";
|
|
14
14
|
import { AnySpendStakeUpsideExactIn } from "@b3dotfun/sdk/anyspend/react/components/AnySpendStakeUpsideExactIn";
|
|
15
|
-
import {
|
|
16
|
-
import { useIsMobile, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
15
|
+
import { useGlobalAccount, useIsMobile, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
17
16
|
import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
18
17
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
19
18
|
import { useEffect, useRef } from "react";
|
|
@@ -35,22 +34,19 @@ export function B3DynamicModal() {
|
|
|
35
34
|
const { theme } = useB3();
|
|
36
35
|
const isMobile = useIsMobile();
|
|
37
36
|
const prevIsOpenRef = useRef(isOpen);
|
|
38
|
-
|
|
39
|
-
const globalAccountWallet = useGlobalWalletState(state => state.globalAccountWallet);
|
|
40
|
-
const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
|
|
37
|
+
const { wallet } = useGlobalAccount();
|
|
41
38
|
const setActiveWallet = useSetActiveWallet();
|
|
42
39
|
|
|
43
40
|
// anyspend cleanup global account chnages by setting account back
|
|
44
41
|
useEffect(() => {
|
|
45
42
|
if (prevIsOpenRef.current && !isOpen) {
|
|
46
|
-
if (
|
|
47
|
-
setActiveWallet(
|
|
48
|
-
setGlobalAccountWallet(undefined);
|
|
43
|
+
if (wallet) {
|
|
44
|
+
setActiveWallet(wallet);
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
prevIsOpenRef.current = isOpen;
|
|
53
|
-
}, [isOpen,
|
|
49
|
+
}, [isOpen, wallet, setActiveWallet]);
|
|
54
50
|
|
|
55
51
|
// Define arrays for different modal type groups
|
|
56
52
|
const fullWidthTypes = [
|
|
@@ -48,18 +48,6 @@ export function useAuthentication(partnerId: string) {
|
|
|
48
48
|
const { switchAccount } = useSwitchAccount();
|
|
49
49
|
debug("@@activeWagmiAccount", activeWagmiAccount);
|
|
50
50
|
|
|
51
|
-
// Check localStorage version and clear if not found or mismatched
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (typeof localStorage !== "undefined") {
|
|
54
|
-
const version = localStorage.getItem("version");
|
|
55
|
-
if (version !== "1") {
|
|
56
|
-
debug("@@localStorage:clearing due to version mismatch", { version });
|
|
57
|
-
localStorage.clear();
|
|
58
|
-
localStorage.setItem("version", "1");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, []);
|
|
62
|
-
|
|
63
51
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
64
52
|
partnerId: partnerId,
|
|
65
53
|
});
|
|
@@ -10,6 +10,7 @@ export function useGlobalAccount() {
|
|
|
10
10
|
const wallets = useConnectedWallets();
|
|
11
11
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
12
12
|
const [globalAccount, setGlobalAccount] = useState<Wallet | undefined>(undefined);
|
|
13
|
+
const [globalAccountWallet, setGlobalAccountWallet] = useState<Wallet | undefined>(undefined);
|
|
13
14
|
const [address, setAddress] = useState<string | undefined>(undefined);
|
|
14
15
|
const walletInfo = useWalletInfo(globalAccount?.id);
|
|
15
16
|
|
|
@@ -22,7 +23,7 @@ export function useGlobalAccount() {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const globalAccountWallet = wallets.find(wallet => wallet.id.startsWith("ecosystem."));
|
|
25
|
-
|
|
26
|
+
setGlobalAccountWallet(globalAccountWallet);
|
|
26
27
|
const account = globalAccountWallet?.getAccount();
|
|
27
28
|
setGlobalAccount(globalAccountWallet);
|
|
28
29
|
setAddress(account?.address);
|
|
@@ -32,5 +33,6 @@ export function useGlobalAccount() {
|
|
|
32
33
|
account: globalAccount,
|
|
33
34
|
address,
|
|
34
35
|
info: walletInfo,
|
|
36
|
+
wallet: globalAccountWallet,
|
|
35
37
|
};
|
|
36
38
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Wallet } from "thirdweb/wallets";
|
|
2
|
-
interface GlobalWalletState {
|
|
3
|
-
globalAccountWallet?: Wallet;
|
|
4
|
-
setGlobalAccountWallet: (account?: Wallet) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare const useGlobalWalletState: import("zustand").UseBoundStore<import("zustand").StoreApi<GlobalWalletState>>;
|
|
7
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useGlobalWalletState = void 0;
|
|
4
|
-
const zustand_1 = require("zustand");
|
|
5
|
-
exports.useGlobalWalletState = (0, zustand_1.create)(set => ({
|
|
6
|
-
globalAccountWallet: undefined,
|
|
7
|
-
setGlobalAccountWallet: account => set({ globalAccountWallet: account }),
|
|
8
|
-
}));
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Wallet } from "thirdweb/wallets";
|
|
2
|
-
interface GlobalWalletState {
|
|
3
|
-
globalAccountWallet?: Wallet;
|
|
4
|
-
setGlobalAccountWallet: (account?: Wallet) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare const useGlobalWalletState: import("zustand").UseBoundStore<import("zustand").StoreApi<GlobalWalletState>>;
|
|
7
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Wallet } from "thirdweb/wallets";
|
|
2
|
-
interface GlobalWalletState {
|
|
3
|
-
globalAccountWallet?: Wallet;
|
|
4
|
-
setGlobalAccountWallet: (account?: Wallet) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare const useGlobalWalletState: import("zustand").UseBoundStore<import("zustand").StoreApi<GlobalWalletState>>;
|
|
7
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Wallet } from "thirdweb/wallets";
|
|
2
|
-
import { create } from "zustand";
|
|
3
|
-
|
|
4
|
-
interface GlobalWalletState {
|
|
5
|
-
globalAccountWallet?: Wallet;
|
|
6
|
-
setGlobalAccountWallet: (account?: Wallet) => void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const useGlobalWalletState = create<GlobalWalletState>(set => ({
|
|
10
|
-
globalAccountWallet: undefined,
|
|
11
|
-
setGlobalAccountWallet: account => set({ globalAccountWallet: account }),
|
|
12
|
-
}));
|