UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 2.21 kB
import{u as e}from"./context-DLtU3JQy.mjs";import{u as t}from"./events-context-CI0iqAXA.mjs";import{u as n,a}from"./internal-context-Z-fyxadS.mjs";import{a as o,u as r,j as d,e as s,b as i}from"./privy-context-DrMxzgOR.mjs";import{x as l,b as c}from"./use-export-wallet-_wu5ex5t.mjs";import{useMemo as u}from"react";import{g as p}from"./useWallets-BzNCTucF.mjs";function m(a){t("fundSolanaWallet",a);let r=e(),{openModal:d}=n(),{setModalData:s}=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";s({funding:l({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:l}=r(),{walletProxy:m,openModal:f,client:y}=n(),{setModalData:h}=o(),g=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):s(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=i(r),{entropyId:x,entropyIdVerifier:W}=p(t,r);await l()?m?(h({connectWallet:{recoveryMethod:r.recoveryMethod,connectingWalletAddress:r.address,isUnifiedWallet:u,entropyId:x,entropyIdVerifier:W,onCompleteNavigateTo:"EmbeddedWalletKeyExportScreen",onFailure:o,shouldForceMFA:!0},keyExport:{appId:g.id,appClientId:g.appClientId,origin:y.apiUrl,address:r.address,entropyId:x,entropyIdVerifier:W,hdWalletIndex:r.walletIndex,chainType:r.chainType,walletId:r.id,isUnifiedWallet:u,imported:r.imported,onSuccess:n,onFailure:o,showBackButton:e?.showBackButton}}),f("EmbeddedWalletConnectingScreen")):o(new a("Wallet not ready for export")):o(new a("Must have valid access token."))}))})),[t,l,m,f,y,h,g])}export{f as a,m as u};