Skip to content

Commit

Permalink
feat: sweep-all
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Nov 10, 2023
1 parent 9ce8ee6 commit ebb214c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/gateway-ui/src/GatewayApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class GatewayApi {

requestWithdrawal = async (
federationId: string,
amountSat: number,
amountSat: number | 'all',
address: string
): Promise<string> => {
try {
Expand Down
20 changes: 18 additions & 2 deletions apps/gateway-ui/src/components/WithdrawCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ export const WithdrawCard = React.memo(function WithdrawCard({
setModalState(true);
}, [amount, address, t]);

const sweepAll = useCallback(() => {
setAmount(balanceMsat / 1000);
createWithdrawal();
}, [balanceMsat, createWithdrawal]);

const startWithdrawal = useCallback(() => {
const withdrawalAmount = amount === balanceMsat / 1000 ? 'all' : amount;

gateway
.requestWithdrawal(federationId, amount, address)
.requestWithdrawal(federationId, withdrawalAmount, address)
.then((txId) => {
alert(`${t('withdraw-card.your-transaction')} ${txId}`);
setAddress('');
Expand All @@ -69,7 +76,7 @@ export const WithdrawCard = React.memo(function WithdrawCard({
console.error(error);
setError(`${t('withdraw-card.error-request')}`);
});
}, [gateway, federationId, amount, address, t]);
}, [gateway, federationId, amount, address, balanceMsat, t]);

return (
<>
Expand Down Expand Up @@ -161,6 +168,15 @@ export const WithdrawCard = React.memo(function WithdrawCard({
>
{t('withdraw-card.card-header')}
</Button>
<Button
borderRadius='8px'
maxW='145px'
isDisabled={!address}
fontSize='sm'
onClick={sweepAll}
>
{t('withdraw-card.sweep-all')}
</Button>
</Stack>
</GatewayCard>

Expand Down

0 comments on commit ebb214c

Please sign in to comment.