Skip to content

Commit 6e010e0

Browse files
joanna-pageprojakubcolony
authored andcommitted
feat: user hub updated with streams
1 parent 9a854d6 commit 6e010e0

File tree

40 files changed

+1225
-492
lines changed

40 files changed

+1225
-492
lines changed

src/components/common/Extensions/UserHub/UserHub.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import Select from '~v5/common/Fields/Select/index.ts';
1010
import TitleLabel from '~v5/shared/TitleLabel/index.ts';
1111

1212
import { tabList } from './consts.ts';
13-
import BalanceTab from './partials/BalanceTab/index.ts';
13+
import BalanceTab from './partials/BalanceTab/BalanceTab.tsx';
1414
import CryptoToFiatTab from './partials/CryptoToFiatTab/CryptoToFiatTab.tsx';
15+
import ReputationTab from './partials/ReputationTab/ReputationTab.tsx';
1516
import StakesTab from './partials/StakesTab/index.ts';
1617
import TransactionsTab from './partials/TransactionsTab/index.ts';
1718
import { UserHubTab } from './types.ts';
@@ -70,7 +71,7 @@ const UserHub: FC<Props> = ({ initialOpenTab = UserHubTab.Balance }) => {
7071
'sm:min-h-[27.75rem]': selectedTab === UserHubTab.Balance,
7172
})}
7273
>
73-
<div className="sticky left-0 right-0 top-0 flex shrink-0 flex-col justify-between border-b border-b-gray-200 bg-base-white px-6 pb-6 pt-4 sm:static sm:left-auto sm:right-auto sm:top-auto sm:w-[216px] sm:border-b-0 sm:border-r sm:border-gray-100 sm:bg-transparent sm:p-6 sm:px-6">
74+
<div className="sticky left-0 right-0 top-0 flex shrink-0 flex-col justify-between border-b border-b-gray-200 bg-base-white px-6 pb-6 pt-4 sm:static sm:left-auto sm:right-auto sm:top-auto sm:w-[13.5rem] sm:border-b-0 sm:border-r sm:border-gray-100 sm:bg-transparent sm:p-6 sm:px-6">
7475
{isMobile ? (
7576
<Select
7677
options={filteredTabList}
@@ -126,10 +127,11 @@ const UserHub: FC<Props> = ({ initialOpenTab = UserHubTab.Balance }) => {
126127
</>
127128
)}
128129
</div>
129-
<div className="relative h-full w-full min-w-0 overflow-y-auto">
130+
<div className="relative h-full w-full">
130131
{selectedTab === UserHubTab.Balance && (
131132
<BalanceTab onTabChange={handleTabChange} />
132133
)}
134+
{selectedTab === UserHubTab.Reputation && <ReputationTab />}
133135
{selectedTab === UserHubTab.Stakes && <StakesTab />}
134136
{selectedTab === UserHubTab.Transactions && (
135137
<TransactionsTab appearance={{ interactive: true }} />

src/components/common/Extensions/UserHub/consts.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Receipt,
44
Invoice,
55
CreditCard,
6+
Star,
67
} from '@phosphor-icons/react';
78
import { defineMessages } from 'react-intl';
89

@@ -16,6 +17,10 @@ export const menuMessages = defineMessages({
1617
id: 'UserSubmenu.balance',
1718
defaultMessage: 'Balance',
1819
},
20+
reputation: {
21+
id: 'UserSubmenu.reputation',
22+
defaultMessage: 'Reputation',
23+
},
1924
stakes: {
2025
id: 'UserSubmenu.stakes',
2126
defaultMessage: 'Stakes',
@@ -37,6 +42,12 @@ export const tabList: UserHubTabList = [
3742
value: UserHubTab.Balance,
3843
icon: Invoice,
3944
},
45+
{
46+
id: UserHubTab.Reputation,
47+
label: formatText(menuMessages.reputation),
48+
value: UserHubTab.Reputation,
49+
icon: Star,
50+
},
4051
{
4152
id: UserHubTab.Stakes,
4253
label: formatText(menuMessages.stakes),

src/components/common/Extensions/UserHub/partials/BalanceTab/BalanceTab.styles.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
1-
import React from 'react';
2-
import { useIntl } from 'react-intl';
1+
import React, { type FC } from 'react';
2+
import { defineMessages } from 'react-intl';
33

44
import { useAppContext } from '~context/AppContext/AppContext.ts';
55
import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts';
6+
import { formatText } from '~utils/intl.ts';
67

7-
import Balance from './partials/Balance.tsx';
8-
import PendingReputation from './partials/PendingReputation/index.ts';
9-
import TotalReputation from './partials/TotalReputation.tsx';
8+
import BalanceInfoRow from './partials/BalanceInfoRow/BalanceInfoRow.tsx';
9+
import StreamsInfoRow from './partials/StreamsInfoRow/StreamsInfoRow.tsx';
1010
import { type BalanceTabProps } from './types.ts';
1111

1212
const displayName = 'common.Extensions.UserHub.partials.BalanceTab';
1313

14-
const BalanceTab = ({ onTabChange }: BalanceTabProps) => {
15-
const { formatMessage } = useIntl();
16-
const {
17-
colony: { colonyAddress, nativeToken },
18-
} = useColonyContext();
14+
const MSG = defineMessages({
15+
title: {
16+
id: `${displayName}.title`,
17+
defaultMessage: 'Your overview in {colonyName}',
18+
},
19+
titleColonyOverview: {
20+
id: `${displayName}.titleColonyOverview`,
21+
defaultMessage: 'Your overview',
22+
},
23+
});
24+
25+
const BalanceTab: FC<BalanceTabProps> = ({ onTabChange }) => {
26+
const { colony } = useColonyContext();
27+
const { metadata, nativeToken } = colony;
28+
const { displayName: colonyDisplayName = '' } = metadata || {};
29+
1930
const { wallet } = useAppContext();
2031

2132
if (!wallet) {
2233
return null;
2334
}
2435

25-
// @TODO: handle empty state <EmptyContent />
2636
return (
2737
<div className="p-6">
28-
<p className="mb-6 heading-5 md:mb-4">
29-
{formatMessage({ id: 'userHub.reputation' })}
30-
</p>
31-
<Balance
38+
<h5 className="mb-6 heading-5 sm:mb-4">
39+
{formatText(MSG.title, { colonyName: colonyDisplayName })}
40+
</h5>
41+
<BalanceInfoRow
3242
nativeToken={nativeToken}
3343
wallet={wallet}
3444
onTabChange={onTabChange}
45+
className="mb-6 border-b border-gray-200 pb-6"
3546
/>
36-
<TotalReputation
37-
colonyAddress={colonyAddress}
38-
wallet={wallet}
39-
nativeToken={nativeToken}
40-
/>
41-
<PendingReputation
42-
colonyAddress={colonyAddress}
43-
wallet={wallet}
44-
nativeToken={nativeToken}
45-
/>
47+
<StreamsInfoRow />
4648
</div>
4749
);
4850
};
4951

5052
BalanceTab.displayName = displayName;
51-
5253
export default BalanceTab;

src/components/common/Extensions/UserHub/partials/BalanceTab/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import clsx from 'clsx';
2+
import { AnimatePresence, motion } from 'framer-motion';
3+
import React, { type FC, useEffect } from 'react';
4+
5+
import { currencySymbolMap } from '~constants/currency.ts';
6+
import { useCurrencyContext } from '~context/CurrencyContext/CurrencyContext.ts';
7+
8+
import { type AvailableToClaimCounterProps } from './types.ts';
9+
10+
const AvailableToClaimCounter: FC<AvailableToClaimCounterProps> = ({
11+
amountAvailableToClaim,
12+
getTotalFunds,
13+
isAtLeastOnePaymentActive,
14+
ratePerSecond,
15+
}) => {
16+
const { currency } = useCurrencyContext();
17+
18+
useEffect(() => {
19+
const timer = setInterval(() => {
20+
getTotalFunds();
21+
}, 1000);
22+
23+
return () => {
24+
clearInterval(timer);
25+
};
26+
}, [getTotalFunds]);
27+
28+
const decimalPlaces = ratePerSecond.toString().split('.')[1]?.length || 0;
29+
const fixedDecimalPlaces = decimalPlaces < 5 ? decimalPlaces : 5;
30+
31+
const formattedNumber = Number(
32+
amountAvailableToClaim.toFixed(fixedDecimalPlaces),
33+
).toLocaleString(undefined, {
34+
minimumFractionDigits: fixedDecimalPlaces,
35+
maximumFractionDigits: fixedDecimalPlaces,
36+
});
37+
38+
const digits = formattedNumber.split('').map((char, index) => ({
39+
char,
40+
key: `${char}-${index}`,
41+
isStatic: char === ',' || char === '.', // Handle commas as static
42+
}));
43+
44+
return isAtLeastOnePaymentActive ? (
45+
<div className="flex items-center justify-end gap-[0.5ch]">
46+
<span>{currencySymbolMap[currency]}</span>
47+
<div className="flex items-center justify-center overflow-hidden">
48+
{digits.map(({ char, key, isStatic }) => (
49+
<div
50+
key={key}
51+
className={clsx('relative inline-block overflow-hidden', {
52+
'w-[1ch]': !isStatic,
53+
})}
54+
>
55+
{isStatic ? (
56+
<div className="flex w-full items-center justify-center">
57+
{char}
58+
</div>
59+
) : (
60+
<AnimatePresence mode="wait">
61+
<motion.div
62+
key={char}
63+
initial={{ y: 50, opacity: 0 }}
64+
animate={{ y: 0, opacity: 1 }}
65+
exit={{ y: -50, opacity: 0 }}
66+
className="flex w-full items-center justify-center"
67+
>
68+
{char}
69+
</motion.div>
70+
</AnimatePresence>
71+
)}
72+
</div>
73+
))}
74+
</div>
75+
<span>{currency}</span>
76+
</div>
77+
) : (
78+
<span>
79+
{currencySymbolMap[currency]} {formattedNumber} {currency}
80+
</span>
81+
);
82+
};
83+
84+
export default AvailableToClaimCounter;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface AvailableToClaimCounterProps {
2+
amountAvailableToClaim: number;
3+
getTotalFunds: () => Promise<void>;
4+
isAtLeastOnePaymentActive?: boolean;
5+
ratePerSecond: number;
6+
}

0 commit comments

Comments
 (0)