Skip to content

Commit

Permalink
Added reset method
Browse files Browse the repository at this point in the history
Added way to know if accounts request received 401
Enabled storage of token only when checkbox is checked.
  • Loading branch information
Korey Sedaghatian committed May 4, 2024
1 parent eb798b4 commit c01c96a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Note: These instructions are for a docker installation but should hopefully be c
9. Browse to the application: `https://<your FF3 domain>/ofx` and you should be prompted to input a token.
10. (Optional) You can bookmark or add this URL to whatever dashboard you are using for future use.
11. Enter you PAT into the text box and hit the tab key.\
Note: Right now the checkbox below the input field does not work but a future version will allow you not to store the token locally (i.e. you would have to enter the token each time you use the app if you do not save it).
Note: If you do not want to enter your PAT each time, make sure to check `Store token for next time`.
12. You should be ready to drop an OFX file and get importing.


Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ff3-ofx",
"version": "0.4.2",
"version": "0.5.0",
"homepage": "./",
"private": true,
"licenses": [
Expand All @@ -19,8 +19,10 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"axios": "^1.6.8",
"moment": "^2.30.1",
"mui-file-dropzone": "^4.0.2",
"ofx-data-extractor": "^1.3.4",
"node-ofx-parser": "^0.5.1",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -34,7 +36,7 @@
"package": "yarn compile && yarn dist",
"test": "react-scripts test",
"eject": "react-scripts eject",
"clean": "rm -rf ./node_modules ./build/*"
"clean": "rm -rf ./node_modules ./build"
},
"eslintConfig": {
"extends": [
Expand Down
17 changes: 10 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ function App() {
setAccounts(accntResponse);
// If we got accounts back, then store the token
if (currentToken && currentToken.value) {
localStorage.setItem('token', JSON.stringify(currentToken));
if ((document.getElementById('chkStoreToken') as HTMLInputElement)?.checked) { // Only store the token if user requested
localStorage.setItem('token', JSON.stringify(currentToken));
}
setToken(currentToken);
}
} else {
} else if (accntResponse === null) { // If the response is null, that means we got an unauthorized response
// Delete localstorage
// localStorage.removeItem('token');
// if (currentToken && (!token || !token.value)) {
// setToken(undefined);
// }
localStorage.removeItem('token');
if (currentToken && (!token || !token.value)) {
setToken(undefined);
}
ApiService.reset();
}
}).catch(e => {
console.log('could not get accounts', e);
Expand Down Expand Up @@ -385,7 +388,7 @@ function App() {
}}
/>
<br/>
<FormControlLabel control={<Checkbox defaultChecked />} label="Store Token for next time" />
<FormControlLabel control={<Checkbox id={'chkStoreToken'} />} label="Store Token for next time" />
</Box>
</Collapse>
<Collapse in={!!token && showFileDrop}>
Expand Down
27 changes: 19 additions & 8 deletions src/lib/apiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const exceptionHandling = {

let myHttpClient: AxiosInstance | undefined;

const reset = () => {
myHttpClient = undefined;
}

const getHttp = (token?: string| null) => {
if (token === null) {
myHttpClient = undefined;
Expand All @@ -31,9 +35,11 @@ const getHttp = (token?: string| null) => {
return myHttpClient;
}

const getAccounts = async(currentToken?: string): Promise<FF3Wrapper<FF3Account>[]> => {
// This is useful for debugging request/response
// http.interceptors.request.use(
const getAccounts = async(currentToken?: string): Promise<FF3Wrapper<FF3Account>[] | null> => {
const http = getHttp(currentToken);

// // This is useful for debugging request/response
// http?.interceptors.request.use(
// request => {
// console.log('Starting Request', JSON.stringify(request, null, 2));
// return request;
Expand All @@ -43,7 +49,7 @@ const getAccounts = async(currentToken?: string): Promise<FF3Wrapper<FF3Account>
// return Promise.reject(error);
// },
// );
// http.interceptors.response.use(
// http?.interceptors.response.use(
// response => {
// console.log('Receiving Response', JSON.stringify(response, null, 2));
// return response;
Expand All @@ -53,11 +59,15 @@ const getAccounts = async(currentToken?: string): Promise<FF3Wrapper<FF3Account>
// return Promise.reject(error);
// },
// );
const http = getHttp(currentToken);

const response = await http?.get('/accounts', exceptionHandling);
if (response && response.status === 200 && response.data.data) {
return response.data.data;
}
if (response && response.status) {
if (response.status === 200 && response.data.data) {
return response.data.data;
} else if (response.status === 401) {
return null;
}
}

// Return an empty array otherwise
return [];
Expand Down Expand Up @@ -121,6 +131,7 @@ const addTransaction = async (txn: FF3AddTransactionWrapper<FF3TransactionSplit>
};

const ApiService = {
reset,
getHttp,
getAccounts,
getAccount,
Expand Down
84 changes: 76 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4339,6 +4339,17 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.6.8":
version: 1.6.8
resolution: "axios@npm:1.6.8"
dependencies:
follow-redirects: "npm:^1.15.6"
form-data: "npm:^4.0.0"
proxy-from-env: "npm:^1.1.0"
checksum: 10c0/0f22da6f490335479a89878bc7d5a1419484fbb437b564a80c34888fc36759ae4f56ea28d55a191695e5ed327f0bad56e7ff60fb6770c14d1be6501505d47ab9
languageName: node
linkType: hard

"axobject-query@npm:^3.2.1":
version: 3.2.1
resolution: "axobject-query@npm:3.2.1"
Expand Down Expand Up @@ -6737,6 +6748,17 @@ __metadata:
languageName: node
linkType: hard

"fast-xml-parser@npm:^3.18.0":
version: 3.21.1
resolution: "fast-xml-parser@npm:3.21.1"
dependencies:
strnum: "npm:^1.0.4"
bin:
xml2js: cli.js
checksum: 10c0/26ed57fd3cb86434959cffa6852ab63231850ff5be6836aef7744b1abc8013fa5696c05179e422965677e116606611242d91ceebf246d91a5247e262d8b59996
languageName: node
linkType: hard

"fastq@npm:^1.6.0":
version: 1.17.0
resolution: "fastq@npm:1.17.0"
Expand Down Expand Up @@ -6778,9 +6800,11 @@ __metadata:
"@testing-library/jest-dom": "npm:^5.14.1"
"@testing-library/react": "npm:^13.0.0"
"@testing-library/user-event": "npm:^13.2.1"
axios: "npm:^1.6.8"
eslint: "npm:^8.18.0"
moment: "npm:^2.30.1"
mui-file-dropzone: "npm:^4.0.2"
ofx-data-extractor: "npm:^1.3.4"
node-ofx-parser: "npm:^0.5.1"
prop-types: "npm:^15.8.1"
react: "npm:^18.2.0"
react-dom: "npm:^18.2.0"
Expand Down Expand Up @@ -6935,6 +6959,16 @@ __metadata:
languageName: node
linkType: hard

"follow-redirects@npm:^1.15.6":
version: 1.15.6
resolution: "follow-redirects@npm:1.15.6"
peerDependenciesMeta:
debug:
optional: true
checksum: 10c0/9ff767f0d7be6aa6870c82ac79cf0368cd73e01bbc00e9eb1c2a16fbb198ec105e3c9b6628bb98e9f3ac66fe29a957b9645bcb9a490bb7aa0d35f908b6b85071
languageName: node
linkType: hard

"for-each@npm:^0.3.3":
version: 0.3.3
resolution: "for-each@npm:0.3.3"
Expand Down Expand Up @@ -6996,6 +7030,17 @@ __metadata:
languageName: node
linkType: hard

"form-data@npm:^4.0.0":
version: 4.0.0
resolution: "form-data@npm:4.0.0"
dependencies:
asynckit: "npm:^0.4.0"
combined-stream: "npm:^1.0.8"
mime-types: "npm:^2.1.12"
checksum: 10c0/cb6f3ac49180be03ff07ba3ff125f9eba2ff0b277fb33c7fc47569fc5e616882c5b1c69b9904c4c4187e97dd0419dd03b134174756f296dec62041e6527e2c6e
languageName: node
linkType: hard

"forwarded@npm:0.2.0":
version: 0.2.0
resolution: "forwarded@npm:0.2.0"
Expand Down Expand Up @@ -9666,6 +9711,13 @@ __metadata:
languageName: node
linkType: hard

"moment@npm:^2.30.1":
version: 2.30.1
resolution: "moment@npm:2.30.1"
checksum: 10c0/865e4279418c6de666fca7786607705fd0189d8a7b7624e2e56be99290ac846f90878a6f602e34b4e0455c549b85385b1baf9966845962b313699e7cb847543a
languageName: node
linkType: hard

"ms@npm:2.0.0":
version: 2.0.0
resolution: "ms@npm:2.0.0"
Expand Down Expand Up @@ -9808,6 +9860,15 @@ __metadata:
languageName: node
linkType: hard

"node-ofx-parser@npm:^0.5.1":
version: 0.5.1
resolution: "node-ofx-parser@npm:0.5.1"
dependencies:
fast-xml-parser: "npm:^3.18.0"
checksum: 10c0/96a8427bdc3895c03e928341d572ff2eb26a7389fa92b6fe250d0a63dc1d178fbff3f4dff94cf5bddf5a28ead8e109b0c79ecba47152295a69a4df77a0e5dd91
languageName: node
linkType: hard

"node-releases@npm:^2.0.14":
version: 2.0.14
resolution: "node-releases@npm:2.0.14"
Expand Down Expand Up @@ -10006,13 +10067,6 @@ __metadata:
languageName: node
linkType: hard

"ofx-data-extractor@npm:^1.3.4":
version: 1.3.4
resolution: "ofx-data-extractor@npm:1.3.4"
checksum: 10c0/7acc4bc5bb734c280fd86b43e2cc2c471c306f5cc02a3e39c50eb701eca0a7d01122911df90144c606d56dcedc9b6ca4dc7ede157d67ad5a80c53b458f9f81f5
languageName: node
linkType: hard

"on-finished@npm:2.4.1":
version: 2.4.1
resolution: "on-finished@npm:2.4.1"
Expand Down Expand Up @@ -11301,6 +11355,13 @@ __metadata:
languageName: node
linkType: hard

"proxy-from-env@npm:^1.1.0":
version: 1.1.0
resolution: "proxy-from-env@npm:1.1.0"
checksum: 10c0/fe7dd8b1bdbbbea18d1459107729c3e4a2243ca870d26d34c2c1bcd3e4425b7bcc5112362df2d93cc7fb9746f6142b5e272fd1cc5c86ddf8580175186f6ad42b
languageName: node
linkType: hard

"psl@npm:^1.1.33":
version: 1.9.0
resolution: "psl@npm:1.9.0"
Expand Down Expand Up @@ -12715,6 +12776,13 @@ __metadata:
languageName: node
linkType: hard

"strnum@npm:^1.0.4":
version: 1.0.5
resolution: "strnum@npm:1.0.5"
checksum: 10c0/64fb8cc2effbd585a6821faa73ad97d4b553c8927e49086a162ffd2cc818787643390b89d567460a8e74300148d11ac052e21c921ef2049f2987f4b1b89a7ff1
languageName: node
linkType: hard

"style-loader@npm:^3.3.1":
version: 3.3.4
resolution: "style-loader@npm:3.3.4"
Expand Down

0 comments on commit c01c96a

Please sign in to comment.