Skip to content

Commit

Permalink
Fix: Issues raised on iOS QA (#325)
Browse files Browse the repository at this point in the history
* fix: consuming before receiving funds

* fix: AmountTextInput focus method

* fix: createToken navigation

* fix: AppStack no longer modal

* fix: back to dashboard on receive

* fix: improves keyboard avoiding distance

* fix: modal bottom margin

* fix: PinScreen incorrect keyboard

* style: removes unused variables

* refactor: removes optional chaining

If there is no property, it's better
to throw an error than to silence it.

* refactor: removes state

* fix: New Address button

* fix: modal bottom margin
  • Loading branch information
tuliomir authored Sep 19, 2023
1 parent 96fd404 commit df914d5
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ const AppStack = () => {
>
<Stack.Navigator
screenOptions={{
presentation: 'modal',
headerShown: false,
}}
>
Expand Down
8 changes: 7 additions & 1 deletion src/components/AmountTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ class AmountTextInput extends React.Component {
}

focus = () => {
this.inputRef.current.focus();
/* After the focus method is called, the screen is still re-rendered at least once more.
* Requesting a delay before the focus command ensures it is executed on the final rendering
* of the component.
*/
setTimeout(() => {
this.inputRef.current.focus();
}, 50);
}

onChangeText = (text) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/HathorHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Logo from './Logo';
import chevronLeft from '../assets/icons/chevron-left.png';
import closeIcon from '../assets/icons/icCloseActive.png';
import baseStyle from '../styles/init';
import { HEADER_HEIGHT } from '../constants';

const HathorHeader = (props) => {
const renderBackButton = () => {
Expand Down Expand Up @@ -75,7 +76,7 @@ const HathorHeader = (props) => {

const styles = StyleSheet.create({
wrapper: {
height: 56,
height: HEADER_HEIGHT,
flexDirection: 'row',
alignItems: 'center',
borderColor: '#eee',
Expand All @@ -95,5 +96,4 @@ const styles = StyleSheet.create({
alignItems: 'center',
},
});

export default HathorHeader;
14 changes: 6 additions & 8 deletions src/components/ModalConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import {
Dimensions, Image, Platform, StyleSheet, TouchableWithoutFeedback, View,
Dimensions, Image, StyleSheet, TouchableWithoutFeedback, View,
} from 'react-native';

import checkLogo from '../assets/images/icCheckBig.png';
Expand Down Expand Up @@ -41,11 +41,9 @@ class ModalConfirmation extends React.Component {
return null;
}

const { height, width } = Dimensions.get('window');

// Prevent the bottom message to be covered by some android phones
const marginBottom = Platform.OS === 'android' ? 40 : 16;
const { width } = Dimensions.get('window');

// Prevents the bottom message from being covered
const styles = StyleSheet.create({
modal: {
position: 'absolute',
Expand All @@ -55,11 +53,11 @@ class ModalConfirmation extends React.Component {
justifyContent: 'flex-end',
alignItems: 'center',
zIndex: 3,
height,
width,
height: '100%',
width: '100%',
},
innerModal: {
marginBottom,
marginBottom: 32,
height: 270,
backgroundColor: 'white',
alignItems: 'center',
Expand Down
6 changes: 6 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ export const MIN_JOB_ESTIMATION = 1;
*/
export const PIN_SIZE = 6;

/**
* Default Hathor Header height, used for recalculating layout offsets.
* @type {number}
*/
export const HEADER_HEIGHT = 56;

/**
* Unleash constants
*/
Expand Down
2 changes: 1 addition & 1 deletion src/screens/CreateTokenAmount.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class CreateTokenAmount extends React.Component {
<HathorHeader
title={t`CREATE TOKEN`}
onBackPress={() => this.props.navigation.goBack()}
onCancel={() => this.props.navigation.pop()}
onCancel={() => this.props.navigation.getParent().goBack()}
/>
<KeyboardAvoidingView behavior='padding' style={{ flex: 1 }} keyboardVerticalOffset={getKeyboardAvoidingViewTopDistance()}>
<View style={{ flex: 1, padding: 16, justifyContent: 'space-between' }}>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/CreateTokenConfirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class CreateTokenConfirm extends React.Component {
<HathorHeader
title={t`CREATE TOKEN`}
onBackPress={() => this.props.navigation.goBack()}
onCancel={() => this.props.navigation.pop()}
onCancel={() => this.props.navigation.getParent().goBack()}
/>

{ this.state.modal && (
Expand Down
2 changes: 1 addition & 1 deletion src/screens/CreateTokenName.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CreateTokenName extends React.Component {
<HathorHeader
title={t`CREATE TOKEN`}
onBackPress={() => this.props.navigation.pop()}
onCancel={() => this.props.navigation.pop()}
onCancel={() => this.props.navigation.getParent().goBack()}
/>
<KeyboardAvoidingView behavior='padding' style={{ flex: 1 }} keyboardVerticalOffset={getKeyboardAvoidingViewTopDistance()}>
<View style={{ flex: 1, padding: 16, justifyContent: 'space-between' }}>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/CreateTokenSymbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CreateTokenSymbol extends React.Component {
<HathorHeader
title={t`CREATE TOKEN`}
onBackPress={() => this.props.navigation.goBack()}
onCancel={() => this.props.navigation.pop()}
onCancel={() => this.props.navigation.getParent().goBack()}
/>
<KeyboardAvoidingView behavior='padding' style={{ flex: 1 }} keyboardVerticalOffset={getKeyboardAvoidingViewTopDistance()}>
<View style={{ flex: 1, padding: 16, justifyContent: 'space-between' }}>
Expand Down
20 changes: 17 additions & 3 deletions src/screens/PaymentRequestDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import OfflineBar from '../components/OfflineBar';
import TextFmt from '../components/TextFmt';
import { clearInvoice } from '../actions';
import { getTokenLabel, renderValue, isTokenNFT } from '../utils';
import NavigationService from '../NavigationService';

/**
* address {string} Invoice destination address
Expand All @@ -46,8 +47,9 @@ class PaymentRequestDetail extends React.Component {
}

async componentDidMount() {
// When we create a new payment request we update the address for a new one
await this.props.wallet.getNextAddress();
// When we create a new payment request, we don't update the address for a new one
// This will only happen when it receives a transaction and becomes a used address
await this.props.wallet.getCurrentAddress();
}

componentDidUpdate(prevProps) {
Expand All @@ -62,6 +64,18 @@ class PaymentRequestDetail extends React.Component {
this.props.dispatch(clearInvoice());
}

/**
* If the payment was not yet received, the user goes back to the "Select Amount" screen.
* Otherwise, goes directly to the Home screen to see the updated wallet.
*/
onBackClick() {
if (this.props.payment !== null) {
NavigationService.resetToMain();
} else {
this.props.navigation.goBack();
}
}

render() {
const { symbol } = this.props.token;
const isNFT = isTokenNFT(get(this.props, 'token.uid'), this.props.tokenMetadata);
Expand All @@ -88,7 +102,7 @@ class PaymentRequestDetail extends React.Component {
<HathorHeader
withBorder
title={t`PAYMENT REQUEST`}
onBackPress={() => this.props.navigation.goBack()}
onBackPress={() => this.onBackClick()}
/>
<View style={{
flex: 1, justifyContent: 'space-between', alignItems: 'center', width: '100%',
Expand Down
5 changes: 4 additions & 1 deletion src/screens/PinScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { t } from 'ttag';

import { BackHandler, Text, View } from 'react-native';
import { BackHandler, Keyboard, Text, View } from 'react-native';
import * as Keychain from 'react-native-keychain';
import { walletUtils, cryptoUtils } from '@hathor/wallet-lib';
import SimpleButton from '../components/SimpleButton';
Expand Down Expand Up @@ -76,6 +76,9 @@ class PinScreen extends React.Component {
}

componentDidMount() {
// If the keyboard is being shown, hide it. This screen's keyboard is built differently
Keyboard.dismiss();

const supportedBiometry = getSupportedBiometry();
const biometryEnabled = isBiometryEnabled();
if (supportedBiometry && biometryEnabled) {
Expand Down
12 changes: 7 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { t } from 'ttag';
import { Linking, Platform, Text } from 'react-native';
import { getStatusBarHeight } from 'react-native-status-bar-height';
import baseStyle from './styles/init';
import { PRIMARY_COLOR, KEYCHAIN_USER, networkObj } from './constants';
import { PRIMARY_COLOR, HEADER_HEIGHT, KEYCHAIN_USER, networkObj } from './constants';
import { STORE } from './store';
import { TxHistory } from './models';

Expand Down Expand Up @@ -243,10 +243,12 @@ function extractAddress(plainText) {
* @return {number} The top distance
*/
export const getKeyboardAvoidingViewTopDistance = () => {
if (Platform.OS === 'android') {
return getStatusBarHeight();
}
return 0;
const statusBarHeight = getStatusBarHeight();
const calculatedHeight = (Platform.OS === 'ios')
? statusBarHeight + HEADER_HEIGHT
: statusBarHeight;

return calculatedHeight;
};

/**
Expand Down

0 comments on commit df914d5

Please sign in to comment.