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-WTldtXS8.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,h as d,d as i,b as s}from"./get-is-unified-wallet-Boa8DYrQ.mjs";import{g as l,i as c}from"./use-export-wallet-CV4p7L0b.mjs";import{useMemo as u}from"react";import{g as p}from"./useWallets-CR0z5IIt.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: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:h}=n(),{setModalData:y}=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):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=s(r),{entropyId:W,entropyIdVerifier:w}=p(t,r);await l()?m?(y({connectWallet:{recoveryMethod:r.recoveryMethod,connectingWalletAddress:r.address,isUnifiedWallet:u,entropyId:W,entropyIdVerifier:w,onCompleteNavigateTo:"EmbeddedWalletKeyExportScreen",onFailure:o,shouldForceMFA:!0},keyExport:{appId:g.id,appClientId:g.appClientId,origin:h.apiUrl,address:r.address,entropyId:W,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,h,y,g])}export{f as a,m as u};