-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEQ] Display name, balance and limits (#12916)
* chore: removed responsive root * chore: reverted old changes * chore: backup * chore: backup * chore: test build * feat: added my profile name, content * chore: re-added deriv/utils to p2p-v2 * chore: backup * chore: resolved code reviews * chore: backup * chore: developed responsive view for profile stats * feat: added responsive screen for my-profile * chore: added documentation for useadvertiserstats * refactor: added deriv-com/ui for p2p-v2, used text component * chore: removed package-lock in p2p-v2 * chore: removed package-lock in p2p-v2 * chore: reverted test changes on useauthorize * chore: updated deriv-ui, resolved code reviews
- Loading branch information
1 parent
267fb5d
commit 2aac4cf
Showing
45 changed files
with
756 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/p2p-v2/src/components/AdvertiserName/AdvertiserName.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.p2p-v2-advertiser-name { | ||
display: grid; | ||
grid-gap: 1.6rem; | ||
grid-template-columns: min-content auto max-content; | ||
|
||
&__details { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
gap: 0.4rem; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/p2p-v2/src/components/AdvertiserName/AdvertiserName.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { Avatar } from '../Avatar'; | ||
import { useAdvertiserStats, useDevice } from '../../hooks'; | ||
import AdvertiserNameStats from './AdvertiserNameStats'; | ||
import AdvertiserNameBadges from './AdvertiserNameBadges'; | ||
import AdvertiserNameToggle from './AdvertiserNameToggle'; | ||
import { Text } from '@deriv-com/ui/dist/components/Text'; | ||
import './AdvertiserName.scss'; | ||
|
||
const AdvertiserName = () => { | ||
const { data: advertiserStats, isLoading } = useAdvertiserStats(); | ||
const { isDesktop } = useDevice(); | ||
|
||
if (isLoading || !advertiserStats) return <h1>Loading...</h1>; | ||
|
||
return ( | ||
<div className='p2p-v2-advertiser-name'> | ||
<Avatar name={advertiserStats.name || ''} /> | ||
<div className='p2p-v2-advertiser-name__details'> | ||
<Text size='md' weight='bold'> | ||
{advertiserStats.name}{' '} | ||
{advertiserStats.show_name && ( | ||
<Text color='less-prominent' size='sm'> | ||
({advertiserStats.fullName}) | ||
</Text> | ||
)} | ||
</Text> | ||
<AdvertiserNameStats /> | ||
<AdvertiserNameBadges /> | ||
</div> | ||
{isDesktop && <AdvertiserNameToggle />} | ||
</div> | ||
); | ||
}; | ||
AdvertiserName.displayName = 'AdvertiserName'; | ||
|
||
export default AdvertiserName; |
5 changes: 5 additions & 0 deletions
5
packages/p2p-v2/src/components/AdvertiserName/AdvertiserNameBadges.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.p2p-v2-advertiser-name-badges { | ||
display: flex; | ||
gap: 0.4rem; | ||
padding: 0.4rem 0; | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/p2p-v2/src/components/AdvertiserName/AdvertiserNameBadges.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { useAdvertiserStats } from '../../hooks'; | ||
import { Badge } from '../Badge'; | ||
import './AdvertiserNameBadges.scss'; | ||
|
||
/** | ||
* This component is used to show an advertiser's badge, for instance: | ||
* +100 Trades, ID verified, Address not verified, etc | ||
* | ||
* Use cases are usually in My Profile page and Advertiser page used under the advertiser's name | ||
*/ | ||
const AdvertiserNameBadges = () => { | ||
const { data: advertiserStats, isLoading } = useAdvertiserStats(); | ||
|
||
if (isLoading || !advertiserStats) return <h1>Loading...</h1>; | ||
|
||
const { isAddressVerified, isIdentityVerified, totalOrders } = advertiserStats; | ||
|
||
return ( | ||
<div className='p2p-v2-advertiser-name-badges'> | ||
{totalOrders >= 100 && <Badge label='100+' status='trades' variant='warning' />} | ||
<Badge | ||
label='ID' | ||
status={isIdentityVerified ? 'verified' : 'not verified'} | ||
variant={isIdentityVerified ? 'success' : 'general'} | ||
/> | ||
<Badge | ||
label='Address' | ||
status={isAddressVerified ? 'verified' : 'not verified'} | ||
variant={isAddressVerified ? 'success' : 'general'} | ||
/> | ||
</div> | ||
); | ||
}; | ||
AdvertiserNameBadges.displayName = 'AdvertiserNameBadges'; | ||
|
||
export default AdvertiserNameBadges; |
35 changes: 35 additions & 0 deletions
35
packages/p2p-v2/src/components/AdvertiserName/AdvertiserNameStats.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.p2p-v2-advertiser-name-stats { | ||
display: flex; | ||
align-items: center; | ||
|
||
@include mobile { | ||
flex-direction: column; | ||
align-items: flex-start; | ||
justify-content: center; | ||
gap: 2rem; | ||
} | ||
|
||
& div { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.8rem; | ||
padding: 0 0.8rem; | ||
border-left: 1px solid #f2f3f4; | ||
|
||
@include mobile { | ||
border-left: none; | ||
padding: 0; | ||
} | ||
|
||
&:first-child { | ||
padding-left: 0; | ||
padding-right: 0.8rem; | ||
border-left: none; | ||
} | ||
} | ||
|
||
&__rating { | ||
display: flex; | ||
gap: 0.5rem; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
packages/p2p-v2/src/components/AdvertiserName/AdvertiserNameStats.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import { useAdvertiserStats, useDevice } from '../../hooks'; | ||
import { StarRating } from '../StarRating'; | ||
import ThumbUpIcon from '../../public/ic-thumb-up.svg'; | ||
import BlockedUserOutlineIcon from '../../public/ic-user-blocked-outline.svg'; | ||
import { Text } from '@deriv-com/ui/dist/components/Text'; | ||
import './AdvertiserNameStats.scss'; | ||
|
||
/** | ||
* This component is to show an advertiser's stats, in UI its commonly used under an advertiser's name | ||
* Example: | ||
* Joined 2d | Not rated yet | x x x x x (5 ratings) | ||
* | ||
* Use cases are to show this in My Profile and Advertiser page | ||
*/ | ||
const AdvertiserNameStats = () => { | ||
const { data: advertiserStats, isLoading } = useAdvertiserStats(); | ||
const { isMobile } = useDevice(); | ||
|
||
// TODO: Use Skeleton loader here | ||
if (isLoading || !advertiserStats) return <h1>Loading...</h1>; | ||
|
||
const { blocked_by_count, daysSinceJoined, rating_average, rating_count, recommended_average } = advertiserStats; | ||
|
||
return ( | ||
<div className='p2p-v2-advertiser-name-stats'> | ||
<div> | ||
<Text color='less-prominent' size='sm'> | ||
Joined {daysSinceJoined}d | ||
</Text> | ||
</div> | ||
{!rating_average && ( | ||
<div> | ||
<Text color='less-prominent' size='sm'> | ||
Not rated yet | ||
</Text> | ||
</div> | ||
)} | ||
{rating_average && ( | ||
<> | ||
<div> | ||
<div className='p2p-v2-advertiser-name-stats__rating'> | ||
{isMobile && ( | ||
<Text color='less-prominent' size='sm'> | ||
({rating_average}) | ||
</Text> | ||
)} | ||
<StarRating ratingValue={rating_average} /> | ||
<Text color='less-prominent' size='sm'> | ||
({rating_count} ratings) | ||
</Text> | ||
</div> | ||
</div> | ||
<div> | ||
<ThumbUpIcon /> | ||
<Text color='less-prominent' size='sm'> | ||
{recommended_average || 0}% | ||
</Text> | ||
</div> | ||
</> | ||
)} | ||
<div> | ||
<BlockedUserOutlineIcon /> | ||
<Text color='less-prominent' size='sm'> | ||
{blocked_by_count} | ||
</Text> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
AdvertiserNameStats.displayName = 'AdvertiserNameStats'; | ||
|
||
export default AdvertiserNameStats; |
17 changes: 17 additions & 0 deletions
17
packages/p2p-v2/src/components/AdvertiserName/AdvertiserNameToggle.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.p2p-v2-advertiser-name-toggle { | ||
display: flex; | ||
gap: 0.8rem; | ||
|
||
@include mobile { | ||
justify-content: space-between; | ||
} | ||
|
||
&__label { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
&-real-name { | ||
font-size: 1rem; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/p2p-v2/src/components/AdvertiserName/AdvertiserNameToggle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { memo, useEffect, useState } from 'react'; | ||
import { p2p } from '@deriv/api'; | ||
import { Text } from '@deriv-com/ui/dist/components/Text'; | ||
import { useAdvertiserStats } from '../../hooks'; | ||
import { ToggleSwitch } from '../ToggleSwitch'; | ||
import './AdvertiserNameToggle.scss'; | ||
|
||
type TAdvertiserNameToggle = { | ||
onToggle?: (shouldShowRealName: boolean) => void; | ||
}; | ||
const AdvertiserNameToggle = memo(({ onToggle }: TAdvertiserNameToggle) => { | ||
const { data: advertiserInfo } = useAdvertiserStats(); | ||
const [shouldShowRealName, setShouldShowRealName] = useState(false); | ||
const { mutate: advertiserUpdate } = p2p.advertiser.useUpdate(); | ||
|
||
useEffect(() => { | ||
setShouldShowRealName(advertiserInfo?.show_name || false); | ||
}, [advertiserInfo?.show_name]); | ||
|
||
const onToggleShowRealName = () => { | ||
advertiserUpdate({ | ||
show_name: !shouldShowRealName ? 1 : 0, | ||
}); | ||
setShouldShowRealName(!shouldShowRealName); | ||
onToggle?.(!shouldShowRealName); | ||
}; | ||
|
||
return ( | ||
<div className='p2p-v2-advertiser-name-toggle'> | ||
<div className='p2p-v2-advertiser-name-toggle__label'> | ||
<Text lineHeight='lg' size='sm'> | ||
Show my real name | ||
</Text> | ||
<Text className='p2p-v2-advertiser-name-toggle__label-real-name' color='less-prominent' lineHeight='xs'> | ||
{advertiserInfo?.fullName} | ||
</Text> | ||
</div> | ||
<ToggleSwitch onChange={onToggleShowRealName} value={shouldShowRealName} /> | ||
</div> | ||
); | ||
}); | ||
AdvertiserNameToggle.displayName = 'AdvertiserNameToggle'; | ||
|
||
export default AdvertiserNameToggle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as AdvertiserName } from './AdvertiserName'; | ||
export { default as AdvertiserNameToggle } from './AdvertiserNameToggle'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.p2p-v2-avatar { | ||
border-radius: 5rem; | ||
width: 6.4rem; | ||
height: 6.4rem; | ||
background-color: #ff444f; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: 2rem; | ||
color: #ffffff; | ||
line-height: 3rem; | ||
|
||
@include mobile { | ||
width: 4.2rem; | ||
height: 4.2rem; | ||
font-size: 1.6rem; | ||
line-height: 1.8rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { memo } from 'react'; | ||
import './Avatar.scss'; | ||
|
||
type TAvatarProps = { | ||
name: string; | ||
}; | ||
|
||
export const getShortNickname = (nickname: string): string => nickname?.substring(0, 2).toUpperCase(); | ||
|
||
const Avatar = ({ name }: TAvatarProps) => { | ||
return <div className='p2p-v2-avatar'>{getShortNickname(name)}</div>; | ||
}; | ||
|
||
export default memo(Avatar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Avatar } from './Avatar'; |
Oops, something went wrong.