import React from 'react'
import { createContext } from 'react'

import { PolkadotExtensionModule, PolkadotExtensionState } from '../../core/interfaces'

export interface PolkadotConnectionPromise {
  resolve: (extensionState: PolkadotExtensionState) => void
  reject: (e: Error) => void
}

interface PolkadotConnectorContextProps {
  extensionModules: PolkadotExtensionModule[] | undefined
  setExtensionModules: React.Dispatch<React.SetStateAction<PolkadotExtensionModule[] | undefined>>
  connectionPromise?: PolkadotConnectionPromise
  setConnectionPromise: React.Dispatch<React.SetStateAction<PolkadotConnectionPromise | undefined>>
}

export const PolkadotConnectorContext = createContext<PolkadotConnectorContextProps>({
  extensionModules: [],
  setExtensionModules: () => {},
  connectionPromise: undefined,
  setConnectionPromise: () => {}
})
