UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 5.07 kB
import{jsx as t,jsxs as e,Fragment as r}from"react/jsx-runtime";import{AlertTriangle as i,Phone as a,Lock as o}from"lucide-react";import{styled as n}from"styled-components";import{u as s}from"./context-Bycd1SKV.mjs";import{a as c,P as l}from"./index-CCyaupaz.mjs";import{c as m,b as p,a as d,e as u}from"./internal-context-e-Eni5bG.mjs";import{a as T}from"./get-is-unified-wallet-DvKS5IUO.mjs";import{R as g}from"./reservoir-kvLjIrEo.mjs";import{S as h}from"./ScreenLayout-CddsD3Of.mjs";import"react";import"@privy-io/js-sdk-core";import"tinycolor2";import"uuid";import"jose";import"eventemitter3";import"./useActiveWallet-Bsy5GTCV.mjs";import"zustand";import"react-device-detect";import"./prepareFundingModalData-CIgFwA7s.mjs";import"./events-context-CI0iqAXA.mjs";import"viem";import"viem/utils";import"./getPublicClient-A9RSftUZ.mjs";import"./useWallets-D0lpBS44.mjs";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"mipd";import"@privy-io/popup";import"./paths-3HW55qZg.mjs";import"./usePrivy-BaiIHGte.mjs";import"@scure/base";import"@headlessui/react";import"@walletconnect/ethereum-provider";import"@privy-io/urls";import"ofetch";import"js-cookie";import"./frame-CwE9r3cT.mjs";import"@privy-io/routes";import"x402/client";import"@privy-io/api-base";import"viem/accounts";import"./use-sign-with-user-signer-eEm9Olt_.mjs";import"./getEmbeddedConnectedWallet-CM6cDQCS.mjs";import"./Button-B8mqatRx.mjs";import"./Screen-BTyXgDrd.mjs";import"./ModalHeader-BLGC-7ev.mjs";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"./index-CJMgUOnw.mjs";const y=({error:n,allowlistConfig:s,onRetry:c,onCaptchaReset:T,onBack:y})=>{let f=((n,s)=>{if(n instanceof g)return{title:"Transaction failed",detail:/*#__PURE__*/e(r,{children:[/*#__PURE__*/t("span",{children:n.message}),/*#__PURE__*/e("span",{children:[" ","Check the"," ",/*#__PURE__*/t(w,{href:n.relayLink,target:"_blank",children:"refund status"}),"."]})]}),ctaText:"Try again",icon:i};if(n instanceof d)switch(n.privyErrorCode){case p.CLIENT_REQUEST_TIMEOUT:return{title:"Timed out",detail:n.message,ctaText:"Try again",icon:i};case p.INSUFFICIENT_BALANCE:return{title:"Insufficient balance",detail:n.message,ctaText:"Try again",icon:i};case p.TRANSACTION_FAILURE:return{title:"Transaction failure",detail:n.message,ctaText:"Try again",icon:i};default:return{title:"Something went wrong",detail:"Try again later",ctaText:"Try again",icon:i}}else{if(n instanceof l&&"twilio_verification_failed"===n.type)return{title:"Something went wrong",detail:n.message,ctaText:"Try again",icon:a};if(!(n instanceof m))return n instanceof u&&n.status&&[400,422].includes(n.status)?{title:"Something went wrong",detail:n.message,ctaText:"Try again",icon:i}:{title:"Something went wrong",detail:"Try again later",ctaText:"Try again",icon:i};switch(n.privyErrorCode){case p.INVALID_CAPTCHA:return{title:"Something went wrong",detail:"Please try again.",ctaText:"Try again",icon:i};case p.DISALLOWED_LOGIN_METHOD:return{title:"Not allowed",detail:n.message,ctaText:"Try another method",icon:i};case p.ALLOWLIST_REJECTED:return{title:s.errorTitle||"You don't have access to this app",detail:s.errorDetail||"Have you been invited?",ctaText:s.errorCtaText||"Try another account",icon:o};case p.CAPTCHA_FAILURE:return{title:"Something went wrong",detail:"You did not pass CAPTCHA. Please try again.",ctaText:"Try again",icon:null};case p.CAPTCHA_TIMEOUT:return{title:"Something went wrong",detail:"Something went wrong! Please try again later.",ctaText:"Try again",icon:null};case p.LINKED_TO_ANOTHER_USER:return{title:"Authentication failed",detail:"This account has already been linked to another user.",ctaText:"Try again",icon:i};case p.NOT_SUPPORTED:return{title:"This region is not supported",detail:"SMS authentication from this region is not available",ctaText:"Try another method",icon:i};case p.TOO_MANY_REQUESTS:return{title:"Request failed",detail:"Too many attempts.",ctaText:"Try again later",icon:i};default:return{title:"Something went wrong",detail:"Try again later",ctaText:"Try again",icon:i}}}})(n,s);/*#__PURE__*/return t(h,{title:f.title,subtitle:f.detail,icon:f.icon,onBack:y,iconVariant:"error",primaryCta:{label:f.ctaText,onClick:()=>{n instanceof m&&(n.privyErrorCode===p.INVALID_CAPTCHA&&T?.(),n.privyErrorCode===p.ALLOWLIST_REJECTED&&s.errorCtaLink)?window.location.href=s.errorCtaLink:c?.()},variant:"error"},watermark:!0})},f={component:()=>{let{navigate:e,data:r,lastScreen:i,currentScreen:a}=T(),o=s(),{reset:n}=c(),l=r?.errorModalData?.previousScreen||(i===a?void 0:i);/*#__PURE__*/return t(y,{error:r?.errorModalData?.error||Error(),allowlistConfig:o.allowlistConfig,onRetry:()=>{e(l||"LandingScreen",!1)},onCaptchaReset:n})}};let w=/*#__PURE__*/n.a.withConfig({displayName:"Link",componentId:"sc-506514cb-0"})(["color:var(--privy-color-accent) !important;font-weight:600;"]);export{f as ErrorScreen,y as ErrorScreenView,f as default};