Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app/search-page): fix responses validation and make fields optional #222

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const RoleDetails = ({
role,
chainId,
reputation,
amountJobsLaunched,
amountJobsProcessed,
amountStaked,
amountAllocated,
amountLocked,
Expand Down Expand Up @@ -266,7 +266,7 @@ const RoleDetails = ({
>
Jobs Launched
</Typography>
<Typography>{amountJobsLaunched}</Typography>
<Typography>{amountJobsProcessed}</Typography>
</Stack>
</Stack>
</Card>
Expand Down Expand Up @@ -315,50 +315,60 @@ const RoleDetails = ({
</Typography>
</Typography>
</Stack>
<Stack gap={{ xs: 1, md: 0 }} direction={{ sm: 'column', md: 'row' }}>
<Typography
sx={{
width: 300,
}}
fontWeight={600}
{amountAllocated !== undefined ? (
<Stack
gap={{ xs: 1, md: 0 }}
direction={{ sm: 'column', md: 'row' }}
>
Tokens Allocated
</Typography>
<Typography>
{amountAllocated}
<Typography
sx={{
marginLeft: 0.5,
width: 300,
}}
color={colorPalette.fog.main}
component="span"
fontWeight={600}
>
HMT
Tokens Allocated
</Typography>
</Typography>
</Stack>
<Stack gap={{ xs: 1, md: 0 }} direction={{ sm: 'column', md: 'row' }}>
<Typography
sx={{
width: 300,
}}
fontWeight={600}
<Typography>
{amountAllocated}
<Typography
sx={{
marginLeft: 0.5,
}}
color={colorPalette.fog.main}
component="span"
>
HMT
</Typography>
</Typography>
</Stack>
) : null}
{amountLocked !== undefined ? (
<Stack
gap={{ xs: 1, md: 0 }}
direction={{ sm: 'column', md: 'row' }}
>
Tokens Locked
</Typography>
<Typography>
{amountLocked}
<Typography
sx={{
marginLeft: 0.5,
width: 300,
}}
color={colorPalette.fog.main}
component="span"
fontWeight={600}
>
HMT
Tokens Locked
</Typography>
</Typography>
</Stack>
<Typography>
{amountLocked}
<Typography
sx={{
marginLeft: 0.5,
}}
color={colorPalette.fog.main}
component="span"
>
HMT
</Typography>
</Typography>
</Stack>
) : null}
</Stack>
</Card>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export const TransactionTableCellValue = ({ value }: { value: string }) => {
if (isPending) {
return '...';
}
const valueInDollars = ethers.formatEther(`${data.hmtPrice * Number(value)}`);
const valueInDollars = (
Number(ethers.formatEther(value)) * data.hmtPrice
).toFixed(2);

return (
<Typography>
{ethers.formatEther(value)}
{Number(ethers.formatEther(value)).toFixed()}
<Typography component="span">HMT</Typography>
<Typography
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ import { apiPaths } from '../api-paths';
import { useWalletSearch } from '@utils/hooks/use-wallet-search';
import { validateResponse } from '../../services/validate-response';

const transformOptionalTokenAmount = (
value: string | undefined,
ctx: z.RefinementCtx
) => {
if (value === undefined) return value;

const valueAsNumber = Number(value);

if (Number.isNaN(valueAsNumber)) {
ctx.addIssue({
path: ['amountStaked'],
code: z.ZodIssueCode.custom,
});
}

return valueAsNumber / 10 ** 18;
};

const walletSchema = z.object({
chainId: z.number(),
address: z.string(),
Expand Down Expand Up @@ -45,16 +63,19 @@ const leaderSchema = z.object({
address: z.string(),
balance: z.string(),
role: z.nativeEnum(Roles),
amountStaked: z.string(),
amountAllocated: z.string(),
amountLocked: z.string(),
lockedUntilTimestamp: z.string(),
amountStaked: z.string().optional().transform(transformOptionalTokenAmount),
amountAllocated: z
.string()
.optional()
.transform(transformOptionalTokenAmount),
amountLocked: z.string().optional().transform(transformOptionalTokenAmount),
lockedUntilTimestamp: z.string().optional(),
reputation: z.number(),
fee: z.number(),
jobTypes: z.array(z.string()).optional().nullable(),
url: z.string().optional().nullable(),
reward: z.string(),
amountJobsLaunched: z.string(),
reward: z.string().optional(),
amountJobsProcessed: z.string(),
});

export type AddressDetailsLeader = z.infer<typeof leaderSchema>;
Expand Down
Loading