"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("@privy-io/js-sdk-core"),s=require("@privy-io/popup"),o=require("./modal-context-BgeioxwT.js"),i=require("./privy-context-UTJouJ1x.js"),a=require("react-device-detect"),n=require("styled-components"),u=require("./CopyableText-SJxK10XO.js"),c=require("./index-BoiKFBqR.js"),l=require("./ScreenLayout-DaFW0I3a.js"),d=require("lucide-react"),p=require("./InfoBanner-D5_XYHKY.js"),y=require("./SelectSourceAsset-D8gSMS4p.js");require("./context-rs-ygOK2.js"),require("tinycolor2"),require("./internal-context-CdsQ3LEl.js"),require("@privy-io/are-addresses-equal"),require("./toViemAccount-CopJpCYv.js"),require("jose"),require("eventemitter3"),require("./index-Ub4KpwSY.js"),require("zustand"),require("viem"),require("viem/utils"),require("./errors-CBapWvRs.js"),require("ofetch"),require("./wallet-connect-BuohfvHK.js"),require("./getPublicClient-CFd_sHBk.js"),require("viem/chains"),require("@coinbase/wallet-sdk"),require("@walletconnect/ethereum-provider"),require("./pkce-CmuJlEgn.js"),require("./paths-DizMb-lU.js"),require("./PrivyPluginContext-DsLtVhZA.js"),require("js-cookie"),require("@privy-io/ethereum"),require("viem/accounts"),require("mipd"),require("@scure/base"),require("./usePrivy-Dt4_yE6Q.js"),require("./use-unlink-wallet-DAxmY7kq.js"),require("./get-entropy-details-for-user-D63rM5_a.js"),require("./user-D2oPA-vS.js"),require("./events-context-Di6--rDg.js"),require("./useActiveWallet-dTc6deka.js"),require("@headlessui/react"),require("@privy-io/urls"),require("./getEmbeddedConnectedWallet-D6YL2FS9.js"),require("./frame-BHa-PKpX.js"),require("@privy-io/routes"),require("./use-deposit-address-CVyd0fqP.js"),require("x402/client"),require("@privy-io/api-base"),require("./use-sign-with-user-signer-BhoaqeNG.js"),require("./ModalHeader-Cpls13mi.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"),require("@heroicons/react/24/outline/InformationCircleIcon");const m=e=>{try{return e.location.origin}catch{return}},f=({data:t,onClose:r})=>/*#__PURE__*/e.jsx(l.ScreenLayout,{showClose:!0,onClose:r,title:"Initiate bank transfer",subtitle:"Use the details below to complete a bank transfer from your bank.",primaryCta:{label:"Done",onClick:r},watermark:!1,footerText:"Exchange rates and fees are set when you authorize and determine the amount you receive. You'll see the applicable rates and fees for your transaction separately",children:/*#__PURE__*/e.jsx(h,{children:(c.DEPOSIT_INSTRUCTIONS_MAP[t.deposit_instructions.asset]||[]).map((([r,s],o)=>{let i=t.deposit_instructions[r];if(!i||Array.isArray(i))return null;let n="asset"===r?i.toUpperCase():i,c=n.length>100?`${n.slice(0,9)}...${n.slice(-9)}`:n;/*#__PURE__*/return e.jsxs(g,{children:[/*#__PURE__*/e.jsx(v,{children:s}),/*#__PURE__*/e.jsx(u.CopyButton,{value:n,includeChildren:a.isMobile,children:/*#__PURE__*/e.jsx(C,{children:c})})]},o)}))})});let h=n.styled.ol`
  border-color: var(--privy-color-border-default);
  border-width: 1px;
  border-radius: var(--privy-border-radius-mdlg);
  border-style: solid;
  display: flex;
  flex-direction: column;

  && {
    padding: 0 1rem;
  }
`,g=n.styled.li`
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;

  &:not(:first-of-type) {
    border-top: 1px solid var(--privy-color-border-default);
  }

  & > {
    :nth-child(1) {
      flex-basis: 30%;
    }

    :nth-child(2) {
      flex-basis: 60%;
    }
  }
`,v=n.styled.span`
  color: var(--privy-color-foreground);
  font-kerning: none;
  font-variant-numeric: lining-nums proportional-nums;
  font-feature-settings: 'calt' off;

  /* text-xs/font-regular */
  font-size: 0.75rem;
  font-style: normal;
  font-weight: 400;
  line-height: 1.125rem; /* 150% */

  text-align: left;
  flex-shrink: 0;
`,C=n.styled.span`
  color: var(--privy-color-foreground);
  font-kerning: none;
  font-feature-settings: 'calt' off;

  /* text-sm/font-medium */
  font-size: 0.875rem;
  font-style: normal;
  font-weight: 500;
  line-height: 1.375rem; /* 157.143% */

  text-align: right;
  word-break: break-all;
