{
  "version": 3,
  "sources": ["../../src/providers/strategies/LedgerProviderStrategy/helpers/initializeLedgerProvider.ts"],
  "sourcesContent": ["import { LedgerConnectStateManager } from 'managers/internal/LedgerConnectStateManager/LedgerConnectStateManager';\nimport { getIsLoggedIn } from 'methods/account/getIsLoggedIn';\nimport { getLedgerErrorCodes } from './getLedgerErrorCodes';\nimport { getLedgerProvider } from './getLedgerProvider/getLedgerProvider';\n\ntype InitializeLedgerProviderType = {\n  manager: LedgerConnectStateManager | null;\n  resolve: (value: Awaited<ReturnType<typeof getLedgerProvider>>) => void;\n  reject: (reason?: string) => void;\n  shouldInitProvider?: boolean;\n};\n\nconst failInitializeErrorText = 'Check if the MultiversX App is open on Ledger';\n\nexport async function initializeLedgerProvider({\n  manager,\n  resolve,\n  reject,\n  shouldInitProvider\n}: InitializeLedgerProviderType) {\n  const shouldInitiateLogin = !getIsLoggedIn();\n\n  // Calls itself to handle retry logic if the user needs to reconnect to the Ledger provider.\n  const handleRetry = () =>\n    initializeLedgerProvider({ manager, resolve, reject, shouldInitProvider });\n\n  const handleCancel = () => reject('Device unavailable');\n\n  try {\n    manager?.updateAccountScreen({\n      isLoading: true\n    });\n\n    if (manager && shouldInitiateLogin) {\n      manager.subscribeToProviderInit({ handleRetry, handleCancel });\n    }\n\n    const data = await getLedgerProvider({ shouldInitProvider });\n\n    if (manager && shouldInitiateLogin) {\n      manager.unsubscribeFromProviderInit({ handleRetry, handleCancel });\n    }\n\n    resolve(data);\n  } catch (err) {\n    if (!shouldInitiateLogin) {\n      throw err;\n    }\n\n    const { errorMessage, defaultErrorMessage } = getLedgerErrorCodes(err);\n    manager?.updateConnectScreen({\n      error: errorMessage ?? defaultErrorMessage ?? failInitializeErrorText\n    });\n\n    if (manager) {\n      manager.subscribeToProviderInit({ handleRetry, handleCancel });\n    }\n  }\n}\n"],
  "mappings": "sHAYA,IAAMA,EAA0B,gDAEhC,eAAsBC,EAAyB,CAC7C,QAAAC,EACA,QAAAC,EACA,OAAAC,EACA,mBAAAC,CACF,EAAiC,CAC/B,IAAMC,EAAsB,CAACC,EAAc,EAGrCC,EAAc,IAClBP,EAAyB,CAAE,QAAAC,EAAS,QAAAC,EAAS,OAAAC,EAAQ,mBAAAC,CAAmB,CAAC,EAErEI,EAAe,IAAML,EAAO,oBAAoB,EAEtD,GAAI,CACFF,GAAS,oBAAoB,CAC3B,UAAW,EACb,CAAC,EAEGA,GAAWI,GACbJ,EAAQ,wBAAwB,CAAE,YAAAM,EAAa,aAAAC,CAAa,CAAC,EAG/D,IAAMC,EAAO,MAAMC,EAAkB,CAAE,mBAAAN,CAAmB,CAAC,EAEvDH,GAAWI,GACbJ,EAAQ,4BAA4B,CAAE,YAAAM,EAAa,aAAAC,CAAa,CAAC,EAGnEN,EAAQO,CAAI,CACd,OAASE,EAAK,CACZ,GAAI,CAACN,EACH,MAAMM,EAGR,GAAM,CAAE,aAAAC,EAAc,oBAAAC,CAAoB,EAAIC,EAAoBH,CAAG,EACrEV,GAAS,oBAAoB,CAC3B,MAAOW,GAAgBC,GAAuBd,CAChD,CAAC,EAEGE,GACFA,EAAQ,wBAAwB,CAAE,YAAAM,EAAa,aAAAC,CAAa,CAAC,CAEjE,CACF",
  "names": ["failInitializeErrorText", "initializeLedgerProvider", "manager", "resolve", "reject", "shouldInitProvider", "shouldInitiateLogin", "getIsLoggedIn", "handleRetry", "handleCancel", "data", "getLedgerProvider", "err", "errorMessage", "defaultErrorMessage", "getLedgerErrorCodes"]
}
