{"version":3,"file":"SignMessage.mjs","sources":["../../../../../../../../../../web/src/ui/b2c/screens/Crypto/SignMessage.tsx"],"sourcesContent":["import { useLingui } from '@lingui/react/macro';\nimport { DEFAULT_SESSION_DURATION_MINUTES } from '@stytch/core';\nimport { StytchEventType } from '@stytch/core/public';\nimport React from 'react';\n\nimport { isSolanaWallet, signMessageWithWallet } from '../../../../utils/crypto';\nimport Button from '../../../components/atoms/Button';\nimport Column from '../../../components/atoms/Column';\nimport TextColumn from '../../../components/molecules/TextColumn';\nimport { useMountEffect } from '../../../hooks/useMountEffect';\nimport {\n  AppScreens,\n  useConfig,\n  useErrorCallback,\n  useEventCallback,\n  useGlobalReducer,\n  useStytch,\n} from '../../GlobalContextProvider';\n\nexport const SignMessage = () => {\n  const { t } = useLingui();\n  const onEvent = useEventCallback();\n  const onError = useErrorCallback();\n  const handleError = () => {\n    // eslint-disable-next-line lingui/no-unlocalized-strings -- This is not shown in the UI, just sent to the error callback\n    onError({ message: '[Error] Could not sign message' });\n    dispatch({ type: 'transition', screen: AppScreens.CryptoError });\n  };\n  const stytchClient = useStytch();\n  const config = useConfig();\n  const [state, dispatch] = useGlobalReducer();\n  const { walletChallenge, walletAddress, walletOption } = state.formState.cryptoState;\n  const walletType = isSolanaWallet(walletOption) ? 'solana' : 'ethereum';\n\n  const onSignWallet = async () => {\n    const signature = await signMessageWithWallet({\n      wallet: walletOption,\n      message: walletChallenge,\n      address: walletAddress,\n    });\n\n    stytchClient.cryptoWallets\n      .authenticate({\n        crypto_wallet_address: walletAddress,\n        crypto_wallet_type: walletType,\n        signature,\n        session_duration_minutes: config.sessionOptions?.sessionDurationMinutes ?? DEFAULT_SESSION_DURATION_MINUTES,\n      })\n      .then((data) => {\n        onEvent({ type: StytchEventType.CryptoWalletAuthenticate, data });\n        dispatch({ type: 'transition', screen: AppScreens.CryptoConfirmation });\n      })\n      .catch(handleError);\n  };\n\n  useMountEffect(() => {\n    onSignWallet();\n  });\n\n  return (\n    <Column gap={6}>\n      <TextColumn\n        header={t({ id: 'crypto.signMessage.title', message: 'Completing signature request...' })}\n        body={t({\n          id: 'crypto.signMessage.instruction',\n          message: 'Complete the signature request through the wallet pop up in the right corner of your screen.',\n        })}\n        helper={t({\n          id: 'crypto.troubleHelp',\n          message: 'If you are having trouble, go back to the main screen and try logging in again.',\n        })}\n      />\n\n      <Button variant=\"outline\" onClick={() => dispatch({ type: 'transition', screen: AppScreens.Main })}>\n        {t({ id: 'button.goBack', message: 'Go back' })}\n      </Button>\n    </Column>\n  );\n};\n"],"names":["SignMessage","useLingui","onEvent","useEventCallback","onError","useErrorCallback","handleError","message","dispatch","type","screen","AppScreens","CryptoError","stytchClient","useStytch","config","useConfig","state","useGlobalReducer","walletChallenge","walletAddress","walletOption","formState","cryptoState","walletType","isSolanaWallet","onSignWallet","signature","signMessageWithWallet","wallet","address","cryptoWallets","authenticate","crypto_wallet_address","crypto_wallet_type","session_duration_minutes","sessionOptions","sessionDurationMinutes","DEFAULT_SESSION_DURATION_MINUTES","then","data","StytchEventType","CryptoWalletAuthenticate","CryptoConfirmation","catch","useMountEffect","React","Column","gap","TextColumn","header","body","helper","Button","variant","onClick","Main"],"mappings":";;;;;;;;;;;MAmBaA,WAAAA,GAAc,IAAA;AACzB,IAAA,MAAM,EAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,GAAA,EAAA,GAAQC,SAAAA,EAAAA;AACd,IAAA,MAAMC,OAAAA,GAAUC,gBAAAA,EAAAA;AAChB,IAAA,MAAMC,OAAAA,GAAUC,gBAAAA,EAAAA;AAChB,IAAA,MAAMC,WAAAA,GAAc,IAAA;;QAElBF,OAAAA,CAAQ;YAAEG,OAAAA,EAAS;AAAiC,SAAA,CAAA;QACpDC,QAAAA,CAAS;YAAEC,IAAAA,EAAM,YAAA;AAAcC,YAAAA,MAAAA,EAAQC,WAAWC;AAAY,SAAA,CAAA;AAChE,IAAA,CAAA;AACA,IAAA,MAAMC,YAAAA,GAAeC,SAAAA,EAAAA;AACrB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