From 7b18f91cb115b45902f0f7e4ccc0ada9d0f857ca Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Sun, 21 Jan 2024 12:30:15 -0800 Subject: [PATCH] feat: impl leave fed --- src/client/pages/fedimints.tsx | 8 +++++++- src/client/src/api/GatewayApi.ts | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/client/pages/fedimints.tsx b/src/client/pages/fedimints.tsx index 37dddf27..fea72a5b 100644 --- a/src/client/pages/fedimints.tsx +++ b/src/client/pages/fedimints.tsx @@ -16,6 +16,7 @@ import { Federation } from '../src/api/types'; import { CellContext } from '@tanstack/react-table'; import { toast } from 'react-toastify'; import { Price } from '../src/components/price/Price'; +import { gatewayApi } from '../src/api/GatewayApi'; const FedimintsView = () => { const federations = useGatewayFederations(); @@ -76,7 +77,12 @@ const FedimintsView = () => { if (props.row.original.balance_msat > 0) { toast.error("Can't leave a federation you've got sats in!"); } else { - toast.warn('Not implemented yet!'); + try { + gatewayApi.leaveFederation(props.row.original.federation_id); + toast.success('Left Federation'); + } catch (e: any) { + toast.error(e.message); + } } }} > diff --git a/src/client/src/api/GatewayApi.ts b/src/client/src/api/GatewayApi.ts index 7800b019..1520ec0c 100644 --- a/src/client/src/api/GatewayApi.ts +++ b/src/client/src/api/GatewayApi.ts @@ -87,6 +87,20 @@ class GatewayApi { } }; + leaveFederation = async (federationId: string): Promise => { + try { + const res: Response = await this.post('leave-fed', { + federation_id: federationId, + }); + + if (!res.ok) { + throw responseToError(res); + } + } catch (error) { + return Promise.reject({ message: 'Error leaving federation', error }); + } + }; + requestWithdrawal = async ( federationId: string, amountSat: number | 'all',