{
  "version": 3,
  "sources": ["../../../src/methods/initApp/initApp.ts"],
  "sourcesContent": ["import { safeWindow } from 'constants/window.constants';\nimport { defineCustomElements } from 'lib/sdkDappUi';\nimport { LogoutManager } from 'managers/LogoutManager/LogoutManager';\nimport { ToastManager } from 'managers/ToastManager';\nimport { registerCallbacks } from 'managers/TransactionManager/helpers/sessionCallbacks';\nimport { restoreProvider } from 'providers/helpers/restoreProvider';\nimport { ProviderFactory } from 'providers/ProviderFactory';\nimport { ICustomProvider } from 'providers/types/providerFactory.types';\nimport { getDefaultNativeAuthConfig } from 'services/nativeAuth/methods/getDefaultNativeAuthConfig';\nimport { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';\nimport {\n  setNativeAuthConfig,\n  setWalletConnectConfig,\n  setProviderSettings\n} from 'store/actions/config/configActions';\nimport { initializeNetwork } from 'store/actions/network/initializeNetwork';\nimport { defaultStorageCallback } from 'store/storage';\nimport { initStore } from 'store/store';\nimport { ThemesEnum } from 'types/theme.types';\nimport { refreshAccount } from 'utils/account/refreshAccount';\nimport { switchTheme } from 'utils/visual/switchTheme';\nimport { InitAppType } from './initApp.types';\nimport { getIsLoggedIn } from '../account/getIsLoggedIn';\nimport { setGasStationMetadata } from './gasStationMetadata/setGasStationMetadata';\nimport { waitForStoreRehydration } from './helpers/waitForStoreRehydration';\nimport { getAccount } from '../account/getAccount';\nimport { trackTransactions } from '../trackTransactions/trackTransactions';\nimport { registerWebsocketListener } from './websocket/registerWebsocket';\n\nconst defaultInitAppProps = {\n  storage: {\n    getStorageCallback: defaultStorageCallback\n  }\n};\n\n/**\n * Flag indicating whether the app has already been initialized.\n *\n * Prevents repeated initialization steps such as provider restoration,\n * websocket listener registration, and transaction tracking setup.\n * This ensures that multiple calls to `initApp` do not cause duplicated\n * subscriptions or side effects.\n *\n * @internal\n */\nlet isAppInitialized = false;\nlet isInitializing = false;\n\n/**\n * Reset the initialization state. Used primarily for testing.\n * @internal\n */\nexport function resetInitAppState() {\n  isAppInitialized = false;\n  isInitializing = false;\n}\n\n/**\n * Initializes the dApp with the given configuration.\n * @param props - The configuration for the dApp initialization.\n *\n * @example\n * ```ts\n   initApp({\n      nativeAuth: true,\n      environment: EnvironmentsEnum.devnet\n   });\n *  ```\n * */\nexport async function initApp({\n  storage = defaultInitAppProps.storage,\n  dAppConfig,\n  customProviders\n}: InitAppType) {\n  if (isInitializing) {\n    return;\n  }\n\n  isInitializing = true;\n\n  const defaultTheme = dAppConfig?.theme ?? ThemesEnum.dark;\n  await defineCustomElements();\n\n  switchTheme(defaultTheme);\n\n  const { getStorageCallback } = storage;\n\n  const store = initStore(getStorageCallback);\n\n  await waitForStoreRehydration({\n    store,\n    getStorageCallback\n  });\n\n  const { apiAddress } = await initializeNetwork({\n    customNetworkConfig: dAppConfig.network,\n    environment: dAppConfig.environment\n  });\n\n  let nativeAuthConfig: NativeAuthConfigType | null = null;\n\n  if (dAppConfig?.nativeAuth) {\n    nativeAuthConfig =\n      typeof dAppConfig.nativeAuth === 'boolean' &&\n      dAppConfig.nativeAuth === true\n        ? getDefaultNativeAuthConfig({ apiAddress })\n        : getDefaultNativeAuthConfig(dAppConfig.nativeAuth);\n  }\n\n  setNativeAuthConfig(nativeAuthConfig);\n  setWalletConnectConfig(dAppConfig?.providers?.walletConnect ?? null);\n  setProviderSettings(dAppConfig?.providers?.settings ?? null);\n\n  const isLoggedIn = getIsLoggedIn();\n  const account = getAccount();\n  const toastManager = ToastManager.getInstance();\n  await toastManager.init({\n    successfulToastLifetime:\n      dAppConfig.transactionTracking?.successfulToastLifetime\n  });\n\n  const usedProviders: ICustomProvider[] = [\n    ...((safeWindow as any)?.multiversx?.providers ?? []),\n    ...(customProviders || [])\n  ];\n\n  const uniqueProviders = usedProviders.filter(\n    (provider, index, arr) =>\n      index === arr.findIndex((item) => item.type === provider.type)\n  );\n\n  ProviderFactory.customProviders = uniqueProviders || [];\n\n  if (!isAppInitialized) {\n    await restoreProvider();\n\n    if (isLoggedIn) {\n      await refreshAccount();\n      await registerWebsocketListener(account.address);\n      trackTransactions();\n      LogoutManager.getInstance().init();\n      registerCallbacks({\n        onSuccess: dAppConfig.transactionTracking?.onSuccess,\n        onFail: dAppConfig.transactionTracking?.onFail\n      });\n    }\n  }\n\n  if (account?.shard != null) {\n    await setGasStationMetadata({\n      shard: Number(account.shard),\n      apiAddress\n    });\n  }\n\n  isAppInitialized = true;\n  isInitializing = false;\n}\n"],
  "mappings": "gnWA6BA,IAAMA,EAAsB,CAC1B,QAAS,CACP,mBAAoBC,CACtB,CACF,EAYIC,EAAmB,GACnBC,EAAiB,GAMd,SAASC,IAAoB,CAClCF,EAAmB,GACnBC,EAAiB,EACnB,CAcA,eAAsBE,GAAQ,CAC5B,QAAAC,EAAUN,EAAoB,QAC9B,WAAAO,EACA,gBAAAC,CACF,EAAgB,CACd,GAAIL,EACF,OAGFA,EAAiB,GAEjB,IAAMM,EAAeF,GAAY,wBACjC,MAAMG,EAAqB,EAE3BC,EAAYF,CAAY,EAExB,GAAM,CAAE,mBAAAG,CAAmB,EAAIN,EAEzBO,EAAQC,EAAUF,CAAkB,EAE1C,MAAMG,EAAwB,CAC5B,MAAAF,EACA,mBAAAD,CACF,CAAC,EAED,GAAM,CAAE,WAAAI,CAAW,EAAI,MAAMC,EAAkB,CAC7C,oBAAqBV,EAAW,QAChC,YAAaA,EAAW,WAC1B,CAAC,EAEGW,EAAgD,KAEhDX,GAAY,aACdW,EACE,OAAOX,EAAW,YAAe,WACjCA,EAAW,aAAe,GACtBY,EAA2B,CAAE,WAAAH,CAAW,CAAC,EACzCG,EAA2BZ,EAAW,UAAU,GAGxDa,EAAoBF,CAAgB,EACpCG,EAAuBd,GAAY,WAAW,eAAiB,IAAI,EACnEe,EAAoBf,GAAY,WAAW,UAAY,IAAI,EAE3D,IAAMgB,EAAaC,EAAc,EAC3BC,EAAUC,EAAW,EAE3B,MADqBC,EAAa,YAAY,EAC3B,KAAK,CACtB,wBACEpB,EAAW,qBAAqB,uBACpC,CAAC,EAOD,IAAMqB,EALmC,CACvC,GAAKC,GAAoB,YAAY,WAAa,CAAC,EACnD,GAAIrB,GAAmB,CAAC,CAC1B,EAEsC,OACpC,CAACsB,EAAUC,EAAOC,IAChBD,IAAUC,EAAI,UAAWC,GAASA,EAAK,OAASH,EAAS,IAAI,CACjE,EAEAI,EAAgB,gBAAkBN,GAAmB,CAAC,EAEjD1B,IACH,MAAMiC,EAAgB,EAElBZ,IACF,MAAMa,EAAe,EACrB,MAAMC,EAA0BZ,EAAQ,OAAO,EAC/Ca,EAAkB,EAClBC,EAAc,YAAY,EAAE,KAAK,EACjCC,EAAkB,CAChB,UAAWjC,EAAW,qBAAqB,UAC3C,OAAQA,EAAW,qBAAqB,MAC1C,CAAC,IAIDkB,GAAS,OAAS,MACpB,MAAMgB,EAAsB,CAC1B,MAAO,OAAOhB,EAAQ,KAAK,EAC3B,WAAAT,CACF,CAAC,EAGHd,EAAmB,GACnBC,EAAiB,EACnB",
  "names": ["defaultInitAppProps", "defaultStorageCallback", "isAppInitialized", "isInitializing", "resetInitAppState", "initApp", "storage", "dAppConfig", "customProviders", "defaultTheme", "defineCustomElements", "switchTheme", "getStorageCallback", "store", "initStore", "waitForStoreRehydration", "apiAddress", "initializeNetwork", "nativeAuthConfig", "getDefaultNativeAuthConfig", "setNativeAuthConfig", "setWalletConnectConfig", "setProviderSettings", "isLoggedIn", "getIsLoggedIn", "account", "getAccount", "ToastManager", "uniqueProviders", "safeWindow", "provider", "index", "arr", "item", "ProviderFactory", "restoreProvider", "refreshAccount", "registerWebsocketListener", "trackTransactions", "LogoutManager", "registerCallbacks", "setGasStationMetadata"]
}
