Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Initial Swaps amount view #1994

Merged
merged 24 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5f03198
Add SWAPS.ACTIVE flag
wachunei Nov 6, 2020
3173290
Update snapshot for main nav
wachunei Nov 6, 2020
0696f10
Add Keypad rules and swap token button
wachunei Nov 9, 2020
8644be0
Switch Swaps feature flag to false
wachunei Nov 10, 2020
707b491
Add Initial Token Selector with dummy tokens
wachunei Nov 11, 2020
2367393
package
estebanmino Nov 10, 2020
4f4e87f
inception
estebanmino Nov 11, 2020
c69c414
Add tokens from SwapsController
wachunei Nov 11, 2020
36a2289
Update Receiver Modal snapshot, it uses ModalHandler now
wachunei Nov 11, 2020
65a31a6
bumpcontrollers
estebanmino Nov 12, 2020
539d1e7
Add empty list message and clear search on modal hide
wachunei Nov 12, 2020
6ca34c9
Add invalid decimal warning
wachunei Nov 12, 2020
b262b4e
Add token balances in token search modal list
wachunei Nov 13, 2020
4bb4bcb
Add asset balance in swaps amount view
wachunei Nov 13, 2020
54c17c2
Remove unused key in token search for swaps
wachunei Nov 13, 2020
6dfd9a4
Fix TokenIcon border radius
wachunei Nov 13, 2020
637452f
Add i18n to swaps amount view
wachunei Nov 16, 2020
f9ba8af
Add TokenSelectButton label prop to test
wachunei Nov 16, 2020
94a14dd
Update main navigation snapshot
wachunei Nov 16, 2020
1662700
bumpcontrollers
estebanmino Nov 17, 2020
24b5456
Update tokens dependency for effect
wachunei Nov 17, 2020
d552524
Remove unnecessary styling
wachunei Nov 17, 2020
3bcdb37
Fix token select modal when keyboard is open
wachunei Dec 9, 2020
0d22484
Merge branch 'develop' into feature/swaps-amount-view
wachunei Dec 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions app/components/Base/Keypad/rules/native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const hasOneDigit = /^\d$/;

function handleInput(currentAmount, inputKey) {
switch (inputKey) {
case 'PERIOD': {
if (currentAmount === '0') {
return `${currentAmount}.`;
}
if (currentAmount.includes('.')) {
return currentAmount;
}

return `${currentAmount}.`;
}
case 'BACK': {
if (currentAmount === '0') {
return currentAmount;
}
if (hasOneDigit.test(currentAmount)) {
return '0';
}

return currentAmount.slice(0, -1);
}
case '0': {
if (currentAmount === '0') {
return currentAmount;
}
return `${currentAmount}${inputKey}`;
}
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': {
if (currentAmount === '0') {
return inputKey;
}

return `${currentAmount}${inputKey}`;
}
default: {
return currentAmount;
}
}
}

export default handleInput;
64 changes: 64 additions & 0 deletions app/components/Base/Keypad/rules/usd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const hasOneDigit = /^\d$/;
const hasTwoDecimals = /^\d+\.\d{2}$/;
const avoidZerosAsDecimals = false;
const hasZeroAsFirstDecimal = /^\d+\.0$/;

function handleUSDInput(currentAmount, inputKey) {
switch (inputKey) {
case 'PERIOD': {
if (currentAmount === '0') {
return `${currentAmount}.`;
}
if (currentAmount.includes('.')) {
return currentAmount;
}

return `${currentAmount}.`;
}
case 'BACK': {
if (currentAmount === '0') {
return currentAmount;
}
if (hasOneDigit.test(currentAmount)) {
return '0';
}

return currentAmount.slice(0, -1);
}
case '0': {
if (currentAmount === '0') {
return currentAmount;
}
if (hasTwoDecimals.test(currentAmount)) {
return currentAmount;
}
if (avoidZerosAsDecimals && hasZeroAsFirstDecimal.test(currentAmount)) {
return currentAmount;
}
return `${currentAmount}${inputKey}`;
}
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': {
if (currentAmount === '0') {
return inputKey;
}
if (hasTwoDecimals.test(currentAmount)) {
return currentAmount;
}

return `${currentAmount}${inputKey}`;
}
default: {
return currentAmount;
}
}
}

export default handleUSDInput;
10 changes: 6 additions & 4 deletions app/components/Base/ListItem.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, View } from 'react-native';
import Device from '../../util/Device';
// import Device from '../../util/Device';
import { colors, fontStyles } from '../../styles/common';
import Text from './Text';

