Skip to content

IOU - Localize amount text input#7221

Merged
Luke9389 merged 7 commits intoExpensify:mainfrom
songlang1994:iou-amount-localization
Jan 19, 2022
Merged

IOU - Localize amount text input#7221
Luke9389 merged 7 commits intoExpensify:mainfrom
songlang1994:iou-amount-localization

Conversation

@songlang1994
Copy link
Copy Markdown
Contributor

@songlang1994 songlang1994 commented Jan 14, 2022

Details

IOU - Localize amount text input. Users will be able to type/paste localized amount format in amount input. See also: #6427 (comment)

Fixed Issues

$ #6427

Tests

  1. Go to preference set language to "Español"
  2. Request money from chats list
  3. Verify that the virtual keypad on mobile shows localized digits.
  4. Verify that localized amount text can be typed with virtual keypad on mobile.
  5. Verify that localized amount text can be typed with hardware keyboard on desktop.
  6. Verify that localized amount text can be pasted.

QA Steps

Same as above.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

web-1

web-2

web-3

Mobile Web

mobile-web-1

mobile-web-2

mobile-web-3

Desktop

desktop-1

desktop-2

desktop-3

iOS

ios-1

ios-2

ios-3

Android

android-1

android-2

android-3

@songlang1994 songlang1994 requested a review from a team as a code owner January 14, 2022 11:59
@MelvinBot MelvinBot requested review from Luke9389 and parasharrajat and removed request for a team January 14, 2022 11:59
Copy link
Copy Markdown
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

Looking really good so far. Giving some styling suggestions.

Comment on lines +131 to +142
isValidLocaleDigit(digit) {
return LocaleDigitUtils.isValidLocaleDigit(this.props.preferredLocale, digit);
}

toLocaleDigit(digit) {
return LocaleDigitUtils.toLocaleDigit(this.props.preferredLocale, digit);
}

fromLocaleDigit(localeDigit) {
return LocaleDigitUtils.fromLocaleDigit(this.props.preferredLocale, localeDigit);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can't think of any other place in the app that will use these functions so I don't think it is a good idea to pollute the WithLocalize context at this time. Maybe directly use them in the IOUAmountPage for now and pass the locale from this.props.preferredLocale. We can refactor these in future if needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently toLocaleDigit is also used by BigNumberPad.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, I cleaned up the isValidLocaleDigit function because it's not used. So only toLocaleDigit and fromLocaleDigit is added in that context.

@songlang1994 songlang1994 changed the title [WIP] IOU - Localize amount text input IOU - Localize amount text input Jan 15, 2022
}

render() {
const formattedAmount = this.replaceAllDigits(this.state.amount, this.props.toLocaleDigit);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't we just use, numberFormat prop directly for the whole input value?

Copy link
Copy Markdown
Contributor Author

@songlang1994 songlang1994 Jan 15, 2022

Choose a reason for hiding this comment

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

Unfortunately we can't. Because the amount might not be a valid number yet while inputing (e.g. "12.").

If we do need to use numberFormat the code will be

get formattedInputingAmount() {
    if (!this.state.amount) {
        return '';
    }

    const endsWithDecimalPoint = this.state.amount.endsWith('.');
    if (endsWithDecimalPoint) {
        const localized = this.props.numberFormat(this.state.amount, {useGrouping: false, minimumFractionDigits: 1});
        return localized.slice(0, -1);
    }

    const fraction = this.state.amount.split('.')[1];
    const fractionDigits = fraction ? fraction.length : 0;
    return this.props.numberFormat(this.state.amount, {useGrouping: false, minimumFractionDigits: fractionDigits});
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok. What is more performant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is no performance issue here since the max length of amount is just 8. But replaceAllDigits here is more readable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds, good. I will give it a go.

Copy link
Copy Markdown
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

Code Looks good.
But when I selected Spanish, I have to type , on my keyboard. Is this behavior correct? or should it be like.. you type . and , is shown to the user when the selected language is Spanish.

@songlang1994
Copy link
Copy Markdown
Contributor Author

But when I selected Spanish, I have to type , on my keyboard.

@parasharrajat That's the expected behavior of current implementation. Maybe you would like to double check it by asking a native Spanish user.

@parasharrajat
Copy link
Copy Markdown
Member

ok. Thanks. I will ask @Luke9389 to test it and then decide.

@parasharrajat
Copy link
Copy Markdown
Member

@Luke9389 I have a question above. Thanks.

@Luke9389
Copy link
Copy Markdown
Contributor

I think needing to type , is totally fine. That's what you'd do if you were expecting a comma, right?

@Luke9389
Copy link
Copy Markdown
Contributor

I think it'd be really frustrating for users to by typing one thing, and then have a totally different character show up.

@parasharrajat
Copy link
Copy Markdown
Member

@songlang1994 You got some conflicts to resolve.

@songlang1994
Copy link
Copy Markdown
Contributor Author

Should I use git rebase then force-push or git merge to resolve the conflicts?

@parasharrajat
Copy link
Copy Markdown
Member

Git merge and resolve conflicts manually.

Copy link
Copy Markdown
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

Ok. LGTM. Good work @songlang1994 .

cc: @Luke9389
🎀 👀 🎀 C+ reviewed

Copy link
Copy Markdown
Contributor

@Luke9389 Luke9389 left a comment

Choose a reason for hiding this comment

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

Nice! I was about to approve this yesterday but wanted to adhere to the Contributor+ structure. Great work both of you @songlang1994 @parasharrajat. 👍

@Luke9389 Luke9389 merged commit dcd2882 into Expensify:main Jan 19, 2022
@OSBotify
Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by @Luke9389 in version: 1.1.31-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Copy Markdown
Contributor

🚀 Deployed to production by @AndrewGable in version: 1.1.32-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants