From 6e5daa2c5c5d02badf34b457c000dd8b04c2f2d5 Mon Sep 17 00:00:00 2001 From: Sergio k Date: Fri, 16 Jun 2023 15:24:04 +0300 Subject: [PATCH 01/12] fixed a bug with the visibility of text input when the keyboard is open --- app/components/screens/support/Field/Field.tsx | 12 +++++++++--- package.json | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/components/screens/support/Field/Field.tsx b/app/components/screens/support/Field/Field.tsx index 5336662..48cb826 100644 --- a/app/components/screens/support/Field/Field.tsx +++ b/app/components/screens/support/Field/Field.tsx @@ -6,7 +6,7 @@ import { Alert } from 'react-native'; import { useAuth } from '../../../../hooks/useAuth'; -import { useState } from 'react'; +import { useCallback, useState } from 'react'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { addDoc, serverTimestamp } from 'firebase/firestore'; import { collection } from '@firebase/firestore'; @@ -15,6 +15,11 @@ import { db } from '../../../../utils/firebase'; export const Field = () => { const { user } = useAuth(); const [message, setMessage] = useState(''); + const [isKeyPress, setIsKeyPress] = useState(false); + + const handleChangeKeyPress = useCallback(() => { + setIsKeyPress((prevState) => !prevState); + }, []) const handleSendMessage = async () => { try { @@ -32,13 +37,15 @@ export const Field = () => { }; return ( - + @@ -59,7 +66,6 @@ const styles = StyleSheet.create({ alignItems: 'center', justifyContent: 'space-between', paddingVertical: 4, - bottom: 40 }, input: { backgroundColor: '#f7fafc', diff --git a/package.json b/package.json index e9ced49..498ee69 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "firebase": "^9.22.1", "react": "18.2.0", "react-native": "0.71.8", + "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-safe-area-context": "4.5.0", "react-native-screens": "~3.20.0", "react-native-stories-view": "^1.0.9", From 97d7370f44c6dbb9e278ab581cebb8c2678e7c7d Mon Sep 17 00:00:00 2001 From: Sergio k Date: Mon, 19 Jun 2023 14:25:56 +0300 Subject: [PATCH 02/12] added the ability to transfer money from the selected card --- .../screens/home/stories/StoryItem.tsx | 5 +-- .../more/ExchangeRate/ExchangeRate.tsx | 2 +- .../contacts/ContactItem/ContactItem.tsx | 28 ++++++++----- .../screens/support/Field/Field.tsx | 2 +- app/hooks/useSendMoney.ts | 41 +++++++++++++++++++ 5 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 app/hooks/useSendMoney.ts diff --git a/app/components/screens/home/stories/StoryItem.tsx b/app/components/screens/home/stories/StoryItem.tsx index be0608d..9ea5e9d 100644 --- a/app/components/screens/home/stories/StoryItem.tsx +++ b/app/components/screens/home/stories/StoryItem.tsx @@ -28,7 +28,7 @@ export const StoryItem: FC = (props) => { source={{ uri: story.images[0] }} resizeMode='cover' style={styles.image} - imageStyle={{ borderRadius: 12 }} + imageStyle={{ borderRadius: 8 }} > {story.heading} @@ -43,9 +43,8 @@ const styles = StyleSheet.create({ height: 100, borderRadius: 12, marginLeft: 16, - borderWidth: 1, + borderWidth: 3, borderColor: '#00f', - padding: 5 }, image: { width: '100%', diff --git a/app/components/screens/more/ExchangeRate/ExchangeRate.tsx b/app/components/screens/more/ExchangeRate/ExchangeRate.tsx index 8d783dd..2d82510 100644 --- a/app/components/screens/more/ExchangeRate/ExchangeRate.tsx +++ b/app/components/screens/more/ExchangeRate/ExchangeRate.tsx @@ -10,7 +10,7 @@ import { BOX_SHADOW } from '../../../../utils/styles'; export const ExchangeRate: FC = () => { const [base, setBase] = useState([]); - const [realRates, setRealRates] = useState({} as Omit);//{"EUR": 41.2507, "PLN": 0, "USD": 37.4406} + const [realRates, setRealRates] = useState({} as Omit); const fetchExchangeRate = useCallback(async () => { try { diff --git a/app/components/screens/payments/contacts/ContactItem/ContactItem.tsx b/app/components/screens/payments/contacts/ContactItem/ContactItem.tsx index 09e2dce..5c7341e 100644 --- a/app/components/screens/payments/contacts/ContactItem/ContactItem.tsx +++ b/app/components/screens/payments/contacts/ContactItem/ContactItem.tsx @@ -4,12 +4,13 @@ import { StyleSheet, View, } from 'react-native'; -import { FC, useState } from 'react'; +import { FC, useCallback, useState } from 'react'; import { IContact } from '../../../../../typedefs/typedefs'; import { Avatar } from '../../../../ui/Avatar'; import { useAccounts } from '../../../../../hooks/useAccounts'; import { handleTransfer } from '../../handleTransfer'; import { ModalWindow } from '../../../../ui/ModalWindow'; +import { useSendMoney } from '../../../../../hooks/useSendMoney'; interface Props { contact: IContact, @@ -19,22 +20,29 @@ export const ContactItem: FC = (props) => { const { contact } = props; const { accounts } = useAccounts(); const [transferAmount, setTransferAmount] = useState(''); - const [showModal, setShowModal] = useState(false); - const handleTransferPress = () => { - setShowModal(true); - }; + const { + setCardName, + cardName, + setShowModal, + showModal, + sendMoney + } = useSendMoney(); - const handleTransferConfirm = async () => { - await handleTransfer(accounts[0], contact.cardNumber, transferAmount); + const handleTransferConfirm = useCallback(async (transferAmount: string) => { + const cardNumber = accounts.find(el => el.name === cardName); + + if (cardNumber) { + await handleTransfer(cardNumber, contact.cardNumber, transferAmount); + } setTransferAmount(''); setShowModal(false); - }; + }, [cardName, setCardName]); return ( - + {contact.displayName} @@ -45,7 +53,7 @@ export const ContactItem: FC = (props) => { setShowModal={setShowModal} setTransferAmount={setTransferAmount} transferAmount={transferAmount} - handleTransferConfirm={handleTransferConfirm} + handleTransferConfirm={() => handleTransferConfirm(transferAmount)} /> ); diff --git a/app/components/screens/support/Field/Field.tsx b/app/components/screens/support/Field/Field.tsx index 48cb826..38203d7 100644 --- a/app/components/screens/support/Field/Field.tsx +++ b/app/components/screens/support/Field/Field.tsx @@ -37,7 +37,7 @@ export const Field = () => { }; return ( - + { + const [showModal, setShowModal] = useState(false); + const [cardName, setCardName] = useState(); + + const handleTransferPress = () => { + setShowModal(true); + }; + + const sendMoney = async () => { + try { + const cardType = await asyncAlert({ + title: 'Credit cards', + message: 'Select card:', + buttons: { + text: 'Mono Black', + resolveValue: 'Mono Black', + textSecond: 'Mono White', + resolveValueSecond: 'Mono White' + }, + }) + + setCardName(cardType as any); + handleTransferPress(); + } catch (error: any) { + Alert.alert('Error selecting', error.message) + } + }; + + return { + showModal, + setShowModal, + cardName, + setCardName, + sendMoney, + } +} From e00b2c135044739b12d5149edb6aa1e4968d3bb5 Mon Sep 17 00:00:00 2001 From: Sergio k Date: Mon, 19 Jun 2023 14:49:32 +0300 Subject: [PATCH 03/12] added the ability to select a credit card when transferring by card number --- .../TransferByCardNumber.tsx | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/components/screens/payments/contacts/TransferByCardNumber/TransferByCardNumber.tsx b/app/components/screens/payments/contacts/TransferByCardNumber/TransferByCardNumber.tsx index 4a39204..15f7bf8 100644 --- a/app/components/screens/payments/contacts/TransferByCardNumber/TransferByCardNumber.tsx +++ b/app/components/screens/payments/contacts/TransferByCardNumber/TransferByCardNumber.tsx @@ -1,16 +1,23 @@ -import { FC, useState } from 'react'; +import { FC, useCallback, useState } from 'react'; import { StyleSheet, View } from 'react-native'; import { handleTransfer } from '../../../payments/handleTransfer'; import { useAccounts } from '../../../../../hooks/useAccounts'; import { Button } from '../../../../../components/ui/Button'; import { ModalWindow } from '../../../../ui/ModalWindow'; +import { useSendMoney } from '../../../../../hooks/useSendMoney'; export const TransferByCardNumber: FC = () => { const [transferAmount, setTransferAmount] = useState(''); const [cardNumber, setCardNumber] = useState(''); - const [showModal, setShowModal] = useState(false); const { accounts } = useAccounts(); + const { + setCardName, + cardName, + setShowModal, + showModal, + sendMoney + } = useSendMoney(); const addSpacesToCardNumber = (cardNumber: string) => { const cardNumberArray = Array.from(cardNumber); @@ -24,21 +31,25 @@ export const TransferByCardNumber: FC = () => { }).join(''); }; - const handleTransferConfirm = async () => { + const handleTransferConfirm = useCallback(async (cardNumber: string, transferAmount: string) => { const cardNumberWithSpaces = addSpacesToCardNumber(cardNumber); - await handleTransfer(accounts[0], cardNumberWithSpaces, transferAmount); + const cardN = accounts.find(el => el.name === cardName); + + if (cardN) { + await handleTransfer(cardN, cardNumberWithSpaces, transferAmount); + } setCardNumber(''); setTransferAmount(''); setShowModal(false); - }; + }, [cardName, setCardName]); return ( <>