import React, { PropsWithChildren, useState } from 'react'

import { PolkadotExtensionModule } from '../../core/interfaces'
import {
  PolkadotConnectionPromise,
  PolkadotConnectorContext
} from '../../store/polkadot-connector/context'

interface PolkadotConnectorProviderProps {}

export const PolkadotConnectorProvider: React.FC<
  PropsWithChildren<PolkadotConnectorProviderProps>
> = ({ children }) => {
  const [extensionModules, setExtensionModules] = useState<PolkadotExtensionModule[] | undefined>(
    undefined
  )
  const [connectionPromise, setConnectionPromise] = useState<PolkadotConnectionPromise | undefined>(
    undefined
  )

  return (
    <PolkadotConnectorContext.Provider
      value={{ extensionModules, setExtensionModules, connectionPromise, setConnectionPromise }}
    >
      {children}
    </PolkadotConnectorContext.Provider>
  )
}
