Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
sbddesign committed May 8, 2022
2 parents 131453d + 242a1a8 commit 704aeae
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
26 changes: 21 additions & 5 deletions backend/api/account/accountController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -44,6 +45,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;
Expand All @@ -58,4 +74,4 @@ const createInvoice = async (req, res) => {
}
};

module.exports = { getAccountAllowance, payInvoice, createInvoice, getAccountBalance };
module.exports = { getAccountAllowance, payInvoice, createInvoice, getAccountBalance, getAccountPermissions };
40 changes: 31 additions & 9 deletions backend/api/account/accountService.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
const debug = require('../../utils/debug');
const senseiNodes = require('../../sensei/nodes');
const accounts = require('../../db/collection');
const collection = require('../../db/collection');

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 DOC_NAME = 'nicks-family';
const MEMBERS_SUBCOLLECTION_NAME = 'members';

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 () => {
Expand All @@ -22,6 +30,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);
Expand All @@ -42,4 +64,4 @@ const createInvoice = async (amountMillisats, description) => {
}
};

module.exports = { getAccountAllowance, payInvoice, createInvoice, getAccountBalance };
module.exports = { getAccountAllowance, payInvoice, createInvoice, getAccountBalance, getAccountPermissions };
5 changes: 3 additions & 2 deletions backend/api/account/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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('/allowance', getAccountAllowance);
router.get('/:username/permissions', getAccountPermissions);
router.get('/:username/allowance', getAccountAllowance);
router.get('/payment/send', payInvoice);
router.get('/payment/receive', createInvoice);

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/routes/Receive.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -28,7 +28,7 @@ const Receive = () => {
</div>
</div>

<div className="flex justify-around align-center mt-1">
<div className="flex justify-around align-center mt-2">
<div>
<Button style="free" size="small">
<ContactsIcon width="32" height="32" />
Expand All @@ -37,7 +37,7 @@ const Receive = () => {
</div>
<div>
<Button style="free" size="small">
<CopyIcon width="32" height="32" />
<EditIcon width="32" height="32" />
<div className="text-sm">Notes & Tags</div>
</Button>
</div>
Expand Down

0 comments on commit 704aeae

Please sign in to comment.