@b3dotfun/sdk 0.0.47 → 0.0.48-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/README.md +225 -6
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +5 -3
- package/dist/cjs/anyspend/types/chain.d.ts +2 -1
- package/dist/cjs/anyspend/utils/chain.js +4 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
- package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +6 -22
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
- package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +141 -81
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/cjs/notifications/index.d.ts +3 -0
- package/dist/cjs/notifications/index.js +25 -0
- package/dist/cjs/notifications/react/hooks/index.d.ts +1 -0
- package/dist/cjs/notifications/react/hooks/index.js +17 -0
- package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/cjs/notifications/react/hooks/useNotifications.js +148 -0
- package/dist/cjs/notifications/react/index.d.ts +1 -0
- package/dist/cjs/notifications/react/index.js +17 -0
- package/dist/cjs/notifications/services/api.d.ts +67 -0
- package/dist/cjs/notifications/services/api.js +184 -0
- package/dist/cjs/notifications/services/index.d.ts +1 -0
- package/dist/cjs/notifications/services/index.js +17 -0
- package/dist/cjs/notifications/types/index.d.ts +51 -0
- package/dist/cjs/notifications/types/index.js +2 -0
- package/dist/cjs/shared/utils/auth-token.d.ts +7 -0
- package/dist/cjs/shared/utils/auth-token.js +17 -0
- package/dist/cjs/shared/utils/index.d.ts +1 -0
- package/dist/cjs/shared/utils/index.js +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -3
- package/dist/esm/anyspend/types/chain.d.ts +2 -1
- package/dist/esm/anyspend/utils/chain.js +4 -0
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +7 -23
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
- package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +144 -84
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
- package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/esm/notifications/index.d.ts +3 -0
- package/dist/esm/notifications/index.js +7 -0
- package/dist/esm/notifications/react/hooks/index.d.ts +1 -0
- package/dist/esm/notifications/react/hooks/index.js +1 -0
- package/dist/esm/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/esm/notifications/react/hooks/useNotifications.js +145 -0
- package/dist/esm/notifications/react/index.d.ts +1 -0
- package/dist/esm/notifications/react/index.js +1 -0
- package/dist/esm/notifications/services/api.d.ts +67 -0
- package/dist/esm/notifications/services/api.js +179 -0
- package/dist/esm/notifications/services/index.d.ts +1 -0
- package/dist/esm/notifications/services/index.js +1 -0
- package/dist/esm/notifications/types/index.d.ts +51 -0
- package/dist/esm/shared/utils/auth-token.d.ts +7 -0
- package/dist/esm/shared/utils/auth-token.js +11 -0
- package/dist/esm/shared/utils/index.d.ts +1 -0
- package/dist/esm/shared/utils/index.js +1 -0
- package/dist/types/anyspend/types/chain.d.ts +2 -1
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/types/notifications/index.d.ts +3 -0
- package/dist/types/notifications/react/hooks/index.d.ts +1 -0
- package/dist/types/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/types/notifications/react/index.d.ts +1 -0
- package/dist/types/notifications/services/api.d.ts +67 -0
- package/dist/types/notifications/services/index.d.ts +1 -0
- package/dist/types/notifications/types/index.d.ts +51 -0
- package/dist/types/shared/utils/auth-token.d.ts +7 -0
- package/dist/types/shared/utils/index.d.ts +1 -0
- package/package.json +23 -3
- package/src/anyspend/react/components/AnySpendCustom.tsx +5 -3
- package/src/anyspend/types/chain.ts +2 -1
- package/src/anyspend/utils/chain.ts +4 -0
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
- package/src/global-account/react/components/B3Provider/types.ts +4 -0
- package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +4 -23
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
- package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
- package/src/global-account/react/hooks/useAuthentication.ts +170 -89
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
- package/src/global-account/react/hooks/useUserQuery.ts +95 -0
- package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
- package/src/global-account/react/stores/useModalStore.ts +0 -2
- package/src/notifications/index.ts +9 -0
- package/src/notifications/react/hooks/index.ts +1 -0
- package/src/notifications/react/hooks/useNotifications.ts +153 -0
- package/src/notifications/react/index.ts +1 -0
- package/src/notifications/services/api.ts +217 -0
- package/src/notifications/services/index.ts +1 -0
- package/src/notifications/types/index.ts +58 -0
- package/src/shared/utils/auth-token.ts +13 -0
- package/src/shared/utils/index.ts +1 -0
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -245
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -243
- package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
- /package/dist/{cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts → esm/notifications/types/index.js} +0 -0
|
@@ -202,5 +202,5 @@ function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit, chain
|
|
|
202
202
|
if (["overview", "tokens", "nfts", "apps", "settings"].includes(tab)) {
|
|
203
203
|
setActiveTab?.(tab);
|
|
204
204
|
}
|
|
205
|
-
}, children: [(0, jsx_runtime_1.jsx)("div", { className: "px-4", children: (0, jsx_runtime_1.jsxs)(react_1.TabsListPrimitive, { className: "grid h-auto grid-cols-2 grid-rows-2 gap-3 rounded-none border-none bg-transparent", children: [(0, jsx_runtime_1.jsxs)(react_1.TabTriggerPrimitive, { value: "overview", className: "data-[state=active]:bg-b3-primary-blue data-[state=active]:hover:bg-b3-primary-blue data-[state=active]:border-b3-primary-blue group flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white p-2 text-center shadow-sm transition-all duration-200 hover:bg-gray-50 hover:shadow-md data-[state=active]:shadow-lg", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.BarChart3, { size: 20, className: "text-b3-primary-blue shrink-0 group-data-[state=active]:text-white" }), (0, jsx_runtime_1.jsx)("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm group-data-[state=active]:text-white", children: "Overview" })] }), (0, jsx_runtime_1.jsxs)(react_1.TabTriggerPrimitive, { value: "tokens", className: "data-[state=active]:bg-b3-primary-blue data-[state=active]:hover:bg-b3-primary-blue data-[state=active]:border-b3-primary-blue group flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white p-2 text-center shadow-sm transition-all duration-200 hover:bg-gray-50 hover:shadow-md data-[state=active]:shadow-lg", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Coins, { size: 20, className: "text-b3-primary-blue shrink-0 group-data-[state=active]:text-white" }), (0, jsx_runtime_1.jsx)("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm group-data-[state=active]:text-white", children: "Tokens" })] }), (0, jsx_runtime_1.jsxs)(react_1.TabTriggerPrimitive, { value: "nfts", className: "data-[state=active]:bg-b3-primary-blue data-[state=active]:hover:bg-b3-primary-blue data-[state=active]:border-b3-primary-blue group flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white p-2 text-center shadow-sm transition-all duration-200 hover:bg-gray-50 hover:shadow-md data-[state=active]:shadow-lg", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Image, { size: 20, className: "text-b3-primary-blue shrink-0 group-data-[state=active]:text-white" }), (0, jsx_runtime_1.jsx)("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm group-data-[state=active]:text-white", children: "NFTs" })] }), (0, jsx_runtime_1.jsxs)(react_1.TabTriggerPrimitive, { value: "settings", className: "data-[state=active]:bg-b3-primary-blue data-[state=active]:hover:bg-b3-primary-blue data-[state=active]:border-b3-primary-blue group flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white p-2 text-center shadow-sm transition-all duration-200 hover:bg-gray-50 hover:shadow-md data-[state=active]:shadow-lg", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Settings, { size: 20, className: "text-b3-primary-blue shrink-0 group-data-[state=active]:text-white" }), (0, jsx_runtime_1.jsx)("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm group-data-[state=active]:text-white", children: "Settings" })] })] }) }), (0, jsx_runtime_1.jsx)(react_1.TabsContentPrimitive, { value: "overview", className: "px-4 pb-4 pt-2", children: (0, jsx_runtime_1.jsx)(BalanceContent_1.BalanceContent, { onLogout: onLogout,
|
|
205
|
+
}, children: [(0, jsx_runtime_1.jsx)("div", { className: "px-4", children: (0, jsx_runtime_1.jsxs)(react_1.TabsListPrimitive, { className: "grid h-auto grid-cols-2 grid-rows-2 gap-3 rounded-none border-none bg-transparent", children: [(0, jsx_runtime_1.jsxs)(react_1.TabTriggerPrimitive, { value: "overview", className: "data-[state=active]:bg-b3-primary-blue data-[state=active]:hover:bg-b3-primary-blue data-[state=active]:border-b3-primary-blue group flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white p-2 text-center shadow-sm transition-all duration-200 hover:bg-gray-50 hover:shadow-md data-[state=active]:shadow-lg", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.BarChart3, { size: 20, className: "text-b3-primary-blue shrink-0 group-data-[state=active]:text-white" }), (0, jsx_runtime_1.jsx)("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm group-data-[state=active]:text-white", children: "Overview" })] }), (0, jsx_runtime_1.jsxs)(react_1.TabTriggerPrimitive, { value: "tokens", className: "data-[state=active]:bg-b3-primary-blue data-[state=active]:hover:bg-b3-primary-blue data-[state=active]:border-b3-primary-blue group flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white p-2 text-center shadow-sm transition-all duration-200 hover:bg-gray-50 hover:shadow-md data-[state=active]:shadow-lg", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Coins, { size: 20, className: "text-b3-primary-blue shrink-0 group-data-[state=active]:text-white" }), (0, jsx_runtime_1.jsx)("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm group-data-[state=active]:text-white", children: "Tokens" })] }), (0, jsx_runtime_1.jsxs)(react_1.TabTriggerPrimitive, { value: "nfts", className: "data-[state=active]:bg-b3-primary-blue data-[state=active]:hover:bg-b3-primary-blue data-[state=active]:border-b3-primary-blue group flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white p-2 text-center shadow-sm transition-all duration-200 hover:bg-gray-50 hover:shadow-md data-[state=active]:shadow-lg", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Image, { size: 20, className: "text-b3-primary-blue shrink-0 group-data-[state=active]:text-white" }), (0, jsx_runtime_1.jsx)("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm group-data-[state=active]:text-white", children: "NFTs" })] }), (0, jsx_runtime_1.jsxs)(react_1.TabTriggerPrimitive, { value: "settings", className: "data-[state=active]:bg-b3-primary-blue data-[state=active]:hover:bg-b3-primary-blue data-[state=active]:border-b3-primary-blue group flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white p-2 text-center shadow-sm transition-all duration-200 hover:bg-gray-50 hover:shadow-md data-[state=active]:shadow-lg", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Settings, { size: 20, className: "text-b3-primary-blue shrink-0 group-data-[state=active]:text-white" }), (0, jsx_runtime_1.jsx)("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm group-data-[state=active]:text-white", children: "Settings" })] })] }) }), (0, jsx_runtime_1.jsx)(react_1.TabsContentPrimitive, { value: "overview", className: "px-4 pb-4 pt-2", children: (0, jsx_runtime_1.jsx)(BalanceContent_1.BalanceContent, { onLogout: onLogout, showDeposit: showDeposit, showSwap: showSwap }) }), (0, jsx_runtime_1.jsx)(react_1.TabsContentPrimitive, { value: "tokens", className: "px-4 pb-4 pt-2", children: (0, jsx_runtime_1.jsx)(ContentTokens_1.ContentTokens, { activeTab: activeTab }) }), (0, jsx_runtime_1.jsx)(react_1.TabsContentPrimitive, { value: "nfts", className: "px-4 pb-4 pt-2", children: (0, jsx_runtime_1.jsx)("div", { className: "grid grid-cols-3 gap-4", children: nfts?.nftResponse ? ((0, jsx_runtime_1.jsx)(AccountAssets_1.AccountAssets, { nfts: nfts.nftResponse, isLoading: isLoading })) : ((0, jsx_runtime_1.jsx)("div", { className: "col-span-3 py-12 text-center text-gray-500", children: "No NFTs found" })) }) }), (0, jsx_runtime_1.jsx)(react_1.TabsContentPrimitive, { value: "apps", className: "px-4 pb-4 pt-2", children: (0, jsx_runtime_1.jsx)(AppsContent, {}) }), (0, jsx_runtime_1.jsx)(react_1.TabsContentPrimitive, { value: "settings", className: "px-4 pb-4 pt-2", children: (0, jsx_runtime_1.jsx)(SettingsContent, {}) })] }) }) }));
|
|
206
206
|
}
|
|
@@ -15,10 +15,10 @@ const react_4 = require("thirdweb/react");
|
|
|
15
15
|
const ManageAccountButton_1 = require("../custom/ManageAccountButton");
|
|
16
16
|
function SignIn(props) {
|
|
17
17
|
const { className } = props;
|
|
18
|
-
const { automaticallySetFirstEoa } = (0, react_1.useB3)();
|
|
18
|
+
const { automaticallySetFirstEoa, partnerId } = (0, react_1.useB3)();
|
|
19
19
|
const { wallet, address: globalAddress, ensName, connectedSmartWallet, connectedEOAWallet, isActiveSmartWallet, isActiveEOAWallet, smartWalletIcon, eoaWalletIcon, } = (0, react_1.useAccountWallet)();
|
|
20
20
|
const isMobile = (0, react_1.useIsMobile)();
|
|
21
|
-
const { logout } = (0, react_1.useAuthentication)(
|
|
21
|
+
const { logout } = (0, react_1.useAuthentication)(partnerId);
|
|
22
22
|
const onDisconnect = async () => {
|
|
23
23
|
await logout();
|
|
24
24
|
};
|
|
@@ -9,7 +9,7 @@ const Loading_1 = require("../ui/Loading");
|
|
|
9
9
|
function SignInWithB3(props) {
|
|
10
10
|
const { setB3ModalOpen, setB3ModalContentType, setEcoSystemAccountAddress } = (0, react_1.useModalStore)();
|
|
11
11
|
const { account } = (0, react_1.useB3)();
|
|
12
|
-
const { isAuthenticating, isAuthenticated } = (0, react_1.
|
|
12
|
+
const { isAuthenticating, isAuthenticated } = (0, react_1.useAuthStore)();
|
|
13
13
|
const isMobile = (0, react_1.useIsMobile)();
|
|
14
14
|
(0, react_2.useEffect)(() => {
|
|
15
15
|
if (account) {
|
|
@@ -3,4 +3,4 @@ import { SignInWithB3ModalProps } from "../../../../global-account/react";
|
|
|
3
3
|
* Component that manages the authentication flow for Sign In With B3
|
|
4
4
|
* Handles different login providers, authentication steps, and session key management
|
|
5
5
|
*/
|
|
6
|
-
export declare function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin,
|
|
6
|
+
export declare function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin, source, signersEnabled, }: SignInWithB3ModalProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -15,16 +15,14 @@ const MAX_REFETCH_ATTEMPTS = 20;
|
|
|
15
15
|
* Component that manages the authentication flow for Sign In With B3
|
|
16
16
|
* Handles different login providers, authentication steps, and session key management
|
|
17
17
|
*/
|
|
18
|
-
function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false,
|
|
19
|
-
const {
|
|
18
|
+
function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
|
|
19
|
+
const { automaticallySetFirstEoa } = (0, react_1.useB3)();
|
|
20
20
|
const [step, setStep] = (0, react_2.useState)(source === "requestPermissions" ? null : "login");
|
|
21
21
|
const [sessionKeyAdded, setSessionKeyAdded] = (0, react_2.useState)(source === "requestPermissions" ? true : false);
|
|
22
22
|
const { setB3ModalContentType, setB3ModalOpen, isOpen } = (0, react_1.useModalStore)();
|
|
23
23
|
const account = (0, react_3.useActiveAccount)();
|
|
24
|
-
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
25
24
|
const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
|
|
26
25
|
const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
|
|
27
|
-
const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
|
|
28
26
|
const [refetchCount, setRefetchCount] = (0, react_2.useState)(0);
|
|
29
27
|
const [refetchError, setRefetchError] = (0, react_2.useState)(null);
|
|
30
28
|
const { data: signers, refetch: refetchSigners, isFetching: isFetchingSigners, } = (0, react_1.useGetAllTWSigners)({
|
|
@@ -34,7 +32,6 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
34
32
|
enabled: signersEnabled,
|
|
35
33
|
},
|
|
36
34
|
});
|
|
37
|
-
const { authenticate } = (0, react_1.useSiwe)();
|
|
38
35
|
const [refetchQueued, setRefetchQueued] = (0, react_2.useState)(false);
|
|
39
36
|
// Enhanced refetchSigners function that tracks number of attempts
|
|
40
37
|
const handleRefetchSigners = (0, react_2.useCallback)(() => {
|
|
@@ -145,13 +142,11 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
145
142
|
sessionKeyAddress,
|
|
146
143
|
partnerId,
|
|
147
144
|
closeAfterLogin,
|
|
148
|
-
loginWithSiwe,
|
|
149
145
|
source: "requestPermissions",
|
|
150
146
|
});
|
|
151
147
|
}, [
|
|
152
148
|
chain,
|
|
153
149
|
closeAfterLogin,
|
|
154
|
-
loginWithSiwe,
|
|
155
150
|
onError,
|
|
156
151
|
onLoginSuccess,
|
|
157
152
|
onSessionKeySuccess,
|
|
@@ -161,19 +156,8 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
161
156
|
strategies,
|
|
162
157
|
]);
|
|
163
158
|
const handleLoginSuccess = (0, react_2.useCallback)(async (account) => {
|
|
164
|
-
debug("Authenticating with B3 via SIWE");
|
|
165
|
-
setIsConnected(true);
|
|
166
|
-
if (loginWithSiwe) {
|
|
167
|
-
debug("setIsAuthenticating:true:1");
|
|
168
|
-
setIsAuthenticating(true);
|
|
169
|
-
const userAuth = await authenticate(account, partnerId);
|
|
170
|
-
setUser(userAuth.user);
|
|
171
|
-
}
|
|
172
|
-
debug("handleLoginSuccess:account", account);
|
|
173
159
|
onLoginSuccess?.(account);
|
|
174
|
-
|
|
175
|
-
setIsAuthenticating(false);
|
|
176
|
-
}, [loginWithSiwe, onLoginSuccess, authenticate, partnerId, setUser, setIsConnected, setIsAuthenticating]);
|
|
160
|
+
}, [onLoginSuccess]);
|
|
177
161
|
(0, react_2.useEffect)(() => {
|
|
178
162
|
if (step === "permissions") {
|
|
179
163
|
setB3ModalContentType({
|
|
@@ -195,14 +179,14 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
195
179
|
if (step === "login") {
|
|
196
180
|
// Custom strategy
|
|
197
181
|
if (strategies?.[0] === "privy") {
|
|
198
|
-
return (0, jsx_runtime_1.jsx)(SignInWithB3Privy_1.SignInWithB3Privy, { onSuccess: handleLoginSuccess,
|
|
182
|
+
return (0, jsx_runtime_1.jsx)(SignInWithB3Privy_1.SignInWithB3Privy, { onSuccess: handleLoginSuccess, chain: chain });
|
|
199
183
|
}
|
|
200
184
|
// Strategies are explicitly provided
|
|
201
185
|
if (strategies) {
|
|
202
|
-
return ((0, jsx_runtime_1.jsx)(LoginStepCustom_1.LoginStepCustom, { strategies: strategies,
|
|
186
|
+
return ((0, jsx_runtime_1.jsx)(LoginStepCustom_1.LoginStepCustom, { strategies: strategies, chain: chain, onSuccess: handleLoginSuccess, onError: onError, automaticallySetFirstEoa: !!automaticallySetFirstEoa }));
|
|
203
187
|
}
|
|
204
188
|
// Default to handle all strategies we support
|
|
205
|
-
return (0, jsx_runtime_1.jsx)(LoginStep_1.LoginStep, {
|
|
189
|
+
return (0, jsx_runtime_1.jsx)(LoginStep_1.LoginStep, { chain: chain, onSuccess: handleLoginSuccess, onError: onError });
|
|
206
190
|
}
|
|
207
191
|
return null;
|
|
208
192
|
}
|
|
@@ -4,8 +4,7 @@ interface SignInWithB3PrivyProps {
|
|
|
4
4
|
onError?: (error: Error) => Promise<void>;
|
|
5
5
|
onSuccess: (account: Account) => Promise<void>;
|
|
6
6
|
accessToken?: string;
|
|
7
|
-
partnerId: string;
|
|
8
7
|
chain: Chain;
|
|
9
8
|
}
|
|
10
|
-
export declare function SignInWithB3Privy({ onSuccess, onError,
|
|
9
|
+
export declare function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps): import("react/jsx-runtime").JSX.Element;
|
|
11
10
|
export {};
|
|
@@ -6,8 +6,9 @@ const react_1 = require("../../../../global-account/react");
|
|
|
6
6
|
const debug_1 = require("../../../../shared/utils/debug");
|
|
7
7
|
const react_2 = require("react");
|
|
8
8
|
const debug = (0, debug_1.debugB3React)("SignInWithB3Privy");
|
|
9
|
-
function SignInWithB3Privy({ onSuccess, onError,
|
|
10
|
-
const {
|
|
9
|
+
function SignInWithB3Privy({ onSuccess, onError, chain }) {
|
|
10
|
+
const { partnerId } = (0, react_1.useB3)();
|
|
11
|
+
const { isLoading, connectTw, fullToken } = (0, react_1.useHandleConnectWithPrivy)(chain, onSuccess);
|
|
11
12
|
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
12
13
|
const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
|
|
13
14
|
const { logout } = (0, react_1.useAuthentication)(partnerId);
|
|
@@ -9,7 +9,6 @@ interface LoginStepProps {
|
|
|
9
9
|
/** Optional callback function called when an error occurs */
|
|
10
10
|
onError?: (error: Error) => Promise<void>;
|
|
11
11
|
/** Partner ID used for authentication */
|
|
12
|
-
partnerId: string;
|
|
13
12
|
/** Blockchain chain information */
|
|
14
13
|
chain: Chain;
|
|
15
14
|
/** Optional authentication strategy options */
|
|
@@ -20,5 +19,5 @@ interface LoginStepContainerProps {
|
|
|
20
19
|
partnerId?: string;
|
|
21
20
|
}
|
|
22
21
|
export declare function LoginStepContainer({ children, partnerId }: LoginStepContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
-
export declare function LoginStep({ onSuccess,
|
|
22
|
+
export declare function LoginStep({ onSuccess, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element;
|
|
24
23
|
export {};
|
|
@@ -5,7 +5,6 @@ exports.LoginStep = LoginStep;
|
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_1 = require("../../../../../global-account/react");
|
|
7
7
|
const constants_1 = require("../../../../../shared/constants");
|
|
8
|
-
const debug_1 = require("../../../../../shared/utils/debug");
|
|
9
8
|
const thirdweb_1 = require("../../../../../shared/utils/thirdweb");
|
|
10
9
|
const react_2 = require("thirdweb/react");
|
|
11
10
|
const wallets_1 = require("thirdweb/wallets");
|
|
@@ -19,14 +18,12 @@ function LoginStepContainer({ children, partnerId }) {
|
|
|
19
18
|
const partnerLogo = partner?.data?.[0]?.loginCustomization?.logoUrl;
|
|
20
19
|
return ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col items-center justify-center pt-6", children: [partnerLogo && ((0, jsx_runtime_1.jsx)("img", { src: partnerLogo, alt: "Partner Logo", className: "partner-logo mb-6 h-12 w-auto object-contain" })), children, (0, jsx_runtime_1.jsxs)("h2", { className: "mt-6 flex items-center gap-2 text-lg font-bold", children: ["Powered by", (0, jsx_runtime_1.jsx)("img", { alt: "B3 Logo", className: "h-5", src: "https://cdn.b3.fun/b3_logo.svg" }), "Connect"] })] }));
|
|
21
20
|
}
|
|
22
|
-
function LoginStep({ onSuccess,
|
|
21
|
+
function LoginStep({ onSuccess, chain }) {
|
|
22
|
+
const { partnerId, theme } = (0, react_1.useB3)();
|
|
23
23
|
const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
|
|
24
24
|
partnerId: partnerId,
|
|
25
25
|
});
|
|
26
|
-
const {
|
|
27
|
-
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
28
|
-
const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
|
|
29
|
-
const { logout } = (0, react_1.useAuthentication)(partnerId);
|
|
26
|
+
const { onConnect } = (0, react_1.useAuthentication)(partnerId);
|
|
30
27
|
return ((0, jsx_runtime_1.jsx)(LoginStepContainer, { partnerId: partnerId, children: (0, jsx_runtime_1.jsx)(react_2.ConnectEmbed, { showThirdwebBranding: false, client: thirdweb_1.client, chain: chain, wallets: [wallet], theme: theme === "light"
|
|
31
28
|
? (0, react_2.lightTheme)({
|
|
32
29
|
colors: {
|
|
@@ -37,50 +34,18 @@ function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
|
37
34
|
colors: {
|
|
38
35
|
modalBg: "hsl(var(--b3-react-background))",
|
|
39
36
|
},
|
|
40
|
-
}),
|
|
37
|
+
}), style: {
|
|
41
38
|
width: "100%",
|
|
42
39
|
height: "100%",
|
|
43
40
|
border: 0,
|
|
44
|
-
},
|
|
45
|
-
// TODO: Integrate with SIWE in useSIWE
|
|
46
|
-
// auth={{
|
|
47
|
-
// isLoggedIn: async (address) => {
|
|
48
|
-
// console.log("checking if logged in!", { address });
|
|
49
|
-
// return await isLoggedIn();
|
|
50
|
-
// },
|
|
51
|
-
// doLogin: async (params) => {
|
|
52
|
-
// console.log("logging in!");
|
|
53
|
-
// await login(params);
|
|
54
|
-
// },
|
|
55
|
-
// getLoginPayload: async ({ address }) =>
|
|
56
|
-
// generatePayload({ address }),
|
|
57
|
-
// doLogout: async () => {
|
|
58
|
-
// console.log("logging out!");
|
|
59
|
-
// await logout();
|
|
60
|
-
// },
|
|
61
|
-
// }}
|
|
62
|
-
header: {
|
|
41
|
+
}, header: {
|
|
63
42
|
title: "Sign in with B3",
|
|
64
43
|
titleIcon: "https://cdn.b3.fun/b3_logo.svg",
|
|
65
44
|
}, className: "b3-login-step", onConnect: async (wallet) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
throw new Error("No account found");
|
|
72
|
-
await onSuccess(account);
|
|
73
|
-
setIsAuthenticated(true);
|
|
74
|
-
console.log("connected!", wallet.id);
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
await onError?.(error);
|
|
78
|
-
await logout();
|
|
79
|
-
setIsAuthenticated(false);
|
|
80
|
-
}
|
|
81
|
-
finally {
|
|
82
|
-
(0, debug_1.debug)("setIsAuthenticating:false:6");
|
|
83
|
-
setIsAuthenticating(false);
|
|
84
|
-
}
|
|
45
|
+
await onConnect(wallet);
|
|
46
|
+
const account = wallet.getAccount();
|
|
47
|
+
if (!account)
|
|
48
|
+
throw new Error("No account found");
|
|
49
|
+
await onSuccess(account);
|
|
85
50
|
} }) }));
|
|
86
51
|
}
|
|
@@ -5,10 +5,9 @@ interface LoginStepCustomProps {
|
|
|
5
5
|
automaticallySetFirstEoa: boolean;
|
|
6
6
|
onSuccess: (account: Account) => Promise<void>;
|
|
7
7
|
onError?: (error: Error) => Promise<void>;
|
|
8
|
-
partnerId: string;
|
|
9
8
|
chain: Chain;
|
|
10
9
|
strategies: AllowedStrategy[];
|
|
11
10
|
maxInitialWallets?: number;
|
|
12
11
|
}
|
|
13
|
-
export declare function LoginStepCustom({ onSuccess, onError,
|
|
12
|
+
export declare function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInitialWallets, automaticallySetFirstEoa, }: LoginStepCustomProps): import("react/jsx-runtime").JSX.Element;
|
|
14
13
|
export {};
|
|
@@ -9,7 +9,8 @@ const react_2 = require("react");
|
|
|
9
9
|
const react_3 = require("thirdweb/react");
|
|
10
10
|
const wallets_1 = require("thirdweb/wallets");
|
|
11
11
|
const debug = (0, debug_1.debugB3React)("LoginStepCustom");
|
|
12
|
-
function LoginStepCustom({ onSuccess, onError,
|
|
12
|
+
function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInitialWallets = 2, automaticallySetFirstEoa, }) {
|
|
13
|
+
const { partnerId } = (0, react_1.useB3)();
|
|
13
14
|
const [isLoading, setIsLoading] = (0, react_2.useState)(false);
|
|
14
15
|
const [showAllWallets, setShowAllWallets] = (0, react_2.useState)(false);
|
|
15
16
|
const { connect } = (0, react_1.useConnect)(partnerId, chain);
|
|
@@ -5,8 +5,9 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("../../../../global-account/react");
|
|
6
6
|
const utils_1 = require("../../../../shared/utils");
|
|
7
7
|
function ManageAccountButton(props) {
|
|
8
|
+
const { partnerId } = (0, react_1.useB3)();
|
|
8
9
|
const { setB3ModalOpen, setB3ModalContentType } = (0, react_1.useModalStore)();
|
|
9
|
-
const { isConnected } = (0, react_1.useAuthentication)(
|
|
10
|
+
const { isConnected } = (0, react_1.useAuthentication)(partnerId);
|
|
10
11
|
const handleClickManageAccount = () => {
|
|
11
12
|
setB3ModalContentType({
|
|
12
13
|
...props,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Wallet } from "thirdweb/wallets";
|
|
1
2
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
2
|
-
export declare function useAuthentication(partnerId: string
|
|
3
|
+
export declare function useAuthentication(partnerId: string): {
|
|
3
4
|
logout: (callback?: () => void) => Promise<void>;
|
|
4
5
|
isAuthenticated: boolean;
|
|
5
6
|
isReady: boolean;
|
|
@@ -7,6 +8,54 @@ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boo
|
|
|
7
8
|
isConnected: boolean;
|
|
8
9
|
wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
|
|
9
10
|
preAuthenticate: typeof preAuthenticate;
|
|
10
|
-
connect: (
|
|
11
|
+
connect: (wallet: Wallet) => Promise<void>;
|
|
11
12
|
isAuthenticating: boolean;
|
|
13
|
+
onConnect: (wallet: Wallet) => Promise<void>;
|
|
14
|
+
user: {
|
|
15
|
+
email?: string | undefined;
|
|
16
|
+
username?: string | undefined;
|
|
17
|
+
telNumber?: string | undefined;
|
|
18
|
+
ens?: string | undefined;
|
|
19
|
+
avatar?: string | undefined;
|
|
20
|
+
preferences?: {} | undefined;
|
|
21
|
+
referredBy?: string | {} | undefined;
|
|
22
|
+
sourceApp?: string | undefined;
|
|
23
|
+
referralCode?: string | undefined;
|
|
24
|
+
userGroups?: number[] | undefined;
|
|
25
|
+
isMigratedFromBSMNT?: boolean | undefined;
|
|
26
|
+
privyLinkedAccounts?: {
|
|
27
|
+
name?: string | undefined;
|
|
28
|
+
address?: string | undefined;
|
|
29
|
+
email?: string | undefined;
|
|
30
|
+
chain_type?: string | undefined;
|
|
31
|
+
lv?: number | undefined;
|
|
32
|
+
wallet_client_type?: string | undefined;
|
|
33
|
+
smart_wallet_type?: string | undefined;
|
|
34
|
+
subject?: string | undefined;
|
|
35
|
+
type: string;
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
twProfiles?: {
|
|
38
|
+
type: string;
|
|
39
|
+
details: {
|
|
40
|
+
id?: string | undefined;
|
|
41
|
+
name?: string | undefined;
|
|
42
|
+
address?: string | undefined;
|
|
43
|
+
email?: string | undefined;
|
|
44
|
+
phone?: string | undefined;
|
|
45
|
+
username?: string | undefined;
|
|
46
|
+
fid?: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
_id: string | {};
|
|
50
|
+
userId: string;
|
|
51
|
+
smartAccountAddress: string;
|
|
52
|
+
createdAt: number;
|
|
53
|
+
updatedAt: number;
|
|
54
|
+
partnerIds: {
|
|
55
|
+
privyId?: string | undefined;
|
|
56
|
+
thirdwebId?: string | undefined;
|
|
57
|
+
};
|
|
58
|
+
} | undefined;
|
|
59
|
+
refetchUser: (wallet?: Wallet) => Promise<void>;
|
|
60
|
+
setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
|
|
12
61
|
};
|
|
@@ -8,116 +8,158 @@ const app_1 = __importDefault(require("../../../global-account/app"));
|
|
|
8
8
|
const bsmnt_1 = require("../../../global-account/bsmnt");
|
|
9
9
|
const react_1 = require("../../../global-account/react");
|
|
10
10
|
const constants_1 = require("../../../shared/constants");
|
|
11
|
-
const supported_1 = require("../../../shared/constants/chains/supported");
|
|
12
11
|
const debug_1 = require("../../../shared/utils/debug");
|
|
13
12
|
const thirdweb_1 = require("../../../shared/utils/thirdweb");
|
|
13
|
+
const core_1 = require("@wagmi/core");
|
|
14
14
|
const react_2 = require("react");
|
|
15
15
|
const react_3 = require("thirdweb/react");
|
|
16
16
|
const wallets_1 = require("thirdweb/wallets");
|
|
17
17
|
const in_app_1 = require("thirdweb/wallets/in-app");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
18
|
+
const wagmi_1 = require("wagmi");
|
|
19
|
+
const useUserQuery_1 = require("./useUserQuery");
|
|
20
|
+
const useWagmiConfig_1 = require("./useWagmiConfig");
|
|
20
21
|
const debug = (0, debug_1.debugB3React)("useAuthentication");
|
|
21
|
-
function useAuthentication(partnerId
|
|
22
|
+
function useAuthentication(partnerId) {
|
|
22
23
|
const { disconnect } = (0, react_3.useDisconnect)();
|
|
23
24
|
const wallets = (0, react_3.useConnectedWallets)();
|
|
24
25
|
const activeWallet = (0, react_3.useActiveWallet)();
|
|
25
|
-
const { authenticate } = (0, useSiwe_1.useSiwe)();
|
|
26
|
-
const { setUser } = (0, react_1.useB3)();
|
|
27
26
|
const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
|
|
28
27
|
const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
|
|
29
|
-
const setIsConnecting = (0, react_1.useAuthStore)(state => state.setIsConnecting);
|
|
30
28
|
const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
|
|
31
29
|
const isConnecting = (0, react_1.useAuthStore)(state => state.isConnecting);
|
|
32
30
|
const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
|
|
33
|
-
const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
|
|
34
|
-
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
35
31
|
const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
|
|
36
|
-
const
|
|
32
|
+
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
37
33
|
const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
|
|
38
|
-
const
|
|
34
|
+
const setActiveWallet = (0, react_3.useSetActiveWallet)();
|
|
35
|
+
const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
|
|
36
|
+
const { authenticate } = (0, react_1.useSiwe)();
|
|
37
|
+
const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
|
|
38
|
+
const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
|
|
39
|
+
const wagmiConfig = (0, useWagmiConfig_1.useWagmiConfig)(partnerId);
|
|
40
|
+
const { connect } = (0, wagmi_1.useConnect)();
|
|
41
|
+
const activeWagmiAccount = (0, wagmi_1.useAccount)();
|
|
42
|
+
const { switchAccount } = (0, wagmi_1.useSwitchAccount)();
|
|
43
|
+
debug("@@activeWagmiAccount", activeWagmiAccount);
|
|
39
44
|
const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
|
|
40
45
|
partnerId: partnerId,
|
|
41
46
|
});
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const syncWagmi = (0, react_2.useCallback)(async () => {
|
|
48
|
+
function syncWagmiFunc() {
|
|
49
|
+
const connectors = (0, core_1.getConnectors)(wagmiConfig);
|
|
50
|
+
debug("@@syncWagmi", {
|
|
51
|
+
connectors,
|
|
52
|
+
wallets,
|
|
53
|
+
});
|
|
54
|
+
// For each that matchs a TW wallet on wallets, connect to the wagmi connector
|
|
55
|
+
// or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
|
|
56
|
+
connectors.forEach(async (connector) => {
|
|
57
|
+
const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
|
|
58
|
+
// If no TW wallet, do not prompt the user to connect
|
|
59
|
+
if (!twWallet) {
|
|
53
60
|
return;
|
|
54
61
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
throw new Error("No account found during auto-connect");
|
|
62
|
+
// Metamask will prompt to connect, we can just switch accounts here.
|
|
63
|
+
if (connector.id === "io.metamask") {
|
|
64
|
+
return switchAccount({ connector });
|
|
59
65
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
if (
|
|
67
|
+
// If it's not an in-app wallet or it is the ecosystem wallet, connect
|
|
68
|
+
connector.id !== "in-app-wallet" ||
|
|
69
|
+
(connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId)) {
|
|
70
|
+
try {
|
|
71
|
+
const options = {
|
|
72
|
+
wallet: twWallet, // the connected wallet
|
|
73
|
+
};
|
|
74
|
+
debug("@@syncWagmi:connecting", { twWallet, connector });
|
|
75
|
+
connect({
|
|
76
|
+
connector,
|
|
77
|
+
...options,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error("@@syncWagmi:error", error);
|
|
82
|
+
}
|
|
70
83
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
debug("Re-authentication failed, attempting fresh authentication");
|
|
74
|
-
const userAuth = await authenticate(account, partnerId);
|
|
75
|
-
setUser(userAuth.user);
|
|
76
|
-
setIsAuthenticated(true);
|
|
77
|
-
setIsAuthenticating(false);
|
|
78
|
-
debug("Fresh authentication successful", { userAuth });
|
|
79
|
-
// Authenticate on BSMNT with B3 JWT
|
|
80
|
-
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
81
|
-
console.log("@@b3Jwt", b3Jwt);
|
|
84
|
+
else {
|
|
85
|
+
debug("@@syncWagmi:not-connecting", connector);
|
|
82
86
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
setIsAuthenticating(false);
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
/**
|
|
94
|
-
* useAutoConnectLoading starts as false
|
|
95
|
-
*/
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
syncWagmiFunc();
|
|
90
|
+
// wagmi config shouldn't change
|
|
91
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
|
+
}, [partnerId, wallets]);
|
|
96
93
|
(0, react_2.useEffect)(() => {
|
|
97
|
-
|
|
94
|
+
syncWagmi();
|
|
95
|
+
}, [wallets, syncWagmi]);
|
|
96
|
+
const authenticateUser = (0, react_2.useCallback)(async (wallet) => {
|
|
97
|
+
setHasStartedConnecting(true);
|
|
98
|
+
const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
|
|
99
|
+
if (!account) {
|
|
100
|
+
throw new Error("No account found during auto-connect");
|
|
101
|
+
}
|
|
102
|
+
if (!account) {
|
|
103
|
+
throw new Error("No account found during auto-connect");
|
|
104
|
+
}
|
|
105
|
+
// Try to re-authenticate first
|
|
106
|
+
try {
|
|
107
|
+
const userAuth = await app_1.default.reAuthenticate();
|
|
108
|
+
setUser(userAuth.user);
|
|
109
|
+
setIsAuthenticated(true);
|
|
98
110
|
setIsAuthenticating(false);
|
|
111
|
+
debug("Re-authenticated successfully", { userAuth });
|
|
112
|
+
// Authenticate on BSMNT with B3 JWT
|
|
113
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
114
|
+
debug("@@b3Jwt", b3Jwt);
|
|
99
115
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
116
|
+
catch (error) {
|
|
117
|
+
// If re-authentication fails, try fresh authentication
|
|
118
|
+
debug("Re-authentication failed, attempting fresh authentication");
|
|
119
|
+
const userAuth = await authenticate(account, partnerId);
|
|
120
|
+
setUser(userAuth.user);
|
|
121
|
+
setIsAuthenticated(true);
|
|
122
|
+
setIsAuthenticating(false);
|
|
123
|
+
debug("Fresh authentication successful", { userAuth });
|
|
124
|
+
// Authenticate on BSMNT with B3 JWT
|
|
125
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
126
|
+
debug("@@b3Jwt", b3Jwt);
|
|
127
|
+
}
|
|
128
|
+
}, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
|
|
129
|
+
const onConnect = (0, react_2.useCallback)(async (wallet) => {
|
|
130
|
+
debug("@@useAuthentication:onConnect", { wallet });
|
|
131
|
+
try {
|
|
132
|
+
setHasStartedConnecting(true);
|
|
133
|
+
setIsConnected(true);
|
|
134
|
+
setIsAuthenticating(true);
|
|
135
|
+
await setActiveWallet(wallet);
|
|
136
|
+
await authenticateUser(wallet);
|
|
106
137
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
debug("setIsAuthenticating:false:5a");
|
|
112
|
-
setIsConnecting(false);
|
|
113
|
-
}, 100); // Add a small delay to prevent quick flickers
|
|
114
|
-
return () => clearTimeout(timeout);
|
|
138
|
+
catch (error) {
|
|
139
|
+
debug("@@useAuthentication:onConnect:failed", { error });
|
|
140
|
+
setIsAuthenticated(false);
|
|
141
|
+
setUser(undefined);
|
|
115
142
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
setIsConnecting(false);
|
|
143
|
+
finally {
|
|
144
|
+
setIsAuthenticating(false);
|
|
119
145
|
}
|
|
120
|
-
|
|
146
|
+
debug({
|
|
147
|
+
isAuthenticated,
|
|
148
|
+
isAuthenticating,
|
|
149
|
+
isConnected,
|
|
150
|
+
});
|
|
151
|
+
}, [
|
|
152
|
+
authenticateUser,
|
|
153
|
+
isAuthenticated,
|
|
154
|
+
isAuthenticating,
|
|
155
|
+
isConnected,
|
|
156
|
+
setActiveWallet,
|
|
157
|
+
setHasStartedConnecting,
|
|
158
|
+
setIsAuthenticated,
|
|
159
|
+
setIsAuthenticating,
|
|
160
|
+
setIsConnected,
|
|
161
|
+
setUser,
|
|
162
|
+
]);
|
|
121
163
|
const logout = async (callback) => {
|
|
122
164
|
if (activeWallet) {
|
|
123
165
|
debug("@@logout:activeWallet", activeWallet);
|
|
@@ -143,7 +185,21 @@ function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
143
185
|
setUser();
|
|
144
186
|
callback?.();
|
|
145
187
|
};
|
|
146
|
-
const
|
|
188
|
+
const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
|
|
189
|
+
client: thirdweb_1.client,
|
|
190
|
+
wallets: [wallet],
|
|
191
|
+
onConnect: onConnect,
|
|
192
|
+
});
|
|
193
|
+
/**
|
|
194
|
+
* useAutoConnectLoading starts as false
|
|
195
|
+
*/
|
|
196
|
+
(0, react_2.useEffect)(() => {
|
|
197
|
+
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
198
|
+
setIsAuthenticating(false);
|
|
199
|
+
}
|
|
200
|
+
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
201
|
+
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
202
|
+
const isReady = isAuthenticated && !isAuthenticating;
|
|
147
203
|
return {
|
|
148
204
|
logout,
|
|
149
205
|
isAuthenticated,
|
|
@@ -152,7 +208,11 @@ function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
152
208
|
isConnected,
|
|
153
209
|
wallet,
|
|
154
210
|
preAuthenticate: in_app_1.preAuthenticate,
|
|
155
|
-
connect,
|
|
211
|
+
connect: onConnect,
|
|
156
212
|
isAuthenticating,
|
|
213
|
+
onConnect,
|
|
214
|
+
user,
|
|
215
|
+
refetchUser: authenticateUser,
|
|
216
|
+
setUser,
|
|
157
217
|
};
|
|
158
218
|
}
|