fix: ๐Ÿ› logging and types

This commit is contained in:
AP 2020-05-20 22:32:55 +02:00
parent 2797e6edf3
commit 4c74ed1536
7 changed files with 30 additions and 38 deletions

View file

@ -167,14 +167,16 @@ export const readMacaroons = (macaroonPath: string): string | null => {
return null;
}
const adminExists = fs.existsSync(`${macaroonPath}admin.macaroon`);
const adminExists = fs.existsSync(`${macaroonPath}/admin.macaroon`);
if (!adminExists) {
logger.error(`No admin.macaroon file found at path: ${macaroonPath}`);
logger.error(
`No admin.macaroon file found at path: ${macaroonPath}/admin.macaroon`
);
return null;
} else {
try {
const ssoAdmin = fs.readFileSync(`${macaroonPath}admin.macaroon`, 'hex');
const ssoAdmin = fs.readFileSync(`${macaroonPath}/admin.macaroon`, 'hex');
return ssoAdmin;
} catch (err) {
logger.error(
@ -219,7 +221,7 @@ export const readCookie = (cookieFile: string): string | null => {
const exists = fs.existsSync(cookieFile);
if (exists) {
try {
logger.info(`Found cookie at path ${cookieFile}`);
logger.verbose(`Found cookie at path ${cookieFile}`);
const cookie = fs.readFileSync(cookieFile, 'utf-8');
return cookie;
} catch (err) {

View file

@ -16,9 +16,14 @@ export const getAuthToken = {
cookie: { type: GraphQLString },
},
resolve: async (_: undefined, params: any, context: ContextType) => {
const { ip, secret } = context;
const { ip, secret, sso } = context;
await requestLimiter(ip, 'getAuthToken');
if (!sso.host || !sso.macaroon) {
logger.warn('Host and macaroon are required for SSO');
return null;
}
if (!params.cookie) {
return null;
}

View file

@ -9,7 +9,9 @@
"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:compatible": "next start",
"start:compatible:two": "next start -p 3001",
"lint": "eslint */**/*.{js,ts,tsx} --quiet --fix",
"prettier": "prettier --write **/*.{ts,tsx,js,css,html}",
"release": "standard-version",

View file

@ -204,16 +204,13 @@ const BalanceView = () => {
)}
{incoming && outgoing && amount && (
<BalanceRoute
{...{
incoming,
outgoing,
amount,
maxFee,
auth,
blocked,
setBlocked: () => setBlocked(true),
callback: () => handleReset('all'),
}}
incoming={incoming}
outgoing={outgoing}
amount={amount}
maxFee={maxFee}
blocked={blocked}
setBlocked={() => setBlocked(true)}
callback={() => handleReset('all')}
/>
)}
</Card>

View file

@ -2,6 +2,7 @@ import React from 'react';
import { toast } from 'react-toastify';
import { useGetRoutesLazyQuery } from 'src/graphql/queries/__generated__/getRoutes.generated';
import { usePayViaRouteMutation } from 'src/graphql/mutations/__generated__/payViaRoute.generated';
import { useAccountState } from 'src/context/AccountContext';
import {
SubCard,
Sub4Title,
@ -23,7 +24,6 @@ type BalancedRouteProps = {
outgoing: any;
amount: number;
maxFee?: number;
auth: {};
blocked: boolean;
setBlocked: () => void;
callback: () => void;
@ -34,11 +34,12 @@ export const BalanceRoute = ({
outgoing,
amount,
maxFee,
auth,
blocked,
setBlocked,
callback,
}: BalancedRouteProps) => {
const { auth } = useAccountState();
const [getRoute, { loading, data, called }] = useGetRoutesLazyQuery({
fetchPolicy: 'no-cache',
onError: error => {

View file

@ -2,6 +2,7 @@ import * as React from 'react';
import styled from 'styled-components';
import { useDecodeRequestQuery } from 'src/graphql/queries/__generated__/decodeRequest.generated';
import { useGetNodeQuery } from 'src/graphql/queries/__generated__/getNode.generated';
import { useAccountState } from 'src/context/AccountContext';
import {
SingleLine,
SubTitle,
@ -28,14 +29,10 @@ export const Centered = styled.div`
interface DecodeProps {
request: string;
auth: {};
}
export const RequestModal: React.FC<DecodeProps> = ({
children,
request,
auth,
}) => {
export const RequestModal: React.FC<DecodeProps> = ({ children, request }) => {
const { auth } = useAccountState();
const { data, loading, error } = useDecodeRequestQuery({
variables: { auth, request },
});
@ -77,18 +74,17 @@ export const RequestModal: React.FC<DecodeProps> = ({
interface KeysendProps {
tokens: number;
auth: {};
publicKey: string;
setTokens: (amount: number) => void;
}
export const KeysendModal: React.FC<KeysendProps> = ({
children,
auth,
publicKey,
tokens,
setTokens,
}) => {
const { auth } = useAccountState();
const { data, loading, error } = useGetNodeQuery({
variables: { auth, publicKey },
});

View file

@ -1,6 +1,5 @@
import React, { useState } from 'react';
import { toast } from 'react-toastify';
import { useAccountState } from 'src/context/AccountContext';
import { usePayInvoiceMutation } from 'src/graphql/mutations/__generated__/pay.generated';
import {
Sub4Title,
@ -24,7 +23,6 @@ export const PayCard = ({ setOpen }: { setOpen: () => void }) => {
const [tokens, setTokens] = useState<number>(0);
const [modalType, setModalType] = useState('none');
const { auth } = useAccountState();
const { minorVersion } = useStatusState();
const canKeysend = minorVersion >= 9;
@ -76,20 +74,11 @@ export const PayCard = ({ setOpen }: { setOpen: () => void }) => {
const renderModal = () => {
if (modalType === 'request') {
return (
<RequestModal request={request} auth={auth}>
{renderButton()}
</RequestModal>
);
return <RequestModal request={request}>{renderButton()}</RequestModal>;
}
if (modalType === 'keysend') {
return (
<KeysendModal
tokens={tokens}
auth={auth}
publicKey={request}
setTokens={setTokens}
>
<KeysendModal tokens={tokens} publicKey={request} setTokens={setTokens}>
{renderButton()}
</KeysendModal>
);