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

feat: add components for nano contract transactions [9] #456

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion locale/da/texts.po
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ msgstr "[Sidste] dddd [•] HH:mm"
msgid "DD MMM YYYY [•] HH:mm"
msgstr "DD MMM YYYY [•] HH:mm"

#: src/utils.js:159
#: src/utils.js:160
msgid "Invalid address"
msgstr "Ugyldig adresse"

Expand Down
2 changes: 1 addition & 1 deletion locale/pt-br/texts.po
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ msgstr "[Última] dddd [•] HH:mm"
msgid "DD MMM YYYY [•] HH:mm"
msgstr "DD MMM YYYY [•] HH:mm"

#: src/utils.js:159
#: src/utils.js:160
msgid "Invalid address"
msgstr "Endereço inválido"

Expand Down
2 changes: 1 addition & 1 deletion locale/ru-ru/texts.po
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ msgstr "[Последний] dddd [•] HH:mm"
msgid "DD MMM YYYY [•] HH:mm"
msgstr "DD MMM YYYY [•] HH:mm"

#: src/utils.js:159
#: src/utils.js:160
msgid "Invalid address"
msgstr "Неправильный адрес"

Expand Down
2 changes: 1 addition & 1 deletion locale/texts.pot
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ msgstr ""
msgid "DD MMM YYYY [•] HH:mm"
msgstr ""

#: src/utils.js:159
#: src/utils.js:160
msgid "Invalid address"
msgstr ""

Expand Down
72 changes: 72 additions & 0 deletions src/components/EditInfoContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) Hathor Labs and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import {
StyleSheet,
View,
TouchableOpacity
} from 'react-native';
import { COLORS } from '../styles/themes';

import { PenIcon } from './Icons/Pen.icon';

export const EditInfoContainer = ({ center, onPress, children }) => (
<TouchableOpacity
style={[
center && styles.editInfoWrapperCentered
]}
onPress={onPress}
>
<View style={[
styles.editInfoContainer,
center && styles.editInfoContainerCentered,
]}
>
<View style={[
center && styles.alignCenter,
]}
>
{children}
</View>
<View style={styles.editIcon}>
<PenIcon />
</View>
</View>
</TouchableOpacity>
);

