Skip to content

Commit

Permalink
Animate fractionals in balance text
Browse files Browse the repository at this point in the history
  • Loading branch information
Perronef5 committed Oct 17, 2024
1 parent 425b365 commit cb60753
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/components/BalanceText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ const BalanceText = () => {
const integral = useMemo(() => Math.floor(amount || 0), [amount])
const [realAmount, setAmount] = useState(amount || 0)

useEffect(() => {
if (!amount) return

setTimeout(() => {
setAmount(amount)
}, 3000)
}, [amount])

const firstFractional = useMemo(() => {
if (amount === undefined) return 0
const decimal = amount - integral
if (realAmount === undefined) return 0
const decimal = realAmount - integral
const fraction = decimal.toString().split('.')[1]
// Fraction with max length of decimals
const fractionWithMaxDecimals = fraction?.slice(0, 1)
return fraction ? Number(fractionWithMaxDecimals) : 0
}, [amount, integral])
}, [realAmount, integral])

const secondFractional = useMemo(() => {
if (amount === undefined) return 0
const decimal = amount - integral
if (realAmount === undefined) return 0
const decimal = realAmount - integral
const fraction = decimal.toString().split('.')[1]
// Fraction with max length of decimals
const fractionWithMaxDecimals = fraction?.slice(1, 2)
return fraction ? Number(fractionWithMaxDecimals) : 0
}, [amount, integral])
}, [realAmount, integral])

useEffect(() => {
if (!amount) return

setTimeout(() => {
setAmount(amount)
}, 3000)
}, [amount])

return (
<Box>
Expand Down
9 changes: 7 additions & 2 deletions src/features/onboarding/import/ImportSubAccountsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ export default () => {

return (
<ScrollBox
backgroundColor="primaryBackground"
contentContainerStyle={{
flex: 1,
backgroundColor: colors.primaryBackground,
}}
refreshControl={
<RefreshControl
enabled
Expand All @@ -229,10 +234,10 @@ export default () => {
/>
}
>
<SafeAreaBox backgroundColor="secondaryBackground" flex={1}>
<SafeAreaBox backgroundColor="primaryBackground" flex={1}>
<Box
flex={1}
backgroundColor="secondaryBackground"
backgroundColor="primaryBackground"
height="100%"
paddingHorizontal="4"
>
Expand Down

0 comments on commit cb60753

Please sign in to comment.