-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dcellar-web-ui): disable selection of SPs with invalid status in …
…SPSelector
- Loading branch information
Showing
6 changed files
with
234 additions
and
166 deletions.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
apps/dcellar-web-ui/src/modules/bucket/components/SPSelector/ErrorBadge.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,69 @@ | ||
import { GREENFIELD_CHAIN_EXPLORER_URL } from '@/base/env'; | ||
import { IconFont } from '@/components/IconFont'; | ||
import { DCTooltip } from '@/components/common/DCTooltip'; | ||
import { Status as StorageProviderStatus } from '@bnb-chain/greenfield-cosmos-types/greenfield/sp/types'; | ||
import { ExternalLinkIcon } from '@node-real/icons'; | ||
import { Badge } from '@node-real/uikit'; | ||
import { A } from './style'; | ||
import { capitalize } from 'radash'; | ||
import { memo } from 'react'; | ||
|
||
type ErrorBadgeProps = { | ||
access: boolean; | ||
address: string; | ||
status: number; | ||
}; | ||
|
||
export const ErrorBadge = memo(function ErrorBadge({ access, address, status }: ErrorBadgeProps) { | ||
const renderUnavailableBadge = () => ( | ||
<DCTooltip title="Check reasons in documentations" placement="bottomLeft"> | ||
<Badge | ||
as="a" | ||
target="_blank" | ||
href="https://docs.nodereal.io/docs/dcellar-faq#storage-provider-related" | ||
ml={4} | ||
colorScheme="danger" | ||
cursor="pointer" | ||
_hover={{ | ||
color: 'scene.danger.normal', | ||
}} | ||
> | ||
SP Error <ExternalLinkIcon boxSize={12} ml={2} /> | ||
</Badge> | ||
</DCTooltip> | ||
); | ||
|
||
const renderStatusBadge = () => { | ||
const statusText = (StorageProviderStatus[status] || 'Unknown') | ||
.replace('STATUS_', '') | ||
.split('_') | ||
.map((s) => capitalize(s)) | ||
.join(' '); | ||
|
||
return ( | ||
<Badge ml={4} colorScheme="danger"> | ||
{statusText} | ||
</Badge> | ||
); | ||
}; | ||
|
||
const renderAccessIcon = () => ( | ||
<A | ||
href={`${GREENFIELD_CHAIN_EXPLORER_URL}/account/${address}`} | ||
target="_blank" | ||
onClick={(e) => e.stopPropagation()} | ||
> | ||
<IconFont type="external" w={12} /> | ||
</A> | ||
); | ||
|
||
if (!access) { | ||
if (status === 0) { | ||
return renderUnavailableBadge(); | ||
} else { | ||
return renderStatusBadge(); | ||
} | ||
} else { | ||
return renderAccessIcon(); | ||
} | ||
}); |
82 changes: 82 additions & 0 deletions
82
apps/dcellar-web-ui/src/modules/bucket/components/SPSelector/OptionItem.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,82 @@ | ||
import { useAppSelector } from '@/store'; | ||
import { Flex, Text } from '@node-real/uikit'; | ||
import { TD } from './style'; | ||
import { DCTooltip } from '@/components/common/DCTooltip'; | ||
import { formatBytes } from '@/utils/formatter'; | ||
import { ErrorBadge } from './ErrorBadge'; | ||
import { memo } from 'react'; | ||
|
||
interface OptionItemProps { | ||
address: string; | ||
name: string; | ||
endpoint: string; | ||
access: boolean; | ||
status: number; | ||
} | ||
|
||
export const OptionItem = memo(function OptionItem({ | ||
address, | ||
name, | ||
endpoint, | ||
access, | ||
status, | ||
}: OptionItemProps) { | ||
const spMetaRecords = useAppSelector((root) => root.sp.spMetaRecords); | ||
const spLatencyRecords = useAppSelector((root) => root.sp.spLatencyRecords); | ||
const meta = spMetaRecords[endpoint]; | ||
const spLatency = spLatencyRecords[endpoint.toLowerCase()] || 0; | ||
const textColor = access ? 'readable.secondary' : 'readable.disable'; | ||
const tooltipColor = access ? 'tertiary' : 'disable'; | ||
|
||
return ( | ||
<Flex key={address} alignItems="center" cursor={access ? 'pointer' : 'not-allowed'}> | ||
<TD | ||
w={251} | ||
key={address} | ||
display="flex" | ||
flexDir="column" | ||
alignItems="flex-start" | ||
whiteSpace="normal" | ||
color={textColor} | ||
> | ||
<Flex alignItems="center" w="100%"> | ||
<Text | ||
maxW="max-content" | ||
minW={0} | ||
flex={1} | ||
lineHeight="17px" | ||
fontSize={14} | ||
fontWeight={400} | ||
w="100%" | ||
color={textColor} | ||
noOfLines={1} | ||
> | ||
{name} | ||
</Text> | ||
<ErrorBadge access={access} address={address} status={status} /> | ||
</Flex> | ||
|
||
<DCTooltip title={endpoint} placement="bottomLeft"> | ||
<Text | ||
lineHeight="14px" | ||
wordBreak="break-all" | ||
fontSize={12} | ||
transformOrigin="0 50%" | ||
transform={'scale(0.85)'} | ||
fontWeight={400} | ||
color={tooltipColor} | ||
noOfLines={1} | ||
> | ||
{endpoint} | ||
</Text> | ||
</DCTooltip> | ||
</TD> | ||
<TD w={120} color={textColor}> | ||
{meta ? formatBytes(meta.FreeReadQuota) : '--'} | ||
</TD> | ||
<TD $dot={access ? spLatency : 0} color={textColor}> | ||
{access && spLatency ? `${spLatency}ms` : '--'} | ||
</TD> | ||
</Flex> | ||
); | ||
}); |
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
Oops, something went wrong.