mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Merge pull request #28 from Re-Ignited-Development/wrap/bank
Wrap/bank - some files needs some clean up
This commit is contained in:
21 files changed
+304
-76
No files matched your search
+4
-1
@@ -9,7 +9,7 @@
|
|||||||
"DestroyPhoneReCheck": 3,
|
"DestroyPhoneReCheck": 3,
|
||||||
"notificationPosition": {
|
"notificationPosition": {
|
||||||
"horizontal": "right",
|
"horizontal": "right",
|
||||||
"vertical": "bottom"
|
"vertical": "top"
|
||||||
},
|
},
|
||||||
"twitter": {
|
"twitter": {
|
||||||
"showNotifications": true,
|
"showNotifications": true,
|
||||||
@@ -22,5 +22,8 @@
|
|||||||
"enableEmojis": true,
|
"enableEmojis": true,
|
||||||
"enableImages": true,
|
"enableImages": true,
|
||||||
"maxImages": 3
|
"maxImages": 3
|
||||||
|
},
|
||||||
|
"bank": {
|
||||||
|
"showNotifications": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+25
-12
@@ -59,6 +59,31 @@ setTimeout(() => {
|
|||||||
)
|
)
|
||||||
}, 1000)
|
}, 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(() => {
|
setTimeout(() => {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
@@ -155,18 +180,6 @@ setTimeout(() => {
|
|||||||
);
|
);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
window.dispatchEvent(
|
|
||||||
new MessageEvent("message", {
|
|
||||||
data: {
|
|
||||||
app: "PHONE",
|
|
||||||
method: "setVisibility",
|
|
||||||
data: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new MessageEvent("message", {
|
new MessageEvent("message", {
|
||||||
|
|||||||
@@ -31,6 +31,11 @@
|
|||||||
color: #388CF8 !important;
|
color: #388CF8 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#bank-app .MuiSnackbar-root {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
#bank-title {
|
#bank-title {
|
||||||
font-family: 'Bebas Neue', cursive;
|
font-family: 'Bebas Neue', cursive;
|
||||||
font-size: 50px;
|
font-size: 50px;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { NavigationBar } from "./navigation/NavigationBar";
|
|||||||
import { BankHome } from './home/BankHome';
|
import { BankHome } from './home/BankHome';
|
||||||
import { BankAccount } from './account/BankAccount';
|
import { BankAccount } from './account/BankAccount';
|
||||||
import { TransactionList } from "./transactions/TransactionList";
|
import { TransactionList } from "./transactions/TransactionList";
|
||||||
|
import { BankAlert } from "./alert/BankAlert";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -67,6 +68,7 @@ export const BankApp = () => {
|
|||||||
<Route path="/bank/account" exact component={BankAccount} />
|
<Route path="/bank/account" exact component={BankAccount} />
|
||||||
<Route path="/bank/transactions" exact component={TransactionList} />
|
<Route path="/bank/transactions" exact component={TransactionList} />
|
||||||
</Switch>
|
</Switch>
|
||||||
|
<BankAlert />
|
||||||
</AppContent>
|
</AppContent>
|
||||||
<NavigationBar />
|
<NavigationBar />
|
||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import React from "react";
|
||||||
|
import MuiAlert from "@material-ui/lab/Alert";
|
||||||
|
|
||||||
|
export function Alert(props) {
|
||||||
|
return <MuiAlert elevation={6} variant="filled" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Alert;
|
||||||
@@ -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 (
|
||||||
|
<Snackbar
|
||||||
|
style={{ width: "80%" }}
|
||||||
|
open={open}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
onClose={_handleClose}
|
||||||
|
>
|
||||||
|
<Alert onClose={_handleClose} severity={severity}>
|
||||||
|
{message}
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,16 +1,45 @@
|
|||||||
import React from 'react'
|
import React, { useEffect, useState } from "react";
|
||||||
import Alert from '@material-ui/lab/Alert';
|
import Notification from "../../../../ui/components/Notification";
|
||||||
import Notification from '../../../../ui/components/Notification';
|
import { usePhone } from "../../../../os/phone/hooks/usePhone";
|
||||||
import { useBankAlert } from './../../hooks/useBankAlert';
|
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 = ({ alert }) => {
|
export const BankNotification = () => {
|
||||||
const { setBankAlert } = useBankAlert();
|
const { notification } = useBankNotification()
|
||||||
|
const classes = useStyles()
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [visible, setVisible ] = useState(false);
|
||||||
|
const { config } = usePhone()
|
||||||
|
|
||||||
const handleClose = () => {
|
useEffect(() => {
|
||||||
setBankAlert(false)
|
if (notification) {
|
||||||
}
|
setVisible(true);
|
||||||
|
}
|
||||||
|
}, [notification?.id])
|
||||||
|
|
||||||
|
if (!config?.bank.showNotifications || !notification) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div></div>
|
<Notification
|
||||||
|
key={notification.id}
|
||||||
|
open={visible}
|
||||||
|
handleClose={() => setVisible(false)}
|
||||||
|
>
|
||||||
|
<div className={classes.content}>
|
||||||
|
<div className={classes.title}>
|
||||||
|
<div className={classes.titleLeft}>
|
||||||
|
<div className={classes.icon}>
|
||||||
|
<FontAwesomeIcon icon={faWonSign} />
|
||||||
|
</div>
|
||||||
|
<div className={classes.heading}>{notification.type}</div>
|
||||||
|
</div>
|
||||||
|
<div className={classes.justNow}>{t("APPS_BANK_TIME_JUST_NOW")}</div>
|
||||||
|
</div>
|
||||||
|
<div className={classes.message}>{notification.source} sent you ${notification.transferAmount}. <br></br> {notification.message}</div>
|
||||||
|
</div>
|
||||||
|
</Notification>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
@@ -6,6 +6,7 @@ import CloseIcon from '@material-ui/icons/Close';
|
|||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||||
|
|
||||||
import { useBankModal} from '../../hooks/useBankModal';
|
import { useBankModal} from '../../hooks/useBankModal';
|
||||||
|
import { Message } from '@material-ui/icons';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
input: {
|
input: {
|
||||||
@@ -50,15 +51,13 @@ export const TransferModal = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const addTransfer = () => {
|
const addTransfer = () => {
|
||||||
|
const transferAmount = parseInt(amount);
|
||||||
Nui.send('phone:addTransfer', {
|
Nui.send('phone:addTransfer', {
|
||||||
targetID,
|
targetID,
|
||||||
amount,
|
transferAmount,
|
||||||
message
|
message
|
||||||
})
|
})
|
||||||
setTimeout(() => {
|
setShowBankModal(false)
|
||||||
setShowBankModal(false)
|
|
||||||
}, 200)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -9,12 +9,16 @@ export const bankState = {
|
|||||||
key: 'modalVisibility',
|
key: 'modalVisibility',
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
bankAlert: atom({
|
transferSuccessful: atom({
|
||||||
key: 'bankAlert',
|
key: 'bankAlert',
|
||||||
default: false
|
default: null
|
||||||
}),
|
}),
|
||||||
bankCredentials: atom({
|
bankCredentials: atom({
|
||||||
key: 'bankCredentails',
|
key: 'bankCredentails',
|
||||||
default: null
|
default: null
|
||||||
|
}),
|
||||||
|
notification: atom({
|
||||||
|
key: 'bankNotification',
|
||||||
|
default: null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
import { bankState } from './state';
|
import { bankState } from './state';
|
||||||
|
|
||||||
export const useBankAlert = () => {
|
export const useBankAlert = (): any => {
|
||||||
const [ bankAlert, setBankAlert ] = useRecoilState(bankState.bankAlert);
|
const [ bankAlert, setBankAlert ] = useRecoilState(bankState.transferSuccessful);
|
||||||
return { bankAlert, setBankAlert };
|
return { bankAlert, setBankAlert };
|
||||||
}
|
}
|
||||||
@@ -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<Transfer | null>(bankState.notification);
|
||||||
|
return { notification }
|
||||||
|
}
|
||||||
@@ -2,12 +2,21 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
|||||||
import { bankState } from './state';
|
import { bankState } from './state';
|
||||||
import { useTransactions } from './useTransactions'
|
import { useTransactions } from './useTransactions'
|
||||||
import { useCredentials } from './useCredentials';
|
import { useCredentials } from './useCredentials';
|
||||||
|
import { useBankAlert } from './useBankAlert';
|
||||||
import { useSetRecoilState } from 'recoil'
|
import { useSetRecoilState } from 'recoil'
|
||||||
|
import { useBankNotification } from './useBankNotification';
|
||||||
|
|
||||||
export const useBankService = () => {
|
export const useBankService = () => {
|
||||||
const setTransaction = useSetRecoilState(bankState.transactions)
|
const setTransaction = useSetRecoilState(bankState.transactions)
|
||||||
const setCredentials = useSetRecoilState(bankState.bankCredentials)
|
const setCredentials = useSetRecoilState(bankState.bankCredentials)
|
||||||
|
const setAlertMessage = useSetRecoilState(bankState.transferSuccessful)
|
||||||
|
const setNotification = useSetRecoilState(bankState.notification);
|
||||||
|
|
||||||
|
///
|
||||||
|
|
||||||
useNuiEvent('BANK', 'setTransaction', setTransaction);
|
useNuiEvent('BANK', 'setTransaction', setTransaction);
|
||||||
useNuiEvent('BANK', 'setCredentials', setCredentials)
|
useNuiEvent('BANK', 'setCredentials', setCredentials);
|
||||||
return {useTransactions, useCredentials};
|
useNuiEvent('BANK', 'setAlert', setAlertMessage);
|
||||||
|
useNuiEvent('BANK', 'setNotification', setNotification);
|
||||||
|
return { useTransactions, useCredentials, useBankAlert, useBankNotification };
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
export interface Credentials {
|
||||||
|
name: string;
|
||||||
|
balance: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Transfer {
|
||||||
|
id: number;
|
||||||
|
targetID: number;
|
||||||
|
source: string;
|
||||||
|
type: string;
|
||||||
|
transferAmount: number;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -16,6 +16,10 @@ interface NotificationConfig {
|
|||||||
vertical: "bottom" | "top";
|
vertical: "bottom" | "top";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface BankConfig {
|
||||||
|
showNotifications: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ServerConfig {
|
export interface ServerConfig {
|
||||||
Locale: string;
|
Locale: string;
|
||||||
KeyTogglePhone: number;
|
KeyTogglePhone: number;
|
||||||
@@ -26,5 +30,6 @@ export interface ServerConfig {
|
|||||||
DestoryChance: number;
|
DestoryChance: number;
|
||||||
DestroyPhoneReCheck: number;
|
DestroyPhoneReCheck: number;
|
||||||
twitter: TwitterConfig;
|
twitter: TwitterConfig;
|
||||||
|
bank: BankConfig;
|
||||||
notificationPosition: NotificationConfig;
|
notificationPosition: NotificationConfig;
|
||||||
}
|
}
|
||||||
@@ -8,11 +8,13 @@ import "./main.css";
|
|||||||
import Phone from "./Phone";
|
import Phone from "./Phone";
|
||||||
import * as serviceWorker from "./serviceWorker";
|
import * as serviceWorker from "./serviceWorker";
|
||||||
import TwitterNotification from "./apps/twitter/components/notification/TwitterNotification";
|
import TwitterNotification from "./apps/twitter/components/notification/TwitterNotification";
|
||||||
|
import { BankNotification } from "./apps/bank/components/notification/BankNotification";
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<HashRouter>
|
<HashRouter>
|
||||||
<RecoilRoot>
|
<RecoilRoot>
|
||||||
<TwitterNotification />
|
<TwitterNotification />
|
||||||
|
<BankNotification />
|
||||||
<Phone />
|
<Phone />
|
||||||
</RecoilRoot>
|
</RecoilRoot>
|
||||||
</HashRouter>,
|
</HashRouter>,
|
||||||
|
|||||||
@@ -41,10 +41,13 @@
|
|||||||
|
|
||||||
"APPS_BANK_HOME_TITLE": "Welcome",
|
"APPS_BANK_HOME_TITLE": "Welcome",
|
||||||
"APPS_BANK_ACCOUNT_LINK": "Account",
|
"APPS_BANK_ACCOUNT_LINK": "Account",
|
||||||
|
"APPS_BANK_TIME_JUST_NOW": "Just now",
|
||||||
"APPS_BANK_ACCOUNT_TITLE": "Account Summary",
|
"APPS_BANK_ACCOUNT_TITLE": "Account Summary",
|
||||||
"APPS_BANK_ACCOUNT_TRANSACTIONS": "Transactions",
|
"APPS_BANK_ACCOUNT_TRANSACTIONS": "Transactions",
|
||||||
"APPS_BANK_ACCOUNT_SEE_TRANSACTION": "See all",
|
"APPS_BANK_ACCOUNT_SEE_TRANSACTION": "See all",
|
||||||
"APPS_BANK_ACTIONS_TRANSFER": "Transfer",
|
"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_NAME": "Name",
|
||||||
"APPS_CONTACT_FORM_NUMBER": "Number",
|
"APPS_CONTACT_FORM_NUMBER": "Number",
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function Notification({ children, handleClose, open }) {
|
|||||||
<Snackbar
|
<Snackbar
|
||||||
className={classes.snackBar}
|
className={classes.snackBar}
|
||||||
anchorOrigin={{ horizontal, vertical }}
|
anchorOrigin={{ horizontal, vertical }}
|
||||||
ClickAwayListenerProps={{ onClickAway: () => null }}
|
ClickAwayListenerProps={{ onClickAway: () => setTimeout(() => { handleClose() }, 5000) }}
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
open={open}
|
open={open}
|
||||||
TransitionComponent={Fade}
|
TransitionComponent={Fade}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ onNet(events.BANK_SEND_TRANSFERS, (transfer: any) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => {
|
onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => {
|
||||||
console.log("Client:", credentials.balance, credentials.name)
|
|
||||||
SendNuiMessage(
|
SendNuiMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
app: "BANK",
|
app: "BANK",
|
||||||
@@ -26,8 +25,28 @@ RegisterNuiCallbackType(events.BANK_ADD_TRANSFER);
|
|||||||
on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => {
|
on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => {
|
||||||
const transfer = data;
|
const transfer = data;
|
||||||
emitNet(events.BANK_ADD_TRANSFER, transfer)
|
emitNet(events.BANK_ADD_TRANSFER, transfer)
|
||||||
|
})
|
||||||
|
|
||||||
setTimeout(() => {
|
onNet(events.BANK_ADD_TRANSFER_SUCCESS, () => {
|
||||||
emitNet(events.BANK_FETCH_TRANSACTIONS);
|
emitNet(events.BANK_FETCH_TRANSACTIONS);
|
||||||
}, 500)
|
})
|
||||||
|
|
||||||
|
onNet(events.BANK_TRANSACTION_ALERT, (bool: boolean) => {
|
||||||
|
SendNuiMessage(
|
||||||
|
JSON.stringify({
|
||||||
|
app: 'BANK',
|
||||||
|
method: 'setAlert',
|
||||||
|
data: bool
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
onNet(events.BANK_TRANSACTION_NOTIFICATION, (transfer: any) => {
|
||||||
|
SendNuiMessage(
|
||||||
|
JSON.stringify({
|
||||||
|
app: "BANK",
|
||||||
|
method: 'setNotification',
|
||||||
|
data: transfer
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
+48
-36
@@ -1,18 +1,9 @@
|
|||||||
import events from '../utils/events';
|
import events from '../utils/events';
|
||||||
import { ESX, getSource } from './server';
|
import { ESX, getSource } from './server';
|
||||||
import { pool } from './db';
|
import { pool } from './db';
|
||||||
import { resourceLimits } from 'worker_threads';
|
import { Transfer, Credentials } from '../../phone/src/common/interfaces/bank';
|
||||||
|
import { useIdentifier } from './functions';
|
||||||
interface Transfer {
|
import { type } from 'os';
|
||||||
targetID: string;
|
|
||||||
amount: number;
|
|
||||||
message: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Credentials {
|
|
||||||
name: string;
|
|
||||||
balance: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
|
async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
|
||||||
@@ -32,63 +23,84 @@ function fetchCredentials(): Credentials {
|
|||||||
balance
|
balance
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(result.name, result.balance);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function addTransfer(identifier: string, transfer: Transfer): Promise<any> {
|
async function addTransfer(identifier: string, transfer: Transfer): Promise<any> {
|
||||||
|
|
||||||
const xPlayer = ESX.GetPlayerFromId(getSource())
|
const xPlayer = ESX.GetPlayerFromId(getSource())
|
||||||
const bankBalance = xPlayer.getAccount('bank').money;
|
const bankBalance = xPlayer.getAccount('bank').money;
|
||||||
console.log(bankBalance)
|
const sourceName = xPlayer.getName()
|
||||||
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, [
|
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
|
||||||
|
|
||||||
|
|
||||||
|
if (transfer.transferAmount > bankBalance) {
|
||||||
|
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false)
|
||||||
|
}
|
||||||
|
else if (transfer.transferAmount < bankBalance) {
|
||||||
|
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true);
|
||||||
|
|
||||||
|
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,
|
identifier,
|
||||||
transfer.targetID,
|
transfer.targetID,
|
||||||
transfer.amount,
|
transfer.transferAmount,
|
||||||
transfer.message
|
transfer.message,
|
||||||
|
"Transfer",
|
||||||
|
sourceName,
|
||||||
])
|
])
|
||||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You succesfully transferred money to someone', 'success')
|
const insertData = <any>results;
|
||||||
|
return await getTransfer(insertData.insertId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a transfer from its ID
|
||||||
|
* @param transferId - transfer id
|
||||||
|
*/
|
||||||
|
async function getTransfer(transferId: number): Promise<Transfer> {
|
||||||
|
const query = "SELECT * FROM npwd_bank_transfers WHERE id = ?"
|
||||||
|
const [ results ] = await pool.query(query, [transferId]);
|
||||||
|
const transfers = <Transfer[]>results;
|
||||||
|
const transfer = transfers[0];
|
||||||
|
return {...transfer};
|
||||||
|
}
|
||||||
|
|
||||||
onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
|
onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
|
||||||
try {
|
try {
|
||||||
const _source = (global as any).source;
|
const _source = (global as any).source;
|
||||||
const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier()
|
const _identifier = await useIdentifier()
|
||||||
const transfer = await fetchAllTransactions(_identifier);
|
const transfer = await fetchAllTransactions(_identifier);
|
||||||
|
|
||||||
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer)
|
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer)
|
||||||
console.log("WOORK")
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Failed to fetch transactions', error)
|
console.log("Failed to fetch transactions");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onNet(events.BANK_ADD_TRANSFER, (transfer: Transfer) => {
|
onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => {
|
||||||
|
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
|
||||||
|
const targetSource = xTarget.source;
|
||||||
try {
|
try {
|
||||||
const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier()
|
const _identifier = await useIdentifier()
|
||||||
addTransfer(_identifier, transfer)
|
const transferNotify = await addTransfer(_identifier, transfer)
|
||||||
|
emitNet(events.BANK_TRANSACTION_NOTIFICATION, targetSource, transferNotify)
|
||||||
|
emitNet(events.BANK_ADD_TRANSFER_SUCCESS, getSource());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Failed to add transfer', error)
|
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onNet(events.BANK_GET_CREDENTIALS, () => {
|
onNet(events.BANK_GET_CREDENTIALS, () => {
|
||||||
try {
|
try {
|
||||||
const credentials = fetchCredentials()
|
const credentials = fetchCredentials()
|
||||||
console.log("New log: ", credentials.balance, credentials.name)
|
|
||||||
emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials)
|
emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log("Failed to fetch credentials");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -45,9 +45,11 @@ export default {
|
|||||||
|
|
||||||
// Bank
|
// Bank
|
||||||
BANK_ADD_TRANSFER: 'phone:addTransfer',
|
BANK_ADD_TRANSFER: 'phone:addTransfer',
|
||||||
|
BANK_ADD_TRANSFER_SUCCESS: 'phone:addTransferSuccess',
|
||||||
BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions',
|
BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions',
|
||||||
BANK_SEND_TRANSFERS: 'phone:sendTransfers',
|
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_SEND_CREDENTIALS: 'phone:sendBankCredentials',
|
||||||
BANK_GET_CREDENTIALS: 'phone:getBankCredentials',
|
BANK_GET_CREDENTIALS: 'phone:getBankCredentials',
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user