const styles = StyleSheet.create({
wrapper: {
padding: 15,
minHeight: Device.isIos() ? 95 : 100
padding: 15
// TODO(wachunei): check if this can be removed without breaking anything
// minHeight: Device.isIos() ? 55 : 100
},
date: {
color: colors.fontSecondary,
Expand All @@ -17,7 +18,8 @@ const styles = StyleSheet.create({
...fontStyles.normal
},
content: {
flexDirection: 'row'
flexDirection: 'row',
alignItems: 'center'
},
actions: {
flexDirection: 'row',
Expand Down
32 changes: 32 additions & 0 deletions app/components/Base/ModalDragger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { colors } from '../../styles/common';
import Device from '../../util/Device';

const styles = StyleSheet.create({
draggerWrapper: {
width: '100%',
height: 33,
alignItems: 'center',
justifyContent: 'center',
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: colors.grey100
},
dragger: {
width: 48,
height: 5,
borderRadius: 4,
backgroundColor: colors.grey400,
opacity: Device.isAndroid() ? 0.6 : 0.5
}
});

function ModalDragger() {
return (
<View style={styles.draggerWrapper}>
<View style={styles.dragger} />
</View>
);
}

export default ModalDragger;
8 changes: 2 additions & 6 deletions app/components/Base/ModalHandler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { useState } from 'react';
import useModalHandler from './hooks/useModalHandler';

function ModalHandler({ children }) {
const [isVisible, setVisible] = useState(false);

const showModal = () => setVisible(true);
const hideModal = () => setVisible(true);
const toggleModal = () => setVisible(!isVisible);
const [isVisible, toggleModal, showModal, hideModal] = useModalHandler(false);

if (typeof children === 'function') {
return children({ isVisible, toggleModal, showModal, hideModal });
Expand Down
11 changes: 11 additions & 0 deletions app/components/Base/hooks/useModalHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useState } from 'react';
function useModalHandler(initialState = false) {
const [isVisible, setVisible] = useState(initialState);

const showModal = () => setVisible(true);
const hideModal = () => setVisible(true);
const toggleModal = () => setVisible(!isVisible);

return [isVisible, toggleModal, showModal, hideModal];
}
export default useModalHandler;
67 changes: 2 additions & 65 deletions app/components/UI/FiatOrders/PaymentMethodApplePay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Logger from '../../../../util/Logger';
import { setLockTime } from '../../../../actions/settings';
import { strings } from '../../../../../locales/i18n';
import { getNotificationDetails } from '..';
import handleUSDInput from '../../../Base/Keypad/rules/usd';

import {
useWyreTerms,
Expand Down Expand Up @@ -129,73 +130,9 @@ const quickAmounts = ['50', '100', '250'];
const minAmount = 50;
const maxAmount = 250;

const hasTwoDecimals = /^\d+\.\d{2}$/;
const hasZeroAsFirstDecimal = /^\d+\.0$/;
const hasZerosAsDecimals = /^\d+\.00$/;
const hasOneDigit = /^\d$/;
const hasPeriodWithoutDecimal = /^\d+\.$/;
const avoidZerosAsDecimals = false;

//* Handlers

const handleNewAmountInput = (currentAmount, newInput) => {
switch (newInput) {
case 'PERIOD': {
if (currentAmount === '0') {
return `${currentAmount}.`;
}
if (currentAmount.includes('.')) {
// TODO: throw error for feedback?
return currentAmount;
}

return `${currentAmount}.`;
}
case 'BACK': {
if (currentAmount === '0') {
return currentAmount;
}
if (hasOneDigit.test(currentAmount)) {
return '0';
}

return currentAmount.slice(0, -1);
}
case '0': {
if (currentAmount === '0') {
return currentAmount;
}
if (hasTwoDecimals.test(currentAmount)) {
return currentAmount;
}
if (avoidZerosAsDecimals && hasZeroAsFirstDecimal.test(currentAmount)) {
return currentAmount;
}
return `${currentAmount}${newInput}`;
}
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': {
if (currentAmount === '0') {
return newInput;
}
if (hasTwoDecimals.test(currentAmount)) {
return currentAmount;
}

return `${currentAmount}${newInput}`;
}
default: {
return currentAmount;
}
}
};

function PaymentMethodApplePay({
lockTime,
Expand Down Expand Up @@ -258,7 +195,7 @@ function PaymentMethodApplePay({
if (isOverMaximum && newInput !== 'BACK') {
return;
}
const newAmount = handleNewAmountInput(amount, newInput);
const newAmount = handleUSDInput(amount, newInput);
if (newAmount === amount) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,7 @@ exports[`ReceiveRequest should render correctly 1`] = `
}
}
>
<View
style={
Object {
"alignItems": "center",
"borderBottomWidth": 0.5,
"borderColor": "#d6d9dc",
"height": 33,
"justifyContent": "center",
"width": "100%",
}
}
>
<View
style={
Object {
"backgroundColor": "#848c96",
"borderRadius": 4,
"height": 5,
"opacity": 0.5,
"width": 48,
}
}
/>
</View>
<ModalDragger />
<View
style={
Object {
Expand Down
20 changes: 2 additions & 18 deletions app/components/UI/ReceiveRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { protectWalletModalVisible } from '../../../actions/user';
import { colors, fontStyles } from '../../../styles/common';
import Text from '../../Base/Text';
import ModalHandler from '../../Base/ModalHandler';
import ModalDragger from '../../Base/ModalDragger';
import AddressQRCode from '../../Views/AddressQRCode';
import EthereumAddress from '../EthereumAddress';
import GlobalAlert from '../GlobalAlert';
Expand All @@ -33,21 +34,6 @@ const styles = StyleSheet.create({
borderTopLeftRadius: 10,
borderTopRightRadius: 10
},
draggerWrapper: {
width: '100%',
height: 33,
alignItems: 'center',
justifyContent: 'center',
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: colors.grey100
},
dragger: {
width: 48,
height: 5,
borderRadius: 4,
backgroundColor: colors.grey400,
opacity: Device.isAndroid() ? 0.6 : 0.5
},
body: {
alignItems: 'center',
paddingHorizontal: 15
Expand Down Expand Up @@ -222,9 +208,7 @@ class ReceiveRequest extends PureComponent {
render() {
return (
<SafeAreaView style={styles.wrapper}>
<View style={styles.draggerWrapper}>
<View style={styles.dragger} />
</View>
<ModalDragger />
<View style={styles.titleWrapper}>
<Text style={styles.title} testID={'receive-request-screen'}>
{strings('receive_request.title')}
Expand Down
Loading