diff --git a/packages/crypto/src/wallets/third-party/hooks/useChainId.tsx b/packages/crypto/src/wallets/third-party/hooks/useChainId.tsx index a012602e..2ecb6ff5 100644 --- a/packages/crypto/src/wallets/third-party/hooks/useChainId.tsx +++ b/packages/crypto/src/wallets/third-party/hooks/useChainId.tsx @@ -2,6 +2,11 @@ import { useMemo, useSyncExternalStore } from 'react' import { EthWalletConnectorBase } from '../classes' +/** + * Subscribe to chainId changes from a given wallet + * + * Note: Its easier for ethWalletConnector to be defined to avoid complex method signatures for subscribe function + **/ export const useChainId = (ethWalletConnector: EthWalletConnectorBase) => { const { getSnapShot, subscribe } = useMemo(() => { if (ethWalletConnector.installed) { diff --git a/packages/crypto/src/wallets/third-party/hooks/useConnect.tsx b/packages/crypto/src/wallets/third-party/hooks/useConnect.tsx index 92af7f77..3acab15c 100644 --- a/packages/crypto/src/wallets/third-party/hooks/useConnect.tsx +++ b/packages/crypto/src/wallets/third-party/hooks/useConnect.tsx @@ -22,6 +22,7 @@ const handleActionRejected = (e: unknown, rejectCallback: (e: JsonRpcError['erro } } +/** Initiate a connection to the passed in wallet */ export const useConnectWallet = (ethWalletConnector: EthWalletConnectorBase) => { const [connectRefused, setConnectRefused] = useState(false) const [connectError, setConnectError] = useState() diff --git a/packages/crypto/src/wallets/third-party/hooks/useCurrentAccount.tsx b/packages/crypto/src/wallets/third-party/hooks/useCurrentAccount.tsx index cf443501..7fb2c3ec 100644 --- a/packages/crypto/src/wallets/third-party/hooks/useCurrentAccount.tsx +++ b/packages/crypto/src/wallets/third-party/hooks/useCurrentAccount.tsx @@ -3,11 +3,16 @@ import { useMemo, useSyncExternalStore } from 'react' import { EthWalletConnectorBase } from '../classes' +/** + * Subscribe to account changes from a given wallet + * + * Note: Its easier for ethWalletConnector to be defined to avoid complex method signatures for subscribe function + **/ export const useCurrentAccountExternal = (ethWalletConnector: EthWalletConnectorBase) => { const { getSnapShot, subscribe } = useMemo(() => { return { getSnapShot: () => ethWalletConnector.allowedAccounts, - subscribe: (notifier: () => void) => ethWalletConnector.subscribeToAccountsChanges(notifier), + subscribe: (notifier: () => void) => ethWalletConnector?.subscribeToAccountsChanges(notifier), } }, [ethWalletConnector]) @@ -23,7 +28,7 @@ export const useCurrentAccount = (ethWalletConnector: EthWalletConnectorBase): [ * see - https://docs.metamask.io/wallet/how-to/connect/access-accounts/#handle-accounts */ const [currentAddress, additionalAddresses] = useMemo(() => { - return addresses.length > 0 ? [EthAddress.fromString(addresses[0]), addresses.slice(1, addresses.length)] : [undefined, []] + return addresses && addresses.length > 0 ? [EthAddress.fromString(addresses[0]), addresses.slice(1, addresses.length)] : [undefined, []] }, [addresses]) if (ethWalletConnector.installed) { diff --git a/packages/crypto/src/wallets/third-party/hooks/useSigner.tsx b/packages/crypto/src/wallets/third-party/hooks/useSigner.tsx index c491a182..6c677748 100644 --- a/packages/crypto/src/wallets/third-party/hooks/useSigner.tsx +++ b/packages/crypto/src/wallets/third-party/hooks/useSigner.tsx @@ -4,6 +4,7 @@ import { JsonRpcSigner } from 'ethers' import { EthWalletConnectorBase } from '../classes' +/** Locate the signer on the passed wallet for a given address */ export const useSigner = (ethWalletConnector: EthWalletConnectorBase, localAddress?: EthAddress): JsonRpcSigner | undefined => { const [signer] = usePromise(async () => { if (ethWalletConnector.installed) {