Skip to content

Commit 08b69e8

Browse files
committed
more cleanup of the moved code
1 parent 6621237 commit 08b69e8

File tree

26 files changed

+11296
-17670
lines changed

26 files changed

+11296
-17670
lines changed

packages/abstraxion/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
"dependencies": {
4444
"@burnt-labs/abstraxion-core": "workspace:*",
4545
"@burnt-labs/constants": "workspace:*",
46+
"@burnt-labs/signers": "workspace:*",
4647
"@burnt-labs/ui": "workspace:*",
48+
"@burnt-labs/wallet-connectors": "workspace:*",
4749
"@cosmjs/amino": "^0.36.0",
4850
"@cosmjs/cosmwasm-stargate": "^0.36.0",
4951
"@cosmjs/crypto": "^0.36.0",
@@ -53,6 +55,7 @@
5355
"@cosmjs/tendermint-rpc": "^0.36.0",
5456
"@cosmjs/utils": "^0.36.0",
5557
"@types/react-dom": "^18.2.18",
58+
"buffer": "^6.0.3",
5659
"cosmjs-types": "^0.9.0",
5760
"jose": "^5.1.3"
5861
}

packages/abstraxion/src/components/Abstraxion/index.tsx

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { ErrorDisplay } from "../ErrorDisplay";
1111
import { AbstraxionSignin } from "../AbstraxionSignin";
1212
import { Connected } from "@/src/components/Connected/Connected.tsx";
13+
import { WalletSelect } from "../WalletSelect";
1314
import { AbstraxionAuth } from "@burnt-labs/abstraxion-core";
1415
import {
1516
BrowserRedirectStrategy,
@@ -32,6 +33,7 @@ export function Abstraxion({ onClose }: ModalProps): JSX.Element | null {
3233
isConnected,
3334
showModal,
3435
setShowModal,
36+
walletAuthMode,
3537
} = useContext(AbstraxionContext);
3638

3739
const closeOnEscKey = useCallback(
@@ -53,21 +55,68 @@ export function Abstraxion({ onClose }: ModalProps): JSX.Element | null {
5355

5456
if (!showModal) return null;
5557

58+
// Determine what to show based on auth mode and connection state
59+
const renderContent = () => {
60+
if (abstraxionError) {
61+
return <ErrorDisplay />;
62+
}
63+
64+
if (abstraxionAccount || isConnected) {
65+
return <Connected onClose={onClose} />;
66+
}
67+
68+
// Not connected - show signin flow
69+
if (walletAuthMode === 'redirect') {
70+
// Existing OAuth flow via dashboard
71+
return <AbstraxionSignin />;
72+
} else {
73+
// Direct mode - show wallet selection
74+
return <WalletSelect />;
75+
}
76+
};
77+
5678
return (
5779
<Dialog onOpenChange={onClose} open={showModal}>
5880
<DialogContent>
59-
{abstraxionError ? (
60-
<ErrorDisplay />
61-
) : abstraxionAccount || isConnected ? (
62-
<Connected onClose={onClose} />
63-
) : !abstraxionAccount ? (
64-
<AbstraxionSignin />
65-
) : null}
81+
{renderContent()}
6682
</DialogContent>
6783
</Dialog>
6884
);
6985
}
7086

87+
/**
88+
* Custom signer interface for Turnkey, Privy, etc.
89+
*/
90+
export interface CustomSigner {
91+
type: 'Secp256K1' | 'EthWallet';
92+
sign: (message: string) => Promise<string>;
93+
getPubkey?: () => Promise<string>; // For Secp256K1
94+
getAddress?: () => Promise<string>; // For EthWallet
95+
}
96+
97+
/**
98+
* Wallet authentication configuration
99+
*/
100+
export interface WalletAuthConfig {
101+
/** Authentication mode: redirect (default), direct (in-app), or local (no AA API) */
102+
mode?: 'redirect' | 'direct' | 'local';
103+
104+
/** Custom AA API URL (for direct mode) */
105+
aaApiUrl?: string;
106+
107+
/** Custom signer (Turnkey, Privy, etc.) */
108+
customSigner?: CustomSigner;
109+
110+
/** Local mode configuration (for building transactions without AA API) */
111+
localConfig?: {
112+
codeId: number;
113+
checksum: string;
114+
feeGranter: string;
115+
workerAddress?: string;
116+
addressPrefix?: string;
117+
};
118+
}
119+
71120
export interface AbstraxionConfig {
72121
contracts?: ContractGrantDescription[];
73122
rpcUrl?: string;
@@ -76,6 +125,9 @@ export interface AbstraxionConfig {
76125
callbackUrl?: string;
77126
treasury?: string;
78127
gasPrice?: string;
128+
129+
/** NEW: Wallet authentication configuration */
130+
walletAuth?: WalletAuthConfig;
79131
}
80132

81133
export function AbstraxionProvider({
@@ -94,6 +146,7 @@ export function AbstraxionProvider({
94146
callbackUrl={config.callbackUrl}
95147
treasury={config.treasury}
96148
gasPrice={config.gasPrice}
149+
walletAuth={config.walletAuth}
97150
>
98151
{children}
99152
</AbstraxionContextProvider>

packages/abstraxion/src/components/AbstraxionContext/index.tsx

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { testnetChainInfo, xionGasValues } from "@burnt-labs/constants";
44
import { GasPrice } from "@cosmjs/stargate";
55
import { SignArbSecp256k1HdWallet } from "@burnt-labs/abstraxion-core";
66
import { abstraxionAuth } from "../Abstraxion";
7+
import { useWalletAuth, type WalletAuthState } from "../../hooks/useWalletAuth";
8+
import type { WalletAuthConfig } from "../Abstraxion";
79

810
export type SpendLimit = { denom: string; amount: string };
911

@@ -41,6 +43,10 @@ export interface AbstraxionContextProps {
4143
gasPrice: GasPrice;
4244
logout: () => void;
4345
login: () => Promise<void>;
46+
47+
// NEW: Wallet authentication state
48+
walletAuthMode: 'redirect' | 'direct' | 'local';
49+
walletAuthState: WalletAuthState | null;
4450
}
4551

4652
export const AbstraxionContext = createContext<AbstraxionContextProps>(
@@ -57,6 +63,7 @@ export function AbstraxionContextProvider({
5763
treasury,
5864
indexerUrl,
5965
gasPrice,
66+
walletAuth,
6067
}: {
6168
children: ReactNode;
6269
contracts?: ContractGrantDescription[];
@@ -68,6 +75,7 @@ export function AbstraxionContextProvider({
6875
treasury?: string;
6976
indexerUrl?: string;
7077
gasPrice?: string;
78+
walletAuth?: WalletAuthConfig;
7179
}): JSX.Element {
7280
// Initialize all loading states as false for consistent hydration, then detect OAuth in useEffect
7381
const [isConnected, setIsConnected] = useState(false);
@@ -91,6 +99,24 @@ export function AbstraxionContextProvider({
9199
gasPriceDefault = GasPrice.fromString("0.001uxion");
92100
}
93101

102+
// Determine wallet auth mode
103+
const walletAuthMode = walletAuth?.mode || 'redirect';
104+
105+
// Initialize wallet auth hook only for direct/local modes
106+
const walletAuthState = useWalletAuth({
107+
config: walletAuth || {},
108+
onSuccess: (smartAccountAddress, walletInfo) => {
109+
// Direct mode connection successful
110+
setGranterAddress(smartAccountAddress);
111+
setIsConnected(true);
112+
setShowModal(false);
113+
},
114+
onError: (error) => {
115+
setAbstraxionError(error);
116+
setIsConnecting(false);
117+
},
118+
});
119+
94120
const configureInstance = useCallback(() => {
95121
abstraxionAuth.configureAbstraxionInstance(
96122
rpcUrl,
@@ -205,10 +231,25 @@ export function AbstraxionContextProvider({
205231

206232
try {
207233
await abstraxionAuth.login();
234+
try {
235+
setIsConnecting(true);
236+
237+
// Check wallet auth mode
238+
if (walletAuthMode === 'redirect') {
239+
// Existing OAuth flow via dashboard redirect
240+
await abstraxionAuth.login();
241+
} else {
242+
// Direct or local mode - show modal with wallet selection
243+
setShowModal(true);
244+
setIsConnecting(false); // Reset since wallet selection is async
245+
}
208246
} catch (error) {
209247
throw error; // Re-throw to allow handling by the caller
210248
} finally {
211249
// Keep isLoggingIn true until auth state change sets isConnecting (only for manual login)
250+
if (walletAuthMode === 'redirect') {
251+
setIsConnecting(false);
252+
}
212253
}
213254
}
214255

@@ -237,8 +278,14 @@ export function AbstraxionContextProvider({
237278
setIsInitializing(false);
238279
setIsConnecting(false);
239280
setIsReturningFromAuth(false);
281+
282+
// Clear wallet auth state if in direct mode
283+
if (walletAuthMode !== 'redirect') {
284+
walletAuthState.disconnect();
285+
}
286+
240287
abstraxionAuth?.logout();
241-
}, [abstraxionAuth]);
288+
}, [abstraxionAuth, walletAuthMode, walletAuthState]);
242289

243290
return (
244291
<AbstraxionContext.Provider
@@ -269,6 +316,8 @@ export function AbstraxionContextProvider({
269316
login,
270317
logout,
271318
gasPrice: gasPrice ? GasPrice.fromString(gasPrice) : gasPriceDefault,
319+
walletAuthMode,
320+
walletAuthState,
272321
}}
273322
>
274323
{children}

packages/abstraxion/utils/queries.ts

Lines changed: 0 additions & 126 deletions
This file was deleted.

packages/account-management/src/authenticators/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Authenticator } from "../indexer-strategies/types";
2-
import { SmartAccountWithCodeId } from "../indexer-strategies/types";
1+
import { Authenticator, SmartAccountWithCodeId } from "../types/authenticator";
32

43
/**
54
* Checks if an authenticator already exists in the list

packages/account-management/src/grants/authz.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SelectedSmartAccount } from "../indexer-strategies/types";
2-
import { ContractGrantDescription } from "../components/AbstraxionGrant/generateContractGrant";
1+
import { SelectedSmartAccount } from "../types/authenticator";
2+
import { ContractGrantDescription } from "../types/grants";
33

44
/**
55
* Checks if any of the contract grant configurations are the current smart account (granter)

packages/account-management/src/grants/feegrant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
AllowanceResponse,
66
ContractsAllowance,
77
MultiAnyAllowance,
8-
} from "../types/allowance-types";
8+
} from "../types/grants";
99

1010
function isAllowedMsgAllowance(
1111
allowance: Allowance,

0 commit comments

Comments
 (0)