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

[#173353526] Fix transaction details crash #1908

Merged
merged 4 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
42 changes: 23 additions & 19 deletions ts/components/wallet/PaymentSummaryComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from "react";
import { Image, ImageSourcePropType, StyleSheet } from "react-native";
import I18n from "../../i18n";
import customVariables from "../../theme/variables";
import { isNullyOrEmpty } from "../../utils/strings";
import ItemSeparatorComponent from "../ItemSeparatorComponent";
import { BadgeComponent } from "../screens/BadgeComponent";

Expand Down Expand Up @@ -59,17 +60,22 @@ const styles = StyleSheet.create({
* This component displays the transaction details
*/
export const PaymentSummaryComponent = (props: Props) => {
const renderItem = (label: string, value: string) => (
<React.Fragment>
<Text small={true} style={props.dark && styles.lighterGray}>
{label}
</Text>
<Text bold={true} dark={!props.dark} white={props.dark}>
{value}
</Text>
<View spacer={true} />
</React.Fragment>
);
const renderItem = (label: string, value?: string) => {
if (isNullyOrEmpty(value)) {
return null;
}
return (
<React.Fragment>
<Text small={true} style={props.dark && styles.lighterGray}>
{label}
</Text>
<Text bold={true} dark={!props.dark} white={props.dark}>
{value}
</Text>
<View spacer={true} />
</React.Fragment>
);
};

const paymentStatus = props.paymentStatus && (
<React.Fragment>
Expand Down Expand Up @@ -103,16 +109,14 @@ export const PaymentSummaryComponent = (props: Props) => {

<View style={styles.row}>
<View style={styles.column}>
{props.recipient &&
renderItem(I18n.t("wallet.recipient"), props.recipient)}
{renderItem(I18n.t("wallet.recipient"), props.recipient)}

{props.description &&
renderItem(
I18n.t("wallet.firstTransactionSummary.object"),
props.description
)}
{renderItem(
I18n.t("wallet.firstTransactionSummary.object"),
props.description
)}

{props.iuv && renderItem(I18n.t("payment.IUV"), props.iuv)}
{renderItem(I18n.t("payment.IUV"), props.iuv)}
</View>

{props.image !== undefined && <Image source={props.image} />}
Expand Down
24 changes: 23 additions & 1 deletion ts/utils/__tests__/string.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize } from "../strings";
import { capitalize, isNullyOrEmpty } from "../strings";

describe("capitalize", () => {
it("should return a string where each word has first char in uppercase-1", () => {
Expand All @@ -21,3 +21,25 @@ describe("capitalize", () => {
expect(capitalize(" hello,world ", ",")).toEqual(" Hello,World ");
});
});

describe("null or empty", () => {
it("should return true", () => {
expect(isNullyOrEmpty(undefined)).toBeTruthy();
});

it("should return false", () => {
expect(isNullyOrEmpty("hello")).toBeFalsy();
});

it("should return true", () => {
expect(isNullyOrEmpty(" ")).toBeTruthy();
});

it("should return true", () => {
expect(isNullyOrEmpty("")).toBeTruthy();
});

it("should return true", () => {
expect(isNullyOrEmpty(null)).toBeTruthy();
});
});
8 changes: 8 additions & 0 deletions ts/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ export const formatTextRecipient = (e: EnteBeneficiario): string => {
${address}${civicNumber}\n
${cap}${city}${province}`.trim();
};

/**
* determine if the text is undefined or empty (or composed only by blanks)
* @param text
*/
export const isNullyOrEmpty = (text: string | undefined | null) => {
return (text || "").trim().length === 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't to use fromNullable ?
something like:

fromNullable(text).fold(false, t => t.trim().length===0)

Just a suggestion, I think your solution works fine too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is definitely better
Update here b2647ce

};