import{jsx as e,jsxs as t,Fragment as o}from"react/jsx-runtime";import{base64 as r}from"@scure/base";import{Edit as i}from"lucide-react";import{useState as n,useEffect as a}from"react";import{styled as s}from"styled-components";import{isHex as l,hexToString as c}from"viem";import{ProviderErrors as m}from"@privy-io/js-sdk-core";import{C as p}from"./CopyToClipboard-DSTf_eKU.mjs";import{a as d}from"./Layouts-BlFm53ED.mjs";import{M as u,D as g}from"./JsonTree-aPaJmPx7.mjs";import{P as h,z as y}from"./wallet-connect-58EobR5U.mjs";import{W as f,r as x}from"./context-BKnOUECq.mjs";import{u as C}from"./internal-context-dfitw7Ot.mjs";import{u as j}from"./modal-context-DBwfUxD-.mjs";import{u as v}from"./privy-context-Bi6vqCPc.mjs";import{S as b}from"./ScreenLayout-Caq5mGD8.mjs";import"./errors-Dd6zfYtp.mjs";import"ofetch";import"./getPublicClient-D4yNgeGy.mjs";import"viem/chains";import"eventemitter3";import"tinycolor2";import"@privy-io/are-addresses-equal";import"./ModalHeader-DffkxvO4.mjs";import"./useActiveWallet-BEfvREjE.mjs";import"viem/utils";import"./events-context-BJ75xIIf.mjs";import"./index-BtwxknTg.mjs";import"zustand";import"react-device-detect";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.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"./Screen-D8KNyGVj.mjs";import"./index-Dq_xe9dz.mjs";const w=s.img`
  && {
    height: ${e=>"sm"===e.size?"65px":"140px"};
    width: ${e=>"sm"===e.size?"65px":"140px"};
    border-radius: 16px;
    margin-bottom: 12px;
  }
`;let T=e=>{if(!l(e))return e;try{let t=c(e);return t.includes("�")?e:t}catch{return e}},S=e=>{try{let t=r.decode(e),o=(new TextDecoder).decode(t);return o.includes("�")?e:o}catch{return e}},E=r=>{let{types:i,primaryType:n,...a}=r.typedData;/*#__PURE__*/return t(o,{children:[/*#__PURE__*/e(A,{data:a}),/*#__PURE__*/e(p,{text:(s=r.typedData,JSON.stringify(s,null,2)),itemName:"full payload to clipboard"})," "]});var s};const R=({method:o,messageData:r,copy:n,iconUrl:a,isLoading:s,success:l,walletProxyIsLoading:c,errorMessage:m,isCancellable:p,onSign:u,onCancel:g,onClose:h})=>/*#__PURE__*/e(b,{title:n.title,subtitle:n.description,showClose:!0,onClose:h,icon:i,iconVariant:"subtle",helpText:m?/*#__PURE__*/e(L,{children:m}):void 0,primaryCta:{label:n.buttonText,onClick:u,disabled:s||l||c,loading:s},secondaryCta:p?{label:"Not now",onClick:g,disabled:s||l||c}:void 0,watermark:!0,children:/*#__PURE__*/t(d,{children:[a?/*#__PURE__*/e(w,{style:{alignSelf:"center"},size:"sm",src:a,alt:"app image"}):null,/*#__PURE__*/t(D,{children:["personal_sign"===o&&/*#__PURE__*/e(U,{children:T(r)}),"eth_signTypedData_v4"===o&&/*#__PURE__*/e(E,{typedData:r}),"solana_signMessage"===o&&/*#__PURE__*/e(U,{children:S(r)})]})]})}),_={component:()=>{let{authenticated:t}=v(),{initializeWalletProxy:o,closePrivyModal:r}=C(),{navigate:i,data:s,onUserCloseViaDialogOrKeybindRef:l}=j(),[c,p]=n(!0),[d,u]=n(""),[g,b]=n(),[w,T]=n(null),[S,E]=n(!1);a((()=>{t||i("LandingScreen")}),[t]),a((()=>{o(f).then((e=>{p(!1),e||(u("An error has occurred, please try again."),b(new h(new y(d,m.E32603_DEFAULT_INTERNAL_ERROR.eipCode))))}))}),[]);let{method:_,data:D,confirmAndSign:L,onSuccess:A,onFailure:U,uiOptions:M}=s.signMessage,I={title:M?.title||"Sign message",description:M?.description||"Signing this message will not cost you any fees.",buttonText:M?.buttonText||"Sign and continue"},k=e=>{e?A(e):U(g||new h(new y("The user rejected the request.",m.E4001_USER_REJECTED_REQUEST.eipCode))),r({shouldCallAuthOnSuccess:!1}),setTimeout((()=>{T(null),u(""),b(void 0)}),200)};l.current=()=>{k(w)};/*#__PURE__*/return e(R,{method:_,messageData:D,copy:I,iconUrl:M?.iconUrl&&"string"==typeof M.iconUrl?M.iconUrl:void 0,isLoading:S,success:null!==w,walletProxyIsLoading:c,errorMessage:d,isCancellable:M?.isCancellable,onSign:async()=>{E(!0),u("");try{let e=await L();T(e),E(!1),setTimeout((()=>{k(e)}),x)}catch(e){console.error(e),u("An error has occurred, please try again."),b(new h(new y(d,m.E32603_DEFAULT_INTERNAL_ERROR.eipCode))),E(!1)}},onCancel:()=>k(null),onClose:()=>k(w)})}};let D=s.div`
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
`,L=s.p`
  && {
    margin: 0;
    width: 100%;
    text-align: center;
    color: var(--privy-color-error-dark);
    font-size: 14px;
    line-height: 22px;
  }
`,A=s(g)`
  margin-top: 0;
`,U=s(u)`
  margin-top: 0;
`;export{_ as SignRequestScreen,R as SignRequestView,_ as default};
//# sourceMappingURL=SignRequestScreen-B3YXUxte.mjs.map
