@b3dotfun/sdk 0.0.22-alpha.1 → 0.0.22-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/global-account/react/components/ManageAccount/ManageAccount.js +9 -2
- package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +6 -0
- package/dist/cjs/global-account/react/hooks/useFirstEOA.js +39 -0
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +8 -4
- package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +6 -0
- package/dist/esm/global-account/react/hooks/useFirstEOA.js +36 -0
- package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +6 -0
- package/package.json +1 -1
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +48 -16
- package/src/global-account/react/hooks/useFirstEOA.tsx +44 -0
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ManageAccount = ManageAccount;
|
|
4
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
@@ -9,6 +12,7 @@ const lucide_react_1 = require("lucide-react");
|
|
|
9
12
|
const react_2 = require("react");
|
|
10
13
|
const react_3 = require("thirdweb/react");
|
|
11
14
|
const viem_1 = require("viem");
|
|
15
|
+
const useFirstEOA_1 = __importDefault(require("../../hooks/useFirstEOA"));
|
|
12
16
|
const AccountAssets_1 = require("../AccountAssets/AccountAssets");
|
|
13
17
|
function centerTruncate(str, length = 4) {
|
|
14
18
|
if (str.length <= length * 2)
|
|
@@ -16,12 +20,16 @@ function centerTruncate(str, length = 4) {
|
|
|
16
20
|
return `${str.slice(0, length)}...${str.slice(-length)}`;
|
|
17
21
|
}
|
|
18
22
|
function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit, chain, partnerId, }) {
|
|
23
|
+
const { automaticallySetFirstEoa } = (0, react_1.useB3)();
|
|
19
24
|
const [activeTab, setActiveTab] = (0, react_2.useState)("balance");
|
|
20
25
|
const [revokingSignerId, setRevokingSignerId] = (0, react_2.useState)(null);
|
|
21
26
|
const account = (0, react_3.useActiveAccount)();
|
|
27
|
+
const { address: eoaAddress, info: { data: eoaInfo }, } = (0, useFirstEOA_1.default)();
|
|
22
28
|
const { data: assets, isLoading } = (0, react_1.useAccountAssets)(account?.address);
|
|
23
29
|
const { data: b3Balance } = (0, react_1.useB3BalanceFromAddresses)(account?.address);
|
|
24
30
|
const { data: nativeBalance } = (0, react_1.useNativeBalance)(account?.address);
|
|
31
|
+
const { data: eoaNativeBalance } = (0, react_1.useNativeBalance)(eoaAddress);
|
|
32
|
+
const { data: eoaB3Balance } = (0, react_1.useB3BalanceFromAddresses)(eoaAddress);
|
|
25
33
|
const { data: signers, refetch: refetchSigners } = (0, react_1.useGetAllTWSigners)({
|
|
26
34
|
chain,
|
|
27
35
|
accountAddress: account?.address,
|
|
@@ -29,7 +37,6 @@ function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit, chain
|
|
|
29
37
|
const { setB3ModalOpen, setB3ModalContentType } = (0, react_1.useModalStore)();
|
|
30
38
|
const { logout } = (0, react_1.useAuthentication)(partnerId);
|
|
31
39
|
const [logoutLoading, setLogoutLoading] = (0, react_2.useState)(false);
|
|
32
|
-
console.log("@@assets", assets);
|
|
33
40
|
const { removeSessionKey } = (0, react_1.useRemoveSessionKey)({
|
|
34
41
|
chain,
|
|
35
42
|
onSuccess: tx => {
|
|
@@ -53,7 +60,7 @@ function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit, chain
|
|
|
53
60
|
setB3ModalOpen(false);
|
|
54
61
|
setLogoutLoading(false);
|
|
55
62
|
};
|
|
56
|
-
const BalanceContent = () => ((0, jsx_runtime_1.jsxs)("div", { className: "flex h-full flex-col items-center justify-between gap-8", children: [(0, jsx_runtime_1.jsx)("div", { className: "w-full", children: (0, jsx_runtime_1.jsxs)("div", { className: "border-b3-react-border bg-b3-react-subtle flex flex-col rounded-lg border p-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-4 flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/b3_logo.svg", alt: "B3", className: "h-6 w-6" }), (0, jsx_runtime_1.jsx)("h2", { className: "font-neue-montreal-bold text-b3-react-primary text-lg", children: "Global Account" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-2", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-b3-react-secondary-foreground text-sm", children: "Your universal account for all B3-powered apps" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-b3-react-muted-foreground font-mono text-sm", children: centerTruncate(account?.address || "", 6) }), (0, jsx_runtime_1.jsx)(react_1.CopyToClipboard, { text: account?.address || "" })] })] })] }) }), (0, jsx_runtime_1.
|
|
63
|
+
const BalanceContent = () => ((0, jsx_runtime_1.jsxs)("div", { className: "flex h-full flex-col items-center justify-between gap-8", children: [(0, jsx_runtime_1.jsx)("div", { className: "w-full", children: (0, jsx_runtime_1.jsxs)("div", { className: "border-b3-react-border bg-b3-react-subtle flex flex-col rounded-lg border p-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-4 flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/b3_logo.svg", alt: "B3", className: "h-6 w-6" }), (0, jsx_runtime_1.jsx)("h2", { className: "font-neue-montreal-bold text-b3-react-primary text-lg", children: "Global Account" })] }), !automaticallySetFirstEoa && ((0, jsx_runtime_1.jsxs)("div", { className: "mb-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-4", children: [(0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/b3-coin-3d.png", alt: "B3", className: "h-10 w-10" }), (0, jsx_runtime_1.jsxs)("span", { className: "font-neue-montreal-bold text-2xl", children: [b3Balance?.formattedTotal || "--", " B3"] })] }), (0, jsx_runtime_1.jsx)("div", { className: "border-b3-react-border my-4 border-t" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-4", children: [(0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/ethereum.svg", alt: "ETH", className: "h-10 w-10" }), (0, jsx_runtime_1.jsxs)("span", { className: "font-neue-montreal-bold text-2xl", children: [nativeBalance?.formattedTotal || "--", " ETH"] })] })] })), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-2", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-b3-react-secondary-foreground text-sm", children: "Your universal account for all B3-powered apps" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-b3-react-muted-foreground font-mono text-sm", children: centerTruncate(account?.address || "", 6) }), (0, jsx_runtime_1.jsx)(react_1.CopyToClipboard, { text: account?.address || "" })] })] })] }) }), (0, jsx_runtime_1.jsx)("div", { className: "border-b3-react-border bg-b3-react-subtle w-full rounded-lg border p-4", children: eoaAddress && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("h3", { className: "font-neue-montreal-bold text-b3-react-primary mb-2", children: ["Connected ", eoaInfo?.name] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-4", children: [(0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/ethereum.svg", alt: "ETH", className: "h-10 w-10" }), (0, jsx_runtime_1.jsxs)("span", { className: "font-neue-montreal-bold text-2xl", children: [eoaNativeBalance?.formattedTotal || "--", " ETH"] })] }), (0, jsx_runtime_1.jsx)("div", { className: "border-b3-react-border my-4 border-t" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-4", children: [(0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/b3-coin-3d.png", alt: "B3", className: "h-10 w-10" }), (0, jsx_runtime_1.jsxs)("span", { className: "font-neue-montreal-bold text-2xl", children: [eoaB3Balance?.formattedTotal || "--", " B3"] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "text-b3-react-muted-foreground mt-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "font-mono text-sm", children: centerTruncate(eoaAddress, 6) }), (0, jsx_runtime_1.jsx)(react_1.CopyToClipboard, { text: eoaAddress })] })] }) })) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex w-full gap-4", children: [(0, jsx_runtime_1.jsx)(react_1.Button, { className: "font-neue-montreal-medium flex-1", onClick: () => {
|
|
57
64
|
setB3ModalOpen(true);
|
|
58
65
|
setB3ModalContentType({
|
|
59
66
|
type: "anySpend",
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = useFirstEOA;
|
|
4
|
+
const react_1 = require("../../../global-account/react");
|
|
5
|
+
const react_2 = require("react");
|
|
6
|
+
const react_3 = require("thirdweb/react");
|
|
7
|
+
function useFirstEOA() {
|
|
8
|
+
const wallets = (0, react_3.useConnectedWallets)();
|
|
9
|
+
const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
|
|
10
|
+
const [firstEOA, setFirstEOA] = (0, react_2.useState)(undefined);
|
|
11
|
+
const [address, setAddress] = (0, react_2.useState)(undefined);
|
|
12
|
+
const walletInfo = (0, react_3.useWalletInfo)(firstEOA?.id);
|
|
13
|
+
console.log("@@wallets", wallets);
|
|
14
|
+
console.log("@@wallets:isConnected", isConnected);
|
|
15
|
+
(0, react_2.useEffect)(() => {
|
|
16
|
+
const autoSelectFirstEOAWallet = async () => {
|
|
17
|
+
// Only proceed if auto-selection is enabled and user is authenticated
|
|
18
|
+
if (!isConnected) {
|
|
19
|
+
console.log("@@wallets:not connected");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Find the first EOA wallet (excluding ecosystem wallets)
|
|
23
|
+
const isEOAWallet = (wallet) => !wallet.id.startsWith("ecosystem.");
|
|
24
|
+
const firstEOAWallet = wallets.find(isEOAWallet);
|
|
25
|
+
console.log("@@wallets:firstEOAWallet", firstEOAWallet);
|
|
26
|
+
const account = await firstEOAWallet?.getAccount();
|
|
27
|
+
console.log("@@wallets:account", account);
|
|
28
|
+
setFirstEOA(firstEOAWallet);
|
|
29
|
+
console.log("@@wallets:address", account?.address);
|
|
30
|
+
setAddress(account?.address);
|
|
31
|
+
};
|
|
32
|
+
autoSelectFirstEOAWallet();
|
|
33
|
+
}, [isConnected, wallets]);
|
|
34
|
+
return {
|
|
35
|
+
account: firstEOA,
|
|
36
|
+
address,
|
|
37
|
+
info: walletInfo,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, CopyToClipboard,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Button, CopyToClipboard, TabsContentPrimitive, TabsListPrimitive, TabsPrimitive, TabTriggerPrimitive, useAccountAssets, useAuthentication, useB3, useB3BalanceFromAddresses, useGetAllTWSigners, useModalStore, useNativeBalance, useRemoveSessionKey, } from "../../../../global-account/react/index.js";
|
|
3
3
|
import { formatAddress } from "../../../../shared/utils/formatAddress.js";
|
|
4
4
|
import { formatNumber } from "../../../../shared/utils/formatNumber.js";
|
|
5
5
|
import { ArrowRightLeft } from "lucide-react";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { useActiveAccount } from "thirdweb/react";
|
|
8
8
|
import { formatUnits } from "viem";
|
|
9
|
+
import useFirstEOA from "../../hooks/useFirstEOA.js";
|
|
9
10
|
import { AccountAssets } from "../AccountAssets/AccountAssets.js";
|
|
10
11
|
function centerTruncate(str, length = 4) {
|
|
11
12
|
if (str.length <= length * 2)
|
|
@@ -13,12 +14,16 @@ function centerTruncate(str, length = 4) {
|
|
|
13
14
|
return `${str.slice(0, length)}...${str.slice(-length)}`;
|
|
14
15
|
}
|
|
15
16
|
export function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit, chain, partnerId, }) {
|
|
17
|
+
const { automaticallySetFirstEoa } = useB3();
|
|
16
18
|
const [activeTab, setActiveTab] = useState("balance");
|
|
17
19
|
const [revokingSignerId, setRevokingSignerId] = useState(null);
|
|
18
20
|
const account = useActiveAccount();
|
|
21
|
+
const { address: eoaAddress, info: { data: eoaInfo }, } = useFirstEOA();
|
|
19
22
|
const { data: assets, isLoading } = useAccountAssets(account?.address);
|
|
20
23
|
const { data: b3Balance } = useB3BalanceFromAddresses(account?.address);
|
|
21
24
|
const { data: nativeBalance } = useNativeBalance(account?.address);
|
|
25
|
+
const { data: eoaNativeBalance } = useNativeBalance(eoaAddress);
|
|
26
|
+
const { data: eoaB3Balance } = useB3BalanceFromAddresses(eoaAddress);
|
|
22
27
|
const { data: signers, refetch: refetchSigners } = useGetAllTWSigners({
|
|
23
28
|
chain,
|
|
24
29
|
accountAddress: account?.address,
|
|
@@ -26,7 +31,6 @@ export function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit
|
|
|
26
31
|
const { setB3ModalOpen, setB3ModalContentType } = useModalStore();
|
|
27
32
|
const { logout } = useAuthentication(partnerId);
|
|
28
33
|
const [logoutLoading, setLogoutLoading] = useState(false);
|
|
29
|
-
console.log("@@assets", assets);
|
|
30
34
|
const { removeSessionKey } = useRemoveSessionKey({
|
|
31
35
|
chain,
|
|
32
36
|
onSuccess: tx => {
|
|
@@ -50,7 +54,7 @@ export function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit
|
|
|
50
54
|
setB3ModalOpen(false);
|
|
51
55
|
setLogoutLoading(false);
|
|
52
56
|
};
|
|
53
|
-
const BalanceContent = () => (_jsxs("div", { className: "flex h-full flex-col items-center justify-between gap-8", children: [_jsx("div", { className: "w-full", children: _jsxs("div", { className: "border-b3-react-border bg-b3-react-subtle flex flex-col rounded-lg border p-4", children: [_jsxs("div", { className: "mb-4 flex items-center gap-3", children: [_jsx("img", { src: "https://cdn.b3.fun/b3_logo.svg", alt: "B3", className: "h-6 w-6" }), _jsx("h2", { className: "font-neue-montreal-bold text-b3-react-primary text-lg", children: "Global Account" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("p", { className: "text-b3-react-secondary-foreground text-sm", children: "Your universal account for all B3-powered apps" }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-b3-react-muted-foreground font-mono text-sm", children: centerTruncate(account?.address || "", 6) }), _jsx(CopyToClipboard, { text: account?.address || "" })] })] })] }) }),
|
|
57
|
+
const BalanceContent = () => (_jsxs("div", { className: "flex h-full flex-col items-center justify-between gap-8", children: [_jsx("div", { className: "w-full", children: _jsxs("div", { className: "border-b3-react-border bg-b3-react-subtle flex flex-col rounded-lg border p-4", children: [_jsxs("div", { className: "mb-4 flex items-center gap-3", children: [_jsx("img", { src: "https://cdn.b3.fun/b3_logo.svg", alt: "B3", className: "h-6 w-6" }), _jsx("h2", { className: "font-neue-montreal-bold text-b3-react-primary text-lg", children: "Global Account" })] }), !automaticallySetFirstEoa && (_jsxs("div", { className: "mb-4", children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx("img", { src: "https://cdn.b3.fun/b3-coin-3d.png", alt: "B3", className: "h-10 w-10" }), _jsxs("span", { className: "font-neue-montreal-bold text-2xl", children: [b3Balance?.formattedTotal || "--", " B3"] })] }), _jsx("div", { className: "border-b3-react-border my-4 border-t" }), _jsxs("div", { className: "flex items-center gap-4", children: [_jsx("img", { src: "https://cdn.b3.fun/ethereum.svg", alt: "ETH", className: "h-10 w-10" }), _jsxs("span", { className: "font-neue-montreal-bold text-2xl", children: [nativeBalance?.formattedTotal || "--", " ETH"] })] })] })), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("p", { className: "text-b3-react-secondary-foreground text-sm", children: "Your universal account for all B3-powered apps" }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-b3-react-muted-foreground font-mono text-sm", children: centerTruncate(account?.address || "", 6) }), _jsx(CopyToClipboard, { text: account?.address || "" })] })] })] }) }), _jsx("div", { className: "border-b3-react-border bg-b3-react-subtle w-full rounded-lg border p-4", children: eoaAddress && (_jsx(_Fragment, { children: _jsxs("div", { children: [_jsxs("h3", { className: "font-neue-montreal-bold text-b3-react-primary mb-2", children: ["Connected ", eoaInfo?.name] }), _jsxs("div", { className: "flex items-center gap-4", children: [_jsx("img", { src: "https://cdn.b3.fun/ethereum.svg", alt: "ETH", className: "h-10 w-10" }), _jsxs("span", { className: "font-neue-montreal-bold text-2xl", children: [eoaNativeBalance?.formattedTotal || "--", " ETH"] })] }), _jsx("div", { className: "border-b3-react-border my-4 border-t" }), _jsxs("div", { className: "flex items-center gap-4", children: [_jsx("img", { src: "https://cdn.b3.fun/b3-coin-3d.png", alt: "B3", className: "h-10 w-10" }), _jsxs("span", { className: "font-neue-montreal-bold text-2xl", children: [eoaB3Balance?.formattedTotal || "--", " B3"] })] }), _jsxs("div", { className: "text-b3-react-muted-foreground mt-2", children: [_jsx("span", { className: "font-mono text-sm", children: centerTruncate(eoaAddress, 6) }), _jsx(CopyToClipboard, { text: eoaAddress })] })] }) })) }), _jsxs("div", { className: "flex w-full gap-4", children: [_jsx(Button, { className: "font-neue-montreal-medium flex-1", onClick: () => {
|
|
54
58
|
setB3ModalOpen(true);
|
|
55
59
|
setB3ModalContentType({
|
|
56
60
|
type: "anySpend",
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useAuthStore } from "../../../global-account/react/index.js";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useConnectedWallets, useWalletInfo } from "thirdweb/react";
|
|
4
|
+
export default function useFirstEOA() {
|
|
5
|
+
const wallets = useConnectedWallets();
|
|
6
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
7
|
+
const [firstEOA, setFirstEOA] = useState(undefined);
|
|
8
|
+
const [address, setAddress] = useState(undefined);
|
|
9
|
+
const walletInfo = useWalletInfo(firstEOA?.id);
|
|
10
|
+
console.log("@@wallets", wallets);
|
|
11
|
+
console.log("@@wallets:isConnected", isConnected);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const autoSelectFirstEOAWallet = async () => {
|
|
14
|
+
// Only proceed if auto-selection is enabled and user is authenticated
|
|
15
|
+
if (!isConnected) {
|
|
16
|
+
console.log("@@wallets:not connected");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Find the first EOA wallet (excluding ecosystem wallets)
|
|
20
|
+
const isEOAWallet = (wallet) => !wallet.id.startsWith("ecosystem.");
|
|
21
|
+
const firstEOAWallet = wallets.find(isEOAWallet);
|
|
22
|
+
console.log("@@wallets:firstEOAWallet", firstEOAWallet);
|
|
23
|
+
const account = await firstEOAWallet?.getAccount();
|
|
24
|
+
console.log("@@wallets:account", account);
|
|
25
|
+
setFirstEOA(firstEOAWallet);
|
|
26
|
+
console.log("@@wallets:address", account?.address);
|
|
27
|
+
setAddress(account?.address);
|
|
28
|
+
};
|
|
29
|
+
autoSelectFirstEOAWallet();
|
|
30
|
+
}, [isConnected, wallets]);
|
|
31
|
+
return {
|
|
32
|
+
account: firstEOA,
|
|
33
|
+
address,
|
|
34
|
+
info: walletInfo,
|
|
35
|
+
};
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Button,
|
|
3
3
|
CopyToClipboard,
|
|
4
|
+
TabsContentPrimitive,
|
|
5
|
+
TabsListPrimitive,
|
|
6
|
+
TabsPrimitive,
|
|
7
|
+
TabTriggerPrimitive,
|
|
4
8
|
TWSignerWithMetadata,
|
|
5
9
|
useAccountAssets,
|
|
6
10
|
useAuthentication,
|
|
11
|
+
useB3,
|
|
7
12
|
useB3BalanceFromAddresses,
|
|
8
13
|
useGetAllTWSigners,
|
|
14
|
+
useModalStore,
|
|
9
15
|
useNativeBalance,
|
|
10
16
|
useRemoveSessionKey,
|
|
11
|
-
useModalStore,
|
|
12
|
-
TabsPrimitive,
|
|
13
|
-
TabsContentPrimitive,
|
|
14
|
-
TabsListPrimitive,
|
|
15
|
-
TabTriggerPrimitive,
|
|
16
17
|
} from "@b3dotfun/sdk/global-account/react";
|
|
17
18
|
import { formatAddress } from "@b3dotfun/sdk/shared/utils/formatAddress";
|
|
18
19
|
import { formatNumber } from "@b3dotfun/sdk/shared/utils/formatNumber";
|
|
@@ -21,6 +22,7 @@ import { useState } from "react";
|
|
|
21
22
|
import { Chain } from "thirdweb";
|
|
22
23
|
import { useActiveAccount } from "thirdweb/react";
|
|
23
24
|
import { formatUnits } from "viem";
|
|
25
|
+
import useFirstEOA from "../../hooks/useFirstEOA";
|
|
24
26
|
import { AccountAssets } from "../AccountAssets/AccountAssets";
|
|
25
27
|
|
|
26
28
|
interface ManageAccountProps {
|
|
@@ -44,12 +46,19 @@ export function ManageAccount({
|
|
|
44
46
|
chain,
|
|
45
47
|
partnerId,
|
|
46
48
|
}: ManageAccountProps) {
|
|
49
|
+
const { automaticallySetFirstEoa } = useB3();
|
|
47
50
|
const [activeTab, setActiveTab] = useState("balance");
|
|
48
51
|
const [revokingSignerId, setRevokingSignerId] = useState<string | null>(null);
|
|
49
52
|
const account = useActiveAccount();
|
|
53
|
+
const {
|
|
54
|
+
address: eoaAddress,
|
|
55
|
+
info: { data: eoaInfo },
|
|
56
|
+
} = useFirstEOA();
|
|
50
57
|
const { data: assets, isLoading } = useAccountAssets(account?.address);
|
|
51
58
|
const { data: b3Balance } = useB3BalanceFromAddresses(account?.address);
|
|
52
59
|
const { data: nativeBalance } = useNativeBalance(account?.address);
|
|
60
|
+
const { data: eoaNativeBalance } = useNativeBalance(eoaAddress);
|
|
61
|
+
const { data: eoaB3Balance } = useB3BalanceFromAddresses(eoaAddress);
|
|
53
62
|
const { data: signers, refetch: refetchSigners } = useGetAllTWSigners({
|
|
54
63
|
chain,
|
|
55
64
|
accountAddress: account?.address,
|
|
@@ -58,8 +67,6 @@ export function ManageAccount({
|
|
|
58
67
|
const { logout } = useAuthentication(partnerId);
|
|
59
68
|
const [logoutLoading, setLogoutLoading] = useState(false);
|
|
60
69
|
|
|
61
|
-
console.log("@@assets", assets);
|
|
62
|
-
|
|
63
70
|
const { removeSessionKey } = useRemoveSessionKey({
|
|
64
71
|
chain,
|
|
65
72
|
onSuccess: tx => {
|
|
@@ -94,6 +101,20 @@ export function ManageAccount({
|
|
|
94
101
|
<img src="https://cdn.b3.fun/b3_logo.svg" alt="B3" className="h-6 w-6" />
|
|
95
102
|
<h2 className="font-neue-montreal-bold text-b3-react-primary text-lg">Global Account</h2>
|
|
96
103
|
</div>
|
|
104
|
+
|
|
105
|
+
{!automaticallySetFirstEoa && (
|
|
106
|
+
<div className="mb-4">
|
|
107
|
+
<div className="flex items-center gap-4">
|
|
108
|
+
<img src="https://cdn.b3.fun/b3-coin-3d.png" alt="B3" className="h-10 w-10" />
|
|
109
|
+
<span className="font-neue-montreal-bold text-2xl">{b3Balance?.formattedTotal || "--"} B3</span>
|
|
110
|
+
</div>
|
|
111
|
+
<div className="border-b3-react-border my-4 border-t" />
|
|
112
|
+
<div className="flex items-center gap-4">
|
|
113
|
+
<img src="https://cdn.b3.fun/ethereum.svg" alt="ETH" className="h-10 w-10" />
|
|
114
|
+
<span className="font-neue-montreal-bold text-2xl">{nativeBalance?.formattedTotal || "--"} ETH</span>
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
97
118
|
<div className="flex flex-col gap-2">
|
|
98
119
|
<p className="text-b3-react-secondary-foreground text-sm">Your universal account for all B3-powered apps</p>
|
|
99
120
|
<div className="flex items-center gap-2">
|
|
@@ -107,15 +128,26 @@ export function ManageAccount({
|
|
|
107
128
|
</div>
|
|
108
129
|
|
|
109
130
|
<div className="border-b3-react-border bg-b3-react-subtle w-full rounded-lg border p-4">
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
131
|
+
{eoaAddress && (
|
|
132
|
+
<>
|
|
133
|
+
<div>
|
|
134
|
+
<h3 className="font-neue-montreal-bold text-b3-react-primary mb-2">Connected {eoaInfo?.name}</h3>
|
|
135
|
+
<div className="flex items-center gap-4">
|
|
136
|
+
<img src="https://cdn.b3.fun/ethereum.svg" alt="ETH" className="h-10 w-10" />
|
|
137
|
+
<span className="font-neue-montreal-bold text-2xl">{eoaNativeBalance?.formattedTotal || "--"} ETH</span>
|
|
138
|
+
</div>
|
|
139
|
+
<div className="border-b3-react-border my-4 border-t" />
|
|
140
|
+
<div className="flex items-center gap-4">
|
|
141
|
+
<img src="https://cdn.b3.fun/b3-coin-3d.png" alt="B3" className="h-10 w-10" />
|
|
142
|
+
<span className="font-neue-montreal-bold text-2xl">{eoaB3Balance?.formattedTotal || "--"} B3</span>
|
|
143
|
+
</div>
|
|
144
|
+
<div className="text-b3-react-muted-foreground mt-2">
|
|
145
|
+
<span className="font-mono text-sm">{centerTruncate(eoaAddress, 6)}</span>
|
|
146
|
+
<CopyToClipboard text={eoaAddress} />
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
</>
|
|
150
|
+
)}
|
|
119
151
|
</div>
|
|
120
152
|
|
|
121
153
|
<div className="flex w-full gap-4">
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useConnectedWallets, useWalletInfo } from "thirdweb/react";
|
|
4
|
+
import { Wallet } from "thirdweb/wallets";
|
|
5
|
+
|
|
6
|
+
export default function useFirstEOA() {
|
|
7
|
+
const wallets = useConnectedWallets();
|
|
8
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
9
|
+
const [firstEOA, setFirstEOA] = useState<Wallet | undefined>(undefined);
|
|
10
|
+
const [address, setAddress] = useState<string | undefined>(undefined);
|
|
11
|
+
const walletInfo = useWalletInfo(firstEOA?.id);
|
|
12
|
+
|
|
13
|
+
console.log("@@wallets", wallets);
|
|
14
|
+
console.log("@@wallets:isConnected", isConnected);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const autoSelectFirstEOAWallet = async () => {
|
|
18
|
+
// Only proceed if auto-selection is enabled and user is authenticated
|
|
19
|
+
if (!isConnected) {
|
|
20
|
+
console.log("@@wallets:not connected");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Find the first EOA wallet (excluding ecosystem wallets)
|
|
25
|
+
const isEOAWallet = (wallet: Wallet) => !wallet.id.startsWith("ecosystem.");
|
|
26
|
+
const firstEOAWallet = wallets.find(isEOAWallet);
|
|
27
|
+
console.log("@@wallets:firstEOAWallet", firstEOAWallet);
|
|
28
|
+
|
|
29
|
+
const account = await firstEOAWallet?.getAccount();
|
|
30
|
+
console.log("@@wallets:account", account);
|
|
31
|
+
setFirstEOA(firstEOAWallet);
|
|
32
|
+
console.log("@@wallets:address", account?.address);
|
|
33
|
+
setAddress(account?.address);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
autoSelectFirstEOAWallet();
|
|
37
|
+
}, [isConnected, wallets]);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
account: firstEOA,
|
|
41
|
+
address,
|
|
42
|
+
info: walletInfo,
|
|
43
|
+
};
|
|
44
|
+
}
|