Skip to content

Commit 8e53f50

Browse files
authored
Merge pull request #1280 from topcoder-platform/feat/v6
Wallet and review phase display issue fixes
2 parents 2e7c888 + 2d9458d commit 8e53f50

File tree

3 files changed

+149
-128
lines changed

3 files changed

+149
-128
lines changed

src/apps/review/src/lib/utils/reviewPhaseGuards.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,28 @@ export const shouldIncludeInReviewPhase = (
180180
}
181181

182182
const normalizedCandidateList = Array.from(normalizedCandidates)
183-
const isExcluded = normalizedCandidateList
184-
.some(candidate => (
185-
EXCLUDED_REVIEW_TYPE_FRAGMENTS
186-
.some(fragment => candidate.includes(fragment))
187-
))
183+
184+
const hasExplicitReviewPhase = hasReviewPhase(submission.review, phases)
185+
|| (
186+
Array.isArray(submission.reviews)
187+
&& submission.reviews.some(review => hasReviewPhase(review, phases))
188+
)
189+
190+
const isExcluded = normalizedCandidateList.some(candidate => (
191+
EXCLUDED_REVIEW_TYPE_FRAGMENTS.some(fragment => {
192+
if (!candidate.includes(fragment)) {
193+
return false
194+
}
195+
196+
if (fragment === 'iterative' && hasExplicitReviewPhase) {
197+
// Treat records that are tied to the official Review phase as review entries,
198+
// even when the review type string mentions "Iterative".
199+
return false
200+
}
201+
202+
return true
203+
})
204+
))
188205

