Skip to content

Commit

Permalink
chore: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Dec 8, 2021
1 parent ed234f2 commit 69e1a5c
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 99 deletions.
58 changes: 29 additions & 29 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ type Channel {
}

type ChannelFeeHealth {
id: String!
mySide: FeeHealth!
partner: Node!
partnerSide: FeeHealth!
id: String
mySide: FeeHealth
partner: Node
partnerSide: FeeHealth
}

type ChannelHealth {
averageVolumeNormalized: String!
id: String!
partner: Node!
score: Float!
volumeNormalized: String!
averageVolumeNormalized: String
id: String
partner: Node
score: Float
volumeNormalized: String
}

type ChannelReport {
Expand All @@ -201,28 +201,28 @@ type ChannelRequest {
}

type ChannelTimeHealth {
id: String!
monitoredDowntime: Float!
monitoredTime: Float!
monitoredUptime: Float!
partner: Node!
score: Float!
significant: Boolean!
id: String
monitoredDowntime: Float
monitoredTime: Float
monitoredUptime: Float
partner: Node
score: Float
significant: Boolean
}

type ChannelsFeeHealth {
channels: ChannelFeeHealth!
score: Float!
channels: [ChannelFeeHealth!]
score: Float
}

type ChannelsHealth {
channels: ChannelHealth!
score: Float!
channels: [ChannelHealth!]
score: Float
}

type ChannelsTimeHealth {
channels: ChannelTimeHealth!
score: Float!
channels: [ChannelTimeHealth!]
score: Float
}

type ClosedChannel {
Expand Down Expand Up @@ -293,13 +293,13 @@ type DecodeInvoice {
}

type FeeHealth {
base: String!
baseOver: Boolean!
baseScore: Float!
rate: Float!
rateOver: Boolean!
rateScore: Float!
score: Float!
base: String
baseOver: Boolean
baseScore: Float
rate: Float
rateOver: Boolean
rateScore: Float
score: Float
}

type Forward {
Expand Down
2 changes: 1 addition & 1 deletion src/client/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const NotAuthenticated: React.FC = () => {
useEffect(() => {
const timeout = setTimeout(
() => push(logoutUrl || `${basePath}/login`),
5000
3000
);

return () => {
Expand Down
13 changes: 6 additions & 7 deletions src/client/pages/sso.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as React from 'react';
import { ServerAccounts } from '../src/components/accounts/ServerAccounts';
import { useCheckAuthToken } from '../src/hooks/UseCheckAuthToken';
import { NextPageContext } from 'next';
import { getProps } from '../src/utils/ssr';
import { LoadingCard } from '../src/components/loading/LoadingCard';

const Wrapped = () => (
<>
<ServerAccounts />
<LoadingCard noCard={true} loadingHeight={'80vh'} />
</>
);
const Wrapped = () => {
useCheckAuthToken();

return <LoadingCard noCard={true} loadingHeight={'80vh'} />;
};

export default Wrapped;

Expand Down
11 changes: 4 additions & 7 deletions src/client/src/components/logoutButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { FC, useEffect } from 'react';
import { LogOut } from 'react-feather';
import { useRouter } from 'next/router';
import { useLogoutMutation } from '../../../src/graphql/mutations/__generated__/logout.generated';
import { useApolloClient } from '@apollo/client';
import { HeaderNavButton } from '../../../src/layouts/header/Header.styled';
Expand All @@ -27,7 +26,6 @@ const LogoutWrapperStyled = styled(Logout)`
`;

export const LogoutWrapper: FC = ({ children }) => {
const { push } = useRouter();
const client = useApolloClient();

const dispatchChat = useChatDispatch();
Expand All @@ -41,9 +39,9 @@ export const LogoutWrapper: FC = ({ children }) => {
dispatchChat({ type: 'disconnected' });
client.clearStore();

logoutUrl ? (window.location.href = logoutUrl) : push('/login');
window.location.href = logoutUrl || '/login';
}
}, [data, dispatchChat, push, client]);
}, [data, dispatchChat, client]);

if (loading) {
return (
Expand All @@ -61,7 +59,6 @@ export const LogoutWrapper: FC = ({ children }) => {
};

export const LogoutButton = () => {
const { push } = useRouter();
const client = useApolloClient();

const dispatchChat = useChatDispatch();
Expand All @@ -75,9 +72,9 @@ export const LogoutButton = () => {
dispatchChat({ type: 'disconnected' });
client.clearStore();

logoutUrl ? (window.location.href = logoutUrl) : push('/login');
window.location.href = logoutUrl || '/login';
}
}, [data, dispatchChat, push, client]);
}, [data, dispatchChat, client]);

if (loading) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as React from 'react';
import { useRouter } from 'next/router';
import { getUrlParam } from '../../../src/utils/url';
import { getUrlParam } from '../utils/url';
import { toast } from 'react-toastify';
import { getErrorContent } from '../../../src/utils/error';
import { getErrorContent } from '../utils/error';
import getConfig from 'next/config';
import { useGetAuthTokenMutation } from '../../../src/graphql/mutations/__generated__/getAuthToken.generated';
import { useGetAuthTokenMutation } from '../graphql/mutations/__generated__/getAuthToken.generated';

const { publicRuntimeConfig } = getConfig();
const { logoutUrl } = publicRuntimeConfig;

export const ServerAccounts: React.FC = () => {
const { push, query } = useRouter();
export const useCheckAuthToken = () => {
const { query } = useRouter();

const cookieParam = getUrlParam(query?.token);

Expand All @@ -19,28 +19,26 @@ export const ServerAccounts: React.FC = () => {
refetchQueries: ['GetNodeInfo'],
onError: error => {
toast.error(getErrorContent(error));
logoutUrl ? (window.location.href = logoutUrl) : push('/login');
window.location.href = logoutUrl || 'login';
},
});

React.useEffect(() => {
if (cookieParam) {
getToken();
} else {
logoutUrl ? (window.location.href = logoutUrl) : push('/login');
window.location.href = logoutUrl || 'login';
}
}, [cookieParam, push, getToken]);
}, [cookieParam, getToken]);

React.useEffect(() => {
if (!cookieParam || !data) return;
if (data.getAuthToken) {
push('/');
window.location.href = '/';
}
if (!data.getAuthToken) {
toast.warning('Unable to SSO. Check your logs.');
logoutUrl ? (window.location.href = logoutUrl) : push('/login');
window.location.href = logoutUrl || 'login';
}
}, [push, data, cookieParam]);

return null;
}, [data, cookieParam]);
};
12 changes: 6 additions & 6 deletions src/client/src/views/homepage/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { chartColors } from '../../styles/Themes';
import { useRouter } from 'next/router';
import { Link } from '../../components/link/Link';
import { useGetServerAccountsQuery } from '../../graphql/queries/__generated__/getServerAccounts.generated';
import { ServerAccountType } from '../../graphql/types';
import { LoadingCard } from '../../components/loading/LoadingCard';
import { useLogoutMutation } from '../../graphql/mutations/__generated__/logout.generated';
import { useGetNodeInfoLazyQuery } from '../../graphql/queries/__generated__/getNodeInfo.generated';
Expand All @@ -21,6 +20,7 @@ import {
import { ColorButton } from '../../components/buttons/colorButton/ColorButton';
import { ConnectTitle, LockPadding } from './HomePage.styled';
import { Login } from './Login';
import { ServerAccount } from '../../graphql/types';

const AccountLine = styled.div`
margin: 8px 0;
Expand Down Expand Up @@ -74,7 +74,7 @@ const RenderIntro = () => {

export const Accounts = () => {
const { push, prefetch } = useRouter();
const [newAccount, setNewAccount] = React.useState<ServerAccountType | null>(
const [newAccount, setNewAccount] = React.useState<ServerAccount | null>(
null
);

Expand Down Expand Up @@ -113,7 +113,7 @@ export const Accounts = () => {
return <RenderIntro />;
}

const getTitle = (account: ServerAccountType) => {
const getTitle = (account: ServerAccount) => {
const { type, name, loggedIn } = account;

const props = {
Expand All @@ -130,21 +130,21 @@ export const Accounts = () => {
);
};

const getButtonTitle = (account: ServerAccountType): string => {
const getButtonTitle = (account: ServerAccount): string => {
if (account.loggedIn) {
return 'Connect';
}
return 'Login';
};

const getArrow = (account: ServerAccountType): boolean => {
const getArrow = (account: ServerAccount): boolean => {
if (account.loggedIn) {
return false;
}
return true;
};

const handleClick = (account: ServerAccountType) => () => {
const handleClick = (account: ServerAccount) => () => {
if (account.type === 'sso') {
getCanConnect();
} else if (account.type === 'server' && account.loggedIn) {
Expand Down
11 changes: 4 additions & 7 deletions src/client/src/views/homepage/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { useState, useEffect } from 'react';
import { toast } from 'react-toastify';
import styled from 'styled-components';
import { useRouter } from 'next/router';
import { getErrorContent } from '../../utils/error';
import { Lock } from 'react-feather';
import { ServerAccountType } from '../../graphql/types';
import { ServerAccount } from '../../graphql/types';
import { getVersion } from '../../utils/version';
import { useGetSessionTokenMutation } from '../../graphql/mutations/__generated__/getSessionToken.generated';
import { SingleLine, Sub4Title, Card } from '../../components/generic/Styled';
Expand Down Expand Up @@ -32,12 +31,10 @@ const IconPadding = styled.span`
`;

type LoginProps = {
account: ServerAccountType;
account: ServerAccount;
};

export const Login = ({ account }: LoginProps) => {
const { push } = useRouter();

const [pass, setPass] = useState('');

const [getSessionToken, { data, loading }] = useGetSessionTokenMutation({
Expand All @@ -55,9 +52,9 @@ export const Login = ({ account }: LoginProps) => {
'ThunderHub supports LND version 0.11.0 and higher. Please update your node, you are in risk of losing funds.'
);
} else {
push('/');
window.location.href = '/';
}
}, [data, loading, push]);
}, [data, loading]);

if (!account) return null;

Expand Down
1 change: 1 addition & 0 deletions src/server/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type JwtObjectType = {
ConfigModule.forRoot({
isGlobal: true,
load: [configuration],
envFilePath: ['.env.local', '.env'],
}),
GraphQLModule.forRootAsync({
inject: [ConfigService],
Expand Down
Loading

0 comments on commit 69e1a5c

Please sign in to comment.