diff --git a/config/client.tsx b/config/client.tsx index 1c134117..198057fe 100644 --- a/config/client.tsx +++ b/config/client.tsx @@ -1,36 +1,29 @@ /* eslint @typescript-eslint/no-var-requires: 0 */ -import * as React from 'react'; -import Head from 'next/head'; -import { ApolloProvider } from '@apollo/react-hooks'; -import { ApolloClient } from 'apollo-client'; +import { IncomingMessage, ServerResponse } from 'http'; +import { useMemo } from 'react'; import { + ApolloClient, InMemoryCache, - IntrospectionFragmentMatcher, NormalizedCacheObject, -} from 'apollo-cache-inmemory'; +} from '@apollo/client'; import getConfig from 'next/config'; -import introspectionQueryResultData from 'src/graphql/fragmentTypes.json'; -import { SchemaLink } from 'apollo-link-schema'; -import { NextPage } from 'next'; - -const fragmentMatcher = new IntrospectionFragmentMatcher({ - introspectionQueryResultData, -}); - -let globalApolloClient: ReturnType | null = null; const { publicRuntimeConfig } = getConfig(); const { apiUrl: uri } = publicRuntimeConfig; -type Context = SchemaLink.ResolverContextFunction | Record; +let apolloClient: ReturnType | null = null; -function createIsomorphLink(ctx: Context) { +function createIsomorphLink(req?: IncomingMessage, res?: ServerResponse) { if (typeof window === 'undefined') { - const schema = require('server/schema'); - return new SchemaLink({ schema, context: ctx }); + const { SchemaLink } = require('@apollo/client/link/schema'); + const { schema } = require('server/schema'); + const { getContext } = require('server/schema/context'); + return new SchemaLink({ + schema, + context: req && res ? getContext(req, res) : {}, + }); } else { - const { HttpLink } = require('apollo-link-http'); - + const { HttpLink } = require('@apollo/client/link/http'); return new HttpLink({ uri, credentials: 'same-origin', @@ -38,147 +31,38 @@ function createIsomorphLink(ctx: Context) { } } -/** - * Creates and configures the ApolloClient - */ -function createApolloClient( - ctx: Context = {}, - initialState: NormalizedCacheObject = {} -) { - const ssrMode = typeof window === 'undefined'; - const cache = new InMemoryCache({ fragmentMatcher }).restore(initialState); - - // Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient +function createApolloClient(req?: IncomingMessage, res?: ServerResponse) { return new ApolloClient({ - ssrMode, - link: createIsomorphLink(ctx), - cache, + credentials: 'same-origin', + ssrMode: typeof window === 'undefined', + link: createIsomorphLink(req, res), + cache: new InMemoryCache({ + possibleTypes: { Transaction: ['InvoiceType', 'PaymentType'] }, + }), }); } -/** - * Always creates a new apollo client on the server - * Creates or reuses apollo client in the browser. - */ -function initApolloClient(ctx?: Context, initialState?: NormalizedCacheObject) { - // Make sure to create a new client for every server-side request so that data - // isn't shared between connections (which would be bad) - if (typeof window === 'undefined') { - return createApolloClient(ctx, initialState); - } - - // Reuse client on the client-side - if (!globalApolloClient) { - globalApolloClient = createApolloClient(ctx, initialState); - } - - return globalApolloClient; -} - -interface WithApolloProps { - apolloClient?: ApolloClient; - apolloState?: NormalizedCacheObject; -} - -interface WithApolloOptions { - ssr?: boolean; -} - -/** - * Creates and provides the apolloContext - * to a next.js PageTree. Use it by wrapping - * your PageComponent via HOC pattern. - */ -export function withApollo( - PageComponent: NextPage, - { ssr }: WithApolloOptions = { ssr: true } +export function initializeApollo( + initialState: NormalizedCacheObject | null = null, + req?: IncomingMessage, + res?: ServerResponse ) { - const WithApollo: NextPage = ({ - apolloClient, - apolloState, - ...pageProps - }) => { - const client = apolloClient || initApolloClient(undefined, apolloState); - return ( - - - - ); - }; + const _apolloClient = apolloClient ?? createApolloClient(req, res); - // Set the correct displayName in development - if (process.env.NODE_ENV !== 'production') { - const displayName = - PageComponent.displayName || PageComponent.name || 'Component'; - - if (displayName === 'App') { - console.warn('This withApollo HOC only works with PageComponents.'); - } - - WithApollo.displayName = `withApollo(${displayName})`; + // If your page has Next.js data fetching methods that use Apollo Client, the initial state + // get hydrated here + if (initialState) { + _apolloClient.cache.restore(initialState); } + // For SSG and SSR always create a new Apollo Client + if (typeof window === 'undefined') return _apolloClient; + // Create the Apollo Client once in the client + if (!apolloClient) apolloClient = _apolloClient; - if (ssr || PageComponent.getInitialProps) { - WithApollo.getInitialProps = async (ctx): Promise => { - const { AppTree } = ctx; - - // Initialize ApolloClient, add it to the ctx object so - // we can use it in `PageComponent.getInitialProp`. - const apolloClient = initApolloClient({ - res: ctx.res, - req: ctx.req, - }); - (ctx as any).apolloClient = apolloClient; - - // Run wrapped getInitialProps methods - let pageProps = {}; - if (PageComponent.getInitialProps) { - pageProps = await PageComponent.getInitialProps(ctx); - } - - // Only on the server: - if (typeof window === 'undefined') { - // When redirecting, the response is finished. - // No point in continuing to render - if (ctx.res && ctx.res.finished) { - return pageProps as WithApolloProps; - } - - // Only if ssr is enabled - if (ssr) { - try { - // Run all GraphQL queries - const { getDataFromTree } = await import('@apollo/react-ssr'); - await getDataFromTree( - - ); - } catch (error) { - // Prevent Apollo Client GraphQL errors from crashing SSR. - // Handle them in components via the data.error prop: - // https://www.apollographql.com/docs/react/api/react-apollo.html#graphql-query-data-error - console.error('Error while running `getDataFromTree`', error); - } - - // getDataFromTree does not call componentWillUnmount - // head side effect therefore need to be cleared manually - Head.rewind(); - } - } - - // Extract query data from the Apollo store - const apolloState = apolloClient.cache.extract(); - - return { - ...pageProps, - apolloState, - }; - }; - } - - return WithApollo; + return _apolloClient; +} + +export function useApollo(initialState: NormalizedCacheObject | null) { + const store = useMemo(() => initializeApollo(initialState), [initialState]); + return store; } diff --git a/next.config.js b/next.config.js index 5cb81782..d1261f76 100644 --- a/next.config.js +++ b/next.config.js @@ -28,7 +28,6 @@ module.exports = withBundleAnalyzer({ fetchFees: process.env.FETCH_FEES === 'false' ? false : true, hodlhodl: process.env.HODL_HODL === 'false' ? false : true, disableLinks: process.env.DISABLE_LINKS === 'true' ? true : false, - noClient: process.env.NO_CLIENT_ACCOUNTS === 'true' ? true : false, noVersionCheck: process.env.NO_VERSION_CHECK === 'true' ? true : false, }, }); diff --git a/package-lock.json b/package-lock.json index 30b05050..0e1b8f2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -143,6 +143,56 @@ "cross-fetch": "3.0.4" } }, + "@apollo/client": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.1.1.tgz", + "integrity": "sha512-c5DxrU81p0B5BsyBXm+5uPJqLCX2epnBsd87PXfRwzDLbp/NiqnWp6a6c5vT5EV2LwJuCq1movmKthoy0gFb0w==", + "requires": { + "@types/zen-observable": "^0.8.0", + "@wry/context": "^0.5.2", + "@wry/equality": "^0.2.0", + "fast-json-stable-stringify": "^2.0.0", + "graphql-tag": "^2.11.0", + "hoist-non-react-statics": "^3.3.2", + "optimism": "^0.12.1", + "prop-types": "^15.7.2", + "symbol-observable": "^1.2.0", + "ts-invariant": "^0.4.4", + "tslib": "^1.10.0", + "zen-observable": "^0.8.14" + }, + "dependencies": { + "@wry/context": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@wry/context/-/context-0.5.2.tgz", + "integrity": "sha512-B/JLuRZ/vbEKHRUiGj6xiMojST1kHhu4WcreLfNN7q9DqQFrb97cWgf/kiYsPSUCAMVN0HzfFc8XjJdzgZzfjw==", + "requires": { + "tslib": "^1.9.3" + } + }, + "@wry/equality": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@wry/equality/-/equality-0.2.0.tgz", + "integrity": "sha512-Y4d+WH6hs+KZJUC8YKLYGarjGekBrhslDbf/R20oV+AakHPINSitHfDRQz3EGcEWc1luXYNUvMhawWtZVWNGvQ==", + "requires": { + "tslib": "^1.9.3" + } + }, + "graphql-tag": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.11.0.tgz", + "integrity": "sha512-VmsD5pJqWJnQZMUeRwrDhfgoyqcfwEkvtpANqcoUG8/tOLkwNgU9mzub/Mc78OJMhHjx7gfAMTxzdG43VGg3bA==" + }, + "optimism": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/optimism/-/optimism-0.12.1.tgz", + "integrity": "sha512-t8I7HM1dw0SECitBYAqFOVHoBAHEQBTeKjIL9y9ImHzAVkdyPK4ifTgM4VJRDtTUY4r/u5Eqxs4XcGPHaoPkeQ==", + "requires": { + "@wry/context": "^0.5.2" + } + } + } + }, "@apollo/protobufjs": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@apollo/protobufjs/-/protobufjs-1.0.4.tgz", @@ -170,36 +220,6 @@ } } }, - "@apollo/react-common": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/@apollo/react-common/-/react-common-3.1.4.tgz", - "integrity": "sha512-X5Kyro73bthWSCBJUC5XYQqMnG0dLWuDZmVkzog9dynovhfiVCV4kPSdgSIkqnb++cwCzOVuQ4rDKVwo2XRzQA==", - "requires": { - "ts-invariant": "^0.4.4", - "tslib": "^1.10.0" - } - }, - "@apollo/react-hooks": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/@apollo/react-hooks/-/react-hooks-3.1.5.tgz", - "integrity": "sha512-y0CJ393DLxIIkksRup4nt+vSjxalbZBXnnXxYbviq/woj+zKa431zy0yT4LqyRKpFy9ahMIwxBnBwfwIoupqLQ==", - "requires": { - "@apollo/react-common": "^3.1.4", - "@wry/equality": "^0.1.9", - "ts-invariant": "^0.4.4", - "tslib": "^1.10.0" - } - }, - "@apollo/react-ssr": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/@apollo/react-ssr/-/react-ssr-3.1.5.tgz", - "integrity": "sha512-wuLPkKlctNn3u8EU8rlECyktpOUCeekFfb0KhIKknpGY6Lza2Qu0bThx7D9MIbVEzhKadNNrzLcpk0Y8/5UuWg==", - "requires": { - "@apollo/react-common": "^3.1.4", - "@apollo/react-hooks": "^3.1.5", - "tslib": "^1.10.0" - } - }, "@apollographql/apollo-tools": { "version": "0.4.8", "resolved": "https://registry.npmjs.org/@apollographql/apollo-tools/-/apollo-tools-0.4.8.tgz", @@ -4834,12 +4854,6 @@ "@types/express": "*" } }, - "@types/crypto-js": { - "version": "3.1.47", - "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-3.1.47.tgz", - "integrity": "sha512-eI6gvpcGHLk3dAuHYnRCAjX+41gMv1nz/VP55wAe5HtmAKDOoPSfr3f6vkMc08ov1S0NsjvUBxDtHHxqQY1LGA==", - "dev": true - }, "@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", @@ -5303,12 +5317,6 @@ "resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.0.tgz", "integrity": "sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg==" }, - "@types/zxcvbn": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.0.tgz", - "integrity": "sha512-GQLOT+SN20a+AI51y3fAimhyTF4Y0RG+YP3gf91OibIZ7CJmPFgoZi+ZR5a+vRbS01LbQosITWum4ATmJ1Z6Pg==", - "dev": true - }, "@typescript-eslint/eslint-plugin": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.6.0.tgz", @@ -5583,15 +5591,6 @@ "@xtuc/long": "4.2.2" } }, - "@wry/context": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/@wry/context/-/context-0.4.4.tgz", - "integrity": "sha512-LrKVLove/zw6h2Md/KZyWxIkFM6AoyKp71OqpH9Hiip1csjPVoD3tPxlbQUNxEnHENks3UGgNpSBCAfq9KWuag==", - "requires": { - "@types/node": ">=6", - "tslib": "^1.9.3" - } - }, "@wry/equality": { "version": "0.1.11", "resolved": "https://registry.npmjs.org/@wry/equality/-/equality-0.1.11.tgz", @@ -5897,15 +5896,6 @@ } } }, - "apollo-cache": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/apollo-cache/-/apollo-cache-1.3.5.tgz", - "integrity": "sha512-1XoDy8kJnyWY/i/+gLTEbYLnoiVtS8y7ikBr/IfmML4Qb+CM7dEEbIUOjnY716WqmZ/UpXIxTfJsY7rMcqiCXA==", - "requires": { - "apollo-utilities": "^1.3.4", - "tslib": "^1.10.0" - } - }, "apollo-cache-control": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/apollo-cache-control/-/apollo-cache-control-0.11.1.tgz", @@ -5916,33 +5906,6 @@ "apollo-server-plugin-base": "^0.9.1" } }, - "apollo-cache-inmemory": { - "version": "1.6.6", - "resolved": "https://registry.npmjs.org/apollo-cache-inmemory/-/apollo-cache-inmemory-1.6.6.tgz", - "integrity": "sha512-L8pToTW/+Xru2FFAhkZ1OA9q4V4nuvfoPecBM34DecAugUZEBhI2Hmpgnzq2hTKZ60LAMrlqiASm0aqAY6F8/A==", - "requires": { - "apollo-cache": "^1.3.5", - "apollo-utilities": "^1.3.4", - "optimism": "^0.10.0", - "ts-invariant": "^0.4.0", - "tslib": "^1.10.0" - } - }, - "apollo-client": { - "version": "2.6.10", - "resolved": "https://registry.npmjs.org/apollo-client/-/apollo-client-2.6.10.tgz", - "integrity": "sha512-jiPlMTN6/5CjZpJOkGeUV0mb4zxx33uXWdj/xQCfAMkuNAC3HN7CvYDyMHHEzmcQ5GV12LszWoQ/VlxET24CtA==", - "requires": { - "@types/zen-observable": "^0.8.0", - "apollo-cache": "1.3.5", - "apollo-link": "^1.0.0", - "apollo-utilities": "1.3.4", - "symbol-observable": "^1.0.2", - "ts-invariant": "^0.4.0", - "tslib": "^1.10.0", - "zen-observable": "^0.8.0" - } - }, "apollo-datasource": { "version": "0.7.2", "resolved": "https://registry.npmjs.org/apollo-datasource/-/apollo-datasource-0.7.2.tgz", @@ -6010,35 +5973,6 @@ "zen-observable-ts": "^0.8.21" } }, - "apollo-link-http": { - "version": "1.5.17", - "resolved": "https://registry.npmjs.org/apollo-link-http/-/apollo-link-http-1.5.17.tgz", - "integrity": "sha512-uWcqAotbwDEU/9+Dm9e1/clO7hTB2kQ/94JYcGouBVLjoKmTeJTUPQKcJGpPwUjZcSqgYicbFqQSoJIW0yrFvg==", - "requires": { - "apollo-link": "^1.2.14", - "apollo-link-http-common": "^0.2.16", - "tslib": "^1.9.3" - } - }, - "apollo-link-http-common": { - "version": "0.2.16", - "resolved": "https://registry.npmjs.org/apollo-link-http-common/-/apollo-link-http-common-0.2.16.tgz", - "integrity": "sha512-2tIhOIrnaF4UbQHf7kjeQA/EmSorB7+HyJIIrUjJOKBgnXwuexi8aMecRlqTIDWcyVXCeqLhUnztMa6bOH/jTg==", - "requires": { - "apollo-link": "^1.2.14", - "ts-invariant": "^0.4.0", - "tslib": "^1.9.3" - } - }, - "apollo-link-schema": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/apollo-link-schema/-/apollo-link-schema-1.2.5.tgz", - "integrity": "sha512-7XUS8fOsObJt9rzp8CUuZ/a9TNUBoChWwEDmdVmYxTlzgGcyUXxkLXkMS9CHUb0cx04jiiWjWQc41C4iakSmzA==", - "requires": { - "apollo-link": "^1.2.14", - "tslib": "^1.9.3" - } - }, "apollo-server": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/apollo-server/-/apollo-server-2.15.1.tgz", @@ -7603,11 +7537,6 @@ "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" }, - "base64url": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", - "integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==" - }, "basic-auth": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", @@ -20530,14 +20459,6 @@ "integrity": "sha512-goYSy5c2UXE4Ra1xixabeVh1guIX/ZV/YokJksb6q2lubWu6UbvPQ20p542/sFIll1nl8JnCyK9oBaOcCWXwvA==", "dev": true }, - "optimism": { - "version": "0.10.3", - "resolved": "https://registry.npmjs.org/optimism/-/optimism-0.10.3.tgz", - "integrity": "sha512-9A5pqGoQk49H6Vhjb9kPgAeeECfUDF6aIICbMDL23kDLStBn1MWk3YvcZ4xWF9CsSf6XEgvRLkXy4xof/56vVw==", - "requires": { - "@wry/context": "^0.4.0" - } - }, "optionator": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", @@ -26674,11 +26595,6 @@ "tslib": "^1.9.3", "zen-observable": "^0.8.0" } - }, - "zxcvbn": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/zxcvbn/-/zxcvbn-4.4.2.tgz", - "integrity": "sha1-KOwXzwl0PtyrBW3dixsGJizHPDA=" } } } diff --git a/package.json b/package.json index 34786872..2ec4a317 100644 --- a/package.json +++ b/package.json @@ -5,22 +5,22 @@ "main": "index.js", "scripts": { "bs": "yarn build && yarn start", - "dev": "cross-env NODE_OPTIONS='--insecure-http-parser' next", + "dev": "next", "dev:compatible": "next", "build": "next build", - "start": "cross-env NODE_OPTIONS='--insecure-http-parser' next start", - "start:two": "cross-env NODE_OPTIONS='--insecure-http-parser' next start -p 3001", + "start": "next start", + "start:two": "next start -p 3001", "start:compatible": "next start", "start:compatible:two": "next start -p 3001", "start:cookie": "sh ./scripts/initCookie.sh", - "lint": "eslint */**/*.{js,ts,tsx} --fix", - "prettier": "prettier --write **/*.{ts,tsx,js,css,html}", + "lint": "eslint . --ext ts --ext tsx --ext js", + "format": "prettier --write \"**/*.{js,ts,tsx}\"", "release": "standard-version --sign", "release:push": "standard-version --sign && git push --follow-tags origin master", "release:test": "standard-version --sign --dry-run", "release:minor": "standard-version --sign --release-as minor && git push --follow-tags origin master", "analyze": "cross-env ANALYZE=true next build", - "generate": "graphql-codegen --config codegen.yml && yarn lint", + "generate": "graphql-codegen --config codegen.yml && yarn format", "test": "jest", "test:watch": "jest --watch", "test:coverage": "jest --coverage", @@ -37,25 +37,15 @@ "author": "", "license": "MIT", "dependencies": { - "@apollo/react-common": "^3.1.4", - "@apollo/react-hooks": "^3.1.5", - "@apollo/react-ssr": "^3.1.5", - "apollo-cache-inmemory": "^1.6.6", - "apollo-client": "^2.6.10", - "apollo-link-http": "^1.5.17", - "apollo-link-schema": "^1.2.5", + "@apollo/client": "^3.1.1", "apollo-server-micro": "^2.15.1", - "apollo-utilities": "^1.3.4", "balanceofsatoshis": "^5.40.2", - "base64url": "^3.0.1", "bcryptjs": "^2.4.3", "cookie": "^0.4.1", - "crypto-js": "^4.0.0", "date-fns": "^2.14.0", "graphql": "^15.3.0", "graphql-iso-date": "^3.6.1", "graphql-rate-limit": "^2.0.1", - "graphql-tag": "^2.10.4", "intersection-observer": "^0.11.0", "js-cookie": "^2.2.1", "js-yaml": "^3.14.0", @@ -84,8 +74,7 @@ "underscore": "^1.10.2", "uuid": "^8.2.0", "victory": "^35.0.3", - "winston": "^3.3.3", - "zxcvbn": "^4.4.2" + "winston": "^3.3.3" }, "devDependencies": { "@babel/core": "^7.10.4", @@ -104,7 +93,6 @@ "@testing-library/react": "^10.4.5", "@types/bcryptjs": "^2.4.2", "@types/cookie": "^0.4.0", - "@types/crypto-js": "^3.1.47", "@types/graphql-iso-date": "^3.4.0", "@types/js-cookie": "^2.2.6", "@types/js-yaml": "^3.12.5", @@ -123,7 +111,6 @@ "@types/styled-theming": "^2.2.4", "@types/underscore": "^1.10.9", "@types/uuid": "^8.0.0", - "@types/zxcvbn": "^4.4.0", "@typescript-eslint/eslint-plugin": "^3.6.0", "@typescript-eslint/parser": "^3.6.0", "apollo-server": "^2.15.1", @@ -143,7 +130,6 @@ "eslint-plugin-prettier": "^3.1.4", "eslint-plugin-react": "^7.20.3", "eslint-plugin-react-hooks": "^4.0.7", - "fast-diff": "^1.2.0", "husky": "^4.2.5", "jest": "^26.1.0", "jest-fetch-mock": "^3.0.3", diff --git a/pages/_app.tsx b/pages/_app.tsx index 15bf052c..49872f2a 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -4,8 +4,9 @@ import { ModalProvider, BaseModalBackground } from 'styled-react-modal'; import { useRouter } from 'next/router'; import Head from 'next/head'; import { StyledToastContainer } from 'src/components/toastContainer/ToastContainer'; -import { NextPage } from 'next'; import { AppProps } from 'next/app'; +import { ApolloProvider } from '@apollo/client'; +import { useApollo } from 'config/client'; import { ContextProvider } from '../src/context/ContextProvider'; import { useConfigState, ConfigProvider } from '../src/context/ConfigContext'; import { GlobalStyles } from '../src/styles/GlobalStyle'; @@ -13,7 +14,6 @@ import { Header } from '../src/layouts/header/Header'; import { Footer } from '../src/layouts/footer/Footer'; import 'react-toastify/dist/ReactToastify.min.css'; import { PageWrapper, HeaderBodyWrapper } from '../src/layouts/Layout.styled'; -import { parseCookies } from '../src/utils/cookies'; import 'react-circular-progressbar/dist/styles.css'; const Wrapper: React.FC = ({ children }) => { @@ -38,46 +38,21 @@ const Wrapper: React.FC = ({ children }) => { ); }; -type InitialProps = { initialConfig: string }; -type MyAppProps = InitialProps & AppProps; - -const App: NextPage = ({ - Component, - pageProps, - initialConfig, -}) => ( - <> - - ThunderHub - Lightning Node Manager - - - - - - - - - - -); - -/* - * Props should be NextPageContext but something wierd - * happens and the context object received is not this - * type. - */ -App.getInitialProps = async ({ ctx }: any) => { - const cookies = parseCookies(ctx?.req); - - if (!cookies?.theme) { - return { initialConfig: 'dark' }; - } - try { - const initialConfig = cookies.theme || 'dark'; - return { initialConfig }; - } catch (error) { - return { initialConfig: 'dark' }; - } -}; - -export default App; +export default function App({ Component, pageProps }: AppProps) { + const apolloClient = useApollo(pageProps.initialApolloState); + return ( + + + ThunderHub - Lightning Node Manager + + + + + + + + + + + ); +} diff --git a/pages/api/v1.tsx b/pages/api/v1.tsx index 3b0c253e..9db63bae 100644 --- a/pages/api/v1.tsx +++ b/pages/api/v1.tsx @@ -1,98 +1,24 @@ import crypto from 'crypto'; import { ApolloServer } from 'apollo-server-micro'; -import { getIp } from 'server/helpers/helpers'; import getConfig from 'next/config'; -import jwt from 'jsonwebtoken'; -import { logger } from 'server/helpers/logger'; -import { - readMacaroons, - readFile, - readCookie, - getAccounts, -} from 'server/helpers/fileHelpers'; -import { ContextType, SSOType } from 'server/types/apiTypes'; -import cookie from 'cookie'; -import schema from 'server/schema'; +import { readCookie } from 'server/helpers/fileHelpers'; +import { schema } from 'server/schema'; +import { getContext } from 'server/schema/context'; const { publicRuntimeConfig, serverRuntimeConfig } = getConfig(); const { apiBaseUrl, nodeEnv } = publicRuntimeConfig; -const { - cookiePath, - macaroonPath, - lnCertPath, - lnServerUrl, - accountConfigPath, -} = serverRuntimeConfig; +const { cookiePath } = serverRuntimeConfig; -const secret = +export const secret = nodeEnv === 'development' ? '123456789' : crypto.randomBytes(64).toString('hex'); -const ssoMacaroon = readMacaroons(macaroonPath); -const ssoCert = readFile(lnCertPath); -const accountConfig = getAccounts(accountConfigPath); - -let ssoAccount: SSOType | null = null; - -if (ssoMacaroon && lnServerUrl) { - ssoAccount = { - macaroon: ssoMacaroon, - host: lnServerUrl, - cert: ssoCert, - }; -} - readCookie(cookiePath); const apolloServer = new ApolloServer({ schema, - context: ({ req, res }) => { - const ip = getIp(req); - - const { AccountAuth, SSOAuth } = cookie.parse(req.headers.cookie ?? ''); - - let ssoVerified = false; - if (SSOAuth) { - logger.silly('SSOAuth cookie found in request'); - if (nodeEnv === 'development') { - ssoVerified = true; - } - try { - jwt.verify(SSOAuth, secret); - ssoVerified = true; - } catch (error) { - logger.silly('SSO authentication cookie failed'); - } - } - - let account = ''; - if (AccountAuth) { - logger.silly('AccountAuth cookie found in request'); - try { - const cookieAccount = jwt.verify(AccountAuth, secret); - if (typeof cookieAccount === 'object') { - account = (cookieAccount as { id?: string })['id'] ?? ''; - } else { - account = cookieAccount; - } - } catch (error) { - logger.silly('Account authentication cookie failed'); - } - } - - const context: ContextType = { - ip, - secret, - ssoVerified, - account, - sso: ssoVerified ? ssoAccount : null, - accounts: accountConfig, - res, - }; - - return context; - }, + context: ({ req, res }) => getContext(req, res), }); export const config = { diff --git a/pages/chain.tsx b/pages/chain.tsx index 2cba2575..18e1e895 100644 --- a/pages/chain.tsx +++ b/pages/chain.tsx @@ -1,7 +1,9 @@ import React from 'react'; - import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_CHAIN_TRANSACTIONS } from 'src/graphql/queries/getChainTransactions'; +import { GET_UTXOS } from 'src/graphql/queries/getUtxos'; import { ChainTransactions } from '../src/views/chain/transactions/ChainTransactions'; import { ChainUtxos } from '../src/views/chain/utxos/ChainUtxos'; @@ -20,4 +22,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_CHAIN_TRANSACTIONS, GET_UTXOS]); +} diff --git a/pages/channels.tsx b/pages/channels.tsx index 10ff4bb1..ba4b347f 100644 --- a/pages/channels.tsx +++ b/pages/channels.tsx @@ -1,12 +1,13 @@ import React, { useState, useEffect } from 'react'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetChannelAmountInfoQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; import styled from 'styled-components'; import { Settings } from 'react-feather'; import { IconCursor } from 'src/views/channels/channels/Channel.style'; import { ChannelManage } from 'src/views/channels/channels/ChannelManage'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; +import { NextPageContext } from 'next'; +import { GET_CHANNELS } from 'src/graphql/queries/getChannels'; +import { getProps } from 'src/utils/ssr'; import { Channels } from '../src/views/channels/channels/Channels'; import { PendingChannels } from '../src/views/channels/pendingChannels/PendingChannels'; import { ClosedChannels } from '../src/views/channels/closedChannels/ClosedChannels'; @@ -41,12 +42,7 @@ const ChannelView = () => { closed: 0, }); - const { auth } = useAccountState(); - - const { data } = useGetChannelAmountInfoQuery({ - skip: !auth, - variables: { auth }, - }); + const { data } = useGetChannelAmountInfoQuery(); useEffect(() => { if (data && data.getNodeInfo) { @@ -119,4 +115,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_CHANNELS]); +} diff --git a/pages/chat.tsx b/pages/chat.tsx index b6346013..560d2c95 100644 --- a/pages/chat.tsx +++ b/pages/chat.tsx @@ -2,9 +2,11 @@ import * as React from 'react'; import styled from 'styled-components'; import { Users } from 'react-feather'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import { ChatInit } from 'src/components/chat/ChatInit'; import { ChatFetcher } from 'src/components/chat/ChatFetcher'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_MESSAGES } from 'src/graphql/queries/getMessages'; import { useChatState } from '../src/context/ChatContext'; import { separateBySender, getSenders } from '../src/utils/chat'; import { @@ -126,4 +128,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_MESSAGES]); +} diff --git a/pages/details.tsx b/pages/details.tsx index 9fb49998..83f452ac 100644 --- a/pages/details.tsx +++ b/pages/details.tsx @@ -1,15 +1,17 @@ import React, { useState } from 'react'; import { toast } from 'react-toastify'; import { ChevronRight, ChevronUp, ChevronDown } from 'react-feather'; -import { useAccountState } from 'src/context/AccountContext'; import { useChannelFeesQuery } from 'src/graphql/queries/__generated__/getChannelFees.generated'; import { useUpdateFeesMutation } from 'src/graphql/mutations/__generated__/updateFees.generated'; import { InputWithDeco } from 'src/components/input/InputWithDeco'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import styled from 'styled-components'; import { useStatusState } from 'src/context/StatusContext'; import { ChannelFeeType } from 'src/graphql/types'; +import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { CHANNEL_FEES } from 'src/graphql/queries/getChannelFees'; import { Card, CardWithTitle, @@ -22,8 +24,6 @@ import { import { getErrorContent } from '../src/utils/error'; import { LoadingCard } from '../src/components/loading/LoadingCard'; import { FeeCard } from '../src/views/fees/FeeCard'; -import { SecureButton } from '../src/components/buttons/secureButton/SecureButton'; -import { AdminSwitch } from '../src/components/adminSwitch/AdminSwitch'; const WithPointer = styled.div` cursor: pointer; @@ -43,11 +43,7 @@ const FeesView = () => { const [max, setMax] = useState(0); const [min, setMin] = useState(0); - const { auth } = useAccountState(); - const { loading, data } = useChannelFeesQuery({ - skip: !auth, - variables: { auth }, onError: error => toast.error(getErrorContent(error)), }); @@ -73,95 +69,101 @@ const FeesView = () => { return ( <> - - - - setIsEdit(prev => !prev)}> - Update All Channel Details - {isEdit ? : } - - - {isEdit && ( - <> - + + + setIsEdit(prev => !prev)}> + Update All Channel Details + {isEdit ? : } + + + {isEdit && ( + <> + + setBaseFee(Number(value))} + /> + setFeeRate(Number(value))} + /> + setCLTV(Number(value))} + /> + {canMax && ( setBaseFee(Number(value))} + inputCallback={value => setMax(Number(value))} /> + )} + {canMin && ( setFeeRate(Number(value))} + inputCallback={value => setMin(Number(value))} /> - setCLTV(Number(value))} - /> - {canMax && ( - setMax(Number(value))} - /> - )} - {canMin && ( - setMin(Number(value))} - /> - )} - - - Update Fees - - - - - )} - - + )} + + + updateFees({ + variables: { + ...(baseFee !== 0 && { base_fee_tokens: baseFee }), + ...(feeRate !== 0 && { fee_rate: feeRate }), + ...(cltv !== 0 && { cltv_delta: cltv }), + ...(max !== 0 && + canMax && { + max_htlc_mtokens: (max * 1000).toString(), + }), + ...(min !== 0 && + canMin && { + min_htlc_mtokens: (min * 1000).toString(), + }), + }, + }) + } + disabled={ + baseFee === 0 && + feeRate === 0 && + cltv === 0 && + max === 0 && + min === 0 + } + fullWidth={true} + withMargin={'16px 0 0'} + > + Update Fees + + + + + )} + + Channel Details @@ -186,4 +188,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [CHANNEL_FEES]); +} diff --git a/pages/forwards.tsx b/pages/forwards.tsx index dcaa1588..0de60934 100644 --- a/pages/forwards.tsx +++ b/pages/forwards.tsx @@ -1,10 +1,11 @@ import React, { useState } from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetForwardsQuery } from 'src/graphql/queries/__generated__/getForwards.generated'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import { ForwardType } from 'src/graphql/types'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_FORWARDS } from 'src/graphql/queries/getForwards'; import { SubTitle, Card, @@ -29,11 +30,8 @@ const ForwardsView = () => { const [time, setTime] = useState('week'); const [indexOpen, setIndexOpen] = useState(0); - const { auth } = useAccountState(); - const { loading, data } = useGetForwardsQuery({ - skip: !auth, - variables: { auth, time }, + variables: { time }, onError: error => toast.error(getErrorContent(error)), }); @@ -89,4 +87,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_FORWARDS]); +} diff --git a/pages/home.tsx b/pages/home.tsx index fc594d62..7393f9fd 100644 --- a/pages/home.tsx +++ b/pages/home.tsx @@ -1,7 +1,9 @@ import React from 'react'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import { Version } from 'src/components/version/Version'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_NODE_INFO } from 'src/graphql/queries/getNodeInfo'; import { NetworkInfo } from '../src/views/home/networkInfo/NetworkInfo'; import { AccountInfo } from '../src/views/home/account/AccountInfo'; import { QuickActions } from '../src/views/home/quickActions/QuickActions'; @@ -9,14 +11,12 @@ import { FlowBox } from '../src/views/home/reports/flow'; import { ForwardBox } from '../src/views/home/reports/forwardReport'; import { LiquidReport } from '../src/views/home/reports/liquidReport/LiquidReport'; import { ConnectCard } from '../src/views/home/connect/Connect'; -import { NodeBar } from '../src/components/nodeInfo/NodeBar'; const HomeView = () => { return ( <> - @@ -33,4 +33,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_NODE_INFO]); +} diff --git a/pages/index.tsx b/pages/index.tsx index 8768186e..6d6d213c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,44 +1,22 @@ import * as React from 'react'; import { Spacer } from 'src/components/spacer/Spacer'; -import { withApollo } from 'config/client'; import { ServerAccounts } from 'src/components/accounts/ServerAccounts'; -import { useAccountState } from 'src/context/AccountContext'; -import getConfig from 'next/config'; import { ThunderStorm } from 'src/views/homepage/HomePage.styled'; import { appendBasePath } from 'src/utils/basePath'; -import { SessionLogin } from '../src/views/login/SessionLogin'; +import { NextPageContext } from 'next'; +import { GET_SERVER_ACCOUNTS } from 'src/graphql/queries/getServerAccounts'; +import { getProps } from 'src/utils/ssr'; import { TopSection } from '../src/views/homepage/Top'; -import { LoginBox } from '../src/views/homepage/LoginBox'; import { Accounts } from '../src/views/homepage/Accounts'; -import { LoadingCard } from '../src/components/loading/LoadingCard'; -import { Section } from '../src/components/section/Section'; -const { publicRuntimeConfig } = getConfig(); -const { noClient } = publicRuntimeConfig; - -const ContextApp = () => { - const { finishedFetch } = useAccountState(); - - return ( - <> - - - {!finishedFetch && ( -
- -
- )} - {finishedFetch && ( - <> - - - {!noClient && } - - )} - - - ); -}; +const ContextApp = () => ( + <> + + + + + +); const Wrapped = () => ( <> @@ -47,4 +25,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_SERVER_ACCOUNTS]); +} diff --git a/pages/peers.tsx b/pages/peers.tsx index 8a5d5d16..c8737dbc 100644 --- a/pages/peers.tsx +++ b/pages/peers.tsx @@ -1,9 +1,10 @@ import React, { useState } from 'react'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetPeersQuery } from 'src/graphql/queries/__generated__/getPeers.generated'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import { PeerType } from 'src/graphql/types'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_PEERS } from 'src/graphql/queries/getPeers'; import { CardWithTitle, SubTitle, @@ -15,12 +16,8 @@ import { AddPeer } from '../src/views/peers/AddPeer'; const PeersView = () => { const [indexOpen, setIndexOpen] = useState(0); - const { auth } = useAccountState(); - const { loading, data } = useGetPeersQuery({ - skip: !auth, - variables: { auth }, - }); + const { loading, data } = useGetPeersQuery(); if (loading || !data?.getPeers) { return ; @@ -53,4 +50,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_PEERS]); +} diff --git a/pages/rebalance.tsx b/pages/rebalance.tsx index b87bb14b..9b7417d6 100644 --- a/pages/rebalance.tsx +++ b/pages/rebalance.tsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import { SimpleBalance } from 'src/views/balance/SimpleBalance'; import { CardWithTitle, @@ -11,6 +10,9 @@ import { } from 'src/components/generic/Styled'; import { Text } from 'src/components/typography/Styled'; import { AdvancedBalance } from 'src/views/balance/AdvancedBalance'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_CHANNELS } from 'src/graphql/queries/getChannels'; import { useStatusState } from '../src/context/StatusContext'; const BalanceView = () => { @@ -64,4 +66,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_CHANNELS]); +} diff --git a/pages/settings.tsx b/pages/settings.tsx index 62780147..43f22f2f 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,12 +1,12 @@ import React from 'react'; import styled from 'styled-components'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; import { SingleLine } from '../src/components/generic/Styled'; import { InterfaceSettings } from '../src/views/settings/Interface'; import { AccountSettings } from '../src/views/settings/Account'; import { DangerView } from '../src/views/settings/Danger'; -import { CurrentSettings } from '../src/views/settings/Current'; import { ChatSettings } from '../src/views/settings/Chat'; import { PrivacySettings } from '../src/views/settings/Privacy'; @@ -25,7 +25,6 @@ const SettingsView = () => { - @@ -38,4 +37,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context); +} diff --git a/pages/stats.tsx b/pages/stats.tsx index ac197313..93ee2b87 100644 --- a/pages/stats.tsx +++ b/pages/stats.tsx @@ -1,12 +1,16 @@ import React from 'react'; import styled from 'styled-components'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import { VolumeStats } from 'src/views/stats/FlowStats'; import { TimeStats } from 'src/views/stats/TimeStats'; import { FeeStats } from 'src/views/stats/FeeStats'; import { StatResume } from 'src/views/stats/StatResume'; import { StatsProvider } from 'src/views/stats/context'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_FEE_HEALTH } from 'src/graphql/queries/getFeeHealth'; +import { GET_VOLUME_HEALTH } from 'src/graphql/queries/getVolumeHealth'; +import { GET_TIME_HEALTH } from 'src/graphql/queries/getTimeHealth'; import { SingleLine } from '../src/components/generic/Styled'; export const ButtonRow = styled.div` @@ -37,4 +41,12 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [ + GET_FEE_HEALTH, + GET_VOLUME_HEALTH, + GET_TIME_HEALTH, + ]); +} diff --git a/pages/tools.tsx b/pages/tools.tsx index 066b1bde..bdf7c5c2 100644 --- a/pages/tools.tsx +++ b/pages/tools.tsx @@ -1,8 +1,10 @@ import React from 'react'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import { Bakery } from 'src/views/tools/bakery/Bakery'; import { Accounting } from 'src/views/tools/accounting/Accounting'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_WALLET_INFO } from 'src/graphql/queries/getWalletInfo'; import { BackupsView } from '../src/views/tools/backups/Backups'; import { MessagesView } from '../src/views/tools/messages/Messages'; import { WalletVersion } from '../src/views/tools/WalletVersion'; @@ -23,4 +25,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [GET_WALLET_INFO]); +} diff --git a/pages/trading.tsx b/pages/trading.tsx index 0f4dbbef..ce151f77 100644 --- a/pages/trading.tsx +++ b/pages/trading.tsx @@ -3,9 +3,10 @@ import { toast } from 'react-toastify'; import { useRouter } from 'next/router'; import { useGetOffersQuery } from 'src/graphql/hodlhodl/__generated__/query.generated'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; import getConfig from 'next/config'; import { HodlOfferType } from 'src/graphql/types'; +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; import { CardWithTitle, SubTitle, @@ -169,4 +170,8 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context); +} diff --git a/pages/transactions.tsx b/pages/transactions.tsx index 390b0631..e1c7c438 100644 --- a/pages/transactions.tsx +++ b/pages/transactions.tsx @@ -1,13 +1,16 @@ import React, { useState, useEffect } from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { InvoiceCard } from 'src/views/transactions/InvoiceCard'; import { useGetResumeQuery, GetResumeQuery, } from 'src/graphql/queries/__generated__/getResume.generated'; import { GridWrapper } from 'src/components/gridWrapper/GridWrapper'; -import { withApollo } from 'config/client'; + +import { NextPageContext } from 'next'; +import { getProps } from 'src/utils/ssr'; +import { GET_RESUME } from 'src/graphql/queries/getResume'; +import { GET_IN_OUT } from 'src/graphql/queries/getInOut'; import { Card, CardWithTitle, @@ -23,11 +26,8 @@ const TransactionsView = () => { const [indexOpen, setIndexOpen] = useState(0); const [token, setToken] = useState(''); - const { auth } = useAccountState(); - const { loading, data, fetchMore } = useGetResumeQuery({ - skip: !auth, - variables: { auth, token: '' }, + variables: { token: '' }, onError: error => toast.error(getErrorContent(error)), }); @@ -82,7 +82,7 @@ const TransactionsView = () => { withMargin={'16px 0 0'} onClick={() => { fetchMore({ - variables: { auth, token }, + variables: { token }, updateQuery: ( prev, { fetchMoreResult }: { fetchMoreResult?: GetResumeQuery } @@ -123,4 +123,11 @@ const Wrapped = () => ( ); -export default withApollo(Wrapped); +export default Wrapped; + +export async function getServerSideProps(context: NextPageContext) { + return await getProps(context, [ + GET_RESUME, + { document: GET_IN_OUT, variables: { time: 'month' } }, + ]); +} diff --git a/server/helpers/auth.ts b/server/helpers/auth.ts new file mode 100644 index 00000000..482db851 --- /dev/null +++ b/server/helpers/auth.ts @@ -0,0 +1,60 @@ +import { authenticatedLndGrpc } from 'ln-service'; +import { SSOType, AccountType } from 'server/types/apiTypes'; +import { LndObject } from 'server/types/ln-service.types'; +import { v5 as uuidv5 } from 'uuid'; +import { logger } from './logger'; + +type LndAuthType = { + cert: string | null; + macaroon: string; + socket: string; +}; + +const THUNDERHUB_NAMESPACE = '00000000-0000-0000-0000-000000000000'; + +export const getUUID = (text: string): string => + uuidv5(text, THUNDERHUB_NAMESPACE); + +export const getAuthLnd = ( + id: string, + sso: SSOType | null, + accounts: AccountType[] +): LndObject | null => { + if (!id) { + logger.silly('Account not authenticated'); + return null; + } + + let authDetails: LndAuthType | null = null; + + if (id === 'test') { + authDetails = { + socket: process.env.TEST_HOST || '', + macaroon: process.env.TEST_MACAROON || '', + cert: process.env.TEST_CERT || '', + }; + } + + if (id === 'sso' && !sso) { + logger.debug('SSO Account is not verified'); + throw new Error('AccountNotAuthenticated'); + } + + if (id === 'sso' && sso) { + authDetails = sso; + } + + if (!authDetails) { + const verifiedAccount = accounts.find(a => a.id === id) || null; + + if (!verifiedAccount) { + logger.debug('Account not found in config file'); + throw new Error('AccountNotAuthenticated'); + } + + authDetails = verifiedAccount; + } + + const { lnd } = authenticatedLndGrpc(authDetails); + return lnd; +}; diff --git a/server/helpers/fileHelpers.ts b/server/helpers/fileHelpers.ts index 68910f81..065d1846 100644 --- a/server/helpers/fileHelpers.ts +++ b/server/helpers/fileHelpers.ts @@ -4,9 +4,9 @@ import path from 'path'; import os from 'os'; import { logger } from 'server/helpers/logger'; import yaml from 'js-yaml'; -import { getUUID } from 'src/utils/auth'; import bcrypt from 'bcryptjs'; import { AccountType as ContextAccountType } from 'server/types/apiTypes'; +import { getUUID } from './auth'; type EncodingType = 'hex' | 'utf-8'; type BitcoinNetwork = 'mainnet' | 'regtest' | 'testnet'; @@ -18,14 +18,14 @@ type AccountType = { network?: BitcoinNetwork; macaroonPath?: string; certificatePath?: string; - password?: string; + password?: string | null; macaroon?: string; certificate?: string; }; type ParsedAccount = { name: string; id: string; - host: string; + socket: string; macaroon: string; cert: string; password: string; @@ -117,7 +117,7 @@ export const hashPasswords = ( const cloned = { ...config }; - let hashedMasterPassword = config?.masterPassword || ''; + let hashedMasterPassword = config?.masterPassword; if ( hashedMasterPassword && @@ -283,7 +283,7 @@ export const getParsedAccount = ( return { name: name || '', id, - host: serverUrl || '', + socket: serverUrl || '', macaroon, cert: cert || '', password: password || masterPassword || '', diff --git a/server/helpers/getNodeFromChannel.ts b/server/helpers/getNodeFromChannel.ts index 5ada2986..472cebc0 100644 --- a/server/helpers/getNodeFromChannel.ts +++ b/server/helpers/getNodeFromChannel.ts @@ -15,7 +15,7 @@ const errorNode = { export const getNodeFromChannel = async ( id: string, publicKey: string, - lnd: LndObject + lnd: LndObject | null ) => { const [channelInfo, channelError] = await toWithError( getChannel({ diff --git a/server/helpers/helpers.ts b/server/helpers/helpers.ts index 453c5b6c..55ae590c 100644 --- a/server/helpers/helpers.ts +++ b/server/helpers/helpers.ts @@ -1,23 +1,7 @@ -import { authenticatedLndGrpc } from 'ln-service'; import getConfig from 'next/config'; -import { - SSO_ACCOUNT, - SERVER_ACCOUNT, - AuthType, - CLIENT_ACCOUNT, -} from 'src/context/AccountContext'; -import { ContextType } from 'server/types/apiTypes'; -import { logger } from './logger'; -const { serverRuntimeConfig, publicRuntimeConfig } = getConfig() || {}; +const { serverRuntimeConfig } = getConfig() || {}; const { nodeEnv } = serverRuntimeConfig || {}; -const { noClient } = publicRuntimeConfig || {}; - -type LndAuthType = { - cert: string | null; - macaroon: string; - host: string; -}; export const getIp = (req: any) => { if (!req || !req.headers) { @@ -31,78 +15,6 @@ export const getIp = (req: any) => { return ip; }; -export const getCorrectAuth = ( - auth: AuthType, - context: ContextType -): LndAuthType => { - if (auth.type === 'test' && nodeEnv !== 'production') { - return { - host: process.env.TEST_HOST || '', - macaroon: process.env.TEST_MACAROON || '', - cert: process.env.TEST_CERT || '', - }; - } - if (auth.type === SERVER_ACCOUNT) { - const { account, accounts } = context; - if (!account) { - logger.debug('Account not available in request'); - throw new Error('AccountNotAuthenticated'); - } - if (account !== auth.id) { - logger.debug( - `Account (${account}) in cookie different to requested account (${auth.id})` - ); - throw new Error('AccountNotAuthenticated'); - } - - const verifiedAccount = accounts.find(a => a.id === account) || null; - - if (!verifiedAccount) { - logger.debug('Account not found in config file'); - throw new Error('AccountNotAuthenticated'); - } - - return verifiedAccount; - } - if (auth.type === SSO_ACCOUNT) { - if (!context.ssoVerified || !context.sso) { - logger.debug('SSO Account is not verified'); - throw new Error('AccountNotAuthenticated'); - } - - return { ...context.sso }; - } - if (auth.type === CLIENT_ACCOUNT && !noClient) { - const { host, macaroon, cert } = auth; - return { host, macaroon, cert }; - } - if (auth.type === CLIENT_ACCOUNT && noClient) { - logger.info(`Client accounts are disabled from the server.`); - throw new Error('AccountTypeDoesNotExist'); - } - logger.info(`No authentication for account type '${auth.type}' found`); - throw new Error('AccountTypeDoesNotExist'); -}; - -export const getAuthLnd = (auth: LndAuthType) => { - const cert = auth.cert || ''; - const macaroon = auth.macaroon || ''; - const socket = auth.host || ''; - - const params = { - macaroon, - socket, - ...(cert !== '' ? { cert } : {}), - }; - - const { lnd } = authenticatedLndGrpc(params); - - return lnd; -}; - -export const getLnd = (auth: AuthType, context: ContextType) => - getAuthLnd(getCorrectAuth(auth, context)); - export const getErrorMsg = (error: any[] | string): string => { if (typeof error === 'string') { return error; diff --git a/server/helpers/rateLimiter.ts b/server/helpers/rateLimiter.ts index b0a37ee4..06eeb454 100644 --- a/server/helpers/rateLimiter.ts +++ b/server/helpers/rateLimiter.ts @@ -10,6 +10,7 @@ interface RateConfigProps { export const RateConfig: RateConfigProps = { getMessages: { max: 10, window: '5s' }, + nodeInfo: { max: 10, window: '5s' }, }; const rateLimiter = getGraphQLRateLimiter({ diff --git a/server/schema/account/__snapshots__/account.test.ts.snap b/server/schema/account/__snapshots__/account.test.ts.snap index a43edb74..94f010f0 100644 --- a/server/schema/account/__snapshots__/account.test.ts.snap +++ b/server/schema/account/__snapshots__/account.test.ts.snap @@ -6,16 +6,10 @@ Object { "getServerAccounts": Array [ Object { "id": "accountID", - "loggedIn": true, + "loggedIn": false, "name": "account", "type": "server", }, - Object { - "id": "sso", - "loggedIn": true, - "name": "SSO Account", - "type": "sso", - }, ], }, "errors": undefined, @@ -34,7 +28,7 @@ Object { "getServerAccounts": Array [ Object { "id": "accountID", - "loggedIn": true, + "loggedIn": false, "name": "account", "type": "server", }, @@ -56,7 +50,7 @@ Object { "getServerAccounts": Array [ Object { "id": "accountID", - "loggedIn": true, + "loggedIn": false, "name": "account", "type": "server", }, diff --git a/server/schema/account/account.test.ts b/server/schema/account/account.test.ts index 74f0835b..df56c2fa 100644 --- a/server/schema/account/account.test.ts +++ b/server/schema/account/account.test.ts @@ -11,7 +11,6 @@ describe('Account Resolvers', () => { const res = await query({ query: GET_SERVER_ACCOUNTS, - variables: { auth: { type: 'test' } }, }); expect(res.errors).toBe(undefined); @@ -22,7 +21,6 @@ describe('Account Resolvers', () => { const res = await query({ query: GET_SERVER_ACCOUNTS, - variables: { auth: { type: 'test' } }, }); expect(res.errors).toBe(undefined); @@ -33,7 +31,6 @@ describe('Account Resolvers', () => { const res = await query({ query: GET_SERVER_ACCOUNTS, - variables: { auth: { type: 'test' } }, }); expect(res.errors).toBe(undefined); diff --git a/server/schema/account/resolvers.ts b/server/schema/account/resolvers.ts index 329fb833..7a533144 100644 --- a/server/schema/account/resolvers.ts +++ b/server/schema/account/resolvers.ts @@ -1,42 +1,68 @@ import { ContextType } from 'server/types/apiTypes'; -import { SSO_ACCOUNT, SERVER_ACCOUNT } from 'src/context/AccountContext'; import { logger } from 'server/helpers/logger'; import { requestLimiter } from 'server/helpers/rateLimiter'; export const accountResolvers = { Query: { + getAccount: async (_: undefined, __: undefined, context: ContextType) => { + const { ip, accounts, id } = context; + await requestLimiter(ip, 'getAccount'); + + if (!id) { + logger.error(`Not authenticated`); + throw new Error('NotAuthenticated'); + } + + if (id === 'sso') { + return { + name: 'SSO Account', + id: 'sso', + loggedIn: true, + type: 'sso', + }; + } + + const currentAccount = accounts.find(a => a.id === id); + + if (!currentAccount) { + logger.error(`No account found for id ${id}`); + throw new Error('NoAccountFound'); + } + + return { ...currentAccount, type: 'server', loggedIn: true }; + }, getServerAccounts: async ( _: undefined, __: undefined, context: ContextType ) => { - const { ip, accounts, account, sso, ssoVerified } = context; + const { ip, accounts, id, sso } = context; await requestLimiter(ip, 'getServerAccounts'); let ssoAccount = null; - if (ssoVerified && sso) { - const { cert, host } = sso; + if (id === 'sso' && sso) { + const { cert, socket } = sso; logger.debug( `Macaroon${ cert ? ', certificate' : '' - } and host (${host}) found for SSO.` + } and host (${socket}) found for SSO.` ); ssoAccount = { name: 'SSO Account', - id: SSO_ACCOUNT, + id: 'sso', loggedIn: true, - type: SSO_ACCOUNT, + type: 'sso', }; } const withStatus = accounts?.map(a => ({ ...a, - loggedIn: a.id === account, - type: SERVER_ACCOUNT, + loggedIn: a.id === id, + type: 'server', })) || []; - return ssoAccount ? [...withStatus, ssoAccount] : withStatus; + return ssoAccount ? [ssoAccount, ...withStatus] : withStatus; }, }, }; diff --git a/server/schema/auth/resolvers.ts b/server/schema/auth/resolvers.ts index 95201e14..6082e640 100644 --- a/server/schema/auth/resolvers.ts +++ b/server/schema/auth/resolvers.ts @@ -6,11 +6,11 @@ import { PRE_PASS_STRING, } from 'server/helpers/fileHelpers'; import { ContextType } from 'server/types/apiTypes'; -import { SSO_ACCOUNT, SERVER_ACCOUNT } from 'src/context/AccountContext'; import { logger } from 'server/helpers/logger'; import cookie from 'cookie'; import { requestLimiter } from 'server/helpers/rateLimiter'; import bcrypt from 'bcryptjs'; +import { appConstants } from 'server/utils/appConstants'; const { serverRuntimeConfig } = getConfig() || {}; const { cookiePath, nodeEnv } = serverRuntimeConfig || {}; @@ -26,7 +26,7 @@ export const authResolvers = { return null; } - if (!sso.host || !sso.macaroon) { + if (!sso.socket || !sso.macaroon) { logger.warn('Host and macaroon are required for SSO'); return null; } @@ -47,11 +47,15 @@ export const authResolvers = { nodeEnv === 'development' ) { refreshCookie(cookiePath); - const token = jwt.sign({ user: SSO_ACCOUNT }, secret); + const token = jwt.sign({ id: 'sso' }, secret); res.setHeader( 'Set-Cookie', - cookie.serialize('SSOAuth', token, { httpOnly: true, sameSite: true }) + cookie.serialize(appConstants.cookieName, token, { + httpOnly: true, + sameSite: true, + path: '/', + }) ); return true; } @@ -83,17 +87,13 @@ export const authResolvers = { } logger.debug(`Correct password for account ${params.id}`); - const token = jwt.sign( - { - id: params.id, - }, - secret - ); + const token = jwt.sign({ id: params.id }, secret); res.setHeader( 'Set-Cookie', - cookie.serialize('AccountAuth', token, { + cookie.serialize(appConstants.cookieName, token, { httpOnly: true, sameSite: true, + path: '/', }) ); return true; @@ -104,20 +104,10 @@ export const authResolvers = { const { ip, res } = context; await requestLimiter(ip, 'logout'); - if (params.type === SSO_ACCOUNT) { - res.setHeader( - 'Set-Cookie', - cookie.serialize('SSOAuth', '', { maxAge: 1 }) - ); - return true; - } - if (params.type === SERVER_ACCOUNT) { - res.setHeader( - 'Set-Cookie', - cookie.serialize('AccountAuth', '', { maxAge: 1 }) - ); - return true; - } + res.setHeader( + 'Set-Cookie', + cookie.serialize(appConstants.cookieName, '', { maxAge: 1 }) + ); return true; }, }, diff --git a/server/schema/bos/resolvers.ts b/server/schema/bos/resolvers.ts index 4851b504..3023804f 100644 --- a/server/schema/bos/resolvers.ts +++ b/server/schema/bos/resolvers.ts @@ -1,16 +1,12 @@ import { ContextType } from 'server/types/apiTypes'; -import { getLnd } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; import { logger } from 'server/helpers/logger'; -import { AuthType } from 'src/context/AccountContext'; - import { rebalance } from 'balanceofsatoshis/swaps'; import { getAccountingReport } from 'balanceofsatoshis/balances'; import request from '@alexbosworth/request'; import { RebalanceResponseType } from 'server/types/balanceofsatoshis.types'; type RebalanceType = { - auth: AuthType; avoid?: String[]; in_through?: String; is_avoiding_high_inbound?: Boolean; @@ -24,7 +20,6 @@ type RebalanceType = { }; type AccountingType = { - auth: AuthType; category?: String; currency?: String; fiat?: String; @@ -39,8 +34,7 @@ export const bosResolvers = { params: AccountingType, context: ContextType ) => { - const { auth, ...settings } = params; - const lnd = getLnd(auth, context); + const { lnd } = context; const response = await to( getAccountingReport({ @@ -48,7 +42,7 @@ export const bosResolvers = { logger, request, is_csv: true, - ...settings, + ...params, }) ); @@ -62,7 +56,6 @@ export const bosResolvers = { context: ContextType ) => { const { - auth, avoid, in_through, is_avoiding_high_inbound, @@ -74,7 +67,7 @@ export const bosResolvers = { out_through, target, } = params; - const lnd = getLnd(auth, context); + const { lnd } = context; const filteredParams = { avoid, diff --git a/server/schema/chain/chain.test.ts b/server/schema/chain/chain.test.ts index 1d4f2109..d6496108 100644 --- a/server/schema/chain/chain.test.ts +++ b/server/schema/chain/chain.test.ts @@ -1,34 +1,31 @@ -import { AuthMock } from 'server/tests/testMocks'; import testServer from 'server/tests/testServer'; -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; jest.mock('ln-service'); describe('Chain Resolvers', () => { test('getChainBalance', async () => { const getChainBalance = gql` - query($auth: authType!) { - getChainBalance(auth: $auth) + query { + getChainBalance } `; const { query } = testServer(); const res = await query({ query: getChainBalance, - variables: AuthMock, }); expect(res.errors).toBe(undefined); expect(res).toMatchSnapshot(); }); test('getPendingChainBalance', async () => { const getPendingChainBalance = gql` - query($auth: authType!) { - getPendingChainBalance(auth: $auth) + query { + getPendingChainBalance } `; const { query } = testServer(); const res = await query({ query: getPendingChainBalance, - variables: AuthMock, }); expect(res.errors).toBe(undefined); expect(res).toMatchSnapshot(); diff --git a/server/schema/chain/resolvers.ts b/server/schema/chain/resolvers.ts index 6c4d9e32..4d1d3bdd 100644 --- a/server/schema/chain/resolvers.ts +++ b/server/schema/chain/resolvers.ts @@ -9,11 +9,7 @@ import { import { ContextType } from 'server/types/apiTypes'; import { logger } from 'server/helpers/logger'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, -} from 'server/helpers/helpers'; +import { getErrorMsg } from 'server/helpers/helpers'; import { sortBy } from 'underscore'; import { to } from 'server/helpers/async'; import { @@ -41,8 +37,7 @@ export const chainResolvers = { ) => { await requestLimiter(context.ip, 'chainBalance'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const value: ChainBalanceProps = await to( getChainBalance({ @@ -58,8 +53,7 @@ export const chainResolvers = { ) => { await requestLimiter(context.ip, 'pendingChainBalance'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const pendingValue: PendingChainBalanceProps = await to< GetPendingChainBalanceType @@ -77,8 +71,7 @@ export const chainResolvers = { ) => { await requestLimiter(context.ip, 'chainTransactions'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const transactionList = await to( getChainTransactions({ @@ -95,8 +88,7 @@ export const chainResolvers = { getUtxos: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getUtxos'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const info = await to(getUtxos({ lnd })); @@ -107,8 +99,7 @@ export const chainResolvers = { createAddress: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getAddress'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const format = params.nested ? 'np2wpkh' : 'p2wpkh'; @@ -128,8 +119,7 @@ export const chainResolvers = { sendToAddress: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'sendToAddress'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const props = params.fee ? { fee_tokens_per_vbyte: params.fee } diff --git a/server/schema/channel/resolvers/mutation/closeChannel.ts b/server/schema/channel/resolvers/mutation/closeChannel.ts index 20aa1dfe..5af08e43 100644 --- a/server/schema/channel/resolvers/mutation/closeChannel.ts +++ b/server/schema/channel/resolvers/mutation/closeChannel.ts @@ -2,11 +2,7 @@ import { closeChannel as lnCloseChannel } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { logger } from 'server/helpers/logger'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, -} from 'server/helpers/helpers'; +import { getErrorMsg } from 'server/helpers/helpers'; export const closeChannel = async ( _: undefined, @@ -15,8 +11,7 @@ export const closeChannel = async ( ) => { await requestLimiter(context.ip, 'closeChannel'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; try { const info = await lnCloseChannel({ diff --git a/server/schema/channel/resolvers/mutation/openChannel.ts b/server/schema/channel/resolvers/mutation/openChannel.ts index d5d3da5e..0380ebda 100644 --- a/server/schema/channel/resolvers/mutation/openChannel.ts +++ b/server/schema/channel/resolvers/mutation/openChannel.ts @@ -2,11 +2,7 @@ import { openChannel as lnOpenChannel } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { logger } from 'server/helpers/logger'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, -} from 'server/helpers/helpers'; +import { getErrorMsg } from 'server/helpers/helpers'; export const openChannel = async ( _: undefined, @@ -15,8 +11,7 @@ export const openChannel = async ( ) => { await requestLimiter(context.ip, 'openChannel'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const openParams = { is_private: params.isPrivate, diff --git a/server/schema/channel/resolvers/mutation/updateFees.ts b/server/schema/channel/resolvers/mutation/updateFees.ts index cf5bc176..33a20f70 100644 --- a/server/schema/channel/resolvers/mutation/updateFees.ts +++ b/server/schema/channel/resolvers/mutation/updateFees.ts @@ -1,7 +1,6 @@ import { updateRoutingFees } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getLnd } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; export const updateFees = async ( @@ -21,7 +20,7 @@ export const updateFees = async ( min_htlc_mtokens, } = params; - const lnd = getLnd(params.auth, context); + const { lnd } = context; if ( !base_fee_tokens && diff --git a/server/schema/channel/resolvers/query/getChannelBalance.ts b/server/schema/channel/resolvers/query/getChannelBalance.ts index bf26d353..ca61b30c 100644 --- a/server/schema/channel/resolvers/query/getChannelBalance.ts +++ b/server/schema/channel/resolvers/query/getChannelBalance.ts @@ -1,7 +1,7 @@ import { getChannelBalance as getLnChannelBalance } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; + import { to } from 'server/helpers/async'; interface ChannelBalanceProps { @@ -16,8 +16,7 @@ export const getChannelBalance = async ( ) => { await requestLimiter(context.ip, 'channelBalance'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const channelBalance: ChannelBalanceProps = await to( getLnChannelBalance({ diff --git a/server/schema/channel/resolvers/query/getChannelFees.ts b/server/schema/channel/resolvers/query/getChannelFees.ts index 650a4961..b6dd292f 100644 --- a/server/schema/channel/resolvers/query/getChannelFees.ts +++ b/server/schema/channel/resolvers/query/getChannelFees.ts @@ -1,7 +1,6 @@ import { getChannels, getWalletInfo } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getLnd } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; interface GetChannelsProps { @@ -37,7 +36,7 @@ export const getChannelFees = async ( ) => { await requestLimiter(context.ip, 'channelFees'); - const lnd = getLnd(params.auth, context); + const { lnd } = context; const { public_key } = await to(getWalletInfo({ lnd })); const { channels }: GetChannelsProps = await to(getChannels({ lnd })); diff --git a/server/schema/channel/resolvers/query/getChannels.ts b/server/schema/channel/resolvers/query/getChannels.ts index 24b09b8f..d405aba3 100644 --- a/server/schema/channel/resolvers/query/getChannels.ts +++ b/server/schema/channel/resolvers/query/getChannels.ts @@ -2,7 +2,7 @@ import { getChannels as getLnChannels, getWalletInfo } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { to } from 'server/helpers/async'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; + import { getChannelAge } from 'server/schema/health/helpers'; import { GetChannelsType } from 'server/types/ln-service.types'; @@ -13,8 +13,7 @@ export const getChannels = async ( ) => { await requestLimiter(context.ip, 'channels'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const { public_key, current_block_height } = await to(getWalletInfo({ lnd })); diff --git a/server/schema/channel/resolvers/query/getClosedChannels.ts b/server/schema/channel/resolvers/query/getClosedChannels.ts index e5e31ece..b3cda1f0 100644 --- a/server/schema/channel/resolvers/query/getClosedChannels.ts +++ b/server/schema/channel/resolvers/query/getClosedChannels.ts @@ -2,7 +2,6 @@ import { getClosedChannels as getLnClosedChannels } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { to } from 'server/helpers/async'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; interface ChannelListProps { channels: ChannelProps[]; @@ -32,8 +31,7 @@ export const getClosedChannels = async ( ) => { await requestLimiter(context.ip, 'closedChannels'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const { channels }: ChannelListProps = await to(getLnClosedChannels({ lnd })); diff --git a/server/schema/channel/resolvers/query/getPendingChannels.ts b/server/schema/channel/resolvers/query/getPendingChannels.ts index 81d9bb7c..b3456101 100644 --- a/server/schema/channel/resolvers/query/getPendingChannels.ts +++ b/server/schema/channel/resolvers/query/getPendingChannels.ts @@ -2,7 +2,6 @@ import { getPendingChannels as getLnPendingChannels } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { to } from 'server/helpers/async'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; interface PendingChannelListProps { pending_channels: PendingChannelProps[]; @@ -32,8 +31,7 @@ export const getPendingChannels = async ( ) => { await requestLimiter(context.ip, 'pendingChannels'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const { pending_channels }: PendingChannelListProps = await to( getLnPendingChannels({ lnd }) diff --git a/server/schema/chat/resolvers.ts b/server/schema/chat/resolvers.ts index a2993d0b..724e76b5 100644 --- a/server/schema/chat/resolvers.ts +++ b/server/schema/chat/resolvers.ts @@ -10,7 +10,7 @@ import { import { ContextType } from 'server/types/apiTypes'; import { to, toWithError } from 'server/helpers/async'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; + import { createCustomRecords, decodeMessage, @@ -26,8 +26,7 @@ export const chatResolvers = { getMessages: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getMessages'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const invoiceList = await to( getInvoices({ @@ -105,8 +104,7 @@ export const chatResolvers = { sendMessage: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'sendMessage'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; if (params.maxFee) { const tokens = Math.max(params.tokens || 100, 100); diff --git a/server/schema/context.ts b/server/schema/context.ts new file mode 100644 index 00000000..fad765a3 --- /dev/null +++ b/server/schema/context.ts @@ -0,0 +1,72 @@ +import { IncomingMessage, ServerResponse } from 'http'; +import { getIp } from 'server/helpers/helpers'; +import jwt from 'jsonwebtoken'; +import { logger } from 'server/helpers/logger'; +import { + readMacaroons, + readFile, + getAccounts, +} from 'server/helpers/fileHelpers'; +import getConfig from 'next/config'; +import { ContextType, SSOType } from 'server/types/apiTypes'; +import cookie from 'cookie'; +import { LndObject } from 'server/types/ln-service.types'; +import { getAuthLnd } from 'server/helpers/auth'; +import { appConstants } from 'server/utils/appConstants'; +import { secret } from 'pages/api/v1'; + +const { serverRuntimeConfig } = getConfig(); +const { + macaroonPath, + lnCertPath, + lnServerUrl, + accountConfigPath, +} = serverRuntimeConfig; + +const ssoMacaroon = readMacaroons(macaroonPath); +const ssoCert = readFile(lnCertPath); +const accountConfig = getAccounts(accountConfigPath); + +let sso: SSOType | null = null; + +if (ssoMacaroon && lnServerUrl) { + sso = { + macaroon: ssoMacaroon, + socket: lnServerUrl, + cert: ssoCert, + }; +} + +export const getContext = (req: IncomingMessage, res: ServerResponse) => { + const ip = getIp(req); + + const cookies = cookie.parse(req.headers.cookie ?? '') || {}; + const auth = cookies[appConstants.cookieName]; + + let lnd: LndObject | null = null; + let id: string | null = null; + + if (auth) { + try { + const data = jwt.verify(auth, secret) as { id: string }; + if (data && data.id) { + lnd = getAuthLnd(data.id, sso, accountConfig); + id = data.id; + } + } catch (error) { + logger.silly('Authentication cookie failed'); + } + } + + const context: ContextType = { + ip, + lnd, + secret, + id, + sso, + accounts: accountConfig, + res, + }; + + return context; +}; diff --git a/server/schema/health/resolvers/getFeeHealth.ts b/server/schema/health/resolvers/getFeeHealth.ts index c7eb0df3..94c90a41 100644 --- a/server/schema/health/resolvers/getFeeHealth.ts +++ b/server/schema/health/resolvers/getFeeHealth.ts @@ -1,5 +1,4 @@ import { getChannels, getChannel, getWalletInfo } from 'ln-service'; -import { getCorrectAuth, getAuthLnd } from 'server/helpers/helpers'; import { requestLimiter } from 'server/helpers/rateLimiter'; import { to, toWithError } from 'server/helpers/async'; import { logger } from 'server/helpers/logger'; @@ -19,8 +18,7 @@ type ChannelFeesType = { export default async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getFeeHealth'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const { public_key } = await to(getWalletInfo({ lnd })); const { channels } = await to(getChannels({ lnd })); diff --git a/server/schema/health/resolvers/getTimeHealth.ts b/server/schema/health/resolvers/getTimeHealth.ts index 81135787..d1c8a372 100644 --- a/server/schema/health/resolvers/getTimeHealth.ts +++ b/server/schema/health/resolvers/getTimeHealth.ts @@ -1,5 +1,4 @@ import { getChannels } from 'ln-service'; -import { getCorrectAuth, getAuthLnd } from 'server/helpers/helpers'; import { requestLimiter } from 'server/helpers/rateLimiter'; import { to } from 'server/helpers/async'; import { ContextType } from 'server/types/apiTypes'; @@ -8,11 +7,10 @@ import { getAverage } from '../helpers'; const halfMonthInMilliSeconds = 1296000000; -export default async (_: undefined, params: any, context: ContextType) => { +export default async (_: undefined, __: any, context: ContextType) => { await requestLimiter(context.ip, 'getTimeHealth'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const { channels } = await to(getChannels({ lnd })); diff --git a/server/schema/health/resolvers/getVolumeHealth.ts b/server/schema/health/resolvers/getVolumeHealth.ts index b6884dd6..300977b4 100644 --- a/server/schema/health/resolvers/getVolumeHealth.ts +++ b/server/schema/health/resolvers/getVolumeHealth.ts @@ -1,6 +1,5 @@ import { getForwards, getChannels, getWalletInfo } from 'ln-service'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getCorrectAuth, getAuthLnd } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; import { subMonths } from 'date-fns'; import { ContextType } from 'server/types/apiTypes'; @@ -15,8 +14,7 @@ const monthInBlocks = 4380; export default async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getVolumeHealth'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const before = new Date().toISOString(); const after = subMonths(new Date(), 1).toISOString(); diff --git a/server/schema/index.ts b/server/schema/index.ts index 60add238..8a63c831 100644 --- a/server/schema/index.ts +++ b/server/schema/index.ts @@ -1,5 +1,5 @@ import merge from 'lodash.merge'; -import { makeExecutableSchema } from 'apollo-server-micro'; +import { makeExecutableSchema } from 'graphql-tools'; import { nodeTypes } from './node/types'; import { nodeResolvers } from './node/resolvers'; import { authResolvers } from './auth/resolvers'; @@ -93,4 +93,4 @@ const resolvers = merge( tbaseResolvers ); -export default makeExecutableSchema({ typeDefs, resolvers }); +export const schema = makeExecutableSchema({ typeDefs, resolvers }); diff --git a/server/schema/invoice/resolvers.ts b/server/schema/invoice/resolvers.ts index 28e204d7..3a795737 100644 --- a/server/schema/invoice/resolvers.ts +++ b/server/schema/invoice/resolvers.ts @@ -9,12 +9,7 @@ import { import { ContextType } from 'server/types/apiTypes'; import { logger } from 'server/helpers/logger'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, - getLnd, -} from 'server/helpers/helpers'; +import { getErrorMsg } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; import { DecodedType } from 'server/types/ln-service.types'; @@ -25,7 +20,7 @@ export const invoiceResolvers = { decodeRequest: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'decode'); - const lnd = getLnd(params.auth, context); + const { lnd } = context; const decoded = await to( decodePaymentRequest({ @@ -49,8 +44,7 @@ export const invoiceResolvers = { createInvoice: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'createInvoice'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; return await to( createInvoiceRequest({ @@ -62,8 +56,8 @@ export const invoiceResolvers = { keysend: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'keysend'); - const { auth, destination, tokens } = params; - const lnd = getLnd(auth, context); + const { destination, tokens } = params; + const { lnd } = context; const preimage = randomBytes(32); const secret = preimage.toString('hex'); @@ -91,8 +85,7 @@ export const invoiceResolvers = { ) => { await requestLimiter(context.ip, 'circularRebalance'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; let route; try { @@ -121,8 +114,8 @@ export const invoiceResolvers = { payViaRoute: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'payViaRoute'); - const { auth, route: routeJSON, id } = params; - const lnd = getLnd(auth, context); + const { route: routeJSON, id } = params; + const { lnd } = context; let route; try { diff --git a/server/schema/macaroon/resolvers.ts b/server/schema/macaroon/resolvers.ts index 1ef107ae..23ce1138 100644 --- a/server/schema/macaroon/resolvers.ts +++ b/server/schema/macaroon/resolvers.ts @@ -1,9 +1,7 @@ import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getLnd } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; import { grantAccess } from 'ln-service'; -import { AuthType } from 'src/context/AccountContext'; import { logger } from 'server/helpers/logger'; export type PermissionsType = { @@ -27,7 +25,6 @@ export type PermissionsType = { }; type ParamsType = { - auth: AuthType; permissions: PermissionsType; }; @@ -40,9 +37,8 @@ export const macaroonResolvers = { ) => { await requestLimiter(context.ip, 'createMacaroon'); - const { auth, permissions } = params; - - const lnd = getLnd(auth, context); + const { permissions } = params; + const { lnd } = context; const { macaroon, permissions: permissionList } = await to( grantAccess({ lnd, ...permissions }) diff --git a/server/schema/network/resolvers.ts b/server/schema/network/resolvers.ts index db91130b..299d13ee 100644 --- a/server/schema/network/resolvers.ts +++ b/server/schema/network/resolvers.ts @@ -1,7 +1,6 @@ import { getNetworkInfo } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getLnd } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; interface NetworkInfoProps { @@ -20,7 +19,7 @@ export const networkResolvers = { getNetworkInfo: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'networkInfo'); - const lnd = getLnd(params.auth, context); + const { lnd } = context; const info: NetworkInfoProps = await to(getNetworkInfo({ lnd })); diff --git a/server/schema/node/resolvers.ts b/server/schema/node/resolvers.ts index f725c5fa..11562304 100644 --- a/server/schema/node/resolvers.ts +++ b/server/schema/node/resolvers.ts @@ -7,7 +7,6 @@ import { GetWalletInfoType, GetNodeType, } from 'server/types/ln-service.types'; -import { getAuthLnd, getCorrectAuth, getLnd } from '../../helpers/helpers'; import { ContextType } from '../../types/apiTypes'; import { logger } from '../../helpers/logger'; @@ -24,16 +23,15 @@ export const nodeResolvers = { getNode: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'closedChannels'); - const { auth, withoutChannels = true, publicKey } = params; - const lnd = getLnd(auth, context); + const { withoutChannels = true, publicKey } = params; + const { lnd } = context; return { lnd, publicKey, withChannels: !withoutChannels }; }, getNodeInfo: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'nodeInfo'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const info = await to( getWalletInfo({ diff --git a/server/schema/peer/resolvers.ts b/server/schema/peer/resolvers.ts index f313e4ad..b4ee247d 100644 --- a/server/schema/peer/resolvers.ts +++ b/server/schema/peer/resolvers.ts @@ -2,11 +2,7 @@ import { getPeers, removePeer, addPeer } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { logger } from 'server/helpers/logger'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, -} from 'server/helpers/helpers'; +import { getErrorMsg } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; interface PeerProps { @@ -26,8 +22,7 @@ export const peerResolvers = { getPeers: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getPeers'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const { peers }: { peers: PeerProps[] } = await to( getPeers({ @@ -67,8 +62,7 @@ export const peerResolvers = { peerSocket = parts[1]; } - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; try { const success: boolean = await addPeer({ @@ -86,8 +80,7 @@ export const peerResolvers = { removePeer: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'removePeer'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; try { const success: boolean = await removePeer({ diff --git a/server/schema/route/resolvers.ts b/server/schema/route/resolvers.ts index f2415b39..a78d83e0 100644 --- a/server/schema/route/resolvers.ts +++ b/server/schema/route/resolvers.ts @@ -6,7 +6,6 @@ import { import { ContextType } from 'server/types/apiTypes'; import { logger } from 'server/helpers/logger'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getLnd } from 'server/helpers/helpers'; import { toWithError, to } from 'server/helpers/async'; import { LndObject, ProbeForRouteType } from 'server/types/ln-service.types'; @@ -21,7 +20,7 @@ export const routeResolvers = { getRoutes: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getRoutes'); - const lnd = getLnd(params.auth, context); + const { lnd } = context; const { public_key } = await getWalletInfo({ lnd }); diff --git a/server/schema/tools/resolvers.ts b/server/schema/tools/resolvers.ts index f4e26e0c..5b5c3dbd 100644 --- a/server/schema/tools/resolvers.ts +++ b/server/schema/tools/resolvers.ts @@ -9,12 +9,7 @@ import { import { ContextType } from 'server/types/apiTypes'; import { logger } from 'server/helpers/logger'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { - getAuthLnd, - getErrorMsg, - getCorrectAuth, - getLnd, -} from 'server/helpers/helpers'; +import { getErrorMsg } from 'server/helpers/helpers'; import { toWithError } from 'server/helpers/async'; import { ChannelType } from 'server/types/ln-service.types'; @@ -23,8 +18,7 @@ export const toolsResolvers = { verifyBackups: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'verifyBackups'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; let backupObj = { backup: '', channels: [] as ChannelType[] }; try { @@ -51,8 +45,7 @@ export const toolsResolvers = { recoverFunds: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'recoverFunds'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; let backupObj = { backup: '' }; try { @@ -78,8 +71,7 @@ export const toolsResolvers = { getBackups: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getBackups'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; try { const backups = await getBackups({ @@ -94,7 +86,7 @@ export const toolsResolvers = { adminCheck: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'adminCheck'); - const lnd = getLnd(params.auth, context); + const { lnd } = context; const [, error] = await toWithError( pay({ @@ -123,8 +115,7 @@ export const toolsResolvers = { verifyMessage: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'verifyMessage'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; try { const message: { signed_by: string } = await verifyMessage({ @@ -142,8 +133,7 @@ export const toolsResolvers = { signMessage: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'signMessage'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; try { const message: { signature: string } = await signMessage({ diff --git a/server/schema/transactions/resolvers.ts b/server/schema/transactions/resolvers.ts index 4b2cd3b7..a1c6742a 100644 --- a/server/schema/transactions/resolvers.ts +++ b/server/schema/transactions/resolvers.ts @@ -8,7 +8,6 @@ import { compareDesc, subHours, subDays, subMonths, subYears } from 'date-fns'; import { sortBy } from 'underscore'; import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; import { GetInvoicesType, @@ -26,8 +25,7 @@ export const transactionResolvers = { getResume: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'payments'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const invoiceProps = params.token ? { token: params.token } @@ -105,8 +103,7 @@ export const transactionResolvers = { getForwards: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'forwards'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; let startDate = new Date(); const endDate = new Date(); diff --git a/server/schema/types.ts b/server/schema/types.ts index 56838b54..09e5c33a 100644 --- a/server/schema/types.ts +++ b/server/schema/types.ts @@ -1,14 +1,6 @@ import { gql } from 'apollo-server-micro'; export const generalTypes = gql` - input authType { - type: String! - id: String - host: String - macaroon: String - cert: String - } - input permissionsType { is_ok_to_adjust_peers: Boolean is_ok_to_create_chain_addresses: Boolean @@ -38,66 +30,54 @@ export const queryTypes = gql` type Query { getBaseNodes: [baseNodesType]! getAccountingReport( - auth: authType! category: String currency: String fiat: String month: String year: String ): String! - getVolumeHealth(auth: authType!): channelsHealth - getTimeHealth(auth: authType!): channelsTimeHealth - getFeeHealth(auth: authType!): channelsFeeHealth - getChannelBalance(auth: authType!): channelBalanceType - getChannels(auth: authType!, active: Boolean): [channelType]! - getClosedChannels(auth: authType!, type: String): [closedChannelType] - getPendingChannels(auth: authType!): [pendingChannelType] - getChannelFees(auth: authType!): [channelFeeType] - getChannelReport(auth: authType!): channelReportType - getNetworkInfo(auth: authType!): networkInfoType - getNodeInfo(auth: authType!): nodeInfoType - adminCheck(auth: authType!): Boolean - getNode( - auth: authType! - publicKey: String! - withoutChannels: Boolean - ): Node! - decodeRequest(auth: authType!, request: String!): decodeType - getWalletInfo(auth: authType!): walletInfoType - getResume(auth: authType!, token: String): getResumeType - getForwards(auth: authType!, time: String): getForwardType + getVolumeHealth: channelsHealth + getTimeHealth: channelsTimeHealth + getFeeHealth: channelsFeeHealth + getChannelBalance: channelBalanceType + getChannels(active: Boolean): [channelType]! + getClosedChannels(type: String): [closedChannelType] + getPendingChannels: [pendingChannelType] + getChannelFees: [channelFeeType] + getChannelReport: channelReportType + getNetworkInfo: networkInfoType + getNodeInfo: nodeInfoType + adminCheck: Boolean + getNode(publicKey: String!, withoutChannels: Boolean): Node! + decodeRequest(request: String!): decodeType + getWalletInfo: walletInfoType + getResume(token: String): getResumeType + getForwards(time: String): getForwardType getBitcoinPrice(logger: Boolean, currency: String): String getBitcoinFees(logger: Boolean): bitcoinFeeType - getForwardReport(auth: authType!, time: String): String - getForwardChannelsReport( - auth: authType! - time: String - order: String - type: String - ): String - getInOut(auth: authType!, time: String): InOutType - getBackups(auth: authType!): String - verifyBackups(auth: authType!, backup: String!): Boolean - recoverFunds(auth: authType!, backup: String!): Boolean + getForwardReport(time: String): String + getForwardChannelsReport(time: String, order: String, type: String): String + getInOut(time: String): InOutType + getBackups: String + verifyBackups(backup: String!): Boolean + recoverFunds(backup: String!): Boolean getRoutes( - auth: authType! outgoing: String! incoming: String! tokens: Int! maxFee: Int ): GetRouteType - getPeers(auth: authType!): [peerType] - signMessage(auth: authType!, message: String!): String - verifyMessage(auth: authType!, message: String!, signature: String!): String - getChainBalance(auth: authType!): Int - getPendingChainBalance(auth: authType!): Int - getChainTransactions(auth: authType!): [getTransactionsType] - getUtxos(auth: authType!): [getUtxosType] + getPeers: [peerType] + signMessage(message: String!): String + verifyMessage(message: String!, signature: String!): String + getChainBalance: Int + getPendingChainBalance: Int + getChainTransactions: [getTransactionsType] + getUtxos: [getUtxosType] getOffers(filter: String): [hodlOfferType] getCountries: [hodlCountryType] getCurrencies: [hodlCurrencyType] getMessages( - auth: authType! token: String initialize: Boolean lastMessage: String @@ -105,6 +85,7 @@ export const queryTypes = gql` getAuthToken(cookie: String): Boolean getSessionToken(id: String, password: String): Boolean getServerAccounts: [serverAccountType] + getAccount: serverAccountType getLnPayInfo: lnPayInfoType getLnPay(amount: Int): String getLatestVersion: String @@ -114,21 +95,18 @@ export const queryTypes = gql` export const mutationTypes = gql` type Mutation { closeChannel( - auth: authType! id: String! forceClose: Boolean targetConfirmations: Int tokensPerVByte: Int ): closeChannelType openChannel( - auth: authType! amount: Int! partnerPublicKey: String! tokensPerVByte: Int isPrivate: Boolean ): openChannelType updateFees( - auth: authType! transaction_id: String transaction_vout: Int base_fee_tokens: Float @@ -137,11 +115,10 @@ export const mutationTypes = gql` max_htlc_mtokens: String min_htlc_mtokens: String ): Boolean - keysend(auth: authType!, destination: String!, tokens: Int!): payType - createInvoice(auth: authType!, amount: Int!): newInvoiceType - circularRebalance(auth: authType!, route: String!): Boolean + keysend(destination: String!, tokens: Int!): payType + createInvoice(amount: Int!): newInvoiceType + circularRebalance(route: String!): Boolean bosRebalance( - auth: authType! avoid: [String] in_through: String is_avoiding_high_inbound: Boolean @@ -153,10 +130,9 @@ export const mutationTypes = gql` out_through: String target: Int ): bosRebalanceResultType - payViaRoute(auth: authType!, route: String!, id: String!): Boolean - createAddress(auth: authType!, nested: Boolean): String + payViaRoute(route: String!, id: String!): Boolean + createAddress(nested: Boolean): String sendToAddress( - auth: authType! address: String! tokens: Int fee: Int @@ -164,15 +140,13 @@ export const mutationTypes = gql` sendAll: Boolean ): sendToType addPeer( - auth: authType! url: String publicKey: String socket: String isTemporary: Boolean ): Boolean - removePeer(auth: authType!, publicKey: String!): Boolean + removePeer(publicKey: String!): Boolean sendMessage( - auth: authType! publicKey: String! message: String! messageType: String @@ -180,6 +154,6 @@ export const mutationTypes = gql` maxFee: Int ): Int logout(type: String!): Boolean - createMacaroon(auth: authType!, permissions: permissionsType!): String + createMacaroon(permissions: permissionsType!): String } `; diff --git a/server/schema/wallet/resolvers.ts b/server/schema/wallet/resolvers.ts index 56bcfaa7..e1a21f8f 100644 --- a/server/schema/wallet/resolvers.ts +++ b/server/schema/wallet/resolvers.ts @@ -2,15 +2,13 @@ import { getWalletVersion } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { to } from 'server/helpers/async'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; export const walletResolvers = { Query: { getWalletInfo: async (_: undefined, params: any, context: ContextType) => { await requestLimiter(context.ip, 'getWalletInfo'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; return await to( getWalletVersion({ diff --git a/server/schema/widgets/resolvers/getChannelReport.ts b/server/schema/widgets/resolvers/getChannelReport.ts index cc0e5beb..4ce65fda 100644 --- a/server/schema/widgets/resolvers/getChannelReport.ts +++ b/server/schema/widgets/resolvers/getChannelReport.ts @@ -1,7 +1,6 @@ import { getChannels } from 'ln-service'; import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getLnd } from 'server/helpers/helpers'; import { to } from 'server/helpers/async'; import { GetChannelsType } from 'server/types/ln-service.types'; @@ -12,7 +11,7 @@ export const getChannelReport = async ( ) => { await requestLimiter(context.ip, 'channelReport'); - const lnd = getLnd(params.auth, context); + const { lnd } = context; const info = await to(getChannels({ lnd })); diff --git a/server/schema/widgets/resolvers/getForwardChannelsReport.ts b/server/schema/widgets/resolvers/getForwardChannelsReport.ts index 216c56df..358212b0 100644 --- a/server/schema/widgets/resolvers/getForwardChannelsReport.ts +++ b/server/schema/widgets/resolvers/getForwardChannelsReport.ts @@ -4,7 +4,7 @@ import { sortBy } from 'underscore'; import { ContextType } from 'server/types/apiTypes'; import { getNodeFromChannel } from 'server/helpers/getNodeFromChannel'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; + import { to } from 'server/helpers/async'; import { GetForwardsType, @@ -19,8 +19,7 @@ export const getForwardChannelsReport = async ( ) => { await requestLimiter(context.ip, 'forwardChannels'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; let startDate = new Date(); const endDate = new Date(); diff --git a/server/schema/widgets/resolvers/getForwardsReport.ts b/server/schema/widgets/resolvers/getForwardsReport.ts index 99e172b8..f342e751 100644 --- a/server/schema/widgets/resolvers/getForwardsReport.ts +++ b/server/schema/widgets/resolvers/getForwardsReport.ts @@ -8,7 +8,7 @@ import { } from 'date-fns'; import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; + import { to } from 'server/helpers/async'; import { GetForwardsType } from 'server/types/ln-service.types'; import { reduceForwardArray } from './helpers'; @@ -20,8 +20,7 @@ export const getForwardReport = async ( ) => { await requestLimiter(context.ip, 'forwardReport'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; let startDate = new Date(); const endDate = new Date(); diff --git a/server/schema/widgets/resolvers/getInOut.ts b/server/schema/widgets/resolvers/getInOut.ts index f2df1a1e..3fd35ae2 100644 --- a/server/schema/widgets/resolvers/getInOut.ts +++ b/server/schema/widgets/resolvers/getInOut.ts @@ -3,7 +3,7 @@ import { differenceInHours, differenceInCalendarDays } from 'date-fns'; import { groupBy } from 'underscore'; import { ContextType } from 'server/types/apiTypes'; import { requestLimiter } from 'server/helpers/rateLimiter'; -import { getAuthLnd, getCorrectAuth } from 'server/helpers/helpers'; + import { to } from 'server/helpers/async'; import { GetInvoicesType, @@ -18,8 +18,7 @@ export const getInOut = async ( ) => { await requestLimiter(context.ip, 'getInOut'); - const auth = getCorrectAuth(params.auth, context); - const lnd = getAuthLnd(auth); + const { lnd } = context; const endDate = new Date(); let periods = 7; diff --git a/server/tests/__mocks__/ln-service.ts b/server/tests/__mocks__/ln-service.ts index ae259dee..cb7986e8 100644 --- a/server/tests/__mocks__/ln-service.ts +++ b/server/tests/__mocks__/ln-service.ts @@ -2,6 +2,14 @@ import * as res from '../lnServiceResponse'; export const authenticatedLndGrpc = jest.fn().mockReturnValue({}); +export const probeForRoute = jest + .fn() + .mockReturnValue(Promise.resolve(res.probeForRouteResponse)); + +export const getNode = jest + .fn() + .mockReturnValue(Promise.resolve(res.getNodeResponse)); + export const getNetworkInfo = jest .fn() .mockReturnValue(Promise.resolve(res.getNetworkInfoResponse)); diff --git a/server/tests/lnServiceResponse.ts b/server/tests/lnServiceResponse.ts index 21f4425a..830eb6f1 100644 --- a/server/tests/lnServiceResponse.ts +++ b/server/tests/lnServiceResponse.ts @@ -342,6 +342,39 @@ export const getNodeResponse = { updated_at: '2011-10-05T14:48:00.000Z', }; +export const probeForRouteResponse = { + route: { + confidence: 1000, + fee: 1000, + fee_mtokens: 'string', + hops: [ + { + channel: 'string', + channel_capacity: 1000, + fee: 1000, + fee_mtokens: 'string', + forward: 1000, + forward_mtokens: 'string', + public_key: 'string', + timeout: 1000, + }, + ], + messages: [ + { + type: 'string', + value: 'string', + }, + ], + mtokens: 'string', + payment: 'string', + safe_fee: 1000, + safe_tokens: 1000, + timeout: 1000, + tokens: 1000, + total_mtokens: 'string', + }, +}; + export const getChannelResponse = { capacity: 1000, id: '100x1x1', diff --git a/server/tests/testMocks.ts b/server/tests/testMocks.ts index a76f17b9..232d485c 100644 --- a/server/tests/testMocks.ts +++ b/server/tests/testMocks.ts @@ -1,27 +1,21 @@ import { ServerResponse } from 'http'; import { ContextType } from 'server/types/apiTypes'; -export const AuthMock = { - auth: { - type: 'test', - }, -}; - export const ContextMock: ContextType = { + lnd: {}, + id: 'test', ip: '1.2.3.4', secret: '123456789', - ssoVerified: true, - account: 'accountID', sso: { macaroon: 'macaroon', cert: 'cert', - host: 'host', + socket: 'host', }, accounts: [ { name: 'account', id: 'accountID', - host: 'host', + socket: 'host', macaroon: 'macaroon', cert: 'cert', password: 'password', @@ -31,30 +25,30 @@ export const ContextMock: ContextType = { }; export const ContextMockNoAccounts: ContextType = { + lnd: {}, + id: 'test', ip: '1.2.3.4', secret: '123456789', - ssoVerified: true, - account: 'accountID', sso: { macaroon: 'macaroon', cert: 'cert', - host: 'host', + socket: 'host', }, accounts: [], res: {} as ServerResponse, }; export const ContextMockNoSSO: ContextType = { + lnd: {}, + id: 'test', ip: '1.2.3.4', secret: '123456789', - ssoVerified: true, - account: 'accountID', sso: null, accounts: [ { name: 'account', id: 'accountID', - host: 'host', + socket: 'host', macaroon: 'macaroon', cert: 'cert', password: 'password', diff --git a/server/tests/testServer.ts b/server/tests/testServer.ts index 69830b50..618090c1 100644 --- a/server/tests/testServer.ts +++ b/server/tests/testServer.ts @@ -3,7 +3,7 @@ import { ApolloServerTestClient, } from 'apollo-server-testing'; import { ApolloServer } from 'apollo-server'; -import schema from 'server/schema'; +import { schema } from 'server/schema'; import { ContextMock } from 'server/tests/testMocks'; export default function testServer(context?: any): ApolloServerTestClient { diff --git a/server/types/apiTypes.ts b/server/types/apiTypes.ts index 99381b8f..38cd08ae 100644 --- a/server/types/apiTypes.ts +++ b/server/types/apiTypes.ts @@ -1,15 +1,16 @@ import { ServerResponse } from 'http'; +import { LndObject } from './ln-service.types'; export type SSOType = { macaroon: string; cert: string | null; - host: string; + socket: string; }; export type AccountType = { name: string; id: string; - host: string; + socket: string; macaroon: string; cert: string | null; password: string; @@ -17,9 +18,9 @@ export type AccountType = { export type ContextType = { ip: string; + lnd: LndObject | null; secret: string; - ssoVerified: boolean; - account: string | null; + id: string | null; sso: SSOType | null; accounts: AccountType[]; res: ServerResponse; diff --git a/server/utils/appConstants.ts b/server/utils/appConstants.ts new file mode 100644 index 00000000..17d0e079 --- /dev/null +++ b/server/utils/appConstants.ts @@ -0,0 +1,3 @@ +export const appConstants = { + cookieName: 'Thub-Auth', +}; diff --git a/src/components/accounts/ServerAccounts.tsx b/src/components/accounts/ServerAccounts.tsx index 5966e41e..db294fa9 100644 --- a/src/components/accounts/ServerAccounts.tsx +++ b/src/components/accounts/ServerAccounts.tsx @@ -1,24 +1,11 @@ import * as React from 'react'; -import { - useAccountDispatch, - useAccountState, - CompleteAccount, - AccountProps, -} from 'src/context/AccountContext'; -import { addIdAndTypeToAccount } from 'src/context/helpers/context'; -import { useGetServerAccountsQuery } from 'src/graphql/queries/__generated__/getServerAccounts.generated'; -import { toast } from 'react-toastify'; import { useRouter } from 'next/router'; import { appendBasePath } from 'src/utils/basePath'; import { getUrlParam } from 'src/utils/url'; import { useGetAuthTokenQuery } from 'src/graphql/queries/__generated__/getAuthToken.generated'; export const ServerAccounts: React.FC = () => { - const { hasAccount } = useAccountState(); - const dispatch = useAccountDispatch(); - const { push, pathname, query } = useRouter(); - - const { data, loading, refetch } = useGetServerAccountsQuery(); + const { push, query } = useRouter(); const cookieParam = getUrlParam(query?.token); @@ -30,42 +17,9 @@ export const ServerAccounts: React.FC = () => { React.useEffect(() => { if (cookieParam && authData && authData.getAuthToken) { - refetch(); push(appendBasePath('/')); } - }, [push, authData, cookieParam, refetch]); - - React.useEffect(() => { - if (hasAccount === 'error' && pathname !== '/') { - toast.error('No account found'); - dispatch({ type: 'resetFetch' }); - push(appendBasePath('/')); - } - }, [hasAccount, push, dispatch, pathname]); - - React.useEffect(() => { - const session = sessionStorage.getItem('session') || null; - const changeId = localStorage.getItem('active') || null; - const savedAccounts = JSON.parse(localStorage.getItem('accounts') || '[]'); - const accountsToAdd = savedAccounts.map((a: AccountProps) => - addIdAndTypeToAccount(a) - ); - dispatch({ - type: 'initialize', - accountsToAdd, - changeId, - session, - }); - }, [dispatch]); - - React.useEffect(() => { - if (!loading && data && data.getServerAccounts) { - dispatch({ - type: 'addServerAccounts', - accountsToAdd: data.getServerAccounts as CompleteAccount[], - }); - } - }, [loading, data, dispatch]); + }, [push, authData, cookieParam]); return null; }; diff --git a/src/components/adminSwitch/AdminSwitch.tsx b/src/components/adminSwitch/AdminSwitch.tsx deleted file mode 100644 index 11da7c61..00000000 --- a/src/components/adminSwitch/AdminSwitch.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import React from 'react'; -import { useAccountState, CLIENT_ACCOUNT } from 'src/context/AccountContext'; - -export const AdminSwitch: React.FC = ({ children }) => { - const { account, session } = useAccountState(); - - if (account?.type === CLIENT_ACCOUNT) { - if (!account.admin && !session) { - return null; - } - } - - return <>{children}; -}; diff --git a/src/components/auth/Auth.styled.tsx b/src/components/auth/Auth.styled.tsx deleted file mode 100644 index 56d500e6..00000000 --- a/src/components/auth/Auth.styled.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import styled from 'styled-components'; -import { Sub4Title } from '../generic/Styled'; -import { fontColors, textColor } from '../../styles/Themes'; - -export const Line = styled.div` - margin: 16px 0; -`; - -export const StyledTitle = styled(Sub4Title)` - text-align: left; - width: 100%; - margin-bottom: 0px; -`; - -export const CheckboxText = styled.div` - font-size: 13px; - color: ${fontColors.grey7}; - text-align: justify; -`; - -export const StyledContainer = styled.div` - color: ${textColor}; - display: flex; - justify-content: flex-start; - align-items: center; - padding-right: 32px; - margin: 32px 0 8px; -`; - -export const FixedWidth = styled.div` - height: 18px; - width: 18px; - margin: 0px; - margin-right: 8px; -`; - -export const QRTextWrapper = styled.div` - display: flex; - margin: 16px 0; - flex-direction: column; - align-items: center; - justify-content: center; -`; diff --git a/src/components/auth/checks/AdminCheck.tsx b/src/components/auth/checks/AdminCheck.tsx deleted file mode 100644 index 6bbe0398..00000000 --- a/src/components/auth/checks/AdminCheck.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import React from 'react'; -import ScaleLoader from 'react-spinners/ScaleLoader'; -import { X, Check } from 'react-feather'; -import { getAuthObj } from 'src/utils/auth'; -import { useGetCanAdminQuery } from 'src/graphql/queries/__generated__/adminCheck.generated'; -import { SingleLine, Sub4Title } from '../../generic/Styled'; -import { themeColors } from '../../../styles/Themes'; - -type AdminProps = { - host: string; - admin: string; - cert?: string; - setChecked: (state: boolean) => void; -}; - -export const AdminCheck: React.FC = ({ - host, - admin, - cert, - setChecked, -}) => { - const { data, loading } = useGetCanAdminQuery({ - fetchPolicy: 'network-only', - skip: !admin, - variables: { auth: getAuthObj(host, undefined, admin, cert) }, - onError: () => { - setChecked(false); - }, - onCompleted: () => { - setChecked(true); - }, - }); - - const content = () => { - if (loading) { - return ; - } - if (data?.adminCheck) { - return ; - } - return ; - }; - - return ( - - Admin Macaroon - {content()} - - ); -}; diff --git a/src/components/auth/checks/ViewCheck.tsx b/src/components/auth/checks/ViewCheck.tsx deleted file mode 100644 index 91dc555a..00000000 --- a/src/components/auth/checks/ViewCheck.tsx +++ /dev/null @@ -1,155 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import ScaleLoader from 'react-spinners/ScaleLoader'; -import { Check, X } from 'react-feather'; -import { getAuthObj } from 'src/utils/auth'; -import { useGetCanConnectQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; -import { themeColors } from '../../../styles/Themes'; -import { SingleLine, Sub4Title, Separation } from '../../generic/Styled'; -import { ColorButton } from '../../buttons/colorButton/ColorButton'; -import { Text } from '../../typography/Styled'; -import { AdminCheck } from './AdminCheck'; - -type ViewProps = { - host: string; - admin?: string; - viewOnly?: string; - cert?: string; - adminChecked: boolean; - callback: () => void; - setAdminChecked: (state: boolean) => void; - handleConnect: () => void; - setName: (name: string) => void; -}; - -export const ViewCheck = ({ - host, - admin, - viewOnly, - cert, - adminChecked, - setAdminChecked, - handleConnect, - callback, - setName, -}: ViewProps) => { - const [confirmed, setConfirmed] = useState(false); - - const { data, loading } = useGetCanConnectQuery({ - fetchPolicy: 'network-only', - variables: { - auth: getAuthObj(host, viewOnly, admin, cert), - }, - onCompleted: () => setConfirmed(true), - onError: () => setConfirmed(false), - }); - - useEffect(() => { - if (!loading && data && data.getNodeInfo) { - setName(data.getNodeInfo.alias); - } - }, [loading, data, setName]); - - const content = () => { - if (loading) { - return ; - } - if (data?.getNodeInfo?.alias) { - return ; - } - return ; - }; - - const renderInfo = () => { - if (!loading && data && data.getNodeInfo) { - return ( - <> - - Alias - {data.getNodeInfo.alias} - - - Synced To Chain - - {data.getNodeInfo.is_synced_to_chain ? 'Yes' : 'No'} - - - - Version - {data.getNodeInfo.version.split(' ')[0]} - - - Active Channels - {data.getNodeInfo.active_channels_count} - - - Pending Channels - {data.getNodeInfo.pending_channels_count} - - - Closed Channels - {data.getNodeInfo.closed_channels_count} - - - - ); - } - return null; - }; - - const renderTitle = () => { - if (!confirmed) { - return 'Go Back'; - } - if (adminChecked && !viewOnly && admin) { - return 'Connect (Admin-Only)'; - } - if (!adminChecked && viewOnly) { - return 'Connect (View-Only)'; - } - if (!adminChecked && admin) { - return 'Connect (View-Only)'; - } - return 'Connect'; - }; - - const renderText = () => ( - - Failed to connect to node. Please verify the information provided. - - ); - - return ( - <> - {renderInfo()} - {!confirmed && !loading && renderText()} - - {viewOnly ? 'View-Only Macaroon' : 'Connected'} - {content()} - - {admin && confirmed && ( - - )} - { - if (confirmed) { - handleConnect(); - } else { - callback(); - } - }} - > - {renderTitle()} - - - ); -}; diff --git a/src/components/auth/index.tsx b/src/components/auth/index.tsx deleted file mode 100644 index 62fd15b5..00000000 --- a/src/components/auth/index.tsx +++ /dev/null @@ -1,169 +0,0 @@ -import React, { useState } from 'react'; -import dynamic from 'next/dynamic'; -import AES from 'crypto-js/aes'; -import { useRouter } from 'next/router'; -import { toast } from 'react-toastify'; -import { - useAccountState, - useAccountDispatch, -} from 'src/context/AccountContext'; -import { getAccountId } from '../../utils/auth'; -import { useStatusDispatch } from '../../context/StatusContext'; -import { LoadingCard } from '../loading/LoadingCard'; -import { appendBasePath } from '../../utils/basePath'; -import { useChatDispatch } from '../../context/ChatContext'; -import { ViewCheck } from './checks/ViewCheck'; -import { BTCLoginForm } from './views/BTCLogin'; -import { ConnectLoginForm } from './views/ConnectLogin'; -import { LoginForm } from './views/NormalLogin'; - -const PasswordInput = dynamic(() => import('./views/Password'), { - ssr: false, - loading: function Loading() { - return ; - }, -}); - -type AuthProps = { - type: string; - status: string; - callback: () => void; - setStatus: (state: string) => void; -}; - -export const Auth = ({ type, status, callback, setStatus }: AuthProps) => { - const { accounts } = useAccountState(); - const { push } = useRouter(); - - const dispatch = useStatusDispatch(); - const dispatchChat = useChatDispatch(); - const dispatchAccount = useAccountDispatch(); - - const [name, setName] = useState(); - const [host, setHost] = useState(); - const [admin, setAdmin] = useState(); - const [viewOnly, setViewOnly] = useState(); - const [cert, setCert] = useState(); - const [password, setPassword] = useState(); - - const [adminChecked, setAdminChecked] = useState(false); - - const handleSet = ({ - host, - admin, - viewOnly, - cert, - }: { - host?: string; - admin?: string; - viewOnly?: string; - cert?: string; - }) => { - const id = getAccountId( - host ?? '', - viewOnly ?? '', - admin ?? '', - cert ?? '' - ); - - const accountExists = accounts - ? accounts.filter(account => account.id === id).length > 0 - : false; - - if (accountExists) { - toast.error('Account already exists.'); - } else if (!host) { - toast.error('A host url is needed to connect.'); - } else if (!admin && !viewOnly) { - toast.error('View-Only or Admin macaroon are needed to connect.'); - } else { - host && setHost(host); - admin && setAdmin(admin); - viewOnly && setViewOnly(viewOnly); - cert && setCert(cert); - - setStatus('confirmNode'); - } - }; - - const handleSave = () => { - if (!host) { - toast.error('A host url is needed to connect.'); - } else if (!admin && !viewOnly) { - toast.error('View-Only or Admin macaroon are needed to connect.'); - } else { - let correctViewOnly = viewOnly || null; - if (!viewOnly && admin && !password) { - correctViewOnly = admin; - } - - const encryptedAdmin = - admin && password ? AES.encrypt(admin, password).toString() : null; - - dispatch({ type: 'disconnected' }); - dispatchChat({ type: 'disconnected' }); - dispatchAccount({ - type: 'addAccountAndSave', - accountToAdd: { - name: name || '', - host, - admin: encryptedAdmin || '', - viewOnly: correctViewOnly || '', - cert: cert || '', - }, - ...(!correctViewOnly && { session: admin }), - }); - - push(appendBasePath('/home')); - } - }; - - const handleConnect = () => { - if (adminChecked) { - setStatus('password'); - } else { - handleSave(); - } - }; - - const renderView = () => { - switch (type) { - case 'login': - return ; - case 'connect': - return ; - default: - return ; - } - }; - - return ( - <> - {status === 'none' && renderView()} - {status === 'confirmNode' && host && ( - - )} - {status === 'password' && ( - { - handleSave(); - setStatus('none'); - }} - loading={false} - /> - )} - - ); -}; diff --git a/src/components/auth/views/BTCLogin.tsx b/src/components/auth/views/BTCLogin.tsx deleted file mode 100644 index 34079bb0..00000000 --- a/src/components/auth/views/BTCLogin.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import React, { useState } from 'react'; -import { toast } from 'react-toastify'; -import { getConfigLnd } from '../../../utils/auth'; -import { Input } from '../../input/Input'; -import { Line, StyledTitle } from '../Auth.styled'; -import { RiskCheckboxAndConfirm } from './Checkboxes'; - -interface AuthProps { - handleSet: ({ - host, - admin, - viewOnly, - cert, - }: { - host?: string; - admin?: string; - viewOnly?: string; - cert?: string; - }) => void; -} - -export const BTCLoginForm = ({ handleSet }: AuthProps) => { - const [json, setJson] = useState(''); - const [checked, setChecked] = useState(false); - - const handleClick = () => { - try { - JSON.parse(json); - const { cert, admin, viewOnly, host } = getConfigLnd(json); - handleSet({ host, admin, viewOnly, cert }); - } catch (error) { - toast.error('Invalid JSON'); - } - }; - - const canConnect = json !== '' && checked; - return ( - <> - - BTCPayServer Connect JSON: - setJson(e.target.value)} /> - - - - ); -}; diff --git a/src/components/auth/views/Checkboxes.tsx b/src/components/auth/views/Checkboxes.tsx deleted file mode 100644 index 9e264ccf..00000000 --- a/src/components/auth/views/Checkboxes.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react'; -import { Checkbox } from '../../checkbox/Checkbox'; -import { CheckboxText } from '../Auth.styled'; -import { ColorButton } from '../../buttons/colorButton/ColorButton'; - -type CheckboxProps = { - handleClick: () => void; - disabled: boolean; - checked: boolean; - onChange: (state: boolean) => void; -}; - -export const RiskCheckboxAndConfirm = ({ - handleClick, - disabled, - checked, - onChange, -}: CheckboxProps) => ( - <> - - - {`I'm feeling reckless. Lightning, LND and ThunderHub are under constant development and I understand that there is always a risk of losing funds.`} - - - - Connect - - -); diff --git a/src/components/auth/views/ConnectLogin.tsx b/src/components/auth/views/ConnectLogin.tsx deleted file mode 100644 index 5d701149..00000000 --- a/src/components/auth/views/ConnectLogin.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import React, { useState } from 'react'; -import { getAuthLnd, getBase64CertfromDerFormat } from '../../../utils/auth'; -import { Input } from '../../input/Input'; -import { Line, StyledTitle } from '../Auth.styled'; -import { RiskCheckboxAndConfirm } from './Checkboxes'; - -interface AuthProps { - handleSet: ({ - host, - admin, - viewOnly, - cert, - }: { - host?: string; - admin?: string; - viewOnly?: string; - cert?: string; - }) => void; -} - -export const ConnectLoginForm = ({ handleSet }: AuthProps) => { - const [url, setUrl] = useState(''); - const [checked, setChecked] = useState(false); - - const handleClick = () => { - const { cert, macaroon, socket } = getAuthLnd(url); - const base64Cert = getBase64CertfromDerFormat(cert) || ''; - - handleSet({ - host: socket, - admin: macaroon, - cert: base64Cert, - }); - }; - - const canConnect = url !== '' && checked; - - return ( - <> - - LND Connect Url: - setUrl(e.target.value)} /> - - - - ); -}; diff --git a/src/components/auth/views/NormalLogin.tsx b/src/components/auth/views/NormalLogin.tsx deleted file mode 100644 index 6d0fe15f..00000000 --- a/src/components/auth/views/NormalLogin.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import React, { useState } from 'react'; -import { Input } from '../../input/Input'; -import { Line, StyledTitle } from '../Auth.styled'; -import { SingleLine, Sub4Title } from '../../generic/Styled'; -import { - MultiButton, - SingleButton, -} from '../../buttons/multiButton/MultiButton'; -import { RiskCheckboxAndConfirm } from './Checkboxes'; - -interface AuthProps { - handleSet: ({ - host, - admin, - viewOnly, - cert, - }: { - host?: string; - admin?: string; - viewOnly?: string; - cert?: string; - }) => void; -} - -export const LoginForm = ({ handleSet }: AuthProps) => { - const [isViewOnly, setIsViewOnly] = useState(true); - const [checked, setChecked] = useState(false); - - const [host, setHost] = useState(''); - const [admin, setAdmin] = useState(''); - const [viewOnly, setRead] = useState(''); - const [cert, setCert] = useState(''); - - const handleClick = () => { - handleSet({ host, admin, viewOnly, cert }); - }; - - const canConnect = - host !== '' && (admin !== '' || viewOnly !== '') && checked; - return ( - <> - - Type of Account: - - setIsViewOnly(true)} - > - ViewOnly - - setIsViewOnly(false)} - > - Admin - - - - - {'Url (host:grpc port):'} - setHost(e.target.value)} - /> - - {!isViewOnly && ( - - Admin: - setAdmin(e.target.value)} - /> - - )} - - - {!isViewOnly ? 'Readonly (optional):' : 'Readonly:'} - - setRead(e.target.value)} - /> - - - Certificate: - setCert(e.target.value)} - /> - - - - ); -}; diff --git a/src/components/auth/views/Password.tsx b/src/components/auth/views/Password.tsx deleted file mode 100644 index 5c895274..00000000 --- a/src/components/auth/views/Password.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import React, { useState } from 'react'; -import zxcvbn from 'zxcvbn'; -import getConfig from 'next/config'; -import { Sub4Title, SubTitle, DarkSubTitle } from '../../generic/Styled'; -import { ColorButton } from '../../buttons/colorButton/ColorButton'; -import { Input } from '../../input/Input'; -import { Line, CheckboxText } from '../Auth.styled'; -import { LoadingBar } from '../../loadingBar/LoadingBar'; -import { Checkbox } from '../../checkbox/Checkbox'; - -interface PasswordProps { - isPass?: string; - setPass: (pass: string) => void; - callback: () => void; - loading: boolean; -} - -const { publicRuntimeConfig } = getConfig(); -const { nodeEnv } = publicRuntimeConfig; - -const PasswordInput = ({ - isPass = '', - setPass, - callback, - loading = false, -}: PasswordProps) => { - const [checked, setChecked] = useState(false); - const strength = (100 * Math.min(zxcvbn(isPass).guesses_log10, 40)) / 40; - const needed = nodeEnv === 'development' ? 1 : checked ? 10 : 20; - - return ( - <> - Please Input a Password - - This password will be used to encrypt your admin macaroon. - - - Password: - setPass(e.target.value)} /> - - - Strength: - - - - - - {'Disable Strong Password Check (Not Recommended)'} - - - - - Connect - - - ); -}; - -export default PasswordInput; diff --git a/src/components/buttons/secureButton/LoginModal.tsx b/src/components/buttons/secureButton/LoginModal.tsx deleted file mode 100644 index 7436febd..00000000 --- a/src/components/buttons/secureButton/LoginModal.tsx +++ /dev/null @@ -1,104 +0,0 @@ -import React, { useState } from 'react'; -import CryptoJS from 'crypto-js'; -import { toast } from 'react-toastify'; -import { ChevronRight } from 'react-feather'; -import { - useAccountState, - useAccountDispatch, -} from 'src/context/AccountContext'; -import { getAuthFromAccount } from 'src/context/helpers/context'; -import { - Sub4Title, - NoWrapTitle, - SubTitle, - ResponsiveLine, -} from '../../generic/Styled'; -import { ColorButton } from '../colorButton/ColorButton'; -import { Input } from '../../input/Input'; -import { MultiButton, SingleButton } from '../multiButton/MultiButton'; - -interface LoginProps { - macaroon: string; - color?: string; - callback: (variables: {}) => void; - variables: {}; - setModalOpen: (value: boolean) => void; -} - -export const LoginModal = ({ - macaroon, - color, - setModalOpen, - callback, - variables, -}: LoginProps) => { - const [pass, setPass] = useState(''); - const [storeSession, setStoreSession] = useState(false); - - const { account } = useAccountState(); - const dispatch = useAccountDispatch(); - - const handleClick = () => { - try { - const bytes = CryptoJS.AES.decrypt(macaroon, pass); - const decrypted = bytes.toString(CryptoJS.enc.Utf8); - - if (storeSession) { - dispatch({ type: 'addSession', session: decrypted }); - } - - callback({ - variables: { - ...variables, - auth: getAuthFromAccount(account, decrypted), - }, - }); - - setModalOpen(false); - } catch (error) { - toast.error('Wrong Password'); - } - }; - - const renderButton = ( - onClick: () => void, - text: string, - selected: boolean - ) => ( - - {text} - - ); - - return ( - <> - Unlock your Account - - Password: - setPass(e.target.value)} - /> - - - {`Don't ask me again this session:`} - - {renderButton(() => setStoreSession(true), 'Yes', storeSession)} - {renderButton(() => setStoreSession(false), 'No', !storeSession)} - - - - Unlock - - - - ); -}; diff --git a/src/components/buttons/secureButton/SecureButton.tsx b/src/components/buttons/secureButton/SecureButton.tsx deleted file mode 100644 index cc1368e5..00000000 --- a/src/components/buttons/secureButton/SecureButton.tsx +++ /dev/null @@ -1,75 +0,0 @@ -import React, { useState } from 'react'; -import { useAccountState, CLIENT_ACCOUNT } from 'src/context/AccountContext'; -import { getAuthFromAccount } from 'src/context/helpers/context'; -import Modal from '../../modal/ReactModal'; -import { ColorButton, ColorButtonProps } from '../colorButton/ColorButton'; -import { LoginModal } from './LoginModal'; - -interface SecureButtonProps extends ColorButtonProps { - callback: (variables: {}) => void; - disabled: boolean; - variables: {}; - color?: string; - withMargin?: string; - mobileMargin?: string; - arrow?: boolean; -} - -export const SecureButton: React.FC = ({ - callback, - color, - disabled, - children, - variables, - ...props -}) => { - const [modalOpen, setModalOpen] = useState(false); - - const { session, account } = useAccountState(); - - if (!account) { - return null; - } - - if ( - account && - account.type === CLIENT_ACCOUNT && - !account.admin && - !session - ) { - return null; - } - - const auth = getAuthFromAccount(account, session); - - const handleClick = () => setModalOpen(true); - - const onClick = - session || account.type !== CLIENT_ACCOUNT - ? () => callback({ variables: { ...variables, auth } }) - : handleClick; - - return ( - <> - - {children} - - {account.type === CLIENT_ACCOUNT && ( - setModalOpen(false)}> - - - )} - - ); -}; diff --git a/src/components/buttons/secureButton/SecureWrapper.tsx b/src/components/buttons/secureButton/SecureWrapper.tsx deleted file mode 100644 index a331094e..00000000 --- a/src/components/buttons/secureButton/SecureWrapper.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import React, { useState } from 'react'; -import { useAccountState, CLIENT_ACCOUNT } from 'src/context/AccountContext'; -import { getAuthFromAccount } from 'src/context/helpers/context'; -import Modal from '../../modal/ReactModal'; -import { LoginModal } from './LoginModal'; - -interface SecureButtonProps { - callback: (variables: {}) => void; - variables: {}; - color?: string; -} - -export const SecureWrapper: React.FC = ({ - callback, - children, - variables, - color, -}) => { - const [modalOpen, setModalOpen] = useState(false); - - const { account, session } = useAccountState(); - - if (!account) { - return null; - } - - if (account.type === CLIENT_ACCOUNT && !account.admin && !session) { - return null; - } - - const auth = getAuthFromAccount(account, session); - - const handleClick = () => setModalOpen(true); - - const onClick = - session || account.type !== CLIENT_ACCOUNT - ? () => callback({ variables: { ...variables, auth } }) - : handleClick; - - return ( - <> -
- {children} -
- {account.type === CLIENT_ACCOUNT && ( - setModalOpen(false)}> - - - )} - - ); -}; diff --git a/src/components/chat/ChatFetcher.tsx b/src/components/chat/ChatFetcher.tsx index 57db60a2..a07f1303 100644 --- a/src/components/chat/ChatFetcher.tsx +++ b/src/components/chat/ChatFetcher.tsx @@ -1,10 +1,9 @@ import * as React from 'react'; import { toast } from 'react-toastify'; import { useRouter } from 'next/router'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetMessagesQuery } from 'src/graphql/queries/__generated__/getMessages.generated'; -import { useStatusState } from 'src/context/StatusContext'; import { MessagesType } from 'src/graphql/types'; +import { useAccount } from 'src/hooks/UseAccount'; import { useChatState, useChatDispatch } from '../../context/ChatContext'; import { getErrorContent } from '../../utils/error'; import { useConfigState } from '../../context/ConfigContext'; @@ -14,8 +13,7 @@ export const ChatFetcher: React.FC = () => { const { chatPollingSpeed } = useConfigState(); - const { connected } = useStatusState(); - const { auth } = useAccountState(); + const account = useAccount(); const { pathname } = useRouter(); const { lastChat, chats, sentChats, initialized } = useChatState(); const dispatch = useChatDispatch(); @@ -24,10 +22,10 @@ export const ChatFetcher: React.FC = () => { const { data, loading, error } = useGetMessagesQuery({ ssr: false, - skip: !auth || initialized || noChatsAvailable || !connected, + skip: initialized || noChatsAvailable || !account, pollInterval: chatPollingSpeed, fetchPolicy: 'network-only', - variables: { auth, initialize: !noChatsAvailable }, + variables: { initialize: !noChatsAvailable }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/components/chat/ChatInit.tsx b/src/components/chat/ChatInit.tsx index 9bd3853a..48d44f0f 100644 --- a/src/components/chat/ChatInit.tsx +++ b/src/components/chat/ChatInit.tsx @@ -1,23 +1,24 @@ import * as React from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetMessagesLazyQuery } from 'src/graphql/queries/__generated__/getMessages.generated'; import { MessagesType } from 'src/graphql/types'; +import { useAccount } from 'src/hooks/UseAccount'; import { useChatDispatch } from '../../context/ChatContext'; import { getErrorContent } from '../../utils/error'; export const ChatInit: React.FC = () => { - const { auth, account } = useAccountState(); const dispatch = useChatDispatch(); const [ getMessages, { data: initData, loading: initLoading, error: initError }, ] = useGetMessagesLazyQuery({ - variables: { auth, initialize: true }, + variables: { initialize: true }, onError: error => toast.error(getErrorContent(error)), }); + const account = useAccount(); + React.useEffect(() => { if (account) { const storageChats = diff --git a/src/components/gridWrapper/GridWrapper.tsx b/src/components/gridWrapper/GridWrapper.tsx index c890cd42..ca1df263 100644 --- a/src/components/gridWrapper/GridWrapper.tsx +++ b/src/components/gridWrapper/GridWrapper.tsx @@ -2,12 +2,10 @@ import React from 'react'; import styled, { css } from 'styled-components'; import { BitcoinFees } from 'src/components/bitcoinInfo/BitcoinFees'; import { BitcoinPrice } from 'src/components/bitcoinInfo/BitcoinPrice'; -import { useAccountState } from 'src/context/AccountContext'; import { mediaWidths } from '../../styles/Themes'; import { Section } from '../section/Section'; import { Navigation } from '../../layouts/navigation/Navigation'; import { StatusCheck } from '../statusCheck/StatusCheck'; -import { LoadingCard } from '../loading/LoadingCard'; import { ServerAccounts } from '../accounts/ServerAccounts'; type GridProps = { @@ -38,24 +36,15 @@ const ContentStyle = styled.div` export const GridWrapper: React.FC = ({ children, noNavigation, -}) => { - const { hasAccount, auth } = useAccountState(); - const renderContent = () => { - if (hasAccount === 'false') { - return ; - } - return children; - }; - return ( -
- - - - - {auth && } - {!noNavigation && } - {renderContent()} - -
- ); -}; +}) => ( +
+ + + + + + {!noNavigation && } + {children} + +
+); diff --git a/src/components/modal/closeChannel/CloseChannel.tsx b/src/components/modal/closeChannel/CloseChannel.tsx index a9cc6fa4..faa240b8 100644 --- a/src/components/modal/closeChannel/CloseChannel.tsx +++ b/src/components/modal/closeChannel/CloseChannel.tsx @@ -10,7 +10,6 @@ import { Sub4Title, } from '../../generic/Styled'; import { getErrorContent } from '../../../utils/error'; -import { SecureButton } from '../../buttons/secureButton/SecureButton'; import { ColorButton } from '../../buttons/colorButton/ColorButton'; import { MultiButton, @@ -48,7 +47,7 @@ export const CloseChannel = ({ const [amount, setAmount] = useState(0); const [isConfirmed, setIsConfirmed] = useState(false); - const [closeChannel] = useCloseChannelMutation({ + const [closeChannel, { loading }] = useCloseChannelMutation({ onCompleted: data => { if (data.closeChannel) { toast.success('Channel Closed'); @@ -79,23 +78,27 @@ export const CloseChannel = ({ Are you sure you want to close the channel? - + closeChannel({ + variables: { + id: channelId, + forceClose: isForce, + ...(isType !== 'none' + ? isType === 'fee' + ? { tokens: amount } + : { target: amount } + : {}), + }, + }) + } > {`Close Channel [ ${channelName}/${channelId} ]`} - + Cancel diff --git a/src/components/modal/removePeer/RemovePeer.tsx b/src/components/modal/removePeer/RemovePeer.tsx index db081327..6471743a 100644 --- a/src/components/modal/removePeer/RemovePeer.tsx +++ b/src/components/modal/removePeer/RemovePeer.tsx @@ -5,7 +5,6 @@ import { toast } from 'react-toastify'; import { useRemovePeerMutation } from 'src/graphql/mutations/__generated__/removePeer.generated'; import { SubTitle } from '../../generic/Styled'; import { getErrorContent } from '../../../utils/error'; -import { SecureButton } from '../../buttons/secureButton/SecureButton'; import { ColorButton } from '../../buttons/colorButton/ColorButton'; interface RemovePeerProps { @@ -42,17 +41,17 @@ export const RemovePeerModal = ({ Are you sure you want to remove this peer? - { + removePeer({ variables: { publicKey } }); }} color={'red'} disabled={loading} + loading={loading} withMargin={'4px'} > {`Remove Peer [${peerAlias || publicKey?.substring(0, 6)}]`} - + Cancel diff --git a/src/components/nodeInfo/NodeBar.tsx b/src/components/nodeInfo/NodeBar.tsx deleted file mode 100644 index 2cf8798e..00000000 --- a/src/components/nodeInfo/NodeBar.tsx +++ /dev/null @@ -1,93 +0,0 @@ -import * as React from 'react'; -import { HelpCircle } from 'react-feather'; -import styled from 'styled-components'; -import ReactTooltip from 'react-tooltip'; -import { - useAccountState, - CLIENT_ACCOUNT, - AccountType, -} from 'src/context/AccountContext'; -import { CardWithTitle, SubTitle } from '../generic/Styled'; -import { useConfigState } from '../../context/ConfigContext'; -import { - ArrowLeft, - ArrowRight, - StyledNodeBar, - NodeBarContainer, -} from './NodeInfo.styled'; -import { NodeCard } from './NodeCard'; - -const StyledQuestion = styled(HelpCircle)` - margin-left: 8px; -`; - -export const NodeBar = () => { - const { accounts } = useAccountState(); - const { multiNodeInfo } = useConfigState(); - const slider = React.useRef(null); - - const viewOnlyAccounts = accounts.filter( - account => account.type === CLIENT_ACCOUNT && account.viewOnly !== '' - ) as AccountType[]; - - const handleScroll = (decrease?: boolean) => { - if (slider.current !== null) { - if (decrease) { - slider.current.scrollLeft -= 240; - } else { - slider.current.scrollLeft += 240; - } - } - }; - - if (viewOnlyAccounts.length <= 1 || !multiNodeInfo) { - return null; - } - - return ( - - - Your Nodes - - - - - -
{ - handleScroll(true); - }} - onKeyDown={() => { - handleScroll(true); - }} - tabIndex={0} - > - -
-
{ - handleScroll(); - }} - onKeyDown={() => { - handleScroll(); - }} - tabIndex={-1} - > - -
- - {viewOnlyAccounts.map(account => ( - - - - ))} - -
- - Only accounts with a view-only macaroon will appear here. - -
- ); -}; diff --git a/src/components/nodeInfo/NodeCard.tsx b/src/components/nodeInfo/NodeCard.tsx deleted file mode 100644 index 7b6211f3..00000000 --- a/src/components/nodeInfo/NodeCard.tsx +++ /dev/null @@ -1,131 +0,0 @@ -import React, { useState } from 'react'; -import { useInView } from 'react-intersection-observer'; -import 'intersection-observer'; // Polyfill -import ScaleLoader from 'react-spinners/ScaleLoader'; -import { useGetNodeInfoQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; -import { AccountType } from 'src/context/AccountContext'; -import { SingleLine, DarkSubTitle, ResponsiveLine } from '../generic/Styled'; -import { themeColors } from '../../styles/Themes'; -import { Price } from '../price/Price'; -import Modal from '../modal/ReactModal'; -import { getAuthObj } from '../../utils/auth'; -import { StatusDot, StatusLine, QuickCard } from './NodeInfo.styled'; -import { NodeInfoModal } from './NodeInfoModal'; - -export const getStatusDot = (status: boolean) => { - return status ? : ; -}; - -interface NodeCardProps { - account: AccountType; - accountId: string; -} - -export const NodeCard = ({ account, accountId }: NodeCardProps) => { - const [isOpen, setIsOpen] = useState(false); - - const { host, viewOnly, cert } = account; - const [ref, inView] = useInView({ - threshold: 0, - triggerOnce: true, - }); - - const auth = getAuthObj(host, viewOnly, undefined, cert); - - const { data, loading, error } = useGetNodeInfoQuery({ - ssr: false, - skip: !inView || !auth, - variables: { auth }, - pollInterval: 10000, - }); - - if (error) { - return null; - } - - const renderContent = () => { - if (!inView) { - return ( - <> - {getStatusDot(false)} -
-
- - Lightning -
-
-
- - Bitcoin -
-
-
- - Channels -
-
-
- - ); - } - if ( - loading || - !data?.getNodeInfo || - !data?.getChannelBalance || - !data?.getChainBalance || - !data?.getPendingChainBalance - ) { - return ; - } - - const { - active_channels_count: active, - closed_channels_count: closed, - alias, - pending_channels_count: pending, - is_synced_to_chain, - } = data.getNodeInfo; - - const { confirmedBalance, pendingBalance } = data.getChannelBalance; - - const chainBalance = data.getChainBalance; - const pendingChainBalance = data.getPendingChainBalance; - - return ( - <> - {getStatusDot(is_synced_to_chain)} -
{alias}
- - Lightning - - - - Bitcoin - - - - Channels -
{`${active} / ${pending} / ${closed}`}
-
- - ); - }; - - return ( - <> - { - setIsOpen(true); - }} - ref={ref} - key={account.id} - > - {renderContent()} - - { - setIsOpen(false); - }} - > - - - - ); -}; diff --git a/src/components/nodeInfo/NodeInfo.styled.tsx b/src/components/nodeInfo/NodeInfo.styled.tsx deleted file mode 100644 index 8fafef75..00000000 --- a/src/components/nodeInfo/NodeInfo.styled.tsx +++ /dev/null @@ -1,105 +0,0 @@ -import styled, { css } from 'styled-components'; -import { ChevronLeft, ChevronRight } from 'react-feather'; -import { Card } from '../generic/Styled'; -import { - inverseTextColor, - buttonBorderColor, - textColor, - mediaWidths, -} from '../../styles/Themes'; - -const arrowCSS = css` - background-color: ${inverseTextColor}; - height: 32px; - width: 32px; - position: absolute; - z-index: 2; - top: 50%; - display: none; - border-radius: 4px; - box-shadow: 0 8px 16px -8px rgba(0, 0, 0, 0.1); - border: 1px solid ${buttonBorderColor}; - cursor: pointer; - - &:hover { - border: 1px solid ${textColor}; - } -`; - -export const ArrowLeft = styled(ChevronLeft)` - ${arrowCSS} - transform: translate(-30%, -50%); -`; - -export const ArrowRight = styled(ChevronRight)` - ${arrowCSS} - transform: translate(30%, -50%); - right: 0; -`; - -export const NodeBarContainer = styled.div` - position: relative; - margin-bottom: 24px; - &:hover { - ${ArrowLeft} { - display: inline-block; - } - ${ArrowRight} { - display: inline-block; - } - } -`; - -export const StyledNodeBar = styled.div` - display: flex; - overflow-x: scroll; - -ms-overflow-style: none; - cursor: pointer; - ::-webkit-scrollbar { - display: none; - } -`; - -const sectionColor = '#69c0ff'; - -export const QuickCard = styled(Card)` - height: 120px; - width: 240px; - min-width: 240px; - display: flex; - flex-direction: column; - justify-content: center; - align-items: stretch; - margin-bottom: 0px; - padding: 10px; - margin-right: 10px; - cursor: pointer; - - @media (${mediaWidths.mobile}) { - height: unset; - width: 160px; - min-width: 160px; - } - - &:hover { - border: 1px solid ${sectionColor}; - } -`; - -export const StatusLine = styled.div` - width: 100%; - position: relative; - right: -8px; - top: -8px; - display: flex; - justify-content: flex-end; - margin: 0 0 -8px 0; -`; - -export const StatusDot = styled.div` - margin: 0 2px; - height: 8px; - width: 8px; - border-radius: 100%; - background-color: ${({ color }: { color: string }) => color}; -`; diff --git a/src/components/nodeInfo/NodeInfoModal.tsx b/src/components/nodeInfo/NodeInfoModal.tsx deleted file mode 100644 index 65198d40..00000000 --- a/src/components/nodeInfo/NodeInfoModal.tsx +++ /dev/null @@ -1,108 +0,0 @@ -import React from 'react'; -import { useAccountDispatch } from 'src/context/AccountContext'; -import { GetNodeInfoQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; -import { NodeInfoType, ChannelBalanceType } from 'src/graphql/types'; -import { - SubTitle, - SingleLine, - DarkSubTitle, - Sub4Title, - Separation, -} from '../generic/Styled'; -import { Price } from '../price/Price'; -import { ColorButton } from '../buttons/colorButton/ColorButton'; -import { useStatusDispatch } from '../../context/StatusContext'; - -interface NodeInfoModalProps { - account: GetNodeInfoQuery | null | undefined; - accountId: string; -} - -export const NodeInfoModal = ({ account, accountId }: NodeInfoModalProps) => { - const dispatch = useStatusDispatch(); - - const dispatchAccount = useAccountDispatch(); - - if (!account) { - return null; - } - - const { - active_channels_count, - closed_channels_count, - alias, - pending_channels_count, - is_synced_to_chain, - peers_count, - version, - } = account.getNodeInfo as NodeInfoType; - - const { - confirmedBalance, - pendingBalance, - } = account.getChannelBalance as ChannelBalanceType; - - const chainBalance = account.getChainBalance; - const pendingChainBalance = account.getPendingChainBalance; - - return ( - <> - {alias} - - - Version: -
{version.split(' ')[0]}
-
- - Is Synced: -
{is_synced_to_chain ? 'True' : 'False'}
-
- - Peer Count: -
{peers_count}
-
- - Active Channels: -
{active_channels_count}
-
- - Pending Channels: -
{pending_channels_count}
-
- - Closed Channels: -
{closed_channels_count}
-
- Lightning - - Balance: - - - - Pending: - - - Bitcoin - - Balance: - - - - Pending: - - - { - dispatch({ - type: 'disconnected', - }); - dispatchAccount({ type: 'changeAccount', changeId: accountId }); - }} - > - Change to this Account - - - ); -}; diff --git a/src/components/stateViews/StateCards.tsx b/src/components/stateViews/StateCards.tsx deleted file mode 100644 index 6ebfb131..00000000 --- a/src/components/stateViews/StateCards.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import React from 'react'; -import ScaleLoader from 'react-spinners/ScaleLoader'; -import styled from 'styled-components'; -import { SubTitle, Card } from '../generic/Styled'; -import { themeColors, mediaWidths, fontColors } from '../../styles/Themes'; -import { SectionTitle } from '../typography/Styled'; -import { CurrentSettings } from '../../views/settings/Current'; -import { AccountSettings } from '../../views/settings/Account'; -import { DangerView } from '../../views/settings/Danger'; - -const FullDiv = styled.div` - display: flex; - flex-direction: column; - justify-content: flex-start; - align-items: center; - width: 100%; - height: 100%; - min-height: 400px; - - @media (${mediaWidths.mobile}) { - justify-content: center; - } -`; - -export const LoadingView = () => ( - - Connecting to your Node - - -); - -const StyledTitle = styled(SectionTitle)` - text-align: center; - margin: 16px 0 32px; -`; - -const StyledSubtitle = styled(SubTitle)` - text-align: center; - margin: 48px 0 4px; -`; - -const StyledParagraph = styled.p` - color: ${fontColors.grey7}; - text-align: center; - margin: 4px 0; -`; - -export const ErrorView = () => ( - <> - - Connection Error - - ThunderHub was unable to connect to your node. - - - {`Please make sure it's online and that the connection details are correct.`} - - - If the problem persists please contact us. - - - - - - -); diff --git a/src/components/statusCheck/StatusCheck.tsx b/src/components/statusCheck/StatusCheck.tsx index f3bf6ec5..d052054e 100644 --- a/src/components/statusCheck/StatusCheck.tsx +++ b/src/components/statusCheck/StatusCheck.tsx @@ -1,7 +1,6 @@ import { useEffect } from 'react'; import { useRouter } from 'next/router'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetNodeInfoQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; import { NodeInfoType, ChannelBalanceType } from 'src/graphql/types'; import { useStatusDispatch, StatusState } from '../../context/StatusContext'; @@ -11,18 +10,16 @@ export const StatusCheck: React.FC = () => { const dispatch = useStatusDispatch(); const { push } = useRouter(); - const { account, auth } = useAccountState(); const { data, loading, error, stopPolling } = useGetNodeInfoQuery({ ssr: false, - skip: !auth, fetchPolicy: 'network-only', - variables: { auth }, + pollInterval: 10000, }); useEffect(() => { if (error) { - account && toast.error(`Unable to connect to ${account.name}`); + toast.error(`Unable to connect to node`); stopPolling(); dispatch({ type: 'disconnected' }); push(appendBasePath('/')); @@ -74,7 +71,7 @@ export const StatusCheck: React.FC = () => { dispatch({ type: 'connected', state }); } - }, [data, dispatch, error, loading, push, account, stopPolling]); + }, [data, dispatch, error, loading, push, stopPolling]); return null; }; diff --git a/src/context/AccountContext.tsx b/src/context/AccountContext.tsx deleted file mode 100644 index cdcadc88..00000000 --- a/src/context/AccountContext.tsx +++ /dev/null @@ -1,317 +0,0 @@ -import * as React from 'react'; -import Cookies from 'js-cookie'; -import { - getAccountById, - deleteAccountById, - addIdAndTypeToAccount, - getAuthFromAccount, -} from './helpers/context'; - -export type SERVER_ACCOUNT_TYPE = 'sso' | 'server' | 'test'; -export type ACCOUNT_TYPE = 'client'; - -export const CLIENT_ACCOUNT: ACCOUNT_TYPE = 'client'; -export const SSO_ACCOUNT: SERVER_ACCOUNT_TYPE = 'sso'; -export const SERVER_ACCOUNT: SERVER_ACCOUNT_TYPE = 'server'; - -type HasAccountType = 'fetched' | 'false' | 'error'; - -export type AuthType = - | { - type: ACCOUNT_TYPE; - host: string; - macaroon: string; - cert: string | null; - } - | { - type: SERVER_ACCOUNT_TYPE; - id: string; - }; - -export type AccountProps = { - name: string; - host: string; - admin: string; - viewOnly: string; - cert: string; -}; - -export type AccountType = { - type: ACCOUNT_TYPE; - id: string; -} & AccountProps; - -export type ServerAccountType = { - type: SERVER_ACCOUNT_TYPE; - id: string; - name: string; - loggedIn?: boolean; -}; - -export type CompleteAccount = AccountType | ServerAccountType; - -export const defaultAuth = { type: SERVER_ACCOUNT, id: '' }; - -type State = { - initialized: boolean; - finishedFetch: boolean; - auth: AuthType; - activeAccount: string | null; - session: string | null; - account: CompleteAccount | null; - accounts: CompleteAccount[]; - hasAccount: HasAccountType; -}; - -type ActionType = - | { - type: 'initialize'; - changeId: string | null; - accountsToAdd: CompleteAccount[]; - session: string | null; - } - | { - type: 'changeAccount' | 'deleteAccount'; - changeId: string; - } - | { - type: 'logout'; - } - | { - type: 'addServerAccounts'; - accountsToAdd: CompleteAccount[]; - } - | { - type: 'addAccountAndSave'; - accountToAdd: AccountProps; - session?: string; - } - | { - type: 'addSession'; - session: string; - } - | { - type: 'removeSession'; - } - | { - type: 'deleteAll'; - } - | { - type: 'resetFetch'; - }; - -type Dispatch = (action: ActionType) => void; - -const StateContext = React.createContext(undefined); -const DispatchContext = React.createContext(undefined); - -const initialState: State = { - initialized: false, - finishedFetch: false, - auth: defaultAuth, - session: null, - activeAccount: null, - account: null, - accounts: [], - hasAccount: 'false', -}; - -const stateReducer = (state: State, action: ActionType): State => { - switch (action.type) { - case 'initialize': { - if (state.initialized) { - return state; - } - const { accountsToAdd, changeId, session } = action; - - const { account, id } = getAccountById(changeId, accountsToAdd); - - if (!account) - return { - ...state, - initialized: true, - accounts: accountsToAdd, - activeAccount: changeId, - session, - }; - - const auth = getAuthFromAccount(account, session); - return { - ...state, - initialized: true, - auth, - account, - accounts: accountsToAdd, - activeAccount: id, - session, - hasAccount: 'fetched', - }; - } - case 'changeAccount': { - const { account, id } = getAccountById(action.changeId, state.accounts); - - if (!account) return state; - - const auth = getAuthFromAccount(account); - - localStorage.setItem('active', `${id}`); - sessionStorage.removeItem('session'); - - return { - ...state, - auth, - session: null, - account, - activeAccount: id, - hasAccount: 'fetched', - }; - } - case 'logout': - localStorage.removeItem('active'); - sessionStorage.clear(); - return { - ...state, - account: null, - activeAccount: null, - auth: defaultAuth, - session: null, - }; - case 'deleteAccount': { - if (!state.accounts || state?.accounts?.length <= 0 || !state.account) { - return state; - } - const { accounts, id } = deleteAccountById( - state.account.id, - action.changeId, - state.accounts - ); - localStorage.setItem('accounts', JSON.stringify(accounts)); - !id && sessionStorage.removeItem('session'); - return { - ...state, - accounts, - ...(!id && { activeId: null, session: null, account: null }), - }; - } - case 'addServerAccounts': { - const clientAccounts = state.accounts.filter( - a => a.type === CLIENT_ACCOUNT - ); - const completeAccounts = [...clientAccounts, ...action.accountsToAdd]; - - if (!state.activeAccount) { - return { - ...state, - finishedFetch: true, - accounts: completeAccounts, - }; - } - - const { account } = getAccountById(state.activeAccount, completeAccounts); - - if (!account && completeAccounts.length > 0) { - return { - ...state, - finishedFetch: true, - accounts: completeAccounts, - hasAccount: 'error', - }; - } - - const auth = getAuthFromAccount(account, state.session); - return { - ...state, - finishedFetch: true, - hasAccount: 'fetched', - auth, - account, - accounts: completeAccounts, - }; - } - case 'addAccountAndSave': { - const account = addIdAndTypeToAccount(action.accountToAdd); - const activeAccount = account.id; - const accounts = [...state.accounts, account]; - - const auth = getAuthFromAccount(account, action.session); - - if (action.session) { - sessionStorage.setItem('session', action.session); - } - - localStorage.setItem('active', `${activeAccount}`); - - const savedAccounts = JSON.parse( - localStorage.getItem('accounts') || '[]' - ); - localStorage.setItem( - 'accounts', - JSON.stringify([...savedAccounts, action.accountToAdd]) - ); - - return { - ...state, - auth, - account, - accounts, - activeAccount, - hasAccount: 'fetched', - ...(action.session && { session: action.session }), - }; - } - case 'addSession': - sessionStorage.setItem('session', action.session); - return { - ...state, - auth: getAuthFromAccount(state.account, action.session), - session: action.session, - }; - case 'removeSession': - sessionStorage.removeItem('session'); - return { - ...state, - auth: getAuthFromAccount(state.account), - session: null, - }; - case 'deleteAll': - localStorage.clear(); - sessionStorage.clear(); - Cookies.remove('config'); - return initialState; - case 'resetFetch': - return { - ...state, - hasAccount: 'false', - }; - default: - return state; - } -}; - -const AccountProvider: React.FC = ({ children }) => { - const [state, dispatch] = React.useReducer(stateReducer, initialState); - - return ( - - {children} - - ); -}; - -const useAccountState = () => { - const context = React.useContext(StateContext); - if (context === undefined) { - throw new Error('useAccountState must be used within a AccountProvider'); - } - return context; -}; - -const useAccountDispatch = () => { - const context = React.useContext(DispatchContext); - if (context === undefined) { - throw new Error('useAccountDispatch must be used within a AccountProvider'); - } - return context; -}; - -export { AccountProvider, useAccountState, useAccountDispatch }; diff --git a/src/context/ConfigContext.tsx b/src/context/ConfigContext.tsx index a53f56ae..ac6e354b 100644 --- a/src/context/ConfigContext.tsx +++ b/src/context/ConfigContext.tsx @@ -27,7 +27,6 @@ type State = { currency: string; theme: string; sidebar: boolean; - multiNodeInfo: boolean; fetchFees: boolean; fetchPrices: boolean; displayValues: boolean; @@ -51,7 +50,6 @@ type ActionType = currency?: string; theme?: string; sidebar?: boolean; - multiNodeInfo?: boolean; fetchFees?: boolean; fetchPrices?: boolean; displayValues?: boolean; @@ -83,7 +81,6 @@ const initialState: State = { currency: currencyTypes.indexOf(defC) > -1 ? defC : 'sat', theme: themeTypes.indexOf(defT) > -1 ? defT : 'dark', sidebar: true, - multiNodeInfo: false, fetchFees, fetchPrices, displayValues: true, diff --git a/src/context/ContextProvider.tsx b/src/context/ContextProvider.tsx index 984ceb9e..6fe3eafa 100644 --- a/src/context/ContextProvider.tsx +++ b/src/context/ContextProvider.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { AccountProvider } from './AccountContext'; import { BitcoinInfoProvider } from './BitcoinContext'; import { StatusProvider } from './StatusContext'; import { PriceProvider } from './PriceContext'; @@ -7,15 +6,13 @@ import { ChatProvider } from './ChatContext'; import { RebalanceProvider } from './RebalanceContext'; export const ContextProvider: React.FC = ({ children }) => ( - - - - - - {children} - - - - - + + + + + {children} + + + + ); diff --git a/src/context/StatusContext.tsx b/src/context/StatusContext.tsx index 7e8fb403..2842a392 100644 --- a/src/context/StatusContext.tsx +++ b/src/context/StatusContext.tsx @@ -1,9 +1,5 @@ import React, { createContext, useContext, useReducer } from 'react'; -type StateStatus = { - connected: boolean; -}; - export type StatusState = { alias: string; color: string; @@ -22,20 +18,19 @@ export type StatusState = { peersCount: number; }; -type CompleteState = StatusState & StateStatus; - -type ActionType = { - type: 'connected' | 'disconnected'; - state?: StatusState; -}; +type ActionType = + | { + type: 'connected'; + state?: StatusState; + } + | { type: 'disconnected' }; type Dispatch = (action: ActionType) => void; -const StateContext = createContext(undefined); +const StateContext = createContext(undefined); const DispatchContext = createContext(undefined); -const initialState = { - connected: false, +const initialState: StatusState = { alias: '', color: '', syncedToChain: false, @@ -53,15 +48,11 @@ const initialState = { peersCount: 0, }; -const stateReducer = ( - state: StatusState, - action: ActionType -): CompleteState => { +const stateReducer = (state: StatusState, action: ActionType): StatusState => { switch (action.type) { case 'connected': - return { ...state, ...action.state, connected: true } || initialState; + return { ...state, ...action.state } || initialState; case 'disconnected': - return initialState; default: return initialState; } diff --git a/src/context/helpers/context.test.ts b/src/context/helpers/context.test.ts deleted file mode 100644 index af32fc2c..00000000 --- a/src/context/helpers/context.test.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { - CLIENT_ACCOUNT, - SSO_ACCOUNT, - CompleteAccount, -} from '../AccountContext'; -import { getAccountById, deleteAccountById } from './context'; - -const firstAccount = { - name: 'Hola', - host: 'Host1', - admin: 'Admin1', - viewOnly: 'ViewOnly1', - cert: 'Cert1', - id: '123', - type: CLIENT_ACCOUNT, -}; -const secondAccount = { - name: 'Chao', - id: '1234', - type: SSO_ACCOUNT, -}; - -const testAccounts: CompleteAccount[] = [firstAccount, secondAccount]; - -describe('Context Helpers', () => { - describe('should getAccountById', () => { - test('account exists', () => { - const { account, id } = getAccountById('1234', testAccounts); - - expect(id).toBe('1234'); - expect(account).toBe(secondAccount); - }); - test('account does not exists', () => { - const { account, id } = getAccountById('false id', testAccounts); - - expect(id).toBe(null); - expect(account).toBe(null); - }); - }); - describe('should deleteAccountById', () => { - test('account exists', () => { - const { accounts, id } = deleteAccountById('123', '1234', testAccounts); - - expect(id).toBe('123'); - expect(accounts).toStrictEqual([firstAccount]); - }); - test('account exists and is current account', () => { - const { accounts, id } = deleteAccountById('123', '123', testAccounts); - - expect(id).toBe(null); - expect(accounts).toStrictEqual([secondAccount]); - }); - test('account does not exists', () => { - const { accounts, id } = deleteAccountById( - '123', - 'false id', - testAccounts - ); - - expect(id).toBe('123'); - expect(accounts).toStrictEqual(testAccounts); - }); - - test('one account', () => { - const { accounts, id } = deleteAccountById('123', '123', [firstAccount]); - - expect(id).toBe(null); - expect(accounts).toStrictEqual([]); - }); - }); -}); diff --git a/src/context/helpers/context.ts b/src/context/helpers/context.ts deleted file mode 100644 index 28bda43b..00000000 --- a/src/context/helpers/context.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { getUUID } from '../../utils/auth'; -import { - CompleteAccount, - AccountProps, - CLIENT_ACCOUNT, - AuthType, - defaultAuth, -} from '../AccountContext'; - -export const getAccountById = ( - id: string | null, - accounts: CompleteAccount[] -) => { - if (!id) return { account: null, id: null }; - - const correctAccount: CompleteAccount | null | undefined = accounts.find( - a => a.id === id - ); - - return { - account: correctAccount || null, - id: correctAccount ? correctAccount.id : null, - }; -}; - -export const deleteAccountById = ( - currentId: string, - id: string, - accounts: CompleteAccount[] -) => { - const newAccounts: CompleteAccount[] = accounts.filter(a => a.id !== id); - - if (newAccounts.length <= 0) { - return { accounts: [], id: null }; - } - - let activeId: string | null = currentId; - if (currentId === id) { - activeId = null; - } - - return { accounts: newAccounts, id: activeId }; -}; - -export const addIdAndTypeToAccount = ( - account: AccountProps -): CompleteAccount => { - const { host, viewOnly, admin, cert } = account; - return { - ...account, - type: CLIENT_ACCOUNT, - id: getUUID(`${host}-${viewOnly}-${admin !== '' ? 1 : 0}-${cert}`), - }; -}; - -export const getAuthFromAccount = ( - account: CompleteAccount | undefined | null, - session?: string | null -): AuthType => { - if (!account) return defaultAuth; - if (account.type !== CLIENT_ACCOUNT) { - return { - type: account.type, - id: account.id, - }; - } - const { host, viewOnly, cert } = account; - if (!host) { - return defaultAuth; - } - if (!viewOnly && !session) { - return defaultAuth; - } - return { - type: account.type, - host, - macaroon: session || viewOnly, - cert, - }; -}; diff --git a/src/graphql/hodlhodl/__generated__/query.generated.tsx b/src/graphql/hodlhodl/__generated__/query.generated.tsx index eb5dbb6f..f09244ba 100644 --- a/src/graphql/hodlhodl/__generated__/query.generated.tsx +++ b/src/graphql/hodlhodl/__generated__/query.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetCountriesQueryVariables = Types.Exact<{ [key: string]: never }>; @@ -132,26 +137,23 @@ export const GetCountriesDocument = gql` * }); */ export function useGetCountriesQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetCountriesQuery, - GetCountriesQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery< - GetCountriesQuery, - GetCountriesQueryVariables - >(GetCountriesDocument, baseOptions); + return useQuery( + GetCountriesDocument, + baseOptions + ); } export function useGetCountriesLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetCountriesQuery, GetCountriesQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetCountriesQuery, - GetCountriesQueryVariables - >(GetCountriesDocument, baseOptions); + return useLazyQuery( + GetCountriesDocument, + baseOptions + ); } export type GetCountriesQueryHookResult = ReturnType< typeof useGetCountriesQuery @@ -159,7 +161,7 @@ export type GetCountriesQueryHookResult = ReturnType< export type GetCountriesLazyQueryHookResult = ReturnType< typeof useGetCountriesLazyQuery >; -export type GetCountriesQueryResult = ApolloReactCommon.QueryResult< +export type GetCountriesQueryResult = QueryResult< GetCountriesQuery, GetCountriesQueryVariables >; @@ -189,26 +191,26 @@ export const GetCurrenciesDocument = gql` * }); */ export function useGetCurrenciesQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetCurrenciesQuery, GetCurrenciesQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetCurrenciesQuery, - GetCurrenciesQueryVariables - >(GetCurrenciesDocument, baseOptions); + return useQuery( + GetCurrenciesDocument, + baseOptions + ); } export function useGetCurrenciesLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetCurrenciesQuery, GetCurrenciesQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetCurrenciesQuery, - GetCurrenciesQueryVariables - >(GetCurrenciesDocument, baseOptions); + return useLazyQuery( + GetCurrenciesDocument, + baseOptions + ); } export type GetCurrenciesQueryHookResult = ReturnType< typeof useGetCurrenciesQuery @@ -216,7 +218,7 @@ export type GetCurrenciesQueryHookResult = ReturnType< export type GetCurrenciesLazyQueryHookResult = ReturnType< typeof useGetCurrenciesLazyQuery >; -export type GetCurrenciesQueryResult = ApolloReactCommon.QueryResult< +export type GetCurrenciesQueryResult = QueryResult< GetCurrenciesQuery, GetCurrenciesQueryVariables >; @@ -285,23 +287,17 @@ export const GetOffersDocument = gql` * }); */ export function useGetOffersQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetOffersQuery, - GetOffersQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetOffersDocument, baseOptions ); } export function useGetOffersLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetOffersQuery, - GetOffersQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery( + return useLazyQuery( GetOffersDocument, baseOptions ); @@ -310,7 +306,7 @@ export type GetOffersQueryHookResult = ReturnType; export type GetOffersLazyQueryHookResult = ReturnType< typeof useGetOffersLazyQuery >; -export type GetOffersQueryResult = ApolloReactCommon.QueryResult< +export type GetOffersQueryResult = QueryResult< GetOffersQuery, GetOffersQueryVariables >; diff --git a/src/graphql/hodlhodl/query.ts b/src/graphql/hodlhodl/query.ts index c944b26a..68a6ca52 100644 --- a/src/graphql/hodlhodl/query.ts +++ b/src/graphql/hodlhodl/query.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_HODL_COUNTRIES = gql` query GetCountries { diff --git a/src/graphql/mutations/__generated__/addPeer.generated.tsx b/src/graphql/mutations/__generated__/addPeer.generated.tsx index 5eb57683..045d7b9c 100644 --- a/src/graphql/mutations/__generated__/addPeer.generated.tsx +++ b/src/graphql/mutations/__generated__/addPeer.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type AddPeerMutationVariables = Types.Exact<{ - auth: Types.AuthType; url?: Types.Maybe; publicKey?: Types.Maybe; socket?: Types.Maybe; @@ -18,14 +22,12 @@ export type AddPeerMutation = { __typename?: 'Mutation' } & Pick< export const AddPeerDocument = gql` mutation AddPeer( - $auth: authType! $url: String $publicKey: String $socket: String $isTemporary: Boolean ) { addPeer( - auth: $auth url: $url publicKey: $publicKey socket: $socket @@ -33,7 +35,7 @@ export const AddPeerDocument = gql` ) } `; -export type AddPeerMutationFn = ApolloReactCommon.MutationFunction< +export type AddPeerMutationFn = MutationFunction< AddPeerMutation, AddPeerMutationVariables >; @@ -51,7 +53,6 @@ export type AddPeerMutationFn = ApolloReactCommon.MutationFunction< * @example * const [addPeerMutation, { data, loading, error }] = useAddPeerMutation({ * variables: { - * auth: // value for 'auth' * url: // value for 'url' * publicKey: // value for 'publicKey' * socket: // value for 'socket' @@ -60,21 +61,16 @@ export type AddPeerMutationFn = ApolloReactCommon.MutationFunction< * }); */ export function useAddPeerMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< - AddPeerMutation, - AddPeerMutationVariables - > + baseOptions?: MutationHookOptions ) { - return ApolloReactHooks.useMutation< - AddPeerMutation, - AddPeerMutationVariables - >(AddPeerDocument, baseOptions); + return useMutation( + AddPeerDocument, + baseOptions + ); } export type AddPeerMutationHookResult = ReturnType; -export type AddPeerMutationResult = ApolloReactCommon.MutationResult< - AddPeerMutation ->; -export type AddPeerMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type AddPeerMutationResult = MutationResult; +export type AddPeerMutationOptions = BaseMutationOptions< AddPeerMutation, AddPeerMutationVariables >; diff --git a/src/graphql/mutations/__generated__/bosRebalance.generated.tsx b/src/graphql/mutations/__generated__/bosRebalance.generated.tsx index b23166af..e8cad46f 100644 --- a/src/graphql/mutations/__generated__/bosRebalance.generated.tsx +++ b/src/graphql/mutations/__generated__/bosRebalance.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type BosRebalanceMutationVariables = Types.Exact<{ - auth: Types.AuthType; avoid?: Types.Maybe>>; in_through?: Types.Maybe; is_avoiding_high_inbound?: Types.Maybe; @@ -56,7 +60,6 @@ export type BosRebalanceMutation = { __typename?: 'Mutation' } & { export const BosRebalanceDocument = gql` mutation BosRebalance( - $auth: authType! $avoid: [String] $in_through: String $is_avoiding_high_inbound: Boolean @@ -69,7 +72,6 @@ export const BosRebalanceDocument = gql` $target: Int ) { bosRebalance( - auth: $auth avoid: $avoid in_through: $in_through is_avoiding_high_inbound: $is_avoiding_high_inbound @@ -106,7 +108,7 @@ export const BosRebalanceDocument = gql` } } `; -export type BosRebalanceMutationFn = ApolloReactCommon.MutationFunction< +export type BosRebalanceMutationFn = MutationFunction< BosRebalanceMutation, BosRebalanceMutationVariables >; @@ -124,7 +126,6 @@ export type BosRebalanceMutationFn = ApolloReactCommon.MutationFunction< * @example * const [bosRebalanceMutation, { data, loading, error }] = useBosRebalanceMutation({ * variables: { - * auth: // value for 'auth' * avoid: // value for 'avoid' * in_through: // value for 'in_through' * is_avoiding_high_inbound: // value for 'is_avoiding_high_inbound' @@ -139,23 +140,21 @@ export type BosRebalanceMutationFn = ApolloReactCommon.MutationFunction< * }); */ export function useBosRebalanceMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< BosRebalanceMutation, BosRebalanceMutationVariables > ) { - return ApolloReactHooks.useMutation< - BosRebalanceMutation, - BosRebalanceMutationVariables - >(BosRebalanceDocument, baseOptions); + return useMutation( + BosRebalanceDocument, + baseOptions + ); } export type BosRebalanceMutationHookResult = ReturnType< typeof useBosRebalanceMutation >; -export type BosRebalanceMutationResult = ApolloReactCommon.MutationResult< - BosRebalanceMutation ->; -export type BosRebalanceMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type BosRebalanceMutationResult = MutationResult; +export type BosRebalanceMutationOptions = BaseMutationOptions< BosRebalanceMutation, BosRebalanceMutationVariables >; diff --git a/src/graphql/mutations/__generated__/circularRebalance.generated.tsx b/src/graphql/mutations/__generated__/circularRebalance.generated.tsx index a38b68ff..051927e7 100644 --- a/src/graphql/mutations/__generated__/circularRebalance.generated.tsx +++ b/src/graphql/mutations/__generated__/circularRebalance.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type CircularRebalanceMutationVariables = Types.Exact<{ - auth: Types.AuthType; route: Types.Scalars['String']; }>; @@ -14,11 +18,11 @@ export type CircularRebalanceMutation = { __typename?: 'Mutation' } & Pick< >; export const CircularRebalanceDocument = gql` - mutation CircularRebalance($auth: authType!, $route: String!) { - circularRebalance(auth: $auth, route: $route) + mutation CircularRebalance($route: String!) { + circularRebalance(route: $route) } `; -export type CircularRebalanceMutationFn = ApolloReactCommon.MutationFunction< +export type CircularRebalanceMutationFn = MutationFunction< CircularRebalanceMutation, CircularRebalanceMutationVariables >; @@ -36,18 +40,17 @@ export type CircularRebalanceMutationFn = ApolloReactCommon.MutationFunction< * @example * const [circularRebalanceMutation, { data, loading, error }] = useCircularRebalanceMutation({ * variables: { - * auth: // value for 'auth' * route: // value for 'route' * }, * }); */ export function useCircularRebalanceMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< CircularRebalanceMutation, CircularRebalanceMutationVariables > ) { - return ApolloReactHooks.useMutation< + return useMutation< CircularRebalanceMutation, CircularRebalanceMutationVariables >(CircularRebalanceDocument, baseOptions); @@ -55,10 +58,10 @@ export function useCircularRebalanceMutation( export type CircularRebalanceMutationHookResult = ReturnType< typeof useCircularRebalanceMutation >; -export type CircularRebalanceMutationResult = ApolloReactCommon.MutationResult< +export type CircularRebalanceMutationResult = MutationResult< CircularRebalanceMutation >; -export type CircularRebalanceMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type CircularRebalanceMutationOptions = BaseMutationOptions< CircularRebalanceMutation, CircularRebalanceMutationVariables >; diff --git a/src/graphql/mutations/__generated__/closeChannel.generated.tsx b/src/graphql/mutations/__generated__/closeChannel.generated.tsx index 4158f07f..7ce63a65 100644 --- a/src/graphql/mutations/__generated__/closeChannel.generated.tsx +++ b/src/graphql/mutations/__generated__/closeChannel.generated.tsx @@ -1,11 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type CloseChannelMutationVariables = Types.Exact<{ id: Types.Scalars['String']; - auth: Types.AuthType; forceClose?: Types.Maybe; target?: Types.Maybe; tokens?: Types.Maybe; @@ -23,7 +27,6 @@ export type CloseChannelMutation = { __typename?: 'Mutation' } & { export const CloseChannelDocument = gql` mutation CloseChannel( $id: String! - $auth: authType! $forceClose: Boolean $target: Int $tokens: Int @@ -33,14 +36,13 @@ export const CloseChannelDocument = gql` forceClose: $forceClose targetConfirmations: $target tokensPerVByte: $tokens - auth: $auth ) { transactionId transactionOutputIndex } } `; -export type CloseChannelMutationFn = ApolloReactCommon.MutationFunction< +export type CloseChannelMutationFn = MutationFunction< CloseChannelMutation, CloseChannelMutationVariables >; @@ -59,7 +61,6 @@ export type CloseChannelMutationFn = ApolloReactCommon.MutationFunction< * const [closeChannelMutation, { data, loading, error }] = useCloseChannelMutation({ * variables: { * id: // value for 'id' - * auth: // value for 'auth' * forceClose: // value for 'forceClose' * target: // value for 'target' * tokens: // value for 'tokens' @@ -67,23 +68,21 @@ export type CloseChannelMutationFn = ApolloReactCommon.MutationFunction< * }); */ export function useCloseChannelMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< CloseChannelMutation, CloseChannelMutationVariables > ) { - return ApolloReactHooks.useMutation< - CloseChannelMutation, - CloseChannelMutationVariables - >(CloseChannelDocument, baseOptions); + return useMutation( + CloseChannelDocument, + baseOptions + ); } export type CloseChannelMutationHookResult = ReturnType< typeof useCloseChannelMutation >; -export type CloseChannelMutationResult = ApolloReactCommon.MutationResult< - CloseChannelMutation ->; -export type CloseChannelMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type CloseChannelMutationResult = MutationResult; +export type CloseChannelMutationOptions = BaseMutationOptions< CloseChannelMutation, CloseChannelMutationVariables >; diff --git a/src/graphql/mutations/__generated__/createAddress.generated.tsx b/src/graphql/mutations/__generated__/createAddress.generated.tsx index 84e1910c..8d6fa320 100644 --- a/src/graphql/mutations/__generated__/createAddress.generated.tsx +++ b/src/graphql/mutations/__generated__/createAddress.generated.tsx @@ -1,11 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type CreateAddressMutationVariables = Types.Exact<{ nested?: Types.Maybe; - auth: Types.AuthType; }>; export type CreateAddressMutation = { __typename?: 'Mutation' } & Pick< @@ -14,11 +18,11 @@ export type CreateAddressMutation = { __typename?: 'Mutation' } & Pick< >; export const CreateAddressDocument = gql` - mutation CreateAddress($nested: Boolean, $auth: authType!) { - createAddress(nested: $nested, auth: $auth) + mutation CreateAddress($nested: Boolean) { + createAddress(nested: $nested) } `; -export type CreateAddressMutationFn = ApolloReactCommon.MutationFunction< +export type CreateAddressMutationFn = MutationFunction< CreateAddressMutation, CreateAddressMutationVariables >; @@ -37,28 +41,25 @@ export type CreateAddressMutationFn = ApolloReactCommon.MutationFunction< * const [createAddressMutation, { data, loading, error }] = useCreateAddressMutation({ * variables: { * nested: // value for 'nested' - * auth: // value for 'auth' * }, * }); */ export function useCreateAddressMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< CreateAddressMutation, CreateAddressMutationVariables > ) { - return ApolloReactHooks.useMutation< - CreateAddressMutation, - CreateAddressMutationVariables - >(CreateAddressDocument, baseOptions); + return useMutation( + CreateAddressDocument, + baseOptions + ); } export type CreateAddressMutationHookResult = ReturnType< typeof useCreateAddressMutation >; -export type CreateAddressMutationResult = ApolloReactCommon.MutationResult< - CreateAddressMutation ->; -export type CreateAddressMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type CreateAddressMutationResult = MutationResult; +export type CreateAddressMutationOptions = BaseMutationOptions< CreateAddressMutation, CreateAddressMutationVariables >; diff --git a/src/graphql/mutations/__generated__/createInvoice.generated.tsx b/src/graphql/mutations/__generated__/createInvoice.generated.tsx index c84e381d..eee0fd0d 100644 --- a/src/graphql/mutations/__generated__/createInvoice.generated.tsx +++ b/src/graphql/mutations/__generated__/createInvoice.generated.tsx @@ -1,11 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type CreateInvoiceMutationVariables = Types.Exact<{ amount: Types.Scalars['Int']; - auth: Types.AuthType; }>; export type CreateInvoiceMutation = { __typename?: 'Mutation' } & { @@ -15,13 +19,13 @@ export type CreateInvoiceMutation = { __typename?: 'Mutation' } & { }; export const CreateInvoiceDocument = gql` - mutation CreateInvoice($amount: Int!, $auth: authType!) { - createInvoice(amount: $amount, auth: $auth) { + mutation CreateInvoice($amount: Int!) { + createInvoice(amount: $amount) { request } } `; -export type CreateInvoiceMutationFn = ApolloReactCommon.MutationFunction< +export type CreateInvoiceMutationFn = MutationFunction< CreateInvoiceMutation, CreateInvoiceMutationVariables >; @@ -40,28 +44,25 @@ export type CreateInvoiceMutationFn = ApolloReactCommon.MutationFunction< * const [createInvoiceMutation, { data, loading, error }] = useCreateInvoiceMutation({ * variables: { * amount: // value for 'amount' - * auth: // value for 'auth' * }, * }); */ export function useCreateInvoiceMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< CreateInvoiceMutation, CreateInvoiceMutationVariables > ) { - return ApolloReactHooks.useMutation< - CreateInvoiceMutation, - CreateInvoiceMutationVariables - >(CreateInvoiceDocument, baseOptions); + return useMutation( + CreateInvoiceDocument, + baseOptions + ); } export type CreateInvoiceMutationHookResult = ReturnType< typeof useCreateInvoiceMutation >; -export type CreateInvoiceMutationResult = ApolloReactCommon.MutationResult< - CreateInvoiceMutation ->; -export type CreateInvoiceMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type CreateInvoiceMutationResult = MutationResult; +export type CreateInvoiceMutationOptions = BaseMutationOptions< CreateInvoiceMutation, CreateInvoiceMutationVariables >; diff --git a/src/graphql/mutations/__generated__/createMacaroon.generated.tsx b/src/graphql/mutations/__generated__/createMacaroon.generated.tsx index c24d3826..2e2f139b 100644 --- a/src/graphql/mutations/__generated__/createMacaroon.generated.tsx +++ b/src/graphql/mutations/__generated__/createMacaroon.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type CreateMacaroonMutationVariables = Types.Exact<{ - auth: Types.AuthType; permissions: Types.PermissionsType; }>; @@ -14,11 +18,11 @@ export type CreateMacaroonMutation = { __typename?: 'Mutation' } & Pick< >; export const CreateMacaroonDocument = gql` - mutation CreateMacaroon($auth: authType!, $permissions: permissionsType!) { - createMacaroon(auth: $auth, permissions: $permissions) + mutation CreateMacaroon($permissions: permissionsType!) { + createMacaroon(permissions: $permissions) } `; -export type CreateMacaroonMutationFn = ApolloReactCommon.MutationFunction< +export type CreateMacaroonMutationFn = MutationFunction< CreateMacaroonMutation, CreateMacaroonMutationVariables >; @@ -36,29 +40,28 @@ export type CreateMacaroonMutationFn = ApolloReactCommon.MutationFunction< * @example * const [createMacaroonMutation, { data, loading, error }] = useCreateMacaroonMutation({ * variables: { - * auth: // value for 'auth' * permissions: // value for 'permissions' * }, * }); */ export function useCreateMacaroonMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< CreateMacaroonMutation, CreateMacaroonMutationVariables > ) { - return ApolloReactHooks.useMutation< - CreateMacaroonMutation, - CreateMacaroonMutationVariables - >(CreateMacaroonDocument, baseOptions); + return useMutation( + CreateMacaroonDocument, + baseOptions + ); } export type CreateMacaroonMutationHookResult = ReturnType< typeof useCreateMacaroonMutation >; -export type CreateMacaroonMutationResult = ApolloReactCommon.MutationResult< +export type CreateMacaroonMutationResult = MutationResult< CreateMacaroonMutation >; -export type CreateMacaroonMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type CreateMacaroonMutationOptions = BaseMutationOptions< CreateMacaroonMutation, CreateMacaroonMutationVariables >; diff --git a/src/graphql/mutations/__generated__/keysend.generated.tsx b/src/graphql/mutations/__generated__/keysend.generated.tsx index 92d32cd5..676d6b2e 100644 --- a/src/graphql/mutations/__generated__/keysend.generated.tsx +++ b/src/graphql/mutations/__generated__/keysend.generated.tsx @@ -1,11 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type KeysendMutationVariables = Types.Exact<{ destination: Types.Scalars['String']; - auth: Types.AuthType; tokens: Types.Scalars['Int']; }>; @@ -16,13 +20,13 @@ export type KeysendMutation = { __typename?: 'Mutation' } & { }; export const KeysendDocument = gql` - mutation Keysend($destination: String!, $auth: authType!, $tokens: Int!) { - keysend(destination: $destination, auth: $auth, tokens: $tokens) { + mutation Keysend($destination: String!, $tokens: Int!) { + keysend(destination: $destination, tokens: $tokens) { is_confirmed } } `; -export type KeysendMutationFn = ApolloReactCommon.MutationFunction< +export type KeysendMutationFn = MutationFunction< KeysendMutation, KeysendMutationVariables >; @@ -41,27 +45,21 @@ export type KeysendMutationFn = ApolloReactCommon.MutationFunction< * const [keysendMutation, { data, loading, error }] = useKeysendMutation({ * variables: { * destination: // value for 'destination' - * auth: // value for 'auth' * tokens: // value for 'tokens' * }, * }); */ export function useKeysendMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< - KeysendMutation, - KeysendMutationVariables - > + baseOptions?: MutationHookOptions ) { - return ApolloReactHooks.useMutation< - KeysendMutation, - KeysendMutationVariables - >(KeysendDocument, baseOptions); + return useMutation( + KeysendDocument, + baseOptions + ); } export type KeysendMutationHookResult = ReturnType; -export type KeysendMutationResult = ApolloReactCommon.MutationResult< - KeysendMutation ->; -export type KeysendMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type KeysendMutationResult = MutationResult; +export type KeysendMutationOptions = BaseMutationOptions< KeysendMutation, KeysendMutationVariables >; diff --git a/src/graphql/mutations/__generated__/logout.generated.tsx b/src/graphql/mutations/__generated__/logout.generated.tsx index 1e8c885e..bfd69f22 100644 --- a/src/graphql/mutations/__generated__/logout.generated.tsx +++ b/src/graphql/mutations/__generated__/logout.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type LogoutMutationVariables = Types.Exact<{ @@ -17,7 +22,7 @@ export const LogoutDocument = gql` logout(type: $type) } `; -export type LogoutMutationFn = ApolloReactCommon.MutationFunction< +export type LogoutMutationFn = MutationFunction< LogoutMutation, LogoutMutationVariables >; @@ -40,21 +45,16 @@ export type LogoutMutationFn = ApolloReactCommon.MutationFunction< * }); */ export function useLogoutMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< - LogoutMutation, - LogoutMutationVariables - > + baseOptions?: MutationHookOptions ) { - return ApolloReactHooks.useMutation( + return useMutation( LogoutDocument, baseOptions ); } export type LogoutMutationHookResult = ReturnType; -export type LogoutMutationResult = ApolloReactCommon.MutationResult< - LogoutMutation ->; -export type LogoutMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type LogoutMutationResult = MutationResult; +export type LogoutMutationOptions = BaseMutationOptions< LogoutMutation, LogoutMutationVariables >; diff --git a/src/graphql/mutations/__generated__/openChannel.generated.tsx b/src/graphql/mutations/__generated__/openChannel.generated.tsx index ee5b01fc..c95ba8ea 100644 --- a/src/graphql/mutations/__generated__/openChannel.generated.tsx +++ b/src/graphql/mutations/__generated__/openChannel.generated.tsx @@ -1,12 +1,16 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type OpenChannelMutationVariables = Types.Exact<{ amount: Types.Scalars['Int']; partnerPublicKey: Types.Scalars['String']; - auth: Types.AuthType; tokensPerVByte?: Types.Maybe; isPrivate?: Types.Maybe; }>; @@ -24,14 +28,12 @@ export const OpenChannelDocument = gql` mutation OpenChannel( $amount: Int! $partnerPublicKey: String! - $auth: authType! $tokensPerVByte: Int $isPrivate: Boolean ) { openChannel( amount: $amount partnerPublicKey: $partnerPublicKey - auth: $auth tokensPerVByte: $tokensPerVByte isPrivate: $isPrivate ) { @@ -40,7 +42,7 @@ export const OpenChannelDocument = gql` } } `; -export type OpenChannelMutationFn = ApolloReactCommon.MutationFunction< +export type OpenChannelMutationFn = MutationFunction< OpenChannelMutation, OpenChannelMutationVariables >; @@ -60,30 +62,27 @@ export type OpenChannelMutationFn = ApolloReactCommon.MutationFunction< * variables: { * amount: // value for 'amount' * partnerPublicKey: // value for 'partnerPublicKey' - * auth: // value for 'auth' * tokensPerVByte: // value for 'tokensPerVByte' * isPrivate: // value for 'isPrivate' * }, * }); */ export function useOpenChannelMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< OpenChannelMutation, OpenChannelMutationVariables > ) { - return ApolloReactHooks.useMutation< - OpenChannelMutation, - OpenChannelMutationVariables - >(OpenChannelDocument, baseOptions); + return useMutation( + OpenChannelDocument, + baseOptions + ); } export type OpenChannelMutationHookResult = ReturnType< typeof useOpenChannelMutation >; -export type OpenChannelMutationResult = ApolloReactCommon.MutationResult< - OpenChannelMutation ->; -export type OpenChannelMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type OpenChannelMutationResult = MutationResult; +export type OpenChannelMutationOptions = BaseMutationOptions< OpenChannelMutation, OpenChannelMutationVariables >; diff --git a/src/graphql/mutations/__generated__/payViaRoute.generated.tsx b/src/graphql/mutations/__generated__/payViaRoute.generated.tsx index e953c6bd..0ca21a98 100644 --- a/src/graphql/mutations/__generated__/payViaRoute.generated.tsx +++ b/src/graphql/mutations/__generated__/payViaRoute.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type PayViaRouteMutationVariables = Types.Exact<{ - auth: Types.AuthType; route: Types.Scalars['String']; id: Types.Scalars['String']; }>; @@ -15,11 +19,11 @@ export type PayViaRouteMutation = { __typename?: 'Mutation' } & Pick< >; export const PayViaRouteDocument = gql` - mutation PayViaRoute($auth: authType!, $route: String!, $id: String!) { - payViaRoute(auth: $auth, route: $route, id: $id) + mutation PayViaRoute($route: String!, $id: String!) { + payViaRoute(route: $route, id: $id) } `; -export type PayViaRouteMutationFn = ApolloReactCommon.MutationFunction< +export type PayViaRouteMutationFn = MutationFunction< PayViaRouteMutation, PayViaRouteMutationVariables >; @@ -37,30 +41,27 @@ export type PayViaRouteMutationFn = ApolloReactCommon.MutationFunction< * @example * const [payViaRouteMutation, { data, loading, error }] = usePayViaRouteMutation({ * variables: { - * auth: // value for 'auth' * route: // value for 'route' * id: // value for 'id' * }, * }); */ export function usePayViaRouteMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< PayViaRouteMutation, PayViaRouteMutationVariables > ) { - return ApolloReactHooks.useMutation< - PayViaRouteMutation, - PayViaRouteMutationVariables - >(PayViaRouteDocument, baseOptions); + return useMutation( + PayViaRouteDocument, + baseOptions + ); } export type PayViaRouteMutationHookResult = ReturnType< typeof usePayViaRouteMutation >; -export type PayViaRouteMutationResult = ApolloReactCommon.MutationResult< - PayViaRouteMutation ->; -export type PayViaRouteMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type PayViaRouteMutationResult = MutationResult; +export type PayViaRouteMutationOptions = BaseMutationOptions< PayViaRouteMutation, PayViaRouteMutationVariables >; diff --git a/src/graphql/mutations/__generated__/removePeer.generated.tsx b/src/graphql/mutations/__generated__/removePeer.generated.tsx index 557847c2..5eee1420 100644 --- a/src/graphql/mutations/__generated__/removePeer.generated.tsx +++ b/src/graphql/mutations/__generated__/removePeer.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type RemovePeerMutationVariables = Types.Exact<{ - auth: Types.AuthType; publicKey: Types.Scalars['String']; }>; @@ -14,11 +18,11 @@ export type RemovePeerMutation = { __typename?: 'Mutation' } & Pick< >; export const RemovePeerDocument = gql` - mutation RemovePeer($auth: authType!, $publicKey: String!) { - removePeer(auth: $auth, publicKey: $publicKey) + mutation RemovePeer($publicKey: String!) { + removePeer(publicKey: $publicKey) } `; -export type RemovePeerMutationFn = ApolloReactCommon.MutationFunction< +export type RemovePeerMutationFn = MutationFunction< RemovePeerMutation, RemovePeerMutationVariables >; @@ -36,29 +40,26 @@ export type RemovePeerMutationFn = ApolloReactCommon.MutationFunction< * @example * const [removePeerMutation, { data, loading, error }] = useRemovePeerMutation({ * variables: { - * auth: // value for 'auth' * publicKey: // value for 'publicKey' * }, * }); */ export function useRemovePeerMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< RemovePeerMutation, RemovePeerMutationVariables > ) { - return ApolloReactHooks.useMutation< - RemovePeerMutation, - RemovePeerMutationVariables - >(RemovePeerDocument, baseOptions); + return useMutation( + RemovePeerDocument, + baseOptions + ); } export type RemovePeerMutationHookResult = ReturnType< typeof useRemovePeerMutation >; -export type RemovePeerMutationResult = ApolloReactCommon.MutationResult< - RemovePeerMutation ->; -export type RemovePeerMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type RemovePeerMutationResult = MutationResult; +export type RemovePeerMutationOptions = BaseMutationOptions< RemovePeerMutation, RemovePeerMutationVariables >; diff --git a/src/graphql/mutations/__generated__/sendMessage.generated.tsx b/src/graphql/mutations/__generated__/sendMessage.generated.tsx index 1e8d4b91..616524de 100644 --- a/src/graphql/mutations/__generated__/sendMessage.generated.tsx +++ b/src/graphql/mutations/__generated__/sendMessage.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type SendMessageMutationVariables = Types.Exact<{ - auth: Types.AuthType; publicKey: Types.Scalars['String']; message: Types.Scalars['String']; messageType?: Types.Maybe; @@ -19,7 +23,6 @@ export type SendMessageMutation = { __typename?: 'Mutation' } & Pick< export const SendMessageDocument = gql` mutation SendMessage( - $auth: authType! $publicKey: String! $message: String! $messageType: String @@ -27,7 +30,6 @@ export const SendMessageDocument = gql` $maxFee: Int ) { sendMessage( - auth: $auth publicKey: $publicKey message: $message messageType: $messageType @@ -36,7 +38,7 @@ export const SendMessageDocument = gql` ) } `; -export type SendMessageMutationFn = ApolloReactCommon.MutationFunction< +export type SendMessageMutationFn = MutationFunction< SendMessageMutation, SendMessageMutationVariables >; @@ -54,7 +56,6 @@ export type SendMessageMutationFn = ApolloReactCommon.MutationFunction< * @example * const [sendMessageMutation, { data, loading, error }] = useSendMessageMutation({ * variables: { - * auth: // value for 'auth' * publicKey: // value for 'publicKey' * message: // value for 'message' * messageType: // value for 'messageType' @@ -64,23 +65,21 @@ export type SendMessageMutationFn = ApolloReactCommon.MutationFunction< * }); */ export function useSendMessageMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< SendMessageMutation, SendMessageMutationVariables > ) { - return ApolloReactHooks.useMutation< - SendMessageMutation, - SendMessageMutationVariables - >(SendMessageDocument, baseOptions); + return useMutation( + SendMessageDocument, + baseOptions + ); } export type SendMessageMutationHookResult = ReturnType< typeof useSendMessageMutation >; -export type SendMessageMutationResult = ApolloReactCommon.MutationResult< - SendMessageMutation ->; -export type SendMessageMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type SendMessageMutationResult = MutationResult; +export type SendMessageMutationOptions = BaseMutationOptions< SendMessageMutation, SendMessageMutationVariables >; diff --git a/src/graphql/mutations/__generated__/sendToAddress.generated.tsx b/src/graphql/mutations/__generated__/sendToAddress.generated.tsx index 087df150..0ec8dfea 100644 --- a/src/graphql/mutations/__generated__/sendToAddress.generated.tsx +++ b/src/graphql/mutations/__generated__/sendToAddress.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type PayAddressMutationVariables = Types.Exact<{ - auth: Types.AuthType; address: Types.Scalars['String']; tokens?: Types.Maybe; fee?: Types.Maybe; @@ -23,7 +27,6 @@ export type PayAddressMutation = { __typename?: 'Mutation' } & { export const PayAddressDocument = gql` mutation PayAddress( - $auth: authType! $address: String! $tokens: Int $fee: Int @@ -31,7 +34,6 @@ export const PayAddressDocument = gql` $sendAll: Boolean ) { sendToAddress( - auth: $auth address: $address tokens: $tokens fee: $fee @@ -46,7 +48,7 @@ export const PayAddressDocument = gql` } } `; -export type PayAddressMutationFn = ApolloReactCommon.MutationFunction< +export type PayAddressMutationFn = MutationFunction< PayAddressMutation, PayAddressMutationVariables >; @@ -64,7 +66,6 @@ export type PayAddressMutationFn = ApolloReactCommon.MutationFunction< * @example * const [payAddressMutation, { data, loading, error }] = usePayAddressMutation({ * variables: { - * auth: // value for 'auth' * address: // value for 'address' * tokens: // value for 'tokens' * fee: // value for 'fee' @@ -74,23 +75,21 @@ export type PayAddressMutationFn = ApolloReactCommon.MutationFunction< * }); */ export function usePayAddressMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< PayAddressMutation, PayAddressMutationVariables > ) { - return ApolloReactHooks.useMutation< - PayAddressMutation, - PayAddressMutationVariables - >(PayAddressDocument, baseOptions); + return useMutation( + PayAddressDocument, + baseOptions + ); } export type PayAddressMutationHookResult = ReturnType< typeof usePayAddressMutation >; -export type PayAddressMutationResult = ApolloReactCommon.MutationResult< - PayAddressMutation ->; -export type PayAddressMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type PayAddressMutationResult = MutationResult; +export type PayAddressMutationOptions = BaseMutationOptions< PayAddressMutation, PayAddressMutationVariables >; diff --git a/src/graphql/mutations/__generated__/updateFees.generated.tsx b/src/graphql/mutations/__generated__/updateFees.generated.tsx index d5323cb8..83b6ae0e 100644 --- a/src/graphql/mutations/__generated__/updateFees.generated.tsx +++ b/src/graphql/mutations/__generated__/updateFees.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + MutationFunction, + useMutation, + MutationHookOptions, + BaseMutationOptions, + MutationResult, +} from '@apollo/client'; import * as Types from '../../types'; export type UpdateFeesMutationVariables = Types.Exact<{ - auth: Types.AuthType; transaction_id?: Types.Maybe; transaction_vout?: Types.Maybe; base_fee_tokens?: Types.Maybe; @@ -21,7 +25,6 @@ export type UpdateFeesMutation = { __typename?: 'Mutation' } & Pick< export const UpdateFeesDocument = gql` mutation UpdateFees( - $auth: authType! $transaction_id: String $transaction_vout: Int $base_fee_tokens: Float @@ -31,7 +34,6 @@ export const UpdateFeesDocument = gql` $min_htlc_mtokens: String ) { updateFees( - auth: $auth transaction_id: $transaction_id transaction_vout: $transaction_vout base_fee_tokens: $base_fee_tokens @@ -42,7 +44,7 @@ export const UpdateFeesDocument = gql` ) } `; -export type UpdateFeesMutationFn = ApolloReactCommon.MutationFunction< +export type UpdateFeesMutationFn = MutationFunction< UpdateFeesMutation, UpdateFeesMutationVariables >; @@ -60,7 +62,6 @@ export type UpdateFeesMutationFn = ApolloReactCommon.MutationFunction< * @example * const [updateFeesMutation, { data, loading, error }] = useUpdateFeesMutation({ * variables: { - * auth: // value for 'auth' * transaction_id: // value for 'transaction_id' * transaction_vout: // value for 'transaction_vout' * base_fee_tokens: // value for 'base_fee_tokens' @@ -72,23 +73,21 @@ export type UpdateFeesMutationFn = ApolloReactCommon.MutationFunction< * }); */ export function useUpdateFeesMutation( - baseOptions?: ApolloReactHooks.MutationHookOptions< + baseOptions?: MutationHookOptions< UpdateFeesMutation, UpdateFeesMutationVariables > ) { - return ApolloReactHooks.useMutation< - UpdateFeesMutation, - UpdateFeesMutationVariables - >(UpdateFeesDocument, baseOptions); + return useMutation( + UpdateFeesDocument, + baseOptions + ); } export type UpdateFeesMutationHookResult = ReturnType< typeof useUpdateFeesMutation >; -export type UpdateFeesMutationResult = ApolloReactCommon.MutationResult< - UpdateFeesMutation ->; -export type UpdateFeesMutationOptions = ApolloReactCommon.BaseMutationOptions< +export type UpdateFeesMutationResult = MutationResult; +export type UpdateFeesMutationOptions = BaseMutationOptions< UpdateFeesMutation, UpdateFeesMutationVariables >; diff --git a/src/graphql/mutations/addPeer.ts b/src/graphql/mutations/addPeer.ts index f6c9a4f4..be498f6a 100644 --- a/src/graphql/mutations/addPeer.ts +++ b/src/graphql/mutations/addPeer.ts @@ -1,15 +1,13 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const ADD_PEER = gql` mutation AddPeer( - $auth: authType! $url: String $publicKey: String $socket: String $isTemporary: Boolean ) { addPeer( - auth: $auth url: $url publicKey: $publicKey socket: $socket diff --git a/src/graphql/mutations/bosRebalance.ts b/src/graphql/mutations/bosRebalance.ts index e88fba65..e60787f0 100644 --- a/src/graphql/mutations/bosRebalance.ts +++ b/src/graphql/mutations/bosRebalance.ts @@ -1,8 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const BOS_REBALANCE = gql` mutation BosRebalance( - $auth: authType! $avoid: [String] $in_through: String $is_avoiding_high_inbound: Boolean @@ -15,7 +14,6 @@ export const BOS_REBALANCE = gql` $target: Int ) { bosRebalance( - auth: $auth avoid: $avoid in_through: $in_through is_avoiding_high_inbound: $is_avoiding_high_inbound diff --git a/src/graphql/mutations/circularRebalance.ts b/src/graphql/mutations/circularRebalance.ts index d34bb222..259cb97a 100644 --- a/src/graphql/mutations/circularRebalance.ts +++ b/src/graphql/mutations/circularRebalance.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const CIRCULAR_REBALANCE = gql` - mutation CircularRebalance($auth: authType!, $route: String!) { - circularRebalance(auth: $auth, route: $route) + mutation CircularRebalance($route: String!) { + circularRebalance(route: $route) } `; diff --git a/src/graphql/mutations/closeChannel.ts b/src/graphql/mutations/closeChannel.ts index f5b3197b..bbc3eb7a 100644 --- a/src/graphql/mutations/closeChannel.ts +++ b/src/graphql/mutations/closeChannel.ts @@ -1,9 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const CLOSE_CHANNEL = gql` mutation CloseChannel( $id: String! - $auth: authType! $forceClose: Boolean $target: Int $tokens: Int @@ -13,7 +12,6 @@ export const CLOSE_CHANNEL = gql` forceClose: $forceClose targetConfirmations: $target tokensPerVByte: $tokens - auth: $auth ) { transactionId transactionOutputIndex diff --git a/src/graphql/mutations/createAddress.ts b/src/graphql/mutations/createAddress.ts index 5a5f830c..9c9cfb47 100644 --- a/src/graphql/mutations/createAddress.ts +++ b/src/graphql/mutations/createAddress.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const CREATE_ADDRESS = gql` - mutation CreateAddress($nested: Boolean, $auth: authType!) { - createAddress(nested: $nested, auth: $auth) + mutation CreateAddress($nested: Boolean) { + createAddress(nested: $nested) } `; diff --git a/src/graphql/mutations/createInvoice.ts b/src/graphql/mutations/createInvoice.ts index 1657a946..07b61057 100644 --- a/src/graphql/mutations/createInvoice.ts +++ b/src/graphql/mutations/createInvoice.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const CREATE_INVOICE = gql` - mutation CreateInvoice($amount: Int!, $auth: authType!) { - createInvoice(amount: $amount, auth: $auth) { + mutation CreateInvoice($amount: Int!) { + createInvoice(amount: $amount) { request } } diff --git a/src/graphql/mutations/createMacaroon.ts b/src/graphql/mutations/createMacaroon.ts index 573631b3..a6357b4b 100644 --- a/src/graphql/mutations/createMacaroon.ts +++ b/src/graphql/mutations/createMacaroon.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const CREATE_MACAROON = gql` - mutation CreateMacaroon($auth: authType!, $permissions: permissionsType!) { - createMacaroon(auth: $auth, permissions: $permissions) + mutation CreateMacaroon($permissions: permissionsType!) { + createMacaroon(permissions: $permissions) } `; diff --git a/src/graphql/mutations/keysend.ts b/src/graphql/mutations/keysend.ts index b9b90f2d..f9de2df5 100644 --- a/src/graphql/mutations/keysend.ts +++ b/src/graphql/mutations/keysend.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const KEY_SEND = gql` - mutation Keysend($destination: String!, $auth: authType!, $tokens: Int!) { - keysend(destination: $destination, auth: $auth, tokens: $tokens) { + mutation Keysend($destination: String!, $tokens: Int!) { + keysend(destination: $destination, tokens: $tokens) { is_confirmed } } diff --git a/src/graphql/mutations/logout.ts b/src/graphql/mutations/logout.ts index 1801003f..269af2e5 100644 --- a/src/graphql/mutations/logout.ts +++ b/src/graphql/mutations/logout.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const LOGOUT = gql` mutation Logout($type: String!) { diff --git a/src/graphql/mutations/openChannel.ts b/src/graphql/mutations/openChannel.ts index e0b74633..f724f677 100644 --- a/src/graphql/mutations/openChannel.ts +++ b/src/graphql/mutations/openChannel.ts @@ -1,17 +1,15 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const OPEN_CHANNEL = gql` mutation OpenChannel( $amount: Int! $partnerPublicKey: String! - $auth: authType! $tokensPerVByte: Int $isPrivate: Boolean ) { openChannel( amount: $amount partnerPublicKey: $partnerPublicKey - auth: $auth tokensPerVByte: $tokensPerVByte isPrivate: $isPrivate ) { diff --git a/src/graphql/mutations/payViaRoute.ts b/src/graphql/mutations/payViaRoute.ts index ca34d22a..2ba29044 100644 --- a/src/graphql/mutations/payViaRoute.ts +++ b/src/graphql/mutations/payViaRoute.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const PAY_VIA_ROUTE = gql` - mutation PayViaRoute($auth: authType!, $route: String!, $id: String!) { - payViaRoute(auth: $auth, route: $route, id: $id) + mutation PayViaRoute($route: String!, $id: String!) { + payViaRoute(route: $route, id: $id) } `; diff --git a/src/graphql/mutations/removePeer.ts b/src/graphql/mutations/removePeer.ts index beba5561..c5d83391 100644 --- a/src/graphql/mutations/removePeer.ts +++ b/src/graphql/mutations/removePeer.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const REMOVE_PEER = gql` - mutation RemovePeer($auth: authType!, $publicKey: String!) { - removePeer(auth: $auth, publicKey: $publicKey) + mutation RemovePeer($publicKey: String!) { + removePeer(publicKey: $publicKey) } `; diff --git a/src/graphql/mutations/sendMessage.ts b/src/graphql/mutations/sendMessage.ts index 2040f8c7..99fe8c5e 100644 --- a/src/graphql/mutations/sendMessage.ts +++ b/src/graphql/mutations/sendMessage.ts @@ -1,8 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const SEND_MESSAGE = gql` mutation SendMessage( - $auth: authType! $publicKey: String! $message: String! $messageType: String @@ -10,7 +9,6 @@ export const SEND_MESSAGE = gql` $maxFee: Int ) { sendMessage( - auth: $auth publicKey: $publicKey message: $message messageType: $messageType diff --git a/src/graphql/mutations/sendToAddress.ts b/src/graphql/mutations/sendToAddress.ts index 4b00efd7..68380fa7 100644 --- a/src/graphql/mutations/sendToAddress.ts +++ b/src/graphql/mutations/sendToAddress.ts @@ -1,8 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const PAY_ADDRESS = gql` mutation PayAddress( - $auth: authType! $address: String! $tokens: Int $fee: Int @@ -10,7 +9,6 @@ export const PAY_ADDRESS = gql` $sendAll: Boolean ) { sendToAddress( - auth: $auth address: $address tokens: $tokens fee: $fee diff --git a/src/graphql/mutations/updateFees.ts b/src/graphql/mutations/updateFees.ts index 49052e75..559f3923 100644 --- a/src/graphql/mutations/updateFees.ts +++ b/src/graphql/mutations/updateFees.ts @@ -1,8 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const UPDATE_FEES = gql` mutation UpdateFees( - $auth: authType! $transaction_id: String $transaction_vout: Int $base_fee_tokens: Float @@ -12,7 +11,6 @@ export const UPDATE_FEES = gql` $min_htlc_mtokens: String ) { updateFees( - auth: $auth transaction_id: $transaction_id transaction_vout: $transaction_vout base_fee_tokens: $base_fee_tokens diff --git a/src/graphql/queries/__generated__/adminCheck.generated.tsx b/src/graphql/queries/__generated__/adminCheck.generated.tsx index 186ffd84..6e31f49f 100644 --- a/src/graphql/queries/__generated__/adminCheck.generated.tsx +++ b/src/graphql/queries/__generated__/adminCheck.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type GetCanAdminQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetCanAdminQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetCanAdminQuery = { __typename?: 'Query' } & Pick< Types.Query, @@ -13,8 +16,8 @@ export type GetCanAdminQuery = { __typename?: 'Query' } & Pick< >; export const GetCanAdminDocument = gql` - query GetCanAdmin($auth: authType!) { - adminCheck(auth: $auth) + query GetCanAdmin { + adminCheck } `; @@ -30,37 +33,33 @@ export const GetCanAdminDocument = gql` * @example * const { data, loading, error } = useGetCanAdminQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetCanAdminQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetCanAdminQuery, - GetCanAdminQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetCanAdminDocument, baseOptions ); } export function useGetCanAdminLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetCanAdminQuery, GetCanAdminQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetCanAdminQuery, - GetCanAdminQueryVariables - >(GetCanAdminDocument, baseOptions); + return useLazyQuery( + GetCanAdminDocument, + baseOptions + ); } export type GetCanAdminQueryHookResult = ReturnType; export type GetCanAdminLazyQueryHookResult = ReturnType< typeof useGetCanAdminLazyQuery >; -export type GetCanAdminQueryResult = ApolloReactCommon.QueryResult< +export type GetCanAdminQueryResult = QueryResult< GetCanAdminQuery, GetCanAdminQueryVariables >; diff --git a/src/graphql/queries/__generated__/decodeRequest.generated.tsx b/src/graphql/queries/__generated__/decodeRequest.generated.tsx index 127bbb37..1a920fb0 100644 --- a/src/graphql/queries/__generated__/decodeRequest.generated.tsx +++ b/src/graphql/queries/__generated__/decodeRequest.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type DecodeRequestQueryVariables = Types.Exact<{ - auth: Types.AuthType; request: Types.Scalars['String']; }>; @@ -83,8 +87,8 @@ export type DecodeRequestQuery = { __typename?: 'Query' } & { }; export const DecodeRequestDocument = gql` - query DecodeRequest($auth: authType!, $request: String!) { - decodeRequest(auth: $auth, request: $request) { + query DecodeRequest($request: String!) { + decodeRequest(request: $request) { chain_address cltv_delta description @@ -148,32 +152,31 @@ export const DecodeRequestDocument = gql` * @example * const { data, loading, error } = useDecodeRequestQuery({ * variables: { - * auth: // value for 'auth' * request: // value for 'request' * }, * }); */ export function useDecodeRequestQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< DecodeRequestQuery, DecodeRequestQueryVariables > ) { - return ApolloReactHooks.useQuery< - DecodeRequestQuery, - DecodeRequestQueryVariables - >(DecodeRequestDocument, baseOptions); + return useQuery( + DecodeRequestDocument, + baseOptions + ); } export function useDecodeRequestLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< DecodeRequestQuery, DecodeRequestQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - DecodeRequestQuery, - DecodeRequestQueryVariables - >(DecodeRequestDocument, baseOptions); + return useLazyQuery( + DecodeRequestDocument, + baseOptions + ); } export type DecodeRequestQueryHookResult = ReturnType< typeof useDecodeRequestQuery @@ -181,7 +184,7 @@ export type DecodeRequestQueryHookResult = ReturnType< export type DecodeRequestLazyQueryHookResult = ReturnType< typeof useDecodeRequestLazyQuery >; -export type DecodeRequestQueryResult = ApolloReactCommon.QueryResult< +export type DecodeRequestQueryResult = QueryResult< DecodeRequestQuery, DecodeRequestQueryVariables >; diff --git a/src/graphql/queries/__generated__/getAccount.generated.tsx b/src/graphql/queries/__generated__/getAccount.generated.tsx new file mode 100644 index 00000000..1a2cafac --- /dev/null +++ b/src/graphql/queries/__generated__/getAccount.generated.tsx @@ -0,0 +1,71 @@ +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; +import * as Types from '../../types'; + +export type GetAccountQueryVariables = Types.Exact<{ [key: string]: never }>; + +export type GetAccountQuery = { __typename?: 'Query' } & { + getAccount?: Types.Maybe< + { __typename?: 'serverAccountType' } & Pick< + Types.ServerAccountType, + 'name' | 'id' | 'loggedIn' | 'type' + > + >; +}; + +export const GetAccountDocument = gql` + query GetAccount { + getAccount { + name + id + loggedIn + type + } + } +`; + +/** + * __useGetAccountQuery__ + * + * To run a query within a React component, call `useGetAccountQuery` and pass it any options that fit your needs. + * When your component renders, `useGetAccountQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useGetAccountQuery({ + * variables: { + * }, + * }); + */ +export function useGetAccountQuery( + baseOptions?: QueryHookOptions +) { + return useQuery( + GetAccountDocument, + baseOptions + ); +} +export function useGetAccountLazyQuery( + baseOptions?: LazyQueryHookOptions +) { + return useLazyQuery( + GetAccountDocument, + baseOptions + ); +} +export type GetAccountQueryHookResult = ReturnType; +export type GetAccountLazyQueryHookResult = ReturnType< + typeof useGetAccountLazyQuery +>; +export type GetAccountQueryResult = QueryResult< + GetAccountQuery, + GetAccountQueryVariables +>; diff --git a/src/graphql/queries/__generated__/getAccountingReport.generated.tsx b/src/graphql/queries/__generated__/getAccountingReport.generated.tsx index d4f3e0ff..59a788c9 100644 --- a/src/graphql/queries/__generated__/getAccountingReport.generated.tsx +++ b/src/graphql/queries/__generated__/getAccountingReport.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetAccountingReportQueryVariables = Types.Exact<{ - auth: Types.AuthType; category?: Types.Maybe; currency?: Types.Maybe; fiat?: Types.Maybe; @@ -19,7 +23,6 @@ export type GetAccountingReportQuery = { __typename?: 'Query' } & Pick< export const GetAccountingReportDocument = gql` query GetAccountingReport( - $auth: authType! $category: String $currency: String $fiat: String @@ -27,7 +30,6 @@ export const GetAccountingReportDocument = gql` $year: String ) { getAccountingReport( - auth: $auth category: $category currency: $currency fiat: $fiat @@ -49,7 +51,6 @@ export const GetAccountingReportDocument = gql` * @example * const { data, loading, error } = useGetAccountingReportQuery({ * variables: { - * auth: // value for 'auth' * category: // value for 'category' * currency: // value for 'currency' * fiat: // value for 'fiat' @@ -59,23 +60,23 @@ export const GetAccountingReportDocument = gql` * }); */ export function useGetAccountingReportQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetAccountingReportQuery, GetAccountingReportQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetAccountingReportQuery, - GetAccountingReportQueryVariables - >(GetAccountingReportDocument, baseOptions); + return useQuery( + GetAccountingReportDocument, + baseOptions + ); } export function useGetAccountingReportLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetAccountingReportQuery, GetAccountingReportQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< + return useLazyQuery< GetAccountingReportQuery, GetAccountingReportQueryVariables >(GetAccountingReportDocument, baseOptions); @@ -86,7 +87,7 @@ export type GetAccountingReportQueryHookResult = ReturnType< export type GetAccountingReportLazyQueryHookResult = ReturnType< typeof useGetAccountingReportLazyQuery >; -export type GetAccountingReportQueryResult = ApolloReactCommon.QueryResult< +export type GetAccountingReportQueryResult = QueryResult< GetAccountingReportQuery, GetAccountingReportQueryVariables >; diff --git a/src/graphql/queries/__generated__/getAuthToken.generated.tsx b/src/graphql/queries/__generated__/getAuthToken.generated.tsx index 9ff8a623..906cedf5 100644 --- a/src/graphql/queries/__generated__/getAuthToken.generated.tsx +++ b/src/graphql/queries/__generated__/getAuthToken.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetAuthTokenQueryVariables = Types.Exact<{ @@ -35,26 +40,23 @@ export const GetAuthTokenDocument = gql` * }); */ export function useGetAuthTokenQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetAuthTokenQuery, - GetAuthTokenQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery< - GetAuthTokenQuery, - GetAuthTokenQueryVariables - >(GetAuthTokenDocument, baseOptions); + return useQuery( + GetAuthTokenDocument, + baseOptions + ); } export function useGetAuthTokenLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetAuthTokenQuery, GetAuthTokenQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetAuthTokenQuery, - GetAuthTokenQueryVariables - >(GetAuthTokenDocument, baseOptions); + return useLazyQuery( + GetAuthTokenDocument, + baseOptions + ); } export type GetAuthTokenQueryHookResult = ReturnType< typeof useGetAuthTokenQuery @@ -62,7 +64,7 @@ export type GetAuthTokenQueryHookResult = ReturnType< export type GetAuthTokenLazyQueryHookResult = ReturnType< typeof useGetAuthTokenLazyQuery >; -export type GetAuthTokenQueryResult = ApolloReactCommon.QueryResult< +export type GetAuthTokenQueryResult = QueryResult< GetAuthTokenQuery, GetAuthTokenQueryVariables >; diff --git a/src/graphql/queries/__generated__/getBackups.generated.tsx b/src/graphql/queries/__generated__/getBackups.generated.tsx index 06d512c2..79b1c7f5 100644 --- a/src/graphql/queries/__generated__/getBackups.generated.tsx +++ b/src/graphql/queries/__generated__/getBackups.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type GetBackupsQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetBackupsQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetBackupsQuery = { __typename?: 'Query' } & Pick< Types.Query, @@ -13,8 +16,8 @@ export type GetBackupsQuery = { __typename?: 'Query' } & Pick< >; export const GetBackupsDocument = gql` - query GetBackups($auth: authType!) { - getBackups(auth: $auth) + query GetBackups { + getBackups } `; @@ -30,37 +33,30 @@ export const GetBackupsDocument = gql` * @example * const { data, loading, error } = useGetBackupsQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetBackupsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetBackupsQuery, - GetBackupsQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetBackupsDocument, baseOptions ); } export function useGetBackupsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetBackupsQuery, - GetBackupsQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery< - GetBackupsQuery, - GetBackupsQueryVariables - >(GetBackupsDocument, baseOptions); + return useLazyQuery( + GetBackupsDocument, + baseOptions + ); } export type GetBackupsQueryHookResult = ReturnType; export type GetBackupsLazyQueryHookResult = ReturnType< typeof useGetBackupsLazyQuery >; -export type GetBackupsQueryResult = ApolloReactCommon.QueryResult< +export type GetBackupsQueryResult = QueryResult< GetBackupsQuery, GetBackupsQueryVariables >; diff --git a/src/graphql/queries/__generated__/getBaseNodes.generated.tsx b/src/graphql/queries/__generated__/getBaseNodes.generated.tsx index bfe490c7..db0479de 100644 --- a/src/graphql/queries/__generated__/getBaseNodes.generated.tsx +++ b/src/graphql/queries/__generated__/getBaseNodes.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetBaseNodesQueryVariables = Types.Exact<{ [key: string]: never }>; @@ -43,26 +48,23 @@ export const GetBaseNodesDocument = gql` * }); */ export function useGetBaseNodesQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetBaseNodesQuery, - GetBaseNodesQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery< - GetBaseNodesQuery, - GetBaseNodesQueryVariables - >(GetBaseNodesDocument, baseOptions); + return useQuery( + GetBaseNodesDocument, + baseOptions + ); } export function useGetBaseNodesLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetBaseNodesQuery, GetBaseNodesQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetBaseNodesQuery, - GetBaseNodesQueryVariables - >(GetBaseNodesDocument, baseOptions); + return useLazyQuery( + GetBaseNodesDocument, + baseOptions + ); } export type GetBaseNodesQueryHookResult = ReturnType< typeof useGetBaseNodesQuery @@ -70,7 +72,7 @@ export type GetBaseNodesQueryHookResult = ReturnType< export type GetBaseNodesLazyQueryHookResult = ReturnType< typeof useGetBaseNodesLazyQuery >; -export type GetBaseNodesQueryResult = ApolloReactCommon.QueryResult< +export type GetBaseNodesQueryResult = QueryResult< GetBaseNodesQuery, GetBaseNodesQueryVariables >; diff --git a/src/graphql/queries/__generated__/getBitcoinFees.generated.tsx b/src/graphql/queries/__generated__/getBitcoinFees.generated.tsx index 06376d30..f45e3898 100644 --- a/src/graphql/queries/__generated__/getBitcoinFees.generated.tsx +++ b/src/graphql/queries/__generated__/getBitcoinFees.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetBitcoinFeesQueryVariables = Types.Exact<{ @@ -42,26 +47,26 @@ export const GetBitcoinFeesDocument = gql` * }); */ export function useGetBitcoinFeesQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetBitcoinFeesQuery, GetBitcoinFeesQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetBitcoinFeesQuery, - GetBitcoinFeesQueryVariables - >(GetBitcoinFeesDocument, baseOptions); + return useQuery( + GetBitcoinFeesDocument, + baseOptions + ); } export function useGetBitcoinFeesLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetBitcoinFeesQuery, GetBitcoinFeesQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetBitcoinFeesQuery, - GetBitcoinFeesQueryVariables - >(GetBitcoinFeesDocument, baseOptions); + return useLazyQuery( + GetBitcoinFeesDocument, + baseOptions + ); } export type GetBitcoinFeesQueryHookResult = ReturnType< typeof useGetBitcoinFeesQuery @@ -69,7 +74,7 @@ export type GetBitcoinFeesQueryHookResult = ReturnType< export type GetBitcoinFeesLazyQueryHookResult = ReturnType< typeof useGetBitcoinFeesLazyQuery >; -export type GetBitcoinFeesQueryResult = ApolloReactCommon.QueryResult< +export type GetBitcoinFeesQueryResult = QueryResult< GetBitcoinFeesQuery, GetBitcoinFeesQueryVariables >; diff --git a/src/graphql/queries/__generated__/getBitcoinPrice.generated.tsx b/src/graphql/queries/__generated__/getBitcoinPrice.generated.tsx index f71c5046..d4952f18 100644 --- a/src/graphql/queries/__generated__/getBitcoinPrice.generated.tsx +++ b/src/graphql/queries/__generated__/getBitcoinPrice.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetBitcoinPriceQueryVariables = Types.Exact<{ @@ -34,26 +39,26 @@ export const GetBitcoinPriceDocument = gql` * }); */ export function useGetBitcoinPriceQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetBitcoinPriceQuery, GetBitcoinPriceQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetBitcoinPriceQuery, - GetBitcoinPriceQueryVariables - >(GetBitcoinPriceDocument, baseOptions); + return useQuery( + GetBitcoinPriceDocument, + baseOptions + ); } export function useGetBitcoinPriceLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetBitcoinPriceQuery, GetBitcoinPriceQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetBitcoinPriceQuery, - GetBitcoinPriceQueryVariables - >(GetBitcoinPriceDocument, baseOptions); + return useLazyQuery( + GetBitcoinPriceDocument, + baseOptions + ); } export type GetBitcoinPriceQueryHookResult = ReturnType< typeof useGetBitcoinPriceQuery @@ -61,7 +66,7 @@ export type GetBitcoinPriceQueryHookResult = ReturnType< export type GetBitcoinPriceLazyQueryHookResult = ReturnType< typeof useGetBitcoinPriceLazyQuery >; -export type GetBitcoinPriceQueryResult = ApolloReactCommon.QueryResult< +export type GetBitcoinPriceQueryResult = QueryResult< GetBitcoinPriceQuery, GetBitcoinPriceQueryVariables >; diff --git a/src/graphql/queries/__generated__/getChainTransactions.generated.tsx b/src/graphql/queries/__generated__/getChainTransactions.generated.tsx index 1982412f..0238b709 100644 --- a/src/graphql/queries/__generated__/getChainTransactions.generated.tsx +++ b/src/graphql/queries/__generated__/getChainTransactions.generated.tsx @@ -1,10 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetChainTransactionsQueryVariables = Types.Exact<{ - auth: Types.AuthType; + [key: string]: never; }>; export type GetChainTransactionsQuery = { __typename?: 'Query' } & { @@ -28,8 +33,8 @@ export type GetChainTransactionsQuery = { __typename?: 'Query' } & { }; export const GetChainTransactionsDocument = gql` - query GetChainTransactions($auth: authType!) { - getChainTransactions(auth: $auth) { + query GetChainTransactions { + getChainTransactions { block_id confirmation_count confirmation_height @@ -54,28 +59,27 @@ export const GetChainTransactionsDocument = gql` * @example * const { data, loading, error } = useGetChainTransactionsQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetChainTransactionsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetChainTransactionsQuery, GetChainTransactionsQueryVariables > ) { - return ApolloReactHooks.useQuery< + return useQuery< GetChainTransactionsQuery, GetChainTransactionsQueryVariables >(GetChainTransactionsDocument, baseOptions); } export function useGetChainTransactionsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetChainTransactionsQuery, GetChainTransactionsQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< + return useLazyQuery< GetChainTransactionsQuery, GetChainTransactionsQueryVariables >(GetChainTransactionsDocument, baseOptions); @@ -86,7 +90,7 @@ export type GetChainTransactionsQueryHookResult = ReturnType< export type GetChainTransactionsLazyQueryHookResult = ReturnType< typeof useGetChainTransactionsLazyQuery >; -export type GetChainTransactionsQueryResult = ApolloReactCommon.QueryResult< +export type GetChainTransactionsQueryResult = QueryResult< GetChainTransactionsQuery, GetChainTransactionsQueryVariables >; diff --git a/src/graphql/queries/__generated__/getChannelFees.generated.tsx b/src/graphql/queries/__generated__/getChannelFees.generated.tsx index 80521c20..41f7c42d 100644 --- a/src/graphql/queries/__generated__/getChannelFees.generated.tsx +++ b/src/graphql/queries/__generated__/getChannelFees.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type ChannelFeesQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type ChannelFeesQueryVariables = Types.Exact<{ [key: string]: never }>; export type ChannelFeesQuery = { __typename?: 'Query' } & { getChannelFees?: Types.Maybe< @@ -59,8 +62,8 @@ export type ChannelFeesQuery = { __typename?: 'Query' } & { }; export const ChannelFeesDocument = gql` - query ChannelFees($auth: authType!) { - getChannelFees(auth: $auth) { + query ChannelFees { + getChannelFees { id partner_public_key partner_node_info { @@ -105,37 +108,33 @@ export const ChannelFeesDocument = gql` * @example * const { data, loading, error } = useChannelFeesQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useChannelFeesQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - ChannelFeesQuery, - ChannelFeesQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( ChannelFeesDocument, baseOptions ); } export function useChannelFeesLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< ChannelFeesQuery, ChannelFeesQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - ChannelFeesQuery, - ChannelFeesQueryVariables - >(ChannelFeesDocument, baseOptions); + return useLazyQuery( + ChannelFeesDocument, + baseOptions + ); } export type ChannelFeesQueryHookResult = ReturnType; export type ChannelFeesLazyQueryHookResult = ReturnType< typeof useChannelFeesLazyQuery >; -export type ChannelFeesQueryResult = ApolloReactCommon.QueryResult< +export type ChannelFeesQueryResult = QueryResult< ChannelFeesQuery, ChannelFeesQueryVariables >; diff --git a/src/graphql/queries/__generated__/getChannelReport.generated.tsx b/src/graphql/queries/__generated__/getChannelReport.generated.tsx index 6d7c38f2..f0597dd2 100644 --- a/src/graphql/queries/__generated__/getChannelReport.generated.tsx +++ b/src/graphql/queries/__generated__/getChannelReport.generated.tsx @@ -1,10 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetLiquidReportQueryVariables = Types.Exact<{ - auth: Types.AuthType; + [key: string]: never; }>; export type GetLiquidReportQuery = { __typename?: 'Query' } & { @@ -17,8 +22,8 @@ export type GetLiquidReportQuery = { __typename?: 'Query' } & { }; export const GetLiquidReportDocument = gql` - query GetLiquidReport($auth: authType!) { - getChannelReport(auth: $auth) { + query GetLiquidReport { + getChannelReport { local remote maxIn @@ -40,31 +45,30 @@ export const GetLiquidReportDocument = gql` * @example * const { data, loading, error } = useGetLiquidReportQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetLiquidReportQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetLiquidReportQuery, GetLiquidReportQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetLiquidReportQuery, - GetLiquidReportQueryVariables - >(GetLiquidReportDocument, baseOptions); + return useQuery( + GetLiquidReportDocument, + baseOptions + ); } export function useGetLiquidReportLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetLiquidReportQuery, GetLiquidReportQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetLiquidReportQuery, - GetLiquidReportQueryVariables - >(GetLiquidReportDocument, baseOptions); + return useLazyQuery( + GetLiquidReportDocument, + baseOptions + ); } export type GetLiquidReportQueryHookResult = ReturnType< typeof useGetLiquidReportQuery @@ -72,7 +76,7 @@ export type GetLiquidReportQueryHookResult = ReturnType< export type GetLiquidReportLazyQueryHookResult = ReturnType< typeof useGetLiquidReportLazyQuery >; -export type GetLiquidReportQueryResult = ApolloReactCommon.QueryResult< +export type GetLiquidReportQueryResult = QueryResult< GetLiquidReportQuery, GetLiquidReportQueryVariables >; diff --git a/src/graphql/queries/__generated__/getChannels.generated.tsx b/src/graphql/queries/__generated__/getChannels.generated.tsx index 27bce2df..63636792 100644 --- a/src/graphql/queries/__generated__/getChannels.generated.tsx +++ b/src/graphql/queries/__generated__/getChannels.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetChannelsQueryVariables = Types.Exact<{ - auth: Types.AuthType; active?: Types.Maybe; }>; @@ -63,8 +67,8 @@ export type GetChannelsQuery = { __typename?: 'Query' } & { }; export const GetChannelsDocument = gql` - query GetChannels($auth: authType!, $active: Boolean) { - getChannels(auth: $auth, active: $active) { + query GetChannels($active: Boolean) { + getChannels(active: $active) { capacity commit_transaction_fee commit_transaction_weight @@ -122,38 +126,34 @@ export const GetChannelsDocument = gql` * @example * const { data, loading, error } = useGetChannelsQuery({ * variables: { - * auth: // value for 'auth' * active: // value for 'active' * }, * }); */ export function useGetChannelsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetChannelsQuery, - GetChannelsQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetChannelsDocument, baseOptions ); } export function useGetChannelsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetChannelsQuery, GetChannelsQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetChannelsQuery, - GetChannelsQueryVariables - >(GetChannelsDocument, baseOptions); + return useLazyQuery( + GetChannelsDocument, + baseOptions + ); } export type GetChannelsQueryHookResult = ReturnType; export type GetChannelsLazyQueryHookResult = ReturnType< typeof useGetChannelsLazyQuery >; -export type GetChannelsQueryResult = ApolloReactCommon.QueryResult< +export type GetChannelsQueryResult = QueryResult< GetChannelsQuery, GetChannelsQueryVariables >; diff --git a/src/graphql/queries/__generated__/getClosedChannels.generated.tsx b/src/graphql/queries/__generated__/getClosedChannels.generated.tsx index c4a94e1e..4218014f 100644 --- a/src/graphql/queries/__generated__/getClosedChannels.generated.tsx +++ b/src/graphql/queries/__generated__/getClosedChannels.generated.tsx @@ -1,10 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetClosedChannelsQueryVariables = Types.Exact<{ - auth: Types.AuthType; + [key: string]: never; }>; export type GetClosedChannelsQuery = { __typename?: 'Query' } & { @@ -41,8 +46,8 @@ export type GetClosedChannelsQuery = { __typename?: 'Query' } & { }; export const GetClosedChannelsDocument = gql` - query GetClosedChannels($auth: authType!) { - getClosedChannels(auth: $auth) { + query GetClosedChannels { + getClosedChannels { capacity close_confirm_height close_transaction_id @@ -82,31 +87,30 @@ export const GetClosedChannelsDocument = gql` * @example * const { data, loading, error } = useGetClosedChannelsQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetClosedChannelsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetClosedChannelsQuery, GetClosedChannelsQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetClosedChannelsQuery, - GetClosedChannelsQueryVariables - >(GetClosedChannelsDocument, baseOptions); + return useQuery( + GetClosedChannelsDocument, + baseOptions + ); } export function useGetClosedChannelsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetClosedChannelsQuery, GetClosedChannelsQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetClosedChannelsQuery, - GetClosedChannelsQueryVariables - >(GetClosedChannelsDocument, baseOptions); + return useLazyQuery( + GetClosedChannelsDocument, + baseOptions + ); } export type GetClosedChannelsQueryHookResult = ReturnType< typeof useGetClosedChannelsQuery @@ -114,7 +118,7 @@ export type GetClosedChannelsQueryHookResult = ReturnType< export type GetClosedChannelsLazyQueryHookResult = ReturnType< typeof useGetClosedChannelsLazyQuery >; -export type GetClosedChannelsQueryResult = ApolloReactCommon.QueryResult< +export type GetClosedChannelsQueryResult = QueryResult< GetClosedChannelsQuery, GetClosedChannelsQueryVariables >; diff --git a/src/graphql/queries/__generated__/getFeeHealth.generated.tsx b/src/graphql/queries/__generated__/getFeeHealth.generated.tsx index 7639e17b..59bacc60 100644 --- a/src/graphql/queries/__generated__/getFeeHealth.generated.tsx +++ b/src/graphql/queries/__generated__/getFeeHealth.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type GetFeeHealthQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetFeeHealthQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetFeeHealthQuery = { __typename?: 'Query' } & { getFeeHealth?: Types.Maybe< @@ -61,8 +64,8 @@ export type GetFeeHealthQuery = { __typename?: 'Query' } & { }; export const GetFeeHealthDocument = gql` - query GetFeeHealth($auth: authType!) { - getFeeHealth(auth: $auth) { + query GetFeeHealth { + getFeeHealth { score channels { id @@ -106,31 +109,27 @@ export const GetFeeHealthDocument = gql` * @example * const { data, loading, error } = useGetFeeHealthQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetFeeHealthQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetFeeHealthQuery, - GetFeeHealthQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery< - GetFeeHealthQuery, - GetFeeHealthQueryVariables - >(GetFeeHealthDocument, baseOptions); + return useQuery( + GetFeeHealthDocument, + baseOptions + ); } export function useGetFeeHealthLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetFeeHealthQuery, GetFeeHealthQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetFeeHealthQuery, - GetFeeHealthQueryVariables - >(GetFeeHealthDocument, baseOptions); + return useLazyQuery( + GetFeeHealthDocument, + baseOptions + ); } export type GetFeeHealthQueryHookResult = ReturnType< typeof useGetFeeHealthQuery @@ -138,7 +137,7 @@ export type GetFeeHealthQueryHookResult = ReturnType< export type GetFeeHealthLazyQueryHookResult = ReturnType< typeof useGetFeeHealthLazyQuery >; -export type GetFeeHealthQueryResult = ApolloReactCommon.QueryResult< +export type GetFeeHealthQueryResult = QueryResult< GetFeeHealthQuery, GetFeeHealthQueryVariables >; diff --git a/src/graphql/queries/__generated__/getForwardChannelsReport.generated.tsx b/src/graphql/queries/__generated__/getForwardChannelsReport.generated.tsx index ab61ab1b..908ed939 100644 --- a/src/graphql/queries/__generated__/getForwardChannelsReport.generated.tsx +++ b/src/graphql/queries/__generated__/getForwardChannelsReport.generated.tsx @@ -1,13 +1,17 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetForwardChannelsReportQueryVariables = Types.Exact<{ time?: Types.Maybe; order?: Types.Maybe; type?: Types.Maybe; - auth: Types.AuthType; }>; export type GetForwardChannelsReportQuery = { __typename?: 'Query' } & Pick< @@ -16,18 +20,8 @@ export type GetForwardChannelsReportQuery = { __typename?: 'Query' } & Pick< >; export const GetForwardChannelsReportDocument = gql` - query GetForwardChannelsReport( - $time: String - $order: String - $type: String - $auth: authType! - ) { - getForwardChannelsReport( - time: $time - order: $order - auth: $auth - type: $type - ) + query GetForwardChannelsReport($time: String, $order: String, $type: String) { + getForwardChannelsReport(time: $time, order: $order, type: $type) } `; @@ -46,28 +40,27 @@ export const GetForwardChannelsReportDocument = gql` * time: // value for 'time' * order: // value for 'order' * type: // value for 'type' - * auth: // value for 'auth' * }, * }); */ export function useGetForwardChannelsReportQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetForwardChannelsReportQuery, GetForwardChannelsReportQueryVariables > ) { - return ApolloReactHooks.useQuery< + return useQuery< GetForwardChannelsReportQuery, GetForwardChannelsReportQueryVariables >(GetForwardChannelsReportDocument, baseOptions); } export function useGetForwardChannelsReportLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetForwardChannelsReportQuery, GetForwardChannelsReportQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< + return useLazyQuery< GetForwardChannelsReportQuery, GetForwardChannelsReportQueryVariables >(GetForwardChannelsReportDocument, baseOptions); @@ -78,7 +71,7 @@ export type GetForwardChannelsReportQueryHookResult = ReturnType< export type GetForwardChannelsReportLazyQueryHookResult = ReturnType< typeof useGetForwardChannelsReportLazyQuery >; -export type GetForwardChannelsReportQueryResult = ApolloReactCommon.QueryResult< +export type GetForwardChannelsReportQueryResult = QueryResult< GetForwardChannelsReportQuery, GetForwardChannelsReportQueryVariables >; diff --git a/src/graphql/queries/__generated__/getForwardReport.generated.tsx b/src/graphql/queries/__generated__/getForwardReport.generated.tsx index a69e0c32..1029d6dc 100644 --- a/src/graphql/queries/__generated__/getForwardReport.generated.tsx +++ b/src/graphql/queries/__generated__/getForwardReport.generated.tsx @@ -1,11 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetForwardReportQueryVariables = Types.Exact<{ time?: Types.Maybe; - auth: Types.AuthType; }>; export type GetForwardReportQuery = { __typename?: 'Query' } & Pick< @@ -14,8 +18,8 @@ export type GetForwardReportQuery = { __typename?: 'Query' } & Pick< >; export const GetForwardReportDocument = gql` - query GetForwardReport($time: String, $auth: authType!) { - getForwardReport(time: $time, auth: $auth) + query GetForwardReport($time: String) { + getForwardReport(time: $time) } `; @@ -32,31 +36,30 @@ export const GetForwardReportDocument = gql` * const { data, loading, error } = useGetForwardReportQuery({ * variables: { * time: // value for 'time' - * auth: // value for 'auth' * }, * }); */ export function useGetForwardReportQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetForwardReportQuery, GetForwardReportQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetForwardReportQuery, - GetForwardReportQueryVariables - >(GetForwardReportDocument, baseOptions); + return useQuery( + GetForwardReportDocument, + baseOptions + ); } export function useGetForwardReportLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetForwardReportQuery, GetForwardReportQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetForwardReportQuery, - GetForwardReportQueryVariables - >(GetForwardReportDocument, baseOptions); + return useLazyQuery( + GetForwardReportDocument, + baseOptions + ); } export type GetForwardReportQueryHookResult = ReturnType< typeof useGetForwardReportQuery @@ -64,7 +67,7 @@ export type GetForwardReportQueryHookResult = ReturnType< export type GetForwardReportLazyQueryHookResult = ReturnType< typeof useGetForwardReportLazyQuery >; -export type GetForwardReportQueryResult = ApolloReactCommon.QueryResult< +export type GetForwardReportQueryResult = QueryResult< GetForwardReportQuery, GetForwardReportQueryVariables >; diff --git a/src/graphql/queries/__generated__/getForwards.generated.tsx b/src/graphql/queries/__generated__/getForwards.generated.tsx index e2300a0c..95ea4e85 100644 --- a/src/graphql/queries/__generated__/getForwards.generated.tsx +++ b/src/graphql/queries/__generated__/getForwards.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetForwardsQueryVariables = Types.Exact<{ - auth: Types.AuthType; time?: Types.Maybe; }>; @@ -73,8 +77,8 @@ export type GetForwardsQuery = { __typename?: 'Query' } & { }; export const GetForwardsDocument = gql` - query GetForwards($auth: authType!, $time: String) { - getForwards(auth: $auth, time: $time) { + query GetForwards($time: String) { + getForwards(time: $time) { forwards { created_at fee @@ -125,38 +129,34 @@ export const GetForwardsDocument = gql` * @example * const { data, loading, error } = useGetForwardsQuery({ * variables: { - * auth: // value for 'auth' * time: // value for 'time' * }, * }); */ export function useGetForwardsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetForwardsQuery, - GetForwardsQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetForwardsDocument, baseOptions ); } export function useGetForwardsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetForwardsQuery, GetForwardsQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetForwardsQuery, - GetForwardsQueryVariables - >(GetForwardsDocument, baseOptions); + return useLazyQuery( + GetForwardsDocument, + baseOptions + ); } export type GetForwardsQueryHookResult = ReturnType; export type GetForwardsLazyQueryHookResult = ReturnType< typeof useGetForwardsLazyQuery >; -export type GetForwardsQueryResult = ApolloReactCommon.QueryResult< +export type GetForwardsQueryResult = QueryResult< GetForwardsQuery, GetForwardsQueryVariables >; diff --git a/src/graphql/queries/__generated__/getInOut.generated.tsx b/src/graphql/queries/__generated__/getInOut.generated.tsx index b9981234..f72aba33 100644 --- a/src/graphql/queries/__generated__/getInOut.generated.tsx +++ b/src/graphql/queries/__generated__/getInOut.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetInOutQueryVariables = Types.Exact<{ - auth: Types.AuthType; time?: Types.Maybe; }>; @@ -18,8 +22,8 @@ export type GetInOutQuery = { __typename?: 'Query' } & { }; export const GetInOutDocument = gql` - query GetInOut($auth: authType!, $time: String) { - getInOut(auth: $auth, time: $time) { + query GetInOut($time: String) { + getInOut(time: $time) { invoices payments confirmedInvoices @@ -40,29 +44,22 @@ export const GetInOutDocument = gql` * @example * const { data, loading, error } = useGetInOutQuery({ * variables: { - * auth: // value for 'auth' * time: // value for 'time' * }, * }); */ export function useGetInOutQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetInOutQuery, - GetInOutQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetInOutDocument, baseOptions ); } export function useGetInOutLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetInOutQuery, - GetInOutQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery( + return useLazyQuery( GetInOutDocument, baseOptions ); @@ -71,7 +68,7 @@ export type GetInOutQueryHookResult = ReturnType; export type GetInOutLazyQueryHookResult = ReturnType< typeof useGetInOutLazyQuery >; -export type GetInOutQueryResult = ApolloReactCommon.QueryResult< +export type GetInOutQueryResult = QueryResult< GetInOutQuery, GetInOutQueryVariables >; diff --git a/src/graphql/queries/__generated__/getLatestVersion.generated.tsx b/src/graphql/queries/__generated__/getLatestVersion.generated.tsx index 485ca4c4..81477025 100644 --- a/src/graphql/queries/__generated__/getLatestVersion.generated.tsx +++ b/src/graphql/queries/__generated__/getLatestVersion.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetLatestVersionQueryVariables = Types.Exact<{ @@ -34,26 +39,26 @@ export const GetLatestVersionDocument = gql` * }); */ export function useGetLatestVersionQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetLatestVersionQuery, GetLatestVersionQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetLatestVersionQuery, - GetLatestVersionQueryVariables - >(GetLatestVersionDocument, baseOptions); + return useQuery( + GetLatestVersionDocument, + baseOptions + ); } export function useGetLatestVersionLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetLatestVersionQuery, GetLatestVersionQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetLatestVersionQuery, - GetLatestVersionQueryVariables - >(GetLatestVersionDocument, baseOptions); + return useLazyQuery( + GetLatestVersionDocument, + baseOptions + ); } export type GetLatestVersionQueryHookResult = ReturnType< typeof useGetLatestVersionQuery @@ -61,7 +66,7 @@ export type GetLatestVersionQueryHookResult = ReturnType< export type GetLatestVersionLazyQueryHookResult = ReturnType< typeof useGetLatestVersionLazyQuery >; -export type GetLatestVersionQueryResult = ApolloReactCommon.QueryResult< +export type GetLatestVersionQueryResult = QueryResult< GetLatestVersionQuery, GetLatestVersionQueryVariables >; diff --git a/src/graphql/queries/__generated__/getLnPay.generated.tsx b/src/graphql/queries/__generated__/getLnPay.generated.tsx index 200397b5..a2d99cca 100644 --- a/src/graphql/queries/__generated__/getLnPay.generated.tsx +++ b/src/graphql/queries/__generated__/getLnPay.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetLnPayQueryVariables = Types.Exact<{ @@ -35,23 +40,17 @@ export const GetLnPayDocument = gql` * }); */ export function useGetLnPayQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetLnPayQuery, - GetLnPayQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetLnPayDocument, baseOptions ); } export function useGetLnPayLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetLnPayQuery, - GetLnPayQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery( + return useLazyQuery( GetLnPayDocument, baseOptions ); @@ -60,7 +59,7 @@ export type GetLnPayQueryHookResult = ReturnType; export type GetLnPayLazyQueryHookResult = ReturnType< typeof useGetLnPayLazyQuery >; -export type GetLnPayQueryResult = ApolloReactCommon.QueryResult< +export type GetLnPayQueryResult = QueryResult< GetLnPayQuery, GetLnPayQueryVariables >; diff --git a/src/graphql/queries/__generated__/getLnPayInfo.generated.tsx b/src/graphql/queries/__generated__/getLnPayInfo.generated.tsx index 738aaca9..b4164c34 100644 --- a/src/graphql/queries/__generated__/getLnPayInfo.generated.tsx +++ b/src/graphql/queries/__generated__/getLnPayInfo.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetLnPayInfoQueryVariables = Types.Exact<{ [key: string]: never }>; @@ -36,26 +41,23 @@ export const GetLnPayInfoDocument = gql` * }); */ export function useGetLnPayInfoQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetLnPayInfoQuery, - GetLnPayInfoQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery< - GetLnPayInfoQuery, - GetLnPayInfoQueryVariables - >(GetLnPayInfoDocument, baseOptions); + return useQuery( + GetLnPayInfoDocument, + baseOptions + ); } export function useGetLnPayInfoLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetLnPayInfoQuery, GetLnPayInfoQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetLnPayInfoQuery, - GetLnPayInfoQueryVariables - >(GetLnPayInfoDocument, baseOptions); + return useLazyQuery( + GetLnPayInfoDocument, + baseOptions + ); } export type GetLnPayInfoQueryHookResult = ReturnType< typeof useGetLnPayInfoQuery @@ -63,7 +65,7 @@ export type GetLnPayInfoQueryHookResult = ReturnType< export type GetLnPayInfoLazyQueryHookResult = ReturnType< typeof useGetLnPayInfoLazyQuery >; -export type GetLnPayInfoQueryResult = ApolloReactCommon.QueryResult< +export type GetLnPayInfoQueryResult = QueryResult< GetLnPayInfoQuery, GetLnPayInfoQueryVariables >; diff --git a/src/graphql/queries/__generated__/getMessages.generated.tsx b/src/graphql/queries/__generated__/getMessages.generated.tsx index 965ced99..4210054c 100644 --- a/src/graphql/queries/__generated__/getMessages.generated.tsx +++ b/src/graphql/queries/__generated__/getMessages.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetMessagesQueryVariables = Types.Exact<{ - auth: Types.AuthType; initialize?: Types.Maybe; lastMessage?: Types.Maybe; }>; @@ -35,16 +39,8 @@ export type GetMessagesQuery = { __typename?: 'Query' } & { }; export const GetMessagesDocument = gql` - query GetMessages( - $auth: authType! - $initialize: Boolean - $lastMessage: String - ) { - getMessages( - auth: $auth - initialize: $initialize - lastMessage: $lastMessage - ) { + query GetMessages($initialize: Boolean, $lastMessage: String) { + getMessages(initialize: $initialize, lastMessage: $lastMessage) { token messages { date @@ -72,39 +68,35 @@ export const GetMessagesDocument = gql` * @example * const { data, loading, error } = useGetMessagesQuery({ * variables: { - * auth: // value for 'auth' * initialize: // value for 'initialize' * lastMessage: // value for 'lastMessage' * }, * }); */ export function useGetMessagesQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetMessagesQuery, - GetMessagesQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetMessagesDocument, baseOptions ); } export function useGetMessagesLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetMessagesQuery, GetMessagesQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetMessagesQuery, - GetMessagesQueryVariables - >(GetMessagesDocument, baseOptions); + return useLazyQuery( + GetMessagesDocument, + baseOptions + ); } export type GetMessagesQueryHookResult = ReturnType; export type GetMessagesLazyQueryHookResult = ReturnType< typeof useGetMessagesLazyQuery >; -export type GetMessagesQueryResult = ApolloReactCommon.QueryResult< +export type GetMessagesQueryResult = QueryResult< GetMessagesQuery, GetMessagesQueryVariables >; diff --git a/src/graphql/queries/__generated__/getNetworkInfo.generated.tsx b/src/graphql/queries/__generated__/getNetworkInfo.generated.tsx index bd252c26..70640631 100644 --- a/src/graphql/queries/__generated__/getNetworkInfo.generated.tsx +++ b/src/graphql/queries/__generated__/getNetworkInfo.generated.tsx @@ -1,10 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetNetworkInfoQueryVariables = Types.Exact<{ - auth: Types.AuthType; + [key: string]: never; }>; export type GetNetworkInfoQuery = { __typename?: 'Query' } & { @@ -24,8 +29,8 @@ export type GetNetworkInfoQuery = { __typename?: 'Query' } & { }; export const GetNetworkInfoDocument = gql` - query GetNetworkInfo($auth: authType!) { - getNetworkInfo(auth: $auth) { + query GetNetworkInfo { + getNetworkInfo { averageChannelSize channelCount maxChannelSize @@ -50,31 +55,30 @@ export const GetNetworkInfoDocument = gql` * @example * const { data, loading, error } = useGetNetworkInfoQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetNetworkInfoQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetNetworkInfoQuery, GetNetworkInfoQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetNetworkInfoQuery, - GetNetworkInfoQueryVariables - >(GetNetworkInfoDocument, baseOptions); + return useQuery( + GetNetworkInfoDocument, + baseOptions + ); } export function useGetNetworkInfoLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetNetworkInfoQuery, GetNetworkInfoQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetNetworkInfoQuery, - GetNetworkInfoQueryVariables - >(GetNetworkInfoDocument, baseOptions); + return useLazyQuery( + GetNetworkInfoDocument, + baseOptions + ); } export type GetNetworkInfoQueryHookResult = ReturnType< typeof useGetNetworkInfoQuery @@ -82,7 +86,7 @@ export type GetNetworkInfoQueryHookResult = ReturnType< export type GetNetworkInfoLazyQueryHookResult = ReturnType< typeof useGetNetworkInfoLazyQuery >; -export type GetNetworkInfoQueryResult = ApolloReactCommon.QueryResult< +export type GetNetworkInfoQueryResult = QueryResult< GetNetworkInfoQuery, GetNetworkInfoQueryVariables >; diff --git a/src/graphql/queries/__generated__/getNode.generated.tsx b/src/graphql/queries/__generated__/getNode.generated.tsx index 2233e7b5..18302a48 100644 --- a/src/graphql/queries/__generated__/getNode.generated.tsx +++ b/src/graphql/queries/__generated__/getNode.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetNodeQueryVariables = Types.Exact<{ - auth: Types.AuthType; publicKey: Types.Scalars['String']; withoutChannels?: Types.Maybe; }>; @@ -19,16 +23,8 @@ export type GetNodeQuery = { __typename?: 'Query' } & { }; export const GetNodeDocument = gql` - query GetNode( - $auth: authType! - $publicKey: String! - $withoutChannels: Boolean - ) { - getNode( - auth: $auth - publicKey: $publicKey - withoutChannels: $withoutChannels - ) { + query GetNode($publicKey: String!, $withoutChannels: Boolean) { + getNode(publicKey: $publicKey, withoutChannels: $withoutChannels) { node { alias capacity @@ -52,37 +48,30 @@ export const GetNodeDocument = gql` * @example * const { data, loading, error } = useGetNodeQuery({ * variables: { - * auth: // value for 'auth' * publicKey: // value for 'publicKey' * withoutChannels: // value for 'withoutChannels' * }, * }); */ export function useGetNodeQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetNodeQuery, - GetNodeQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetNodeDocument, baseOptions ); } export function useGetNodeLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetNodeQuery, - GetNodeQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery( + return useLazyQuery( GetNodeDocument, baseOptions ); } export type GetNodeQueryHookResult = ReturnType; export type GetNodeLazyQueryHookResult = ReturnType; -export type GetNodeQueryResult = ApolloReactCommon.QueryResult< +export type GetNodeQueryResult = QueryResult< GetNodeQuery, GetNodeQueryVariables >; diff --git a/src/graphql/queries/__generated__/getNodeInfo.generated.tsx b/src/graphql/queries/__generated__/getNodeInfo.generated.tsx index 8d58e6d6..855c803e 100644 --- a/src/graphql/queries/__generated__/getNodeInfo.generated.tsx +++ b/src/graphql/queries/__generated__/getNodeInfo.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type GetCanConnectQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetCanConnectQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetCanConnectQuery = { __typename?: 'Query' } & { getNodeInfo?: Types.Maybe< @@ -24,9 +27,7 @@ export type GetCanConnectQuery = { __typename?: 'Query' } & { >; }; -export type GetNodeInfoQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetNodeInfoQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetNodeInfoQuery = { __typename?: 'Query' } & Pick< Types.Query, @@ -55,7 +56,7 @@ export type GetNodeInfoQuery = { __typename?: 'Query' } & Pick< }; export type GetChannelAmountInfoQueryVariables = Types.Exact<{ - auth: Types.AuthType; + [key: string]: never; }>; export type GetChannelAmountInfoQuery = { __typename?: 'Query' } & { @@ -70,7 +71,7 @@ export type GetChannelAmountInfoQuery = { __typename?: 'Query' } & { }; export type GetCanConnectInfoQueryVariables = Types.Exact<{ - auth: Types.AuthType; + [key: string]: never; }>; export type GetCanConnectInfoQuery = { __typename?: 'Query' } & { @@ -83,8 +84,8 @@ export type GetCanConnectInfoQuery = { __typename?: 'Query' } & { }; export const GetCanConnectDocument = gql` - query GetCanConnect($auth: authType!) { - getNodeInfo(auth: $auth) { + query GetCanConnect { + getNodeInfo { chains color active_channels_count @@ -110,31 +111,30 @@ export const GetCanConnectDocument = gql` * @example * const { data, loading, error } = useGetCanConnectQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetCanConnectQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetCanConnectQuery, GetCanConnectQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetCanConnectQuery, - GetCanConnectQueryVariables - >(GetCanConnectDocument, baseOptions); + return useQuery( + GetCanConnectDocument, + baseOptions + ); } export function useGetCanConnectLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetCanConnectQuery, GetCanConnectQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetCanConnectQuery, - GetCanConnectQueryVariables - >(GetCanConnectDocument, baseOptions); + return useLazyQuery( + GetCanConnectDocument, + baseOptions + ); } export type GetCanConnectQueryHookResult = ReturnType< typeof useGetCanConnectQuery @@ -142,13 +142,13 @@ export type GetCanConnectQueryHookResult = ReturnType< export type GetCanConnectLazyQueryHookResult = ReturnType< typeof useGetCanConnectLazyQuery >; -export type GetCanConnectQueryResult = ApolloReactCommon.QueryResult< +export type GetCanConnectQueryResult = QueryResult< GetCanConnectQuery, GetCanConnectQueryVariables >; export const GetNodeInfoDocument = gql` - query GetNodeInfo($auth: authType!) { - getNodeInfo(auth: $auth) { + query GetNodeInfo { + getNodeInfo { chains color active_channels_count @@ -159,9 +159,9 @@ export const GetNodeInfoDocument = gql` pending_channels_count version } - getChainBalance(auth: $auth) - getPendingChainBalance(auth: $auth) - getChannelBalance(auth: $auth) { + getChainBalance + getPendingChainBalance + getChannelBalance { confirmedBalance pendingBalance } @@ -180,43 +180,39 @@ export const GetNodeInfoDocument = gql` * @example * const { data, loading, error } = useGetNodeInfoQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetNodeInfoQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetNodeInfoQuery, - GetNodeInfoQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetNodeInfoDocument, baseOptions ); } export function useGetNodeInfoLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetNodeInfoQuery, GetNodeInfoQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetNodeInfoQuery, - GetNodeInfoQueryVariables - >(GetNodeInfoDocument, baseOptions); + return useLazyQuery( + GetNodeInfoDocument, + baseOptions + ); } export type GetNodeInfoQueryHookResult = ReturnType; export type GetNodeInfoLazyQueryHookResult = ReturnType< typeof useGetNodeInfoLazyQuery >; -export type GetNodeInfoQueryResult = ApolloReactCommon.QueryResult< +export type GetNodeInfoQueryResult = QueryResult< GetNodeInfoQuery, GetNodeInfoQueryVariables >; export const GetChannelAmountInfoDocument = gql` - query GetChannelAmountInfo($auth: authType!) { - getNodeInfo(auth: $auth) { + query GetChannelAmountInfo { + getNodeInfo { active_channels_count closed_channels_count pending_channels_count @@ -236,28 +232,27 @@ export const GetChannelAmountInfoDocument = gql` * @example * const { data, loading, error } = useGetChannelAmountInfoQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetChannelAmountInfoQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetChannelAmountInfoQuery, GetChannelAmountInfoQueryVariables > ) { - return ApolloReactHooks.useQuery< + return useQuery< GetChannelAmountInfoQuery, GetChannelAmountInfoQueryVariables >(GetChannelAmountInfoDocument, baseOptions); } export function useGetChannelAmountInfoLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetChannelAmountInfoQuery, GetChannelAmountInfoQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< + return useLazyQuery< GetChannelAmountInfoQuery, GetChannelAmountInfoQueryVariables >(GetChannelAmountInfoDocument, baseOptions); @@ -268,13 +263,13 @@ export type GetChannelAmountInfoQueryHookResult = ReturnType< export type GetChannelAmountInfoLazyQueryHookResult = ReturnType< typeof useGetChannelAmountInfoLazyQuery >; -export type GetChannelAmountInfoQueryResult = ApolloReactCommon.QueryResult< +export type GetChannelAmountInfoQueryResult = QueryResult< GetChannelAmountInfoQuery, GetChannelAmountInfoQueryVariables >; export const GetCanConnectInfoDocument = gql` - query GetCanConnectInfo($auth: authType!) { - getNodeInfo(auth: $auth) { + query GetCanConnectInfo { + getNodeInfo { public_key uris } @@ -293,31 +288,30 @@ export const GetCanConnectInfoDocument = gql` * @example * const { data, loading, error } = useGetCanConnectInfoQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetCanConnectInfoQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetCanConnectInfoQuery, GetCanConnectInfoQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetCanConnectInfoQuery, - GetCanConnectInfoQueryVariables - >(GetCanConnectInfoDocument, baseOptions); + return useQuery( + GetCanConnectInfoDocument, + baseOptions + ); } export function useGetCanConnectInfoLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetCanConnectInfoQuery, GetCanConnectInfoQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetCanConnectInfoQuery, - GetCanConnectInfoQueryVariables - >(GetCanConnectInfoDocument, baseOptions); + return useLazyQuery( + GetCanConnectInfoDocument, + baseOptions + ); } export type GetCanConnectInfoQueryHookResult = ReturnType< typeof useGetCanConnectInfoQuery @@ -325,7 +319,7 @@ export type GetCanConnectInfoQueryHookResult = ReturnType< export type GetCanConnectInfoLazyQueryHookResult = ReturnType< typeof useGetCanConnectInfoLazyQuery >; -export type GetCanConnectInfoQueryResult = ApolloReactCommon.QueryResult< +export type GetCanConnectInfoQueryResult = QueryResult< GetCanConnectInfoQuery, GetCanConnectInfoQueryVariables >; diff --git a/src/graphql/queries/__generated__/getPeers.generated.tsx b/src/graphql/queries/__generated__/getPeers.generated.tsx index 07433506..34afb9fa 100644 --- a/src/graphql/queries/__generated__/getPeers.generated.tsx +++ b/src/graphql/queries/__generated__/getPeers.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type GetPeersQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetPeersQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetPeersQuery = { __typename?: 'Query' } & { getPeers?: Types.Maybe< @@ -36,8 +39,8 @@ export type GetPeersQuery = { __typename?: 'Query' } & { }; export const GetPeersDocument = gql` - query GetPeers($auth: authType!) { - getPeers(auth: $auth) { + query GetPeers { + getPeers { bytes_received bytes_sent is_inbound @@ -72,28 +75,21 @@ export const GetPeersDocument = gql` * @example * const { data, loading, error } = useGetPeersQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetPeersQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetPeersQuery, - GetPeersQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetPeersDocument, baseOptions ); } export function useGetPeersLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetPeersQuery, - GetPeersQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery( + return useLazyQuery( GetPeersDocument, baseOptions ); @@ -102,7 +98,7 @@ export type GetPeersQueryHookResult = ReturnType; export type GetPeersLazyQueryHookResult = ReturnType< typeof useGetPeersLazyQuery >; -export type GetPeersQueryResult = ApolloReactCommon.QueryResult< +export type GetPeersQueryResult = QueryResult< GetPeersQuery, GetPeersQueryVariables >; diff --git a/src/graphql/queries/__generated__/getPendingChannels.generated.tsx b/src/graphql/queries/__generated__/getPendingChannels.generated.tsx index 2f4c4425..04759ff5 100644 --- a/src/graphql/queries/__generated__/getPendingChannels.generated.tsx +++ b/src/graphql/queries/__generated__/getPendingChannels.generated.tsx @@ -1,10 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetPendingChannelsQueryVariables = Types.Exact<{ - auth: Types.AuthType; + [key: string]: never; }>; export type GetPendingChannelsQuery = { __typename?: 'Query' } & { @@ -41,8 +46,8 @@ export type GetPendingChannelsQuery = { __typename?: 'Query' } & { }; export const GetPendingChannelsDocument = gql` - query GetPendingChannels($auth: authType!) { - getPendingChannels(auth: $auth) { + query GetPendingChannels { + getPendingChannels { close_transaction_id is_active is_closing @@ -82,28 +87,27 @@ export const GetPendingChannelsDocument = gql` * @example * const { data, loading, error } = useGetPendingChannelsQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetPendingChannelsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetPendingChannelsQuery, GetPendingChannelsQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetPendingChannelsQuery, - GetPendingChannelsQueryVariables - >(GetPendingChannelsDocument, baseOptions); + return useQuery( + GetPendingChannelsDocument, + baseOptions + ); } export function useGetPendingChannelsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetPendingChannelsQuery, GetPendingChannelsQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< + return useLazyQuery< GetPendingChannelsQuery, GetPendingChannelsQueryVariables >(GetPendingChannelsDocument, baseOptions); @@ -114,7 +118,7 @@ export type GetPendingChannelsQueryHookResult = ReturnType< export type GetPendingChannelsLazyQueryHookResult = ReturnType< typeof useGetPendingChannelsLazyQuery >; -export type GetPendingChannelsQueryResult = ApolloReactCommon.QueryResult< +export type GetPendingChannelsQueryResult = QueryResult< GetPendingChannelsQuery, GetPendingChannelsQueryVariables >; diff --git a/src/graphql/queries/__generated__/getResume.generated.tsx b/src/graphql/queries/__generated__/getResume.generated.tsx index e8157f9b..15589b8c 100644 --- a/src/graphql/queries/__generated__/getResume.generated.tsx +++ b/src/graphql/queries/__generated__/getResume.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetResumeQueryVariables = Types.Exact<{ - auth: Types.AuthType; token?: Types.Maybe; }>; @@ -80,8 +84,8 @@ export type GetResumeQuery = { __typename?: 'Query' } & { }; export const GetResumeDocument = gql` - query GetResume($auth: authType!, $token: String) { - getResume(auth: $auth, token: $token) { + query GetResume($token: String) { + getResume(token: $token) { token resume { ... on InvoiceType { @@ -151,29 +155,22 @@ export const GetResumeDocument = gql` * @example * const { data, loading, error } = useGetResumeQuery({ * variables: { - * auth: // value for 'auth' * token: // value for 'token' * }, * }); */ export function useGetResumeQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetResumeQuery, - GetResumeQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetResumeDocument, baseOptions ); } export function useGetResumeLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetResumeQuery, - GetResumeQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery( + return useLazyQuery( GetResumeDocument, baseOptions ); @@ -182,7 +179,7 @@ export type GetResumeQueryHookResult = ReturnType; export type GetResumeLazyQueryHookResult = ReturnType< typeof useGetResumeLazyQuery >; -export type GetResumeQueryResult = ApolloReactCommon.QueryResult< +export type GetResumeQueryResult = QueryResult< GetResumeQuery, GetResumeQueryVariables >; diff --git a/src/graphql/queries/__generated__/getRoutes.generated.tsx b/src/graphql/queries/__generated__/getRoutes.generated.tsx index c39f421a..46c1e75a 100644 --- a/src/graphql/queries/__generated__/getRoutes.generated.tsx +++ b/src/graphql/queries/__generated__/getRoutes.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetRoutesQueryVariables = Types.Exact<{ - auth: Types.AuthType; outgoing: Types.Scalars['String']; incoming: Types.Scalars['String']; tokens: Types.Scalars['Int']; @@ -43,14 +47,12 @@ export type GetRoutesQuery = { __typename?: 'Query' } & { export const GetRoutesDocument = gql` query GetRoutes( - $auth: authType! $outgoing: String! $incoming: String! $tokens: Int! $maxFee: Int ) { getRoutes( - auth: $auth outgoing: $outgoing incoming: $incoming tokens: $tokens @@ -90,7 +92,6 @@ export const GetRoutesDocument = gql` * @example * const { data, loading, error } = useGetRoutesQuery({ * variables: { - * auth: // value for 'auth' * outgoing: // value for 'outgoing' * incoming: // value for 'incoming' * tokens: // value for 'tokens' @@ -99,23 +100,17 @@ export const GetRoutesDocument = gql` * }); */ export function useGetRoutesQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetRoutesQuery, - GetRoutesQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetRoutesDocument, baseOptions ); } export function useGetRoutesLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetRoutesQuery, - GetRoutesQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery( + return useLazyQuery( GetRoutesDocument, baseOptions ); @@ -124,7 +119,7 @@ export type GetRoutesQueryHookResult = ReturnType; export type GetRoutesLazyQueryHookResult = ReturnType< typeof useGetRoutesLazyQuery >; -export type GetRoutesQueryResult = ApolloReactCommon.QueryResult< +export type GetRoutesQueryResult = QueryResult< GetRoutesQuery, GetRoutesQueryVariables >; diff --git a/src/graphql/queries/__generated__/getServerAccounts.generated.tsx b/src/graphql/queries/__generated__/getServerAccounts.generated.tsx index a99519f1..7c9e8df7 100644 --- a/src/graphql/queries/__generated__/getServerAccounts.generated.tsx +++ b/src/graphql/queries/__generated__/getServerAccounts.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetServerAccountsQueryVariables = Types.Exact<{ @@ -47,26 +52,26 @@ export const GetServerAccountsDocument = gql` * }); */ export function useGetServerAccountsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetServerAccountsQuery, GetServerAccountsQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetServerAccountsQuery, - GetServerAccountsQueryVariables - >(GetServerAccountsDocument, baseOptions); + return useQuery( + GetServerAccountsDocument, + baseOptions + ); } export function useGetServerAccountsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetServerAccountsQuery, GetServerAccountsQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetServerAccountsQuery, - GetServerAccountsQueryVariables - >(GetServerAccountsDocument, baseOptions); + return useLazyQuery( + GetServerAccountsDocument, + baseOptions + ); } export type GetServerAccountsQueryHookResult = ReturnType< typeof useGetServerAccountsQuery @@ -74,7 +79,7 @@ export type GetServerAccountsQueryHookResult = ReturnType< export type GetServerAccountsLazyQueryHookResult = ReturnType< typeof useGetServerAccountsLazyQuery >; -export type GetServerAccountsQueryResult = ApolloReactCommon.QueryResult< +export type GetServerAccountsQueryResult = QueryResult< GetServerAccountsQuery, GetServerAccountsQueryVariables >; diff --git a/src/graphql/queries/__generated__/getSessionToken.generated.tsx b/src/graphql/queries/__generated__/getSessionToken.generated.tsx index c2b1d7a2..02a065db 100644 --- a/src/graphql/queries/__generated__/getSessionToken.generated.tsx +++ b/src/graphql/queries/__generated__/getSessionToken.generated.tsx @@ -1,6 +1,11 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetSessionTokenQueryVariables = Types.Exact<{ @@ -37,26 +42,26 @@ export const GetSessionTokenDocument = gql` * }); */ export function useGetSessionTokenQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetSessionTokenQuery, GetSessionTokenQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetSessionTokenQuery, - GetSessionTokenQueryVariables - >(GetSessionTokenDocument, baseOptions); + return useQuery( + GetSessionTokenDocument, + baseOptions + ); } export function useGetSessionTokenLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetSessionTokenQuery, GetSessionTokenQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetSessionTokenQuery, - GetSessionTokenQueryVariables - >(GetSessionTokenDocument, baseOptions); + return useLazyQuery( + GetSessionTokenDocument, + baseOptions + ); } export type GetSessionTokenQueryHookResult = ReturnType< typeof useGetSessionTokenQuery @@ -64,7 +69,7 @@ export type GetSessionTokenQueryHookResult = ReturnType< export type GetSessionTokenLazyQueryHookResult = ReturnType< typeof useGetSessionTokenLazyQuery >; -export type GetSessionTokenQueryResult = ApolloReactCommon.QueryResult< +export type GetSessionTokenQueryResult = QueryResult< GetSessionTokenQuery, GetSessionTokenQueryVariables >; diff --git a/src/graphql/queries/__generated__/getTimeHealth.generated.tsx b/src/graphql/queries/__generated__/getTimeHealth.generated.tsx index 5aebd687..22158ad1 100644 --- a/src/graphql/queries/__generated__/getTimeHealth.generated.tsx +++ b/src/graphql/queries/__generated__/getTimeHealth.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type GetTimeHealthQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetTimeHealthQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetTimeHealthQuery = { __typename?: 'Query' } & { getTimeHealth?: Types.Maybe< @@ -42,8 +45,8 @@ export type GetTimeHealthQuery = { __typename?: 'Query' } & { }; export const GetTimeHealthDocument = gql` - query GetTimeHealth($auth: authType!) { - getTimeHealth(auth: $auth) { + query GetTimeHealth { + getTimeHealth { score channels { id @@ -74,31 +77,30 @@ export const GetTimeHealthDocument = gql` * @example * const { data, loading, error } = useGetTimeHealthQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetTimeHealthQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetTimeHealthQuery, GetTimeHealthQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetTimeHealthQuery, - GetTimeHealthQueryVariables - >(GetTimeHealthDocument, baseOptions); + return useQuery( + GetTimeHealthDocument, + baseOptions + ); } export function useGetTimeHealthLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetTimeHealthQuery, GetTimeHealthQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetTimeHealthQuery, - GetTimeHealthQueryVariables - >(GetTimeHealthDocument, baseOptions); + return useLazyQuery( + GetTimeHealthDocument, + baseOptions + ); } export type GetTimeHealthQueryHookResult = ReturnType< typeof useGetTimeHealthQuery @@ -106,7 +108,7 @@ export type GetTimeHealthQueryHookResult = ReturnType< export type GetTimeHealthLazyQueryHookResult = ReturnType< typeof useGetTimeHealthLazyQuery >; -export type GetTimeHealthQueryResult = ApolloReactCommon.QueryResult< +export type GetTimeHealthQueryResult = QueryResult< GetTimeHealthQuery, GetTimeHealthQueryVariables >; diff --git a/src/graphql/queries/__generated__/getUtxos.generated.tsx b/src/graphql/queries/__generated__/getUtxos.generated.tsx index edd45fcd..2c847e21 100644 --- a/src/graphql/queries/__generated__/getUtxos.generated.tsx +++ b/src/graphql/queries/__generated__/getUtxos.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type GetUtxosQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetUtxosQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetUtxosQuery = { __typename?: 'Query' } & { getUtxos?: Types.Maybe< @@ -27,8 +30,8 @@ export type GetUtxosQuery = { __typename?: 'Query' } & { }; export const GetUtxosDocument = gql` - query GetUtxos($auth: authType!) { - getUtxos(auth: $auth) { + query GetUtxos { + getUtxos { address address_format confirmation_count @@ -52,28 +55,21 @@ export const GetUtxosDocument = gql` * @example * const { data, loading, error } = useGetUtxosQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetUtxosQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - GetUtxosQuery, - GetUtxosQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( GetUtxosDocument, baseOptions ); } export function useGetUtxosLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< - GetUtxosQuery, - GetUtxosQueryVariables - > + baseOptions?: LazyQueryHookOptions ) { - return ApolloReactHooks.useLazyQuery( + return useLazyQuery( GetUtxosDocument, baseOptions ); @@ -82,7 +78,7 @@ export type GetUtxosQueryHookResult = ReturnType; export type GetUtxosLazyQueryHookResult = ReturnType< typeof useGetUtxosLazyQuery >; -export type GetUtxosQueryResult = ApolloReactCommon.QueryResult< +export type GetUtxosQueryResult = QueryResult< GetUtxosQuery, GetUtxosQueryVariables >; diff --git a/src/graphql/queries/__generated__/getVolumeHealth.generated.tsx b/src/graphql/queries/__generated__/getVolumeHealth.generated.tsx index 6bd5755e..2e46c295 100644 --- a/src/graphql/queries/__generated__/getVolumeHealth.generated.tsx +++ b/src/graphql/queries/__generated__/getVolumeHealth.generated.tsx @@ -1,10 +1,15 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type GetVolumeHealthQueryVariables = Types.Exact<{ - auth: Types.AuthType; + [key: string]: never; }>; export type GetVolumeHealthQuery = { __typename?: 'Query' } & { @@ -34,8 +39,8 @@ export type GetVolumeHealthQuery = { __typename?: 'Query' } & { }; export const GetVolumeHealthDocument = gql` - query GetVolumeHealth($auth: authType!) { - getVolumeHealth(auth: $auth) { + query GetVolumeHealth { + getVolumeHealth { score channels { id @@ -64,31 +69,30 @@ export const GetVolumeHealthDocument = gql` * @example * const { data, loading, error } = useGetVolumeHealthQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetVolumeHealthQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetVolumeHealthQuery, GetVolumeHealthQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetVolumeHealthQuery, - GetVolumeHealthQueryVariables - >(GetVolumeHealthDocument, baseOptions); + return useQuery( + GetVolumeHealthDocument, + baseOptions + ); } export function useGetVolumeHealthLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetVolumeHealthQuery, GetVolumeHealthQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetVolumeHealthQuery, - GetVolumeHealthQueryVariables - >(GetVolumeHealthDocument, baseOptions); + return useLazyQuery( + GetVolumeHealthDocument, + baseOptions + ); } export type GetVolumeHealthQueryHookResult = ReturnType< typeof useGetVolumeHealthQuery @@ -96,7 +100,7 @@ export type GetVolumeHealthQueryHookResult = ReturnType< export type GetVolumeHealthLazyQueryHookResult = ReturnType< typeof useGetVolumeHealthLazyQuery >; -export type GetVolumeHealthQueryResult = ApolloReactCommon.QueryResult< +export type GetVolumeHealthQueryResult = QueryResult< GetVolumeHealthQuery, GetVolumeHealthQueryVariables >; diff --git a/src/graphql/queries/__generated__/getWalletInfo.generated.tsx b/src/graphql/queries/__generated__/getWalletInfo.generated.tsx index 40d63874..1a9e45a0 100644 --- a/src/graphql/queries/__generated__/getWalletInfo.generated.tsx +++ b/src/graphql/queries/__generated__/getWalletInfo.generated.tsx @@ -1,11 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; -export type GetWalletInfoQueryVariables = Types.Exact<{ - auth: Types.AuthType; -}>; +export type GetWalletInfoQueryVariables = Types.Exact<{ [key: string]: never }>; export type GetWalletInfoQuery = { __typename?: 'Query' } & { getWalletInfo?: Types.Maybe< @@ -25,8 +28,8 @@ export type GetWalletInfoQuery = { __typename?: 'Query' } & { }; export const GetWalletInfoDocument = gql` - query GetWalletInfo($auth: authType!) { - getWalletInfo(auth: $auth) { + query GetWalletInfo { + getWalletInfo { build_tags commit_hash is_autopilotrpc_enabled @@ -52,31 +55,30 @@ export const GetWalletInfoDocument = gql` * @example * const { data, loading, error } = useGetWalletInfoQuery({ * variables: { - * auth: // value for 'auth' * }, * }); */ export function useGetWalletInfoQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< GetWalletInfoQuery, GetWalletInfoQueryVariables > ) { - return ApolloReactHooks.useQuery< - GetWalletInfoQuery, - GetWalletInfoQueryVariables - >(GetWalletInfoDocument, baseOptions); + return useQuery( + GetWalletInfoDocument, + baseOptions + ); } export function useGetWalletInfoLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< GetWalletInfoQuery, GetWalletInfoQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - GetWalletInfoQuery, - GetWalletInfoQueryVariables - >(GetWalletInfoDocument, baseOptions); + return useLazyQuery( + GetWalletInfoDocument, + baseOptions + ); } export type GetWalletInfoQueryHookResult = ReturnType< typeof useGetWalletInfoQuery @@ -84,7 +86,7 @@ export type GetWalletInfoQueryHookResult = ReturnType< export type GetWalletInfoLazyQueryHookResult = ReturnType< typeof useGetWalletInfoLazyQuery >; -export type GetWalletInfoQueryResult = ApolloReactCommon.QueryResult< +export type GetWalletInfoQueryResult = QueryResult< GetWalletInfoQuery, GetWalletInfoQueryVariables >; diff --git a/src/graphql/queries/__generated__/recoverFunds.generated.tsx b/src/graphql/queries/__generated__/recoverFunds.generated.tsx index 7198f155..446d3365 100644 --- a/src/graphql/queries/__generated__/recoverFunds.generated.tsx +++ b/src/graphql/queries/__generated__/recoverFunds.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type RecoverFundsQueryVariables = Types.Exact<{ - auth: Types.AuthType; backup: Types.Scalars['String']; }>; @@ -14,8 +18,8 @@ export type RecoverFundsQuery = { __typename?: 'Query' } & Pick< >; export const RecoverFundsDocument = gql` - query RecoverFunds($auth: authType!, $backup: String!) { - recoverFunds(auth: $auth, backup: $backup) + query RecoverFunds($backup: String!) { + recoverFunds(backup: $backup) } `; @@ -31,32 +35,28 @@ export const RecoverFundsDocument = gql` * @example * const { data, loading, error } = useRecoverFundsQuery({ * variables: { - * auth: // value for 'auth' * backup: // value for 'backup' * }, * }); */ export function useRecoverFundsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - RecoverFundsQuery, - RecoverFundsQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery< - RecoverFundsQuery, - RecoverFundsQueryVariables - >(RecoverFundsDocument, baseOptions); + return useQuery( + RecoverFundsDocument, + baseOptions + ); } export function useRecoverFundsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< RecoverFundsQuery, RecoverFundsQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - RecoverFundsQuery, - RecoverFundsQueryVariables - >(RecoverFundsDocument, baseOptions); + return useLazyQuery( + RecoverFundsDocument, + baseOptions + ); } export type RecoverFundsQueryHookResult = ReturnType< typeof useRecoverFundsQuery @@ -64,7 +64,7 @@ export type RecoverFundsQueryHookResult = ReturnType< export type RecoverFundsLazyQueryHookResult = ReturnType< typeof useRecoverFundsLazyQuery >; -export type RecoverFundsQueryResult = ApolloReactCommon.QueryResult< +export type RecoverFundsQueryResult = QueryResult< RecoverFundsQuery, RecoverFundsQueryVariables >; diff --git a/src/graphql/queries/__generated__/signMessage.generated.tsx b/src/graphql/queries/__generated__/signMessage.generated.tsx index 70bab120..2430c812 100644 --- a/src/graphql/queries/__generated__/signMessage.generated.tsx +++ b/src/graphql/queries/__generated__/signMessage.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type SignMessageQueryVariables = Types.Exact<{ - auth: Types.AuthType; message: Types.Scalars['String']; }>; @@ -14,8 +18,8 @@ export type SignMessageQuery = { __typename?: 'Query' } & Pick< >; export const SignMessageDocument = gql` - query SignMessage($auth: authType!, $message: String!) { - signMessage(auth: $auth, message: $message) + query SignMessage($message: String!) { + signMessage(message: $message) } `; @@ -31,38 +35,34 @@ export const SignMessageDocument = gql` * @example * const { data, loading, error } = useSignMessageQuery({ * variables: { - * auth: // value for 'auth' * message: // value for 'message' * }, * }); */ export function useSignMessageQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< - SignMessageQuery, - SignMessageQueryVariables - > + baseOptions?: QueryHookOptions ) { - return ApolloReactHooks.useQuery( + return useQuery( SignMessageDocument, baseOptions ); } export function useSignMessageLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< SignMessageQuery, SignMessageQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - SignMessageQuery, - SignMessageQueryVariables - >(SignMessageDocument, baseOptions); + return useLazyQuery( + SignMessageDocument, + baseOptions + ); } export type SignMessageQueryHookResult = ReturnType; export type SignMessageLazyQueryHookResult = ReturnType< typeof useSignMessageLazyQuery >; -export type SignMessageQueryResult = ApolloReactCommon.QueryResult< +export type SignMessageQueryResult = QueryResult< SignMessageQuery, SignMessageQueryVariables >; diff --git a/src/graphql/queries/__generated__/verifyBackups.generated.tsx b/src/graphql/queries/__generated__/verifyBackups.generated.tsx index abf634e6..090adeee 100644 --- a/src/graphql/queries/__generated__/verifyBackups.generated.tsx +++ b/src/graphql/queries/__generated__/verifyBackups.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type VerifyBackupsQueryVariables = Types.Exact<{ - auth: Types.AuthType; backup: Types.Scalars['String']; }>; @@ -14,8 +18,8 @@ export type VerifyBackupsQuery = { __typename?: 'Query' } & Pick< >; export const VerifyBackupsDocument = gql` - query VerifyBackups($auth: authType!, $backup: String!) { - verifyBackups(auth: $auth, backup: $backup) + query VerifyBackups($backup: String!) { + verifyBackups(backup: $backup) } `; @@ -31,32 +35,31 @@ export const VerifyBackupsDocument = gql` * @example * const { data, loading, error } = useVerifyBackupsQuery({ * variables: { - * auth: // value for 'auth' * backup: // value for 'backup' * }, * }); */ export function useVerifyBackupsQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< VerifyBackupsQuery, VerifyBackupsQueryVariables > ) { - return ApolloReactHooks.useQuery< - VerifyBackupsQuery, - VerifyBackupsQueryVariables - >(VerifyBackupsDocument, baseOptions); + return useQuery( + VerifyBackupsDocument, + baseOptions + ); } export function useVerifyBackupsLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< VerifyBackupsQuery, VerifyBackupsQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - VerifyBackupsQuery, - VerifyBackupsQueryVariables - >(VerifyBackupsDocument, baseOptions); + return useLazyQuery( + VerifyBackupsDocument, + baseOptions + ); } export type VerifyBackupsQueryHookResult = ReturnType< typeof useVerifyBackupsQuery @@ -64,7 +67,7 @@ export type VerifyBackupsQueryHookResult = ReturnType< export type VerifyBackupsLazyQueryHookResult = ReturnType< typeof useVerifyBackupsLazyQuery >; -export type VerifyBackupsQueryResult = ApolloReactCommon.QueryResult< +export type VerifyBackupsQueryResult = QueryResult< VerifyBackupsQuery, VerifyBackupsQueryVariables >; diff --git a/src/graphql/queries/__generated__/verifyMessage.generated.tsx b/src/graphql/queries/__generated__/verifyMessage.generated.tsx index 034fcf32..a0111e8b 100644 --- a/src/graphql/queries/__generated__/verifyMessage.generated.tsx +++ b/src/graphql/queries/__generated__/verifyMessage.generated.tsx @@ -1,10 +1,14 @@ -import gql from 'graphql-tag'; -import * as ApolloReactCommon from '@apollo/react-common'; -import * as ApolloReactHooks from '@apollo/react-hooks'; +import { + gql, + QueryHookOptions, + useQuery, + useLazyQuery, + QueryResult, + LazyQueryHookOptions, +} from '@apollo/client'; import * as Types from '../../types'; export type VerifyMessageQueryVariables = Types.Exact<{ - auth: Types.AuthType; message: Types.Scalars['String']; signature: Types.Scalars['String']; }>; @@ -15,12 +19,8 @@ export type VerifyMessageQuery = { __typename?: 'Query' } & Pick< >; export const VerifyMessageDocument = gql` - query VerifyMessage( - $auth: authType! - $message: String! - $signature: String! - ) { - verifyMessage(auth: $auth, message: $message, signature: $signature) + query VerifyMessage($message: String!, $signature: String!) { + verifyMessage(message: $message, signature: $signature) } `; @@ -36,33 +36,32 @@ export const VerifyMessageDocument = gql` * @example * const { data, loading, error } = useVerifyMessageQuery({ * variables: { - * auth: // value for 'auth' * message: // value for 'message' * signature: // value for 'signature' * }, * }); */ export function useVerifyMessageQuery( - baseOptions?: ApolloReactHooks.QueryHookOptions< + baseOptions?: QueryHookOptions< VerifyMessageQuery, VerifyMessageQueryVariables > ) { - return ApolloReactHooks.useQuery< - VerifyMessageQuery, - VerifyMessageQueryVariables - >(VerifyMessageDocument, baseOptions); + return useQuery( + VerifyMessageDocument, + baseOptions + ); } export function useVerifyMessageLazyQuery( - baseOptions?: ApolloReactHooks.LazyQueryHookOptions< + baseOptions?: LazyQueryHookOptions< VerifyMessageQuery, VerifyMessageQueryVariables > ) { - return ApolloReactHooks.useLazyQuery< - VerifyMessageQuery, - VerifyMessageQueryVariables - >(VerifyMessageDocument, baseOptions); + return useLazyQuery( + VerifyMessageDocument, + baseOptions + ); } export type VerifyMessageQueryHookResult = ReturnType< typeof useVerifyMessageQuery @@ -70,7 +69,7 @@ export type VerifyMessageQueryHookResult = ReturnType< export type VerifyMessageLazyQueryHookResult = ReturnType< typeof useVerifyMessageLazyQuery >; -export type VerifyMessageQueryResult = ApolloReactCommon.QueryResult< +export type VerifyMessageQueryResult = QueryResult< VerifyMessageQuery, VerifyMessageQueryVariables >; diff --git a/src/graphql/queries/__tests__/__snapshots__/queryTests.ts.snap b/src/graphql/queries/__tests__/__snapshots__/queryTests.ts.snap index ab2a2a82..2772dcd0 100644 --- a/src/graphql/queries/__tests__/__snapshots__/queryTests.ts.snap +++ b/src/graphql/queries/__tests__/__snapshots__/queryTests.ts.snap @@ -11,13 +11,39 @@ Object { "destination": "string", "destination_node": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "expires_at": "2011-10-05T14:48:00.000Z", "id": "string", "probe_route": Object { - "route": null, + "route": Object { + "confidence": 1000, + "fee": 1000, + "fee_mtokens": "string", + "hops": Array [ + Object { + "channel": "string", + "channel_capacity": 1000, + "fee": 1000, + "fee_mtokens": "string", + "forward": 1000, + "forward_mtokens": "string", + "node": Object { + "node": Object { + "alias": "string", + }, + }, + "public_key": "string", + "timeout": 1000, + }, + ], + "mtokens": "string", + "safe_fee": 1000, + "safe_tokens": 1000, + "timeout": 1000, + "tokens": 1000, + }, }, "routes": Array [ Array [ @@ -153,39 +179,72 @@ Object { "getChannelFees": Array [ Object { "channelInfo": Object { - "channel": null, + "channel": Object { + "node_policies": null, + "partner_node_policies": Object { + "base_fee_mtokens": "2000", + "cltv_delta": 1000, + "fee_rate": 1000, + "max_htlc_mtokens": "10000", + "min_htlc_mtokens": "10000", + }, + "transaction_id": "string", + "transaction_vout": 1000, + }, }, "id": "100x1x1", "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "color": null, + "alias": "string", + "color": "string", }, }, "partner_public_key": "string", }, Object { "channelInfo": Object { - "channel": null, + "channel": Object { + "node_policies": null, + "partner_node_policies": Object { + "base_fee_mtokens": "2000", + "cltv_delta": 1000, + "fee_rate": 1000, + "max_htlc_mtokens": "10000", + "min_htlc_mtokens": "10000", + }, + "transaction_id": "string", + "transaction_vout": 1000, + }, }, "id": "100x1x1", "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "color": null, + "alias": "string", + "color": "string", }, }, "partner_public_key": "string", }, Object { "channelInfo": Object { - "channel": null, + "channel": Object { + "node_policies": null, + "partner_node_policies": Object { + "base_fee_mtokens": "2000", + "cltv_delta": 1000, + "fee_rate": 1000, + "max_htlc_mtokens": "10000", + "min_htlc_mtokens": "10000", + }, + "transaction_id": "string", + "transaction_vout": 1000, + }, }, "id": "100x1x1", "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "color": null, + "alias": "string", + "color": "string", }, }, "partner_public_key": "string", @@ -221,15 +280,21 @@ Object { "local_balance": 1000, "local_reserve": 1000, "partner_fee_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "base_fee_mtokens": "2000", + "cltv_delta": 1000, + "fee_rate": 1000, + }, + }, }, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "string", @@ -258,15 +323,21 @@ Object { "local_balance": 1000, "local_reserve": 1000, "partner_fee_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "base_fee_mtokens": "2000", + "cltv_delta": 1000, + "fee_rate": 1000, + }, + }, }, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "string", @@ -295,15 +366,21 @@ Object { "local_balance": 1000, "local_reserve": 1000, "partner_fee_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "base_fee_mtokens": "2000", + "cltv_delta": 1000, + "fee_rate": 1000, + }, + }, }, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "string", @@ -347,11 +424,11 @@ Object { "is_remote_force_close": false, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "abcdef", @@ -372,11 +449,11 @@ Object { "is_remote_force_close": false, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "abcdef", @@ -397,11 +474,11 @@ Object { "is_remote_force_close": false, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "abcdef", @@ -459,7 +536,7 @@ Object { }, "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "partnerSide": Object { @@ -485,7 +562,7 @@ Object { }, "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "partnerSide": Object { @@ -511,7 +588,7 @@ Object { }, "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "partnerSide": Object { @@ -549,12 +626,30 @@ Object { "fee_mtokens": "string", "incoming_channel": "1", "incoming_channel_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "node": Object { + "node": Object { + "alias": "string", + "color": "string", + }, + }, + }, + }, }, "mtokens": "string", "outgoing_channel": "2", "outgoing_channel_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "node": Object { + "node": Object { + "alias": "string", + "color": "string", + }, + }, + }, + }, }, "tokens": 1000, }, @@ -564,12 +659,30 @@ Object { "fee_mtokens": "string", "incoming_channel": "1", "incoming_channel_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "node": Object { + "node": Object { + "alias": "string", + "color": "string", + }, + }, + }, + }, }, "mtokens": "string", "outgoing_channel": "2", "outgoing_channel_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "node": Object { + "node": Object { + "alias": "string", + "color": "string", + }, + }, + }, + }, }, "tokens": 1000, }, @@ -579,12 +692,30 @@ Object { "fee_mtokens": "string", "incoming_channel": "12", "incoming_channel_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "node": Object { + "node": Object { + "alias": "string", + "color": "string", + }, + }, + }, + }, }, "mtokens": "string", "outgoing_channel": "22", "outgoing_channel_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "node": Object { + "node": Object { + "alias": "string", + "color": "string", + }, + }, + }, + }, }, "tokens": 1000, }, @@ -594,12 +725,30 @@ Object { "fee_mtokens": "string", "incoming_channel": "1", "incoming_channel_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "node": Object { + "node": Object { + "alias": "string", + "color": "string", + }, + }, + }, + }, }, "mtokens": "string", "outgoing_channel": "2", "outgoing_channel_info": Object { - "channel": null, + "channel": Object { + "partner_node_policies": Object { + "node": Object { + "node": Object { + "alias": "string", + "color": "string", + }, + }, + }, + }, }, "tokens": 1000, }, @@ -685,11 +834,11 @@ Object { "data": Object { "getNode": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, }, @@ -708,11 +857,11 @@ Object { "data": Object { "getNode": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, }, @@ -771,11 +920,11 @@ Object { "is_sync_peer": true, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "ping_time": 1000, @@ -791,11 +940,11 @@ Object { "is_sync_peer": true, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "ping_time": 1000, @@ -829,11 +978,11 @@ Object { "local_reserve": 1000, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "string", @@ -854,11 +1003,11 @@ Object { "local_reserve": 1000, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "string", @@ -879,11 +1028,11 @@ Object { "local_reserve": 1000, "partner_node_info": Object { "node": Object { - "alias": "Node not found", - "capacity": null, - "channel_count": null, - "color": null, - "updated_at": null, + "alias": "string", + "capacity": "1000", + "channel_count": 1000, + "color": "string", + "updated_at": "2011-10-05T14:48:00.000Z", }, }, "partner_public_key": "string", @@ -953,16 +1102,10 @@ Object { "getServerAccounts": Array [ Object { "id": "accountID", - "loggedIn": true, + "loggedIn": false, "name": "account", "type": "server", }, - Object { - "id": "sso", - "loggedIn": true, - "name": "SSO Account", - "type": "sso", - }, ], }, "errors": undefined, @@ -987,7 +1130,7 @@ Object { "monitoredUptime": 1, "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "score": 50, @@ -1000,7 +1143,7 @@ Object { "monitoredUptime": 1, "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "score": 50, @@ -1013,7 +1156,7 @@ Object { "monitoredUptime": 1, "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "score": 50, @@ -1077,7 +1220,7 @@ Object { "id": "100x1x1", "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "score": 0, @@ -1088,7 +1231,7 @@ Object { "id": "100x1x1", "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "score": 0, @@ -1099,7 +1242,7 @@ Object { "id": "100x1x1", "partner": Object { "node": Object { - "alias": "Node not found", + "alias": "string", }, }, "score": 0, diff --git a/src/graphql/queries/__tests__/queryTests.ts b/src/graphql/queries/__tests__/queryTests.ts index bf5710cd..840e60c9 100644 --- a/src/graphql/queries/__tests__/queryTests.ts +++ b/src/graphql/queries/__tests__/queryTests.ts @@ -1,4 +1,3 @@ -import { AuthMock } from 'server/tests/testMocks'; import testServer from 'server/tests/testServer'; import { DECODE_REQUEST } from '../decodeRequest'; import { GET_BACKUPS } from '../getBackups'; @@ -35,83 +34,65 @@ import { VERIFY_MESSAGE } from '../verifyMessage'; jest.mock('ln-service'); jest.mock('balanceofsatoshis/swaps'); -type CaseType = [string, { query: any; variables: {} }]; +type CaseType = [string, { query: any; variables?: {} }]; const cases: CaseType[] = [ - [ - 'DECODE_REQUEST', - { query: DECODE_REQUEST, variables: { ...AuthMock, request: '' } }, - ], - ['GET_BACKUPS', { query: GET_BACKUPS, variables: AuthMock }], - [ - 'GET_CHAIN_TRANSACTIONS', - { query: GET_CHAIN_TRANSACTIONS, variables: AuthMock }, - ], - ['GET_CHANNEL_FEES', { query: CHANNEL_FEES, variables: AuthMock }], - ['GET_LIQUID_REPORT', { query: GET_LIQUID_REPORT, variables: AuthMock }], - ['GET_CHANNELS', { query: GET_CHANNELS, variables: AuthMock }], - ['GET_CLOSED_CHANNELS', { query: GET_CLOSED_CHANNELS, variables: AuthMock }], - ['GET_FEE_HEALTH', { query: GET_FEE_HEALTH, variables: AuthMock }], + ['DECODE_REQUEST', { query: DECODE_REQUEST, variables: { request: '' } }], + ['GET_BACKUPS', { query: GET_BACKUPS }], + ['GET_CHAIN_TRANSACTIONS', { query: GET_CHAIN_TRANSACTIONS }], + ['GET_CHANNEL_FEES', { query: CHANNEL_FEES }], + ['GET_LIQUID_REPORT', { query: GET_LIQUID_REPORT }], + ['GET_CHANNELS', { query: GET_CHANNELS }], + ['GET_CLOSED_CHANNELS', { query: GET_CLOSED_CHANNELS }], + ['GET_FEE_HEALTH', { query: GET_FEE_HEALTH }], // [ // 'GET_FORWARD_CHANNELS_REPORT', - // { query: GET_FORWARD_CHANNELS_REPORT, variables: AuthMock }, + // { query: GET_FORWARD_CHANNELS_REPORT }, // ], - // ['GET_FORWARD_REPORT', { query: GET_FORWARD_REPORT, variables: AuthMock }], - ['GET_FORWARDS', { query: GET_FORWARDS, variables: AuthMock }], - ['GET_MESSAGES', { query: GET_MESSAGES, variables: AuthMock }], - ['GET_NETWORK_INFO', { query: GET_NETWORK_INFO, variables: AuthMock }], - [ - 'GET_NODE', - { query: GET_NODE, variables: { ...AuthMock, publicKey: 'abc' } }, - ], + // ['GET_FORWARD_REPORT', { query: GET_FORWARD_REPORT }], + ['GET_FORWARDS', { query: GET_FORWARDS }], + ['GET_MESSAGES', { query: GET_MESSAGES }], + ['GET_NETWORK_INFO', { query: GET_NETWORK_INFO }], + ['GET_NODE', { query: GET_NODE, variables: { publicKey: 'abc' } }], [ 'GET_NODE withoutChannels', { query: GET_NODE, - variables: { ...AuthMock, publicKey: 'abc', withoutChannels: false }, + variables: { publicKey: 'abc', withoutChannels: false }, }, ], - ['GET_CAN_CONNECT', { query: GET_CAN_CONNECT, variables: AuthMock }], - ['GET_NODE_INFO', { query: GET_NODE_INFO, variables: AuthMock }], - [ - 'GET_CHANNEL_AMOUNT_INFO', - { query: GET_CHANNEL_AMOUNT_INFO, variables: AuthMock }, - ], - ['GET_CONNECT_INFO', { query: GET_CONNECT_INFO, variables: AuthMock }], - ['GET_PEERS', { query: GET_PEERS, variables: AuthMock }], - [ - 'GET_PENDING_CHANNELS', - { query: GET_PENDING_CHANNELS, variables: AuthMock }, - ], - ['GET_RESUME', { query: GET_RESUME, variables: AuthMock }], - ['GET_SERVER_ACCOUNTS', { query: GET_SERVER_ACCOUNTS, variables: AuthMock }], - ['GET_TIME_HEALTH', { query: GET_TIME_HEALTH, variables: AuthMock }], - ['GET_UTXOS', { query: GET_UTXOS, variables: AuthMock }], - ['GET_VOLUME_HEALTH', { query: GET_VOLUME_HEALTH, variables: AuthMock }], - ['GET_WALLET_INFO', { query: GET_WALLET_INFO, variables: AuthMock }], + ['GET_CAN_CONNECT', { query: GET_CAN_CONNECT }], + ['GET_NODE_INFO', { query: GET_NODE_INFO }], + ['GET_CHANNEL_AMOUNT_INFO', { query: GET_CHANNEL_AMOUNT_INFO }], + ['GET_CONNECT_INFO', { query: GET_CONNECT_INFO }], + ['GET_PEERS', { query: GET_PEERS }], + ['GET_PENDING_CHANNELS', { query: GET_PENDING_CHANNELS }], + ['GET_RESUME', { query: GET_RESUME }], + ['GET_SERVER_ACCOUNTS', { query: GET_SERVER_ACCOUNTS }], + ['GET_TIME_HEALTH', { query: GET_TIME_HEALTH }], + ['GET_UTXOS', { query: GET_UTXOS }], + ['GET_VOLUME_HEALTH', { query: GET_VOLUME_HEALTH }], + ['GET_WALLET_INFO', { query: GET_WALLET_INFO }], [ 'RECOVER_FUNDS', { query: RECOVER_FUNDS, - variables: { ...AuthMock, backup: '{"backup":"backup_string"}' }, + variables: { backup: '{"backup":"backup_string"}' }, }, ], - [ - 'SIGN_MESSAGE', - { query: SIGN_MESSAGE, variables: { ...AuthMock, message: 'message' } }, - ], + ['SIGN_MESSAGE', { query: SIGN_MESSAGE, variables: { message: 'message' } }], [ 'VERIFY_BACKUPS', { query: VERIFY_BACKUPS, - variables: { ...AuthMock, backup: '{"backup":"backup_string"}' }, + variables: { backup: '{"backup":"backup_string"}' }, }, ], [ 'VERIFY_MESSAGE', { query: VERIFY_MESSAGE, - variables: { ...AuthMock, message: 'message', signature: 'signature' }, + variables: { message: 'message', signature: 'signature' }, }, ], ]; @@ -121,7 +102,7 @@ describe('Query tests', () => { const { query } = testServer(); const res = await query({ query: test.query, - variables: test.variables, + ...(test.variables && { variables: test.variables }), }); if (res.errors) { diff --git a/src/graphql/queries/adminCheck.ts b/src/graphql/queries/adminCheck.ts index 07cda584..d24209b5 100644 --- a/src/graphql/queries/adminCheck.ts +++ b/src/graphql/queries/adminCheck.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_CAN_ADMIN = gql` - query GetCanAdmin($auth: authType!) { - adminCheck(auth: $auth) + query GetCanAdmin { + adminCheck } `; diff --git a/src/graphql/queries/decodeRequest.ts b/src/graphql/queries/decodeRequest.ts index 7a1c6e89..4b0cf9bd 100644 --- a/src/graphql/queries/decodeRequest.ts +++ b/src/graphql/queries/decodeRequest.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const DECODE_REQUEST = gql` - query DecodeRequest($auth: authType!, $request: String!) { - decodeRequest(auth: $auth, request: $request) { + query DecodeRequest($request: String!) { + decodeRequest(request: $request) { chain_address cltv_delta description diff --git a/src/graphql/queries/getAccount.ts b/src/graphql/queries/getAccount.ts new file mode 100644 index 00000000..87cd737d --- /dev/null +++ b/src/graphql/queries/getAccount.ts @@ -0,0 +1,12 @@ +import { gql } from '@apollo/client'; + +export const GET_ACCOUNT = gql` + query GetAccount { + getAccount { + name + id + loggedIn + type + } + } +`; diff --git a/src/graphql/queries/getAccountingReport.ts b/src/graphql/queries/getAccountingReport.ts index 313ebef4..aa0c02ea 100644 --- a/src/graphql/queries/getAccountingReport.ts +++ b/src/graphql/queries/getAccountingReport.ts @@ -1,8 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_ACCOUNTING_REPORT = gql` query GetAccountingReport( - $auth: authType! $category: String $currency: String $fiat: String @@ -10,7 +9,6 @@ export const GET_ACCOUNTING_REPORT = gql` $year: String ) { getAccountingReport( - auth: $auth category: $category currency: $currency fiat: $fiat diff --git a/src/graphql/queries/getAuthToken.ts b/src/graphql/queries/getAuthToken.ts index f3cb0929..9a907869 100644 --- a/src/graphql/queries/getAuthToken.ts +++ b/src/graphql/queries/getAuthToken.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_AUTH_TOKEN = gql` query GetAuthToken($cookie: String) { diff --git a/src/graphql/queries/getBackups.ts b/src/graphql/queries/getBackups.ts index 824192f7..1b106c4b 100644 --- a/src/graphql/queries/getBackups.ts +++ b/src/graphql/queries/getBackups.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_BACKUPS = gql` - query GetBackups($auth: authType!) { - getBackups(auth: $auth) + query GetBackups { + getBackups } `; diff --git a/src/graphql/queries/getBaseNodes.ts b/src/graphql/queries/getBaseNodes.ts index 276ae89a..6199d3ef 100644 --- a/src/graphql/queries/getBaseNodes.ts +++ b/src/graphql/queries/getBaseNodes.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_BASE_NODES = gql` query GetBaseNodes { diff --git a/src/graphql/queries/getBitcoinFees.ts b/src/graphql/queries/getBitcoinFees.ts index 9ad108b0..858f3b9c 100644 --- a/src/graphql/queries/getBitcoinFees.ts +++ b/src/graphql/queries/getBitcoinFees.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_BITCOIN_FEES = gql` query GetBitcoinFees { diff --git a/src/graphql/queries/getBitcoinPrice.ts b/src/graphql/queries/getBitcoinPrice.ts index fd0bc224..bd3dc121 100644 --- a/src/graphql/queries/getBitcoinPrice.ts +++ b/src/graphql/queries/getBitcoinPrice.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_BITCOIN_PRICE = gql` query GetBitcoinPrice { diff --git a/src/graphql/queries/getChainTransactions.ts b/src/graphql/queries/getChainTransactions.ts index 1b819d8e..a72c5d6a 100644 --- a/src/graphql/queries/getChainTransactions.ts +++ b/src/graphql/queries/getChainTransactions.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_CHAIN_TRANSACTIONS = gql` - query GetChainTransactions($auth: authType!) { - getChainTransactions(auth: $auth) { + query GetChainTransactions { + getChainTransactions { block_id confirmation_count confirmation_height diff --git a/src/graphql/queries/getChannelFees.ts b/src/graphql/queries/getChannelFees.ts index 9813d521..e8b16674 100644 --- a/src/graphql/queries/getChannelFees.ts +++ b/src/graphql/queries/getChannelFees.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const CHANNEL_FEES = gql` - query ChannelFees($auth: authType!) { - getChannelFees(auth: $auth) { + query ChannelFees { + getChannelFees { id partner_public_key partner_node_info { diff --git a/src/graphql/queries/getChannelReport.ts b/src/graphql/queries/getChannelReport.ts index 55152820..9bf35f34 100644 --- a/src/graphql/queries/getChannelReport.ts +++ b/src/graphql/queries/getChannelReport.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_LIQUID_REPORT = gql` - query GetLiquidReport($auth: authType!) { - getChannelReport(auth: $auth) { + query GetLiquidReport { + getChannelReport { local remote maxIn diff --git a/src/graphql/queries/getChannels.ts b/src/graphql/queries/getChannels.ts index 118b6733..5ed28d7a 100644 --- a/src/graphql/queries/getChannels.ts +++ b/src/graphql/queries/getChannels.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_CHANNELS = gql` - query GetChannels($auth: authType!, $active: Boolean) { - getChannels(auth: $auth, active: $active) { + query GetChannels($active: Boolean) { + getChannels(active: $active) { capacity commit_transaction_fee commit_transaction_weight diff --git a/src/graphql/queries/getClosedChannels.ts b/src/graphql/queries/getClosedChannels.ts index 7ba7842c..e2ce8379 100644 --- a/src/graphql/queries/getClosedChannels.ts +++ b/src/graphql/queries/getClosedChannels.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_CLOSED_CHANNELS = gql` - query GetClosedChannels($auth: authType!) { - getClosedChannels(auth: $auth) { + query GetClosedChannels { + getClosedChannels { capacity close_confirm_height close_transaction_id diff --git a/src/graphql/queries/getFeeHealth.ts b/src/graphql/queries/getFeeHealth.ts index e9fb70fa..195a5300 100644 --- a/src/graphql/queries/getFeeHealth.ts +++ b/src/graphql/queries/getFeeHealth.ts @@ -1,8 +1,8 @@ import { gql } from 'apollo-server-micro'; export const GET_FEE_HEALTH = gql` - query GetFeeHealth($auth: authType!) { - getFeeHealth(auth: $auth) { + query GetFeeHealth { + getFeeHealth { score channels { id diff --git a/src/graphql/queries/getForwardChannelsReport.ts b/src/graphql/queries/getForwardChannelsReport.ts index fb7028be..3c6a4743 100644 --- a/src/graphql/queries/getForwardChannelsReport.ts +++ b/src/graphql/queries/getForwardChannelsReport.ts @@ -1,17 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_FORWARD_CHANNELS_REPORT = gql` - query GetForwardChannelsReport( - $time: String - $order: String - $type: String - $auth: authType! - ) { - getForwardChannelsReport( - time: $time - order: $order - auth: $auth - type: $type - ) + query GetForwardChannelsReport($time: String, $order: String, $type: String) { + getForwardChannelsReport(time: $time, order: $order, type: $type) } `; diff --git a/src/graphql/queries/getForwardReport.ts b/src/graphql/queries/getForwardReport.ts index b3bf3510..670085d5 100644 --- a/src/graphql/queries/getForwardReport.ts +++ b/src/graphql/queries/getForwardReport.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_FORWARD_REPORT = gql` - query GetForwardReport($time: String, $auth: authType!) { - getForwardReport(time: $time, auth: $auth) + query GetForwardReport($time: String) { + getForwardReport(time: $time) } `; diff --git a/src/graphql/queries/getForwards.ts b/src/graphql/queries/getForwards.ts index 4049fc9e..19aed0f5 100644 --- a/src/graphql/queries/getForwards.ts +++ b/src/graphql/queries/getForwards.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_FORWARDS = gql` - query GetForwards($auth: authType!, $time: String) { - getForwards(auth: $auth, time: $time) { + query GetForwards($time: String) { + getForwards(time: $time) { forwards { created_at fee diff --git a/src/graphql/queries/getInOut.ts b/src/graphql/queries/getInOut.ts index 4d062e36..10dccb06 100644 --- a/src/graphql/queries/getInOut.ts +++ b/src/graphql/queries/getInOut.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_IN_OUT = gql` - query GetInOut($auth: authType!, $time: String) { - getInOut(auth: $auth, time: $time) { + query GetInOut($time: String) { + getInOut(time: $time) { invoices payments confirmedInvoices diff --git a/src/graphql/queries/getLatestVersion.ts b/src/graphql/queries/getLatestVersion.ts index e5fb801d..d6660f65 100644 --- a/src/graphql/queries/getLatestVersion.ts +++ b/src/graphql/queries/getLatestVersion.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_LATEST_VERSION = gql` query GetLatestVersion { diff --git a/src/graphql/queries/getLnPay.ts b/src/graphql/queries/getLnPay.ts index a3784802..4bd7e4ab 100644 --- a/src/graphql/queries/getLnPay.ts +++ b/src/graphql/queries/getLnPay.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_LN_PAY = gql` query GetLnPay($amount: Int!) { diff --git a/src/graphql/queries/getLnPayInfo.ts b/src/graphql/queries/getLnPayInfo.ts index 7ee34d5f..f8c5a085 100644 --- a/src/graphql/queries/getLnPayInfo.ts +++ b/src/graphql/queries/getLnPayInfo.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_LN_PAY_INFO = gql` query GetLnPayInfo { diff --git a/src/graphql/queries/getMessages.ts b/src/graphql/queries/getMessages.ts index 4211a1c4..ff586751 100644 --- a/src/graphql/queries/getMessages.ts +++ b/src/graphql/queries/getMessages.ts @@ -1,16 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_MESSAGES = gql` - query GetMessages( - $auth: authType! - $initialize: Boolean - $lastMessage: String - ) { - getMessages( - auth: $auth - initialize: $initialize - lastMessage: $lastMessage - ) { + query GetMessages($initialize: Boolean, $lastMessage: String) { + getMessages(initialize: $initialize, lastMessage: $lastMessage) { token messages { date diff --git a/src/graphql/queries/getNetworkInfo.ts b/src/graphql/queries/getNetworkInfo.ts index 452f1d14..ec7a392b 100644 --- a/src/graphql/queries/getNetworkInfo.ts +++ b/src/graphql/queries/getNetworkInfo.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_NETWORK_INFO = gql` - query GetNetworkInfo($auth: authType!) { - getNetworkInfo(auth: $auth) { + query GetNetworkInfo { + getNetworkInfo { averageChannelSize channelCount maxChannelSize diff --git a/src/graphql/queries/getNode.ts b/src/graphql/queries/getNode.ts index 15ca3cd4..3d8fa477 100644 --- a/src/graphql/queries/getNode.ts +++ b/src/graphql/queries/getNode.ts @@ -1,16 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_NODE = gql` - query GetNode( - $auth: authType! - $publicKey: String! - $withoutChannels: Boolean - ) { - getNode( - auth: $auth - publicKey: $publicKey - withoutChannels: $withoutChannels - ) { + query GetNode($publicKey: String!, $withoutChannels: Boolean) { + getNode(publicKey: $publicKey, withoutChannels: $withoutChannels) { node { alias capacity diff --git a/src/graphql/queries/getNodeInfo.ts b/src/graphql/queries/getNodeInfo.ts index 02823381..981fbfe0 100644 --- a/src/graphql/queries/getNodeInfo.ts +++ b/src/graphql/queries/getNodeInfo.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_CAN_CONNECT = gql` - query GetCanConnect($auth: authType!) { - getNodeInfo(auth: $auth) { + query GetCanConnect { + getNodeInfo { chains color active_channels_count @@ -17,8 +17,8 @@ export const GET_CAN_CONNECT = gql` `; export const GET_NODE_INFO = gql` - query GetNodeInfo($auth: authType!) { - getNodeInfo(auth: $auth) { + query GetNodeInfo { + getNodeInfo { chains color active_channels_count @@ -29,9 +29,9 @@ export const GET_NODE_INFO = gql` pending_channels_count version } - getChainBalance(auth: $auth) - getPendingChainBalance(auth: $auth) - getChannelBalance(auth: $auth) { + getChainBalance + getPendingChainBalance + getChannelBalance { confirmedBalance pendingBalance } @@ -39,8 +39,8 @@ export const GET_NODE_INFO = gql` `; export const GET_CHANNEL_AMOUNT_INFO = gql` - query GetChannelAmountInfo($auth: authType!) { - getNodeInfo(auth: $auth) { + query GetChannelAmountInfo { + getNodeInfo { active_channels_count closed_channels_count pending_channels_count @@ -49,8 +49,8 @@ export const GET_CHANNEL_AMOUNT_INFO = gql` `; export const GET_CONNECT_INFO = gql` - query GetCanConnectInfo($auth: authType!) { - getNodeInfo(auth: $auth) { + query GetCanConnectInfo { + getNodeInfo { public_key uris } diff --git a/src/graphql/queries/getPeers.ts b/src/graphql/queries/getPeers.ts index ccc5d2ce..71662022 100644 --- a/src/graphql/queries/getPeers.ts +++ b/src/graphql/queries/getPeers.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_PEERS = gql` - query GetPeers($auth: authType!) { - getPeers(auth: $auth) { + query GetPeers { + getPeers { bytes_received bytes_sent is_inbound diff --git a/src/graphql/queries/getPendingChannels.ts b/src/graphql/queries/getPendingChannels.ts index 0f003508..8f73b59e 100644 --- a/src/graphql/queries/getPendingChannels.ts +++ b/src/graphql/queries/getPendingChannels.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_PENDING_CHANNELS = gql` - query GetPendingChannels($auth: authType!) { - getPendingChannels(auth: $auth) { + query GetPendingChannels { + getPendingChannels { close_transaction_id is_active is_closing diff --git a/src/graphql/queries/getResume.ts b/src/graphql/queries/getResume.ts index e1bc7faa..675d341e 100644 --- a/src/graphql/queries/getResume.ts +++ b/src/graphql/queries/getResume.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_RESUME = gql` - query GetResume($auth: authType!, $token: String) { - getResume(auth: $auth, token: $token) { + query GetResume($token: String) { + getResume(token: $token) { token resume { ... on InvoiceType { diff --git a/src/graphql/queries/getRoutes.ts b/src/graphql/queries/getRoutes.ts index 71dc7155..bd539386 100644 --- a/src/graphql/queries/getRoutes.ts +++ b/src/graphql/queries/getRoutes.ts @@ -1,15 +1,13 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_ROUTES = gql` query GetRoutes( - $auth: authType! $outgoing: String! $incoming: String! $tokens: Int! $maxFee: Int ) { getRoutes( - auth: $auth outgoing: $outgoing incoming: $incoming tokens: $tokens diff --git a/src/graphql/queries/getServerAccounts.ts b/src/graphql/queries/getServerAccounts.ts index d1dced3b..94d3a367 100644 --- a/src/graphql/queries/getServerAccounts.ts +++ b/src/graphql/queries/getServerAccounts.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_SERVER_ACCOUNTS = gql` query GetServerAccounts { diff --git a/src/graphql/queries/getSessionToken.ts b/src/graphql/queries/getSessionToken.ts index 65da0235..11af6b8f 100644 --- a/src/graphql/queries/getSessionToken.ts +++ b/src/graphql/queries/getSessionToken.ts @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_SESSION_TOKEN = gql` query GetSessionToken($id: String!, $password: String!) { diff --git a/src/graphql/queries/getTimeHealth.ts b/src/graphql/queries/getTimeHealth.ts index 7eee7451..cf419643 100644 --- a/src/graphql/queries/getTimeHealth.ts +++ b/src/graphql/queries/getTimeHealth.ts @@ -1,8 +1,8 @@ import { gql } from 'apollo-server-micro'; export const GET_TIME_HEALTH = gql` - query GetTimeHealth($auth: authType!) { - getTimeHealth(auth: $auth) { + query GetTimeHealth { + getTimeHealth { score channels { id diff --git a/src/graphql/queries/getUtxos.ts b/src/graphql/queries/getUtxos.ts index e1bdf2ff..dd36c618 100644 --- a/src/graphql/queries/getUtxos.ts +++ b/src/graphql/queries/getUtxos.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_UTXOS = gql` - query GetUtxos($auth: authType!) { - getUtxos(auth: $auth) { + query GetUtxos { + getUtxos { address address_format confirmation_count diff --git a/src/graphql/queries/getVolumeHealth.ts b/src/graphql/queries/getVolumeHealth.ts index 074926d0..1c57ba02 100644 --- a/src/graphql/queries/getVolumeHealth.ts +++ b/src/graphql/queries/getVolumeHealth.ts @@ -1,8 +1,8 @@ import { gql } from 'apollo-server-micro'; export const GET_VOLUME_HEALTH = gql` - query GetVolumeHealth($auth: authType!) { - getVolumeHealth(auth: $auth) { + query GetVolumeHealth { + getVolumeHealth { score channels { id diff --git a/src/graphql/queries/getWalletInfo.ts b/src/graphql/queries/getWalletInfo.ts index 69239951..71a2c16f 100644 --- a/src/graphql/queries/getWalletInfo.ts +++ b/src/graphql/queries/getWalletInfo.ts @@ -1,8 +1,8 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const GET_WALLET_INFO = gql` - query GetWalletInfo($auth: authType!) { - getWalletInfo(auth: $auth) { + query GetWalletInfo { + getWalletInfo { build_tags commit_hash is_autopilotrpc_enabled diff --git a/src/graphql/queries/recoverFunds.ts b/src/graphql/queries/recoverFunds.ts index 68207421..37f3b794 100644 --- a/src/graphql/queries/recoverFunds.ts +++ b/src/graphql/queries/recoverFunds.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const RECOVER_FUNDS = gql` - query RecoverFunds($auth: authType!, $backup: String!) { - recoverFunds(auth: $auth, backup: $backup) + query RecoverFunds($backup: String!) { + recoverFunds(backup: $backup) } `; diff --git a/src/graphql/queries/signMessage.ts b/src/graphql/queries/signMessage.ts index f9c53b19..acf6c98a 100644 --- a/src/graphql/queries/signMessage.ts +++ b/src/graphql/queries/signMessage.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const SIGN_MESSAGE = gql` - query SignMessage($auth: authType!, $message: String!) { - signMessage(auth: $auth, message: $message) + query SignMessage($message: String!) { + signMessage(message: $message) } `; diff --git a/src/graphql/queries/verifyBackups.ts b/src/graphql/queries/verifyBackups.ts index 5dfd968f..e80fc830 100644 --- a/src/graphql/queries/verifyBackups.ts +++ b/src/graphql/queries/verifyBackups.ts @@ -1,7 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const VERIFY_BACKUPS = gql` - query VerifyBackups($auth: authType!, $backup: String!) { - verifyBackups(auth: $auth, backup: $backup) + query VerifyBackups($backup: String!) { + verifyBackups(backup: $backup) } `; diff --git a/src/graphql/queries/verifyMessage.ts b/src/graphql/queries/verifyMessage.ts index 5f4fb2d9..f647cda8 100644 --- a/src/graphql/queries/verifyMessage.ts +++ b/src/graphql/queries/verifyMessage.ts @@ -1,11 +1,7 @@ -import gql from 'graphql-tag'; +import { gql } from '@apollo/client'; export const VERIFY_MESSAGE = gql` - query VerifyMessage( - $auth: authType! - $message: String! - $signature: String! - ) { - verifyMessage(auth: $auth, message: $message, signature: $signature) + query VerifyMessage($message: String!, $signature: String!) { + verifyMessage(message: $message, signature: $signature) } `; diff --git a/src/graphql/types.ts b/src/graphql/types.ts index 9cc1e216..3166b926 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -15,14 +15,6 @@ export type Scalars = { DateTime: any; }; -export type AuthType = { - type: Scalars['String']; - id?: Maybe; - host?: Maybe; - macaroon?: Maybe; - cert?: Maybe; -}; - export type PermissionsType = { is_ok_to_adjust_peers?: Maybe; is_ok_to_create_chain_addresses?: Maybe; @@ -87,13 +79,13 @@ export type Query = { getAuthToken?: Maybe; getSessionToken?: Maybe; getServerAccounts?: Maybe>>; + getAccount?: Maybe; getLnPayInfo?: Maybe; getLnPay?: Maybe; getLatestVersion?: Maybe; }; export type QueryGetAccountingReportArgs = { - auth: AuthType; category?: Maybe; currency?: Maybe; fiat?: Maybe; @@ -101,78 +93,28 @@ export type QueryGetAccountingReportArgs = { year?: Maybe; }; -export type QueryGetVolumeHealthArgs = { - auth: AuthType; -}; - -export type QueryGetTimeHealthArgs = { - auth: AuthType; -}; - -export type QueryGetFeeHealthArgs = { - auth: AuthType; -}; - -export type QueryGetChannelBalanceArgs = { - auth: AuthType; -}; - export type QueryGetChannelsArgs = { - auth: AuthType; active?: Maybe; }; export type QueryGetClosedChannelsArgs = { - auth: AuthType; type?: Maybe; }; -export type QueryGetPendingChannelsArgs = { - auth: AuthType; -}; - -export type QueryGetChannelFeesArgs = { - auth: AuthType; -}; - -export type QueryGetChannelReportArgs = { - auth: AuthType; -}; - -export type QueryGetNetworkInfoArgs = { - auth: AuthType; -}; - -export type QueryGetNodeInfoArgs = { - auth: AuthType; -}; - -export type QueryAdminCheckArgs = { - auth: AuthType; -}; - export type QueryGetNodeArgs = { - auth: AuthType; publicKey: Scalars['String']; withoutChannels?: Maybe; }; export type QueryDecodeRequestArgs = { - auth: AuthType; request: Scalars['String']; }; -export type QueryGetWalletInfoArgs = { - auth: AuthType; -}; - export type QueryGetResumeArgs = { - auth: AuthType; token?: Maybe; }; export type QueryGetForwardsArgs = { - auth: AuthType; time?: Maybe; }; @@ -186,81 +128,48 @@ export type QueryGetBitcoinFeesArgs = { }; export type QueryGetForwardReportArgs = { - auth: AuthType; time?: Maybe; }; export type QueryGetForwardChannelsReportArgs = { - auth: AuthType; time?: Maybe; order?: Maybe; type?: Maybe; }; export type QueryGetInOutArgs = { - auth: AuthType; time?: Maybe; }; -export type QueryGetBackupsArgs = { - auth: AuthType; -}; - export type QueryVerifyBackupsArgs = { - auth: AuthType; backup: Scalars['String']; }; export type QueryRecoverFundsArgs = { - auth: AuthType; backup: Scalars['String']; }; export type QueryGetRoutesArgs = { - auth: AuthType; outgoing: Scalars['String']; incoming: Scalars['String']; tokens: Scalars['Int']; maxFee?: Maybe; }; -export type QueryGetPeersArgs = { - auth: AuthType; -}; - export type QuerySignMessageArgs = { - auth: AuthType; message: Scalars['String']; }; export type QueryVerifyMessageArgs = { - auth: AuthType; message: Scalars['String']; signature: Scalars['String']; }; -export type QueryGetChainBalanceArgs = { - auth: AuthType; -}; - -export type QueryGetPendingChainBalanceArgs = { - auth: AuthType; -}; - -export type QueryGetChainTransactionsArgs = { - auth: AuthType; -}; - -export type QueryGetUtxosArgs = { - auth: AuthType; -}; - export type QueryGetOffersArgs = { filter?: Maybe; }; export type QueryGetMessagesArgs = { - auth: AuthType; token?: Maybe; initialize?: Maybe; lastMessage?: Maybe; @@ -299,7 +208,6 @@ export type Mutation = { }; export type MutationCloseChannelArgs = { - auth: AuthType; id: Scalars['String']; forceClose?: Maybe; targetConfirmations?: Maybe; @@ -307,7 +215,6 @@ export type MutationCloseChannelArgs = { }; export type MutationOpenChannelArgs = { - auth: AuthType; amount: Scalars['Int']; partnerPublicKey: Scalars['String']; tokensPerVByte?: Maybe; @@ -315,7 +222,6 @@ export type MutationOpenChannelArgs = { }; export type MutationUpdateFeesArgs = { - auth: AuthType; transaction_id?: Maybe; transaction_vout?: Maybe; base_fee_tokens?: Maybe; @@ -326,23 +232,19 @@ export type MutationUpdateFeesArgs = { }; export type MutationKeysendArgs = { - auth: AuthType; destination: Scalars['String']; tokens: Scalars['Int']; }; export type MutationCreateInvoiceArgs = { - auth: AuthType; amount: Scalars['Int']; }; export type MutationCircularRebalanceArgs = { - auth: AuthType; route: Scalars['String']; }; export type MutationBosRebalanceArgs = { - auth: AuthType; avoid?: Maybe>>; in_through?: Maybe; is_avoiding_high_inbound?: Maybe; @@ -356,18 +258,15 @@ export type MutationBosRebalanceArgs = { }; export type MutationPayViaRouteArgs = { - auth: AuthType; route: Scalars['String']; id: Scalars['String']; }; export type MutationCreateAddressArgs = { - auth: AuthType; nested?: Maybe; }; export type MutationSendToAddressArgs = { - auth: AuthType; address: Scalars['String']; tokens?: Maybe; fee?: Maybe; @@ -376,7 +275,6 @@ export type MutationSendToAddressArgs = { }; export type MutationAddPeerArgs = { - auth: AuthType; url?: Maybe; publicKey?: Maybe; socket?: Maybe; @@ -384,12 +282,10 @@ export type MutationAddPeerArgs = { }; export type MutationRemovePeerArgs = { - auth: AuthType; publicKey: Scalars['String']; }; export type MutationSendMessageArgs = { - auth: AuthType; publicKey: Scalars['String']; message: Scalars['String']; messageType?: Maybe; @@ -402,7 +298,6 @@ export type MutationLogoutArgs = { }; export type MutationCreateMacaroonArgs = { - auth: AuthType; permissions: PermissionsType; }; diff --git a/src/hooks/UseAccount.tsx b/src/hooks/UseAccount.tsx new file mode 100644 index 00000000..01624a0b --- /dev/null +++ b/src/hooks/UseAccount.tsx @@ -0,0 +1,31 @@ +import { useState, useEffect } from 'react'; +import { ServerAccountType } from 'src/graphql/types'; +import { useGetAccountQuery } from 'src/graphql/queries/__generated__/getAccount.generated'; +import { useGetServerAccountsQuery } from 'src/graphql/queries/__generated__/getServerAccounts.generated'; + +export const useAccount = (): ServerAccountType | null => { + const [account, setAccount] = useState(null); + + const { data, loading } = useGetAccountQuery(); + + useEffect(() => { + if (!loading && data?.getAccount) { + setAccount(data.getAccount); + } + }, [data, loading]); + + return account; +}; + +export const useAccounts = (): ServerAccountType[] => { + const [accounts, setAccounts] = useState([]); + + const { data, loading } = useGetServerAccountsQuery(); + + useEffect(() => { + if (loading || !data?.getServerAccounts?.length) return; + setAccounts(data.getServerAccounts as ServerAccountType[]); + }, [data, loading]); + + return accounts || []; +}; diff --git a/src/hooks/UseMutationWithReset.tsx b/src/hooks/UseMutationWithReset.tsx index 9116df68..9220051c 100644 --- a/src/hooks/UseMutationWithReset.tsx +++ b/src/hooks/UseMutationWithReset.tsx @@ -1,8 +1,8 @@ import * as React from 'react'; export const useMutationResultWithReset = ( - data: T | undefined -): [T | undefined, () => void] => { + data: T | undefined | null +): [T | undefined | null, () => void] => { const current = React.useRef(data); const latest = React.useRef(data); const [, setState] = React.useState(0); diff --git a/src/layouts/header/Header.tsx b/src/layouts/header/Header.tsx index a97f0f47..e03ec029 100644 --- a/src/layouts/header/Header.tsx +++ b/src/layouts/header/Header.tsx @@ -16,7 +16,6 @@ import { headerColor, headerTextColor } from '../../styles/Themes'; import { SingleLine } from '../../components/generic/Styled'; import { BurgerMenu } from '../../components/burgerMenu/BurgerMenu'; import { Section } from '../../components/section/Section'; -import { useStatusState } from '../../context/StatusContext'; import { Link } from '../../components/link/Link'; import { ViewSwitch } from '../../components/viewSwitch/ViewSwitch'; import { @@ -41,7 +40,8 @@ const { hodlhodl } = publicRuntimeConfig; export const Header = () => { const { pathname } = useRouter(); const [open, setOpen] = useState(false); - const { connected } = useStatusState(); + + const isRoot = pathname === '/'; const showHomeButton = (): boolean => pathname === TRADER || pathname === CHAT || pathname === SETTINGS; @@ -95,16 +95,16 @@ export const Header = () => { textColor={headerTextColor} > - - - + + + ThunderHub - {connected && renderLoggedIn()} + {!isRoot && renderLoggedIn()} diff --git a/src/layouts/navigation/Navigation.tsx b/src/layouts/navigation/Navigation.tsx index 60d12ddf..2f71b4ac 100644 --- a/src/layouts/navigation/Navigation.tsx +++ b/src/layouts/navigation/Navigation.tsx @@ -27,7 +27,6 @@ import { } from '../../styles/Themes'; import { useConfigState } from '../../context/ConfigContext'; import { Link } from '../../components/link/Link'; -import { useStatusState } from '../../context/StatusContext'; import { SideSettings } from './sideSettings/SideSettings'; import { NodeInfo } from './nodeInfo/NodeInfo'; @@ -135,7 +134,8 @@ interface NavigationProps { export const Navigation = ({ isBurger, setOpen }: NavigationProps) => { const { pathname } = useRouter(); const { sidebar } = useConfigState(); - const { connected } = useStatusState(); + + const isRoot = pathname === '/'; const renderNavButton = ( title: string, @@ -204,7 +204,7 @@ export const Navigation = ({ isBurger, setOpen }: NavigationProps) => { - {connected && } + {!isRoot && } {renderLinks()} diff --git a/src/utils/auth.ts b/src/utils/auth.ts deleted file mode 100644 index 3696bc1e..00000000 --- a/src/utils/auth.ts +++ /dev/null @@ -1,128 +0,0 @@ -import base64url from 'base64url'; -import { v5 as uuidv5 } from 'uuid'; -import { AuthType } from 'src/graphql/types'; -import { CLIENT_ACCOUNT, defaultAuth } from '../context/AccountContext'; - -const THUNDERHUB_NAMESPACE = '00000000-0000-0000-0000-000000000000'; - -export const getUUID = (text: string): string => - uuidv5(text, THUNDERHUB_NAMESPACE); - -export const getAccountId = (host = '', viewOnly = '', admin = '', cert = '') => - getUUID(`${host}-${viewOnly}-${admin !== '' ? 1 : 0}-${cert}`); - -export const getAuthLnd = (lndconnect: string) => { - const auth = lndconnect.replace('lndconnect', 'https'); - - let url; - - try { - url = new URL(auth); - } catch (error) { - return { - cert: '', - macaroon: '', - socket: '', - }; - } - - const cert = url.searchParams.get('cert') || ''; - const macaroon = url.searchParams.get('macaroon') || ''; - const socket = url.host; - - return { - cert: base64url.toBase64(cert), - macaroon: base64url.toBase64(macaroon), - socket, - }; -}; - -export const getBase64CertfromDerFormat = (base64: string) => { - if (!base64) return null; - - const prefix = '-----BEGIN CERTIFICATE-----\n'; - const postfix = '-----END CERTIFICATE-----'; - const pem = base64.match(/.{0,64}/g) || []; - const pemString = pem.join('\n'); - const pemComplete = prefix + pemString + postfix; - const pemText = base64url.encode(pemComplete); - - return pemText; -}; - -interface ConfigLnd { - cert?: string; - admin?: string; - viewOnly?: string; - host?: string; - name?: string; -} - -const emptyObject: ConfigLnd = { - cert: undefined, - admin: undefined, - viewOnly: undefined, - host: undefined, -}; - -export const getConfigLnd = (json: string): ConfigLnd => { - const parsedJson = JSON.parse(json); - - const config = parsedJson.configurations; - - if (config && config.length >= 1) { - const cert = config[0].certificateThumbprint || ''; - const admin = config[0].adminMacaroon; - const viewOnly = config[0].readonlyMacaroon; - const host = config[0].host; - const port = config[0].port; - - return { - cert, - admin, - viewOnly, - host: `${host}:${port}`, - }; - } - - return emptyObject; -}; - -export const getQRConfig = (json: string): ConfigLnd => { - const config = JSON.parse(json); - - if (config) { - const { name = '', cert = '', admin, viewOnly, host } = config; - - return { - name, - cert, - admin, - viewOnly, - host, - }; - } - - return { ...emptyObject, name: undefined }; -}; - -export const getAuthObj = ( - host: string | undefined, - viewOnly: string | undefined, - admin: string | undefined, - cert: string | undefined -): AuthType => { - if (!host) { - return defaultAuth; - } - if (!viewOnly && !admin) { - return defaultAuth; - } - - return { - type: CLIENT_ACCOUNT, - host, - macaroon: viewOnly && viewOnly !== '' ? viewOnly : admin, - cert, - }; -}; diff --git a/src/utils/error.tsx b/src/utils/error.tsx index 32dcd9d6..a2a3b2f4 100644 --- a/src/utils/error.tsx +++ b/src/utils/error.tsx @@ -1,6 +1,6 @@ import React, { ReactNode } from 'react'; import styled from 'styled-components'; -import { ApolloError } from 'apollo-client'; +import { ApolloError } from '@apollo/client'; const getMessage = (error: string) => { switch (error) { diff --git a/src/utils/ssr.ts b/src/utils/ssr.ts new file mode 100644 index 00000000..82571382 --- /dev/null +++ b/src/utils/ssr.ts @@ -0,0 +1,64 @@ +import { NextPageContext } from 'next'; +import { initializeApollo } from 'config/client'; +import { parseCookies } from 'src/utils/cookies'; +import { DocumentNode } from 'graphql'; + +const themeProp = (context: NextPageContext): string => { + if (!context?.req) return 'dark'; + const cookies = parseCookies(context.req); + + if (cookies?.theme) { + return cookies.theme; + } + return 'dark'; +}; + +type QueryProps = { + document: DocumentNode; + variables: {}; +}; + +const isNotDocumentNode = ( + toBeDetermined: DocumentNode | QueryProps +): toBeDetermined is QueryProps => { + if ((toBeDetermined as QueryProps).document) { + return true; + } + return false; +}; + +export const getProps = async ( + context: NextPageContext, + queries?: (DocumentNode | QueryProps)[] +) => { + const theme = themeProp(context); + const apolloClient = initializeApollo(undefined, context.req, context.res); + + if (queries?.length) { + for (const query of queries) { + if (isNotDocumentNode(query)) { + await apolloClient.query({ + query: query.document, + variables: query.variables, + }); + } else { + await apolloClient.query({ + query, + }); + } + } + } else { + return { + props: { + initialConfig: theme, + }, + }; + } + + return { + props: { + initialApolloState: apolloClient.cache.extract(), + initialConfig: theme, + }, + }; +}; diff --git a/src/views/balance/AdvancedBalance.tsx b/src/views/balance/AdvancedBalance.tsx index 8ed126bc..a32a7cc5 100644 --- a/src/views/balance/AdvancedBalance.tsx +++ b/src/views/balance/AdvancedBalance.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { useBosRebalanceMutation } from 'src/graphql/mutations/__generated__/bosRebalance.generated'; import { toast } from 'react-toastify'; import { getErrorContent } from 'src/utils/error'; -import { SecureButton } from 'src/components/buttons/secureButton/SecureButton'; import { Card, Separation, SingleLine } from 'src/components/generic/Styled'; import { InputWithDeco } from 'src/components/input/InputWithDeco'; import { @@ -484,23 +483,26 @@ export const AdvancedBalance = () => { Reset )} - a.id), - node: state.node.id, - in_through: state.in_through.id, - out_through: state.out_through.id, - out_channels: state.out_channels.map(c => c.id), - }} fullWidth={true} + onClick={() => { + rebalance({ + variables: { + ...state, + avoid: state.avoid.map(a => a.id), + node: state.node.id, + in_through: state.in_through.id, + out_through: state.out_through.id, + out_channels: state.out_channels.map(c => c.id), + }, + }); + }} > Rebalance - +
)} diff --git a/src/views/balance/BalanceRoute.tsx b/src/views/balance/BalanceRoute.tsx index ca3ad3e2..b89ae4ff 100644 --- a/src/views/balance/BalanceRoute.tsx +++ b/src/views/balance/BalanceRoute.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { toast } from 'react-toastify'; import { useGetRoutesLazyQuery } from 'src/graphql/queries/__generated__/getRoutes.generated'; -import { useAccountState } from 'src/context/AccountContext'; import { useCircularRebalanceMutation } from 'src/graphql/mutations/__generated__/circularRebalance.generated'; import { ChannelType } from 'src/graphql/types'; import { @@ -13,11 +12,9 @@ import { import { getErrorContent } from '../../utils/error'; import { themeColors, chartColors } from '../../styles/Themes'; import { renderLine } from '../../components/generic/helpers'; -import { SecureButton } from '../../components/buttons/secureButton/SecureButton'; import { ColorButton } from '../../components/buttons/colorButton/ColorButton'; import { Price } from '../../components/price/Price'; import { getPercent } from '../../utils/helpers'; -import { AdminSwitch } from '../../components/adminSwitch/AdminSwitch'; import { HopCard } from './Balance.styled'; type BalancedRouteProps = { @@ -39,8 +36,6 @@ export const BalanceRoute = ({ setBlocked, callback, }: BalancedRouteProps) => { - const { auth } = useAccountState(); - const [getRoute, { loading, data, called }] = useGetRoutesLazyQuery({ fetchPolicy: 'no-cache', onError: error => { @@ -80,7 +75,6 @@ export const BalanceRoute = ({ setBlocked(); getRoute({ variables: { - auth, outgoing: outgoing.id, incoming: incoming.partner_public_key, tokens: amount, @@ -126,16 +120,20 @@ export const BalanceRoute = ({ Reset - { + payRoute({ + variables: { route: JSON.stringify(data.getRoutes) }, + }); + }} + loading={loadingP} disabled={loadingP} - variables={{ route: JSON.stringify(data.getRoutes) }} fullWidth={true} arrow={true} withMargin={'0 0 0 8px'} > Balance Channel - + ); } @@ -146,7 +144,7 @@ export const BalanceRoute = ({ <> {renderGetRoute()} {renderRoute()} - {renderButton()} + {renderButton()} ); }; diff --git a/src/views/balance/Modals/ModalChannels.tsx b/src/views/balance/Modals/ModalChannels.tsx index e9201d7d..912f6dae 100644 --- a/src/views/balance/Modals/ModalChannels.tsx +++ b/src/views/balance/Modals/ModalChannels.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { useAccountState } from 'src/context/AccountContext'; import { LoadingCard } from 'src/components/loading/LoadingCard'; import { SubCard, @@ -29,12 +28,7 @@ export const ModalChannels: React.FC = ({ dispatch, callback, }) => { - const { auth } = useAccountState(); - - const { loading, data } = useGetChannelsQuery({ - skip: !auth, - variables: { auth }, - }); + const { loading, data } = useGetChannelsQuery(); if (loading || !data || !data.getChannels) { return ; diff --git a/src/views/balance/Modals/ModalNodes.tsx b/src/views/balance/Modals/ModalNodes.tsx index 35a67989..d78d2285 100644 --- a/src/views/balance/Modals/ModalNodes.tsx +++ b/src/views/balance/Modals/ModalNodes.tsx @@ -1,6 +1,5 @@ import * as React from 'react'; import { useGetPeersQuery } from 'src/graphql/queries/__generated__/getPeers.generated'; -import { useAccountState } from 'src/context/AccountContext'; import { LoadingCard } from 'src/components/loading/LoadingCard'; import { SubCard, @@ -33,12 +32,7 @@ export const ModalNodes: React.FC = ({ openSet, }) => { const [newNode, newNodeSet] = React.useState(''); - const { auth } = useAccountState(); - - const { loading, data } = useGetPeersQuery({ - skip: !auth, - variables: { auth }, - }); + const { loading, data } = useGetPeersQuery(); const [ getNode, @@ -139,9 +133,7 @@ export const ModalNodes: React.FC = ({ - getNode({ variables: { auth, publicKey: newNode } }) - } + onClick={() => getNode({ variables: { publicKey: newNode } })} > diff --git a/src/views/balance/SimpleBalance.tsx b/src/views/balance/SimpleBalance.tsx index 07d6f993..b9dd2736 100644 --- a/src/views/balance/SimpleBalance.tsx +++ b/src/views/balance/SimpleBalance.tsx @@ -1,7 +1,6 @@ import React, { useState } from 'react'; import { toast } from 'react-toastify'; import sortBy from 'lodash.sortby'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetChannelsQuery } from 'src/graphql/queries/__generated__/getChannels.generated'; import { ChannelType } from 'src/graphql/types'; import { @@ -24,8 +23,6 @@ import { } from 'src/context/RebalanceContext'; export const SimpleBalance = () => { - const { auth } = useAccountState(); - const dispatch = useRebalanceDispatch(); const { inChannel: incoming, outChannel: outgoing } = useRebalanceState(); @@ -34,8 +31,7 @@ export const SimpleBalance = () => { const [blocked, setBlocked] = useState(false); const { loading, data } = useGetChannelsQuery({ - skip: !auth, - variables: { auth, active: true }, + variables: { active: true }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/chain/transactions/ChainTransactions.tsx b/src/views/chain/transactions/ChainTransactions.tsx index 692042d0..4c5ca245 100644 --- a/src/views/chain/transactions/ChainTransactions.tsx +++ b/src/views/chain/transactions/ChainTransactions.tsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetChainTransactionsQuery } from 'src/graphql/queries/__generated__/getChainTransactions.generated'; import { GetTransactionsType } from 'src/graphql/types'; import { @@ -14,11 +13,8 @@ import { TransactionsCard } from './TransactionsCard'; export const ChainTransactions = () => { const [indexOpen, setIndexOpen] = useState(0); - const { auth } = useAccountState(); const { loading, data } = useGetChainTransactionsQuery({ - skip: !auth, - variables: { auth }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/chain/utxos/ChainUtxos.tsx b/src/views/chain/utxos/ChainUtxos.tsx index 01466b00..8a2ff704 100644 --- a/src/views/chain/utxos/ChainUtxos.tsx +++ b/src/views/chain/utxos/ChainUtxos.tsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetUtxosQuery } from 'src/graphql/queries/__generated__/getUtxos.generated'; import { GetUtxosType } from 'src/graphql/types'; import { @@ -14,11 +13,8 @@ import { UtxoCard } from './UtxoCard'; export const ChainUtxos = () => { const [indexOpen, setIndexOpen] = useState(0); - const { auth } = useAccountState(); const { loading, data } = useGetUtxosQuery({ - skip: !auth, - variables: { auth }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/channels/channels/ChannelCard.tsx b/src/views/channels/channels/ChannelCard.tsx index 4de0432f..fe86d613 100644 --- a/src/views/channels/channels/ChannelCard.tsx +++ b/src/views/channels/channels/ChannelCard.tsx @@ -39,7 +39,6 @@ import { } from '../../../components/generic/helpers'; import Modal from '../../../components/modal/ReactModal'; import { CloseChannel } from '../../../components/modal/closeChannel/CloseChannel'; -import { AdminSwitch } from '../../../components/adminSwitch/AdminSwitch'; import { ColorButton } from '../../../components/buttons/colorButton/ColorButton'; import { getPrice } from '../../../components/price/Price'; import { usePriceState } from '../../../context/PriceContext'; @@ -235,18 +234,16 @@ export const ChannelCard: React.FC = ({ Partner Node Info {renderPartner()} - - - - setModalOpen(true)} - > - Close Channel - - - + + + setModalOpen(true)} + > + Close Channel + + ); }; diff --git a/src/views/channels/channels/Channels.tsx b/src/views/channels/channels/Channels.tsx index 4e7aff1b..c0335707 100644 --- a/src/views/channels/channels/Channels.tsx +++ b/src/views/channels/channels/Channels.tsx @@ -1,6 +1,5 @@ import React, { useState, useEffect, useRef } from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetChannelsQuery } from 'src/graphql/queries/__generated__/getChannels.generated'; import { useConfigState } from 'src/context/ConfigContext'; import { sortBy } from 'underscore'; @@ -22,8 +21,6 @@ export const Channels: React.FC = () => { const { sortDirection, channelSort } = useConfigState(); const [indexOpen, setIndexOpen] = useState(0); - const { auth } = useAccountState(); - const { inChannel, outChannel } = useRebalanceState(); const hasIn = !!inChannel; const hasOut = !!outChannel; @@ -49,8 +46,6 @@ export const Channels: React.FC = () => { }, [hasIn, hasOut, push]); const { loading, data } = useGetChannelsQuery({ - skip: !auth, - variables: { auth }, errorPolicy: 'all', onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/channels/closedChannels/ClosedChannels.tsx b/src/views/channels/closedChannels/ClosedChannels.tsx index 6e1a89fa..4cbbd027 100644 --- a/src/views/channels/closedChannels/ClosedChannels.tsx +++ b/src/views/channels/closedChannels/ClosedChannels.tsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetClosedChannelsQuery } from 'src/graphql/queries/__generated__/getClosedChannels.generated'; import { ClosedChannelType } from 'src/graphql/types'; import { Card } from '../../../components/generic/Styled'; @@ -11,11 +10,7 @@ import { ClosedCard } from './ClosedCard'; export const ClosedChannels = () => { const [indexOpen, setIndexOpen] = useState(0); - const { auth } = useAccountState(); - const { loading, data } = useGetClosedChannelsQuery({ - skip: !auth, - variables: { auth }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/channels/pendingChannels/PendingChannels.tsx b/src/views/channels/pendingChannels/PendingChannels.tsx index 0531ab8a..7f9efac4 100644 --- a/src/views/channels/pendingChannels/PendingChannels.tsx +++ b/src/views/channels/pendingChannels/PendingChannels.tsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetPendingChannelsQuery } from 'src/graphql/queries/__generated__/getPendingChannels.generated'; import { PendingChannelType } from 'src/graphql/types'; import { Card } from '../../../components/generic/Styled'; @@ -11,11 +10,7 @@ import { PendingCard } from './PendingCard'; export const PendingChannels = () => { const [indexOpen, setIndexOpen] = useState(0); - const { auth } = useAccountState(); - const { loading, data } = useGetPendingChannelsQuery({ - skip: !auth, - variables: { auth }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/chat/ChatBubble.tsx b/src/views/chat/ChatBubble.tsx index e9f8671a..43120738 100644 --- a/src/views/chat/ChatBubble.tsx +++ b/src/views/chat/ChatBubble.tsx @@ -3,16 +3,15 @@ import { ThemeSet } from 'styled-theming'; import { toast } from 'react-toastify'; import { Circle } from 'react-feather'; import ScaleLoader from 'react-spinners/ScaleLoader'; -import { useAccountState } from 'src/context/AccountContext'; import { useSendMessageMutation } from 'src/graphql/mutations/__generated__/sendMessage.generated'; import { useMutationResultWithReset } from 'src/hooks/UseMutationWithReset'; +import { useAccount } from 'src/hooks/UseAccount'; import { chatBubbleColor, chatSentBubbleColor, chartColors, } from '../../styles/Themes'; import { getErrorContent } from '../../utils/error'; -import { SecureWrapper } from '../../components/buttons/secureButton/SecureWrapper'; import { useChatState, useChatDispatch, @@ -36,7 +35,8 @@ const SendButton = ({ amount }: SendButtonProps) => { const { maxFee } = useConfigState(); const { sender } = useChatState(); const dispatch = useChatDispatch(); - const { account } = useAccountState(); + + const account = useAccount(); const [sendMessage, { loading, data: _data }] = useSendMessageMutation({ onError: error => toast.error(getErrorContent(error)), @@ -66,21 +66,21 @@ const SendButton = ({ amount }: SendButtonProps) => { }, [loading, data, amount, dispatch, sender, account, resetMutationResult]); return ( - + sendMessage({ + variables: { + message: 'payment', + messageType: 'payment', + publicKey: sender, + tokens: amount, + maxFee, + }, + }) + } > - - {loading ? : 'Pay'} - - + {loading ? : 'Pay'} + ); }; diff --git a/src/views/chat/ChatInput.tsx b/src/views/chat/ChatInput.tsx index 251b13ec..eaae6f0d 100644 --- a/src/views/chat/ChatInput.tsx +++ b/src/views/chat/ChatInput.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useSendMessageMutation } from 'src/graphql/mutations/__generated__/sendMessage.generated'; import { useMutationResultWithReset } from 'src/hooks/UseMutationWithReset'; +import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; +import { useAccount } from 'src/hooks/UseAccount'; import { Input } from '../../components/input/Input'; import { SingleLine } from '../../components/generic/Styled'; -import { SecureButton } from '../../components/buttons/secureButton/SecureButton'; import { useChatState, useChatDispatch } from '../../context/ChatContext'; import { getErrorContent } from '../../utils/error'; import { useConfigState } from '../../context/ConfigContext'; @@ -21,12 +21,13 @@ export const ChatInput = ({ withMargin?: string; }) => { const [message, setMessage] = React.useState(''); - const { account } = useAccountState(); const { maxFee } = useConfigState(); const { sender } = useChatState(); const dispatch = useChatDispatch(); + const account = useAccount(); + const [sendMessage, { loading, data: _data }] = useSendMessageMutation({ onError: error => toast.error(getErrorContent(error)), }); @@ -78,21 +79,24 @@ export const ChatInput = ({ withMargin={withMargin} onChange={e => setMessage(e.target.value)} /> - 0 && { tokens }), - maxFee, - }} withMargin={'0 0 0 8px'} + onClick={() => { + sendMessage({ + variables: { + message: formattedMessage, + messageType: contentType, + publicKey: customSender || sender, + ...(tokens > 0 && { tokens }), + maxFee, + }, + }); + }} > Send - + ); }; diff --git a/src/views/chat/ChatStart.tsx b/src/views/chat/ChatStart.tsx index ade4e920..96f41c7a 100644 --- a/src/views/chat/ChatStart.tsx +++ b/src/views/chat/ChatStart.tsx @@ -1,6 +1,5 @@ import * as React from 'react'; import { X, ChevronRight } from 'react-feather'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetPeersQuery } from 'src/graphql/queries/__generated__/getPeers.generated'; import { PeerType } from 'src/graphql/types'; import { Input } from '../../components/input/Input'; @@ -75,11 +74,8 @@ export const ChatStart = ({ noTitle }: { noTitle?: boolean }) => { const [indexOpen, setIndexOpen] = React.useState(0); const [willSend, setWillSend] = React.useState(false); const [publicKey, setPublicKey] = React.useState(''); - const { auth } = useAccountState(); - const { loading, data } = useGetPeersQuery({ - skip: !auth, - variables: { auth }, - }); + + const { loading, data } = useGetPeersQuery(); const renderPeers = () => { if (!loading && data?.getPeers) { diff --git a/src/views/chat/Contacts.tsx b/src/views/chat/Contacts.tsx index a22e017e..c93b0ff4 100644 --- a/src/views/chat/Contacts.tsx +++ b/src/views/chat/Contacts.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetNodeLazyQuery } from 'src/graphql/queries/__generated__/getNode.generated'; +import { useAccount } from 'src/hooks/UseAccount'; import { useChatDispatch, useChatState, @@ -40,9 +40,10 @@ export const ContactCard = ({ const dispatch = useChatDispatch(); const [nodeName, setNodeName] = React.useState(alias || ''); - const { auth, account } = useAccountState(); + const account = useAccount(); + const [getInfo, { data, loading }] = useGetNodeLazyQuery({ - variables: { auth, publicKey: contactSender || '' }, + variables: { publicKey: contactSender || '' }, }); React.useEffect(() => { diff --git a/src/views/fees/FeeCard.tsx b/src/views/fees/FeeCard.tsx index 8fbc382f..f6fad79c 100644 --- a/src/views/fees/FeeCard.tsx +++ b/src/views/fees/FeeCard.tsx @@ -7,6 +7,7 @@ import { ChannelFeeType } from 'src/graphql/types'; import { formatSats } from 'src/utils/helpers'; import { chartColors } from 'src/styles/Themes'; import { useStatusState } from 'src/context/StatusContext'; +import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; import { SubCard, Separation, @@ -18,8 +19,6 @@ import { import { renderLine, getWithCopy } from '../../components/generic/helpers'; import { MainInfo, NodeTitle } from '../../components/generic/CardGeneric'; import { getErrorContent } from '../../utils/error'; -import { SecureButton } from '../../components/buttons/secureButton/SecureButton'; -import { AdminSwitch } from '../../components/adminSwitch/AdminSwitch'; import { WarningText } from '../stats/styles'; import { FeeCardColumn, FeeCardNoWrap } from './styles'; @@ -135,79 +134,81 @@ export const FeeCard: React.FC = ({ {renderLine('Transaction Id:', getWithCopy(transaction_id))} {renderLine('Transaction Vout:', transaction_vout)} - + + setBaseFee(Number(value))} + /> + setFeeRate(Number(value))} + /> + setCLTV(Number(value))} + /> + {canMax && ( setBaseFee(Number(value))} + inputCallback={value => setMax(Number(value))} /> + )} + {canMin && ( setFeeRate(Number(value))} + inputCallback={value => setMin(Number(value))} /> - setCLTV(Number(value))} - /> - {canMax && ( - setMax(Number(value))} - /> - )} - {canMin && ( - setMin(Number(value))} - /> - )} - - Update Fees - - - + )} + + updateFees({ + variables: { + transaction_id, + transaction_vout, + ...(newBaseFee !== 0 && { + base_fee_tokens: newBaseFee, + }), + ...(newFeeRate !== 0 && { + fee_rate: newFeeRate, + }), + ...(newCLTV !== 0 && { cltv_delta: newCLTV }), + ...(newMax !== 0 && + canMax && { max_htlc_mtokens: (newMax * 1000).toString() }), + ...(newMin !== 0 && + canMin && { min_htlc_mtokens: (newMin * 1000).toString() }), + }, + }) + } + disabled={!withChanges} + fullWidth={true} + withMargin={'16px 0 0'} + > + Update Fees + + ); }; diff --git a/src/views/home/account/AccountInfo.tsx b/src/views/home/account/AccountInfo.tsx index 86062dd3..0281ef6a 100644 --- a/src/views/home/account/AccountInfo.tsx +++ b/src/views/home/account/AccountInfo.tsx @@ -10,8 +10,6 @@ import { DarkSubTitle, ResponsiveLine, } from '../../../components/generic/Styled'; -import { LoadingCard } from '../../../components/loading/LoadingCard'; -import { AdminSwitch } from '../../../components/adminSwitch/AdminSwitch'; import { Price } from '../../../components/price/Price'; import { mediaWidths } from '../../../styles/Themes'; import { useStatusState } from '../../../context/StatusContext'; @@ -51,22 +49,12 @@ export const AccountInfo = () => { const [state, setState] = useState('none'); const { - connected, chainBalance, chainPending, channelBalance, channelPending, } = useStatusState(); - if (!connected) { - return ( - <> - - - - ); - } - const formatCB = ; const formatPB = ; const formatCCB = ; @@ -152,12 +140,10 @@ export const AccountInfo = () => {
Lightning
{renderBalances(formatCCB, formatPCB)} - - {showLn && showChain && renderButtons('send_ln', 'receive_ln')} - {showLn && !showChain && ( - setState('none')}>Cancel - )} - + {showLn && showChain && renderButtons('send_ln', 'receive_ln')} + {showLn && !showChain && ( + setState('none')}>Cancel + )} ); @@ -169,12 +155,10 @@ export const AccountInfo = () => {
Bitcoin
{renderBalances(formatCB, formatPB)} - - {showLn && showChain && renderButtons('send_chain', 'receive_chain')} - {!showLn && showChain && ( - setState('none')}>Cancel - )} - + {showLn && showChain && renderButtons('send_chain', 'receive_chain')} + {!showLn && showChain && ( + setState('none')}>Cancel + )} ); diff --git a/src/views/home/account/createInvoice/CreateInvoice.tsx b/src/views/home/account/createInvoice/CreateInvoice.tsx index 3b37acfa..d64c5778 100644 --- a/src/views/home/account/createInvoice/CreateInvoice.tsx +++ b/src/views/home/account/createInvoice/CreateInvoice.tsx @@ -6,7 +6,6 @@ import QRCode from 'qrcode.react'; import CopyToClipboard from 'react-copy-to-clipboard'; import { useCreateInvoiceMutation } from 'src/graphql/mutations/__generated__/createInvoice.generated'; import { getErrorContent } from '../../../../utils/error'; -import { SecureButton } from '../../../../components/buttons/secureButton/SecureButton'; import { ColorButton } from '../../../../components/buttons/colorButton/ColorButton'; import { NoWrapTitle, @@ -93,9 +92,8 @@ export const CreateInvoiceCard = ({ color }: { color: string }) => { type={'number'} onChange={e => setAmount(Number(e.target.value))} /> - createInvoice({ variables: { amount } })} disabled={amount === 0} withMargin={'0 0 0 16px'} mobileMargin={'0'} @@ -104,7 +102,7 @@ export const CreateInvoiceCard = ({ color }: { color: string }) => { mobileFullWidth={true} > Create Invoice - + ); diff --git a/src/views/home/account/pay/KeysendModal.tsx b/src/views/home/account/pay/KeysendModal.tsx index 7f1136b2..ecc491e1 100644 --- a/src/views/home/account/pay/KeysendModal.tsx +++ b/src/views/home/account/pay/KeysendModal.tsx @@ -1,12 +1,11 @@ import * as React from 'react'; import styled from 'styled-components'; import { useGetNodeQuery } from 'src/graphql/queries/__generated__/getNode.generated'; -import { useAccountState } from 'src/context/AccountContext'; import { useKeysendMutation } from 'src/graphql/mutations/__generated__/keysend.generated'; import { toast } from 'react-toastify'; import { getErrorContent } from 'src/utils/error'; -import { SecureButton } from 'src/components/buttons/secureButton/SecureButton'; import { InputWithDeco } from 'src/components/input/InputWithDeco'; +import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; import { SingleLine, SubTitle, @@ -33,10 +32,9 @@ export const KeysendModal: React.FC = ({ handleReset, }) => { const [tokens, setTokens] = React.useState(0); - const { auth } = useAccountState(); const { data, loading, error } = useGetNodeQuery({ - variables: { auth, publicKey }, + variables: { publicKey }, }); const [keysend, { loading: keysendLoading }] = useKeysendMutation({ @@ -81,16 +79,17 @@ export const KeysendModal: React.FC = ({ Remember keysend is an experimental feature. Use at your own risk. - + keysend({ variables: { destination: publicKey, tokens } }) + } + loading={keysendLoading} disabled={loading || keysendLoading} withMargin={'16px 0 0'} - loading={keysendLoading} fullWidth={true} > Send - + ); }; diff --git a/src/views/home/account/pay/RequestModal.tsx b/src/views/home/account/pay/RequestModal.tsx index 6822ad1e..1701b1e8 100644 --- a/src/views/home/account/pay/RequestModal.tsx +++ b/src/views/home/account/pay/RequestModal.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import styled from 'styled-components'; import { useDecodeRequestQuery } from 'src/graphql/queries/__generated__/decodeRequest.generated'; -import { useAccountState } from 'src/context/AccountContext'; import { XCircle, ChevronDown, ChevronUp } from 'react-feather'; import { useConfigState } from 'src/context/ConfigContext'; import { usePriceState } from 'src/context/PriceContext'; @@ -9,8 +8,8 @@ import { Clickable } from 'src/views/stats/styles'; import { usePayViaRouteMutation } from 'src/graphql/mutations/__generated__/payViaRoute.generated'; import { toast } from 'react-toastify'; import { getErrorContent } from 'src/utils/error'; -import { SecureButton } from 'src/components/buttons/secureButton/SecureButton'; import { ProbedRouteHop } from 'src/graphql/types'; +import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; import { SingleLine, SubTitle, @@ -86,11 +85,9 @@ export const RequestModal: React.FC = ({ request, handleReset, }) => { - const { auth } = useAccountState(); - const { data, loading, error } = useDecodeRequestQuery({ fetchPolicy: 'network-only', - variables: { auth, request }, + variables: { request }, }); const [makePayment, { loading: payLoading }] = usePayViaRouteMutation({ @@ -178,16 +175,17 @@ export const RequestModal: React.FC = ({ format({ amount: foundRoute.safe_fee, override: 'sat' }) )} {renderRoute()} - + makePayment({ variables: { route: JSON.stringify(foundRoute), id } }) + } disabled={payLoading || loading} withMargin={'16px 0 0'} loading={payLoading} fullWidth={true} > Send - + ); }; diff --git a/src/views/home/account/receiveOnChain/ReceiveOnChain.tsx b/src/views/home/account/receiveOnChain/ReceiveOnChain.tsx index 4b9c5839..d4a3d395 100644 --- a/src/views/home/account/receiveOnChain/ReceiveOnChain.tsx +++ b/src/views/home/account/receiveOnChain/ReceiveOnChain.tsx @@ -10,7 +10,6 @@ import { ResponsiveLine, } from '../../../../components/generic/Styled'; import { getErrorContent } from '../../../../utils/error'; -import { SecureButton } from '../../../../components/buttons/secureButton/SecureButton'; import { ColorButton } from '../../../../components/buttons/colorButton/ColorButton'; import { MultiButton, @@ -115,9 +114,8 @@ export const ReceiveOnChainCard = () => { - createAddress({ variables: { nested } })} disabled={received} withMargin={'0 0 0 16px'} mobileMargin={'16px 0 0'} @@ -126,7 +124,7 @@ export const ReceiveOnChainCard = () => { mobileFullWidth={true} > Create Address - + )} diff --git a/src/views/home/account/sendOnChain/SendOnChain.tsx b/src/views/home/account/sendOnChain/SendOnChain.tsx index 3f466417..a400134f 100644 --- a/src/views/home/account/sendOnChain/SendOnChain.tsx +++ b/src/views/home/account/sendOnChain/SendOnChain.tsx @@ -9,7 +9,6 @@ import { } from '../../../../components/generic/Styled'; import { getErrorContent } from '../../../../utils/error'; import { useBitcoinState } from '../../../../context/BitcoinContext'; -import { SecureButton } from '../../../../components/buttons/secureButton/SecureButton'; import { Input } from '../../../../components/input/Input'; import { MultiButton, @@ -199,9 +198,12 @@ export const SendOnChainCard = ({ setOpen }: { setOpen: () => void }) => { 'Fee:', type === 'target' ? `${amount} Blocks` : `${amount} Sats/Byte` )} - + payAddress({ + variables: { address, ...typeAmount(), ...tokenAmount }, + }) + } disabled={!canSend} withMargin={'16px 0 0'} fullWidth={true} @@ -209,7 +211,7 @@ export const SendOnChainCard = ({ setOpen }: { setOpen: () => void }) => { loading={loading} > Send To Address - + ); diff --git a/src/views/home/connect/Connect.tsx b/src/views/home/connect/Connect.tsx index 62473b7f..e463fd73 100644 --- a/src/views/home/connect/Connect.tsx +++ b/src/views/home/connect/Connect.tsx @@ -3,7 +3,6 @@ import { toast } from 'react-toastify'; import { Radio, Copy, X } from 'react-feather'; import styled from 'styled-components'; import CopyToClipboard from 'react-copy-to-clipboard'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetCanConnectInfoQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; import { renderLine } from 'src/components/generic/helpers'; @@ -64,12 +63,9 @@ const ButtonRow = styled.div` `; export const ConnectCard = () => { - const { auth } = useAccountState(); const [open, openSet] = useState(false); const { loading, data } = useGetCanConnectInfoQuery({ - skip: !auth, - variables: { auth }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/home/networkInfo/NetworkInfo.tsx b/src/views/home/networkInfo/NetworkInfo.tsx index b89ad88a..21ce614e 100644 --- a/src/views/home/networkInfo/NetworkInfo.tsx +++ b/src/views/home/networkInfo/NetworkInfo.tsx @@ -1,7 +1,6 @@ import React from 'react'; import styled from 'styled-components'; import { Globe, Cpu } from 'react-feather'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetNetworkInfoQuery } from 'src/graphql/queries/__generated__/getNetworkInfo.generated'; import { Card, @@ -62,12 +61,7 @@ const Padding = styled.span` `; export const NetworkInfo = () => { - const { auth } = useAccountState(); - - const { loading, data, error } = useGetNetworkInfoQuery({ - skip: !auth, - variables: { auth }, - }); + const { loading, data, error } = useGetNetworkInfoQuery(); if (error) { return null; diff --git a/src/views/home/quickActions/QuickActions.tsx b/src/views/home/quickActions/QuickActions.tsx index 7b0cdb4b..0837d603 100644 --- a/src/views/home/quickActions/QuickActions.tsx +++ b/src/views/home/quickActions/QuickActions.tsx @@ -12,7 +12,6 @@ import { cardColor, cardBorderColor, } from '../../../styles/Themes'; -import { AdminSwitch } from '../../../components/adminSwitch/AdminSwitch'; import { DecodeCard } from './decode/Decode'; import { SupportCard } from './donate/DonateCard'; import { SupportBar } from './donate/DonateContent'; @@ -75,13 +74,11 @@ export const QuickActions = () => { default: return ( - - setOpenCard('support')} /> - setOpenCard('open_channel')}> - - Open - - + setOpenCard('support')} /> + setOpenCard('open_channel')}> + + Open + setOpenCard('decode')}> Decode diff --git a/src/views/home/quickActions/decode/Decoded.tsx b/src/views/home/quickActions/decode/Decoded.tsx index dfbaaf96..2a2d4d50 100644 --- a/src/views/home/quickActions/decode/Decoded.tsx +++ b/src/views/home/quickActions/decode/Decoded.tsx @@ -1,6 +1,5 @@ import * as React from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useDecodeRequestQuery } from 'src/graphql/queries/__generated__/decodeRequest.generated'; import { Separation, @@ -25,16 +24,13 @@ interface DecodedProps { } export const Decoded = ({ request, setShow }: DecodedProps) => { - const { auth } = useAccountState(); - const { currency, displayValues } = useConfigState(); const priceContext = usePriceState(); const format = getPrice(currency, displayValues, priceContext); const { data, loading } = useDecodeRequestQuery({ - skip: !auth, fetchPolicy: 'network-only', - variables: { auth, request }, + variables: { request }, onError: error => { setShow(false); toast.error(getErrorContent(error)); diff --git a/src/views/home/quickActions/openChannel/OpenChannel.tsx b/src/views/home/quickActions/openChannel/OpenChannel.tsx index 47580a19..1500bcec 100644 --- a/src/views/home/quickActions/openChannel/OpenChannel.tsx +++ b/src/views/home/quickActions/openChannel/OpenChannel.tsx @@ -3,10 +3,10 @@ import { ChevronRight } from 'react-feather'; import { toast } from 'react-toastify'; import { useOpenChannelMutation } from 'src/graphql/mutations/__generated__/openChannel.generated'; import { InputWithDeco } from 'src/components/input/InputWithDeco'; +import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; import { Separation } from '../../../../components/generic/Styled'; import { getErrorContent } from '../../../../utils/error'; import { useBitcoinState } from '../../../../context/BitcoinContext'; -import { SecureButton } from '../../../../components/buttons/secureButton/SecureButton'; import { Input } from '../../../../components/input/Input'; import { SingleButton, @@ -143,20 +143,23 @@ export const OpenChannelCard = ({ )} - + openChannel({ + variables: { + amount: size, + partnerPublicKey: publicKey || '', + tokensPerVByte: fee, + isPrivate: privateChannel, + }, + }) + } disabled={!canOpen} > Open Channel - + ); }; diff --git a/src/views/home/quickActions/openChannel/OpenRecommended.tsx b/src/views/home/quickActions/openChannel/OpenRecommended.tsx index b6fe4f77..d9366760 100644 --- a/src/views/home/quickActions/openChannel/OpenRecommended.tsx +++ b/src/views/home/quickActions/openChannel/OpenRecommended.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { BaseNodesType } from 'src/graphql/types'; import { useGetNodeQuery } from 'src/graphql/queries/__generated__/getNode.generated'; -import { useAccountState } from 'src/context/AccountContext'; import { LoadingCard } from 'src/components/loading/LoadingCard'; import { DarkSubTitle, @@ -11,9 +10,9 @@ import { import { renderLine, getNodeLink } from 'src/components/generic/helpers'; import { useGetPeersQuery } from 'src/graphql/queries/__generated__/getPeers.generated'; import { useAddPeerMutation } from 'src/graphql/mutations/__generated__/addPeer.generated'; -import { SecureButton } from 'src/components/buttons/secureButton/SecureButton'; import { toast } from 'react-toastify'; import { getErrorContent } from 'src/utils/error'; +import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; import { OpenChannelCard } from './OpenChannel'; type OpenProps = { @@ -23,17 +22,12 @@ type OpenProps = { export const OpenRecommended = ({ partner, setOpenCard }: OpenProps) => { const [alreadyConnected, setConnected] = React.useState(false); - const { auth } = useAccountState(); const { data, loading } = useGetNodeQuery({ - skip: !auth, - variables: { auth, publicKey: partner.public_key || '' }, + variables: { publicKey: partner.public_key || '' }, }); - const { data: peerData, loading: peerLoading } = useGetPeersQuery({ - skip: !auth, - variables: { auth }, - }); + const { data: peerData, loading: peerLoading } = useGetPeersQuery(); React.useEffect(() => { if (!peerLoading && peerData && peerData.getPeers) { @@ -68,16 +62,22 @@ export const OpenRecommended = ({ partner, setOpenCard }: OpenProps) => { {renderLine('Node Public Key', getNodeLink(partner.public_key))} You need to connect first to this node. - + addPeer({ + variables: { + publicKey: partner.public_key, + socket: partner.socket, + }, + }) + } loading={addLoading} disabled={addLoading} - variables={{ publicKey: partner.public_key, socket: partner.socket }} fullWidth={true} > Connect - + ); } diff --git a/src/views/home/reports/flow/index.tsx b/src/views/home/reports/flow/index.tsx index 1a67e221..4e864e3a 100644 --- a/src/views/home/reports/flow/index.tsx +++ b/src/views/home/reports/flow/index.tsx @@ -1,7 +1,6 @@ import React, { useState } from 'react'; import styled, { css } from 'styled-components'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetInOutQuery } from 'src/graphql/queries/__generated__/getInOut.generated'; import { CardWithTitle, @@ -77,10 +76,8 @@ export const FlowBox = () => { const [isTime, setIsTime] = useState('month'); const [isType, setIsType] = useState('amount'); - const { auth } = useAccountState(); const { data, loading } = useGetInOutQuery({ - skip: !auth, - variables: { time: isTime, auth }, + variables: { time: isTime }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/home/reports/forwardReport/ForwardChannelReport.tsx b/src/views/home/reports/forwardReport/ForwardChannelReport.tsx index 07a11d13..cfc54821 100644 --- a/src/views/home/reports/forwardReport/ForwardChannelReport.tsx +++ b/src/views/home/reports/forwardReport/ForwardChannelReport.tsx @@ -2,7 +2,6 @@ import React, { useState } from 'react'; import { toast } from 'react-toastify'; import { GitCommit, ArrowDown, ArrowUp } from 'react-feather'; import styled from 'styled-components'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetForwardChannelsReportQuery } from 'src/graphql/queries/__generated__/getForwardChannelsReport.generated'; import { MultiButton, @@ -67,11 +66,8 @@ export const ForwardChannelsReport = ({ isTime, isType }: Props) => { const priceContext = usePriceState(); const format = getPrice(currency, displayValues, priceContext); - const { auth } = useAccountState(); - const { data, loading } = useGetForwardChannelsReportQuery({ - skip: !auth, - variables: { time: isTime, order: isType, auth, type }, + variables: { time: isTime, order: isType, type }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/home/reports/forwardReport/ForwardReport.tsx b/src/views/home/reports/forwardReport/ForwardReport.tsx index 9663a09b..96ecda05 100644 --- a/src/views/home/reports/forwardReport/ForwardReport.tsx +++ b/src/views/home/reports/forwardReport/ForwardReport.tsx @@ -8,7 +8,6 @@ import { VictoryTooltip, } from 'victory'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetForwardReportQuery } from 'src/graphql/queries/__generated__/getForwardReport.generated'; import { renderLine } from 'src/components/generic/helpers'; import { @@ -52,11 +51,8 @@ export const ForwardReport = ({ isTime, isType }: Props) => { const priceContext = usePriceState(); const format = getPrice(currency, displayValues, priceContext); - const { auth } = useAccountState(); - const { data, loading } = useGetForwardReportQuery({ - skip: !auth, - variables: { time: isTime, auth }, + variables: { time: isTime }, onError: error => toast.error(getErrorContent(error)), }); diff --git a/src/views/home/reports/liquidReport/LiquidReport.tsx b/src/views/home/reports/liquidReport/LiquidReport.tsx index 0505bd0e..de504633 100644 --- a/src/views/home/reports/liquidReport/LiquidReport.tsx +++ b/src/views/home/reports/liquidReport/LiquidReport.tsx @@ -6,7 +6,6 @@ import { VictoryVoronoiContainer, VictoryTooltip, } from 'victory'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetLiquidReportQuery } from 'src/graphql/queries/__generated__/getChannelReport.generated'; import { CardWithTitle, @@ -24,16 +23,11 @@ import { getPrice } from '../../../../components/price/Price'; import { usePriceState } from '../../../../context/PriceContext'; export const LiquidReport = () => { - const { auth } = useAccountState(); - const { theme, currency, displayValues } = useConfigState(); const priceContext = usePriceState(); const format = getPrice(currency, displayValues, priceContext); - const { data, loading } = useGetLiquidReportQuery({ - skip: !auth, - variables: { auth }, - }); + const { data, loading } = useGetLiquidReportQuery(); if (loading) { return ; diff --git a/src/views/homepage/Accounts.tsx b/src/views/homepage/Accounts.tsx index 02dfee66..135b1a87 100644 --- a/src/views/homepage/Accounts.tsx +++ b/src/views/homepage/Accounts.tsx @@ -1,43 +1,26 @@ import * as React from 'react'; import styled from 'styled-components'; import { toast } from 'react-toastify'; -import { getAuthObj } from 'src/utils/auth'; import { Lock, Unlock } from 'react-feather'; import { chartColors } from 'src/styles/Themes'; -import { - useAccountState, - CLIENT_ACCOUNT, - useAccountDispatch, - SSO_ACCOUNT, - SERVER_ACCOUNT, - CompleteAccount, - ServerAccountType, - AccountType, -} from 'src/context/AccountContext'; import { useRouter } from 'next/router'; import { appendBasePath } from 'src/utils/basePath'; import { useStatusDispatch } from 'src/context/StatusContext'; import { useGetCanConnectLazyQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; -import getConfig from 'next/config'; import { Link } from 'src/components/link/Link'; +import { useGetServerAccountsQuery } from 'src/graphql/queries/__generated__/getServerAccounts.generated'; +import { ServerAccountType } from 'src/graphql/types'; +import { LoadingCard } from 'src/components/loading/LoadingCard'; import { Section } from '../../components/section/Section'; import { Card, SingleLine } from '../../components/generic/Styled'; import { ColorButton } from '../../components/buttons/colorButton/ColorButton'; -import { dontShowSessionLogin } from '../login/helpers'; import { ConnectTitle, LockPadding } from './HomePage.styled'; - -const { publicRuntimeConfig } = getConfig(); -const { noClient } = publicRuntimeConfig; +import { Login } from './Login'; const AccountLine = styled.div` margin: 8px 0; `; -const TypeText = styled.div` - font-size: 14px; - margin-right: 8px; -`; - const renderIntro = () => (
Hi! Welcome to ThunderHub @@ -56,10 +39,14 @@ const renderIntro = () => ( export const Accounts = () => { const { push } = useRouter(); const dispatchStatus = useStatusDispatch(); - const [newAccount, setNewAccount] = React.useState(''); + const [newAccount, setNewAccount] = React.useState( + null + ); - const { accounts, activeAccount, account } = useAccountState(); - const dispatch = useAccountDispatch(); + const { + data: accountData, + loading: loadingData, + } = useGetServerAccountsQuery(); const [getCanConnect, { data, loading }] = useGetCanConnectLazyQuery({ fetchPolicy: 'network-only', @@ -69,162 +56,93 @@ export const Accounts = () => { }); React.useEffect(() => { - if (!loading && data && data.getNodeInfo && newAccount) { - dispatch({ type: 'changeAccount', changeId: newAccount }); + if (!loading && data && data.getNodeInfo) { dispatchStatus({ type: 'connected' }); push(appendBasePath('/home')); } - }, [data, loading, newAccount, dispatch, push, dispatchStatus]); + }, [data, loading, push, dispatchStatus]); - const change = - accounts.length > 0 && account && dontShowSessionLogin(account); - - if (accounts.length <= 0) { - if (noClient && !account) { - return renderIntro(); - } - return null; + if (loadingData) { + return ( +
+ +
+ ); } - const filteredAccounts = accounts.filter(a => { - if (a.type === CLIENT_ACCOUNT) { - if (noClient) { - return false; - } - if (a.id === activeAccount && !a.viewOnly) { - return false; - } - } - if (a.type === SERVER_ACCOUNT) { - if (a.id === activeAccount && !a.loggedIn) { - return false; - } - } - return true; - }); - - if (filteredAccounts.length < 1) { - if (noClient && !account) { - return renderIntro(); - } - return null; + if (!accountData?.getServerAccounts?.length) { + return renderIntro(); } - const isType = (admin: string, viewOnly: string): string => { - if (!admin && viewOnly) { - return '(View Only)'; - } - if (admin && !viewOnly) { - return '(Admin Only)'; - } - return ''; + const getTitle = (account: ServerAccountType) => { + const { type, name, loggedIn } = account; + + const props = { + color: chartColors.green, + size: 14, + }; + return ( +
+ {type === 'sso' ? 'SSO Account' : name} + + {loggedIn ? : } + +
+ ); }; - const getTitle = (account: CompleteAccount) => { - const { type, name } = account; - if (type !== CLIENT_ACCOUNT) { - const { loggedIn } = account as ServerAccountType; - const props = { - color: chartColors.green, - size: 14, - }; - return ( -
- {type === SSO_ACCOUNT ? 'SSO Account' : name} - - {loggedIn ? : } - -
- ); - } - return name; - }; - - const getButtonTitle = (account: CompleteAccount): string => { - if (account.type === CLIENT_ACCOUNT && account.viewOnly) { - return 'Connect'; - } - if (account.type === SSO_ACCOUNT) { - return 'Connect'; - } - if (account.type === SERVER_ACCOUNT && account.loggedIn) { + const getButtonTitle = (account: ServerAccountType): string => { + if (account.loggedIn) { return 'Connect'; } return 'Login'; }; - const getArrow = (account: CompleteAccount): boolean => { - if (account.type === CLIENT_ACCOUNT && account.viewOnly) { - return false; - } - if (account.type === SSO_ACCOUNT) { - return false; - } - if (account.type === SERVER_ACCOUNT && account.loggedIn) { + const getArrow = (account: ServerAccountType): boolean => { + if (account.loggedIn) { return false; } return true; }; - const handleClick = (account: CompleteAccount) => () => { - const { id, type } = account; - if (type === CLIENT_ACCOUNT && (account as AccountType).viewOnly) { - const { viewOnly, cert, host } = account as AccountType; - setNewAccount(id); - getCanConnect({ - variables: { - auth: getAuthObj(host, viewOnly, undefined, cert), - }, - }); - } else if (type === SSO_ACCOUNT) { - setNewAccount(id); - getCanConnect({ - variables: { auth: { type: SSO_ACCOUNT, id } }, - }); - } else if ( - type === SERVER_ACCOUNT && - (account as ServerAccountType).loggedIn - ) { - setNewAccount(id); - getCanConnect({ - variables: { auth: { type: SERVER_ACCOUNT, id } }, - }); + const handleClick = (account: ServerAccountType) => () => { + if (account.type === 'sso') { + getCanConnect(); + } else if (account.type === 'server' && account.loggedIn) { + getCanConnect(); } else { - dispatch({ type: 'changeAccount', changeId: id }); + setNewAccount(account); } }; return ( -
- - {change ? 'Accounts' : 'Other Accounts'} - - - {filteredAccounts.map((account, index) => { - return ( - - - {getTitle(account)} + <> + {newAccount && } +
+ + {!newAccount ? 'Accounts' : 'Other Accounts'} + + + {accountData?.getServerAccounts?.map((account, index) => { + if (!account) return null; + return ( + - {account.type === CLIENT_ACCOUNT && ( - - {isType(account.admin, account.viewOnly)} - - )} + {getTitle(account)} {getButtonTitle(account)} - - - ); - })} - -
+
+ ); + })} +
+
+ ); }; diff --git a/src/views/login/SessionLogin.tsx b/src/views/homepage/Login.tsx similarity index 52% rename from src/views/login/SessionLogin.tsx rename to src/views/homepage/Login.tsx index bfd6ba29..546dec15 100644 --- a/src/views/login/SessionLogin.tsx +++ b/src/views/homepage/Login.tsx @@ -1,22 +1,14 @@ import React, { useState, useEffect } from 'react'; -import CryptoJS from 'crypto-js'; import { toast } from 'react-toastify'; import styled from 'styled-components'; -import { - useAccountState, - useAccountDispatch, - CLIENT_ACCOUNT, - SERVER_ACCOUNT, -} from 'src/context/AccountContext'; import { useRouter } from 'next/router'; import { appendBasePath } from 'src/utils/basePath'; import { useGetCanConnectLazyQuery } from 'src/graphql/queries/__generated__/getNodeInfo.generated'; import { useGetSessionTokenLazyQuery } from 'src/graphql/queries/__generated__/getSessionToken.generated'; -import { getAuthFromAccount } from 'src/context/helpers/context'; import { getErrorContent } from 'src/utils/error'; import { Lock } from 'react-feather'; +import { ServerAccountType } from 'src/graphql/types'; import { SingleLine, Sub4Title, Card } from '../../components/generic/Styled'; -import { getAuthObj } from '../../utils/auth'; import { ColorButton } from '../../components/buttons/colorButton/ColorButton'; import { Input } from '../../components/input/Input'; import { Section } from '../../components/section/Section'; @@ -27,7 +19,6 @@ import { chartColors, } from '../../styles/Themes'; import { useStatusDispatch } from '../../context/StatusContext'; -import { dontShowSessionLogin } from './helpers'; const StyledTitle = styled(Title)` font-size: 24px; @@ -42,10 +33,12 @@ const IconPadding = styled.span` margin-left: 4px; `; -export const SessionLogin = () => { +type LoginProps = { + account: ServerAccountType; +}; + +export const Login = ({ account }: LoginProps) => { const { push } = useRouter(); - const { account } = useAccountState(); - const dispatchAccount = useAccountDispatch(); const [pass, setPass] = useState(''); const dispatch = useStatusDispatch(); @@ -71,96 +64,27 @@ export const SessionLogin = () => { useEffect(() => { if (!sLoading && sData && sData.getSessionToken) { - account && - getCanConnect({ - variables: { - auth: getAuthFromAccount(account), - }, - }); + account && getCanConnect(); } }, [sLoading, sData, push, getCanConnect, account]); useEffect(() => { - if ( - !loading && - data && - data.getNodeInfo && - account?.type === SERVER_ACCOUNT - ) { + if (!loading && data && data.getNodeInfo) { dispatch({ type: 'connected' }); push(appendBasePath('/home')); } - if ( - !loading && - data && - data.getNodeInfo && - account?.type === CLIENT_ACCOUNT - ) { - const bytes = CryptoJS.AES.decrypt(account.admin, pass); - const decrypted = bytes.toString(CryptoJS.enc.Utf8); + }, [data, loading, dispatch, pass, account, push]); - dispatchAccount({ type: 'addSession', session: decrypted }); - dispatch({ type: 'connected' }); - push(appendBasePath('/home')); - } - }, [data, loading, dispatch, pass, account, dispatchAccount, push]); - - if (account && dontShowSessionLogin(account)) { - return null; - } - - const handleClick = () => { - if (account?.type === CLIENT_ACCOUNT) { - try { - const bytes = CryptoJS.AES.decrypt(account.admin, pass); - const decrypted = bytes.toString(CryptoJS.enc.Utf8); - - const auth = getAuthObj( - account.host, - decrypted, - undefined, - account.cert - ); - - auth && - getCanConnect({ - variables: { - auth, - }, - }); - } catch (error) { - toast.error('Wrong Password'); - } - } else { - getSessionToken({ variables: { id: account?.id || '', password: pass } }); - } - }; - - const getTitle = () => { - if (!account) { - return null; - } - if (account.type === CLIENT_ACCOUNT) { - if (!account.viewOnly) { - return `Login to ${account.name} (admin-only):`; - } - } - if (account.type === SERVER_ACCOUNT) { - return ( - <> - {`Login to ${account.name}`} - - - - - ); - } - return `Login to ${account.name}`; - }; + if (!account) return null; return (
- {getTitle()} + + {`Login to ${account.name}`} + + + + Password: @@ -172,7 +96,11 @@ export const SessionLogin = () => { + getSessionToken({ + variables: { id: account.id, password: pass }, + }) + } withMargin={'16px 0 0'} fullWidth={true} loading={loading || sLoading} diff --git a/src/views/homepage/LoginBox.tsx b/src/views/homepage/LoginBox.tsx deleted file mode 100644 index e0f68139..00000000 --- a/src/views/homepage/LoginBox.tsx +++ /dev/null @@ -1,177 +0,0 @@ -import React, { useState } from 'react'; -import styled from 'styled-components'; -import { useAccountState } from 'src/context/AccountContext'; -import { ChevronDown, ChevronUp } from 'react-feather'; -import { - Card, - Separation, - SubTitle, - SingleLine, -} from '../../components/generic/Styled'; -import { Section } from '../../components/section/Section'; -import { - MultiButton, - SingleButton, -} from '../../components/buttons/multiButton/MultiButton'; -import { Link } from '../../components/link/Link'; -import { Auth } from '../../components/auth'; -import { mediaWidths, unSelectedNavButton } from '../../styles/Themes'; -import { ConnectTitle } from './HomePage.styled'; - -const Text = styled.p` - width: 100%; - text-align: center; -`; - -const HelpBox = styled.div` - font-size: 14px; - color: ${unSelectedNavButton}; - cursor: pointer; -`; - -const Help = styled.div` - width: 100%; - text-align: right; - margin-bottom: -24px; - - :hover { - font-weight: bold; - } - - @media (${mediaWidths.mobile}) { - text-align: center; - margin-bottom: 0; - } -`; - -export const LoginBox = () => { - const [isOpen, isOpenSet] = useState(false); - const [isType, setIsType] = useState('login'); - const [status, setStatus] = useState('none'); - const [help, setHelp] = useState(false); - const { accounts } = useAccountState(); - - const change = accounts.length <= 0; - - const renderButtons = () => ( - <> - - { - setHelp(false); - setIsType('login'); - }} - > - Details - - { - setHelp(false); - setIsType('connect'); - }} - > - LndConnect - - { - setHelp(false); - setIsType('btcpay'); - }} - > - BTCPayServer - - - - ); - - const renderText = () => { - switch (isType) { - case 'btcpay': - return ( - <> - - - {`To connect with your BTCPayServer instance you need the connection JSON that they provide.`} - - To access this JSON in your BPS instance, go to: - - {`Server Settings > Services > gRPC server > Show QR Code > QR Code Information > Open Config file`} - - {`Then copy the complete JSON and paste it below.`} - - - ); - case 'connect': - return ( - <> - - - { - 'To connect via LNDConnect paste the LNDConnectUrl down below. Find the url format specification ' - } - - here. - - - - - ); - default: - return null; - } - }; - - const renderHelp = () => { - switch (isType) { - case 'btcpay': - case 'connect': - return Need Help?; - default: - return null; - } - }; - - const renderContent = () => ( - <> - {status === 'none' && ( - <> - {renderButtons()} - setHelp(prev => !prev)}> - {!help && renderHelp()} - {help && renderText()} - - - )} - setStatus('none')} - /> - - ); - - return ( -
- {change && ( - Connect to your Node - )} - - {!change && ( - isOpenSet(o => !o)}> - Add another Node - {isOpen ? : } - - )} - {isOpen || change ? renderContent() : null} - -
- ); -}; diff --git a/src/views/login/helpers.tsx b/src/views/login/helpers.tsx deleted file mode 100644 index 4dc923ea..00000000 --- a/src/views/login/helpers.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { - SSO_ACCOUNT, - CLIENT_ACCOUNT, - CompleteAccount, -} from 'src/context/AccountContext'; - -export const dontShowSessionLogin = (account: CompleteAccount): boolean => { - switch (true) { - case account.type === SSO_ACCOUNT: - case account.type !== CLIENT_ACCOUNT && account.loggedIn: - case account.type === CLIENT_ACCOUNT && !account.admin: - case account.type === CLIENT_ACCOUNT && - !!account.admin && - !!account.viewOnly: - return true; - default: - return false; - } -}; diff --git a/src/views/peers/AddPeer.tsx b/src/views/peers/AddPeer.tsx index 6b88fc69..bdc7033f 100644 --- a/src/views/peers/AddPeer.tsx +++ b/src/views/peers/AddPeer.tsx @@ -18,7 +18,6 @@ import { SingleButton, } from '../../components/buttons/multiButton/MultiButton'; import { getErrorContent } from '../../utils/error'; -import { SecureButton } from '../../components/buttons/secureButton/SecureButton'; export const AddPeer = () => { const [isAdding, setIsAdding] = useState(false); @@ -105,9 +104,12 @@ export const AddPeer = () => { {renderButton(() => setTemp(false), 'No', !temp)} - + addPeer({ + variables: { url, publicKey: key, socket, isTemporary: temp }, + }) + } disabled={url === '' && (socket === '' || key === '')} withMargin={'16px 0 0'} loading={loading} @@ -115,7 +117,7 @@ export const AddPeer = () => { fullWidth={true} > Add - +
); diff --git a/src/views/peers/PeersCard.tsx b/src/views/peers/PeersCard.tsx index b5cc2a6f..97cfec4a 100644 --- a/src/views/peers/PeersCard.tsx +++ b/src/views/peers/PeersCard.tsx @@ -28,7 +28,6 @@ import { getPercent } from '../../utils/helpers'; import { useConfigState } from '../../context/ConfigContext'; import { usePriceState } from '../../context/PriceContext'; import { getPrice } from '../../components/price/Price'; -import { AdminSwitch } from '../../components/adminSwitch/AdminSwitch'; import { ColorButton } from '../../components/buttons/colorButton/ColorButton'; import Modal from '../../components/modal/ReactModal'; import { RemovePeerModal } from '../../components/modal/removePeer/RemovePeer'; @@ -112,18 +111,16 @@ export const PeersCard = ({ 'Last Update:', `${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})` )} - - - - setModalOpen(true)} - > - Remove Peer - - - + + + setModalOpen(true)} + > + Remove Peer + + ); }; diff --git a/src/views/settings/Account.tsx b/src/views/settings/Account.tsx index 77becbcc..270b7e95 100644 --- a/src/views/settings/Account.tsx +++ b/src/views/settings/Account.tsx @@ -1,21 +1,14 @@ -import React, { useState, useEffect } from 'react'; -import { X, LogOut } from 'react-feather'; +import React, { useEffect } from 'react'; +import { LogOut } from 'react-feather'; import { useRouter } from 'next/router'; -import { - useAccountState, - useAccountDispatch, - SSO_ACCOUNT, -} from 'src/context/AccountContext'; import { chartColors } from 'src/styles/Themes'; import { useLogoutMutation } from 'src/graphql/mutations/__generated__/logout.generated'; -import getConfig from 'next/config'; +import { useAccounts, useAccount } from 'src/hooks/UseAccount'; import { CardWithTitle, SubTitle, Card, - SingleLine, Sub4Title, - Separation, } from '../../components/generic/Styled'; import { SettingsLine } from '../../../pages/settings'; import { ColorButton } from '../../components/buttons/colorButton/ColorButton'; @@ -24,69 +17,34 @@ import { SingleButton, } from '../../components/buttons/multiButton/MultiButton'; import { useStatusDispatch } from '../../context/StatusContext'; -import { Auth } from '../../components/auth'; import { appendBasePath } from '../../utils/basePath'; import { useChatDispatch } from '../../context/ChatContext'; -const { publicRuntimeConfig } = getConfig(); -const { noClient } = publicRuntimeConfig; - export const AccountSettings = () => { - const [status, setStatus] = useState('none'); - const { push } = useRouter(); - const { account, accounts } = useAccountState(); const dispatch = useStatusDispatch(); const dispatchChat = useChatDispatch(); - const dispatchAccount = useAccountDispatch(); - - const [isType, setIsType] = useState('login'); - const [willAdd, setWillAdd] = useState(false); const [logout, { data, loading }] = useLogoutMutation({ refetchQueries: ['GetServerAccounts'], }); + const accounts = useAccounts(); + const account = useAccount(); + useEffect(() => { if (data && data.logout) { dispatch({ type: 'disconnected' }); dispatchChat({ type: 'disconnected' }); - dispatchAccount({ type: 'logout' }); push(appendBasePath('/')); } - }, [data, dispatch, dispatchChat, dispatchAccount, push]); + }, [data, dispatch, dispatchChat, push]); if (!account) { return null; } - const renderButtons = () => ( - - Connection Type: - - setIsType('login')} - > - Connection Details - - setIsType('connect')} - > - LndConnect Url - - setIsType('btcpay')} - > - BTCPayServer Info - - - - ); - const renderChangeAccount = () => { if (accounts.length <= 1) { return null; @@ -96,81 +54,33 @@ export const AccountSettings = () => { Change Account - {accounts.map( - ({ name: accountName, id: accountId, type: accountType }) => { - return ( - { - if (accountId !== account.id) { - switch (accountType) { - case SSO_ACCOUNT: - dispatchAccount({ - type: 'changeAccount', - changeId: accountId, - }); - break; - default: - dispatch({ type: 'disconnected' }); - dispatchChat({ type: 'disconnected' }); - dispatchAccount({ - type: 'changeAccount', - changeId: accountId, - }); - push(appendBasePath('/')); - break; - } - } - }} - > - {accountName} - - ); - } - )} + {accounts.map(({ name: accountName, id: accountId }) => { + return ( + { + if (accountId !== account.id) { + dispatch({ type: 'disconnected' }); + dispatchChat({ type: 'disconnected' }); + push(appendBasePath('/')); + } + }} + > + {accountName} + + ); + })} ); }; - const renderAddClientAccount = () => ( - <> - - Add Browser Account - { - if (willAdd) { - setIsType('login'); - } - setWillAdd(prev => !prev); - }} - > - {willAdd ? : 'Add New Account'} - - - {willAdd && ( - <> - - {status === 'none' && renderButtons()} - setStatus('none')} - /> - - - )} - - ); - return ( Account {renderChangeAccount()} - {!noClient && renderAddClientAccount()} Logout { - const { account } = useAccountState(); - - if (account?.type !== CLIENT_ACCOUNT) { - return null; - } - - const { name, host, viewOnly, admin, cert } = account; - - const renderField = (title: string, field: string | null, rows?: number) => { - if (!field) return null; - - return ( - <> - {title} - - - ); - }; - - if (admin === '' && viewOnly === '') { - return null; - } - - return ( - - Current Account: - - {renderField('Name:', name, 2)} - {renderField('Host:', host, 2)} - {renderField('AES-256 Encrypted Admin Macaroon:', admin)} - {renderField('Read-only Macaroon:', viewOnly)} - {renderField('Certificate:', cert)} - - - ); -}; diff --git a/src/views/settings/Danger.tsx b/src/views/settings/Danger.tsx index 8b57c289..1b6be5ac 100644 --- a/src/views/settings/Danger.tsx +++ b/src/views/settings/Danger.tsx @@ -2,11 +2,7 @@ import React from 'react'; import styled from 'styled-components'; import { AlertCircle } from 'react-feather'; import { useRouter } from 'next/router'; -import { - useAccountState, - useAccountDispatch, - CLIENT_ACCOUNT, -} from 'src/context/AccountContext'; +import { useLogoutMutation } from 'src/graphql/mutations/__generated__/logout.generated'; import { Card, CardWithTitle, @@ -16,10 +12,6 @@ import { } from '../../components/generic/Styled'; import { fontColors } from '../../styles/Themes'; import { ColorButton } from '../../components/buttons/colorButton/ColorButton'; -import { - MultiButton, - SingleButton, -} from '../../components/buttons/multiButton/MultiButton'; import { useStatusDispatch } from '../../context/StatusContext'; import { appendBasePath } from '../../utils/basePath'; import { useChatDispatch } from '../../context/ChatContext'; @@ -60,58 +52,23 @@ export const FixedWidth = styled.div` `; export const DangerView = () => { - const { accounts } = useAccountState(); - - const clientAccounts = accounts.filter(a => a.type === CLIENT_ACCOUNT); - const dispatch = useStatusDispatch(); const chatDispatch = useChatDispatch(); - const dispatchAccount = useAccountDispatch(); const { push } = useRouter(); - if (clientAccounts.length <= 0) { - return null; - } + const [logout] = useLogoutMutation({ + onCompleted: () => push(appendBasePath('/')), + }); const handleDeleteAll = () => { dispatch({ type: 'disconnected' }); chatDispatch({ type: 'disconnected' }); - dispatchAccount({ type: 'deleteAll' }); - push(appendBasePath('/')); - }; - const renderButton = () => { - if (clientAccounts.length > 1) { - return ( - - {clientAccounts.map(({ name: accountName, id: accountId }) => { - return ( - { - dispatchAccount({ - type: 'deleteAccount', - changeId: accountId, - }); - }} - > - {accountName} - - ); - })} - - ); - } - if (clientAccounts.length === 1) { - return ( - - {clientAccounts[0].name} - - ); - } - return null; + localStorage.clear(); + sessionStorage.clear(); + + logout(); }; return ( @@ -119,11 +76,7 @@ export const DangerView = () => { Danger Zone - Delete Account: - {renderButton()} - - - Delete all Accounts and Settings: + Delete all accounts, chats and settings: Delete All diff --git a/src/views/settings/Interface.tsx b/src/views/settings/Interface.tsx index cf0fb6bd..81c92553 100644 --- a/src/views/settings/Interface.tsx +++ b/src/views/settings/Interface.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { useAccountState, CLIENT_ACCOUNT } from 'src/context/AccountContext'; + import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; import Modal from 'src/components/modal/ReactModal'; import numeral from 'numeral'; @@ -24,16 +24,10 @@ import { usePriceState, usePriceDispatch } from '../../context/PriceContext'; export const InterfaceSettings = () => { const [changeFiat, changeFiatSet] = useState(false); const { fiat, prices, dontShow } = usePriceState(); - const { theme, currency, multiNodeInfo } = useConfigState(); + const { theme, currency } = useConfigState(); const dispatch = useConfigDispatch(); const priceDispatch = usePriceDispatch(); - const { accounts } = useAccountState(); - - const viewOnlyAccounts = accounts.filter( - account => account.type === CLIENT_ACCOUNT && account.viewOnly !== '' - ); - const renderButton = ( title: string, value: string, @@ -46,11 +40,6 @@ export const InterfaceSettings = () => { localStorage.setItem(type, value); type === 'theme' && dispatch({ type: 'themeChange', theme: value }); type === 'currency' && dispatch({ type: 'change', currency: value }); - type === 'nodeInfo' && - dispatch({ - type: 'change', - multiNodeInfo: value === 'true' ? true : false, - }); }} > {title} @@ -107,15 +96,6 @@ export const InterfaceSettings = () => { {renderButton('Dark', 'dark', 'theme', theme)} - {viewOnlyAccounts.length > 1 && ( - - Show all accounts on homepage - - {renderButton('Yes', 'true', 'nodeInfo', `${multiNodeInfo}`)} - {renderButton('No', 'false', 'nodeInfo', `${multiNodeInfo}`)} - - - )} Currency diff --git a/src/views/settings/index.tsx b/src/views/settings/index.tsx index 6af10f1a..73c58cb5 100644 --- a/src/views/settings/index.tsx +++ b/src/views/settings/index.tsx @@ -4,7 +4,6 @@ import { SingleLine } from '../../components/generic/Styled'; import { InterfaceSettings } from './Interface'; import { AccountSettings } from './Account'; import { DangerView } from './Danger'; -import { CurrentSettings } from './Current'; export const ButtonRow = styled.div` width: auto; @@ -19,7 +18,6 @@ const SettingsView = () => { return ( <> - diff --git a/src/views/stats/FeeStats.tsx b/src/views/stats/FeeStats.tsx index 9338b2ef..01cbef04 100644 --- a/src/views/stats/FeeStats.tsx +++ b/src/views/stats/FeeStats.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetFeeHealthQuery } from 'src/graphql/queries/__generated__/getFeeHealth.generated'; import { SubCard, @@ -84,11 +83,8 @@ export const FeeStats = () => { const [open, openSet] = React.useState(0); const [openTwo, openTwoSet] = React.useState(0); const dispatch = useStatsDispatch(); - const { auth } = useAccountState(); - const { data, loading } = useGetFeeHealthQuery({ - skip: !auth, - variables: { auth }, - }); + + const { data, loading } = useGetFeeHealthQuery(); React.useEffect(() => { if (data && data.getFeeHealth) { diff --git a/src/views/stats/FlowStats.tsx b/src/views/stats/FlowStats.tsx index 8afbe17e..5bf381f8 100644 --- a/src/views/stats/FlowStats.tsx +++ b/src/views/stats/FlowStats.tsx @@ -1,6 +1,5 @@ import * as React from 'react'; import { useGetVolumeHealthQuery } from 'src/graphql/queries/__generated__/getVolumeHealth.generated'; -import { useAccountState } from 'src/context/AccountContext'; import { SubCard, DarkSubTitle, @@ -65,11 +64,7 @@ const VolumeStatCard = ({ export const VolumeStats = () => { const [open, openSet] = React.useState(0); const dispatch = useStatsDispatch(); - const { auth } = useAccountState(); - const { data, loading } = useGetVolumeHealthQuery({ - skip: !auth, - variables: { auth }, - }); + const { data, loading } = useGetVolumeHealthQuery(); React.useEffect(() => { if (data && data.getVolumeHealth) { diff --git a/src/views/stats/TimeStats.tsx b/src/views/stats/TimeStats.tsx index dd47d4cf..f8ee6fad 100644 --- a/src/views/stats/TimeStats.tsx +++ b/src/views/stats/TimeStats.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetTimeHealthQuery } from 'src/graphql/queries/__generated__/getTimeHealth.generated'; import { SubCard, @@ -68,11 +67,7 @@ const TimeStatCard = ({ channel, open, openSet, index }: TimeStatCardProps) => { export const TimeStats = () => { const [open, openSet] = React.useState(0); const dispatch = useStatsDispatch(); - const { auth } = useAccountState(); - const { data, loading } = useGetTimeHealthQuery({ - skip: !auth, - variables: { auth }, - }); + const { data, loading } = useGetTimeHealthQuery(); React.useEffect(() => { if (data && data.getTimeHealth) { diff --git a/src/views/tools/WalletVersion.tsx b/src/views/tools/WalletVersion.tsx index b9debd80..1b6446fd 100644 --- a/src/views/tools/WalletVersion.tsx +++ b/src/views/tools/WalletVersion.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetWalletInfoQuery } from 'src/graphql/queries/__generated__/getWalletInfo.generated'; import { CardWithTitle, @@ -15,10 +14,8 @@ import { renderLine } from '../../components/generic/helpers'; export const WalletVersion = () => { const { minorVersion } = useStatusState(); - const { auth } = useAccountState(); const { data, loading, error } = useGetWalletInfoQuery({ skip: minorVersion < 10, - variables: { auth }, }); const getStatus = (status: boolean) => (status ? 'Enabled' : 'Disabled'); diff --git a/src/views/tools/accounting/Accounting.tsx b/src/views/tools/accounting/Accounting.tsx index 731ed39e..9f9dbd32 100644 --- a/src/views/tools/accounting/Accounting.tsx +++ b/src/views/tools/accounting/Accounting.tsx @@ -8,7 +8,6 @@ import { Separation, } from 'src/components/generic/Styled'; import { useGetAccountingReportLazyQuery } from 'src/graphql/queries/__generated__/getAccountingReport.generated'; -import { useAccountState } from 'src/context/AccountContext'; import { ColorButton } from 'src/components/buttons/colorButton/ColorButton'; import { MultiButton, @@ -77,7 +76,6 @@ const reducer = (state: StateType, action: ActionType): StateType => { }; export const Accounting = () => { - const { auth } = useAccountState(); const [showDetails, setShowDetails] = React.useState(false); const [state, dispatch] = React.useReducer(reducer, initialState); @@ -183,7 +181,6 @@ export const Accounting = () => { onClick={() => getReport({ variables: { - auth, // fiat: state.fiat, category: state.type, ...(state.year && { year: state.year.toString() }), diff --git a/src/views/tools/backups/Backups.tsx b/src/views/tools/backups/Backups.tsx index 8825725a..7fef8dd7 100644 --- a/src/views/tools/backups/Backups.tsx +++ b/src/views/tools/backups/Backups.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { useAccountState } from 'src/context/AccountContext'; +import { useAccount } from 'src/hooks/UseAccount'; import { CardWithTitle, CardTitle, @@ -10,7 +10,6 @@ import { ResponsiveLine, DarkSubTitle, } from '../../../components/generic/Styled'; -import { AdminSwitch } from '../../../components/adminSwitch/AdminSwitch'; import { getDateDif, getFormatDate } from '../../../components/generic/helpers'; import { DownloadBackups } from './DownloadBackups'; import { VerifyBackups } from './VerifyBackups'; @@ -18,7 +17,8 @@ import { RecoverFunds } from './RecoverFunds'; export const BackupsView = () => { const [lastDate, setLastDate] = useState(''); - const { account } = useAccountState(); + + const account = useAccount(); useEffect(() => { if (account) { @@ -47,9 +47,7 @@ export const BackupsView = () => { - - - + ); diff --git a/src/views/tools/backups/DownloadBackups.tsx b/src/views/tools/backups/DownloadBackups.tsx index 61789285..1e7d4767 100644 --- a/src/views/tools/backups/DownloadBackups.tsx +++ b/src/views/tools/backups/DownloadBackups.tsx @@ -1,20 +1,19 @@ import React, { useEffect } from 'react'; import { toast } from 'react-toastify'; -import { useAccountState } from 'src/context/AccountContext'; import { useGetBackupsLazyQuery } from 'src/graphql/queries/__generated__/getBackups.generated'; +import { useAccount } from 'src/hooks/UseAccount'; import { DarkSubTitle, SingleLine } from '../../../components/generic/Styled'; import { saveToPc } from '../../../utils/helpers'; import { getErrorContent } from '../../../utils/error'; import { ColorButton } from '../../../components/buttons/colorButton/ColorButton'; export const DownloadBackups = () => { - const { account, auth } = useAccountState(); - const [getBackups, { data, loading }] = useGetBackupsLazyQuery({ - variables: { auth }, onError: error => toast.error(getErrorContent(error)), }); + const account = useAccount(); + useEffect(() => { if (account && !loading && data && data.getBackups) { saveToPc(data.getBackups, `ChannelBackup-${account.name}-${account.id}`); diff --git a/src/views/tools/backups/RecoverFunds.tsx b/src/views/tools/backups/RecoverFunds.tsx index a39a27a2..26cd7680 100644 --- a/src/views/tools/backups/RecoverFunds.tsx +++ b/src/views/tools/backups/RecoverFunds.tsx @@ -4,7 +4,6 @@ import { X } from 'react-feather'; import { useRecoverFundsLazyQuery } from 'src/graphql/queries/__generated__/recoverFunds.generated'; import { getErrorContent } from '../../../utils/error'; import { SingleLine, DarkSubTitle } from '../../../components/generic/Styled'; -import { SecureButton } from '../../../components/buttons/secureButton/SecureButton'; import { ColorButton } from '../../../components/buttons/colorButton/ColorButton'; import { Input } from '../../../components/input/Input'; import { NoWrap } from '../Tools.styled'; @@ -31,16 +30,15 @@ export const RecoverFunds = () => { setBackupString(e.target.value)} /> - recoverFunds({ variables: { backup: backupString } })} disabled={backupString === ''} loading={loading} > Recover - + ); diff --git a/src/views/tools/backups/VerifyBackups.tsx b/src/views/tools/backups/VerifyBackups.tsx index f7056998..2589cdef 100644 --- a/src/views/tools/backups/VerifyBackups.tsx +++ b/src/views/tools/backups/VerifyBackups.tsx @@ -1,7 +1,6 @@ import React, { useState, useEffect } from 'react'; import { toast } from 'react-toastify'; import { X } from 'react-feather'; -import { useAccountState } from 'src/context/AccountContext'; import { useVerifyBackupsLazyQuery } from 'src/graphql/queries/__generated__/verifyBackups.generated'; import { getErrorContent } from '../../../utils/error'; import { @@ -17,8 +16,6 @@ export const VerifyBackups = () => { const [backupString, setBackupString] = useState(''); const [isPasting, setIsPasting] = useState(false); - const { auth } = useAccountState(); - const [verifyBackup, { data, loading }] = useVerifyBackupsLazyQuery({ onError: error => toast.error(getErrorContent(error)), }); @@ -50,7 +47,7 @@ export const VerifyBackups = () => { loading={loading} onClick={() => verifyBackup({ - variables: { auth, backup: backupString }, + variables: { backup: backupString }, }) } > diff --git a/src/views/tools/bakery/Bakery.tsx b/src/views/tools/bakery/Bakery.tsx index 77747c72..3e5f9667 100644 --- a/src/views/tools/bakery/Bakery.tsx +++ b/src/views/tools/bakery/Bakery.tsx @@ -18,7 +18,6 @@ import { PermissionsType } from 'server/schema/macaroon/resolvers'; import { useCreateMacaroonMutation } from 'src/graphql/mutations/__generated__/createMacaroon.generated'; import { toast } from 'react-toastify'; import { getErrorContent } from 'src/utils/error'; -import { SecureButton } from 'src/components/buttons/secureButton/SecureButton'; import { useMutationResultWithReset } from 'src/hooks/UseMutationWithReset'; import Modal from 'src/components/modal/ReactModal'; import { shorten } from 'src/components/generic/helpers'; @@ -127,16 +126,15 @@ export const Bakery = () => { {renderLine('Stop Daemon', 'is_ok_to_stop_daemon')} {renderLine('Verify bytes signature', 'is_ok_to_verify_bytes_signatures')} {renderLine('Verify messages', 'is_ok_to_verify_messages')} - bake({ variables: { permissions } })} disabled={loading || !hasATrue} loading={loading} > Bake new macaroon - + ); diff --git a/src/views/tools/messages/SignMessage.tsx b/src/views/tools/messages/SignMessage.tsx index ad161afb..66a3b826 100644 --- a/src/views/tools/messages/SignMessage.tsx +++ b/src/views/tools/messages/SignMessage.tsx @@ -2,10 +2,8 @@ import React, { useState, useEffect } from 'react'; import { toast } from 'react-toastify'; import { X, Copy } from 'react-feather'; import CopyToClipboard from 'react-copy-to-clipboard'; -import { useAccountState } from 'src/context/AccountContext'; import { useSignMessageLazyQuery } from 'src/graphql/queries/__generated__/signMessage.generated'; import { Input } from '../../../components/input/Input'; -import { SecureButton } from '../../../components/buttons/secureButton/SecureButton'; import { ColorButton } from '../../../components/buttons/colorButton/ColorButton'; import { SingleLine, @@ -13,7 +11,6 @@ import { Separation, } from '../../../components/generic/Styled'; import { getErrorContent } from '../../../utils/error'; -import { AdminSwitch } from '../../../components/adminSwitch/AdminSwitch'; import { Column, WrapRequest } from '../Tools.styled'; import { NoWrap } from './Messages'; @@ -22,8 +19,6 @@ export const SignMessage = () => { const [isPasting, setIsPasting] = useState(false); const [signed, setSigned] = useState(''); - const { auth } = useAccountState(); - const [signMessage, { data, loading }] = useSignMessageLazyQuery({ onError: error => toast.error(getErrorContent(error)), }); @@ -45,16 +40,15 @@ export const SignMessage = () => { onChange={e => setMessage(e.target.value)} /> - signMessage({ variables: { message } })} fullWidth={true} withMargin={'8px 0 4px'} disabled={message === ''} loading={loading} > Sign - + ); @@ -75,7 +69,7 @@ export const SignMessage = () => { ); return ( - + <> Sign Message { {isPasting && renderInput()} {signed !== '' && isPasting && renderMessage()} - + ); }; diff --git a/src/views/tools/messages/VerifyMessage.tsx b/src/views/tools/messages/VerifyMessage.tsx index b31e1e93..190bdaf9 100644 --- a/src/views/tools/messages/VerifyMessage.tsx +++ b/src/views/tools/messages/VerifyMessage.tsx @@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react'; import { toast } from 'react-toastify'; import { X, Copy } from 'react-feather'; import CopyToClipboard from 'react-copy-to-clipboard'; -import { useAccountState } from 'src/context/AccountContext'; import { useVerifyMessageLazyQuery } from 'src/graphql/queries/__generated__/verifyMessage.generated'; import { Input } from '../../../components/input/Input'; import { ColorButton } from '../../../components/buttons/colorButton/ColorButton'; @@ -22,8 +21,6 @@ export const VerifyMessage = () => { const [isPasting, setIsPasting] = useState(false); const [signedBy, setSignedBy] = useState(''); - const { auth } = useAccountState(); - const [signMessage, { data, loading }] = useVerifyMessageLazyQuery({ onError: error => toast.error(getErrorContent(error)), }); @@ -59,7 +56,7 @@ export const VerifyMessage = () => { withMargin={'8px 0 4px'} disabled={message === '' || signature === ''} loading={loading} - onClick={() => signMessage({ variables: { auth, message, signature } })} + onClick={() => signMessage({ variables: { message, signature } })} > Verify