189206
if (process.env.NODE_ENV !== 'production') {
190207
// eslint-disable-next-line no-console

src/apps/wallet/src/home/tabs/home/HomeTab.tsx

Lines changed: 126 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* eslint-disable react/jsx-wrap-multilines */
2-
import { FC, useEffect, useState } from 'react'
2+
import { FC, useMemo } from 'react'
33

44
import { UserProfile } from '~/libs/core'
55
import { IconOutline, LinkButton, LoadingCircles } from '~/libs/ui'
66

7-
import { Balance } from '../../../lib/models/WalletDetails'
87
import { InfoRow, PayoutGuard } from '../../../lib'
98
import { BannerImage, BannerText } from '../../../lib/assets/home'
109
import { nullToZero } from '../../../lib/util'
@@ -17,21 +16,136 @@ interface HomeTabProps {
1716
profile: UserProfile
1817
}
1918

19+
type WalletDetailsData = NonNullable<WalletDetailsResponse['data']>
20+
interface WalletInfoRowsProps {
21+
walletDetails: WalletDetailsData
22+
profile: UserProfile
23+
balanceSum: number
24+
}
25+
26+
const WalletInfoRows: FC<WalletInfoRowsProps> = props => (
27+
<div className={styles['info-row-container']}>
28+
<InfoRow
29+
title='Account Balance'
30+
value={`$${props.balanceSum}`}
31+
action={
32+
<LinkButton
33+
label='MANAGE YOUR WINNINGS'
34+
iconToRight
35+
icon={IconOutline.ArrowRightIcon}
36+
size='md'
37+
link
38+
to='#winnings'
39+
/>
40+
}
41+
/>
42+
43+
<PayoutGuard profile={props.profile}>
44+
{props.walletDetails.withdrawalMethod.isSetupComplete && (
45+
<InfoRow
46+
title='Est. Payment Fees'
47+
value={`$${nullToZero(props.walletDetails.estimatedFees)} USD`}
48+
action={
49+
<LinkButton
50+
label='ADJUST YOUR PAYOUT SETTINGS'
51+
iconToRight
52+
icon={IconOutline.ArrowRightIcon}
53+
size='md'
54+
link
55+
to='#payout'
56+
/>
57+
}
58+
/>
59+
)}
60+
{props.walletDetails.taxForm.isSetupComplete && (
61+
<InfoRow
62+
title='Est. Tax Withholding %'
63+
value={`${nullToZero(props.walletDetails.taxWithholdingPercentage)}%`}
64+
action={
65+
<LinkButton
66+
label='ADJUST YOUR PAYOUT SETTINGS'
67+
iconToRight
68+
icon={IconOutline.ArrowRightIcon}
69+
size='md'
70+
link
71+
to='#payout'
72+
/>
73+
}
74+
/>
75+
)}
76+
77+
{!props.walletDetails.withdrawalMethod.isSetupComplete && (
78+
<InfoRow
79+
title='Withdrawal Method'
80+
value={<Chip text='Setup Required' />}
81+
action={
82+
<LinkButton
83+
label='SETUP WITHDRAWAL METHOD'
84+
iconToRight
85+
icon={IconOutline.ArrowRightIcon}
86+
size='md'
87+
link
88+
to='#payout'
89+
/>
90+
}
91+
/>
92+
)}
93+
94+
{!props.walletDetails.taxForm.isSetupComplete && (
95+
<InfoRow
96+
title='Tax Form'
97+
value={<Chip text='Setup Required' />}
98+
action={
99+
<LinkButton
100+
label='COMPLETE TAX FORM'
101+
iconToRight
102+
icon={IconOutline.ArrowRightIcon}
103+
size='md'
104+
link
105+
to='#payout'
106+
/>
107+
}
108+
/>
109+
)}
110+
{!props.walletDetails.identityVerification.isSetupComplete && (
111+
<InfoRow
112+
title='ID Verification'
113+
value={<Chip text='Setup Required' />}
114+
action={
115+
<LinkButton
116+
label='COMPLETE VERIFICATION'
117+
iconToRight
118+
icon={IconOutline.ArrowRightIcon}
119+
size='md'
120+
link
121+
to='#payout'
122+
/>
123+
}
124+
/>
125+
)}
126+
</PayoutGuard>
127+
</div>
128+
)
129+
20130
const HomeTab: FC<HomeTabProps> = props => {
21131

22132
const { data: walletDetails, isLoading, error }: WalletDetailsResponse = useWalletDetails()
23-
const [balanceSum, setBalanceSum] = useState(0)
24133

25-
useEffect(() => {
26-
if (walletDetails) {
27-
setBalanceSum(
28-
walletDetails.account.balances.reduce((sum: number, balance: Balance) => sum + balance.amount, 0),
29-
)
30-
}
31-
}, [walletDetails])
134+
const balanceSum = useMemo(
135+
() => (walletDetails ? walletDetails.account.balances.reduce((sum, balance) => sum + balance.amount, 0) : 0),
136+
[walletDetails],
137+
)
32138

33139
if (error) {
34-
return <div>{error}</div>
140+
let errorMessage = 'Unable to load wallet details.'
141+
142+
if (typeof error === 'string') {
143+
errorMessage = error
144+
} else if (error && typeof error === 'object' && 'message' in error) {
145+
errorMessage = (error as Error).message || errorMessage
146+
}
147+
148+
return <div>{errorMessage}</div>
35149
}
36150

37151
return (
@@ -42,117 +156,7 @@ const HomeTab: FC<HomeTabProps> = props => {
42156
</div>
43157
{isLoading && <LoadingCircles />}
44158
{!isLoading && walletDetails && (
45-
<div className={styles['info-row-container']}>
46-
<InfoRow
47-
title='Account Balance'
48-
value={`$${balanceSum}`}
49-
action={
50-
<LinkButton
51-
label='MANAGE YOUR WINNINGS'
52-
iconToRight
53-
icon={IconOutline.ArrowRightIcon}
54-
size='md'
55-
link
56-
to='#winnings'
57-
/>
58-
}
59-
/>
60-
61-
<PayoutGuard profile={props.profile}>
62-
{walletDetails.withdrawalMethod.isSetupComplete && (
63-
<InfoRow
64-
title='Est. Payment Fees'
65-
value={`$${nullToZero(walletDetails.estimatedFees)} USD`}
66-
action={
67-
<LinkButton
68-
label='ADJUST YOUR PAYOUT SETTINGS'
69-
iconToRight
70-
icon={IconOutline.ArrowRightIcon}
71-
size='md'
72-
link
73-
to='#payout'
74-
/>
75-
}
76-
/>
77-
)}
78-
{walletDetails.taxForm.isSetupComplete && (
79-
<InfoRow
80-
title='Est. Tax Withholding %'
81-
value={`${nullToZero(walletDetails.taxWithholdingPercentage)}%`}
82-
action={
83-
<LinkButton
84-
label='ADJUST YOUR PAYOUT SETTINGS'
85-
iconToRight
86-
icon={IconOutline.ArrowRightIcon}
87-
size='md'
88-
link
89-
to='#payout'
90-
/>
91-
}
92-
/>
93-
)}
94-
95-
{!walletDetails?.withdrawalMethod.isSetupComplete && (
96-
<InfoRow
97-
title='Withdrawal Method'
98-
value={
99-
walletDetails?.withdrawalMethod.isSetupComplete ? (
100-
'Your preferred method'
101-
) : (
102-
<Chip text='Setup Required' />
103-
)
104-
}
105-
action={
106-
<LinkButton
107-
label='SETUP WITHDRAWAL METHOD'
108-
iconToRight
109-
icon={IconOutline.ArrowRightIcon}
110-
size='md'
111-
link
112-
to='#payout'
113-
/>
114-
}
115-
/>
116-
)}
117-
118-
{!walletDetails?.taxForm.isSetupComplete && (
119-
<InfoRow
120-
title='Tax Form'
121-
value={
122-
walletDetails?.taxForm.isSetupComplete
123-
? 'All set'
124-
: <Chip text='Setup Required' />
125-
}
126-
action={
127-
<LinkButton
128-
label='COMPLETE TAX FORM'
129-
iconToRight
130-
icon={IconOutline.ArrowRightIcon}
131-
size='md'
132-
link
133-
to='#payout'
134-
/>
135-
}
136-
/>
137-
)}
138-
{!walletDetails?.identityVerification.isSetupComplete && (
139-
<InfoRow
140-
title='ID Verification'
141-
value={<Chip text='Setup Required' />}
142-
action={
143-
<LinkButton
144-
label='COMPLETE VERIFICATION'
145-
iconToRight
146-
icon={IconOutline.ArrowRightIcon}
147-
size='md'
148-
link
149-
to='#payout'
150-
/>
151-
}
152-
/>
153-
)}
154-
</PayoutGuard>
155-
</div>
159+
<WalletInfoRows walletDetails={walletDetails} profile={props.profile} balanceSum={balanceSum} />
156160
)}
157161
</div>
158162
)

src/apps/wallet/src/lib/hooks/use-wallet-details.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getWalletDetails } from '../services/wallet'
55

66
export interface Response<T> {
77
data?: Readonly<T>
8-
error?: Readonly<string>
8+
error?: Readonly<Error> | string
99
mutate: KeyedMutator<any>
1010
isLoading?: Readonly<boolean>
1111
}

0 commit comments

Comments
 (0)