{"version":3,"file":"WalletButtons.mjs","sources":["../../../../../../../../../../web/src/ui/b2c/screens/Crypto/WalletButtons.tsx"],"sourcesContent":["import { MessageDescriptor } from '@lingui/core';\nimport { msg } from '@lingui/core/macro';\nimport { useLingui } from '@lingui/react/macro';\nimport { Wallets } from '@stytch/core/public';\nimport * as React from 'react';\n\nimport { GenericWalletIcon } from '../../../../assets';\nimport { isWalletVisible, useCryptoButtonProps, WalletToText } from '../../../../utils/crypto';\nimport Button from '../../../components/atoms/Button';\nimport ButtonColumn from '../../../components/molecules/ButtonColumn';\nimport { AppScreens, useConfig, useGlobalReducer } from '../../GlobalContextProvider';\n\nconst MAX_BUTTONS = 6;\n\nconst walletMessages = {\n  [Wallets.Phantom]: msg({ id: 'crypto.wallet.continueWithPhantom', message: 'Continue with Phantom' }),\n  [Wallets.Binance]: msg({ id: 'crypto.wallet.continueWithBinance', message: 'Continue with Binance' }),\n  [Wallets.Coinbase]: msg({ id: 'crypto.wallet.continueWithCoinbase', message: 'Continue with Coinbase' }),\n  [Wallets.Metamask]: msg({ id: 'crypto.wallet.continueWithMetamask', message: 'Continue with Metamask' }),\n  [Wallets.GenericEthereumWallet]: msg({\n    id: 'crypto.wallet.continueWithEthereum',\n    message: 'Continue with Other Ethereum Wallet',\n  }),\n  [Wallets.GenericSolanaWallet]: msg({\n    id: 'crypto.wallet.continueWithSolana',\n    message: 'Continue with Other Solana Wallet',\n  }),\n} satisfies Record<Wallets, MessageDescriptor>;\n\nexport const CryptoWalletButtons = ({ type }: { type: 'main' | 'other' }) => {\n  const { t } = useLingui();\n  const [state, dispatch] = useGlobalReducer();\n  const config = useConfig();\n\n  const { getIcon, getId } = useCryptoButtonProps();\n\n  const oAuthOptions = config.oauthOptions?.providers.length ?? 0;\n\n  // Crypto Buttons on screen = Maximum Buttons - OAuth Buttons - 1 (Other crypto or set up new wallet)\n  const cryptoButtonsOnMainScreen = MAX_BUTTONS - oAuthOptions - 1;\n  const onWalletStart = (wallet: Wallets) => {\n    dispatch({\n      type: 'update_crypto_state',\n      cryptoState: {\n        ...state.formState.cryptoState,\n        walletOption: wallet,\n      },\n    });\n    dispatch({ type: 'transition', screen: AppScreens.CryptoConnect });\n  };\n\n  const allDetectedWallets = (Object.keys(Wallets) as (keyof typeof Wallets)[]).filter((wallet) =>\n    isWalletVisible(Wallets[wallet]),\n  );\n\n  const renderOtherScreenButton = allDetectedWallets.length > cryptoButtonsOnMainScreen;\n\n  const mainWallets = allDetectedWallets.slice(0, cryptoButtonsOnMainScreen);\n  const otherWallet = allDetectedWallets.slice(cryptoButtonsOnMainScreen);\n\n  const walletsToRender = type === 'main' ? mainWallets : otherWallet;\n\n  return (\n    <ButtonColumn>\n      {walletsToRender.map((wallet) => {\n        const walletEnum = Wallets[wallet];\n        const Icon = getIcon(walletEnum);\n        return (\n          <Button\n            key={wallet}\n            variant=\"outline\"\n            icon={<Icon />}\n            onClick={() => onWalletStart(walletEnum)}\n            id={getId(walletEnum)}\n          >\n            {type === 'main' ? t(walletMessages[walletEnum]) : t(WalletToText[walletEnum])}\n          </Button>\n        );\n      })}\n\n      {renderOtherScreenButton && type === 'main' ? (\n        <Button\n          variant=\"outline\"\n          icon={<GenericWalletIcon />}\n          onClick={() => dispatch({ type: 'transition', screen: AppScreens.CryptoOtherScreen })}\n          id={getId(Wallets.GenericEthereumWallet)}\n        >\n          {t(msg({ id: 'crypto.wallet.continueWithOtherWallet', message: 'Continue with other Crypto Wallet' }))}\n        </Button>\n      ) : (\n        <Button\n          variant=\"outline\"\n          onClick={() => dispatch({ type: 'transition', screen: AppScreens.CryptoSetupWallet })}\n        >\n          {t(msg({ id: 'crypto.wallet.setupNewWallet', message: 'Set up a new crypto wallet' }))}\n        </Button>\n      )}\n    </ButtonColumn>\n  );\n};\n"],"names":["MAX_BUTTONS","walletMessages","Wallets","Phantom","Binance","Coinbase","Metamask","GenericEthereumWallet","GenericSolanaWallet","CryptoWalletButtons","type","useLingui","state","dispatch","useGlobalReducer","config","useConfig","getIcon","getId","useCryptoButtonProps","oAuthOptions","oauthOptions","providers","length","cryptoButtonsOnMainScreen","onWalletStart","wallet","cryptoState","formState","walletOption","screen","AppScreens","CryptoConnect","allDetectedWallets","Object","keys","filter","isWalletVisible","renderOtherScreenButton","mainWallets","slice","otherWallet","walletsToRender","React.createElement","ButtonColumn","map","walletEnum","Icon","Button","key","variant","icon","onClick","id","WalletToText","GenericWalletIcon","CryptoOtherScreen","CryptoSetupWallet"],"mappings":";;;;;;;;;;AAYA,MAAMA,WAAAA,GAAc,CAAA;AAEpB,MAAMC,cAAAA,GAAiB;IACrB,CAACC,OAAAA,CAAQC,OAAO,GAAC;;;;IACjB,CAACD,OAAAA,CAAQE,OAAO,GAAC;;;;IACjB,CAACF,OAAAA,CAAQG,QAAQ,GAAC;;;;IAClB,CAACH,OAAAA,CAAQI,QAAQ,GAAC;;;;IAClB,CAACJ,OAAAA,CAAQK,qBAAqB,GAAC;;;;IAI/B,CAACL,OAAAA,CAAQM,mBAAmB,GAAC;;;;AAI/B,CAAA;AAEO,MAAMC,mBAAAA,GAAsB,CAAC,EAAEC,IAAI,EAA8B,GAAA;AACtE,IAAA,MAAM,EAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,GAAA,EAAA,GAAQC,SAAAA,EAAAA;IACd,MAAM,CAACC,KAAAA,EAAOC,QAAAA,CAAS,GAAGC,gBAAAA,EAAAA;AAC1B,IAAA,MAAMC,MAAAA,GAASC,SAAAA,EAAAA;AAEf,IAAA,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAE,GAAGC,oBAAAA,EAAAA;AAE3B,IAAA,MAAMC,YAAAA,GAAeL,MAAAA,CAAOM,YAAY,EAAEC,UAAUC,MAAAA,IAAU,CAAA;;IAG9D,MAAMC,yBAAAA,GAA4BxB,cAAcoB,YAAAA,GAAe,CAAA;AAC/D,IAAA,MAAMK,gBAAgB,CAACC,MAAAA,GAAAA;QACrBb,QAAAA,CAAS;YACPH,IAAAA,EAAM,qBAAA;YACNiB,W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