Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ accounting #75

Merged
merged 6 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pages/tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ 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 { BackupsView } from '../src/views/tools/backups/Backups';
import { MessagesView } from '../src/views/tools/messages/Messages';
import { WalletVersion } from '../src/views/tools/WalletVersion';

const ToolsView = () => (
<>
<Accounting />
<BackupsView />
<MessagesView />
<Bakery />
Expand Down
67 changes: 64 additions & 3 deletions server/schema/bos/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ContextType } from 'server/types/apiTypes';
import { getLnd } from 'server/helpers/helpers';
import { rebalance } from 'balanceofsatoshis/swaps';
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';

type RebalanceType = {
auth: AuthType;
avoid?: String[];
Expand All @@ -19,21 +22,79 @@ type RebalanceType = {
target?: Number;
};

type AccountingType = {
auth: AuthType;
category?: String;
currency?: String;
fiat?: String;
month?: String;
year?: String;
};

export const bosResolvers = {
Query: {
getAccountingReport: async (
_: undefined,
params: AccountingType,
context: ContextType
) => {
const { auth, ...settings } = params;
const lnd = getLnd(auth, context);

const response = await to(
getAccountingReport({
lnd,
logger,
request,
is_csv: true,
...settings,
})
);

return response;
},
},
Mutation: {
bosRebalance: async (
_: undefined,
params: RebalanceType,
context: ContextType
) => {
const { auth, ...extraparams } = params;
const {
auth,
avoid,
in_through,
is_avoiding_high_inbound,
max_fee,
max_fee_rate,
max_rebalance,
node,
out_channels,
out_through,
target,
} = params;
const lnd = getLnd(auth, context);

const filteredParams = {
...(avoid.length > 0 && { avoid }),
...(in_through && { in_through }),
...(is_avoiding_high_inbound && { is_avoiding_high_inbound }),
...(max_fee > 0 && { max_fee }),
...(max_fee_rate > 0 && { max_fee_rate }),
...(max_rebalance > 0 && { max_rebalance }),
...(node && { node }),
...(out_channels.length > 0 && { out_channels }),
...(out_through && { out_through }),
...(target && { target }),
};

logger.info('Rebalance Params: %o', filteredParams);

const response = await to(
rebalance({
lnd,
logger,
...extraparams,
...filteredParams,
})
);

Expand Down
8 changes: 8 additions & 0 deletions server/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export const generalTypes = gql`

export const queryTypes = gql`
type Query {
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
Expand Down
3 changes: 3 additions & 0 deletions server/tests/__mocks__/balanceofsatoshis/balances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getAccountingReport = jest
.fn()
.mockReturnValue(Promise.resolve({}));
1 change: 1 addition & 0 deletions src/components/buttons/multiButton/MultiButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const StyledSingleButton = styled.button<StyledSingleProps>`
background-color: transparent;
color: ${multiSelectColor};
flex-grow: 1;
transition: background-color 0.5s ease;

${({ selected, buttonColor }) =>
selected
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/graphql/queries/getAccountingReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import gql from 'graphql-tag';

export const GET_ACCOUNTING_REPORT = gql`
query GetAccountingReport(
$auth: authType!
$category: String
$currency: String
$fiat: String
$month: String
$year: String
) {
getAccountingReport(
auth: $auth
category: $category
currency: $currency
fiat: $fiat
month: $month
year: $year
)
}
`;
10 changes: 10 additions & 0 deletions src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type PermissionsType = {

export type Query = {
__typename?: 'Query';
getAccountingReport: Scalars['String'];
getVolumeHealth?: Maybe<ChannelsHealth>;
getTimeHealth?: Maybe<ChannelsTimeHealth>;
getFeeHealth?: Maybe<ChannelsFeeHealth>;
Expand Down Expand Up @@ -90,6 +91,15 @@ export type Query = {
getLatestVersion?: Maybe<Scalars['String']>;
};

export type QueryGetAccountingReportArgs = {
auth: AuthType;
category?: Maybe<Scalars['String']>;
currency?: Maybe<Scalars['String']>;
fiat?: Maybe<Scalars['String']>;
month?: Maybe<Scalars['String']>;
year?: Maybe<Scalars['String']>;
};

export type QueryGetVolumeHealthArgs = {
auth: AuthType;
};
Expand Down
8 changes: 6 additions & 2 deletions src/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ export const getPercent = (
return Math.round(percent);
};

export const saveToPc = (jsonData: string, filename: string) => {
export const saveToPc = (
jsonData: string,
filename: string,
isCsv?: boolean
) => {
const fileData = jsonData;
const blob = new Blob([fileData], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.download = `${filename}.txt`;
link.download = isCsv ? `${filename}.csv` : `${filename}.txt`;
link.href = url;
link.click();
};
Expand Down
13 changes: 10 additions & 3 deletions src/views/balance/AdvancedBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export const AdvancedBalance = () => {
{hasAvoid ? <Minus size={18} /> : <Plus size={18} />}
</ColorButton>
</SettingLine>
<SettingLine title={'In Through Channel'}>
<SettingLine title={'Decrease Inbound Of'}>
{hasInChannel ? (
<RebalanceTag>{state.in_through.alias}</RebalanceTag>
) : null}
Expand All @@ -247,7 +247,7 @@ export const AdvancedBalance = () => {
</ColorButton>
</SettingLine>
{!hasOutChannels && (
<SettingLine title={'Out Through Channel'}>
<SettingLine title={'Increase Inbound Of'}>
{hasOutChannel ? (
<RebalanceTag>{state.out_through.alias}</RebalanceTag>
) : null}
Expand Down Expand Up @@ -427,7 +427,14 @@ export const AdvancedBalance = () => {
</BetaNotification>
<InputWithDeco title={'Type'} noInput={true}>
<MultiButton>
{renderButton(() => isDetailedSet(false), 'Auto', !isDetailed)}
{renderButton(
() => {
dispatch({ type: 'clearFilters' });
isDetailedSet(false);
},
'Auto',
!isDetailed
)}
{renderButton(() => isDetailedSet(true), 'Detailed', isDetailed)}
</MultiButton>
</InputWithDeco>
Expand Down
5 changes: 5 additions & 0 deletions src/views/tools/Tools.styled.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from 'styled-components';
import { ResponsiveLine } from 'src/components/generic/Styled';

export const NoWrap = styled.div`
margin-right: 16px;
Expand All @@ -22,3 +23,7 @@ export const Column = styled.div`
justify-content: center;
align-items: center;
`;

export const ToolsResponsiveLine = styled(ResponsiveLine)`
margin-bottom: 8px;
`;
6 changes: 5 additions & 1 deletion src/views/tools/WalletVersion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Card,
Sub4Title,
Separation,
DarkSubTitle,
} from '../../components/generic/Styled';
import { useStatusState } from '../../context/StatusContext';
import { LoadingCard } from '../../components/loading/LoadingCard';
Expand All @@ -30,7 +31,10 @@ export const WalletVersion = () => {
if (minorVersion < 10) {
return (
<Card>
Update to LND version 0.10.0 or higher to see your wallet build info.
<DarkSubTitle>
Update to LND version 0.10.0 or higher to see your wallet build
info.
</DarkSubTitle>
</Card>
);
}
Expand Down
Loading