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