From 1dcd43b3cff4886a28c17d3007bb7c49eb27b835 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 3 Nov 2020 12:31:50 +0100 Subject: [PATCH 01/33] change snackbar position --- phone/src/apps/bank/components/BankApp.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phone/src/apps/bank/components/BankApp.css b/phone/src/apps/bank/components/BankApp.css index 64993ad..ad19ba4 100644 --- a/phone/src/apps/bank/components/BankApp.css +++ b/phone/src/apps/bank/components/BankApp.css @@ -31,6 +31,11 @@ color: #388CF8 !important; } + +#bank-app .MuiSnackbar-root { + position: absolute; +} + #bank-title { font-family: 'Bebas Neue', cursive; font-size: 50px; From d238e2a61222e4184aa69eb82ec13f57e1fddb55 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 3 Nov 2020 12:32:11 +0100 Subject: [PATCH 02/33] feat(bank/nui): alert component --- phone/src/apps/bank/components/BankApp.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phone/src/apps/bank/components/BankApp.tsx b/phone/src/apps/bank/components/BankApp.tsx index cfc38c9..e143a84 100644 --- a/phone/src/apps/bank/components/BankApp.tsx +++ b/phone/src/apps/bank/components/BankApp.tsx @@ -21,6 +21,7 @@ import { NavigationBar } from "./navigation/NavigationBar"; import { BankHome } from './home/BankHome'; import { BankAccount } from './account/BankAccount'; import { TransactionList } from "./transactions/TransactionList"; +import { BankAlert } from "./notification/BankAlert"; const useStyles = makeStyles((theme) => ({ root: { @@ -67,6 +68,7 @@ export const BankApp = () => { + From e17f9211f55359a0c7e803d4a03ecb847e2b806a Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 3 Nov 2020 12:32:41 +0100 Subject: [PATCH 03/33] feat(bank/nui): new state for alert --- .../components/notification/BankNotification.tsx | 16 ---------------- phone/src/apps/bank/hooks/state.ts | 4 ++-- phone/src/apps/bank/hooks/useBankService.ts | 5 ++++- 3 files changed, 6 insertions(+), 19 deletions(-) delete mode 100644 phone/src/apps/bank/components/notification/BankNotification.tsx diff --git a/phone/src/apps/bank/components/notification/BankNotification.tsx b/phone/src/apps/bank/components/notification/BankNotification.tsx deleted file mode 100644 index 6f64552..0000000 --- a/phone/src/apps/bank/components/notification/BankNotification.tsx +++ /dev/null @@ -1,16 +0,0 @@ -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/hooks/state.ts b/phone/src/apps/bank/hooks/state.ts index 2f17396..35cc439 100644 --- a/phone/src/apps/bank/hooks/state.ts +++ b/phone/src/apps/bank/hooks/state.ts @@ -11,10 +11,10 @@ export const bankState = { }), bankAlert: atom({ key: 'bankAlert', - default: false + default: null }), bankCredentials: atom({ key: 'bankCredentails', default: null - }) + }), } \ 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 168b3f8..92b7852 100644 --- a/phone/src/apps/bank/hooks/useBankService.ts +++ b/phone/src/apps/bank/hooks/useBankService.ts @@ -2,12 +2,15 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { bankState } from './state'; import { useTransactions } from './useTransactions' import { useCredentials } from './useCredentials'; +import { useBankAlert } from './useBankAlert'; import { useSetRecoilState } from 'recoil' export const useBankService = () => { const setTransaction = useSetRecoilState(bankState.transactions) const setCredentials = useSetRecoilState(bankState.bankCredentials) + const setAlertMessage = useSetRecoilState(bankState.bankAlert) useNuiEvent('BANK', 'setTransaction', setTransaction); useNuiEvent('BANK', 'setCredentials', setCredentials) - return {useTransactions, useCredentials}; + useNuiEvent('BANK', 'setAlert', setAlertMessage) + return {useTransactions, useCredentials, useBankAlert}; } \ No newline at end of file From 8dc15d5cc8ea7fdee54f67d4ab7b7adbc7932218 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 3 Nov 2020 12:33:23 +0100 Subject: [PATCH 04/33] server/client functionality for transferring + alerts | not done --- resources/client/cl_bank.ts | 10 ++++++++++ resources/server/sv_bank.ts | 25 +++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/resources/client/cl_bank.ts b/resources/client/cl_bank.ts index c5681c1..96a6651 100644 --- a/resources/client/cl_bank.ts +++ b/resources/client/cl_bank.ts @@ -31,3 +31,13 @@ on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => { emitNet(events.BANK_FETCH_TRANSACTIONS); }, 500) }) + +onNet(events.BANK_TRANSACTION_ALERT, (message: string, alert: string) => { + SendNuiMessage( + JSON.stringify({ + app: 'BANK', + method: 'setAlert', + data: { message, alert } + }) + ) +}) diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index a005995..6b7d7ca 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -1,18 +1,7 @@ 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; -} +import { Transfer, Credentials } from '../../phone/src/common/interfaces/bank'; async function fetchAllTransactions(identifier: string): Promise { @@ -37,11 +26,13 @@ function fetchCredentials(): Credentials { return result; } - async function addTransfer(identifier: string, transfer: Transfer): Promise { - const xPlayer = ESX.GetPlayerFromId(getSource()) const bankBalance = xPlayer.getAccount('bank').money; + + + const xTarget = ESX.GetPlayerFromId(transfer.targetID) + console.log(bankBalance) if (transfer.amount > bankBalance) { console.log("poor man") @@ -49,6 +40,7 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise } else if (transfer.amount <= bankBalance) { const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message) VALUES (?, ?, ?, ?)" + // emit alert to target iD await pool.query(query, [ identifier, @@ -56,7 +48,12 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise transfer.amount, transfer.message ]) + emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You succesfully transferred money to someone', 'success') + + xTarget.addAccountMoney('bank', transfer.amount) + + } } From a804aede814295b47275fce2e8b9a046c8680d49 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 3 Nov 2020 12:33:55 +0100 Subject: [PATCH 05/33] feat(phone/common): interface for bank --- phone/src/common/interfaces/bank.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 phone/src/common/interfaces/bank.ts diff --git a/phone/src/common/interfaces/bank.ts b/phone/src/common/interfaces/bank.ts new file mode 100644 index 0000000..f595f07 --- /dev/null +++ b/phone/src/common/interfaces/bank.ts @@ -0,0 +1,11 @@ +export interface Credentials { + name: string; + balance: number; +} + +export interface Transfer { + targetID: number; + amount: number; + message: string; +} + From bf2a991ebc871c0b987130a6a5e71837e737d718 Mon Sep 17 00:00:00 2001 From: chip Date: Tue, 3 Nov 2020 12:35:12 +0100 Subject: [PATCH 06/33] new component for notifications --- .../components/notification/BankAlert.tsx | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 phone/src/apps/bank/components/notification/BankAlert.tsx diff --git a/phone/src/apps/bank/components/notification/BankAlert.tsx b/phone/src/apps/bank/components/notification/BankAlert.tsx new file mode 100644 index 0000000..e1b1979 --- /dev/null +++ b/phone/src/apps/bank/components/notification/BankAlert.tsx @@ -0,0 +1,24 @@ +import React, { useState } from 'react' +import MuiAlert from '@material-ui/lab/Alert'; +import Notification from '../../../../ui/components/Notification'; +import { useBankAlert } from '../../hooks/useBankAlert'; +import Snackbar from '@material-ui/core/Snackbar'; + +export const BankAlert = () => { + const [ open, setOpen ] = useState(false); + const { bankAlert, setBankAlert } = useBankAlert() + + + + const _handleClose = () => { + setOpen(false) + } + + return ( + + + You transferrred money + + + ) +} From b8ef73b95f1e3470c651d77c632ef947e67ac769 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:01:28 +0100 Subject: [PATCH 07/33] feat(bank/nui): bank alert component --- .../src/apps/bank/components/alert/Alert.tsx | 8 ++++ .../apps/bank/components/alert/BankAlert.tsx | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 phone/src/apps/bank/components/alert/Alert.tsx create mode 100644 phone/src/apps/bank/components/alert/BankAlert.tsx diff --git a/phone/src/apps/bank/components/alert/Alert.tsx b/phone/src/apps/bank/components/alert/Alert.tsx new file mode 100644 index 0000000..2ba1e67 --- /dev/null +++ b/phone/src/apps/bank/components/alert/Alert.tsx @@ -0,0 +1,8 @@ +import React from "react"; +import MuiAlert from "@material-ui/lab/Alert"; + +export function Alert(props) { + return ; +} + +export default Alert; diff --git a/phone/src/apps/bank/components/alert/BankAlert.tsx b/phone/src/apps/bank/components/alert/BankAlert.tsx new file mode 100644 index 0000000..cda9c51 --- /dev/null +++ b/phone/src/apps/bank/components/alert/BankAlert.tsx @@ -0,0 +1,43 @@ +import React, { useState, useEffect } from "react"; +import { useBankAlert } from "../../hooks/useBankAlert"; +import Snackbar from "@material-ui/core/Snackbar"; +import Alert from "./Alert"; +import { useTranslation } from "react-i18next"; + +export const BankAlert = () => { + const { t } = useTranslation(); + const [open, setOpen] = useState(false); + const { bankAlert, setBankAlert } = useBankAlert(); + const [ message, setMessage ] = useState(null); + const [severity, setSeverity] = useState(""); + + const _handleClose = () => { + setOpen(false); + setBankAlert(null); + }; + + useEffect(() => { + if (bankAlert === true ) { + setOpen(true); + setMessage(t("APPS_BANK_ALERT_TRANSFER_SUCCESS")); + setSeverity("success") + } else if (bankAlert === false) { + setOpen(true); + setMessage(t("APPS_BANK_ALERT_TRANSFER_FAILURE")); + setSeverity("error") + } + }, [bankAlert]) + + return ( + + + {message} + + + ); +}; \ No newline at end of file From 25d64b486f0bff04094d0777387326e640e53b16 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:09:59 +0100 Subject: [PATCH 08/33] feat(bank/nui): bank notification component --- .../notification/BankNotification.tsx | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 phone/src/apps/bank/components/notification/BankNotification.tsx 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..071b749 --- /dev/null +++ b/phone/src/apps/bank/components/notification/BankNotification.tsx @@ -0,0 +1,45 @@ +import React, { useEffect, useState } from "react"; +import Notification from "../../../../ui/components/Notification"; +import { usePhone } from "../../../../os/phone/hooks/usePhone"; +import { useTranslation } from "react-i18next"; +import useStyles from './notification.style'; +import { useBankNotification } from "../../hooks/useBankNotification"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faWonSign } from "@fortawesome/free-solid-svg-icons"; + +export const BankNotification = () => { + const { notification } = useBankNotification() + const classes = useStyles() + const { t } = useTranslation(); + const [visible, setVisible ] = useState(false); + const { config } = usePhone() + + useEffect(() => { + if (notification) { + setVisible(true); + } + }, [notification?.id]) + + if (!config?.bank.showNotifications || !notification) return null; + + return ( + setVisible(false)} + > +
+
+
+
+ +
+
{notification.type}
+
+
{t("APPS_BANK_TIME_JUST_NOW")}
+
+
{notification.source} sent you ${notification.amount} || {notification.message}
+
+
+ ) +} \ No newline at end of file From 3d865dd887c3641d918a4b43e326c45fe72bca7b Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:10:29 +0100 Subject: [PATCH 09/33] feat(bank/nui): additional styling for notification --- .../notification/notification.style.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 phone/src/apps/bank/components/notification/notification.style.ts diff --git a/phone/src/apps/bank/components/notification/notification.style.ts b/phone/src/apps/bank/components/notification/notification.style.ts new file mode 100644 index 0000000..7d80b71 --- /dev/null +++ b/phone/src/apps/bank/components/notification/notification.style.ts @@ -0,0 +1,43 @@ +import { makeStyles, createStyles, Theme } from "@material-ui/core/styles"; + +const useStyles = makeStyles((theme: Theme) => + createStyles({ + content: { + padding: theme.spacing(2), + overflowY: 'hidden' + }, + title: { + display: "flex", + flexFlow: "row nowrap", + justifyContent: "space-between", + alignItems: "center", + }, + titleLeft: { + display: "flex", + flexFlow: "row nowrap", + justifyContent: "flex-start", + alignItems: "center", + }, + icon: { + marginTop: "3px", + marginRight: "5px", + }, + heading: { + marginBottom: "3px", + }, + justNow: { + fontSize: "18px", + fontStyle: "italic", + paddingRight: "3px", + }, + message: { + fontSize: "16px", + overflow: "hidden", + display: "-webkit-box", + WebkitLineClamp: 2, + WebkitBoxOrient: "vertical", + }, + }) +) + +export default useStyles; \ No newline at end of file From e6cee7b414b58ad44377ba5127a1653f2c232db9 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:11:12 +0100 Subject: [PATCH 10/33] feat(bank/nui): state and hooks for alert and notificatioln --- phone/src/apps/bank/hooks/state.ts | 6 +++++- phone/src/apps/bank/hooks/useBankAlert.ts | 4 ++-- phone/src/apps/bank/hooks/useBankNotification.ts | 13 +++++++++++++ phone/src/apps/bank/hooks/useBankService.ts | 14 ++++++++++---- 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 phone/src/apps/bank/hooks/useBankNotification.ts diff --git a/phone/src/apps/bank/hooks/state.ts b/phone/src/apps/bank/hooks/state.ts index 35cc439..70ad8d4 100644 --- a/phone/src/apps/bank/hooks/state.ts +++ b/phone/src/apps/bank/hooks/state.ts @@ -9,7 +9,7 @@ export const bankState = { key: 'modalVisibility', default: false, }), - bankAlert: atom({ + transferSuccessful: atom({ key: 'bankAlert', default: null }), @@ -17,4 +17,8 @@ export const bankState = { key: 'bankCredentails', default: null }), + notification: atom({ + key: 'bankNotification', + 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 index 2fb828a..da6deb0 100644 --- a/phone/src/apps/bank/hooks/useBankAlert.ts +++ b/phone/src/apps/bank/hooks/useBankAlert.ts @@ -1,7 +1,7 @@ import { useRecoilState } from 'recoil'; import { bankState } from './state'; -export const useBankAlert = () => { - const [ bankAlert, setBankAlert ] = useRecoilState(bankState.bankAlert); +export const useBankAlert = (): any => { + const [ bankAlert, setBankAlert ] = useRecoilState(bankState.transferSuccessful); return { bankAlert, setBankAlert }; } \ No newline at end of file diff --git a/phone/src/apps/bank/hooks/useBankNotification.ts b/phone/src/apps/bank/hooks/useBankNotification.ts new file mode 100644 index 0000000..e67087f --- /dev/null +++ b/phone/src/apps/bank/hooks/useBankNotification.ts @@ -0,0 +1,13 @@ +import { useRecoilValue } from 'recoil'; + +import { Transfer } from '../../../common/interfaces/bank'; +import { bankState } from './state'; + +interface IBankNotification { + notification: Transfer | null; +} + +export const useBankNotification = (): IBankNotification => { + const notification = useRecoilValue(bankState.notification); + return { notification } +} \ 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 92b7852..f853886 100644 --- a/phone/src/apps/bank/hooks/useBankService.ts +++ b/phone/src/apps/bank/hooks/useBankService.ts @@ -4,13 +4,19 @@ import { useTransactions } from './useTransactions' import { useCredentials } from './useCredentials'; import { useBankAlert } from './useBankAlert'; import { useSetRecoilState } from 'recoil' +import { useBankNotification } from './useBankNotification'; export const useBankService = () => { const setTransaction = useSetRecoilState(bankState.transactions) const setCredentials = useSetRecoilState(bankState.bankCredentials) - const setAlertMessage = useSetRecoilState(bankState.bankAlert) + const setAlertMessage = useSetRecoilState(bankState.transferSuccessful) + const setNotification = useSetRecoilState(bankState.notification); + + /// + useNuiEvent('BANK', 'setTransaction', setTransaction); - useNuiEvent('BANK', 'setCredentials', setCredentials) - useNuiEvent('BANK', 'setAlert', setAlertMessage) - return {useTransactions, useCredentials, useBankAlert}; + useNuiEvent('BANK', 'setCredentials', setCredentials); + useNuiEvent('BANK', 'setAlert', setAlertMessage); + useNuiEvent('BANK', 'setNotification', setNotification); + return { useTransactions, useCredentials, useBankAlert, useBankNotification }; } \ No newline at end of file From b6ac33116e2e0fcfbbb40b2b4f27adeb440ed3c6 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:12:21 +0100 Subject: [PATCH 11/33] some testing with the transfer modal --- phone/src/apps/bank/components/transfers/TransferModal.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/phone/src/apps/bank/components/transfers/TransferModal.tsx b/phone/src/apps/bank/components/transfers/TransferModal.tsx index fe4050b..df85633 100644 --- a/phone/src/apps/bank/components/transfers/TransferModal.tsx +++ b/phone/src/apps/bank/components/transfers/TransferModal.tsx @@ -6,6 +6,7 @@ import CloseIcon from '@material-ui/icons/Close'; import Nui from '../../../../os/nui-events/utils/Nui'; import { useBankModal} from '../../hooks/useBankModal'; +import { Message } from '@material-ui/icons'; const useStyles = makeStyles((theme) => ({ input: { @@ -55,10 +56,7 @@ export const TransferModal = () => { amount, message }) - setTimeout(() => { - setShowBankModal(false) - }, 200) - + setShowBankModal(false) } return ( From 54586266b51f80eca2bd71ac53b5e16c5e8b0385 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:13:07 +0100 Subject: [PATCH 12/33] feat(bank/nui): add BankAlert to BankApp --- phone/src/apps/bank/components/BankApp.tsx | 2 +- .../components/notification/BankAlert.tsx | 24 ------------------- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 phone/src/apps/bank/components/notification/BankAlert.tsx diff --git a/phone/src/apps/bank/components/BankApp.tsx b/phone/src/apps/bank/components/BankApp.tsx index e143a84..55415f5 100644 --- a/phone/src/apps/bank/components/BankApp.tsx +++ b/phone/src/apps/bank/components/BankApp.tsx @@ -21,7 +21,7 @@ import { NavigationBar } from "./navigation/NavigationBar"; import { BankHome } from './home/BankHome'; import { BankAccount } from './account/BankAccount'; import { TransactionList } from "./transactions/TransactionList"; -import { BankAlert } from "./notification/BankAlert"; +import { BankAlert } from "./alert/BankAlert"; const useStyles = makeStyles((theme) => ({ root: { diff --git a/phone/src/apps/bank/components/notification/BankAlert.tsx b/phone/src/apps/bank/components/notification/BankAlert.tsx deleted file mode 100644 index e1b1979..0000000 --- a/phone/src/apps/bank/components/notification/BankAlert.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import React, { useState } from 'react' -import MuiAlert from '@material-ui/lab/Alert'; -import Notification from '../../../../ui/components/Notification'; -import { useBankAlert } from '../../hooks/useBankAlert'; -import Snackbar from '@material-ui/core/Snackbar'; - -export const BankAlert = () => { - const [ open, setOpen ] = useState(false); - const { bankAlert, setBankAlert } = useBankAlert() - - - - const _handleClose = () => { - setOpen(false) - } - - return ( - - - You transferrred money - - - ) -} From 4c2952b9addc9cdc46b414bf2189595af4feaecb Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:13:49 +0100 Subject: [PATCH 13/33] feat(bank/nui): added interfaces to config.ts and new interface for bank --- phone/src/common/interfaces/bank.ts | 3 +++ phone/src/common/interfaces/config.ts | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/phone/src/common/interfaces/bank.ts b/phone/src/common/interfaces/bank.ts index f595f07..66f7c29 100644 --- a/phone/src/common/interfaces/bank.ts +++ b/phone/src/common/interfaces/bank.ts @@ -4,7 +4,10 @@ export interface Credentials { } export interface Transfer { + id: number; targetID: number; + source: string; + type: string; amount: number; message: string; } diff --git a/phone/src/common/interfaces/config.ts b/phone/src/common/interfaces/config.ts index 85715eb..c5f43bf 100644 --- a/phone/src/common/interfaces/config.ts +++ b/phone/src/common/interfaces/config.ts @@ -16,6 +16,10 @@ interface NotificationConfig { vertical: "bottom" | "top"; } +interface BankConfig { + showNotifications: boolean; +} + export interface ServerConfig { Locale: string; KeyTogglePhone: number; @@ -26,5 +30,6 @@ export interface ServerConfig { DestoryChance: number; DestroyPhoneReCheck: number; twitter: TwitterConfig; + bank: BankConfig; notificationPosition: NotificationConfig; } From 568654855f1820eefc46299ea466621a0648f3a9 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:14:27 +0100 Subject: [PATCH 14/33] use of useBankSerice --- phone/src/Phone.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 0865345..b26b104 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -59,6 +59,31 @@ setTimeout(() => { ) }, 1000) +setTimeout(() => { + new MessageEvent("messsage", { + data: { + app: "BANK", + method: "setNotification", + data: { + id: 1, + message: "ahhaha" + } + } + }) +}, 1000) + +setTimeout(() => { + new MessageEvent("messsage", { + data: { + app: "TWITTER", + method: "setNotification", + data: { + id: 1, + message: "ahhaha" + } + } + }) +}, 1000) setTimeout(() => { window.dispatchEvent( From f04108e216844d8018bf6f7b908c14ae8c453b7f Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:14:55 +0100 Subject: [PATCH 15/33] added Bank Notification to the root fiel --- phone/src/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phone/src/index.tsx b/phone/src/index.tsx index c7fc224..eb1d652 100644 --- a/phone/src/index.tsx +++ b/phone/src/index.tsx @@ -8,11 +8,13 @@ import "./main.css"; import Phone from "./Phone"; import * as serviceWorker from "./serviceWorker"; import TwitterNotification from "./apps/twitter/components/notification/TwitterNotification"; +import { BankNotification } from "./apps/bank/components/notification/BankNotification"; ReactDOM.render( + , From 198d9937abf12e981f5dd59c0ef02ad7dde0b760 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:15:21 +0100 Subject: [PATCH 16/33] feat(phone/locale): more translation for the bank ap --- phone/src/locale/en.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 4094108..644289d 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -41,10 +41,13 @@ "APPS_BANK_HOME_TITLE": "Welcome", "APPS_BANK_ACCOUNT_LINK": "Account", + "APPS_BANK_TIME_JUST_NOW": "Just now", "APPS_BANK_ACCOUNT_TITLE": "Account Summary", "APPS_BANK_ACCOUNT_TRANSACTIONS": "Transactions", "APPS_BANK_ACCOUNT_SEE_TRANSACTION": "See all", "APPS_BANK_ACTIONS_TRANSFER": "Transfer", + "APPS_BANK_ALERT_TRANSFER_SUCCESS": "Transfer done successfully!", + "APPS_BANK_ALERT_TRANSFER_FAILURE": "Transfer failed!", "APPS_CONTACT_FORM_NAME": "Name", "APPS_CONTACT_FORM_NUMBER": "Number", From 8f0b6efd0159dfc56172710c9ec39626eaa8eed7 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:15:50 +0100 Subject: [PATCH 17/33] feat(bank/client): events for alert and notification --- resources/client/cl_bank.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/resources/client/cl_bank.ts b/resources/client/cl_bank.ts index 96a6651..36c3411 100644 --- a/resources/client/cl_bank.ts +++ b/resources/client/cl_bank.ts @@ -32,12 +32,22 @@ on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => { }, 500) }) -onNet(events.BANK_TRANSACTION_ALERT, (message: string, alert: string) => { +onNet(events.BANK_TRANSACTION_ALERT, (bool: boolean) => { SendNuiMessage( JSON.stringify({ app: 'BANK', method: 'setAlert', - data: { message, alert } + data: bool + }) + ) +}) + +onNet(events.BANK_TRANSACTION_NOTIFICATION, (transfer: any) => { + SendNuiMessage( + JSON.stringify({ + app: "BANK", + method: 'setNotification', + data: transfer }) ) }) From 66655f40f6c06a85021d0d81a5bdccea24a43f92 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:16:53 +0100 Subject: [PATCH 18/33] feat(bank/server): able to get current transfer | checks for transferring | (needs clean up) --- resources/server/sv_bank.ts | 50 ++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index 6b7d7ca..3ee71f6 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -29,34 +29,47 @@ function fetchCredentials(): Credentials { async function addTransfer(identifier: string, transfer: Transfer): Promise { const xPlayer = ESX.GetPlayerFromId(getSource()) const bankBalance = xPlayer.getAccount('bank').money; + const sourceName = xPlayer.getName() - - const xTarget = ESX.GetPlayerFromId(transfer.targetID) - - 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') + emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false) } - else if (transfer.amount <= bankBalance) { - const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message) VALUES (?, ?, ?, ?)" + else if (transfer.amount < bankBalance) { + emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true) + + + const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)" // emit alert to target iD + console.log("rich man") - await pool.query(query, [ + const [results] = await pool.query(query, [ identifier, transfer.targetID, transfer.amount, - transfer.message + transfer.message, + "Deposit", + sourceName, ]) - - emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You succesfully transferred money to someone', 'success') - - xTarget.addAccountMoney('bank', transfer.amount) - - + const insertData = results; + console.log("ID: ", insertData.insertId) + return await getTransfer(insertData.insertId) + //xTarget.addAccountMoney('bank', transfer.amount) } } +/** + * Gets a transfer from its ID + * @param transferId - transfer id + */ +async function getTransfer(transferId: number): Promise { + const query = "SELECT * FROM npwd_bank_transfers WHERE id = ?" + const [ results ] = await pool.query(query, [transferId]); + const transfers = results; + const transfer = transfers[0]; + return {...transfer}; +} + onNet(events.BANK_FETCH_TRANSACTIONS, async () => { try { const _source = (global as any).source; @@ -64,17 +77,18 @@ onNet(events.BANK_FETCH_TRANSACTIONS, async () => { 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) => { +onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => { try { const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier() - addTransfer(_identifier, transfer) + const transferNotify = await addTransfer(_identifier, transfer) + console.log(transferNotify.id) + emitNet(events.BANK_TRANSACTION_NOTIFICATION, getSource(), transferNotify) } catch (error) { console.log('Failed to add transfer', error) } From b0dd8c58dd586fbb57e012bbaf5c8ddb427f57d3 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:17:45 +0100 Subject: [PATCH 19/33] feat(config): bank/showNotifications --- config.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index 6b01a9c..c0c10cd 100644 --- a/config.json +++ b/config.json @@ -9,7 +9,7 @@ "DestroyPhoneReCheck": 3, "notificationPosition": { "horizontal": "right", - "vertical": "bottom" + "vertical": "top" }, "twitter": { "showNotifications": true, @@ -22,5 +22,8 @@ "enableEmojis": true, "enableImages": true, "maxImages": 3 + }, + "bank": { + "showNotifications": true } } \ No newline at end of file From a110c12a66f0db750f841e25db83ff2be783b941 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:18:28 +0100 Subject: [PATCH 20/33] more events for bank app --- resources/utils/events.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 0dc62a1..9b2565e 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -47,7 +47,8 @@ export default { BANK_ADD_TRANSFER: 'phone:addTransfer', BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions', BANK_SEND_TRANSFERS: 'phone:sendTransfers', - BANK_TRANSACTION_ALERT: 'phone:transactionAlert', + BANK_TRANSACTION_ALERT: 'phone:bankTransactionAlert', + BANK_TRANSACTION_NOTIFICATION: 'phone:bankTransactionNotification', BANK_SEND_CREDENTIALS: 'phone:sendBankCredentials', BANK_GET_CREDENTIALS: 'phone:getBankCredentials', From 47ae3d069159acd5d59444f25c3cb7e654b28afe Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 16:33:44 +0100 Subject: [PATCH 21/33] cleanup(bank): client|server| new events --- resources/client/cl_bank.ts | 7 +++---- resources/server/sv_bank.ts | 18 ++++++------------ resources/utils/events.ts | 1 + 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/resources/client/cl_bank.ts b/resources/client/cl_bank.ts index 36c3411..c29703c 100644 --- a/resources/client/cl_bank.ts +++ b/resources/client/cl_bank.ts @@ -12,7 +12,6 @@ onNet(events.BANK_SEND_TRANSFERS, (transfer: any) => { }) onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => { - console.log("Client:", credentials.balance, credentials.name) SendNuiMessage( JSON.stringify({ app: "BANK", @@ -26,10 +25,10 @@ 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) +onNet(events.BANK_ADD_TRANSFER_SUCCESS, () => { + emitNet(events.BANK_FETCH_TRANSACTIONS); }) onNet(events.BANK_TRANSACTION_ALERT, (bool: boolean) => { diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index 3ee71f6..91321ed 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -21,8 +21,6 @@ function fetchCredentials(): Credentials { balance } - console.log(result.name, result.balance); - return result; } @@ -31,17 +29,15 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise const bankBalance = xPlayer.getAccount('bank').money; const sourceName = xPlayer.getName() + const xTarget = ESX.GetPlayerFromId(transfer.targetID); + + if (transfer.amount > bankBalance) { - console.log("poor man") emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false) } else if (transfer.amount < bankBalance) { emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true) - - const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)" - // emit alert to target iD - console.log("rich man") const [results] = await pool.query(query, [ identifier, @@ -52,9 +48,7 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise sourceName, ]) const insertData = results; - console.log("ID: ", insertData.insertId) return await getTransfer(insertData.insertId) - //xTarget.addAccountMoney('bank', transfer.amount) } } @@ -79,7 +73,7 @@ onNet(events.BANK_FETCH_TRANSACTIONS, async () => { emitNet(events.BANK_SEND_TRANSFERS, _source, transfer) } catch (error) { - console.log('Failed to fetch transactions', error) + console.log(error) } }) @@ -87,10 +81,10 @@ onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => { try { const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier() const transferNotify = await addTransfer(_identifier, transfer) - console.log(transferNotify.id) emitNet(events.BANK_TRANSACTION_NOTIFICATION, getSource(), transferNotify) + emitNet(events.BANK_ADD_TRANSFER_SUCCESS); } catch (error) { - console.log('Failed to add transfer', error) + emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false) } }) diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 9b2565e..de34896 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -45,6 +45,7 @@ export default { // Bank BANK_ADD_TRANSFER: 'phone:addTransfer', + BANK_ADD_TRANSFER_SUCCESS: 'phone:addTransferSuccess', BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions', BANK_SEND_TRANSFERS: 'phone:sendTransfers', BANK_TRANSACTION_ALERT: 'phone:bankTransactionAlert', From 5110b2efd7f883060f61ddda74982171fe649c9f Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 22:36:36 +0100 Subject: [PATCH 22/33] tweak(phone): not open phone when started up --- phone/src/Phone.tsx | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index b26b104..0e442ba 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -180,18 +180,6 @@ setTimeout(() => { ); }, 1000); -setTimeout(() => { - window.dispatchEvent( - new MessageEvent("message", { - data: { - app: "PHONE", - method: "setVisibility", - data: true, - }, - }) - ); -}, 1000); - setTimeout(() => { window.dispatchEvent( new MessageEvent("message", { From 7af8443af2e2bdaca3677a4994635aaa49443ca8 Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 22:37:34 +0100 Subject: [PATCH 23/33] tweak(notification/nui): fix so the component is hidden when you click on any other nui element in the phone --- phone/src/ui/components/Notification.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone/src/ui/components/Notification.tsx b/phone/src/ui/components/Notification.tsx index 851880d..37da3a7 100644 --- a/phone/src/ui/components/Notification.tsx +++ b/phone/src/ui/components/Notification.tsx @@ -32,7 +32,7 @@ function Notification({ children, handleClose, open }) { null }} + //ClickAwayListenerProps={{ onClickAway: () => null }} onClose={handleClose} open={open} TransitionComponent={Fade} From 1fcf7c809b8bf0dffb7ab5d6d6ceb836e04cc50e Mon Sep 17 00:00:00 2001 From: chip Date: Wed, 4 Nov 2020 22:39:00 +0100 Subject: [PATCH 24/33] feat(bank/nui): more server functionality --- resources/server/sv_bank.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index 91321ed..e8cb223 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -44,7 +44,7 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise transfer.targetID, transfer.amount, transfer.message, - "Deposit", + "Transaction", sourceName, ]) const insertData = results; From 37ff0428fa0666cdea9a81f4760d4ee180e95b8f Mon Sep 17 00:00:00 2001 From: chip Date: Thu, 5 Nov 2020 13:27:25 +0100 Subject: [PATCH 25/33] feat(bank/server): transaction functionality | need to get the source of the player --- resources/server/sv_bank.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index e8cb223..f37dac0 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -2,6 +2,7 @@ import events from '../utils/events'; import { ESX, getSource } from './server'; import { pool } from './db'; import { Transfer, Credentials } from '../../phone/src/common/interfaces/bank'; +import { useIdentifier } from './functions'; async function fetchAllTransactions(identifier: string): Promise { @@ -37,6 +38,10 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise } else if (transfer.amount < bankBalance) { emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true) + + //xTarget.addAccountMoney('bank', transfer.amount);// + //xPlayer.removeAccountMoney('bank', transfer.amount); + const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)" const [results] = await pool.query(query, [ @@ -67,22 +72,22 @@ async function getTransfer(transferId: number): Promise { onNet(events.BANK_FETCH_TRANSACTIONS, async () => { try { const _source = (global as any).source; - const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier() + const _identifier = await useIdentifier() const transfer = await fetchAllTransactions(_identifier); emitNet(events.BANK_SEND_TRANSFERS, _source, transfer) } catch (error) { - console.log(error) + console.log("Failed to fetch transactions"); } }) onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => { try { - const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier() + const _identifier = await useIdentifier() const transferNotify = await addTransfer(_identifier, transfer) emitNet(events.BANK_TRANSACTION_NOTIFICATION, getSource(), transferNotify) - emitNet(events.BANK_ADD_TRANSFER_SUCCESS); + emitNet(events.BANK_ADD_TRANSFER_SUCCESS, getSource()); } catch (error) { emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false) } @@ -91,9 +96,8 @@ onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => { 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) + console.log("Failed to fetch credentials"); } }) \ No newline at end of file From 199f568105fe5dffba1757a01e100a212d5549af Mon Sep 17 00:00:00 2001 From: chip Date: Thu, 5 Nov 2020 13:40:55 +0100 Subject: [PATCH 26/33] tweak(bank/nui): notification layout tweak --- .../src/apps/bank/components/notification/BankNotification.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone/src/apps/bank/components/notification/BankNotification.tsx b/phone/src/apps/bank/components/notification/BankNotification.tsx index 071b749..d89064b 100644 --- a/phone/src/apps/bank/components/notification/BankNotification.tsx +++ b/phone/src/apps/bank/components/notification/BankNotification.tsx @@ -38,7 +38,7 @@ export const BankNotification = () => {
{t("APPS_BANK_TIME_JUST_NOW")}
-
{notification.source} sent you ${notification.amount} || {notification.message}
+
{notification.source} sent you ${notification.amount}.

{notification.message}
) From 4d029cd7afaa01d5927f5c7f5e8dd14d03336262 Mon Sep 17 00:00:00 2001 From: chip Date: Thu, 5 Nov 2020 13:42:59 +0100 Subject: [PATCH 27/33] fix(bank/server): changed type for transaction when transferring --- resources/server/sv_bank.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index f37dac0..840c8c8 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -49,7 +49,7 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise transfer.targetID, transfer.amount, transfer.message, - "Transaction", + "Transfer", sourceName, ]) const insertData = results; From bbbc6826e48535baf784493601aaae97dd92ddb3 Mon Sep 17 00:00:00 2001 From: chip Date: Thu, 5 Nov 2020 17:11:01 +0100 Subject: [PATCH 28/33] feat(bank/nui): adding account money ready for testing --- resources/server/sv_bank.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index 840c8c8..c06fde2 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -39,8 +39,8 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise else if (transfer.amount < bankBalance) { emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true) - //xTarget.addAccountMoney('bank', transfer.amount);// - //xPlayer.removeAccountMoney('bank', transfer.amount); + xTarget.addAccountMoney('bank', transfer.amount); + xPlayer.removeAccountMoney('bank', transfer.amount); const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)" From ac3dc237017577cc45e54b42d2201e053c16c425 Mon Sep 17 00:00:00 2001 From: chip Date: Fri, 6 Nov 2020 02:20:19 +0100 Subject: [PATCH 29/33] fix(bank/nui): change of interface property for notification message --- .../src/apps/bank/components/notification/BankNotification.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone/src/apps/bank/components/notification/BankNotification.tsx b/phone/src/apps/bank/components/notification/BankNotification.tsx index d89064b..122bff0 100644 --- a/phone/src/apps/bank/components/notification/BankNotification.tsx +++ b/phone/src/apps/bank/components/notification/BankNotification.tsx @@ -38,7 +38,7 @@ export const BankNotification = () => {
{t("APPS_BANK_TIME_JUST_NOW")}
-
{notification.source} sent you ${notification.amount}.

{notification.message}
+
{notification.source} sent you ${notification.transferAmount}.

{notification.message}
) From c7faca15edc76779c3b43fc9265d196fa3c89179 Mon Sep 17 00:00:00 2001 From: chip Date: Fri, 6 Nov 2020 02:20:46 +0100 Subject: [PATCH 30/33] feat(bank/nui): bank transferring works fine --- resources/server/sv_bank.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/resources/server/sv_bank.ts b/resources/server/sv_bank.ts index c06fde2..97941f8 100644 --- a/resources/server/sv_bank.ts +++ b/resources/server/sv_bank.ts @@ -3,6 +3,7 @@ import { ESX, getSource } from './server'; import { pool } from './db'; import { Transfer, Credentials } from '../../phone/src/common/interfaces/bank'; import { useIdentifier } from './functions'; +import { type } from 'os'; async function fetchAllTransactions(identifier: string): Promise { @@ -33,21 +34,21 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise const xTarget = ESX.GetPlayerFromId(transfer.targetID); - if (transfer.amount > bankBalance) { + if (transfer.transferAmount > bankBalance) { emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false) } - else if (transfer.amount < bankBalance) { - emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true) + else if (transfer.transferAmount < bankBalance) { + emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true); - xTarget.addAccountMoney('bank', transfer.amount); - xPlayer.removeAccountMoney('bank', transfer.amount); + xTarget.addAccountMoney('bank', transfer.transferAmount); + xPlayer.removeAccountMoney('bank', transfer.transferAmount); const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)" const [results] = await pool.query(query, [ identifier, transfer.targetID, - transfer.amount, + transfer.transferAmount, transfer.message, "Transfer", sourceName, @@ -83,10 +84,12 @@ onNet(events.BANK_FETCH_TRANSACTIONS, async () => { }) onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => { + const xTarget = ESX.GetPlayerFromId(transfer.targetID); + const targetSource = xTarget.source; try { const _identifier = await useIdentifier() const transferNotify = await addTransfer(_identifier, transfer) - emitNet(events.BANK_TRANSACTION_NOTIFICATION, getSource(), transferNotify) + emitNet(events.BANK_TRANSACTION_NOTIFICATION, targetSource, transferNotify) emitNet(events.BANK_ADD_TRANSFER_SUCCESS, getSource()); } catch (error) { emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false) From a7b01008705e527da7578d7e00d2c279351fcfc9 Mon Sep 17 00:00:00 2001 From: chip Date: Fri, 6 Nov 2020 02:21:34 +0100 Subject: [PATCH 31/33] fix(bank/nui): fix notification to be removed after x amount of seconds --- phone/src/ui/components/Notification.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone/src/ui/components/Notification.tsx b/phone/src/ui/components/Notification.tsx index 37da3a7..03254f1 100644 --- a/phone/src/ui/components/Notification.tsx +++ b/phone/src/ui/components/Notification.tsx @@ -32,7 +32,7 @@ function Notification({ children, handleClose, open }) { null }} + ClickAwayListenerProps={{ onClickAway: () => setTimeout(() => { handleClose() }, 5000) }} onClose={handleClose} open={open} TransitionComponent={Fade} From c0497bbd92fa09dc1ba499cf5de00073fb579f65 Mon Sep 17 00:00:00 2001 From: chip Date: Fri, 6 Nov 2020 02:22:09 +0100 Subject: [PATCH 32/33] tweak(bank/interface): change of bank transfer interface amount property --- phone/src/common/interfaces/bank.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone/src/common/interfaces/bank.ts b/phone/src/common/interfaces/bank.ts index 66f7c29..b11a21e 100644 --- a/phone/src/common/interfaces/bank.ts +++ b/phone/src/common/interfaces/bank.ts @@ -8,7 +8,7 @@ export interface Transfer { targetID: number; source: string; type: string; - amount: number; + transferAmount: number; message: string; } From e1ff6eb3827626e2d89c5eff5d5a92e5625e850e Mon Sep 17 00:00:00 2001 From: chip Date: Fri, 6 Nov 2020 02:22:55 +0100 Subject: [PATCH 33/33] fix(bank/nui): parseInt amount --- phone/src/apps/bank/components/transfers/TransferModal.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phone/src/apps/bank/components/transfers/TransferModal.tsx b/phone/src/apps/bank/components/transfers/TransferModal.tsx index df85633..6759bf0 100644 --- a/phone/src/apps/bank/components/transfers/TransferModal.tsx +++ b/phone/src/apps/bank/components/transfers/TransferModal.tsx @@ -51,9 +51,10 @@ export const TransferModal = () => { } const addTransfer = () => { + const transferAmount = parseInt(amount); Nui.send('phone:addTransfer', { targetID, - amount, + transferAmount, message }) setShowBankModal(false)