From f01f6efce602dcc7d3acf7444fb511143ee5ccc9 Mon Sep 17 00:00:00 2001 From: Oluwatobi Bamidele Date: Thu, 12 Dec 2024 07:57:41 +0200 Subject: [PATCH 1/3] update: add pubkey, route hint and sats amount to connection code --- src/pages/superadmin/header/InviteModal.tsx | 105 ++++++++++++++++---- src/people/utils/style.ts | 5 + src/store/main.ts | 17 +++- 3 files changed, 107 insertions(+), 20 deletions(-) diff --git a/src/pages/superadmin/header/InviteModal.tsx b/src/pages/superadmin/header/InviteModal.tsx index 5a20fc3f..8c941222 100644 --- a/src/pages/superadmin/header/InviteModal.tsx +++ b/src/pages/superadmin/header/InviteModal.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { nonWidgetConfigs } from 'people/utils/Constants'; import { useIsMobile } from 'hooks/uiHooks'; -import { InvoiceForm, InvoiceInput, InvoiceLabel } from 'people/utils/style'; +import { InvoiceForm, InvoiceInput, InvoiceInputContainer, InvoiceLabel } from 'people/utils/style'; import styled from 'styled-components'; import { BudgetButton } from 'people/widgetViews/workspace/style'; import { useStores } from 'store'; @@ -32,11 +32,41 @@ const InviteModal = (props: InviteProps) => { const { open, close, addToast } = props; const [loading, setLoading] = useState(false); const [inviteNumber, setInviteNumber] = useState(1); + const [satAmount, setSatAmount] = useState(1); + const [pubkey, setPubkey] = useState(''); const config = nonWidgetConfigs['workspaceusers']; + const parsePubkey = (pubkey: string): { parsedPubkey: string; routeHint: string } => { + if (pubkey) { + const result = pubkey.split('_'); + if (result.length === 3) { + return { parsedPubkey: result[0], routeHint: `${result[1]}_${result[2]}` }; + } + } + return { parsedPubkey: '', routeHint: '' }; + }; + const createConnectionCode = async () => { setLoading(true); - const status = await main.createConnectionCodes(inviteNumber); + let extractedPubkey = ''; + let parsedRouteHint = ''; + + if (pubkey) { + const {parsedPubkey, routeHint} = parsePubkey(pubkey); + if (!parsedPubkey && !routeHint) { + setLoading(false); + if (addToast) addToast('Invalid Pubkey', 'error'); + return; + } + extractedPubkey = parsedPubkey; + parsedRouteHint = routeHint; + } + + const status = await main.createConnectionCodes({ + users_number: inviteNumber, + sats_amount: satAmount, + ...(extractedPubkey && parsedRouteHint && { pubkey: extractedPubkey, route_hint: parsedRouteHint }) + }); if (status === 200) { if (addToast) addToast('Users invite code created successfully', 'success'); @@ -80,22 +110,61 @@ const InviteModal = (props: InviteProps) => { Invite Users - - Number of users - - setInviteNumber(Number(e.target.value))} - /> + + + Number of users + + setInviteNumber(Number(e.target.value))} + /> + + + + + Pubkey + + setPubkey(e.target.value)} + /> + + + + Sats Amount + + setSatAmount(Number(e.target.value))} + /> + { + async createConnectionCodes({ + users_number, + sats_amount, + pubkey, + route_hint + }: { + users_number: number; + sats_amount?: number; + pubkey?: string; + route_hint?: string; + }): Promise { try { if (!uiStore.meInfo) return 406; const info = uiStore.meInfo; const data = { - number: users_number + number: users_number, + pubkey: pubkey, + route_hint, + sats_amount }; const body = JSON.stringify(data); From b50ede3f6ebacf4ff98406b950369ec4b689fd09 Mon Sep 17 00:00:00 2001 From: Oluwatobi Bamidele Date: Thu, 12 Dec 2024 07:58:22 +0200 Subject: [PATCH 2/3] fix: fixed prettier --- src/pages/superadmin/header/InviteModal.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/superadmin/header/InviteModal.tsx b/src/pages/superadmin/header/InviteModal.tsx index 8c941222..0da8ffd7 100644 --- a/src/pages/superadmin/header/InviteModal.tsx +++ b/src/pages/superadmin/header/InviteModal.tsx @@ -52,7 +52,7 @@ const InviteModal = (props: InviteProps) => { let parsedRouteHint = ''; if (pubkey) { - const {parsedPubkey, routeHint} = parsePubkey(pubkey); + const { parsedPubkey, routeHint } = parsePubkey(pubkey); if (!parsedPubkey && !routeHint) { setLoading(false); if (addToast) addToast('Invalid Pubkey', 'error'); @@ -65,7 +65,8 @@ const InviteModal = (props: InviteProps) => { const status = await main.createConnectionCodes({ users_number: inviteNumber, sats_amount: satAmount, - ...(extractedPubkey && parsedRouteHint && { pubkey: extractedPubkey, route_hint: parsedRouteHint }) + ...(extractedPubkey && + parsedRouteHint && { pubkey: extractedPubkey, route_hint: parsedRouteHint }) }); if (status === 200) { From aa26f688d2c041cf72b8ec63071c8a1e3b3cc9d7 Mon Sep 17 00:00:00 2001 From: Oluwatobi Bamidele Date: Thu, 12 Dec 2024 21:14:07 +0100 Subject: [PATCH 3/3] fix: invite modal --- src/pages/superadmin/header/InviteModal.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/superadmin/header/InviteModal.tsx b/src/pages/superadmin/header/InviteModal.tsx index 0da8ffd7..9175d089 100644 --- a/src/pages/superadmin/header/InviteModal.tsx +++ b/src/pages/superadmin/header/InviteModal.tsx @@ -72,6 +72,8 @@ const InviteModal = (props: InviteProps) => { if (status === 200) { if (addToast) addToast('Users invite code created successfully', 'success'); setInviteNumber(1); + setPubkey(''); + setSatAmount(1); close(); } else { if (addToast) addToast('Could not create users invite code', 'error');