Skip to content

Commit

Permalink
Fix "less than" format amount bug (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngkidwarrior authored Apr 23, 2024
2 parents 492ea49 + 833cb69 commit 482f09e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
6 changes: 2 additions & 4 deletions apps/next/pages/activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HomeLayout } from 'app/features/home/layout.web'
import Head from 'next/head'
import { userProtectedGetSSP } from 'utils/userProtected'
import type { NextPageWithLayout } from './_app'
import { ButtonOption, TopNav } from 'app/components/TopNav'
import { TopNav } from 'app/components/TopNav'

export const Page: NextPageWithLayout = () => {
return (
Expand All @@ -19,9 +19,7 @@ export const Page: NextPageWithLayout = () => {
export const getServerSideProps = userProtectedGetSSP()

Page.getLayout = (children) => (
<HomeLayout TopNav={<TopNav header="Activity" button={ButtonOption.NONE} />}>
{children}
</HomeLayout>
<HomeLayout TopNav={<TopNav header="Activity" />}>{children}</HomeLayout>
)

export default Page
3 changes: 0 additions & 3 deletions packages/app/components/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export enum ButtonOption {
QR = 'QR',
SETTINGS = 'SETTINGS',
REFERRAL = 'REFERRAL',
NONE = 'NONE',
}

interface TopNavProps {
Expand Down Expand Up @@ -131,8 +130,6 @@ export function TopNav({
onPress={handleSettingsBottomSheet}
/>
)
case ButtonOption.NONE:
return null
default:
if (__DEV__) throw new Error(`Unknown button option: ${button}`)
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ exports[`EarnTokensScreen renders: EarnTokensScreen 1`] = `
}
suppressHighlighting={true}
>
&lt;0 SEND
0 SEND
</Text>
</View>
</View>
Expand Down Expand Up @@ -610,7 +610,7 @@ exports[`EarnTokensScreen renders: EarnTokensScreen 1`] = `
}
suppressHighlighting={true}
>
&lt;1 SEND
1 SEND
</Text>
<Text
selectable={true}
Expand Down
4 changes: 4 additions & 0 deletions packages/app/utils/formatAmount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@ describe('Additional scenarios', () => {
it('should handle when num is less than default maxDecimals', () => {
expect(formatAmount(0.0045)).toBe('<0.00')
})

it('should handle when num is greater than and has no decimals', () => {
expect(formatAmount(123)).toBe('123')
})
})
4 changes: 2 additions & 2 deletions packages/app/utils/formatAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ export default function formatAmount(
return abbreviateNumber(flooredAmount, maxDecimals)
}

const countLeadingZeros = (digits[1] && (digits[1].match(/^0+/) || [''])[0].length) || 0
const countLeadingZeros = digits[1] && (digits[1].match(/^0+/) || [''])[0].length

const lessThanMin = countLeadingZeros >= maxDecimals
const lessThanMin = countLeadingZeros && countLeadingZeros >= maxDecimals

return (
(lessThanMin ? '<' : '') +
Expand Down

0 comments on commit 482f09e

Please sign in to comment.