Skip to content

Commit

Permalink
fix: Organize Plaid env variables for development and sandbox envs (#480
Browse files Browse the repository at this point in the history
)
  • Loading branch information
abouolia authored Jun 3, 2024
1 parent 7c06c8b commit 175bc24
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 227 deletions.
5 changes: 1 addition & 4 deletions packages/server/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,7 @@ module.exports = {
plaid: {
env: process.env.PLAID_ENV || 'sandbox',
clientId: process.env.PLAID_CLIENT_ID,
secretDevelopment: process.env.PLAID_SECRET_DEVELOPMENT,
secretSandbox: process.env.PLAID_SECRET_SANDBOX,
redirectSandBox: process.env.PLAID_SANDBOX_REDIRECT_URI,
redirectDevelopment: process.env.PLAID_DEVELOPMENT_REDIRECT_URI,
secret: process.env.PLAID_SECRET,
linkWebhook: process.env.PLAID_LINK_WEBHOOK,
},

Expand Down
5 changes: 1 addition & 4 deletions packages/server/src/lib/Plaid/Plaid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ export class PlaidClientWrapper {
baseOptions: {
headers: {
'PLAID-CLIENT-ID': config.plaid.clientId,
'PLAID-SECRET':
config.plaid.env === 'development'
? config.plaid.secretDevelopment
: config.plaid.secretSandbox,
'PLAID-SECRET': config.plaid.secret,
'Plaid-Version': '2020-09-14',
},
},
Expand Down
4 changes: 0 additions & 4 deletions packages/webapp/src/components/DialogsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import InvoiceMailDialog from '@/containers/Sales/Invoices/InvoiceMailDialog/Inv
import EstimateMailDialog from '@/containers/Sales/Estimates/EstimateMailDialog/EstimateMailDialog';
import ReceiptMailDialog from '@/containers/Sales/Receipts/ReceiptMailDialog/ReceiptMailDialog';
import PaymentMailDialog from '@/containers/Sales/PaymentReceives/PaymentMailDialog/PaymentMailDialog';
import { ConnectBankDialog } from '@/containers/CashFlow/ConnectBankDialog';
import { ExportDialog } from '@/containers/Dialogs/ExportDialog';

/**
Expand Down Expand Up @@ -97,7 +96,6 @@ export default function DialogsContainer() {
<NotifyPaymentReceiveViaSMSDialog
dialogName={DialogsName.NotifyPaymentViaForm}
/>

<BadDebtDialog dialogName={DialogsName.BadDebtForm} />
<SMSMessageDialog dialogName={DialogsName.SMSMessageForm} />
<RefundCreditNoteDialog dialogName={DialogsName.RefundCreditNote} />
Expand Down Expand Up @@ -148,8 +146,6 @@ export default function DialogsContainer() {
<EstimateMailDialog dialogName={DialogsName.EstimateMail} />
<ReceiptMailDialog dialogName={DialogsName.ReceiptMail} />
<PaymentMailDialog dialogName={DialogsName.PaymentMail} />
<ConnectBankDialog dialogName={DialogsName.ConnectBankCreditCard} />

<ExportDialog dialogName={DialogsName.Export} />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
FeatureCan,
} from '@/components';
import { useRefreshCashflowAccounts } from '@/hooks/query';
import { useOpenPlaidConnect } from '@/hooks/utils/useOpenPlaidConnect';
import { CashflowAction, AbilitySubject } from '@/constants/abilityOption';

import withDialogActions from '@/containers/Dialog/withDialogActions';
Expand All @@ -39,6 +40,9 @@ function CashFlowAccountsActionsBar({
}) {
const { refresh } = useRefreshCashflowAccounts();

// Opens the Plaid popup.
const { openPlaidAsync, isPlaidLoading } = useOpenPlaidConnect();

// Handle refresh button click.
const handleRefreshBtnClick = () => {
refresh();
Expand All @@ -64,7 +68,7 @@ function CashFlowAccountsActionsBar({
};
// Handle connect button click.
const handleConnectToBank = () => {
openDialog(DialogsName.ConnectBankCreditCard);
openPlaidAsync();
};

return (
Expand Down Expand Up @@ -116,6 +120,7 @@ function CashFlowAccountsActionsBar({
className={Classes.MINIMAL}
text={'Connect to Bank / Credit Card'}
onClick={handleConnectToBank}
disabled={isPlaidLoading}
/>
<NavbarDivider />
</FeatureCan>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 25 additions & 0 deletions packages/webapp/src/hooks/utils/useOpenPlaidConnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useCallback } from 'react';
import { useSetBankingPlaidToken } from '../state/banking';
import { AppToaster } from '@/components';
import { useGetPlaidLinkToken } from '../query';
import { Intent } from '@blueprintjs/core';

export const useOpenPlaidConnect = () => {
const { mutateAsync: getPlaidLinkToken, isLoading } = useGetPlaidLinkToken();
const setPlaidId = useSetBankingPlaidToken();

const openPlaidAsync = useCallback(() => {
return getPlaidLinkToken()
.then((res) => {
setPlaidId(res.data.link_token);
})
.catch(() => {
AppToaster.show({
message: 'Something went wrong.',
intent: Intent.DANGER,
});
});
}, [getPlaidLinkToken, setPlaidId]);

return { openPlaidAsync, isPlaidLoading: isLoading };
};

0 comments on commit 175bc24

Please sign in to comment.