UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 6.68 kB
"use strict";var e=require("viem"),r=require("@privy-io/js-sdk-core"),n=require("./getPublicClient-CGlodIp_.js"),i=require("./getErc20Balance-DknCauCO.js"),a=require("react/jsx-runtime"),t=require("react"),o=require("./Button-Bm_Ft0Dw.js"),s=require("./Layouts-dRL0OSpp.js"),c=require("./ModalHeader-DB7Tbjwz.js"),l=require("./FundWalletMethodHeader-BKgYjMau.js"),d=require("./Row-CxDF-VMy.js"),u=require("./ErrorMessage-f0cRWc29.js"),m=require("./Value-C-XtZyFa.js"),h=require("./Subtitle-Dtmrw8l5.js"),p=require("./Title-C-tHJvrb.js"),g=require("@heroicons/react/24/outline/WalletIcon"),j=require("styled-components"),f=require("./getChainName-C4rO8-3n.js"),y=require("./Chip-ChrHHazc.js"),x=require("./NetworkIcon-BZ9Mj6vV.js"),b=require("./shared-BPGwTh8c.js"),C=require("@headlessui/react"),v=require("@heroicons/react/24/outline/ChevronDownIcon"),w=require("./formatErc20TokenAmount-DxwoWe7e.js"),q=require("./ethers-DZGJ4Y5i.js"),N=require("./styles-D4VeJNv1.js");function I(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var k=/*#__PURE__*/I(g),S=/*#__PURE__*/I(v);const B=({balance:e,className:r,chain:n})=>/*#__PURE__*/a.jsx(b.Box,{className:r,$state:void 0,children:/*#__PURE__*/a.jsx(F,{balance:e,chain:n})}),F=({balance:e,chain:r})=>/*#__PURE__*/a.jsxs(a.Fragment,{children:[/*#__PURE__*/a.jsxs(T,{children:[/*#__PURE__*/a.jsx(E,{chainId:"object"==typeof r?r.id:"solana"}),/*#__PURE__*/a.jsx(m.Value,{children:"object"==typeof r?r.name:f.getChainName(r)})]}),/*#__PURE__*/a.jsxs(y.Chip,{isLoading:!1,isPulsing:!1,color:"gray",children:[/*#__PURE__*/a.jsx(A,{children:/*#__PURE__*/a.jsx(k.default,{})}),e]})]});let T=/*#__PURE__*/j.styled.div.withConfig({displayName:"Container",componentId:"sc-63f80cee-0"})(["display:flex;align-items:center;"]),A=/*#__PURE__*/j.styled.div.withConfig({displayName:"IconContainer",componentId:"sc-63f80cee-1"})(["height:0.75rem;width:0.75rem;margin-right:0.2rem;"]),E=/*#__PURE__*/j.styled(x.NetworkIcon).withConfig({displayName:"StyledNetworkIcon",componentId:"sc-63f80cee-2"})(["height:1.25rem;width:1.25rem;display:inline-block;margin-right:0.5rem;border-radius:4px;"]);const M=({options:e,onSelect:r,selected:n,className:i})=>/*#__PURE__*/a.jsxs(C.Menu,{as:W,children:[/*#__PURE__*/a.jsxs(C.MenuButton,{as:L,children:[/*#__PURE__*/a.jsx(F,{balance:n.balance,chain:n.chain}),/*#__PURE__*/a.jsx($,{height:16})]}),/*#__PURE__*/a.jsx(C.MenuItems,{as:P,className:i,children:e.map(((e,n)=>/*#__PURE__*/a.jsx(C.MenuItem,{as:R,onClick:()=>r(n),children:/*#__PURE__*/a.jsx(F,{balance:e.balance,chain:e.chain})},n)))})]});let W=/*#__PURE__*/j.styled.div.withConfig({displayName:"Wrapper",componentId:"sc-31c00f79-0"})(["width:100%;position:relative;"]),P=/*#__PURE__*/j.styled.div.withConfig({displayName:"Popover",componentId:"sc-31c00f79-1"})(["width:100%;margin-top:0.5rem;position:absolute;background-color:var(--privy-color-background);border-radius:var(--privy-border-radius-md);overflow-x:hidden;overflow-y:auto;box-shadow:0px 1px 2px 0px rgba(16,24,40,0.05);max-height:11.75rem;&&{border:solid 1px var(--privy-color-foreground-4);}z-index:1;"]),R=/*#__PURE__*/j.styled.button.withConfig({displayName:"Button",componentId:"sc-31c00f79-2"})(["width:100%;display:flex;justify-content:space-between;&&{padding:1rem;}:not(:last-child){border-bottom:solid 1px var(--privy-color-foreground-4);}:hover{background:var(--privy-color-background-2);}"]),$=/*#__PURE__*/j.styled(S.default).withConfig({displayName:"StyledChevronIcon",componentId:"sc-31c00f79-3"})(["height:1rem;margin-left:0.5rem;"]),L=/*#__PURE__*/j.styled.button.withConfig({displayName:"StyledMenuButton",componentId:"sc-31c00f79-4"})([""," span{margin-left:auto;}","{transition:rotate 100ms ease-in;}&[aria-expanded='true']{","{rotate:-180deg;}}"],b.BoxStyles,$,$);exports.BridgeNetworkSelectionView=({displayName:e,errorMessage:n,configuredFundingChain:i,formattedBalance:g,fundingAmount:j,fundingCurrency:y,fundingAmountInUsd:x,options:b,selectedOption:C,isPreparing:v,isSubmitting:I,addressToFund:k,fundingWalletAddress:S,onSubmit:F,onSelect:T,onAmountChange:A,erc20ContractInfo:E})=>{let W=t.useRef(null);/*#__PURE__*/return a.jsxs(a.Fragment,{children:[/*#__PURE__*/a.jsx(l.t,{}),/*#__PURE__*/a.jsx(s.RefactorSpacerTop,{}),/*#__PURE__*/a.jsx(p.Title,{children:"Transfer from another network"}),/*#__PURE__*/a.jsxs(h.Subtitle,{children:["You need more funds on the"," ","object"==typeof i?i.name:f.getChainName(i)," ","network. Bridge from another blockchain network."]}),/*#__PURE__*/a.jsxs(N.FundingQuantityWrapper,{style:{marginTop:"2rem"},children:[/*#__PURE__*/a.jsxs(N.FundingQuantity,{onClick:()=>W.current?.focus(),children:[/*#__PURE__*/a.jsx(N.FundingAmountInput,{ref:W,value:j,onChange:e=>{let r=e.target.value;if(/^[0-9.]*$/.test(r)&&r.split(".").length-1<=1){let e=/\.$/.test(r)?".":"",n=Number(r.replace(/\.$/,"")||"0");if(Number.isNaN(n))return void A("0");A(n.toString()+e)}}}),/*#__PURE__*/a.jsx(N.FundingCurrency,{children:y})]}),x&&/*#__PURE__*/a.jsx(N.FundingDollars,{children:x})]}),/*#__PURE__*/a.jsxs(d.Row,{style:{marginTop:"1.5rem"},children:[/*#__PURE__*/a.jsx(m.LabelSm,{children:"From"}),/*#__PURE__*/a.jsx(m.LabelSm,{children:r.formatWalletAddress(S)})]}),/*#__PURE__*/a.jsx(M,{selected:{chain:C.chain,balance:C.isErc20Quote?w.formatErc20TokenAmount({amount:C.erc20Balance??0n,decimals:E?.decimals??6})+` ${E?.symbol||""}`:q.getNativeCurrencyFromWei(C.balance,C.chain.nativeCurrency.symbol,3,!0)},options:b.map((({chain:e,balance:r,isErc20Quote:n,erc20Balance:i})=>({chain:e,balance:n?w.formatErc20TokenAmount({amount:i??0n,decimals:E?.decimals??6})+` ${E?.symbol||""}`:q.getNativeCurrencyFromWei(r,e.nativeCurrency.symbol,3,!0)}))),onSelect:T}),/*#__PURE__*/a.jsxs(d.Row,{style:{marginTop:"1.5rem"},children:[/*#__PURE__*/a.jsx(m.LabelSm,{children:"To"}),/*#__PURE__*/a.jsx(m.LabelSm,{children:r.formatWalletAddress(k)})]}),/*#__PURE__*/a.jsx(B,{chain:i,balance:g}),/*#__PURE__*/a.jsx(u.ErrorMessage,{style:{marginTop:"1rem"},children:n}),/*#__PURE__*/a.jsxs(o.PrimaryButtonWithoutGray,{style:{marginTop:"1rem"},loading:I||v,disabled:v||I,onClick:F,children:["Confirm with ",e]}),/*#__PURE__*/a.jsx(s.RefactorSpacerBottom,{}),/*#__PURE__*/a.jsx(c.BlobbyFooter,{})]})},exports.getBalanceForChains=({chains:a,appId:t,address:o,rpcConfig:s,includeUsdc:c})=>Promise.all(a.map((async a=>{let l=e.createPublicClient({chain:a,transport:e.http(n.getJsonRpcEndpointFromChain(a,s,t))}),d=await l.getBalance({address:o}).catch((()=>0n)),u=null,m=r.UsdcAddressMap[a.id];if(c&&m){let{balance:e}=await i.getErc20Balance({address:o,chain:a,rpcConfig:s,appId:t,erc20Address:m});u=e}return{balance:d,erc20Balance:u,erc20Address:m,chain:a}})));