UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 2.33 kB
import{useCallback as e}from"react";import{ar as a,as as t,b as n,f as s,an as r,am as o,at as c,au as i}from"./privy-provider-L7_Cz9Ka.mjs";import{getAssociatedTokenAddressSync as l,createAssociatedTokenAccountIdempotentInstruction as d,createTransferInstruction as m}from"@solana/spl-token";import{Connection as u,PublicKey as p,Transaction as w,SystemProgram as f,TransactionInstruction as h,VersionedTransaction as k,TransactionMessage as y}from"@solana/web3.js";import{getSolanaRpcEndpointForCluster as g,SolanaClient as b}from"@privy-io/js-sdk-core";import{u as B}from"./internal-context-D5bEplez.mjs";var T={id:a,getBalance:({address:e,cluster:a})=>new u(g(a)).getBalance(new p(e)),getTokenBalance:async({address:e,cluster:a,mintAddress:t})=>await new b({...a,rpcUrl:g(a)}).getTokenAccountsByOwner(e,t)||{amount:BigInt(0),decimals:9},createTransferTransaction:async({from:e,to:a,amount:t,cluster:n})=>{let s=new p(e),r=new w;r.add(f.transfer({fromPubkey:s,toPubkey:new p(a),lamports:t}));let o=new u(g(n)),c=await o.getLatestBlockhash();return r.recentBlockhash=c.blockhash,r.feePayer=s,{transaction:r,connection:o}},createSplTransferTransaction:async({from:e,to:a,amount:t,cluster:n,mintAddress:s})=>{let r=new p(s),o=new p(e),c=new p(a),i=new w,f=l(r,o),h=l(r,c);i.add(d(o,h,c,r)),i.add(m(f,h,o,t));let k=new u(g(n)),y=await k.getLatestBlockhash();return i.recentBlockhash=y.blockhash,i.feePayer=o,{transaction:i,connection:k}},createBridgeTransactionFromRelayQuote:async({quote:e,from:a,cluster:n})=>{let s=e.steps[0]?.items?.[0];if(!s)return;let r=s.data.instructions.map((({keys:e,programId:a,data:n})=>new h({keys:e.map((({pubkey:e,isSigner:a,isWritable:t})=>({pubkey:new p(e),isSigner:a,isWritable:t}))),programId:new p(a),data:t(n,"hex")}))),o=s.data.addressLookupTableAddresses?.map((e=>new p(e))),c=new u(g(n)),i=await Promise.all((o??[]).map((async e=>c.getAddressLookupTable(e).then((e=>e.value))))),{blockhash:l}=await c.getLatestBlockhash();return{transaction:new k(new y({payerKey:new p(a),instructions:r,recentBlockhash:l}).compileToV0Message(i)),connection:c}}};const v=a=>{n("fundSolanaWallet",a);let t=s(),{setModalData:l}=r(),{openModal:d}=B();return o(T),{fundWallet:e((async(e,a)=>{l({funding:c({address:e,appConfig:t,fundWalletConfig:a,methodScreen:i})}),d(i)}),[t,l,d])}};export{T as t,v as u};