diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index eb8c65a..4fe7842 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -34,6 +34,23 @@ setTimeout(() => { ); }, 1000); + +setTimeout(() => { + window.dispatchEvent( + new MessageEvent("message", { + data: { + app: "BANK", + method: "setCredentials", + data: + { + name: "Firstname Lastname", + balance: 2000 + } + }, + }) + ); +}, 1000); + setTimeout(() => { window.dispatchEvent( new MessageEvent("message", { @@ -44,13 +61,43 @@ setTimeout(() => { { id: 1, amount: 200, - type: 'transfer' + type: 'Deposit', + source: "chip" + },{ + id: 2, + amount: 200, + type: 'Withdraw', + source: "chip" + }, + { + id: 3, + amount: 200, + type: 'Withdraw', + source: "chip" + }, + { + id: 4, + amount: 50, + type: 'Deposit', + source: "chip" + }, + { + id: 4, + amount: 50, + type: 'Deposit', + source: "chip" + }, + { + id: 4, + amount: 50, + type: 'Deposit', + source: "chip" } ] } }) ) -}) +}, 1000) setTimeout(() => { window.dispatchEvent( diff --git a/phone/src/apps/bank/components/BankApp.css b/phone/src/apps/bank/components/BankApp.css index 648c400..64993ad 100644 --- a/phone/src/apps/bank/components/BankApp.css +++ b/phone/src/apps/bank/components/BankApp.css @@ -1 +1,45 @@ @import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap"); + +/* #### Generated By: http://www.cufonfonts.com #### */ + +@font-face { + font-family: 'Bahnschrift Regular'; + font-style: normal; + font-weight: normal; + src: local('Bahnschrift Regular'), url('../fonts/BAHNSCHRIFT.woff') format('woff'); + } + +#account-section, #transaction-section { + font-family: 'Bahnschrift Regular' +} + +#transaction-section .MuiTablePagination-root { + font-size: 15px; +} + +#transaction-section .MuiTablePagination-caption { + font-size: 15px; + font-family: 'Bahnschrift Regular'; +} + +#transaction-section .MuiTablePagination-actions { + font-size: 50px; +} + + +#bank-app .Mui-selected { + color: #388CF8 !important; +} + +#bank-title { + font-family: 'Bebas Neue', cursive; + font-size: 50px; +} + +.card-name { + font-size: 20px; +} + +#actionButton a { + color: #fff; +} \ No newline at end of file diff --git a/phone/src/apps/bank/components/BankApp.tsx b/phone/src/apps/bank/components/BankApp.tsx index 58a3d81..cfc38c9 100644 --- a/phone/src/apps/bank/components/BankApp.tsx +++ b/phone/src/apps/bank/components/BankApp.tsx @@ -1,19 +1,26 @@ import React from "react"; -import { makeStyles } from "@material-ui/core"; -import { BankTitle } from './BankTitle'; +import { makeStyles, Paper, Typography } from "@material-ui/core"; +import { BankTitle } from "./BankTitle"; import { AppWrapper } from "../../../ui/components"; import { AppContent } from "../../../ui/components/AppContent"; import { Button } from "../../../ui/components/Button"; import { useTranslation } from "react-i18next"; import { useTransactions } from "../hooks/useTransactions"; -import { TransactionList } from './transactions/TransactionList'; import "./BankApp.css"; -import { useApp } from "../../../os/apps/hooks/useApps"; -import { TransferModal } from './transfers/TransferModal'; +import { TransferModal } from "./transfers/TransferModal"; -import { useBankModal } from '../hooks/useBankModal'; -import { useModal } from "../../twitter/hooks/useModal"; +import { useBankModal } from "../hooks/useBankModal"; +import { useCredentials } from "../hooks/useCredentials"; +import { Switch, Route } from "react-router-dom"; + +// image +import CreditCard from '../img/credit-card.png' +import { NavigationBar } from "./navigation/NavigationBar"; + +import { BankHome } from './home/BankHome'; +import { BankAccount } from './account/BankAccount'; +import { TransactionList } from "./transactions/TransactionList"; const useStyles = makeStyles((theme) => ({ root: { @@ -41,29 +48,27 @@ const useStyles = makeStyles((theme) => ({ })); export const BankApp = () => { - - const { showBankModal, setShowBankModal } = useBankModal() - - const { transactionList } = useTransactions(); + const { showBankModal, setShowBankModal } = useBankModal(); const { t } = useTranslation(); const classes = useStyles(); - const openTransactionsModal = () => { - setShowBankModal(true) - } + setShowBankModal(true); + }; return ( - +
-
- -
- + + + + +
+ ); }; diff --git a/phone/src/apps/bank/components/BankTitle.tsx b/phone/src/apps/bank/components/BankTitle.tsx index e70dfee..9697a7a 100644 --- a/phone/src/apps/bank/components/BankTitle.tsx +++ b/phone/src/apps/bank/components/BankTitle.tsx @@ -3,11 +3,13 @@ import Paper from "@material-ui/core/Paper"; import { Typography ,makeStyles } from "@material-ui/core"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import './BankApp.css' + const useStyles = makeStyles((theme) => ({ root: { height: "90px", width: "100%", - display: "block", + display: "flex", margin: 0, justifyContent: "center", alignItems: "center", @@ -24,10 +26,7 @@ export const BankTitle = () => { const classes = useStyles(); return ( - WhoDis Banking - - - Some player name + WhoDis Banking ); }; diff --git a/phone/src/apps/bank/components/account/AccountTransactions.tsx b/phone/src/apps/bank/components/account/AccountTransactions.tsx new file mode 100644 index 0000000..3f0e8aa --- /dev/null +++ b/phone/src/apps/bank/components/account/AccountTransactions.tsx @@ -0,0 +1,104 @@ +import React from "react"; +import { useTranslation } from "react-i18next"; +import { makeStyles, Paper, Typography, Button } from "@material-ui/core"; +import { useTransactions } from "../../hooks/useTransactions"; +import { red } from "@material-ui/core/colors"; +const useStyles = makeStyles((theme) => ({ + root: { + width: "100%", + }, + header: { + width: "90%", + display: "flex", + justifyItems: "center", + justifyContent: "space-between", + margin: "auto", + }, + title: { + padding: 7, + borderRadius: "10px", + display: "flex", + justifyItems: "center", + justifyContent: "center", + fontSize: "24px", + }, + seeAll: { + fontFamily: "Bahnschrift Regular", + fontWeight: "bold", + height: 'auto' + }, + transcationDiv: { + marginTop: '-30px', + }, + transactions: { + marginLeft: "32px", + display: "flex", + justifyContent: "space-between", + borderBottom: "2px solid #707070", + width: "85%", + margin: "auto", + }, + tranSource: { + fontSize: "22px", + }, + tranType: { + fontSize: "18px", + fontWeight: "bold", + color: "#BFBFBF", + marginTop: "-18px", + width: "100%", + }, + + depositType: { + color: "#55B452", + marginRight: "32px", + fontSize: "22px", + fontWeight: "bold", + }, + withdrawType: { + color: "#FF5E5E", + marginRight: "32px", + fontSize: "22px", + fontWeight: "bold", + }, +})); + +export const AccountTransactions = (): any => { + const classes = useStyles(); + + const TransactionTypes = { + Deposit: classes.depositType, + Withdraw: classes.withdrawType, + Transfer: classes.depositType + }; + + const { transactionList } = useTransactions(); + const { t } = useTranslation(); + return ( +
+
+

{t("APPS_BANK_ACCOUNT_TRANSACTIONS")}

+ +
+ +
+ {transactionList.slice(0, 3).map((transaction: any) => ( +
+
+

{transaction.source}

+

{transaction.type}

+
+
+

+ {transaction.type == "Withdraw" ? "-" : "+"} + {transaction.amount} +

+
+
+ ))} +
+
+ ); +}; diff --git a/phone/src/apps/bank/components/account/BankAccount.tsx b/phone/src/apps/bank/components/account/BankAccount.tsx new file mode 100644 index 0000000..7531b6a --- /dev/null +++ b/phone/src/apps/bank/components/account/BankAccount.tsx @@ -0,0 +1,33 @@ +import React from 'react' +import { Button } from "../../../../ui/components/Button"; +import { makeStyles, Paper, Typography } from "@material-ui/core"; +import { useTranslation } from "react-i18next"; +import { BankCard } from './BankCard'; +import { AccountTransactions } from './AccountTransactions'; +import { useCredentials } from '../../hooks/useCredentials'; + +const useStyles = makeStyles((theme) => ({ + root: { + width: '100%', + fontFamily: 'Bahnschrift Regular' + }, + title: { + fontSize: '30px', + marginLeft: '29px' + } +})) + +export const BankAccount = () => { + const classes = useStyles(); + const { credentials } = useCredentials(); + const { t } = useTranslation(); + return ( +
+
+

{t("APPS_BANK_ACCOUNT_TITLE")}

+
+ + +
+ ) +} diff --git a/phone/src/apps/bank/components/account/BankCard.tsx b/phone/src/apps/bank/components/account/BankCard.tsx new file mode 100644 index 0000000..58b84af --- /dev/null +++ b/phone/src/apps/bank/components/account/BankCard.tsx @@ -0,0 +1,58 @@ +import React from 'react' +import { makeStyles, Box, Typography } from "@material-ui/core"; +import { shadows } from '@material-ui/system'; + + /* + overflow: hidden; + text-overflow: ellipsis; + word-wrap: break-word; + display: block; + line-height: 1em; + max-height: 2em; */ + +const useStyles = makeStyles((theme) => ({ + root: { + background: '#388CF8', + height: '179px', + width: '350px', + margin: 'auto', + borderRadius: '15px', + fontFamily: 'Bahnschrift Regular' + }, + cardName: { + margin: 10, + paddingTop: 15, + fontSize: '24px', + }, + cardAccount: { + margin: '10px', + marginTop: '10px', + color: '#DFDFDF', + fontWeight: 'bold', + borderBottom: '2px solid #D8D1D1', + paddingBottom: 5 + }, + balance: { + position: "absolute", + bottom: '53%', + left: '10%' + }, + balanceFont: { + fontSize: '29px' + } +})) + +export const BankCard = (props) => { + const classes = useStyles(); + return ( + +
+

{props.name}

+

{props.account}

+
+
+

${props.balance}

+
+
+ ) +} diff --git a/phone/src/apps/bank/components/bank.styles.ts b/phone/src/apps/bank/components/bank.styles.ts new file mode 100644 index 0000000..173b7a5 --- /dev/null +++ b/phone/src/apps/bank/components/bank.styles.ts @@ -0,0 +1,95 @@ +import { makeStyles } from "@material-ui/core"; + +const useStyles = makeStyles((theme) => ({ + paper: { + padding: theme.spacing(1), + textAlign: "center", + width: "50%", + backgroundColor: "#2d3436", + margin: 20, + color: "#fff", + }, + table: { + width: "100%", + color: "#fff", + }, + cell: { + color: "#fff", + }, + container: { + maxHeight: 350, + }, + list: { + marginTop: "8.5em", + }, + root: { + width: "100%", + }, + header: { + width: "90%", + display: "flex", + justifyItems: "center", + justifyContent: "space-between", + margin: "auto", + }, + title: { + padding: 7, + borderRadius: "10px", + display: "flex", + justifyItems: "center", + justifyContent: "center", + fontSize: "30px", + }, + seeAll: { + fontFamily: "Bahnschrift Regular", + fontWeight: "bold", + height: "auto", + }, + transcationDiv: { + marginTop: "-30px", + minHeight: 200, + maxHeight: 240 + }, + transactions: { + marginLeft: "32px", + display: "flex", + justifyContent: "space-between", + borderBottom: "2px solid #707070", + width: "85%", + margin: "auto", + }, + tranSource: { + fontSize: "22px", + }, + tranType: { + fontSize: "18px", + fontWeight: "bold", + color: "#BFBFBF", + marginTop: "-18px", + width: "100%", + }, + + depositType: { + color: "#55B452", + marginRight: "32px", + fontSize: "22px", + fontWeight: "bold", + }, + withdrawType: { + color: "#FF5E5E", + marginRight: "32px", + fontSize: "22px", + fontWeight: "bold", + }, + pagination: { + background: '#262525', + width: '100%', + position: 'absolute', + bottom: 0, + maxWidth: '100%', + overflow: 'hidden', + borderBottom: "2px solid #707070" + } +})) + +export default useStyles \ No newline at end of file diff --git a/phone/src/apps/bank/components/home/BankHome.tsx b/phone/src/apps/bank/components/home/BankHome.tsx new file mode 100644 index 0000000..e6ca10c --- /dev/null +++ b/phone/src/apps/bank/components/home/BankHome.tsx @@ -0,0 +1,42 @@ +import React from "react"; +import { makeStyles, Paper, Typography } from "@material-ui/core"; +import { BankTitle } from "../BankTitle"; +import { Button } from "../../../../ui/components/Button"; +import { useTranslation } from "react-i18next"; +import { useTransactions } from "../../hooks/useTransactions"; +import { TransactionList } from "../transactions/TransactionList"; +import { TransferModal } from "../transfers/TransferModal"; + +import { useBankModal } from "../../hooks/useBankModal"; +import { useCredentials } from "../../hooks/useCredentials"; +import { NavLink } from 'react-router-dom'; + +// image +import CreditCard from '../img/credit-card.png' +import useStyles from './home.styles'; + +export const BankHome = () => { + const { showBankModal, setShowBankModal } = useBankModal(); + const { credentials } = useCredentials(); + const { transactionList } = useTransactions(); + const { t } = useTranslation(); + const classes = useStyles(); + + const openTransactionsModal = () => { + setShowBankModal(true); + }; + + return ( +
+ {t("APPS_BANK_HOME_TITLE")}, {credentials.name} +
+

Checking:

+

${credentials.balance}

+
+
+ + +
+
+ ); +}; \ No newline at end of file diff --git a/phone/src/apps/bank/components/home/home.styles.ts b/phone/src/apps/bank/components/home/home.styles.ts new file mode 100644 index 0000000..191964e --- /dev/null +++ b/phone/src/apps/bank/components/home/home.styles.ts @@ -0,0 +1,48 @@ +import { makeStyles } from "@material-ui/core"; + +const useStyles = makeStyles((theme) => ({ + root: { + width: "100%", + fontFamily: 'Bahnschrift Regular' + }, + headTitle: { + textAlign: 'center', + fontSize: '28px', + marginTop: 30, + }, + actions: { + width: '50%', + display: 'block', + margin: '0 auto', + textAlign: 'center' + }, + actionButton: { + background: '#388CF8', + width: 200, + height: 50, + borderRadius: '10px', + textDecoration: 'none', + margin: 'auto', + fontFamily: 'Bahnschrift Regular', + fontWeight: 'bold', + fontSize: '20px', + marginBottom: 20, + boxShadow: '0px 2px 7px -2px rgba(0,0,0,0.75)' + }, + accounts: { + marginTop: 20, + display: 'flex', + alignItems: 'center', + justifyContent: 'space-between', + margin: 30, + borderBottom: '1px solid #707070' + }, + accountsType: { + + }, + accountBalance: { + + }, +})) + +export default useStyles; \ No newline at end of file diff --git a/phone/src/apps/bank/components/navigation/NavigationBar.tsx b/phone/src/apps/bank/components/navigation/NavigationBar.tsx new file mode 100644 index 0000000..9a18dd9 --- /dev/null +++ b/phone/src/apps/bank/components/navigation/NavigationBar.tsx @@ -0,0 +1,51 @@ +import React, { useState } from 'react' + +import { Link } from "react-router-dom"; +import { BottomNavigation, BottomNavigationAction } from "@material-ui/core"; +import { makeStyles } from "@material-ui/core/styles"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faHome, faList, faMoneyCheck } from "@fortawesome/free-solid-svg-icons"; + + +const useStyles = makeStyles((theme) => ({ + root: { + width: "100%", + }, + icon: { + color: "#f44336", + }, +})) + +export const NavigationBar = () => { + const classes = useStyles(); + const [activePage, setActivePage] = useState(0) + return ( + { + setActivePage(newPage); + }} + showLabels + className={classes.root} + > + } + to="/bank" + /> + } + to="/bank/account" + /> + } + to="/bank/transactions" + /> + + ) +} diff --git a/phone/src/apps/bank/components/notification/BankNotification.tsx b/phone/src/apps/bank/components/notification/BankNotification.tsx new file mode 100644 index 0000000..6f64552 --- /dev/null +++ b/phone/src/apps/bank/components/notification/BankNotification.tsx @@ -0,0 +1,16 @@ +import React from 'react' +import Alert from '@material-ui/lab/Alert'; +import Notification from '../../../../ui/components/Notification'; +import { useBankAlert } from './../../hooks/useBankAlert'; + +export const BankNotification = ({ alert }) => { + const { setBankAlert } = useBankAlert(); + + const handleClose = () => { + setBankAlert(false) + } + + return ( +
+ ) +} diff --git a/phone/src/apps/bank/components/transactions/TransactionList.tsx b/phone/src/apps/bank/components/transactions/TransactionList.tsx index 233af19..0727829 100644 --- a/phone/src/apps/bank/components/transactions/TransactionList.tsx +++ b/phone/src/apps/bank/components/transactions/TransactionList.tsx @@ -1,19 +1,86 @@ -import React from "react"; +import React, { useState } from "react"; import { List } from "../../../../ui/components/List"; import { ListItem } from "../../../../ui/components/ListItem"; import ListItemText from "@material-ui/core/ListItemText"; +import { Typography, makeStyles, Button } from "@material-ui/core"; + +import useStyles from '../bank.styles'; + +import { useTranslation } from "react-i18next"; + +import TablePagination from '@material-ui/core/TablePagination'; + +import { useTransactions } from "../../hooks/useTransactions"; + +const columns = [ + { id: "type", label: "Type", minWidth: 100 }, + { id: "amount", label: "Amount", minWidth: 100 }, + { + id: "message", + label: "Message", + minWidth: 170, + align: "left", + format: (value: number) => value.toLocaleString("en-US"), + }, +]; + +export const TransactionList = () => { + const { transactionList } = useTransactions(); + const { t } = useTranslation(); + const classes = useStyles(); + const [page, setPage] = useState(0); + const [rowsPerPage, setRowsPerPage] = useState(5); + + const TransactionTypes = { + Deposit: classes.depositType, + Withdraw: classes.withdrawType, + Transfer: classes.depositType + }; + + + const handleChangePage = (event, newPage) => { + setPage(newPage); + }; + + const handleChangeRowsPerPage = (event) => { + setRowsPerPage(+event.target.value); + setPage(0); + }; -export const TransactionList = ({ transactions }) => { return ( - - {transactions.map((transaction) => ( - - +
+

{t("APPS_BANK_ACCOUNT_TRANSACTIONS")}

+
+ +
+ {transactionList + .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) + .map((transaction: any) => ( +
+
+

{transaction.source}

+

{transaction.type}

+
+
+

+ {transaction.type == "Withdraw" ? "-" : "+"} + {transaction.amount} +

+
+
+ ))} + - - ))} - +
+
); }; diff --git a/phone/src/apps/bank/components/transfers/TransferModal.tsx b/phone/src/apps/bank/components/transfers/TransferModal.tsx index 97aee59..fe4050b 100644 --- a/phone/src/apps/bank/components/transfers/TransferModal.tsx +++ b/phone/src/apps/bank/components/transfers/TransferModal.tsx @@ -1,13 +1,44 @@ import React, { useState } from 'react' import Modal from '../../../../ui/components/Modal'; -import { Button, List, ListItem, TextField } from '@material-ui/core'; +import { Button, List, ListItem, TextField, makeStyles } from '@material-ui/core'; +import CloseIcon from '@material-ui/icons/Close'; import Nui from '../../../../os/nui-events/utils/Nui'; import { useBankModal} from '../../hooks/useBankModal'; +const useStyles = makeStyles((theme) => ({ + input: { + width: "60%", + margin: 'auto', + + }, + modalInput: { + fontSize: 20 + }, + modalInputCenter: { + fontSize: 20, + textAlign: 'center', + }, + transferButton: { + background: "#2E7D32", + width: 120, + padding: 5, + margin: "auto", + fontSize: 16, + marginBottom: 30 + }, + closeButton: { + position: 'absolute', + right: 0, + width: "10%" + } +})) + export const TransferModal = () => { + const classes = useStyles(); + const [ targetID, setTargetID ] = useState(''); const [ amount, setAmount ] = useState(''); const [ message, setMessage ] = useState(''); @@ -24,14 +55,21 @@ export const TransferModal = () => { amount, message }) + setTimeout(() => { + setShowBankModal(false) + }, 200) + } return ( - - + + - setTargetID(e.target.value)} @@ -39,20 +77,26 @@ export const TransferModal = () => { setAmount(e.target.value)} /> - setMessage(e.target.value)} /> - + ) } diff --git a/phone/src/apps/bank/fonts/BAHNSCHRIFT.woff b/phone/src/apps/bank/fonts/BAHNSCHRIFT.woff new file mode 100644 index 0000000..2d86200 Binary files /dev/null and b/phone/src/apps/bank/fonts/BAHNSCHRIFT.woff differ diff --git a/phone/src/apps/bank/hooks/state.ts b/phone/src/apps/bank/hooks/state.ts index a1dd1ac..2f17396 100644 --- a/phone/src/apps/bank/hooks/state.ts +++ b/phone/src/apps/bank/hooks/state.ts @@ -8,5 +8,13 @@ export const bankState = { bankModal: atom({ key: 'modalVisibility', default: false, + }), + bankAlert: atom({ + key: 'bankAlert', + default: false + }), + bankCredentials: atom({ + key: 'bankCredentails', + default: null }) } \ No newline at end of file diff --git a/phone/src/apps/bank/hooks/useBankAlert.ts b/phone/src/apps/bank/hooks/useBankAlert.ts new file mode 100644 index 0000000..2fb828a --- /dev/null +++ b/phone/src/apps/bank/hooks/useBankAlert.ts @@ -0,0 +1,7 @@ +import { useRecoilState } from 'recoil'; +import { bankState } from './state'; + +export const useBankAlert = () => { + const [ bankAlert, setBankAlert ] = useRecoilState(bankState.bankAlert); + return { bankAlert, setBankAlert }; +} \ No newline at end of file diff --git a/phone/src/apps/bank/hooks/useBankService.ts b/phone/src/apps/bank/hooks/useBankService.ts index f200043..168b3f8 100644 --- a/phone/src/apps/bank/hooks/useBankService.ts +++ b/phone/src/apps/bank/hooks/useBankService.ts @@ -1,10 +1,13 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { bankState } from './state'; import { useTransactions } from './useTransactions' +import { useCredentials } from './useCredentials'; import { useSetRecoilState } from 'recoil' export const useBankService = () => { const setTransaction = useSetRecoilState(bankState.transactions) + const setCredentials = useSetRecoilState(bankState.bankCredentials) useNuiEvent('BANK', 'setTransaction', setTransaction); - return useTransactions; + useNuiEvent('BANK', 'setCredentials', setCredentials) + return {useTransactions, useCredentials}; } \ No newline at end of file diff --git a/phone/src/apps/bank/hooks/useCredentials.ts b/phone/src/apps/bank/hooks/useCredentials.ts new file mode 100644 index 0000000..1b73fcd --- /dev/null +++ b/phone/src/apps/bank/hooks/useCredentials.ts @@ -0,0 +1,7 @@ +import { useRecoilValue } from 'recoil'; +import { bankState } from './state'; + +export const useCredentials = (): any => { + const credentials = useRecoilValue(bankState.bankCredentials); + return { credentials }; +} \ No newline at end of file diff --git a/phone/src/apps/twitter/hooks/useTwitterNotification.ts b/phone/src/apps/twitter/hooks/useTwitterNotification.ts index 2e4c231..73b1893 100644 --- a/phone/src/apps/twitter/hooks/useTwitterNotification.ts +++ b/phone/src/apps/twitter/hooks/useTwitterNotification.ts @@ -1,6 +1,6 @@ import { useRecoilValue } from "recoil"; -import { Tweet } from "../interfaces"; +import { Tweet } from "../../../common/interfaces/twitter"; import { twitterState } from "./state"; interface ITwitterNotification { diff --git a/phone/src/apps/twitter/interfaces.ts b/phone/src/apps/twitter/interfaces.ts deleted file mode 100644 index e69de29..0000000 diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index fcb0a23..8ed8b3b 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -8,8 +8,6 @@ "APPS_SETTINGS": "Settings", "APPS_BANK": "WhoDis Banking", "APPS_EXAMPLE": "Example app", - "APPS_BANK_DEPOSIT": "Deposit", - "APPS_BANK_WITHDRAW": "Withdraw", "APPS_BANK_TRANSFER": "Transfer", "APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper", "APPS_SETTINGS_OPTIONS_FRAME": "Frame", @@ -38,6 +36,11 @@ "APPS_TWITTER_TIME_JUST_NOW": "Just now", "APPS_TWITTER_TIME_MINUTES": "m", "APPS_TWITTER_TIME_HOURS": "h", - "APPS_TWITTER_TIME_DAYS": "d" + "APPS_TWITTER_TIME_DAYS": "d", + + "APPS_BANK_HOME_TITLE": "Welcome, ", + "APPS_BANK_ACCOUNT_TITLE": "Account Summary", + "APPS_BANK_ACCOUNT_TRANSACTIONS": "Transactions", + "APPS_BANK_ACCOUNT_SEE_TRANSACTION": "See all" } } diff --git a/phone/src/os/apps/hooks/useApps.tsx b/phone/src/os/apps/hooks/useApps.tsx index c81aee8..f744ab6 100644 --- a/phone/src/os/apps/hooks/useApps.tsx +++ b/phone/src/os/apps/hooks/useApps.tsx @@ -14,7 +14,7 @@ import { faAd, faPlaneArrival, faPhoneAlt, - faLandmark, + faWonSign } from "@fortawesome/free-solid-svg-icons"; import { faTwitter } from "@fortawesome/free-brands-svg-icons"; @@ -86,7 +86,7 @@ const appsState = atom({ { id: "BANK", nameLocale: "APPS_BANK", - icon: , + icon: , backgroundColor: blue[900], color: common.white, path: "/bank", diff --git a/phone/src/ui/components/GridMenu.tsx b/phone/src/ui/components/GridMenu.tsx index 8c6b8e2..7839fc4 100644 --- a/phone/src/ui/components/GridMenu.tsx +++ b/phone/src/ui/components/GridMenu.tsx @@ -35,7 +35,6 @@ export const GridMenu = ({ items, Component = AppIcon }) => { key={item.id} item className={classes.item} - tabIndex="-1" component={Link} to={item.path} > diff --git a/resources/client/cl_bank.ts b/resources/client/cl_bank.ts new file mode 100644 index 0000000..c5681c1 --- /dev/null +++ b/resources/client/cl_bank.ts @@ -0,0 +1,33 @@ +import events from '../utils/events'; + + +onNet(events.BANK_SEND_TRANSFERS, (transfer: any) => { + SendNuiMessage( + JSON.stringify({ + app: "BANK", + method: "setTransaction", + data: transfer + }) + ) +}) + +onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => { + console.log("Client:", credentials.balance, credentials.name) + SendNuiMessage( + JSON.stringify({ + app: "BANK", + method: "setCredentials", + data: credentials + }) + ) +}) + +RegisterNuiCallbackType(events.BANK_ADD_TRANSFER); +on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => { + const transfer = data; + emitNet(events.BANK_ADD_TRANSFER, transfer) + + setTimeout(() => { + emitNet(events.BANK_FETCH_TRANSACTIONS); + }, 500) +}) diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index 0b2ead5..2ac5c9a 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -237,6 +237,8 @@ async function Phone() { emitNet('phone:getCredentials') emitNet(events.CONTACTS_GET_CONTACTS); emitNet(events.SELLOUT_FETCH_LISTING); + emitNet(events.BANK_FETCH_TRANSACTIONS); + emitNet(events.BANK_GET_CREDENTIALS); console.log("Sellout fetched from client side")// Gets the credentials. Will eventually most likely only get the phone number and name, idk. SetCursorLocation(0.90, 0.922) //Experimental let res = GetActiveScreenResolution() @@ -274,6 +276,8 @@ async function Phone() { emitNet('phone:getCredentials') emitNet(events.CONTACTS_GET_CONTACTS); emitNet(events.SELLOUT_FETCH_LISTING); + emitNet(events.BANK_FETCH_TRANSACTIONS); + emitNet(events.BANK_GET_CREDENTIALS); console.log("Sellout fetched from client side") SetCursorLocation(0.936, 0.922) //Experimental let res = GetActiveScreenResolution() diff --git a/resources/client/client.ts b/resources/client/client.ts index ec8d76d..2b6c28d 100644 --- a/resources/client/client.ts +++ b/resources/client/client.ts @@ -3,6 +3,7 @@ import './cl_main'; import './cl_twitter'; import './cl_contacts'; import './cl_sellout'; +import './cl_bank'; export let ESX: ESXClient = null; diff --git a/resources/server/server.ts b/resources/server/server.ts index f2060ed..cc0af0e 100644 --- a/resources/server/server.ts +++ b/resources/server/server.ts @@ -5,6 +5,7 @@ import './sv_twitter'; import './sv_main'; import './sv_contacts'; import './sv_sellout'; +import './sv_bank'; export let ESX: ESXServer = null; diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts new file mode 100644 index 0000000..a005995 --- /dev/null +++ b/resources/server/sv_bank.ts @@ -0,0 +1,94 @@ +import events from '../utils/events'; +import { ESX, getSource } from './server'; +import { pool } from './db'; +import { resourceLimits } from 'worker_threads'; + +interface Transfer { + targetID: string; + amount: number; + message: string; +} + +interface Credentials { + name: string; + balance: number; +} + + +async function fetchAllTransactions(identifier: string): Promise { + const query = "SELECT * FROM npwd_bank_transfers WHERE identifier = ? ORDER BY id DESC" + const [ results ] = await pool.query(query, [identifier]) + const transactions = results; + + return transactions; +} + +function fetchCredentials(): Credentials { + const name = ESX.GetPlayerFromId(getSource()).getName(); + const balance = ESX.GetPlayerFromId(getSource()).getAccount('bank').money + + const result = { + name, + balance + } + + console.log(result.name, result.balance); + + return result; +} + + +async function addTransfer(identifier: string, transfer: Transfer): Promise { + + const xPlayer = ESX.GetPlayerFromId(getSource()) + const bankBalance = xPlayer.getAccount('bank').money; + console.log(bankBalance) + if (transfer.amount > bankBalance) { + console.log("poor man") + emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You do not have enough money on your account', 'error') + } + else if (transfer.amount <= bankBalance) { + const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message) VALUES (?, ?, ?, ?)" + + await pool.query(query, [ + identifier, + transfer.targetID, + transfer.amount, + transfer.message + ]) + emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You succesfully transferred money to someone', 'success') + } +} + +onNet(events.BANK_FETCH_TRANSACTIONS, async () => { + try { + const _source = (global as any).source; + const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier() + const transfer = await fetchAllTransactions(_identifier); + + emitNet(events.BANK_SEND_TRANSFERS, _source, transfer) + console.log("WOORK") + + } catch (error) { + console.log('Failed to fetch transactions', error) + } +}) + +onNet(events.BANK_ADD_TRANSFER, (transfer: Transfer) => { + try { + const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier() + addTransfer(_identifier, transfer) + } catch (error) { + console.log('Failed to add transfer', error) + } +}) + +onNet(events.BANK_GET_CREDENTIALS, () => { + try { + const credentials = fetchCredentials() + console.log("New log: ", credentials.balance, credentials.name) + emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials) + } catch (error) { + console.log(error) + } +}) \ No newline at end of file diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 1bac517..cd7bab2 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -34,5 +34,13 @@ export default { // Sellout SELLOUT_ADD_LISTING: 'phone:addListing', SELLOUT_FETCH_LISTING: 'phone:fetchAllListings', - SELLOUT_SEND_LISTING: 'phone:sendAllListings' + SELLOUT_SEND_LISTING: 'phone:sendAllListings', + + // Bank + BANK_ADD_TRANSFER: 'phone:addTransfer', + BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions', + BANK_SEND_TRANSFERS: 'phone:sendTransfers', + BANK_TRANSACTION_ALERT: 'phone:transactionAlert', + BANK_SEND_CREDENTIALS: 'phone:sendBankCredentials', + BANK_GET_CREDENTIALS: 'phone:getBankCredentials' }