diff --git a/.env b/.env index 0e41d3e..9160df6 100644 --- a/.env +++ b/.env @@ -1 +1,3 @@ -PORT = 3000 \ No newline at end of file +PORT = 3000 +REACT_APP_VERSION = $npm_package_version +REACT_APP_NAME = $npm_package_name \ No newline at end of file diff --git a/package.json b/package.json index e1216ad..ab84f7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ff3-ofx", - "version": "0.7.0", + "version": "0.7.1", "homepage": "./", "private": true, "licenses": [ diff --git a/src/App.tsx b/src/App.tsx index 9a03d8b..0ea5158 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,7 +7,7 @@ import { FF3Account, FF3AddTransactionWrapper, FF3Error, FF3TransactionSplit, FF import Button from '@mui/material/Button'; import RefreshIcon from '@mui/icons-material/Refresh'; import CheckIcon from '@mui/icons-material/Check'; -import { Box, Checkbox, Collapse, FormControlLabel, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, Typography } from '@mui/material'; +import { Alert, Box, Checkbox, Collapse, FormControlLabel, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, Typography } from '@mui/material'; import FileDrop from 'components/FileDrop'; import * as OFXParser from 'node-ofx-parser'; import Summary from 'components/Summary'; @@ -48,6 +48,17 @@ function App() { // The current progress for the transactions being processed const [showFileDrop, setShowFileDrop] = useState(true); const [errorMessage, setErrorMessage] = useState(''); + // Set to true if an update is available + const [updateAvailable, setUpdateAvailable] = useState(false); + + const checkForUpdates = useCallback(async () => { + const myVersion = `${process.env.REACT_APP_VERSION}`; + const latestVersion = await ApiService.getLatestVersion(); + if (myVersion !== latestVersion?.substring(1)) { + console.error('THERE IS A NEW VERSION OUT', myVersion, latestVersion); + setUpdateAvailable(true); + } + }, []); /** * Fetch the list of accounts @@ -404,11 +415,20 @@ function App() { } }, [accounts, init]); + useEffect(() => { + checkForUpdates(); + }, [checkForUpdates]); + const bankBalance: number = ofxData ? parseFloat(parseFloat('' + ofxData.balance).toFixed(2)) : 0; return (
+ {updateAvailable && ( + + You are currently running {process.env.REACT_APP_NAME} version {process.env.REACT_APP_VERSION}. There is a new version available here. + + )}
@@ -449,7 +469,7 @@ function App() { - + Account Number: {ofxData?.accountNumber}, Account Type: {ofxData?.accountType}, Org: {ofxData?.org}, Bank: {bankName} ({ofxData?.intuitId}) diff --git a/src/lib/apiService.ts b/src/lib/apiService.ts index 6856b2a..3f9e5d6 100644 --- a/src/lib/apiService.ts +++ b/src/lib/apiService.ts @@ -17,11 +17,12 @@ const reset = () => { myHttpClient = undefined; } -const getHttp = (token?: string| null) => { +const getHttp = (token?: string| null, url?: string | null) => { if (token === null) { - myHttpClient = undefined; - } else if (!myHttpClient && token) { + reset(); + } else if (token) { console.info('Creating http client...'); + reset(); myHttpClient = axios.create({ baseURL: BASE_URL, headers: { @@ -30,11 +31,41 @@ const getHttp = (token?: string| null) => { 'Authorization': `Bearer ${token}` }, }); + } else if (!!url) { + reset(); + myHttpClient = axios.create({ + baseURL: url, + headers: { + 'Content-type': 'application/json', + 'Accept': 'application/json' + }, + }); } return myHttpClient; } +const getLatestVersion = async(): Promise => { + const response = await axios.get('https://api.github.com/repos/pelaxa/ff3-ofx/tags',{ + headers: { + 'Content-type': 'application/json', + 'Accept': 'application/json' + }, + ...exceptionHandling + } ); + + if (response && response.status) { + if (response.status === 200 && response.data.length > 0) { + console.info('tags', response.data); + return response.data[0].name; // latest tag is on top + } + } + + // Return null + return null; + +} + const getAccounts = async(currentToken?: string): Promise[] | null> => { const http = getHttp(currentToken); @@ -138,6 +169,7 @@ const ApiService = { getTransactions, getAccountTransactions, addTransaction, + getLatestVersion, }; export default ApiService;