-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Initial Swaps amount view (#1994)
Co-authored-by: Esteban Mino <[email protected]>
- Loading branch information
1 parent
326df28
commit 2898607
Showing
23 changed files
with
1,485 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.