@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 2.51 kB
JavaScript
"use strict";var e=require("./context-D-ZJYjUg.js"),t=require("./events-context-Di6--rDg.js"),n=require("./internal-context-BJv4f_bO.js"),r=require("./get-is-unified-wallet-UpdjHxOV.js"),a=require("./use-export-wallet-B5ujV5Nk.js"),i=require("react"),o=require("./useWallets-CKAypPZB.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 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}=o.getEntropyDetailsForUser(t,f);await l()?s?(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,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")}}};