From fdd1bc000e78d7ac8b6b38f47c5925819651c159 Mon Sep 17 00:00:00 2001 From: Jordan Brookman Date: Sat, 7 May 2022 21:44:25 -0400 Subject: [PATCH 1/3] Fix icon for Notes & Tags --- frontend/src/routes/Receive.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/Receive.js b/frontend/src/routes/Receive.js index 92a42c1..c9bae78 100644 --- a/frontend/src/routes/Receive.js +++ b/frontend/src/routes/Receive.js @@ -1,4 +1,4 @@ -import {CaretDownIcon, ContactsIcon, CopyIcon, QrCodeIcon, ShareIcon} from "@bitcoin-design/bitcoin-icons-react/filled"; +import { CaretDownIcon, ContactsIcon, CopyIcon, EditIcon, QrCodeIcon, ShareIcon } from "@bitcoin-design/bitcoin-icons-react/filled"; import Button from "../components/Button"; import InputText from "../components/InputText"; @@ -28,7 +28,7 @@ const Receive = () => { -
+
From c6304d48b0c4483a356e08f90af6e084efe5336e Mon Sep 17 00:00:00 2001 From: Nick Chaloult Date: Sat, 7 May 2022 22:34:36 -0400 Subject: [PATCH 2/3] Add GET .../account/:username/permissions endpoint --- backend/api/account/accountController.js | 17 ++++++++++++++++- backend/api/account/accountService.js | 21 +++++++++++++++++++-- backend/api/account/index.js | 3 ++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/backend/api/account/accountController.js b/backend/api/account/accountController.js index f36a56a..7c35930 100644 --- a/backend/api/account/accountController.js +++ b/backend/api/account/accountController.js @@ -44,6 +44,21 @@ const getAccountBalance = async (req, res) => { } }; +const getAccountPermissions = async (req, res) => { + try { + // TODO: Input verification logic? + const accountName = req.params.username; + const response = await accountService.getAccountPermissions(accountName); + debug.info(`Response for getting an account's permissions: ${JSON.stringify(response)}`); + + if (!response.success) res.status(500).json(response); + else res.status(200).json(response); + } catch (error) { + debug.error(error.stack); + res.status(500).json({ message: error.message, error: error.stack }); + } +}; + const createInvoice = async (req, res) => { try { const amountMillisats = req.body.amountMillisats; @@ -58,4 +73,4 @@ const createInvoice = async (req, res) => { } }; -module.exports = { getAccountAllowance, payInvoice, createInvoice, getAccountBalance }; +module.exports = { getAccountAllowance, payInvoice, createInvoice, getAccountBalance, getAccountPermissions }; diff --git a/backend/api/account/accountService.js b/backend/api/account/accountService.js index 16c000a..43c6b5c 100644 --- a/backend/api/account/accountService.js +++ b/backend/api/account/accountService.js @@ -1,6 +1,9 @@ const debug = require('../../utils/debug'); const senseiNodes = require('../../sensei/nodes'); -const accounts = require('../../db/collection'); +const collection = require('../../db/collection'); + +const DOC_NAME = 'nicks-family'; +const MEMBERS_SUBCOLLECTION_NAME = 'members'; const getAccountAllowance = async (username) => { try { @@ -22,6 +25,20 @@ const getAccountBalance = async () => { } }; +const getAccountPermissions = async (accountName) => { + const docRef = await collection.doc(DOC_NAME).collection(MEMBERS_SUBCOLLECTION_NAME).doc(accountName); + const doc = await docRef.get(); + if (!doc.exists) { + const errMsg = `Firestore document "${docName}/${subcollectionName}/${accountName}" does not exist in the families collection`; + debug.error(errMsg); + throw new Error(errMsg); + } + + // TODO: Error handling? + const permissions = doc.data().permissions; + return { success: true, permissions }; +}; + const payInvoice = async (invoice) => { try { const response = await senseiNodes.payInvoice(invoice); @@ -42,4 +59,4 @@ const createInvoice = async (amountMillisats, description) => { } }; -module.exports = { getAccountAllowance, payInvoice, createInvoice, getAccountBalance }; +module.exports = { getAccountAllowance, payInvoice, createInvoice, getAccountBalance, getAccountPermissions }; diff --git a/backend/api/account/index.js b/backend/api/account/index.js index 98ac1ff..c1d2802 100644 --- a/backend/api/account/index.js +++ b/backend/api/account/index.js @@ -1,9 +1,10 @@ const express = require('express'); const router = express(); -const { getAccountAllowance, payInvoice, createInvoice, getAccountBalance } = require('./accountController'); +const { getAccountAllowance, payInvoice, createInvoice, getAccountBalance, getAccountPermissions } = require('./accountController'); router.get('/account/balance', getAccountBalance); +router.get('/:username/permissions', getAccountPermissions); router.get('/allowance', getAccountAllowance); router.get('/payment/send', payInvoice); router.get('/payment/receive', createInvoice); From 242a1a84f49e9fffbbaab6b003ae488fca947fed Mon Sep 17 00:00:00 2001 From: Nick Chaloult Date: Sat, 7 May 2022 22:38:25 -0400 Subject: [PATCH 3/3] Add GET .../account/:username/allowance endpoint --- backend/api/account/accountController.js | 9 +++++---- backend/api/account/accountService.js | 19 ++++++++++++------- backend/api/account/index.js | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/backend/api/account/accountController.js b/backend/api/account/accountController.js index 7c35930..074f6f1 100644 --- a/backend/api/account/accountController.js +++ b/backend/api/account/accountController.js @@ -3,12 +3,13 @@ const accountService = require('./accountService'); const getAccountAllowance = async (req, res) => { try { - const username = req.body.username; - const response = await accountService.getAccountAllowance(username); - debug.info(`Account Allowance Response: ${JSON.stringify(response)}`); + // TODO: Input verification logic? + const accountName = req.params.username; + const response = await accountService.getAccountAllowance(accountName); + debug.info(`Response for getting an account's allowance: ${JSON.stringify(response)}`); + if (!response.success) res.status(500).json(response); else res.status(200).json(response); - } catch (error) { debug.error(error.stack); res.status(500).json({ message: error.message, error: error.stack }); diff --git a/backend/api/account/accountService.js b/backend/api/account/accountService.js index 43c6b5c..636ab81 100644 --- a/backend/api/account/accountService.js +++ b/backend/api/account/accountService.js @@ -5,14 +5,19 @@ const collection = require('../../db/collection'); const DOC_NAME = 'nicks-family'; const MEMBERS_SUBCOLLECTION_NAME = 'members'; -const getAccountAllowance = async (username) => { - try { - // get allowance from firestore - return { success: true, message: nodes }; - } catch (error) { - debug.error(error.stack); - throw new Error(error); +const getAccountAllowance = async (accountName) => { + const docRef = await collection.doc(DOC_NAME).collection(MEMBERS_SUBCOLLECTION_NAME).doc(accountName); + const doc = await docRef.get(); + if (!doc.exists) { + const errMsg = `Firestore document "${docName}/${subcollectionName}/${accountName}" does not exist in the families collection`; + debug.error(errMsg); + throw new Error(errMsg); } + + // TODO: Error handling? + const allowance = doc.data().allowance; + return { success: true, allowance }; + }; const getAccountBalance = async () => { diff --git a/backend/api/account/index.js b/backend/api/account/index.js index c1d2802..c8de08a 100644 --- a/backend/api/account/index.js +++ b/backend/api/account/index.js @@ -5,7 +5,7 @@ const { getAccountAllowance, payInvoice, createInvoice, getAccountBalance, getAc router.get('/account/balance', getAccountBalance); router.get('/:username/permissions', getAccountPermissions); -router.get('/allowance', getAccountAllowance); +router.get('/:username/allowance', getAccountAllowance); router.get('/payment/send', payInvoice); router.get('/payment/receive', createInvoice);