Skip to content

Commit

Permalink
Merge branch 'develop' into yuri/relayer-subsidized-txs
Browse files Browse the repository at this point in the history
  • Loading branch information
yurixander committed Jan 26, 2025
2 parents c895520 + 2f42856 commit 83b39d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 4 additions & 2 deletions apps/tangle-dapp/src/components/KeyStatsItem/KeyStatsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type KeyStatsItemProps = {
tooltip?: string;
className?: string;
showDataBeforeLoading?: boolean;
hideErrorNotification?: boolean;
children?: ReactNode;
error: Error | null;
isLoading?: boolean;
Expand All @@ -27,6 +28,7 @@ const KeyStatsItem: FC<KeyStatsItemProps> = ({
tooltip,
className,
showDataBeforeLoading,
hideErrorNotification = false,
prefix,
suffix,
children,
Expand All @@ -36,13 +38,13 @@ const KeyStatsItem: FC<KeyStatsItemProps> = ({
// If present, report errors to the user via a toast
// notification.
useEffect(() => {
if (error !== null) {
if (error !== null && !hideErrorNotification) {
notificationApi({
variant: 'error',
message: error.message,
});
}
}, [error]);
}, [error, hideErrorNotification]);

return (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const RewardsAndPoints = () => {
return (
<div className="grid grid-cols-2 gap-6">
<KeyStatsItem
hideErrorNotification
isLoading={isLoading}
className="!p-0"
title="Unclaimed Rewards"
Expand Down
31 changes: 28 additions & 3 deletions apps/tangle-dapp/src/data/rewards/useAccountRewardInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function useAccountRewardInfo() {
[activeSubstrateAddress, assetIds, overrideRpcEndpoint, rpcEndpoint],
),
fetcher,
useMemo(() => ({ shouldRetryOnError: false }), []),
);

const result = useMemo(() => {
Expand Down Expand Up @@ -102,8 +103,8 @@ const responseSchema = z.union([
jsonrpc: z.string(),
error: z.object({
code: z.number(),
data: z.string(),
message: z.string(),
data: z.string().optional(),
}),
}),
z.object({
Expand Down Expand Up @@ -144,12 +145,36 @@ async function fetcher([rpcEndpoint, activeAddress, assetIds]: [
});

if (!response.ok) {
throw new Error(`Failed to fetch rewards for ${assetId}`);
return {
id: 1,
jsonrpc: '2.0',
error: {
code: response.status,
message: response.statusText,
},
} satisfies z.infer<typeof responseSchema>;
}

const parsed = JSONParseBigInt(await response.text());

return responseSchema.parse(parsed);
const result = responseSchema.safeParse(parsed);
if (result.success === false) {
const message =
result.error.issues.length > 0
? result.error.issues[0].message
: 'Failed to parse rewards';

return {
id: 1,
jsonrpc: '2.0',
error: {
code: response.status,
message,
},
} satisfies z.infer<typeof responseSchema>;
}

return result.data;
}),
);

Expand Down

0 comments on commit 83b39d7

Please sign in to comment.