@b3dotfun/sdk 0.0.62-alpha.1 → 0.0.62-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.
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +5 -4
- package/dist/cjs/global-account/react/hooks/useSimBalance.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useSimBalance.js +6 -5
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +7 -6
- package/dist/esm/global-account/react/hooks/useSimBalance.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useSimBalance.js +6 -5
- package/dist/types/global-account/react/hooks/useSimBalance.d.ts +1 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpendStakeB3.tsx +8 -11
- package/src/global-account/react/hooks/useSimBalance.ts +6 -5
|
@@ -38,13 +38,14 @@ function generateEncodedDataForStakingB3(amount, beneficiary) {
|
|
|
38
38
|
function AnySpendStakeB3({ loadOrder, mode = "modal", recipientAddress, stakeAmount, onSuccess, }) {
|
|
39
39
|
const hasMounted = (0, react_1.useHasMounted)();
|
|
40
40
|
const { setB3ModalOpen } = (0, react_1.useModalStore)();
|
|
41
|
-
// Fetch B3 token balance
|
|
42
|
-
const { formattedBalance: b3Balance, isLoading: isBalanceLoading, rawBalance: b3RawBalance, } = (0, react_1.useTokenBalance)({
|
|
43
|
-
token: anyspend_1.B3_TOKEN,
|
|
44
|
-
});
|
|
45
41
|
// Wagmi hooks for direct staking
|
|
46
42
|
const { address } = (0, wagmi_1.useAccount)();
|
|
47
43
|
const { switchChainAndExecute, isSwitchingOrExecuting } = (0, react_1.useUnifiedChainSwitchAndExecute)();
|
|
44
|
+
// Fetch B3 token balance
|
|
45
|
+
const { data: simBalance, isLoading: isBalanceLoading } = (0, react_1.useSimBalance)(address, [chains_1.base.id]);
|
|
46
|
+
const b3RawBalanceStr = simBalance?.balances.find(b => (0, anyspend_1.eqci)(b.address, anyspend_1.B3_TOKEN.address))?.amount || "0";
|
|
47
|
+
const b3RawBalance = BigInt(b3RawBalanceStr);
|
|
48
|
+
const b3Balance = (0, number_1.formatTokenAmount)(b3RawBalance, anyspend_1.B3_TOKEN.decimals);
|
|
48
49
|
// State for direct staking flow
|
|
49
50
|
const [isStaking, setIsStaking] = (0, react_3.useState)(false);
|
|
50
51
|
const [stakingTxHash, setStakingTxHash] = (0, react_3.useState)("");
|
|
@@ -21,4 +21,4 @@ export interface SimBalanceResponse {
|
|
|
21
21
|
wallet_address: string;
|
|
22
22
|
balances: SimBalanceItem[];
|
|
23
23
|
}
|
|
24
|
-
export declare function useSimBalance(address?: string): import("@tanstack/react-query").UseQueryResult<SimBalanceResponse, Error>;
|
|
24
|
+
export declare function useSimBalance(address?: string, chainIdsParam?: number[]): import("@tanstack/react-query").UseQueryResult<SimBalanceResponse, Error>;
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSimBalance = useSimBalance;
|
|
4
4
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
|
-
async function fetchSimBalance(address) {
|
|
5
|
+
async function fetchSimBalance(address, chainIdsParam) {
|
|
6
6
|
if (!address)
|
|
7
7
|
throw new Error("Address is required");
|
|
8
|
-
|
|
8
|
+
const chainIds = chainIdsParam.length === 0 ? "mainnet" : chainIdsParam.join(",");
|
|
9
|
+
let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${address}?metadata=logo&chain_ids=${chainIds}`;
|
|
9
10
|
if (process.env.NEXT_PUBLIC_LOCAL_KEY) {
|
|
10
11
|
url += `&localkey=${process.env.NEXT_PUBLIC_LOCAL_KEY}`;
|
|
11
12
|
}
|
|
@@ -16,13 +17,13 @@ async function fetchSimBalance(address) {
|
|
|
16
17
|
const balanceData = await response.json();
|
|
17
18
|
return balanceData;
|
|
18
19
|
}
|
|
19
|
-
function useSimBalance(address) {
|
|
20
|
+
function useSimBalance(address, chainIdsParam) {
|
|
20
21
|
return (0, react_query_1.useQuery)({
|
|
21
|
-
queryKey: ["simBalance", address],
|
|
22
|
+
queryKey: ["simBalance", address, chainIdsParam],
|
|
22
23
|
queryFn: () => {
|
|
23
24
|
if (!address)
|
|
24
25
|
throw new Error("Address is required");
|
|
25
|
-
return fetchSimBalance(address);
|
|
26
|
+
return fetchSimBalance(address, chainIdsParam || []);
|
|
26
27
|
},
|
|
27
28
|
enabled: Boolean(address),
|
|
28
29
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { ABI_ERC20_STAKING, B3_TOKEN } from "../../../anyspend/index.js";
|
|
3
|
-
import { Button, GlareCardRounded, Input, StyleRoot, TextLoop, useHasMounted, useModalStore,
|
|
2
|
+
import { ABI_ERC20_STAKING, B3_TOKEN, eqci } from "../../../anyspend/index.js";
|
|
3
|
+
import { Button, GlareCardRounded, Input, StyleRoot, TextLoop, useHasMounted, useModalStore, useSimBalance, useUnifiedChainSwitchAndExecute, } from "../../../global-account/react/index.js";
|
|
4
4
|
import { PUBLIC_BASE_RPC_URL } from "../../../shared/constants/index.js";
|
|
5
5
|
import { formatTokenAmount } from "../../../shared/utils/number.js";
|
|
6
6
|
import invariant from "invariant";
|
|
@@ -32,13 +32,14 @@ function generateEncodedDataForStakingB3(amount, beneficiary) {
|
|
|
32
32
|
export function AnySpendStakeB3({ loadOrder, mode = "modal", recipientAddress, stakeAmount, onSuccess, }) {
|
|
33
33
|
const hasMounted = useHasMounted();
|
|
34
34
|
const { setB3ModalOpen } = useModalStore();
|
|
35
|
-
// Fetch B3 token balance
|
|
36
|
-
const { formattedBalance: b3Balance, isLoading: isBalanceLoading, rawBalance: b3RawBalance, } = useTokenBalance({
|
|
37
|
-
token: B3_TOKEN,
|
|
38
|
-
});
|
|
39
35
|
// Wagmi hooks for direct staking
|
|
40
36
|
const { address } = useAccount();
|
|
41
37
|
const { switchChainAndExecute, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
38
|
+
// Fetch B3 token balance
|
|
39
|
+
const { data: simBalance, isLoading: isBalanceLoading } = useSimBalance(address, [base.id]);
|
|
40
|
+
const b3RawBalanceStr = simBalance?.balances.find(b => eqci(b.address, B3_TOKEN.address))?.amount || "0";
|
|
41
|
+
const b3RawBalance = BigInt(b3RawBalanceStr);
|
|
42
|
+
const b3Balance = formatTokenAmount(b3RawBalance, B3_TOKEN.decimals);
|
|
42
43
|
// State for direct staking flow
|
|
43
44
|
const [isStaking, setIsStaking] = useState(false);
|
|
44
45
|
const [stakingTxHash, setStakingTxHash] = useState("");
|
|
@@ -21,4 +21,4 @@ export interface SimBalanceResponse {
|
|
|
21
21
|
wallet_address: string;
|
|
22
22
|
balances: SimBalanceItem[];
|
|
23
23
|
}
|
|
24
|
-
export declare function useSimBalance(address?: string): import("@tanstack/react-query").UseQueryResult<SimBalanceResponse, Error>;
|
|
24
|
+
export declare function useSimBalance(address?: string, chainIdsParam?: number[]): import("@tanstack/react-query").UseQueryResult<SimBalanceResponse, Error>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
async function fetchSimBalance(address) {
|
|
2
|
+
async function fetchSimBalance(address, chainIdsParam) {
|
|
3
3
|
if (!address)
|
|
4
4
|
throw new Error("Address is required");
|
|
5
|
-
|
|
5
|
+
const chainIds = chainIdsParam.length === 0 ? "mainnet" : chainIdsParam.join(",");
|
|
6
|
+
let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${address}?metadata=logo&chain_ids=${chainIds}`;
|
|
6
7
|
if (process.env.NEXT_PUBLIC_LOCAL_KEY) {
|
|
7
8
|
url += `&localkey=${process.env.NEXT_PUBLIC_LOCAL_KEY}`;
|
|
8
9
|
}
|
|
@@ -13,13 +14,13 @@ async function fetchSimBalance(address) {
|
|
|
13
14
|
const balanceData = await response.json();
|
|
14
15
|
return balanceData;
|
|
15
16
|
}
|
|
16
|
-
export function useSimBalance(address) {
|
|
17
|
+
export function useSimBalance(address, chainIdsParam) {
|
|
17
18
|
return useQuery({
|
|
18
|
-
queryKey: ["simBalance", address],
|
|
19
|
+
queryKey: ["simBalance", address, chainIdsParam],
|
|
19
20
|
queryFn: () => {
|
|
20
21
|
if (!address)
|
|
21
22
|
throw new Error("Address is required");
|
|
22
|
-
return fetchSimBalance(address);
|
|
23
|
+
return fetchSimBalance(address, chainIdsParam || []);
|
|
23
24
|
},
|
|
24
25
|
enabled: Boolean(address),
|
|
25
26
|
});
|
|
@@ -21,4 +21,4 @@ export interface SimBalanceResponse {
|
|
|
21
21
|
wallet_address: string;
|
|
22
22
|
balances: SimBalanceItem[];
|
|
23
23
|
}
|
|
24
|
-
export declare function useSimBalance(address?: string): import("@tanstack/react-query").UseQueryResult<SimBalanceResponse, Error>;
|
|
24
|
+
export declare function useSimBalance(address?: string, chainIdsParam?: number[]): import("@tanstack/react-query").UseQueryResult<SimBalanceResponse, Error>;
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ABI_ERC20_STAKING, B3_TOKEN } from "@b3dotfun/sdk/anyspend";
|
|
1
|
+
import { ABI_ERC20_STAKING, B3_TOKEN, eqci } from "@b3dotfun/sdk/anyspend";
|
|
2
2
|
import {
|
|
3
3
|
Button,
|
|
4
4
|
GlareCardRounded,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
TextLoop,
|
|
8
8
|
useHasMounted,
|
|
9
9
|
useModalStore,
|
|
10
|
-
|
|
10
|
+
useSimBalance,
|
|
11
11
|
useUnifiedChainSwitchAndExecute,
|
|
12
12
|
} from "@b3dotfun/sdk/global-account/react";
|
|
13
13
|
import { PUBLIC_BASE_RPC_URL } from "@b3dotfun/sdk/shared/constants";
|
|
@@ -58,19 +58,16 @@ export function AnySpendStakeB3({
|
|
|
58
58
|
const hasMounted = useHasMounted();
|
|
59
59
|
const { setB3ModalOpen } = useModalStore();
|
|
60
60
|
|
|
61
|
-
// Fetch B3 token balance
|
|
62
|
-
const {
|
|
63
|
-
formattedBalance: b3Balance,
|
|
64
|
-
isLoading: isBalanceLoading,
|
|
65
|
-
rawBalance: b3RawBalance,
|
|
66
|
-
} = useTokenBalance({
|
|
67
|
-
token: B3_TOKEN,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
61
|
// Wagmi hooks for direct staking
|
|
71
62
|
const { address } = useAccount();
|
|
72
63
|
const { switchChainAndExecute, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
73
64
|
|
|
65
|
+
// Fetch B3 token balance
|
|
66
|
+
const { data: simBalance, isLoading: isBalanceLoading } = useSimBalance(address, [base.id]);
|
|
67
|
+
const b3RawBalanceStr = simBalance?.balances.find(b => eqci(b.address, B3_TOKEN.address))?.amount || "0";
|
|
68
|
+
const b3RawBalance = BigInt(b3RawBalanceStr);
|
|
69
|
+
const b3Balance = formatTokenAmount(b3RawBalance, B3_TOKEN.decimals);
|
|
70
|
+
|
|
74
71
|
// State for direct staking flow
|
|
75
72
|
const [isStaking, setIsStaking] = useState(false);
|
|
76
73
|
const [stakingTxHash, setStakingTxHash] = useState<string>("");
|
|
@@ -26,10 +26,11 @@ export interface SimBalanceResponse {
|
|
|
26
26
|
balances: SimBalanceItem[];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
async function fetchSimBalance(address: string): Promise<SimBalanceResponse> {
|
|
29
|
+
async function fetchSimBalance(address: string, chainIdsParam: number[]): Promise<SimBalanceResponse> {
|
|
30
30
|
if (!address) throw new Error("Address is required");
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
const chainIds = chainIdsParam.length === 0 ? "mainnet" : chainIdsParam.join(",");
|
|
33
|
+
let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${address}?metadata=logo&chain_ids=${chainIds}`;
|
|
33
34
|
if (process.env.NEXT_PUBLIC_LOCAL_KEY) {
|
|
34
35
|
url += `&localkey=${process.env.NEXT_PUBLIC_LOCAL_KEY}`;
|
|
35
36
|
}
|
|
@@ -44,12 +45,12 @@ async function fetchSimBalance(address: string): Promise<SimBalanceResponse> {
|
|
|
44
45
|
return balanceData;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
export function useSimBalance(address?: string) {
|
|
48
|
+
export function useSimBalance(address?: string, chainIdsParam?: number[]) {
|
|
48
49
|
return useQuery({
|
|
49
|
-
queryKey: ["simBalance", address],
|
|
50
|
+
queryKey: ["simBalance", address, chainIdsParam],
|
|
50
51
|
queryFn: () => {
|
|
51
52
|
if (!address) throw new Error("Address is required");
|
|
52
|
-
return fetchSimBalance(address);
|
|
53
|
+
return fetchSimBalance(address, chainIdsParam || []);
|
|
53
54
|
},
|
|
54
55
|
enabled: Boolean(address),
|
|
55
56
|
});
|