diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz deleted file mode 100644 index 831e628a..00000000 Binary files a/.yarn/install-state.gz and /dev/null differ diff --git a/packages/auto-utils/src/api.ts b/packages/auto-utils/src/api.ts index 26bc354d..5a244844 100644 --- a/packages/auto-utils/src/api.ts +++ b/packages/auto-utils/src/api.ts @@ -1,50 +1,32 @@ -import { ApiPromise as PolkadotApiPromise, WsProvider } from '@polkadot/api' +import { ApiPromise, WsProvider } from '@polkadot/api' import { getNetworkDomainRpcUrls, getNetworkRpcUrls } from './network' -import type { ApiPromise } from './types/api' import type { DomainInput, NetworkInput } from './types/network' -let provider: WsProvider | null = null -let apiInstance: ApiPromise | null = null - -let domainProvider: WsProvider | null = null -let apiDomainInstance: ApiPromise | null = null - export const activate = async (input?: NetworkInput): Promise => { // Get the first rpc urls for the network const rpcUrl = getNetworkRpcUrls(input) // Create the provider - provider = new WsProvider(rpcUrl[0]) + const provider = new WsProvider(rpcUrl[0]) // Create the API instance - apiInstance = await PolkadotApiPromise.create({ provider }) + const api = await ApiPromise.create({ provider }) + await api.isReady - return apiInstance + return api } export const activateDomain = async (input: DomainInput): Promise => { // Get the first rpc urls for the network const rpcUrl = getNetworkDomainRpcUrls(input) // Create the provider - domainProvider = new WsProvider(rpcUrl[0]) + const provider = new WsProvider(rpcUrl[0]) // Create the API instance - apiDomainInstance = await PolkadotApiPromise.create({ provider: domainProvider }) - - return apiDomainInstance -} + const api = await ApiPromise.create({ provider }) + await api.isReady -export const disconnect = async (): Promise => { - // Disconnect the API instance and the provider if they exist - if (apiInstance) { - await apiInstance.disconnect() - apiInstance = null - provider = null - } + return api } -export const disconnectDomain = async (): Promise => { - // Disconnect the API instance and the provider if they exist - if (apiDomainInstance) { - await apiDomainInstance.disconnect() - apiDomainInstance = null - domainProvider = null - } +export const disconnect = async (api: ApiPromise): Promise => { + // Disconnect the API instance and the provider + await api.disconnect() }