import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{useState as o,useRef as s,useCallback as i}from"react";import{poll as a}from"@privy-io/js-sdk-core";import{trigger as n}from"@privy-io/popup";import{u as c}from"./modal-context-DBwfUxD-.mjs";import{u as l}from"./privy-context-Bi6vqCPc.mjs";import{isMobile as u}from"react-device-detect";import{styled as m}from"styled-components";import{a as d}from"./CopyableText-ChtfBWx4.mjs";import{D as p}from"./index-C5jxD-zy.mjs";import{S as f}from"./ScreenLayout-Caq5mGD8.mjs";import{XCircle as y,Hourglass as h,UserCheck as g,Check as v}from"lucide-react";import{I as C}from"./InfoBanner-DkQEPd77.mjs";import{A as w,C as b,S as k}from"./SelectSourceAsset-BFTx8rzA.mjs";import"./context-BKnOUECq.mjs";import"tinycolor2";import"./internal-context-dfitw7Ot.mjs";import"@privy-io/are-addresses-equal";import"./toViemAccount-4iGGrW4w.mjs";import"jose";import"eventemitter3";import"./index-BtwxknTg.mjs";import"zustand";import"viem";import"viem/utils";import"./errors-Dd6zfYtp.mjs";import"ofetch";import"./wallet-connect-58EobR5U.mjs";import"./getPublicClient-D4yNgeGy.mjs";import"viem/chains";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"./pkce-BinverJO.mjs";import"./paths-BH8W4zMc.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"js-cookie";import"@privy-io/ethereum";import"viem/accounts";import"mipd";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";import"./events-context-BJ75xIIf.mjs";import"./useActiveWallet-BEfvREjE.mjs";import"@headlessui/react";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import"./frame-DtizlaLu.mjs";import"@privy-io/routes";import"./use-deposit-address-BwThybOQ.mjs";import"x402/client";import"@privy-io/api-base";import"./use-sign-with-user-signer-CQI6hUH7.mjs";import"./ModalHeader-DffkxvO4.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";import"@heroicons/react/24/outline/InformationCircleIcon";const j=e=>{try{return e.location.origin}catch{return}},x=({data:r,onClose:o})=>/*#__PURE__*/e(f,{showClose:!0,onClose:o,title:"Initiate bank transfer",subtitle:"Use the details below to complete a bank transfer from your bank.",primaryCta:{label:"Done",onClick:o},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(A,{children:(p[r.deposit_instructions.asset]||[]).map((([o,s],i)=>{let a=r.deposit_instructions[o];if(!a||Array.isArray(a))return null;let n="asset"===o?a.toUpperCase():a,c=n.length>100?`${n.slice(0,9)}...${n.slice(-9)}`:n;/*#__PURE__*/return t(S,{children:[/*#__PURE__*/e(E,{children:s}),/*#__PURE__*/e(d,{value:n,includeChildren:u,children:/*#__PURE__*/e(T,{children:c})})]},i)}))})});let A=m.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;
  }
