@unifold/connect-react-native 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +456 -0
- package/dist/index.d.ts +456 -0
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/stripe.d.mts +230 -0
- package/dist/stripe.d.ts +230 -0
- package/dist/stripe.js +3 -0
- package/dist/stripe.mjs +3 -0
- package/package.json +15 -4
package/dist/stripe.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import {useState,useRef,useEffect,useCallback,useMemo}from'react';import {StyleSheet,Platform,View,TouchableOpacity,Text,KeyboardAvoidingView,ScrollView,TextInput,ActivityIndicator,Keyboard,Clipboard}from'react-native';import {Onramp,useOnramp,isPlatformPaySupported,PlatformPay,initStripe}from'@stripe/stripe-react-native';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import gn,{G,Path,Defs,ClipPath,Rect,LinearGradient,Stop,Circle}from'react-native-svg';var Qr="__unifold_stripe_onramp__";function or(e){globalThis[Qr]=e;}var Xr="#00D924",en="#000000",tn="#1C1C1E",Bt="#FFFFFF",Vt="#8E8E93",ir="#636366",rn=[["1","2","3"],["4","5","6"],["7","8","9"],["\u232B","0","."]];function ht({initialAmount:e="",currency:a="USD",onConfirm:o,onCancel:l}){let[c,x]=useState(e),B=T=>{if(T==="\u232B"){x(S=>S.slice(0,-1));return}if(T==="."){if(c.includes("."))return;x(S=>S===""?"0.":S+".");return}x(S=>{let k=S.indexOf(".");return k!==-1&&S.length-k>2?S:S==="0"&&T!=="."?T:S+T});},L=c===""?"0":c,D=parseFloat(c),W=c!==""&&!isNaN(D)&&D>0;return jsxs(View,{style:I.screen,children:[jsxs(View,{style:I.header,children:[jsx(TouchableOpacity,{style:I.cancelBtn,onPress:l,children:jsx(Text,{style:I.cancelText,children:"Cancel"})}),jsx(Text,{style:I.headerTitle,children:"Enter amount"}),jsx(View,{style:{width:64}})]}),jsxs(View,{style:I.amountContainer,children:[jsxs(Text,{style:[I.amountText,L==="0"&&I.amountPlaceholder],adjustsFontSizeToFit:true,numberOfLines:1,children:["$",L]}),jsx(Text,{style:I.currencyLabel,children:a.toUpperCase()})]}),jsx(View,{style:I.numpad,children:rn.map((T,S)=>jsx(View,{style:I.numpadRow,children:T.map(k=>jsx(TouchableOpacity,{style:I.numpadKey,onPress:()=>B(k),activeOpacity:.6,children:jsx(Text,{style:k==="\u232B"?I.backspaceText:I.numpadKeyText,children:k})},k))},S))}),jsx(TouchableOpacity,{style:[I.confirmBtn,!W&&I.confirmBtnDisabled],onPress:()=>W&&o(c),disabled:!W,children:jsx(Text,{style:[I.confirmBtnText,!W&&I.confirmBtnTextDisabled],children:"Continue"})})]})}var I=StyleSheet.create({screen:{flex:1,backgroundColor:en,paddingHorizontal:24,paddingBottom:48},header:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",paddingTop:60,paddingBottom:8},cancelBtn:{width:64},cancelText:{color:Vt,fontSize:16,fontWeight:"500"},headerTitle:{color:Bt,fontSize:17,fontWeight:"700"},amountContainer:{flex:1,alignItems:"center",justifyContent:"center",gap:8},amountText:{fontSize:64,fontWeight:"300",color:Bt,letterSpacing:-2,minWidth:80,textAlign:"center"},amountPlaceholder:{color:ir},currencyLabel:{fontSize:15,color:Vt,letterSpacing:1,fontWeight:"500"},numpad:{gap:4,marginBottom:24},numpadRow:{flexDirection:"row",justifyContent:"space-between"},numpadKey:{flex:1,height:68,alignItems:"center",justifyContent:"center",borderRadius:16,marginHorizontal:4},numpadKeyText:{fontSize:28,fontWeight:"400",color:Bt},backspaceText:{fontSize:22,color:Vt},confirmBtn:{backgroundColor:Xr,borderRadius:24,paddingVertical:18,alignItems:"center"},confirmBtnDisabled:{backgroundColor:tn},confirmBtnText:{color:"#000000",fontSize:17,fontWeight:"700"},confirmBtnTextDisabled:{color:ir}});var Nt="#00D924",ln="#000000",_t="#1C1C1E",sr="#38383A",Ft="#FFFFFF",ct="#8E8E93",j="#636366",lt=4;function bt({initialData:e={},loading:a=false,onComplete:o,onCancel:l}){let[c,x]=useState(1),[B,L]=useState(e.firstName??""),[D,W]=useState(e.lastName??""),[T,S]=useState(e.dobMonth??""),[k,O]=useState(e.dobDay??""),[y,N]=useState(e.dobYear??""),[b,Ve]=useState(e.addressLine1??""),[m,ge]=useState(e.addressLine2??""),[te,C]=useState(e.city??""),[se,M]=useState(e.state??""),[ve,Le]=useState(e.postalCode??""),[Ae,Re]=useState(e.country??"US"),[Ee,Ne]=useState(e.idNumber??""),Fe=useRef(null),K=useRef(null),ze=useRef(null),he=useRef(null),_e=useRef(null),Ye=useRef(null),be=useRef(null),De=useRef(null),ae=()=>{switch(c){case 1:return B.trim().length>0&&D.trim().length>0;case 2:return T.length===2&&k.length===2&&y.length===4;case 3:return b.trim().length>0&&te.trim().length>0&&se.trim().length>0&&ve.trim().length>0;case 4:return Ee.trim().length>0;default:return false}},re=()=>{ae()&&(c<lt?x(w=>w+1):o({firstName:B,lastName:D,idNumber:Ee,dobMonth:T,dobDay:k,dobYear:y,addressLine1:b,addressLine2:m,city:te,state:se,postalCode:ve,country:Ae}));},F=()=>{c>1?x(w=>w-1):l();},h=["Enter your name","Enter your date of birth","Enter your address","Enter your SSN"],U=["Use your full legal name as it appears on your ID.","We use this to verify your identity.","Enter the address associated with your ID.","Your SSN is encrypted and used only for identity verification."];return jsx(KeyboardAvoidingView,{style:p.flex,behavior:Platform.OS==="ios"?"padding":void 0,children:jsxs(View,{style:p.screen,children:[jsxs(View,{style:p.header,children:[jsx(TouchableOpacity,{style:p.backBtn,onPress:F,children:jsx(Text,{style:p.backBtnText,children:"\u2039"})}),jsxs(Text,{style:p.stepCounter,children:[c," of ",lt]}),jsx(TouchableOpacity,{style:p.closeBtn,onPress:l,children:jsx(Text,{style:p.closeText,children:"\u2715"})})]}),jsx(View,{style:p.progressTrack,children:Array.from({length:lt}).map((w,V)=>jsx(View,{style:[p.progressSegment,V<c&&p.progressSegmentDone,V+1===c&&p.progressSegmentActive]},V))}),jsxs(ScrollView,{style:p.flex,contentContainerStyle:p.content,keyboardShouldPersistTaps:"handled",children:[jsx(Text,{style:p.title,children:h[c-1]}),jsx(Text,{style:p.subtitle,children:U[c-1]}),c===1&&jsxs(Fragment,{children:[jsx(Te,{label:"First name",children:jsx(TextInput,{style:p.input,placeholder:"Jane",placeholderTextColor:j,value:B,onChangeText:L,autoCapitalize:"words",returnKeyType:"next",onSubmitEditing:()=>Fe.current?.focus()})}),jsx(Te,{label:"Last name",children:jsx(TextInput,{ref:Fe,style:p.input,placeholder:"Doe",placeholderTextColor:j,value:D,onChangeText:W,autoCapitalize:"words",returnKeyType:"done",onSubmitEditing:re})})]}),c===2&&jsxs(View,{style:p.dobRow,children:[jsxs(View,{style:p.dobCol,children:[jsx(Text,{style:p.dobLabel,children:"Month"}),jsx(TextInput,{style:[p.input,p.dobInput],placeholder:"MM",placeholderTextColor:j,value:T,onChangeText:w=>{let V=w.replace(/\D/g,"").slice(0,2);S(V),V.length===2&&K.current?.focus();},keyboardType:"number-pad",maxLength:2})]}),jsxs(View,{style:p.dobCol,children:[jsx(Text,{style:p.dobLabel,children:"Day"}),jsx(TextInput,{ref:K,style:[p.input,p.dobInput],placeholder:"DD",placeholderTextColor:j,value:k,onChangeText:w=>{let V=w.replace(/\D/g,"").slice(0,2);O(V),V.length===2&&ze.current?.focus();},keyboardType:"number-pad",maxLength:2})]}),jsxs(View,{style:p.dobColWide,children:[jsx(Text,{style:p.dobLabel,children:"Year"}),jsx(TextInput,{ref:ze,style:[p.input,p.dobInput],placeholder:"YYYY",placeholderTextColor:j,value:y,onChangeText:w=>{let V=w.replace(/\D/g,"").slice(0,4);N(V);},keyboardType:"number-pad",maxLength:4,returnKeyType:"done",onSubmitEditing:re})]})]}),c===3&&jsxs(Fragment,{children:[jsx(Te,{label:"Street address",children:jsx(TextInput,{style:p.input,placeholder:"123 Main St",placeholderTextColor:j,value:b,onChangeText:Ve,returnKeyType:"next",onSubmitEditing:()=>he.current?.focus()})}),jsx(Te,{label:"Apt, suite, etc. (optional)",children:jsx(TextInput,{ref:he,style:p.input,placeholder:"Apt 2",placeholderTextColor:j,value:m,onChangeText:ge,returnKeyType:"next",onSubmitEditing:()=>_e.current?.focus()})}),jsx(Te,{label:"City",children:jsx(TextInput,{ref:_e,style:p.input,placeholder:"San Francisco",placeholderTextColor:j,value:te,onChangeText:C,autoCapitalize:"words",returnKeyType:"next",onSubmitEditing:()=>Ye.current?.focus()})}),jsxs(View,{style:p.row,children:[jsx(View,{style:[p.flex,{marginRight:8}],children:jsx(Te,{label:"State",children:jsx(TextInput,{ref:Ye,style:p.input,placeholder:"NY",placeholderTextColor:j,value:se,onChangeText:w=>M(w.toUpperCase().slice(0,2)),autoCapitalize:"characters",maxLength:2,returnKeyType:"next",onSubmitEditing:()=>be.current?.focus()})})}),jsx(View,{style:p.flex,children:jsx(Te,{label:"ZIP code",children:jsx(TextInput,{ref:be,style:p.input,placeholder:"11201",placeholderTextColor:j,value:ve,onChangeText:Le,keyboardType:"number-pad",maxLength:10,returnKeyType:"next",onSubmitEditing:()=>De.current?.focus()})})})]}),jsx(Te,{label:"Country",children:jsx(TextInput,{ref:De,style:p.input,placeholder:"US",placeholderTextColor:j,value:Ae,onChangeText:w=>Re(w.toUpperCase().slice(0,2)),autoCapitalize:"characters",maxLength:2,returnKeyType:"done",onSubmitEditing:re})})]}),c===4&&jsxs(Te,{label:"Social Security Number",children:[jsx(TextInput,{style:p.input,placeholder:"123-45-6789",placeholderTextColor:j,value:Ee,onChangeText:Ne,keyboardType:"number-pad",secureTextEntry:true,returnKeyType:"done",onSubmitEditing:re}),jsx(Text,{style:p.ssnHint,children:"Your SSN is transmitted securely and never stored on this device."})]})]}),jsx(View,{style:p.footer,children:a&&c===lt?jsx(View,{style:p.continueBtn,children:jsx(ActivityIndicator,{color:"#000"})}):jsx(TouchableOpacity,{style:[p.continueBtn,!ae()&&p.continueBtnDisabled],onPress:re,disabled:!ae(),children:jsx(Text,{style:[p.continueBtnText,!ae()&&p.continueBtnTextDisabled],children:c===lt?"Submit":"Continue"})})})]})})}function Te({label:e,children:a}){return jsxs(View,{style:ar.container,children:[jsx(Text,{style:ar.label,children:e}),a]})}var ar=StyleSheet.create({container:{marginBottom:20},label:{fontSize:13,color:ct,marginBottom:8,fontWeight:"600",textTransform:"uppercase",letterSpacing:.5}}),p=StyleSheet.create({flex:{flex:1},screen:{flex:1,backgroundColor:ln},header:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",paddingTop:60,paddingHorizontal:20,paddingBottom:16},backBtn:{width:36,height:36,borderRadius:18,backgroundColor:_t,alignItems:"center",justifyContent:"center"},backBtnText:{color:Ft,fontSize:22,marginTop:-1},stepCounter:{color:ct,fontSize:15,fontWeight:"600"},closeBtn:{width:36,height:36,borderRadius:18,backgroundColor:_t,alignItems:"center",justifyContent:"center"},closeText:{color:ct,fontSize:14,fontWeight:"600"},progressTrack:{flexDirection:"row",gap:4,paddingHorizontal:20,marginBottom:32},progressSegment:{flex:1,height:3,borderRadius:2,backgroundColor:sr},progressSegmentDone:{backgroundColor:Nt},progressSegmentActive:{backgroundColor:Nt},content:{paddingHorizontal:24,paddingBottom:16},title:{fontSize:28,fontWeight:"700",color:Ft,marginBottom:8,lineHeight:34},subtitle:{fontSize:15,color:ct,marginBottom:32,lineHeight:22},input:{backgroundColor:_t,borderRadius:12,padding:16,fontSize:17,color:Ft,borderWidth:1,borderColor:sr},dobRow:{flexDirection:"row",gap:10,marginBottom:20},dobCol:{flex:1},dobColWide:{flex:1.5},dobLabel:{fontSize:13,color:ct,fontWeight:"600",marginBottom:8,textTransform:"uppercase",letterSpacing:.5,textAlign:"center"},dobInput:{textAlign:"center"},row:{flexDirection:"row"},ssnHint:{fontSize:12,color:j,marginTop:10,lineHeight:18},footer:{paddingHorizontal:24,paddingBottom:48,paddingTop:12},continueBtn:{backgroundColor:Nt,borderRadius:24,paddingVertical:18,alignItems:"center"},continueBtnDisabled:{backgroundColor:_t},continueBtnText:{color:"#000000",fontSize:17,fontWeight:"700"},continueBtnTextDisabled:{color:j}});var cn="https://api.unifold.io",dr,dn="pk_test_123";function un(){return typeof __DEV__<"u"&&__DEV__&&dr?dr:cn}function ur(){return un()}function wt(){return dn}var pr="",mr;function xt(e){pr=e;}function Ct(e){mr=e;}function ce(){let e=pr||wt();return e}function de(){return mr??ur()}async function Tt(){let e=`${de()}/v1/public/onramps/headless/stripe/config`,a=ce(),o=await fetch(e,{method:"GET",headers:{"x-publishable-key":a,"Content-Type":"application/json"}});if(!o.ok)throw new Error(`Failed to load Stripe config: ${o.status}`);let l=await o.json();if(!l?.publishable_key)throw new Error("Missing Stripe publishable key in config response");return l.publishable_key}async function fr(e){let a=await fetch(`${de()}/v1/public/onramps/headless/stripe/oauth/start`,{method:"POST",headers:{"x-publishable-key":ce(),"Content-Type":"application/json"},body:JSON.stringify({email:e})});if(!a.ok)throw new Error(`Failed to create auth intent: ${a.status}`);let o=await a.json();return o.auth_intent_id??o.id}async function yr(e){let a=await fetch(`${de()}/v1/public/onramps/headless/stripe/oauth/token`,{method:"POST",headers:{"x-publishable-key":ce(),"Content-Type":"application/json"},body:JSON.stringify({auth_intent_id:e})});if(!a.ok)throw new Error(`Failed to exchange auth intent for tokens: ${a.status}`);return a.json()}async function gr(e,a){let o={crypto_customer_id:e.cryptoCustomerId,payment_token:e.paymentToken,source_amount:e.sourceAmount,source_currency:e.sourceCurrency,destination_currency:e.destinationCurrency,wallet_address:e.walletAddress,destination_network:e.destinationNetwork},l=await fetch(`${de()}/v1/public/onramps/headless/stripe/sessions`,{method:"POST",headers:{"x-publishable-key":ce(),"x-stripe-oauth-token":a,"Content-Type":"application/json"},body:JSON.stringify(o)}),c=await l.text();if(!l.ok)throw new Error(`Failed to create onramp session: ${l.status} ${c}`);return JSON.parse(c)}async function hr(e,a){let o=await fetch(`${de()}/v1/public/onramps/headless/stripe/sessions/${e}/confirm`,{method:"POST",headers:{"x-publishable-key":ce(),"x-stripe-oauth-token":a,"Content-Type":"application/json"}}),l=await o.text();if(!o.ok)throw new Error(`Failed to confirm onramp session: ${o.status} ${l}`);return JSON.parse(l)}async function _r(e,a){let o=`${de()}/v1/public/onramps/headless/stripe/customers/${e}`,l=await fetch(o,{method:"GET",headers:{"x-publishable-key":ce(),"x-stripe-oauth-token":a}}),c=await l.text();if(!l.ok)throw new Error(`Failed to get onramp customer: ${l.status} ${c}`);return JSON.parse(c)}async function br(e,a){let o=`${de()}/v1/public/onramps/headless/stripe/sessions/${e}`,l=await fetch(o,{method:"GET",headers:{"x-publishable-key":ce(),"x-stripe-oauth-token":a}}),c=await l.text();if(!l.ok)throw new Error(`Failed to get onramp session: ${l.status} ${c}`);return JSON.parse(c)}async function wr(e,a){let o=await fetch(`${de()}/v1/public/onramps/headless/stripe/sessions/${e}/quote/refresh`,{method:"POST",headers:{"x-publishable-key":ce(),"x-stripe-oauth-token":a,"Content-Type":"application/json"}});if(!o.ok){let l=await o.text();throw new Error(`Failed to refresh quote: ${o.status} ${l}`)}return o.json()}async function xr(e){if(!e.recipient_address)throw new Error("[Unifold] recipient_address is required for fetchDepositAddress. Pass recipientAddress in your onramp config.");let a={external_user_id:e.external_user_id,destination_chain_type:e.destination_chain_type||"ethereum",destination_chain_id:e.destination_chain_id||"8453",destination_token_address:e.destination_token_address||"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",recipient_address:e.recipient_address,client_metadata:{}},o=await fetch(`${de()}/v1/public/deposit_addresses`,{method:"POST",headers:{accept:"application/json","x-publishable-key":ce(),"Content-Type":"application/json"},body:JSON.stringify(a)});if(!o.ok)throw new Error(`Failed to create deposit address: ${o.status}`);return o.json()}async function Cr(e){let a=new URLSearchParams({token_address:e.token_address,chain_id:e.chain_id,chain_type:e.chain_type}),o=await fetch(`${de()}/v1/public/onramps/headless/stripe/default_token?${a.toString()}`,{method:"GET",headers:{accept:"application/json","x-publishable-key":ce()}});if(!o.ok)throw new Error(`Failed to fetch default onramp token: ${o.status}`);return o.json()}var Tr={firstName:"",lastName:"",idNumber:"",dobDay:"",dobMonth:"",dobYear:"",addressLine1:"",addressLine2:"",city:"",state:"",postalCode:"",country:"US"};function St(e){let a=e?.flowOrder==="amount_first",o=a?"session_params":"email",{configure:l,hasLinkAccount:c,registerLinkUser:x,authorize:B,attachKycInfo:L,presentKycInfoVerification:D,verifyIdentity:W,registerWalletAddress:T,collectPaymentMethod:S,createCryptoPaymentToken:k}=useOnramp(),[O,y]=useState(o),[N,b]=useState(false),[Ve,m]=useState(""),[ge,te]=useState(null),[C,se]=useState(e?.email??""),[M,ve]=useState(e?.phone??""),[Le,Ae]=useState(""),[Re,Ee]=useState("US"),[Ne,Fe]=useState(""),[K,ze]=useState(""),[he,_e]=useState(false),[Ye,be]=useState(false),De=useRef(false),ae=useRef(false),re=useRef(""),F=useRef(null),[h,U]=useState(Tr),[w,V]=useState(e?.defaultWalletAddress??"0x102471956A026866171C44F326e1DfafB6C6e34c"),[Wr,Kr]=useState(""),[We,tt]=useState(e?.defaultNetwork??Onramp.CryptoNetwork.base),[Ke,Yt]=useState(e?.defaultSourceAmount??"100"),[ft,Gt]=useState(e?.defaultSourceCurrency??"usd"),[yt,vt]=useState(e?.defaultDestinationCurrency??"usdc"),[we,rt]=useState(null),[Ht,At]=useState(false),[Ur,$r]=useState(false),nt=useRef(null),ot=useRef(false),qt=useRef(e?.onComplete),Qt=useRef(e?.onError),Jt=useRef(e?.onStepChange),Zt=useRef(o);useEffect(()=>{qt.current=e?.onComplete;},[e?.onComplete]),useEffect(()=>{Qt.current=e?.onError;},[e?.onError]),useEffect(()=>{Jt.current=e?.onStepChange;},[e?.onStepChange]);let Rt=useRef(o);useEffect(()=>{O!==Rt.current&&(Jt.current?.(O,Rt.current),Rt.current=O),Zt.current=O;},[O]);let f=useCallback((r,d,_)=>{let P={code:r,message:d,step:Zt.current,stripeErrorCode:_};te(P),m(""),Qt.current?.(P);},[]),Xt=useCallback(r=>{let d={sessionId:r.id,status:r.status,sourceAmount:r.transaction_details.source_amount,sourceCurrency:r.transaction_details.source_currency,destinationAmount:r.transaction_details.destination_amount,destinationCurrency:r.transaction_details.destination_currency,destinationNetwork:r.transaction_details.destination_network,walletAddress:r.transaction_details.wallet_address,fees:{networkFee:r.transaction_details.fees.network_fee_amount,transactionFee:r.transaction_details.fees.transaction_fee_amount}};return qt.current?.(d),d},[]),R=useCallback(()=>te(null),[]);useEffect(()=>{isPlatformPaySupported().then($r);},[]),useEffect(()=>(ot.current=false,()=>{ot.current=true,nt.current&&clearTimeout(nt.current);}),[]),useEffect(()=>{if(!e?.publishableKey||!e?.externalUserId||!e?.recipientAddress||he||Ye)return;let r=false;be(true);async function d(){try{let[_,P]=await Promise.all([xr({external_user_id:e.externalUserId,recipient_address:e.recipientAddress,destination_chain_type:e?.destinationChainType,destination_chain_id:e?.destinationChainId,destination_token_address:e?.destinationTokenAddress}),e?.destinationTokenAddress&&e?.destinationChainId&&e?.destinationChainType?Cr({token_address:e.destinationTokenAddress,chain_id:e.destinationChainId,chain_type:e.destinationChainType}).catch(Y=>(console.warn("[useStripeOnramp] fetchDefaultOnrampToken failed, using chain_id fallback:",Y?.message),null)):Promise.resolve(null)]);if(r)return;let le=e?.destinationChainType??"ethereum",xe=_.data.find(Y=>Y.chain_type===le);if(xe?.address){let Y=xe.address.toLowerCase();V(Y),re.current=Y,xe.recipient_address&&Kr(xe.recipient_address);}else console.warn("[resolveWallet] No wallet found for chain_type",le,"in",_.data?.length,"wallets");let Q={base:Onramp.CryptoNetwork.base,ethereum:Onramp.CryptoNetwork.ethereum,solana:Onramp.CryptoNetwork.solana,bitcoin:Onramp.CryptoNetwork.bitcoin,polygon:Onramp.CryptoNetwork.polygon},st={8453:"base",1:"ethereum",137:"polygon"},Ge=P?.destination_network,at="none";if(Ge&&Q[Ge])tt(Q[Ge]),at=Ge+" (from default_token API)";else if(e?.destinationChainId&&st[e.destinationChainId]){let Y=st[e.destinationChainId];Q[Y]&&tt(Q[Y]),at=Y+" (from chain_id "+e.destinationChainId+")";}else Q[le]&&(tt(Q[le]),at=le+" (from chain_type fallback)");P?.destination_currency&&vt(P.destination_currency.toLowerCase()),_e(!0),ae.current=!0;}catch(_){console.error("[useStripeOnramp] Failed to resolve wallet:",_?.message),_e(true),ae.current=true;}finally{r||be(false);}}return d(),()=>{r=true;}},[e?.publishableKey,e?.externalUserId]);let it=useCallback(async()=>{if(F.current)return F.current;let r=l({merchantDisplayName:e?.merchantDisplayName??"Unifold",appearance:{lightColors:{primary:"#2d22a1",contentOnPrimary:"#ffffff",borderSelected:"#07b8b8"},darkColors:{primary:"#800080",contentOnPrimary:"#ffffff",borderSelected:"#526f3e"},style:"ALWAYS_DARK",primaryButton:{cornerRadius:8,height:48}}}).then(d=>(d.error&&(console.error("[useStripeOnramp] configureSDK error:",d.error.message,d.error.code),F.current=null),d)).catch(d=>{throw console.error("[useStripeOnramp] configureSDK threw:",d?.message??d),F.current=null,d});return F.current=r,r},[l,e?.merchantDisplayName]);useEffect(()=>{it();},[]);let Ue=useCallback(async r=>{b(true),R(),m("Creating auth intent...");try{let d=await fr(r);m("Waiting for authorization...");let _=await B(d);if(_?.error){f("authorization_error",_.error.message,_.error.code),y("email");return}if(_?.status==="Denied"){f("authorization_error","Authorization denied by user."),y("email");return}if(_?.status!=="Consented"||!_.customerId){f("authorization_error","Authorization was canceled."),y("email");return}m("Exchanging tokens...");let P=await yr(d),le=_.customerId,xe=P.access_token;Fe(le),ze(xe),m("Checking verification status...");try{let Q=await _r(le,xe),st=Q.verifications.find(Ce=>Ce.name==="kyc_verified"),Ge=Q.verifications.find(Ce=>Ce.name==="id_document_verified"),at=st?.status==="verified",Y=st?.status==="rejected",nr=Ge?.status==="verified",Dt=Q.provided_fields.includes("first_name");if(m(""),Y&&!Dt)f("kyc_error","KYC was previously rejected. Please submit with correct info."),y("kyc");else if(Y&&Dt)y(nr?"wallet":"identity");else if(!at&&!Dt)y("kyc");else if(!nr)y("identity");else if(ae.current&&re.current)try{let Ce=await T(re.current,We);Ce?.error?(f("wallet_error",Ce.error.message,Ce.error.code),y("wallet")):y(a?"payment_method":"session_params");}catch(Ce){console.warn("[proceedToAuthorize] Inline wallet registration failed, falling back to wallet step:",Ce?.message),y("wallet");}else y("wallet");}catch(Q){console.warn("[getOnrampCustomer] failed, defaulting to kyc:",Q?.message),m(""),y("kyc");}}catch(d){f("authorization_error",d?.message??String(d)),y("email");}finally{b(false);}},[B,R,f,T,We,a]),jr=useCallback(async()=>{if(Keyboard.dismiss(),!C){f("validation_error","Please enter an email address.");return}b(true),R(),m("");try{m("Configuring...");let r=await it();if(r.error){f("configuration_error",r.error.message,r.error.code);return}m("Checking Link account...");let d=await c(C);if(d.error){f("authorization_error",d.error.message,d.error.code);return}d.hasLinkAccount?await Ue(C):(m(""),y("register"));}catch(r){f("unknown_error",r?.message??String(r));}finally{b(false);}},[R,it,C,f,c,Ue]),Mr=useCallback(async()=>{if(!M){f("validation_error","Please enter your phone number.");return}b(true),R(),m("");try{m("Creating Link account...");let r=await x({email:C,phone:M,fullName:Le||C,country:Re||"US"});if(r.error){f("registration_error",r.error.message,r.error.code);return}await Ue(C);}catch(r){f("registration_error",r?.message??String(r));}finally{b(false);}},[R,Re,C,f,Le,M,x,Ue]);useEffect(()=>{De.current||O==="email"&&e?.email&&(De.current=true,e?.phone?(async()=>{b(true),R();try{m("Configuring...");let r=await it();if(r.error){f("configuration_error",r.error.message,r.error.code);return}m("Checking Link account...");let d=await c(e.email);if(d.error){f("authorization_error",d.error.message,d.error.code);return}if(d.hasLinkAccount)await Ue(e.email);else {m("Creating Link account...");let _=await x({email:e.email,phone:e.phone,fullName:e.email,country:"US"});if(_.error){f("registration_error",_.error.message,_.error.code);return}await Ue(e.email);}}catch(r){f("unknown_error",r?.message??String(r));}finally{b(false);}})():(async()=>{b(true),R();try{m("Configuring...");let r=await it();if(r.error){f("configuration_error",r.error.message,r.error.code);return}m("Checking Link account...");let d=await c(e.email);if(d.error){f("authorization_error",d.error.message,d.error.code);return}d.hasLinkAccount?await Ue(e.email):(m(""),y("register"));}catch(r){f("unknown_error",r?.message??String(r));}finally{b(false);}})());},[O]);let Yr=useCallback(async r=>{b(true),R(),m(""),U(r);try{let d={firstName:r.firstName,lastName:r.lastName,idNumber:r.idNumber||void 0,dateOfBirth:{day:parseInt(r.dobDay,10),month:parseInt(r.dobMonth,10),year:parseInt(r.dobYear,10)},address:{line1:r.addressLine1,line2:r.addressLine2||void 0,city:r.city,state:r.state,postalCode:r.postalCode,country:r.country}},_=await L(d);if(_?.error){if(_.error.stripeErrorCode==="consumer_person_already_verified"){m(""),y("identity");return}f("kyc_error",_.error.message,_.error.stripeErrorCode??_.error.code),y("kyc");return}m("Please review your KYC information...");let P=await D(null);if(P?.error){f("kyc_error",P.error.message,P.error.stripeErrorCode??P.error.code),y("kyc");return}if(P?.status==="UpdateAddress"){f("kyc_error","Please update your address and resubmit."),y("kyc");return}m(""),y("identity");}catch(d){f("kyc_error",d?.message??String(d)),y("kyc");}finally{b(false);}},[L,R,f,D]),er=useCallback(async()=>{b(true),R(),m("Launching identity verification...");try{let r=await W();if(r?.error){f("identity_error",r.error.message,r.error.code);return}m(""),y("wallet");}catch(r){f("identity_error",r?.message??String(r));}finally{b(false);}},[R,f,W]);useEffect(()=>{O==="identity"&&!N&&er();},[O]);let tr=useCallback(async()=>{if(!w){f("validation_error","Please enter a wallet address.");return}b(true),R(),m("");try{let r=await T(w.toLowerCase(),We);if(r?.error){f("wallet_error",r.error.message,r.error.code);return}m(""),y(a?"payment_method":"session_params");}catch(r){f("wallet_error",r?.message??String(r));}finally{b(false);}},[R,f,w,We,T,a]);useEffect(()=>{O==="wallet"&&he&&w&&!N&&tr();},[O,he,w]);let Gr=useCallback(async(r=false)=>{if(!Ke||isNaN(Number(Ke))||Number(Ke)<=0){f("validation_error","Please enter a valid amount.");return}b(true),R(),m("");try{let d;if(r){m("Opening Apple Pay...");let xe={applePay:{merchantCountryCode:"US",currencyCode:ft.toUpperCase(),cartItems:[{paymentType:PlatformPay.PaymentType.Immediate,label:`${yt.toUpperCase()} purchase + fees`,amount:Ke||"0.00"}]}};d=await S("PlatformPay",xe);}else m("Select a payment method..."),d=await S("Card");if(d?.error){f("payment_error",d.error.message,d.error.code),y("payment_method");return}if(!d?.displayData){f("payment_error","Payment method selection was canceled."),y("payment_method");return}m("Creating payment token...");let _=await k();if(_?.error){f("payment_error",_.error.message,_.error.code),y("payment_method");return}let P=_.cryptoPaymentToken;m("Creating onramp session...");let le=await gr({cryptoCustomerId:Ne,paymentToken:P,sourceAmount:Number(Ke),sourceCurrency:ft,destinationCurrency:yt,walletAddress:w.toLowerCase(),destinationNetwork:We},K);rt(le),At(r),m(""),y("quote");}catch(d){f("session_error",d?.message??String(d)),y("payment_method");}finally{b(false);}},[K,R,S,k,Ne,yt,f,Ke,ft,w,We]),Hr=useCallback(async()=>{if(we){b(true),R(),m("");try{let r=await wr(we.id,K);rt(r);}catch(r){f("session_error",r?.message??String(r));}finally{b(false);}}},[K,R,f,we]),rr=useCallback((r,d)=>{ot.current=false;let _=async()=>{try{let P=await br(r,d);if(ot.current)return;P.status==="fulfillment_complete"?(rt(P),y("success"),Xt(P)):nt.current=setTimeout(_,3e3);}catch(P){if(ot.current)return;console.error("[pollSessionStatus] error:",P?.message),nt.current=setTimeout(_,5e3);}};nt.current=setTimeout(_,3e3);},[Xt]),Et=useCallback(async()=>{if(we){b(true),R(),m("");try{m("Confirming purchase...");let r=await hr(we.id,K);rt(r),y("processing"),m(""),rr(r.id,K);}catch(r){f("session_error",r?.message??String(r));}finally{b(false);}}},[K,R,f,rr,we]);useEffect(()=>{O==="quote"&&Ht&&we&&!N&&(At(false),Et());},[O,Ht,we,N,Et]);let qr=useCallback(()=>{y(o),b(false),m(""),te(null),se(e?.email??""),ve(e?.phone??""),Ae(""),Ee("US"),Fe(""),ze(""),_e(false),be(false),U(Tr),V(e?.recipientAddress??""),tt(Onramp.CryptoNetwork.ethereum),Yt(e?.defaultSourceAmount??"100"),Gt(e?.defaultSourceCurrency??"usd"),vt(e?.defaultDestinationCurrency??"usdc"),rt(null),At(false),De.current=false;},[e,o]);return {step:O,loading:N,status:Ve,error:ge,email:C,phone:M,fullName:Le,country:Re,customerId:Ne,accessToken:K,session:we,kycData:h,walletAddress:w,resolvedRecipientAddress:Wr,walletNetwork:We,sourceAmount:Ke,sourceCurrency:ft,destinationCurrency:yt,applePaySupported:Ur,walletReady:he,walletLoading:Ye,setStep:y,setStatus:m,setEmail:se,setPhone:ve,setFullName:Ae,setCountry:Ee,setWalletAddress:V,setWalletNetwork:tt,setSourceAmount:Yt,setSourceCurrency:Gt,setDestinationCurrency:vt,checkEmail:jr,register:Mr,attachKyc:Yr,verifyIdentity:er,registerWallet:tr,collectPaymentMethod:Gr,refreshQuote:Hr,confirmCheckout:Et,reset:qr,clearError:R,amountFirst:a}}function kr({size:e=28}){return jsx(gn,{width:e,height:e,viewBox:"0 0 28 28",fill:"none",children:jsxs(G,{fillRule:"evenodd",children:[jsx(Path,{fill:"#0052FF",fillRule:"nonzero",d:"M14 28a14 14 0 1 0 0-28 14 14 0 0 0 0 28"}),jsx(Path,{fill:"#FFF",d:"M13.967 23.86c5.445 0 9.86-4.415 9.86-9.86s-4.415-9.86-9.86-9.86c-5.166 0-9.403 3.974-9.825 9.03h14.63v1.642H4.142c.413 5.065 4.654 9.047 9.826 9.047Z"})]})})}function Pr({size:e=28}){return jsxs(gn,{width:e,height:e,viewBox:"0 0 28 28",fill:"none",children:[jsxs(G,{clipPath:"url(#eth_clip)",children:[jsx(Path,{d:"M14 28C21.732 28 28 21.732 28 14C28 6.26801 21.732 0 14 0C6.26801 0 0 6.26801 0 14C0 21.732 6.26801 28 14 28Z",fill:"#627EEA"}),jsx(Path,{d:"M14.4357 3.5V11.2612L20.9956 14.1925L14.4357 3.5Z",fill:"white",fillOpacity:.602}),jsx(Path,{d:"M14.4357 3.5L7.875 14.1925L14.4357 11.2612V3.5Z",fill:"white"}),jsx(Path,{d:"M14.4357 19.222V24.4956L21 15.414L14.4357 19.222Z",fill:"white",fillOpacity:.602}),jsx(Path,{d:"M14.4357 24.4956V19.2211L7.875 15.414L14.4357 24.4956Z",fill:"white"}),jsx(Path,{d:"M14.4357 18.0014L20.9956 14.1925L14.4357 11.263V18.0014Z",fill:"white",fillOpacity:.2}),jsx(Path,{d:"M7.875 14.1925L14.4357 18.0014V11.263L7.875 14.1925Z",fill:"white",fillOpacity:.602})]}),jsx(Defs,{children:jsx(ClipPath,{id:"eth_clip",children:jsx(Rect,{width:28,height:28,fill:"white"})})})]})}function Rr({size:e=28}){return jsxs(gn,{width:e,height:e,viewBox:"0 0 28 28",fill:"none",children:[jsxs(G,{clipPath:"url(#btc_clip)",children:[jsx(Path,{d:"M14 28C21.732 28 28 21.732 28 14C28 6.26801 21.732 0 14 0C6.26801 0 0 6.26801 0 14C0 21.732 6.26801 28 14 28Z",fill:"#F7931A"}),jsx(Path,{d:"M20.0594 12.1625C20.3438 10.2594 18.9 9.23124 16.9203 8.55311L17.5656 5.97186L15.9906 5.57811L15.3672 8.09374C14.9516 7.9953 14.525 7.89686 14.0985 7.79843L14.7328 5.27186L13.1578 4.87811L12.5125 7.45936C12.1735 7.3828 11.8344 7.30624 11.5063 7.22968V7.21874L9.34065 6.67186L8.92502 8.35624C8.92502 8.35624 10.0844 8.61874 10.0625 8.64061C10.6969 8.79374 10.8063 9.2203 10.7844 9.54843L10.0625 12.4578C10.1063 12.4687 10.161 12.4797 10.2266 12.5125C10.1828 12.5016 10.1281 12.4906 10.0735 12.4687L9.05627 16.5375C8.97971 16.7344 8.78284 17.0187 8.34534 16.9094C8.36721 16.9312 7.20784 16.625 7.20784 16.625L6.43127 18.4297L8.47659 18.9437C8.8594 19.0422 9.23127 19.1406 9.59221 19.2281L8.9469 21.8422L10.5219 22.2359L11.1672 19.6547C11.5938 19.775 12.0094 19.8734 12.4141 19.9828L11.7688 22.5531L13.3438 22.9469L13.9891 20.3328C16.6578 20.8359 18.6594 20.6281 19.5016 18.2219C20.1797 16.2859 19.4688 15.1703 18.0688 14.4375C19.086 14.2078 19.8516 13.5406 20.0594 12.1625ZM16.4938 17.1609C16.0125 19.0969 12.7531 18.0469 11.6922 17.7844L12.5453 14.35C13.6063 14.6125 16.9969 15.1484 16.4938 17.1609ZM16.975 12.1297C16.5375 13.8906 13.825 12.9937 12.95 12.775L13.7266 9.6578C14.6016 9.87655 17.4344 10.2812 16.975 12.1297Z",fill:"white"})]}),jsx(Defs,{children:jsx(ClipPath,{id:"btc_clip",children:jsx(Rect,{width:28,height:28,fill:"white"})})})]})}function Er({size:e=28}){return jsxs(gn,{width:e,height:e,viewBox:"0 0 256 256",fill:"none",children:[jsxs(Defs,{children:[jsxs(LinearGradient,{id:"sol1",x1:"360.9",y1:"-37.5",x2:"141.2",y2:"383.3",gradientUnits:"userSpaceOnUse",children:[jsx(Stop,{offset:"0",stopColor:"#00FFA3"}),jsx(Stop,{offset:"1",stopColor:"#DC1FFF"})]}),jsxs(LinearGradient,{id:"sol2",x1:"264.8",y1:"-87.6",x2:"45.16",y2:"333.15",gradientUnits:"userSpaceOnUse",children:[jsx(Stop,{offset:"0",stopColor:"#00FFA3"}),jsx(Stop,{offset:"1",stopColor:"#DC1FFF"})]}),jsxs(LinearGradient,{id:"sol3",x1:"312.55",y1:"-62.69",x2:"92.88",y2:"358.06",gradientUnits:"userSpaceOnUse",children:[jsx(Stop,{offset:"0",stopColor:"#00FFA3"}),jsx(Stop,{offset:"1",stopColor:"#DC1FFF"})]})]}),jsx(Circle,{cx:128,cy:128,r:128,fill:"black"}),jsxs(G,{transform:"translate(128,128) scale(0.35) translate(-198.85,-156)",children:[jsx(Path,{fill:"url(#sol2)",d:"M64.6,3.8C67.1,1.4,70.4,0,73.8,0h317.4c5.8,0,8.7,7,4.6,11.1l-62.7,62.7c-2.4,2.4-5.7,3.8-9.2,3.8H6.5c-5.8,0-8.7-7-4.6-11.1L64.6,3.8z"}),jsx(Path,{fill:"url(#sol3)",d:"M333.1,120.1c-2.4-2.4-5.7-3.8-9.2-3.8H6.5c-5.8,0-8.7,7-4.6,11.1l62.7,62.7c2.4,2.4,5.7,3.8,9.2,3.8h317.4c5.8,0,8.7-7,4.6-11.1L333.1,120.1z"}),jsx(Path,{fill:"url(#sol1)",d:"M64.6,237.9c2.4-2.4,5.7-3.8,9.2-3.8h317.4c5.8,0,8.7,7,4.6,11.1l-62.7,62.7c-2.4,2.4-5.7,3.8-9.2,3.8H6.5c-5.8,0-8.7-7-4.6-11.1L64.6,237.9z"})]})]})}function Dr({size:e=28}){return jsx(gn,{width:e,height:e,viewBox:"0 0 32 32",fill:"none",children:jsxs(G,{children:[jsx(Circle,{cx:16,cy:16,r:16,fill:"#6F41D8"}),jsx(Path,{fill:"#FFF",d:"M21.092 12.693c-.369-.215-.848-.215-1.254 0l-2.879 1.654-1.955 1.078-2.879 1.653c-.369.216-.848.216-1.254 0l-2.288-1.294c-.369-.215-.627-.61-.627-1.042V12.19c0-.431.221-.826.627-1.042l2.25-1.258c.37-.216.85-.216 1.256 0l2.25 1.258c.37.216.628.611.628 1.042v1.654l1.955-1.115v-1.653a1.16 1.16 0 0 0-.627-1.042l-4.17-2.372c-.369-.216-.848-.216-1.254 0l-4.244 2.372A1.16 1.16 0 0 0 6 11.076v4.78c0 .432.221.827.627 1.043l4.244 2.372c.369.215.849.215 1.254 0l2.879-1.618 1.955-1.114 2.879-1.617c.369-.216.848-.216 1.254 0l2.251 1.258c.37.215.627.61.627 1.042v2.552c0 .431-.22.826-.627 1.042l-2.25 1.294c-.37.216-.85.216-1.255 0l-2.251-1.258c-.37-.216-.628-.611-.628-1.042v-1.654l-1.955 1.115v1.653c0 .431.221.827.627 1.042l4.244 2.372c.369.216.848.216 1.254 0l4.244-2.372c.369-.215.627-.61.627-1.042v-4.78a1.16 1.16 0 0 0-.627-1.042l-4.28-2.409z"})]})})}var q="#00D924",Lr="#00D92440",Kn="#000000",Oe="#1C1C1E",Be="#38383A",Pe="#FFFFFF",fe="#8E8E93",ye="#636366",Un="#FF453A",Ir=[{label:"Base",value:Onramp.CryptoNetwork.base,defaultCrypto:"usdc",Icon:kr},{label:"Ethereum",value:Onramp.CryptoNetwork.ethereum,defaultCrypto:"eth",Icon:Pr},{label:"Bitcoin",value:Onramp.CryptoNetwork.bitcoin,defaultCrypto:"btc",Icon:Rr},{label:"Solana",value:Onramp.CryptoNetwork.solana,defaultCrypto:"sol",Icon:Er},{label:"Polygon",value:Onramp.CryptoNetwork.polygon,defaultCrypto:"matic",Icon:Dr}];function Br(e,a){let o=parseFloat(e);if(isNaN(o))return e;let l=a.toLowerCase(),c=["eth","btc"].includes(l)?4:2;return o.toFixed(c)}function Ot({config:e,onComplete:a}){let{step:o,loading:l,status:c,error:x,email:B,phone:L,session:D,kycData:W,walletAddress:T,resolvedRecipientAddress:S,walletNetwork:k,sourceAmount:O,sourceCurrency:y,destinationCurrency:N,applePaySupported:b,walletReady:Ve,walletLoading:m,setStep:ge,setEmail:te,setPhone:C,setWalletAddress:se,setWalletNetwork:M,setSourceAmount:ve,setDestinationCurrency:Le,checkEmail:Ae,register:Re,attachKyc:Ee,verifyIdentity:Ne,registerWallet:Fe,collectPaymentMethod:K,refreshQuote:ze,confirmCheckout:he,reset:_e,clearError:Ye,amountFirst:be}=St(e),De=!!e?.email,ae=!!e?.phone,re=!!e?.publishableKey&&!!e?.externalUserId,F=()=>{_e(),a?.();};if(o==="email")return De?jsx(View,{style:n.screen,children:jsxs(View,{style:A.centered,children:[jsx(ActivityIndicator,{size:"large",color:q}),jsx(Se,{error:x,progress:c,loading:l})]})}):jsx(KeyboardAvoidingView,{style:n.flex,behavior:Platform.OS==="ios"?"padding":void 0,children:jsxs(View,{style:n.screen,children:[jsx(Ze,{onPress:F}),jsxs(View,{style:n.content,children:[jsx(Text,{style:n.title,children:"Enter your email"}),jsx(Text,{style:n.subtitle,children:"We'll check if you have a Link account or create one for you."}),jsxs(View,{style:n.fieldWrap,children:[jsx(Text,{style:n.fieldLabel,children:"Email address"}),jsx(TextInput,{style:n.input,placeholder:"jane@example.com",placeholderTextColor:ye,keyboardType:"email-address",autoCapitalize:"none",autoCorrect:false,value:B,onChangeText:te,autoFocus:true,returnKeyType:"done",onSubmitEditing:Ae})]})]}),jsxs(View,{style:n.footer,children:[l?jsx(View,{style:n.continueBtn,children:jsx(ActivityIndicator,{color:"#fff"})}):jsx(TouchableOpacity,{style:[n.continueBtn,!B&&n.continueBtnDisabled],onPress:Ae,disabled:!B,children:jsx(Text,{style:[n.continueBtnText,!B&&n.continueBtnTextDisabled],children:"Continue"})}),jsx(Se,{error:x,progress:c,loading:l})]})]})});if(o==="register")return ae?jsx(View,{style:n.screen,children:jsxs(View,{style:A.centered,children:[jsx(ActivityIndicator,{size:"large",color:q}),jsx(Se,{error:x,progress:c,loading:l})]})}):jsx(KeyboardAvoidingView,{style:n.flex,behavior:Platform.OS==="ios"?"padding":void 0,children:jsxs(View,{style:n.screen,children:[jsx(Ze,{onPress:F}),jsxs(View,{style:n.content,children:[jsx(Text,{style:n.title,children:"Enter your phone"}),jsx(Text,{style:n.subtitle,children:"We'll send a verification code to confirm your number."}),jsxs(View,{style:n.fieldWrap,children:[jsx(Text,{style:n.fieldLabel,children:"Phone number"}),jsx(TextInput,{style:n.input,placeholder:"+12125551234",placeholderTextColor:ye,keyboardType:"phone-pad",value:L,onChangeText:h=>C(h.replace(/[^\d+]/g,"").replace(/(?!^)\+/g,"")),autoFocus:true,returnKeyType:"done",onSubmitEditing:Re}),jsx(Text,{style:n.hint,children:"Include country code, e.g. +12125551234"})]}),jsxs(View,{style:n.emailRow,children:[jsx(Text,{style:n.emailLabel,children:"Signing up as"}),jsx(Text,{style:n.emailValue,children:B})]})]}),jsxs(View,{style:n.footer,children:[l?jsx(View,{style:n.continueBtn,children:jsx(ActivityIndicator,{color:"#fff"})}):jsx(TouchableOpacity,{style:[n.continueBtn,!L&&n.continueBtnDisabled],onPress:Re,disabled:!L,children:jsx(Text,{style:[n.continueBtnText,!L&&n.continueBtnTextDisabled],children:"Continue"})}),jsx(Se,{error:x,progress:c,loading:l})]})]})});if(o==="kyc")return jsx(bt,{initialData:W,loading:l,onComplete:Ee,onCancel:()=>ge("email")});if(o==="identity")return jsxs(View,{style:n.screen,children:[jsx(Ze,{onPress:F}),jsxs(View,{style:A.centered,children:[l?jsxs(Fragment,{children:[jsx(View,{style:A.spinnerWrap,children:jsx(ActivityIndicator,{size:"large",color:q})}),jsx(Text,{style:A.heading,children:"Verifying identity"}),jsx(Text,{style:A.sub,children:c||"Preparing identity verification..."})]}):jsxs(Fragment,{children:[jsx(View,{style:A.spinnerWrap,children:jsx(Text,{style:A.idIcon,children:"\u{1FAAA}"})}),jsx(Text,{style:A.heading,children:"Identity verification"}),jsx(Text,{style:A.sub,children:c||"Tap below to continue verification."})]}),jsx(Se,{error:x,progress:c,loading:false})]}),!l&&jsx(View,{style:n.footer,children:jsx(TouchableOpacity,{style:n.continueBtn,onPress:Ne,children:jsx(Text,{style:n.continueBtnText,children:"Continue Verification"})})})]});if(o==="wallet")return re?jsx(View,{style:n.screen,children:jsxs(View,{style:A.centered,children:[jsx(ActivityIndicator,{size:"large",color:q}),jsx(Se,{error:x,progress:c,loading:l})]})}):jsx(KeyboardAvoidingView,{style:n.flex,behavior:Platform.OS==="ios"?"padding":void 0,children:jsxs(View,{style:n.screen,children:[jsx(Ze,{onPress:F}),jsxs(View,{style:n.content,children:[jsx(Text,{style:n.title,children:"Your crypto wallet"}),jsx(Text,{style:n.subtitle,children:"Enter the wallet address where you'd like to receive your crypto."}),jsxs(View,{style:n.fieldWrap,children:[jsx(Text,{style:n.fieldLabel,children:"Wallet address"}),jsx(TextInput,{style:[n.input,ke.input],placeholder:"0x...",placeholderTextColor:ye,autoCapitalize:"none",autoCorrect:false,value:T,onChangeText:se})]}),jsxs(View,{style:n.fieldWrap,children:[jsx(Text,{style:n.fieldLabel,children:"Network"}),jsx(View,{style:ke.list,children:Ir.map(h=>{let U=k===h.value;return jsxs(TouchableOpacity,{style:[ke.row,U&&ke.rowSelected],onPress:()=>{M(h.value),Le(h.defaultCrypto);},children:[jsx(View,{style:ke.iconWrap,children:jsx(h.Icon,{size:24})}),jsx(Text,{style:[ke.rowText,U&&ke.rowTextSelected],children:h.label}),U&&jsx(View,{style:ke.checkCircle,children:jsx(Text,{style:ke.check,children:"\u2713"})})]},h.value)})})]})]}),jsxs(View,{style:n.footer,children:[l?jsx(View,{style:n.continueBtn,children:jsx(ActivityIndicator,{color:"#fff"})}):jsx(TouchableOpacity,{style:[n.continueBtn,!T&&n.continueBtnDisabled],onPress:Fe,disabled:!T,children:jsx(Text,{style:[n.continueBtnText,!T&&n.continueBtnTextDisabled],children:"Continue"})}),jsx(Se,{error:x,progress:c,loading:l})]})]})});if(o==="session_params")return jsx(ht,{initialAmount:O,currency:y,onConfirm:h=>{ve(h),ge(be?"email":"payment_method");},onCancel:()=>{be?F():ge("wallet");}});if(o==="payment_method"){let h=Ir.find(U=>U.value===k)?.label??k;return jsxs(View,{style:n.screen,children:[jsx(Ze,{onPress:F}),jsxs(View,{style:n.content,children:[jsx(Text,{style:n.title,children:"How do you want to pay?"}),jsxs(View,{style:X.summary,children:[jsxs(View,{style:X.summaryCol,children:[jsx(Text,{style:X.summaryLabel,children:"You spend"}),jsxs(Text,{style:X.summaryAmount,children:["$",O," ",jsx(Text,{style:X.summaryCurrency,children:y.toUpperCase()})]})]}),jsx(View,{style:X.divider}),jsxs(View,{style:X.summaryCol,children:[jsx(Text,{style:X.summaryLabel,children:"You receive"}),jsxs(Text,{style:X.summaryDest,children:[N.toUpperCase(),jsxs(Text,{style:X.summaryNetwork,children:[" on ",h]})]})]})]})]}),jsxs(View,{style:n.footer,children:[l?jsx(View,{style:n.continueBtn,children:jsx(ActivityIndicator,{color:"#fff"})}):jsxs(Fragment,{children:[b&&jsx(TouchableOpacity,{style:X.applePayBtn,onPress:()=>K(true),children:jsxs(Text,{style:X.applePayBtnText,children:["Pay with ","\uF8FF"," Pay"]})}),jsx(TouchableOpacity,{style:n.continueBtn,onPress:()=>K(false),children:jsx(Text,{style:n.continueBtnText,children:"Pay with Card"})})]}),jsx(Se,{error:x,progress:c,loading:l})]})]})}if(o==="quote"&&D){let h=D.transaction_details,U=new Date(h.quote_expiration*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),w=h.wallet_address.slice(0,6)+"..."+h.wallet_address.slice(-4),V=Br(h.destination_amount,h.destination_currency);return jsxs(View,{style:n.screen,children:[jsx(View,{style:{opacity:l?0:1},pointerEvents:l?"none":"auto",children:jsx(Ze,{onPress:F})}),jsxs(View,{style:n.content,children:[jsx(Text,{style:n.title,children:"Review your purchase"}),jsxs(View,{style:E.heroBox,children:[jsx(Text,{style:E.heroLabel,children:"You receive"}),jsxs(Text,{style:E.heroAmount,children:[V," ",jsx(Text,{style:E.heroCurrency,children:h.destination_currency.toUpperCase()})]}),jsx(Text,{style:E.heroNetwork,children:h.destination_network})]}),jsxs(View,{style:E.card,children:[jsx(Xe,{label:"You pay",value:`${h.source_amount} ${h.source_currency.toUpperCase()}`}),jsx(Xe,{label:"Network fee",value:`$${h.fees.network_fee_amount}`}),jsx(Xe,{label:"Transaction fee",value:`$${h.fees.transaction_fee_amount}`}),jsx(Xe,{label:"Wallet",value:w,mono:true}),jsx(Xe,{label:"Quote expires",value:U,last:true})]})]}),jsxs(View,{style:n.footer,children:[l?jsx(View,{style:n.continueBtn,children:jsx(ActivityIndicator,{color:"#fff"})}):jsxs(Fragment,{children:[jsx(TouchableOpacity,{style:n.continueBtn,onPress:he,children:jsx(Text,{style:n.continueBtnText,children:"Confirm Purchase"})}),jsx(TouchableOpacity,{style:n.ghostBtn,onPress:ze,children:jsx(Text,{style:n.ghostBtnText,children:"Refresh Quote"})})]}),jsx(Se,{error:x,progress:c,loading:l})]})]})}if(o==="processing")return jsx(View,{style:n.screen,children:jsxs(View,{style:A.centered,children:[jsx(View,{style:A.spinnerWrap,children:jsx(ActivityIndicator,{size:"large",color:q})}),jsx(Text,{style:A.heading,children:"Processing your purchase"}),jsxs(Text,{style:A.sub,children:["Your payment has been confirmed.",`
|
|
2
|
+
`,"We're sending your crypto \u2014 this usually takes less than a minute."]})]})});if(o==="success"&&D){let h=D.transaction_details,U=Br(h.destination_amount,h.destination_currency),w=S||e?.recipientAddress||"";return jsxs(View,{style:n.screen,children:[jsxs(ScrollView,{contentContainerStyle:A.centered,showsVerticalScrollIndicator:false,children:[jsx(View,{style:A.checkCircle,children:jsx(Text,{style:A.checkMark,children:"\u2713"})}),jsx(Text,{style:A.heading,children:"Purchase complete!"}),jsx(Text,{style:A.sub,children:"Your crypto is on its way to your wallet."}),jsxs(View,{style:[E.heroBox,A.detailCard],children:[jsx(Text,{style:E.heroLabel,children:"You received"}),jsx(Text,{style:E.heroAmount,children:U}),jsxs(Text,{style:E.heroCurrency,children:[h.destination_currency.toUpperCase()," (",h.destination_network,")"]})]}),jsxs(View,{style:[E.card,A.detailCard],children:[jsx(Vr,{label:"Deposit Address",address:h.wallet_address}),w?jsx(Vr,{label:"Recipient Address",address:w,last:true}):jsx(Xe,{label:"Session",value:D.id.slice(0,8)+"..."+D.id.slice(-6),mono:true,last:true})]})]}),jsx(View,{style:n.footer,children:jsx(TouchableOpacity,{style:n.continueBtn,onPress:()=>{_e(),a?.();},children:jsx(Text,{style:n.continueBtnText,children:"Done"})})})]})}return null}function Ze({onPress:e}){return jsxs(View,{style:n.header,children:[jsx(View,{style:n.headerSpacer}),jsx(TouchableOpacity,{style:n.closeBtn,onPress:e,children:jsx(Text,{style:n.closeBtnText,children:"\u2715"})})]})}function Se({error:e,progress:a,loading:o}){return e?jsx(Text,{style:n.errorText,children:e.message}):a&&o&&__DEV__?jsx(Text,{style:n.progressText,children:a}):null}function Xe({label:e,value:a,mono:o,last:l}){return jsxs(View,{style:[E.row,l&&E.rowLast],children:[jsx(Text,{style:E.rowLabel,children:e}),jsx(Text,{style:[E.rowValue,o&&E.rowMono],children:a})]})}function Vr({label:e,address:a,last:o}){let[l,c]=useState(false),x=()=>{Clipboard.setString(a),c(true),setTimeout(()=>c(false),2e3);};return jsxs(TouchableOpacity,{style:[E.row,o&&E.rowLast,{flexDirection:"column",alignItems:"flex-start",gap:6}],onPress:x,activeOpacity:.7,children:[jsxs(View,{style:{flexDirection:"row",justifyContent:"space-between",width:"100%"},children:[jsx(Text,{style:E.rowLabel,children:e}),jsx(Text,{style:{fontSize:12,color:l?q:fe},children:l?"Copied!":"Tap to copy"})]}),jsx(Text,{style:[E.rowValue,E.rowMono,{fontSize:12,lineHeight:18}],selectable:true,children:a})]})}var n=StyleSheet.create({flex:{flex:1},screen:{flex:1,backgroundColor:Kn,paddingHorizontal:24,paddingBottom:48},header:{flexDirection:"row",justifyContent:"flex-end",paddingTop:60,paddingBottom:16},headerSpacer:{flex:1},closeBtn:{width:36,height:36,borderRadius:18,backgroundColor:Oe,alignItems:"center",justifyContent:"center"},closeBtnText:{color:fe,fontSize:14,fontWeight:"600"},content:{flex:1,paddingTop:16},title:{fontSize:28,fontWeight:"700",color:Pe,marginBottom:8},subtitle:{fontSize:15,color:fe,marginBottom:36,lineHeight:22},fieldWrap:{marginBottom:20},fieldLabel:{fontSize:13,color:fe,fontWeight:"600",marginBottom:8,textTransform:"uppercase",letterSpacing:.5},input:{backgroundColor:Oe,borderRadius:12,padding:16,fontSize:17,color:Pe,borderWidth:1,borderColor:Be},hint:{fontSize:12,color:ye,marginTop:8},emailRow:{flexDirection:"row",alignItems:"center",gap:6,marginTop:4,backgroundColor:Oe,paddingHorizontal:14,paddingVertical:10,borderRadius:10},emailLabel:{fontSize:13,color:ye},emailValue:{fontSize:13,color:Pe,fontWeight:"600"},footer:{gap:12},continueBtn:{backgroundColor:q,borderRadius:24,paddingVertical:18,alignItems:"center"},continueBtnDisabled:{backgroundColor:Oe},continueBtnText:{color:"#000000",fontSize:17,fontWeight:"700"},continueBtnTextDisabled:{color:ye},ghostBtn:{paddingVertical:16,alignItems:"center"},ghostBtnText:{color:fe,fontSize:15,fontWeight:"500"},errorText:{fontSize:14,color:Un,textAlign:"center",lineHeight:20,marginTop:24},progressText:{fontSize:13,color:ye,textAlign:"center",lineHeight:18,marginTop:24}}),E=StyleSheet.create({heroBox:{backgroundColor:Oe,borderRadius:16,padding:24,alignItems:"center",marginBottom:16,marginTop:8,borderWidth:1,borderColor:Be,gap:4},heroLabel:{fontSize:13,color:ye,fontWeight:"600",letterSpacing:.5,textTransform:"uppercase"},heroAmount:{fontSize:48,fontWeight:"700",color:Pe,letterSpacing:-1},heroCurrency:{fontSize:22,fontWeight:"500",color:q},heroNetwork:{fontSize:13,color:ye,marginTop:2},card:{backgroundColor:Oe,borderRadius:16,borderWidth:1,borderColor:Be,overflow:"hidden"},row:{flexDirection:"row",justifyContent:"space-between",alignItems:"center",paddingVertical:14,paddingHorizontal:16,borderBottomWidth:1,borderBottomColor:Be},rowLast:{borderBottomWidth:0},rowLabel:{fontSize:14,color:fe},rowValue:{fontSize:14,fontWeight:"600",color:Pe},rowMono:{fontFamily:Platform.OS==="ios"?"Menlo":"monospace",fontSize:13}}),X=StyleSheet.create({summary:{backgroundColor:Oe,borderRadius:16,padding:20,marginTop:16,marginBottom:28,borderWidth:1,borderColor:Be,gap:16},summaryCol:{gap:4},summaryLabel:{fontSize:12,color:ye,fontWeight:"600",textTransform:"uppercase",letterSpacing:.3},summaryAmount:{fontSize:24,fontWeight:"700",color:Pe},summaryCurrency:{fontSize:14,fontWeight:"400",color:fe},summaryDest:{fontSize:24,fontWeight:"700",color:q},summaryNetwork:{fontSize:13,fontWeight:"400",color:fe},divider:{height:1,backgroundColor:Be},applePayBtn:{backgroundColor:Pe,borderRadius:24,paddingVertical:18,alignItems:"center",marginBottom:10},applePayBtnText:{color:"#000",fontSize:17,fontWeight:"700"}}),ke=StyleSheet.create({input:{fontSize:14,fontFamily:Platform.OS==="ios"?"Menlo":"monospace"},list:{gap:8},row:{flexDirection:"row",alignItems:"center",paddingVertical:14,paddingHorizontal:16,borderRadius:14,borderWidth:1,borderColor:Be,backgroundColor:Oe},rowSelected:{borderColor:q,backgroundColor:Lr},iconWrap:{width:32,height:32,alignItems:"center",justifyContent:"center",marginRight:12},rowText:{flex:1,fontSize:15,color:fe,fontWeight:"500"},rowTextSelected:{color:Pe,fontWeight:"600"},checkCircle:{width:24,height:24,borderRadius:12,backgroundColor:q,alignItems:"center",justifyContent:"center"},check:{fontSize:14,color:"#000",fontWeight:"700"}}),A=StyleSheet.create({centered:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:24},spinnerWrap:{width:80,height:80,borderRadius:40,backgroundColor:Oe,borderWidth:1,borderColor:Be,alignItems:"center",justifyContent:"center",marginBottom:28},idIcon:{fontSize:36},checkCircle:{width:80,height:80,borderRadius:40,backgroundColor:Lr,borderWidth:2,borderColor:q,alignItems:"center",justifyContent:"center",marginBottom:28},checkMark:{fontSize:36,color:q,fontWeight:"600"},heading:{fontSize:28,fontWeight:"700",color:Pe,textAlign:"center",marginBottom:10},sub:{fontSize:15,color:fe,textAlign:"center",lineHeight:22,marginBottom:36},detailCard:{width:"100%"}});var qn="https://api.unifold.io",Qn="https://api-staging.unifold.io";function Jn(){return typeof __DEV__<"u"&&__DEV__?Qn:qn}function Pt({publishableKey:e,email:a,phone:o,externalUserId:l,flowOrder:c,destinationChainType:x="ethereum",destinationChainId:B="8453",destinationTokenAddress:L,recipientAddress:D,onComplete:W,onError:T,onStepChange:S,onClose:k,merchantIdentifier:O="merchant.io.unifold",urlScheme:y="unifoldOnramp"}){let N=e||wt(),[b,Ve]=useState("loading"),[m,ge]=useState(null);useEffect(()=>{let C=false;async function se(){try{N&&(xt(N),Ct(Jn()));let M=await Tt();if(C||(await initStripe({publishableKey:M,merchantIdentifier:O,urlScheme:y}),C))return;Ve("ready");}catch(M){if(C)return;console.error("[StripeOnramp] Init failed:",M),ge(M?.message??"Failed to load Stripe configuration"),Ve("error");}}return se(),()=>{C=true;}},[N,O,y]);let te=useMemo(()=>{let C={publishableKey:N,externalUserId:l,destinationChainType:x,destinationChainId:B,onComplete:W,onError:T,onStepChange:S};return L&&(C.destinationTokenAddress=L),D&&(C.recipientAddress=D),a&&(C.email=a),o&&(C.phone=o),c&&(C.flowOrder=c),C},[N,l,x,B,L,D,a,o,c,W,T,S]);return b==="error"?jsxs(View,{style:et.centered,children:[jsx(Text,{style:et.errorText,children:"Unable to initialize"}),jsx(Text,{style:et.errorDetail,children:m}),k&&jsx(TouchableOpacity,{style:et.retryBtn,onPress:k,children:jsx(Text,{style:et.retryBtnText,children:"Go Back"})})]}):b==="loading"?jsx(View,{style:et.centered,children:jsx(ActivityIndicator,{size:"large",color:"#00D924"})}):jsx(Ot,{config:te,onComplete:k})}var et=StyleSheet.create({centered:{flex:1,justifyContent:"center",alignItems:"center",backgroundColor:"#000000",paddingHorizontal:24},errorText:{color:"#FF453A",fontSize:18,fontWeight:"600",marginBottom:8},errorDetail:{color:"#8E8E93",fontSize:14,textAlign:"center",marginBottom:24},retryBtn:{backgroundColor:"#00D924",borderRadius:24,paddingVertical:14,paddingHorizontal:32},retryBtnText:{color:"#000000",fontSize:16,fontWeight:"700"}});function zr(){let{configure:e}=useOnramp(),a=useRef(false);return useEffect(()=>{a.current||(a.current=true,e({merchantDisplayName:"Unifold",appearance:{lightColors:{primary:"#2d22a1",contentOnPrimary:"#ffffff",borderSelected:"#07b8b8"},darkColors:{primary:"#800080",contentOnPrimary:"#ffffff",borderSelected:"#526f3e"},style:"ALWAYS_DARK",primaryButton:{cornerRadius:8,height:48}}}).then(o=>{o.error&&console.error("[StripeOnrampPreconfigure] error:",o.error.message);}).catch(o=>{console.error("[StripeOnrampPreconfigure] threw:",o?.message);}));},[e]),null}or(Pt);
|
|
3
|
+
export{ht as AmountScreen,bt as KYCWizardScreen,Ot as OnrampScreen,Pt as StripeOnramp,zr as StripeOnrampPreconfigure,Tt as getStripePublishableKey,Ct as setStripeOnrampApiUrl,xt as setStripeOnrampPublishableKey,St as useStripeOnramp};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unifold/connect-react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "Unifold Connect React Native SDK - Crypto deposit and onramp for React Native/Expo",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./stripe": {
|
|
15
|
+
"types": "./dist/stripe.d.ts",
|
|
16
|
+
"import": "./dist/stripe.mjs",
|
|
17
|
+
"require": "./dist/stripe.js"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"files": [
|
|
@@ -24,11 +29,15 @@
|
|
|
24
29
|
"react-native": ">=0.72.0",
|
|
25
30
|
"react-native-gesture-handler": ">=2.0.0",
|
|
26
31
|
"react-native-svg": ">=13.0.0",
|
|
27
|
-
"react-native-webview": ">=11.0.0"
|
|
32
|
+
"react-native-webview": ">=11.0.0",
|
|
33
|
+
"@stripe/stripe-react-native": ">=0.62.0"
|
|
28
34
|
},
|
|
29
35
|
"peerDependenciesMeta": {
|
|
30
36
|
"expo": {
|
|
31
37
|
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"@stripe/stripe-react-native": {
|
|
40
|
+
"optional": true
|
|
32
41
|
}
|
|
33
42
|
},
|
|
34
43
|
"dependencies": {
|
|
@@ -38,9 +47,10 @@
|
|
|
38
47
|
"devDependencies": {
|
|
39
48
|
"@types/react": "^18.2.0",
|
|
40
49
|
"@types/react-native": "^0.72.0",
|
|
50
|
+
"dts-bundle-generator": "^9.5.1",
|
|
41
51
|
"tsup": "^8.0.0",
|
|
42
52
|
"typescript": "^5.0.0",
|
|
43
|
-
"@unifold/ui-react-native": "0.1.
|
|
53
|
+
"@unifold/ui-react-native": "0.1.13"
|
|
44
54
|
},
|
|
45
55
|
"keywords": [
|
|
46
56
|
"unifold",
|
|
@@ -67,7 +77,8 @@
|
|
|
67
77
|
},
|
|
68
78
|
"homepage": "https://unifold.io",
|
|
69
79
|
"scripts": {
|
|
70
|
-
"build": "tsup",
|
|
80
|
+
"build": "tsup && pnpm build:dts",
|
|
81
|
+
"build:dts": "dts-bundle-generator --config dts-bundle-generator.config.json && cp dist/index.d.ts dist/index.d.mts && cp dist/stripe.d.ts dist/stripe.d.mts",
|
|
71
82
|
"dev": "tsup --watch",
|
|
72
83
|
"clean": "rm -rf dist",
|
|
73
84
|
"lint": "eslint \"src/**/*.ts*\"",
|