@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 2.48 kB
JavaScript
"use strict";var e=require("./context-DFq1obBO.js"),t=require("./events-context-Di6--rDg.js"),n=require("./internal-context-NWsAL807.js"),r=require("./get-is-unified-wallet-D4ouXJpi.js"),a=require("./prepareFundingModalData-Cnd6rhhJ.js"),i=require("react"),l=require("./useWallets-BLFNjTwC.js");exports.useExportWallet=function(){let{user:t,getAccessToken:o}=r.usePrivyContext(),{walletProxy:d,openModal:s,client:u}=n.usePrivyInternal(),{setModalData:c}=r.usePrivyModal(),p=e.useAppConfig();return i.useMemo((()=>({exportWallet:e=>new Promise((async(i,y)=>{if(!t)return void y(new n.PrivyClientError("User must be authenticated before exporting their Privy wallet"));let f=e?.address?r.getPrivyWalletWithAddress(t,e.address):r.getPrivySolanaWallet(t);if(!f)return void y(new n.PrivyClientError("User must have an embedded wallet."));if(!a.isFirstClassChainWallet(f))return void y(Error(`Export is not supported for ${f.chainType} wallets`));let v=r.getIsUnifiedWallet(f),{entropyId:g,entropyIdVerifier:W}=l.getEntropyDetailsForUser(t,f);await o()?d?(c({connectWallet:{recoveryMethod:f.recoveryMethod,connectingWalletAddress:f.address,isUnifiedWallet:v,entropyId:g,entropyIdVerifier:W,onCompleteNavigateTo:"EmbeddedWalletKeyExportScreen",onFailure:y,shouldForceMFA:!0},keyExport:{appId:p.id,appClientId:p.appClientId,origin:u.apiUrl,address:f.address,entropyId:g,entropyIdVerifier:W,hdWalletIndex:f.walletIndex,chainType:f.chainType,walletId:f.id,isUnifiedWallet:v,imported:f.imported,onSuccess:i,onFailure:y}}),s("EmbeddedWalletConnectingScreen")):y(new n.PrivyClientError("Wallet not ready for export")):y(new n.PrivyClientError("Must have valid access token."))}))})),[t,o,d,s,u,c,p])},exports.useFundWallet=function(i){t.usePrivyEventSubscription("fundSolanaWallet",i);let l=e.useAppConfig(),{openModal:o}=n.usePrivyInternal(),{setModalData:d}=r.usePrivyModal();return{fundWallet:async({address:e,options:t})=>{let n=t?.amount||l.fundingConfig?.defaultRecommendedAmount||"1",r=t?.asset||l.fundingConfig?.defaultRecommendedCurrency.asset||"native-currency",i=t?.chain||"solana:mainnet";d({funding:a.prepareSolanaFundingModalData({address:e,appConfig:l,methodScreen:"FundingMethodSelectionScreen",fundWalletConfig:{...t,amount:n,asset:r,chain:i},externalSolanaFundingScreen:"FundSolWalletWithExternalSolanaWallet"}),solanaFundingData:{amount:n,asset:"native-currency"===r?"SOL":"USDC",chain:i,destinationAddress:e,sourceWalletData:void 0}}),o("FundingMethodSelectionScreen")}}};