@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 2.19 kB
JavaScript
import{u as e}from"./context-Bycd1SKV.mjs";import{u as t}from"./events-context-CI0iqAXA.mjs";import{u as n,a}from"./internal-context-e-Eni5bG.mjs";import{a as o,u as r,h as d,c as i,d as l}from"./get-is-unified-wallet-DvKS5IUO.mjs";import{g as s,i as c}from"./prepareFundingModalData-CIgFwA7s.mjs";import{useMemo as u}from"react";import{g as p}from"./useWallets-D0lpBS44.mjs";function m(a){t("fundSolanaWallet",a);let r=e(),{openModal:d}=n(),{setModalData:i}=o();return{fundWallet:async({address:e,options:t})=>{let n=t?.amount||r.fundingConfig?.defaultRecommendedAmount||"1",a=t?.asset||r.fundingConfig?.defaultRecommendedCurrency.asset||"native-currency",o=t?.chain||"solana:mainnet";i({funding:s({address:e,appConfig:r,methodScreen:"FundingMethodSelectionScreen",fundWalletConfig:{...t,amount:n,asset:a,chain:o},externalSolanaFundingScreen:"FundSolWalletWithExternalSolanaWallet"}),solanaFundingData:{amount:n,asset:"native-currency"===a?"SOL":"USDC",chain:o,destinationAddress:e,sourceWalletData:void 0}}),d("FundingMethodSelectionScreen")}}}function f(){let{user:t,getAccessToken:s}=r(),{walletProxy:m,openModal:f,client:g}=n(),{setModalData:y}=o(),h=e();return u((()=>({exportWallet:e=>new Promise((async(n,o)=>{if(!t)return void o(new a("User must be authenticated before exporting their Privy wallet"));let r=e?.address?d(t,e.address):i(t);if(!r)return void o(new a("User must have an embedded wallet."));if(!c(r))return void o(Error(`Export is not supported for ${r.chainType} wallets`));let u=l(r),{entropyId:W,entropyIdVerifier:x}=p(t,r);await s()?m?(y({connectWallet:{recoveryMethod:r.recoveryMethod,connectingWalletAddress:r.address,isUnifiedWallet:u,entropyId:W,entropyIdVerifier:x,onCompleteNavigateTo:"EmbeddedWalletKeyExportScreen",onFailure:o,shouldForceMFA:!0},keyExport:{appId:h.id,appClientId:h.appClientId,origin:g.apiUrl,address:r.address,entropyId:W,entropyIdVerifier:x,hdWalletIndex:r.walletIndex,chainType:r.chainType,walletId:r.id,isUnifiedWallet:u,imported:r.imported,onSuccess:n,onFailure:o}}),f("EmbeddedWalletConnectingScreen")):o(new a("Wallet not ready for export")):o(new a("Must have valid access token."))}))})),[t,s,m,f,g,y,h])}export{f as a,m as u};