`;const j=({onClose:t})=>/*#__PURE__*/e.jsx(l.ScreenLayout,{showClose:!0,onClose:t,icon:d.XCircle,iconVariant:"error",title:"Something went wrong",subtitle:"We couldn't complete account setup. This isn't caused by anything you did.",primaryCta:{label:"Close",onClick:t},watermark:!0}),k=({onClose:t,reason:r})=>{let s=r?r.charAt(0).toLowerCase()+r.slice(1):void 0;/*#__PURE__*/return e.jsx(l.ScreenLayout,{showClose:!0,onClose:t,icon:d.XCircle,iconVariant:"error",title:"Identity verification failed",subtitle:s?`We can't complete identity verification because ${s}. Please try again or contact support for assistance.`:"We couldn't verify your identity. Please try again or contact support for assistance.",primaryCta:{label:"Close",onClick:t},watermark:!0})},q=({onClose:t,email:r})=>/*#__PURE__*/e.jsx(l.ScreenLayout,{showClose:!0,onClose:t,icon:d.Hourglass,title:"Identity verification in progress",subtitle:"We're waiting for Persona to approve your identity verification. This usually takes a few minutes, but may take up to 24 hours.",primaryCta:{label:"Done",onClick:t},watermark:!0,children:/*#__PURE__*/e.jsxs(p.InfoBanner,{theme:"light",children:["You'll receive an email at ",r," once approved with instructions for completing your deposit."]})}),b=({onClose:t,onAcceptTerms:r,isLoading:s})=>/*#__PURE__*/e.jsx(l.ScreenLayout,{showClose:!0,onClose:t,icon:d.UserCheck,title:"Verify your identity to continue",subtitle:"Finish verification with Persona — it takes just a few minutes and requires a government ID.",helpText:/*#__PURE__*/e.jsxs(e.Fragment,{children:['This app uses Bridge to securely connect accounts and move funds. By clicking "Accept," you agree to Bridge\'s'," ",/*#__PURE__*/e.jsx("a",{href:"https://www.bridge.xyz/legal",target:"_blank",rel:"noopener noreferrer",children:"Terms of Service"})," ","and"," ",/*#__PURE__*/e.jsx("a",{href:"https://www.bridge.xyz/legal/row-privacy-policy/bridge-building-limited",target:"_blank",rel:"noopener noreferrer",children:"Privacy Policy"}),"."]}),primaryCta:{label:"Accept and continue",onClick:r,loading:s},watermark:!0}),x=({onClose:t})=>/*#__PURE__*/e.jsx(l.ScreenLayout,{showClose:!0,onClose:t,icon:d.Check,iconVariant:"success",title:"Identity verified successfully",subtitle:"We've successfully verified your identity. Now initiate a bank transfer to view instructions.",primaryCta:{label:"Initiate bank transfer",onClick:()=>{},loading:!0},watermark:!0}),w=({opts:t,onClose:r,onEditSourceAsset:s,onSelectAmount:o,isLoading:i})=>/*#__PURE__*/e.jsxs(l.ScreenLayout,{showClose:!0,onClose:r,headerTitle:`Buy ${t.destination.asset.toLocaleUpperCase()}`,primaryCta:{label:"Continue",onClick:o,loading:i},watermark:!0,children:[/*#__PURE__*/e.jsx(y.AmountInput,{currency:t.source.selectedAsset,inputMode:"decimal",autoFocus:!0}),/*#__PURE__*/e.jsx(y.CurrencySelector,{selectedAsset:t.source.selectedAsset,onEditSourceAsset:s})]}),S=({onClose:t,onAcceptTerms:r,onSelectAmount:s,onSelectSource:o,onEditSourceAsset:i,opts:a,state:n,email:u,isLoading:c})=>"select-amount"===n.status?/*#__PURE__*/e.jsx(w,{onClose:t,onSelectAmount:s,onEditSourceAsset:i,opts:a,isLoading:c}):"select-source-asset"===n.status?/*#__PURE__*/e.jsx(y.SelectSourceAsset,{onSelectSource:o,opts:a,isLoading:c}):"kyc-prompt"===n.status?/*#__PURE__*/e.jsx(b,{onClose:t,onAcceptTerms:r,opts:a,isLoading:c}):"kyc-incomplete"===n.status?/*#__PURE__*/e.jsx(q,{onClose:t,email:u}):"kyc-success"===n.status?/*#__PURE__*/e.jsx(x,{onClose:t}):"kyc-error"===n.status?/*#__PURE__*/e.jsx(k,{onClose:t,reason:n.reason}):"account-details"===n.status?/*#__PURE__*/e.jsx(f,{onClose:t,data:n.data}):"create-customer-error"===n.status||"get-customer-error"===n.status?/*#__PURE__*/e.jsx(j,{onClose:t}):null,A={component:()=>{let{user:a}=i.usePrivyContext(),n=o.usePrivyModal().data;if(!n?.FundWithBankDepositScreen)throw Error("Missing data");let{onSuccess:u,onFailure:c,opts:l,createOrUpdateCustomer:d,getCustomer:p,getOrCreateVirtualAccount:y}=n.FundWithBankDepositScreen,[f,h]=t.useState(l),[g,v]=t.useState({status:"select-amount"}),[C,j]=t.useState(null),[k,q]=t.useState(!1),b=t.useRef(null),x=t.useCallback((async()=>{let e;q(!0),j(null);try{e=await p({kycRedirectUrl:window.location.origin})}catch(e){if(!e||"object"!=typeof e||!("status"in e)||404!==e.status)return v({status:"get-customer-error"}),j(e),void q(!1)}if(!e)try{e=await d({hasAcceptedTerms:!1,kycRedirectUrl:window.location.origin})}catch(e){return v({status:"create-customer-error"}),j(e),void q(!1)}if(!e)return v({status:"create-customer-error"}),j(Error("Unable to create customer")),void q(!1);if("not_started"===e.status&&e.kyc_url)return v({status:"kyc-prompt",kycUrl:e.kyc_url}),void q(!1);if("not_started"===e.status)return v({status:"get-customer-error"}),j(Error("Unexpected user state")),void q(!1);if("rejected"===e.status)return v({status:"kyc-error",reason:e.rejection_reasons?.[0]?.reason}),j(Error("User KYC rejected.")),void q(!1);if("incomplete"===e.status)return v({status:"kyc-incomplete"}),void q(!1);if("active"!==e.status)return v({status:"get-customer-error"}),j(Error("Unexpected user state")),void q(!1);e.status;try{let e=await y({destination:f.destination,provider:f.provider,source:{asset:f.source.selectedAsset}});v({status:"account-details",data:e})}catch(e){return v({status:"create-customer-error"}),j(e),void q(!1)}}),[f]),w=t.useCallback((async()=>{if(j(null),q(!0),"kyc-prompt"!==g.status)return j(Error("Unexpected state")),void q(!1);let e=s.trigger({location:g.kycUrl});if(await d({hasAcceptedTerms:!0}),!e)return j(Error("Unable to begin kyc flow.")),q(!1),void v({status:"create-customer-error"});b.current=new AbortController;let t=await(async(e,t)=>{let s=await r.poll({operation:async()=>({done:m(e)===window.location.origin,closed:e.closed}),until:({done:e,closed:t})=>e||t,delay:0,interval:500,attempts:360,signal:t});return"aborted"===s.status?(e.close(),{status:"aborted"}):"max_attempts"===s.status?{status:"timeout"}:s.result.done?(e.close(),{status:"redirected"}):{status:"closed"}})(e,b.current.signal);if("aborted"===t.status)return;if("closed"===t.status)return void q(!1);t.status;let o=await r.poll({operation:()=>p({}),until:e=>"active"===e.status||"rejected"===e.status,delay:0,interval:2e3,attempts:60,signal:b.current.signal});if("aborted"!==o.status){if("max_attempts"===o.status)return v({status:"kyc-incomplete"}),void q(!1);if(o.status,"rejected"===o.result.status)return v({status:"kyc-error",reason:o.result.rejection_reasons?.[0]?.reason}),j(Error("User KYC rejected.")),void q(!1);if("active"!==o.result.status)return v({status:"kyc-incomplete"}),void q(!1);e.closed||e.close(),o.result.status;try{v({status:"kyc-success"});let e=await y({destination:f.destination,provider:f.provider,source:{asset:f.source.selectedAsset}});v({status:"account-details",data:e})}catch(e){v({status:"create-customer-error"}),j(e)}finally{q(!1)}}}),[v,j,q,d,y,g,f,b]),A=t.useCallback((e=>{v({status:"select-amount"}),h({...f,source:{...f.source,selectedAsset:e}})}),[v,h]),I=t.useCallback((()=>{v({status:"select-source-asset"})}),[v]);/*#__PURE__*/return e.jsx(S,{onClose:t.useCallback((async()=>{b.current?.abort(),C?c(C):await u()}),[C,b]),opts:f,state:g,isLoading:k,email:a.email.address,onAcceptTerms:w,onSelectAmount:x,onSelectSource:A,onEditSourceAsset:I})}};exports.FundWithBankDepositScreen=A,exports.default=A;
//# sourceMappingURL=FundWithBankDepositScreen-D-Hso006.js.map
