import { useContext } from 'react';
import { ArconnectContextInterface } from '../types';
import { ArconnectContext } from './context';

export function useArconnect(): ArconnectContextInterface {
  const useArconnectContext: ArconnectContextInterface =
    useContext(ArconnectContext);

  if (useArconnectContext === null) {
    throw new Error(
      'useArconnect() can only be used inside of <ArconnectProvider />, ' +
        'please declare it at a higher level.'
    );
  }

  return useArconnectContext;
}
