UNPKG

@multiversx/sdk-dapp-swap

Version:

A library to hold the main logic for swapping between tokens on the MultiversX blockchain

3 lines (2 loc) 1.72 kB
import{a as y}from"./chunk-4XMIBGR3.js";import{a,d as f,f as d}from"./chunk-5W737WN4.js";d();import L,{useMemo as r}from"react";import{from as b,split as k,HttpLink as z,ApolloClient as R,InMemoryCache as C}from"@apollo/client";import{setContext as M}from"@apollo/client/link/context";import{onError as S}from"@apollo/client/link/error";import{WebSocketLink as $}from"@apollo/client/link/ws";import{getMainDefinition as x}from"@apollo/client/utilities";import{print as N}from"graphql";var j=({children:P,accessToken:i,graphQLAddress:n,getAuthorizationHeaders:s})=>{let e=r(()=>M((h,v)=>f(void 0,[h,v],function*(o,{headers:t}){let c={url:n,params:o==null?void 0:o.variables,body:{operationName:o==null?void 0:o.operationName,variables:o==null?void 0:o.variables,query:N(o==null?void 0:o.query)},method:"POST"},u=yield s==null?void 0:s(c),A=i?{Authorization:`Bearer ${i}`}:{};return{headers:a(a(a({},t),A),u)}})),[i]),l=r(()=>{let o=S(({graphQLErrors:t,networkError:h})=>{t&&t.forEach(({message:v,locations:c,path:u})=>{console.log(`[GraphQL error]: Message: ${v}, Location: ${c}, Path: ${u}`)}),h&&console.log(`[Network error]: ${h}`)});return b([o,new z({uri:n})])},[n]),m=r(()=>new $({uri:n.replace("https","wss"),options:{reconnect:!0}}),[]),p=r(()=>k(({query:o})=>{let t=x(o);return t.kind==="OperationDefinition"&&t.operation==="subscription"},m,e.concat(l)),[m,e,l]),w=r(()=>new R({cache:new C,link:e.concat(p),queryDeduplication:!1,defaultOptions:{watchQuery:{fetchPolicy:"no-cache",errorPolicy:"all"},query:{fetchPolicy:"no-cache",errorPolicy:"all"}}}),[e,p]);return L.createElement(y.Provider,{value:{client:w,accessToken:i,isAuthenticated:Boolean(i)}},P)};export{j as a}; //# sourceMappingURL=chunk-MO6AZ2GD.js.map