"use strict";var e=require("react/jsx-runtime"),r=require("@scure/base"),i=require("lucide-react"),t=require("react"),s=require("styled-components"),o=require("viem"),n=require("@privy-io/js-sdk-core"),a=require("./CopyToClipboard-CC0DCGEH.js"),l=require("./Layouts-D3TOcPhm.js"),c=require("./JsonTree-C28xtYM0.js"),u=require("./wallet-connect-BuohfvHK.js"),d=require("./context-rs-ygOK2.js"),p=require("./internal-context-CdsQ3LEl.js"),y=require("./modal-context-BgeioxwT.js"),g=require("./privy-context-UTJouJ1x.js"),x=require("./ScreenLayout-DaFW0I3a.js");require("./errors-CBapWvRs.js"),require("ofetch"),require("./getPublicClient-CFd_sHBk.js"),require("viem/chains"),require("eventemitter3"),require("tinycolor2"),require("@privy-io/are-addresses-equal"),require("./ModalHeader-Cpls13mi.js"),require("./useActiveWallet-dTc6deka.js"),require("viem/utils"),require("./events-context-Di6--rDg.js"),require("./index-Ub4KpwSY.js"),require("zustand"),require("react-device-detect"),require("./get-entropy-details-for-user-D63rM5_a.js"),require("./user-D2oPA-vS.js"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("./Screen-8NusMFtu.js"),require("./index-ByFhjjzH.js");const q=s.styled.img`
  && {
    height: ${e=>"sm"===e.size?"65px":"140px"};
    width: ${e=>"sm"===e.size?"65px":"140px"};
    border-radius: 16px;
    margin-bottom: 12px;
  }
`;let h=e=>{if(!o.isHex(e))return e;try{let r=o.hexToString(e);return r.includes("�")?e:r}catch{return e}},v=e=>{try{let i=r.base64.decode(e),t=(new TextDecoder).decode(i);return t.includes("�")?e:t}catch{return e}},m=r=>{let{types:i,primaryType:t,...s}=r.typedData;/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(T,{data:s}),/*#__PURE__*/e.jsx(a.CopytoClipboardButton,{text:(o=r.typedData,JSON.stringify(o,null,2)),itemName:"full payload to clipboard"})," "]});var o};const j=({method:r,messageData:t,copy:s,iconUrl:o,isLoading:n,success:a,walletProxyIsLoading:c,errorMessage:u,isCancellable:d,onSign:p,onCancel:y,onClose:g})=>/*#__PURE__*/e.jsx(x.ScreenLayout,{title:s.title,subtitle:s.description,showClose:!0,onClose:g,icon:i.Edit,iconVariant:"subtle",helpText:u?/*#__PURE__*/e.jsx(C,{children:u}):void 0,primaryCta:{label:s.buttonText,onClick:p,disabled:n||a||c,loading:n},secondaryCta:d?{label:"Not now",onClick:y,disabled:n||a||c}:void 0,watermark:!0,children:/*#__PURE__*/e.jsxs(l.FixedGappedContainer,{children:[o?/*#__PURE__*/e.jsx(q,{style:{alignSelf:"center"},size:"sm",src:o,alt:"app image"}):null,/*#__PURE__*/e.jsxs(S,{children:["personal_sign"===r&&/*#__PURE__*/e.jsx(R,{children:h(t)}),"eth_signTypedData_v4"===r&&/*#__PURE__*/e.jsx(m,{typedData:t}),"solana_signMessage"===r&&/*#__PURE__*/e.jsx(R,{children:v(t)})]})]})}),E={component:()=>{let{authenticated:r}=g.usePrivyContext(),{initializeWalletProxy:i,closePrivyModal:s}=p.usePrivyInternal(),{navigate:o,data:a,onUserCloseViaDialogOrKeybindRef:l}=y.usePrivyModal(),[c,x]=t.useState(!0),[q,h]=t.useState(""),[v,m]=t.useState(),[E,S]=t.useState(null),[C,T]=t.useState(!1);t.useEffect((()=>{r||o("LandingScreen")}),[r]),t.useEffect((()=>{i(d.WALLET_PROXY_TIMEOUT).then((e=>{x(!1),e||(h("An error has occurred, please try again."),m(new u.PrivyProviderRpcError(new u.ProviderRpcError(q,n.ProviderErrors.E32603_DEFAULT_INTERNAL_ERROR.eipCode))))}))}),[]);let{method:R,data:b,confirmAndSign:f,onSuccess:P,onFailure:w,uiOptions:_}=a.signMessage,L={title:_?.title||"Sign message",description:_?.description||"Signing this message will not cost you any fees.",buttonText:_?.buttonText||"Sign and continue"},A=e=>{e?P(e):w(v||new u.PrivyProviderRpcError(new u.ProviderRpcError("The user rejected the request.",n.ProviderErrors.E4001_USER_REJECTED_REQUEST.eipCode))),s({shouldCallAuthOnSuccess:!1}),setTimeout((()=>{S(null),h(""),m(void 0)}),200)};l.current=()=>{A(E)};/*#__PURE__*/return e.jsx(j,{method:R,messageData:b,copy:L,iconUrl:_?.iconUrl&&"string"==typeof _.iconUrl?_.iconUrl:void 0,isLoading:C,success:null!==E,walletProxyIsLoading:c,errorMessage:q,isCancellable:_?.isCancellable,onSign:async()=>{T(!0),h("");try{let e=await f();S(e),T(!1),setTimeout((()=>{A(e)}),d.DEFAULT_SUCCESS_SCREEN_DURATION_MS)}catch(e){console.error(e),h("An error has occurred, please try again."),m(new u.PrivyProviderRpcError(new u.ProviderRpcError(q,n.ProviderErrors.E32603_DEFAULT_INTERNAL_ERROR.eipCode))),T(!1)}},onCancel:()=>A(null),onClose:()=>A(E)})}};let S=s.styled.div`
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
`,C=s.styled.p`
  && {
    margin: 0;
    width: 100%;
    text-align: center;
    color: var(--privy-color-error-dark);
    font-size: 14px;
    line-height: 22px;
  }
`,T=s.styled(c.DisplayJsonTree)`
  margin-top: 0;
`,R=s.styled(c.Message)`
  margin-top: 0;
`;exports.SignRequestScreen=E,exports.SignRequestView=j,exports.default=E;
//# sourceMappingURL=SignRequestScreen-0OEZ76q0.js.map