`,S=m.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%;
    }
  }
`,E=m.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;
`,T=m.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 U=({onClose:t})=>/*#__PURE__*/e(f,{showClose:!0,onClose:t,icon:y,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}),I=({onClose:t,reason:r})=>{let o=r?r.charAt(0).toLowerCase()+r.slice(1):void 0;/*#__PURE__*/return e(f,{showClose:!0,onClose:t,icon:y,iconVariant:"error",title:"Identity verification failed",subtitle:o?`We can't complete identity verification because ${o}. 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})},_=({onClose:r,email:o})=>/*#__PURE__*/e(f,{showClose:!0,onClose:r,icon:h,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:r},watermark:!0,children:/*#__PURE__*/t(C,{theme:"light",children:["You'll receive an email at ",o," once approved with instructions for completing your deposit."]})}),L=({onClose:o,onAcceptTerms:s,isLoading:i})=>/*#__PURE__*/e(f,{showClose:!0,onClose:o,icon:g,title:"Verify your identity to continue",subtitle:"Finish verification with Persona — it takes just a few minutes and requires a government ID.",helpText:/*#__PURE__*/t(r,{children:['This app uses Bridge to securely connect accounts and move funds. By clicking "Accept," you agree to Bridge\'s'," ",/*#__PURE__*/e("a",{href:"https://www.bridge.xyz/legal",target:"_blank",rel:"noopener noreferrer",children:"Terms of Service"})," ","and"," ",/*#__PURE__*/e("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:s,loading:i},watermark:!0}),P=({onClose:t})=>/*#__PURE__*/e(f,{showClose:!0,onClose:t,icon:v,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:r,onClose:o,onEditSourceAsset:s,onSelectAmount:i,isLoading:a})=>/*#__PURE__*/t(f,{showClose:!0,onClose:o,headerTitle:`Buy ${r.destination.asset.toLocaleUpperCase()}`,primaryCta:{label:"Continue",onClick:i,loading:a},watermark:!0,children:[/*#__PURE__*/e(w,{currency:r.source.selectedAsset,inputMode:"decimal",autoFocus:!0}),/*#__PURE__*/e(b,{selectedAsset:r.source.selectedAsset,onEditSourceAsset:s})]}),B=({onClose:t,onAcceptTerms:r,onSelectAmount:o,onSelectSource:s,onEditSourceAsset:i,opts:a,state:n,email:c,isLoading:l})=>"select-amount"===n.status?/*#__PURE__*/e(W,{onClose:t,onSelectAmount:o,onEditSourceAsset:i,opts:a,isLoading:l}):"select-source-asset"===n.status?/*#__PURE__*/e(k,{onSelectSource:s,opts:a,isLoading:l}):"kyc-prompt"===n.status?/*#__PURE__*/e(L,{onClose:t,onAcceptTerms:r,opts:a,isLoading:l}):"kyc-incomplete"===n.status?/*#__PURE__*/e(_,{onClose:t,email:c}):"kyc-success"===n.status?/*#__PURE__*/e(P,{onClose:t}):"kyc-error"===n.status?/*#__PURE__*/e(I,{onClose:t,reason:n.reason}):"account-details"===n.status?/*#__PURE__*/e(x,{onClose:t,data:n.data}):"create-customer-error"===n.status||"get-customer-error"===n.status?/*#__PURE__*/e(U,{onClose:t}):null,D={component:()=>{let{user:t}=l(),r=c().data;if(!r?.FundWithBankDepositScreen)throw Error("Missing data");let{onSuccess:u,onFailure:m,opts:d,createOrUpdateCustomer:p,getCustomer:f,getOrCreateVirtualAccount:y}=r.FundWithBankDepositScreen,[h,g]=o(d),[v,C]=o({status:"select-amount"}),[w,b]=o(null),[k,x]=o(!1),A=s(null),S=i((async()=>{let e;x(!0),b(null);try{e=await f({kycRedirectUrl:window.location.origin})}catch(e){if(!e||"object"!=typeof e||!("status"in e)||404!==e.status)return C({status:"get-customer-error"}),b(e),void x(!1)}if(!e)try{e=await p({hasAcceptedTerms:!1,kycRedirectUrl:window.location.origin})}catch(e){return C({status:"create-customer-error"}),b(e),void x(!1)}if(!e)return C({status:"create-customer-error"}),b(Error("Unable to create customer")),void x(!1);if("not_started"===e.status&&e.kyc_url)return C({status:"kyc-prompt",kycUrl:e.kyc_url}),void x(!1);if("not_started"===e.status)return C({status:"get-customer-error"}),b(Error("Unexpected user state")),void x(!1);if("rejected"===e.status)return C({status:"kyc-error",reason:e.rejection_reasons?.[0]?.reason}),b(Error("User KYC rejected.")),void x(!1);if("incomplete"===e.status)return C({status:"kyc-incomplete"}),void x(!1);if("active"!==e.status)return C({status:"get-customer-error"}),b(Error("Unexpected user state")),void x(!1);e.status;try{let e=await y({destination:h.destination,provider:h.provider,source:{asset:h.source.selectedAsset}});C({status:"account-details",data:e})}catch(e){return C({status:"create-customer-error"}),b(e),void x(!1)}}),[h]),E=i((async()=>{if(b(null),x(!0),"kyc-prompt"!==v.status)return b(Error("Unexpected state")),void x(!1);let e=n({location:v.kycUrl});if(await p({hasAcceptedTerms:!0}),!e)return b(Error("Unable to begin kyc flow.")),x(!1),void C({status:"create-customer-error"});A.current=new AbortController;let t=await(async(e,t)=>{let r=await a({operation:async()=>({done:j(e)===window.location.origin,closed:e.closed}),until:({done:e,closed:t})=>e||t,delay:0,interval:500,attempts:360,signal:t});return"aborted"===r.status?(e.close(),{status:"aborted"}):"max_attempts"===r.status?{status:"timeout"}:r.result.done?(e.close(),{status:"redirected"}):{status:"closed"}})(e,A.current.signal);if("aborted"===t.status)return;if("closed"===t.status)return void x(!1);t.status;let r=await a({operation:()=>f({}),until:e=>"active"===e.status||"rejected"===e.status,delay:0,interval:2e3,attempts:60,signal:A.current.signal});if("aborted"!==r.status){if("max_attempts"===r.status)return C({status:"kyc-incomplete"}),void x(!1);if(r.status,"rejected"===r.result.status)return C({status:"kyc-error",reason:r.result.rejection_reasons?.[0]?.reason}),b(Error("User KYC rejected.")),void x(!1);if("active"!==r.result.status)return C({status:"kyc-incomplete"}),void x(!1);e.closed||e.close(),r.result.status;try{C({status:"kyc-success"});let e=await y({destination:h.destination,provider:h.provider,source:{asset:h.source.selectedAsset}});C({status:"account-details",data:e})}catch(e){C({status:"create-customer-error"}),b(e)}finally{x(!1)}}}),[C,b,x,p,y,v,h,A]),T=i((e=>{C({status:"select-amount"}),g({...h,source:{...h.source,selectedAsset:e}})}),[C,g]),U=i((()=>{C({status:"select-source-asset"})}),[C]);/*#__PURE__*/return e(B,{onClose:i((async()=>{A.current?.abort(),w?m(w):await u()}),[w,A]),opts:h,state:v,isLoading:k,email:t.email.address,onAcceptTerms:E,onSelectAmount:S,onSelectSource:T,onEditSourceAsset:U})}};export{D as FundWithBankDepositScreen,D as default};
//# sourceMappingURL=FundWithBankDepositScreen-s-Y_8aQs.mjs.map
