This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from niteshbalusu11:clean-failed-payments-com…
…mand Added clean-failed-payments command
- Loading branch information
Showing
16 changed files
with
613 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
|
||
/* | ||
Renders the output of the CleanFailedPayments command. | ||
*/ | ||
|
||
const styles = { | ||
div: { | ||
marginTop: '50px', | ||
marginLeft: '10px', | ||
}, | ||
text: { | ||
fontSize: '15px', | ||
fontWeight: 'bold', | ||
display: 'inline-block', | ||
}, | ||
}; | ||
|
||
type Data = { | ||
data: { | ||
total_failed_payments_deleted?: number; | ||
total_failed_payments_found?: number; | ||
}; | ||
}; | ||
|
||
const CleanFailedPaymentsOutput = ({ data }: Data) => { | ||
return ( | ||
<div style={styles.div}> | ||
{data.total_failed_payments_deleted === undefined && data.total_failed_payments_found === undefined ? ( | ||
<h3>{'No Failed Payments Found/Deleted'}</h3> | ||
) : null} | ||
|
||
{data.total_failed_payments_deleted !== undefined ? ( | ||
<h3 id="paymentsdeleted">{`Total Failed Payments Deleted: ${data.total_failed_payments_deleted}`}</h3> | ||
) : null} | ||
|
||
{data.total_failed_payments_found !== undefined ? ( | ||
<h3 id="paymentsfound">{`Total Failed Payments Found: ${data.total_failed_payments_found}`}</h3> | ||
) : null} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CleanFailedPaymentsOutput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import * as types from '~shared/types'; | ||
|
||
import { CssBaseline, FormControlLabel, Stack, TextField } from '@mui/material'; | ||
import React, { useState } from 'react'; | ||
import { | ||
StandardHomeButtonLink, | ||
StandardSwitch, | ||
StartFlexBox, | ||
SubmitButton, | ||
} from '~client/standard_components/app-components'; | ||
import commands, { globalCommands } from '../../commands'; | ||
|
||
import { CleanFailedPaymentsOutput } from '~client/output'; | ||
import Head from 'next/head'; | ||
import { axiosPostWithAlert } from '~client/utils/axios'; | ||
|
||
const CleanFailedPaymentsCommand = commands.find(n => n.value === 'CleanFailedPayments'); | ||
|
||
/* | ||
Renders the bos clean-failed-payments command | ||
GET call to the NestJs process to get failed payments found or deleted | ||
*/ | ||
|
||
const CleanFailedPayments = () => { | ||
const [data, setData] = useState(undefined); | ||
const [dryRun, setDryRun] = useState(false); | ||
const [node, setNode] = useState(''); | ||
|
||
const handleDryRunChange = () => { | ||
setDryRun(previousValue => !previousValue); | ||
}; | ||
|
||
const handleNodeChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setNode(event.target.value); | ||
}; | ||
|
||
const fetchData = async () => { | ||
const postBody: types.commandCleanFailedPayments = { | ||
node, | ||
is_dry_run: dryRun, | ||
}; | ||
|
||
const { result } = await axiosPostWithAlert({ path: 'clean-failed-payments', postBody }); | ||
|
||
if (!!result) { | ||
setData(result); | ||
} | ||
}; | ||
|
||
return ( | ||
<CssBaseline> | ||
<Head> | ||
<title>Clean Failed Payments</title> | ||
</Head> | ||
<StartFlexBox> | ||
<StandardHomeButtonLink /> | ||
<Stack spacing={3} style={styles.form}> | ||
<h2>{CleanFailedPaymentsCommand.name}</h2> | ||
<h4 style={styles.h4}>{CleanFailedPaymentsCommand.longDescription}</h4> | ||
<FormControlLabel | ||
style={styles.switch} | ||
control={ | ||
<StandardSwitch | ||
checked={dryRun} | ||
onChange={handleDryRunChange} | ||
id={CleanFailedPaymentsCommand.flags.dryrun} | ||
/> | ||
} | ||
label={CleanFailedPaymentsCommand.flags.dryrun} | ||
/> | ||
<TextField | ||
type="text" | ||
placeholder={globalCommands.node.name} | ||
label={globalCommands.node.name} | ||
id={globalCommands.node.value} | ||
onChange={handleNodeChange} | ||
style={styles.textField} | ||
/> | ||
<SubmitButton variant="contained" onClick={fetchData}> | ||
Run Command | ||
</SubmitButton> | ||
{!!data ? <CleanFailedPaymentsOutput data={data} /> : null} | ||
</Stack> | ||
</StartFlexBox> | ||
</CssBaseline> | ||
); | ||
}; | ||
|
||
export default CleanFailedPayments; | ||
|
||
const styles = { | ||
form: { | ||
marginLeft: '50px', | ||
marginTop: '100px', | ||
width: '700px', | ||
}, | ||
h4: { | ||
marginTop: '0px', | ||
}, | ||
switch: { | ||
width: '100px', | ||
}, | ||
textField: { | ||
width: '500px', | ||
}, | ||
}; |
28 changes: 28 additions & 0 deletions
28
src/server/commands/cleanFailedPayments/clean_failed_payments_command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { cleanFailedPayments } from 'balanceofsatoshis/wallets'; | ||
|
||
/** Clean out failed payments from the wallet | ||
{ | ||
is_dry_run: <Avoid Actually Deleting Payments> | ||
lnd: <Authenticated LND API Object> | ||
logger: <Winston Logger Object> | ||
} | ||
@returns via Promise | ||
{ | ||
[total_failed_payments_found]: <Failed Payments Found Number> | ||
[total_failed_payments_deleted]: <Failed Payments Deleted Number> | ||
} | ||
*/ | ||
|
||
const cleanFailedPaymentsCommand = async ({ args, lnd, logger }) => { | ||
const result = await cleanFailedPayments({ | ||
lnd, | ||
logger, | ||
is_dry_run: args.is_dry_run, | ||
}); | ||
|
||
return { result }; | ||
}; | ||
|
||
export default cleanFailedPaymentsCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.