const styles = StyleSheet.create({
editInfoWrapperCentered: {
alignSelf: 'center',
},
editInfoContainer: {
paddingVertical: 8,
paddingLeft: 8,
paddingRight: 40,
borderRadius: 8,
backgroundColor: COLORS.white,
},
editInfoContainerCentered: {
paddingLeft: 40,
},
alignCenter: {
alignItems: 'center',
},
editIcon: {
position: 'absolute',
display: 'flex',
justifyContent: 'center',
top: 0,
right: 0,
bottom: 0,
width: 24,
height: '100%',
marginVertical: 8,
marginRight: 8,
},
});
10 changes: 9 additions & 1 deletion src/components/HathorHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const HathorHeader = ({
const left = React.Children.toArray(children).find(
(child) => child.type.displayName === HathorHeaderLeft.displayName
);
const central = React.Children.toArray(children).find(
(child) => child.type.displayName === HathorHeaderCentral.displayName
);
const right = React.Children.toArray(children).find(
(child) => child.type.displayName === HathorHeaderRight.displayName
);
Expand All @@ -40,6 +43,7 @@ const HathorHeader = ({
&& (
<InnerWrapper>
{left}
{central}
{right}
</InnerWrapper>
)}
Expand Down Expand Up @@ -70,10 +74,14 @@ const InnerWrapper = ({ children }) => (
const HathorHeaderLeft = ({ children }) => (<View>{children}</View>);
HathorHeaderLeft.displayName = 'HathorHeaderLeft';

const HathorHeaderCentral = ({ style, children }) => <View style={style}>{children}</View>;
HathorHeaderCentral.displayName = 'HathorHeaderCentral';

const HathorHeaderRight = ({ children }) => <View>{children}</View>;
HathorHeaderRight.displayName = 'HathorHeaderRight';

HathorHeader.Left = HathorHeaderLeft;
HathorHeader.Central = HathorHeaderCentral;
HathorHeader.Right = HathorHeaderRight;

const CancelButton = ({ onCancel }) => (
Expand Down Expand Up @@ -118,7 +126,7 @@ const RightComponent = ({ rightElement, onCancel }) => {

const styles = StyleSheet.create({
wrapper: {
height: STYLE.headerHeight,
minHeight: STYLE.headerHeight,
flexDirection: 'row',
alignItems: 'flex-end',
borderColor: COLORS.borderColor,
Expand Down
116 changes: 116 additions & 0 deletions src/components/ModalBase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* Copyright (c) Hathor Labs and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import {
StyleSheet,
View,
Text,
} from 'react-native';
import Modal from 'react-native-modal';

import { COLORS } from '../styles/themes';
import NewHathorButton from './NewHathorButton';

const ModalBase = ({ styleModal, styleWrapper, show, onDismiss, children }) => {
const hasChildren = children != null;

const title = hasChildren && React.Children.toArray(children).find(
(child) => child.type.displayName === Title.displayName
);
const body = hasChildren && React.Children.toArray(children).find(
(child) => child.type.displayName === Body.displayName
);
const button = hasChildren && React.Children.toArray(children).find(
(child) => child.type.displayName === Button.displayName
);
const discreteButton = hasChildren && React.Children.toArray(children).find(
(child) => child.type.displayName === DiscreteButton.displayName
);

return (
<Modal
isVisible={show}
animationIn='slideInUp'
swipeDirection={['down']}
onSwipeComplete={onDismiss}
onBackButtonPress={onDismiss}
onBackdropPress={onDismiss}
style={styleModal}
propagateSwipe
>
<View style={[
styles.wrapper,
styleWrapper,
]}
>
{title && title}
{body && body}
{button && button}
{discreteButton && discreteButton}
</View>
</Modal>
);
};

const Title = ({ children }) => (
<View style={styles.titleWrapper}>
<Text style={styles.title}>
{children}
</Text>
</View>
);
Title.displayName = 'ModalBaseTitle';

/**
* @param {Object} props
* @property {ReactNode} props.children
* @property {StyleProp<ViewStyle>} props.style
*/
const Body = ({ style, children }) => (
<View style={style}>
{children}
</View>
);
Body.displayName = 'ModalBaseBody';

const Button = ({ title, disabled, secondary, danger, onPress }) => (
<NewHathorButton title={title} {...{ disabled, secondary, danger, onPress }} />
);
Button.displayName = 'ModalBaseButton';

const DiscreteButton = ({ title, onPress }) => (
<NewHathorButton title={title} discrete {...{ onPress }} wrapperStyle={styles.discreteButton} />
);
DiscreteButton.displayName = 'ModalBaseDiscreteButton';

ModalBase.Title = Title;
ModalBase.Body = Body;
ModalBase.Button = Button;
ModalBase.DiscreteButton = DiscreteButton;

const styles = StyleSheet.create({
wrapper: {
borderRadius: 8,
paddingVertical: 24,
paddingHorizontal: 16,
backgroundColor: COLORS.white,
},
titleWrapper: {
paddingBottom: 20,
},
title: {
color: 'black',
fontSize: 18,
lineHeight: 20,
},
discreteButton: {
marginTop: 8,
},
});

export { ModalBase }
24 changes: 24 additions & 0 deletions src/components/NewHathorButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const NewHathorButton = (props) => {
textStyle.push(style.textDisabled);
}

if (props.discrete) {
wrapperViewStyle.push(style.wrapperDiscrete);
textStyle.push(style.textDiscrete);
}

if (props.secondary) {
wrapperViewStyle.push(style.wrapperSecondary);
textStyle.push(style.textSecondary);
Expand All @@ -34,6 +39,11 @@ const NewHathorButton = (props) => {
}
}

if (props.danger) {
wrapperViewStyle.push(style.wrapperSecondaryDanger);
textStyle.push(style.textSecondaryDanger);
}

return (
<View style={[...wrapperViewStyle, props.wrapperStyle, props.style]}>
<TouchableOpacity onPress={props.onPress} style={style.touchable} disabled={props.disabled}>
Expand Down Expand Up @@ -79,6 +89,14 @@ const style = StyleSheet.create({
wrapperSecondaryDisabled: {
borderColor: COLORS.textColorShadow,
},
wrapperDiscrete: {
backgroundColor: COLORS.backgroundColor,
borderColor: COLORS.backgroundColor,
borderWidth: 1.5,
},
wrapperSecondaryDanger: {
borderColor: COLORS.errorBgColor,
},
touchable: {
flex: 1,
flexDirection: 'row',
Expand All @@ -101,6 +119,12 @@ const style = StyleSheet.create({
textDisabled: {
color: COLORS.textColorShadow,
},
textDiscrete: {
color: COLORS.freeze300,
},
textSecondaryDanger: {
color: COLORS.errorBgColor,
},
});

export default NewHathorButton;
35 changes: 35 additions & 0 deletions src/components/TextLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) Hathor Labs and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import {
StyleSheet,
Text,
} from 'react-native';

export const TextLabel = ({ pb8, bold, children }) => (
<Text style={[
styles.textLabel,
pb8 && styles.pb8,
bold && styles.bold,
]}
>{children}</Text>
);

const styles = StyleSheet.create({
textLabel: {
fontSize: 12,
lineHeight: 20,
color: 'hsla(0, 0%, 38%, 1)',
},
pb8: {
paddingBottom: 8,
},
bold: {
fontWeight: 'bold',
},
});
35 changes: 35 additions & 0 deletions src/components/TextValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) Hathor Labs and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import {
StyleSheet,
Text,
} from 'react-native';

export const TextValue = ({ bold, pb4, children }) => (
<Text style={[
styles.textValue,
bold && styles.bold,
pb4 && styles.pb4,
]}
>{children}</Text>
);

const styles = StyleSheet.create({
textValue: {
fontSize: 14,
lineHeight: 20,
color: 'black',
},
pb4: {
paddingBottom: 4,
},
bold: {
fontWeight: 'bold',
},
});
Loading
Loading