Skip to content

Commit

Permalink
fix: negative numbers for amount
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhdaware committed Jul 24, 2024
1 parent a1d6a2a commit 97f6583
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 48 deletions.
8 changes: 4 additions & 4 deletions packages/blade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@
"typescript-transform-paths": "3.4.7",
"@types/body-scroll-lock": "3.1.0",
"ramda": "0.29.1",
"@razorpay/i18nify-js": "1.9.3",
"@razorpay/i18nify-react": "4.0.8",
"@razorpay/i18nify-js": "1.10.3",
"@razorpay/i18nify-react": "4.0.9",
"plop": "3.1.1",
"node-plop": "0.32.0",
"svgson": "5.3.1"
Expand All @@ -300,8 +300,8 @@
"react-hot-toast": "2.4.1",
"@gorhom/bottom-sheet": "^4.4.6",
"@gorhom/portal": "^1.0.14",
"@razorpay/i18nify-js": "^1.9.3",
"@razorpay/i18nify-react": "^4.0.8"
"@razorpay/i18nify-js": "^1.10.3",
"@razorpay/i18nify-react": "^4.0.9"
},
"peerDependenciesMeta": {
"react-native": {
Expand Down
30 changes: 22 additions & 8 deletions packages/blade/src/components/Amount/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ const AmountValue = ({
fontFamily={numberFontFamily}
as={isReactNative ? undefined : 'span'}
>
{amount.minusSign}
{amount.integer}
</BaseText>
<BaseText
Expand All @@ -142,7 +141,6 @@ const AmountValue = ({
color={amountValueColor}
lineHeight={amountLineHeights[type][size]}
>
{amount.minusSign}
{amount.formatted}
</BaseText>
);
Expand Down Expand Up @@ -188,27 +186,29 @@ export const formatAmountWithSuffix = ({
};
}
case 'humanize': {
const formatted = formatNumber(value, {
const options = {
intlOptions: {
notation: 'compact',
maximumFractionDigits: 2,
trailingZeroDisplay: 'stripIfInteger',
},
});
} as const;
return {
formatted,
...formatNumberByParts(value, options),
formatted: formatNumber(value, options),
};
}

default: {
const formatted = formatNumber(value, {
const options = {
intlOptions: {
maximumFractionDigits: 0,
roundingMode: 'floor',
},
});
} as const;
return {
formatted,
...formatNumberByParts(value, options),
formatted: formatNumber(value, options),
};
}
}
Expand Down Expand Up @@ -298,6 +298,8 @@ const _Amount = ({
: normalAmountSizes[type][size];
const isReactNative = getPlatformType() === 'react-native';

console.log(renderedValue);

return (
<BaseBox
display={(isReactNative ? 'flex' : 'inline-flex') as never}
Expand All @@ -311,6 +313,18 @@ const _Amount = ({
flexDirection="row"
position="relative"
>
{renderedValue.minusSign ? (
<BaseText
fontSize={normalAmountSizes[type][size]}
fontWeight={weight}
lineHeight={amountLineHeights[type][size]}
color={amountValueColor}
as={isReactNative ? undefined : 'span'}
marginX="spacing.2"
>
{renderedValue.minusSign}
</BaseText>
) : null}
{currencyPosition === 'left' && (
<BaseText
marginRight="spacing.1"
Expand Down
47 changes: 11 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4334,17 +4334,17 @@
dependencies:
"@babel/runtime" "^7.13.10"

"@razorpay/i18nify-js@1.9.3":
version "1.9.3"
resolved "https://registry.yarnpkg.com/@razorpay/i18nify-js/-/i18nify-js-1.9.3.tgz#7b04d201733d06da53c434fd987097e6d1cf0544"
integrity sha512-CxatwqjxGe481dHxa9Gc7iC9tICGeJ/olRC2486SbWa0hybPME7AQAU1y+1u3iQOOGG8aH7ZLyRMnHrHder6tA==
"@razorpay/i18nify-js@1.10.3":
version "1.10.3"
resolved "https://registry.yarnpkg.com/@razorpay/i18nify-js/-/i18nify-js-1.10.3.tgz#a42596e7306cf378c3fff4ee90f6fc1d6216f355"
integrity sha512-zP7wRR4x6+kaZm/ptao81Gbw5KraUiswf93yFIHAZzQUAJnLsIPRa/O9Uz2cbDkhz0sF7JPJMGnadxAafrhnxA==
dependencies:
"@internationalized/date" "^3.5.2"

"@razorpay/i18nify-react@4.0.8":
version "4.0.8"
resolved "https://registry.yarnpkg.com/@razorpay/i18nify-react/-/i18nify-react-4.0.8.tgz#6d997f6de917e7aa441399dc8e10ec2944aa665d"
integrity sha512-BoyDyw6kHNTMv1q1Rvd3GL4IlSZibzMiTRrgRmz1zZYNqAxyG6/W33CEF+Mr+3gIfv7QYwbdQlRle3HA7CpVBA==
"@razorpay/i18nify-react@4.0.9":
version "4.0.9"
resolved "https://registry.yarnpkg.com/@razorpay/i18nify-react/-/i18nify-react-4.0.9.tgz#3419b000fb0a69b1b6713f6ef42aa50e56cb4051"
integrity sha512-7GR21S8LtTnxKbQsXqyzdvaVsPi+IsOgKr49Vpkvj3Dqdy0qgaLCDt8eHpv+iMndm/4AYMiWn+CL/bwjYlFp5A==

"@react-hook/intersection-observer@^3.1.1":
version "3.1.1"
Expand Down Expand Up @@ -25894,7 +25894,7 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0":
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand All @@ -25912,15 +25912,6 @@ string-width@^1.0.1:
is-fullwidth-code-point "^1.0.0"
strip-ansi "^3.0.0"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^5.0.0, string-width@^5.0.1, string-width@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
Expand Down Expand Up @@ -26041,7 +26032,7 @@ stringify-object@^3.3.0:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand All @@ -26062,13 +26053,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -28724,7 +28708,7 @@ worker-rpc@^0.1.0:
dependencies:
microevent.ts "~0.1.1"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -28742,15 +28726,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 97f6583

Please sign in to comment.