mirror of
https://github.com/luxfhe/research-ocp-fhe.git
synced 2026-11-03 06:05:38 +00:00
35 lines
967 B
TypeScript
35 lines
967 B
TypeScript
'use client';
|
|
|
|
import { useAccount, useConnectorClient } from 'wagmi';
|
|
import { useRole } from './use-role';
|
|
import { clientToSigner } from '@/lib/wagmi-etheres-adapter';
|
|
import { Wallet } from 'ethers';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
|
export function useSigner() {
|
|
const { isOwnWallet, selectedWallet } = useRole();
|
|
const { data: connectorClient } = useConnectorClient();
|
|
const { address: connectedAddress } = useAccount();
|
|
|
|
return useQuery({
|
|
queryKey: [
|
|
'signer',
|
|
isOwnWallet,
|
|
selectedWallet ?? '0x',
|
|
connectedAddress ?? '0x',
|
|
],
|
|
queryFn: () => {
|
|
if (isOwnWallet) {
|
|
// Use connected wallet via wagmi
|
|
return connectorClient ? clientToSigner(connectorClient) : null;
|
|
} else {
|
|
// Use predefined wallet with private key
|
|
if (selectedWallet?.privateKey) {
|
|
return new Wallet(selectedWallet.privateKey);
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
});
|
|
}
|