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EAAqBO,cAAc,CACjCrB,YAAaJ,IAEfuB,OAAOG,SAASC,QAClB,CACF,IACA,EAKH,C","sources":["hooks/auth/useSwitchSession.ts"],"sourcesContent":["import { useDispatch, useSelector } from 'react-redux';\nimport LocalStorage from 'utils/bom-dom-manipulation/local-storage';\nimport { CommandNames } from 'utils/constants/swarm/swarm-command-names';\nimport { storageKeyName } from 'utils/generic/storage-key-name';\nimport { swarmCommand } from 'services/get-swarm-data';\nimport { setRememberMe, setUserLoggedIn } from 'store/actions';\nimport { getUser } from 'store/selectors/user-data';\n\ntype TChildSessionData = { details?: { Token: string } };\n\nexport const useSwitchSession = () => {\n  const dispatch = useDispatch();\n  const user: Record<string, any> = useSelector(getUser);\n  const parentAccountCurrency = LocalStorage.getItem(\n    storageKeyName('account', 'PARENT_ACCOUNT_CURRENCY')\n  );\n\n  const parentCurrency =\n    parentAccountCurrency !== 'null' ? parentAccountCurrency : user.currency;\n\n  const switchSession = (currency: string): void => {\n    LocalStorage.setItem(\n      storageKeyName('account', 'SWITCH_MULTI_ACCOUNT'),\n      'true'\n    );\n    const params =\n      currency === parentCurrency\n        ? {}\n        : { currency_id: currency === 'USDT' ? 'TUS' : currency };\n\n    const command =\n      currency === parentCurrency\n        ? CommandNames.GET_PARENT_SESSION\n        : CommandNames.GET_CHILD_SESSION;\n\n    swarmCommand(command, params, (data: TChildSessionData) => {\n      if (data?.details?.Token) {\n        const authData = JSON.parse(\n          LocalStorage.getItem(storageKeyName('account', 'AUTH_DATA'))\n        );\n\n        if (authData?.auth_token) {\n          authData.auth_token = data.details.Token;\n\n          if (!user.owner_id) {\n            const parentAccountCurrency = LocalStorage.getItem(\n              storageKeyName('account', 'PARENT_ACCOUNT_CURRENCY')\n            );\n\n            LocalStorage.setItem(\n              storageKeyName('account', 'PARENT_ACCOUNT_CURRENCY'),\n              user.currency || parentAccountCurrency\n            );\n          }\n\n          dispatch(setRememberMe(false));\n          dispatch(setUserLoggedIn(false));\n\n          LocalStorage.setItem(\n            storageKeyName('account', 'AUTH_DATA'),\n            JSON.stringify(authData)\n          );\n\n          window.__dataspot__?.updateProfile({\n            currency_id: currency\n          });\n          window.location.reload();\n        }\n      }\n    });\n  };\n\n  return {\n    switchSession: switchSession\n  };\n};\n"],"names":["useSwitchSession","dispatch","useDispatch","user","useSelector","getUser","parentAccountCurrency","LocalStorage","getItem","storageKeyName","parentCurrency","currency","switchSession","setItem","params","currency_id","command","CommandNames","GET_PARENT_SESSION","GET_CHILD_SESSION","swarmCommand","data","_data$details","details","Token","authData","JSON","parse","auth_token","_window$__dataspot__","owner_id","setRememberMe","setUserLoggedIn","stringify","window","__dataspot__","updateProfile","location","reload"],"sourceRoot":""}