Skip to content

Commit

Permalink
fix ts error
Browse files Browse the repository at this point in the history
  • Loading branch information
snoopy1412 committed Nov 19, 2024
1 parent 2dce5d0 commit 3c37a2a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/collator/_hooks/collator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const useCreateCollator = ({

const { writeContractAsync, ...rest } = useWriteContract();

const oldKey = genKey({ address: address as `0x${string}`, votes: votes ?? 0n });
const oldKey = genKey({ address: address as `0x${string}`, votes: (votes as bigint) ?? 0n });

const createCollator = useCallback(
async ({ commission }: CreateAndCollatorProps) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/collator/_hooks/commissionLocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const useCommissionLocks = () => {
});

const isLockPeriod = useMemo(() => {
const locked = result?.data ?? 0n;
const locked = (result?.data as bigint) ?? 0n;
const now = BigInt(Math.floor(Date.now() / 1000));

return locked > now;
Expand Down
2 changes: 1 addition & 1 deletion src/components/collator/_hooks/update-commission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const useUpdateCommission = ({
}
});

const newKey = genKey({ address: collatorAddress, votes: votes ?? 0n });
const newKey = genKey({ address: collatorAddress, votes: (votes as bigint) ?? 0n });

const { writeContractAsync, isPending } = useWriteContract();

Expand Down
4 changes: 2 additions & 2 deletions src/components/collator/collator-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ const CollatorTabs = ({ onClose, isOpen }: CollatorTabsProps) => {
/>
)}
{selected === 'overview' && (
<CollatorOverview sessionKey={sessionKey} commissionOf={commissionOf} />
<CollatorOverview sessionKey={sessionKey} commissionOf={commissionOf as bigint} />
)}
{selected === 'manage' && (
<CollatorManagement
sessionKey={sessionKey}
commissionOf={commissionOf}
commissionOf={commissionOf as bigint}
refetch={refetch}
onStopSuccess={handleStopSuccess}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useAssetsToVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export async function assetsToVotes(
inputAmount: bigint,
operation: Operation
): Promise<bigint> {
return await readContract(config, {
return (await readContract(config, {
abi,
address,
functionName: 'assetsToVotes',
args: [commission, calculateAssets(totalAmount, inputAmount, operation)]
});
})) as unknown as bigint;
}

function calculateAssets(totalAmount: bigint, inputAmount: bigint, operation: Operation): bigint {
Expand Down
17 changes: 12 additions & 5 deletions src/view/stake/_hooks/staked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import useWalletStatus from '@/hooks/useWalletStatus';
import { useCallback, useMemo } from 'react';
import { useReadContract, useReadContracts } from 'wagmi';
import dayjs from 'dayjs';
import { Abi } from 'viem';

export type StakedDepositsInfo = [account: `0x${string}`, assets: bigint, collator: `0x${string}`];
export type StakedDepositInfo = {
Expand All @@ -24,7 +25,7 @@ export const useStakedDepositsOf = ({ account, enabled = true }: StakedDepositsO
isLoading: isStakedDepositsOfLoading,
isRefetching: isStakedDepositsOfRefetching,
refetch: refetchStakedDepositsOf
} = useReadContract({
} = useReadContract<typeof hubAbi, 'stakedDepositsOf', bigint[]>({
address,
abi: hubAbi,
functionName: 'stakedDepositsOf',
Expand All @@ -43,7 +44,7 @@ export const useStakedDepositsOf = ({ account, enabled = true }: StakedDepositsO
refetch: refetchCombinedInfo
} = useReadContracts({
contracts:
stakedDepositsOf?.flatMap((deposit) => [
((stakedDepositsOf as bigint[])?.flatMap((deposit) => [
{
address: address as `0x${string}`,
abi: hubAbi,
Expand All @@ -56,9 +57,15 @@ export const useStakedDepositsOf = ({ account, enabled = true }: StakedDepositsO
functionName: 'depositOf',
args: [deposit]
}
]) ?? [],
]) as unknown as readonly {
abi?: Abi | undefined;
functionName?: string | undefined;
args?: readonly unknown[] | undefined;
address?: `0x${string}` | undefined;
chainId?: number | undefined;
}[]) ?? [],
query: {
enabled: !!account && !!stakedDepositsOf?.length,
enabled: !!account && !!(stakedDepositsOf as bigint[])?.length,
retry: true,
retryDelay: 1000,
refetchOnWindowFocus: false,
Expand All @@ -74,7 +81,7 @@ export const useStakedDepositsOf = ({ account, enabled = true }: StakedDepositsO
const processedData = useMemo(() => {
if (!combinedInfo) return [];
return (
stakedDepositsOf?.map((tokenId, index) => {
(stakedDepositsOf as bigint[])?.map((tokenId, index) => {
const depositInfo = combinedInfo[index * 2]?.result as unknown as StakedDepositsInfo;
const depositOf = combinedInfo[index * 2 + 1]?.result;

Expand Down

0 comments on commit 3c37a2a

Please sign in to comment.