From 1b0a2e82be16d4ad776ee2e9ac1730e533e5772c Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Wed, 21 Aug 2024 17:00:27 +0200 Subject: [PATCH] fix: typecheck issues --- apps/nextjs/src/app/_components/StarkName.tsx | 2 +- .../TransactionSubmittedModalButton.tsx | 1 + .../wallet/transactions/TransactionAction.tsx | 2 +- .../transactions/TransactionStatusL2.tsx | 3 + .../src/app/_components/wallet/utils.tsx | 4 +- .../app/account/assets/BridgeNftWrapper.tsx | 3 +- .../app/account/delegates/DelegateCard.tsx | 99 +++++++++++-------- .../src/app/account/lords/Migration.tsx | 5 +- apps/nextjs/src/app/account/lords/VeLords.tsx | 2 +- .../src/app/account/profile/Profile.tsx | 17 +++- .../src/app/account/profile/ProfileForm.tsx | 7 +- .../src/app/account/profile/SignInSIWS.tsx | 1 + apps/nextjs/src/app/bridge/Transfer.tsx | 4 +- apps/nextjs/src/app/bridge/TransferLog.tsx | 1 + .../collection/[id]/(list)/L2ERC721Card.tsx | 3 + .../app/collection/[id]/(list)/mint/page.tsx | 35 ++++--- .../[id]/[tokenId]/ContractImage.tsx | 5 +- apps/nextjs/src/app/games/[id]/page.tsx | 2 +- apps/nextjs/src/app/swap/SwapTokens.tsx | 24 ++--- .../bridge/useWriteInitiateWithdrawLords.ts | 1 + apps/nextjs/src/hooks/market/useBuyToken.tsx | 2 + .../src/hooks/market/useCancelListing.tsx | 1 + .../src/hooks/market/useEditListing.tsx | 1 + apps/nextjs/src/hooks/market/useListToken.tsx | 2 + .../src/hooks/staking/useCurrentDelegate.ts | 3 +- .../src/hooks/staking/useDelegateRealms.ts | 3 +- .../hooks/token/starknet/useERC721Approval.ts | 1 + apps/nextjs/src/hooks/useAirdropClaim.ts | 2 +- apps/nextjs/src/hooks/useStarkName.ts | 2 +- apps/nextjs/src/hooks/useTransactions.ts | 7 +- apps/nextjs/src/hooks/useTransferProgress.ts | 20 ++-- apps/nextjs/src/hooks/useTransferToL2.ts | 17 +++- apps/nextjs/src/lib/ark/ark-api.test.ts | 11 ++- apps/nextjs/src/lib/ark/client.test.ts | 1 + apps/nextjs/src/lib/ark/getPrices.ts | 7 +- .../WalletsProvider/WalletsProvider.tsx | 6 +- apps/nextjs/src/providers/Web3Providers.tsx | 83 ++++++++-------- apps/nextjs/src/types/ark.ts | 13 +++ 38 files changed, 237 insertions(+), 166 deletions(-) diff --git a/apps/nextjs/src/app/_components/StarkName.tsx b/apps/nextjs/src/app/_components/StarkName.tsx index 9db2542d..48983a14 100644 --- a/apps/nextjs/src/app/_components/StarkName.tsx +++ b/apps/nextjs/src/app/_components/StarkName.tsx @@ -11,7 +11,7 @@ export const StarkName = ({ address }: { address?: string }) => { }, [address]); const { data: starkName, refetch } = useStarkName({ - address: address, + address: address as `0x${string}`, }); useEffect(() => { diff --git a/apps/nextjs/src/app/_components/modal/TransactionSubmittedModal/TransactionSubmittedModalButton.tsx b/apps/nextjs/src/app/_components/modal/TransactionSubmittedModal/TransactionSubmittedModalButton.tsx index dac2c18a..733d387b 100644 --- a/apps/nextjs/src/app/_components/modal/TransactionSubmittedModal/TransactionSubmittedModalButton.tsx +++ b/apps/nextjs/src/app/_components/modal/TransactionSubmittedModal/TransactionSubmittedModalButton.tsx @@ -34,6 +34,7 @@ const TransactionSubmittedModalButton = ({ const { type, l2hash, l1hash } = transfer; const isTransferCompleted = l1hash && l2hash; + if (l1hash === undefined || l2hash === undefined) return null; let explorers; if (type === ActionType.TRANSFER_TO_L2 || isTransferCompleted) { diff --git a/apps/nextjs/src/app/_components/wallet/transactions/TransactionAction.tsx b/apps/nextjs/src/app/_components/wallet/transactions/TransactionAction.tsx index d07a28d8..0e5ebc26 100644 --- a/apps/nextjs/src/app/_components/wallet/transactions/TransactionAction.tsx +++ b/apps/nextjs/src/app/_components/wallet/transactions/TransactionAction.tsx @@ -31,7 +31,7 @@ export const TransactionAction = ({ tx }: { tx: CombinedTransaction }) => { type: TransactionType.BRIDGE_REALMS_L2_TO_L1_CONFIRM, chainId: SUPPORTED_L2_CHAIN_ID, status: "complete", - timestamp: new Date().getTime(), + timestamp: new Date().getTime().toString(), }); toast({ title: TransactionType.BRIDGE_REALMS_L2_TO_L1_CONFIRM, diff --git a/apps/nextjs/src/app/_components/wallet/transactions/TransactionStatusL2.tsx b/apps/nextjs/src/app/_components/wallet/transactions/TransactionStatusL2.tsx index c0799f8b..325fc0e8 100644 --- a/apps/nextjs/src/app/_components/wallet/transactions/TransactionStatusL2.tsx +++ b/apps/nextjs/src/app/_components/wallet/transactions/TransactionStatusL2.tsx @@ -18,8 +18,11 @@ export function TransactionStatusL2({ hash }: { hash: string }) { ? "Loading..." : isError ? error?.message + // @ts-expect-error TODO: check types with apibara : data?.status === "REJECTED" + // @ts-expect-error TODO: check types with apibara ? `${data.status}` + // @ts-expect-error TODO: check types with apibara : `${data?.execution_status}`} ); diff --git a/apps/nextjs/src/app/_components/wallet/utils.tsx b/apps/nextjs/src/app/_components/wallet/utils.tsx index 91b4e8d5..62f7ff34 100644 --- a/apps/nextjs/src/app/_components/wallet/utils.tsx +++ b/apps/nextjs/src/app/_components/wallet/utils.tsx @@ -11,9 +11,9 @@ export const RenderExplorers = ({ isL1 = true }) => { const { address } = useAccount(); const { address: l2address } = useL2Account(); - const explorersL1 = [{ text: address, url: ETHERSCAN_ACCOUNT_URL(address) }]; + const explorersL1 = [{ text: address, url: ETHERSCAN_ACCOUNT_URL(address as string) }]; const explorersL2 = [ - { text: l2address, url: STARKSCAN_ACCOUNT_URL(l2address) }, + { text: l2address, url: STARKSCAN_ACCOUNT_URL(l2address as string) }, ]; const explorers = isL1 ? explorersL1 : explorersL2; diff --git a/apps/nextjs/src/app/account/assets/BridgeNftWrapper.tsx b/apps/nextjs/src/app/account/assets/BridgeNftWrapper.tsx index 9ef998ee..2addd2a8 100644 --- a/apps/nextjs/src/app/account/assets/BridgeNftWrapper.tsx +++ b/apps/nextjs/src/app/account/assets/BridgeNftWrapper.tsx @@ -23,13 +23,14 @@ import { import AssetL1CollectionPreview from "./AssetL1CollectionPreview"; import AssetL2CollectionPreview from "./AssetL2CollectionPreview"; +import { TransactionFinalityStatus } from "starknet"; export const BridgeNftWrapper = () => { const [activeChain, setActiveChain] = useState("l1"); const { address } = useAccount(); const { data: pendingWithdrawals } = usePendingRealmsWithdrawals({ address, - status: "ACCEPTED_ON_L1", + status: TransactionFinalityStatus.ACCEPTED_ON_L1, }); const { toggleAccount } = useUIStore((state) => state); diff --git a/apps/nextjs/src/app/account/delegates/DelegateCard.tsx b/apps/nextjs/src/app/account/delegates/DelegateCard.tsx index 7f3e7efd..ab5b6aca 100644 --- a/apps/nextjs/src/app/account/delegates/DelegateCard.tsx +++ b/apps/nextjs/src/app/account/delegates/DelegateCard.tsx @@ -20,11 +20,19 @@ import { import { SocialIcons } from "../../_components/SocialIcons"; import { DelegateActions } from "./DelegateActions"; +type DelegateCardProps = { + delegate: RouterOutputs["delegates"]["all"]["items"][0] & { + delegateProfile?: NonNullable<{ + interests: string[]; + statement: string; + github: string; + twitter: string; + }>; + } +} export function DelegateCard({ delegate, -}: { - delegate: RouterOutputs["delegates"]["all"]["items"][0]; -}) { +}: DelegateCardProps) { //const { data, isLoading, isError } = useStarkProfile({ address: delegate.id }); //const starkName = useStarkDisplayName(delegate.id); @@ -51,51 +59,56 @@ export function DelegateCard({ - {delegate.delegateProfile && ( -
- { } - {delegate.delegateProfile.interests - ?.slice(0, 3) + { + delegate.delegateProfile && ( +
+ { + delegate.delegateProfile.interests + ?.slice(0, 3) - .map((interest, index: number) => ( - - {interest} - - ))} - {delegate.delegateProfile.interests && - delegate.delegateProfile.interests.length > 3 && ( - - + .map((interest: string, index: number) => ( - +{delegate.delegateProfile.interests.length - 3} + {interest} - - -
- {delegate.delegateProfile.interests - .slice(3) - .map((interest, index) => ( - - {interest} - - ))} -
-
-
- )} -
- )} + ))} + { + delegate.delegateProfile.interests && + delegate.delegateProfile.interests.length > 3 && ( + + + + +{ + delegate.delegateProfile.interests.length - 3} + + + +
+ { + delegate.delegateProfile.interests + .slice(3) + .map((interest: string, index: number) => ( + + {interest} + + ))} +
+
+
+ )} +
+ ) + } {delegate.delegateProfile && ( diff --git a/apps/nextjs/src/app/account/lords/Migration.tsx b/apps/nextjs/src/app/account/lords/Migration.tsx index 387accb2..ae2e9c7f 100644 --- a/apps/nextjs/src/app/account/lords/Migration.tsx +++ b/apps/nextjs/src/app/account/lords/Migration.tsx @@ -1,4 +1,5 @@ -import type { UsersRealmsQuery } from "@/types/subgraph"; +import type { Realm, UsersRealmsQuery } from "@/types/subgraph"; +import type { ColumnDef } from "@tanstack/react-table"; import { useState } from "react"; import Link from "next/link"; import { GalleonStaking } from "@/abi/L1/v1GalleonStaking"; @@ -47,7 +48,7 @@ function UnstakeStep({ ? realmsData.bridgedRealms : realmsData.bridgedV2Realms } - columns={columns} + columns={columns as ColumnDef>[]} onRowSelectionChange={setSelectedRows} rowSelection={selectedRows} /> diff --git a/apps/nextjs/src/app/account/lords/VeLords.tsx b/apps/nextjs/src/app/account/lords/VeLords.tsx index 89d9c5af..338a0424 100644 --- a/apps/nextjs/src/app/account/lords/VeLords.tsx +++ b/apps/nextjs/src/app/account/lords/VeLords.tsx @@ -29,7 +29,7 @@ export const VeLords = () => { const { address } = useAccount(); const { isLoading, data } = useBalance({ address, - token: LORDS[SUPPORTED_L2_CHAIN_ID]?.address, + token: LORDS[SUPPORTED_L2_CHAIN_ID]?.address as `0x${string}`, watch: true, }); const [amount, setAmount] = useState(); diff --git a/apps/nextjs/src/app/account/profile/Profile.tsx b/apps/nextjs/src/app/account/profile/Profile.tsx index 0a7f48ab..bdb2726f 100644 --- a/apps/nextjs/src/app/account/profile/Profile.tsx +++ b/apps/nextjs/src/app/account/profile/Profile.tsx @@ -29,6 +29,19 @@ import { import { ProfileForm } from "./ProfileForm"; import { SignInSIWS } from "./SignInSIWS"; +export interface DelegateProfile { + statement: string, + interests: string[], + twitter: string, + telegram: string, + discord: string, + github: string, +} +interface DelegatesById { + data: RouterOutputs["delegates"]["byId"] & { + delegateProfile: DelegateProfile, + } +} export const Profile = ({ initialDelegate, }: { @@ -38,7 +51,7 @@ export const Profile = ({ SUPPORTED_L2_CHAIN_ID ] as `0x${string}`; const { address } = useAccount(); - const { data: delegate } = api.delegates.byId.useQuery( + const { data: delegate }: DelegatesById = api.delegates.byId.useQuery( { user: address ?? "0x", }, @@ -129,7 +142,7 @@ export const Profile = ({ diff --git a/apps/nextjs/src/app/account/profile/ProfileForm.tsx b/apps/nextjs/src/app/account/profile/ProfileForm.tsx index 096d20d0..dcccc265 100644 --- a/apps/nextjs/src/app/account/profile/ProfileForm.tsx +++ b/apps/nextjs/src/app/account/profile/ProfileForm.tsx @@ -10,7 +10,8 @@ import { Github, Loader } from "lucide-react"; import { useSession } from "next-auth/react"; import { useForm } from "react-hook-form"; -import type { RouterOutputs } from "@realms-world/api"; +import type { DelegateProfile } from "@/app/account/profile/Profile"; + import { CreateDelegateProfileSchema } from "@realms-world/db/schema"; import { Button, @@ -33,9 +34,7 @@ export const ProfileForm = ({ delegateProfile, }: { delegateId: string; - delegateProfile?: NonNullable< - RouterOutputs["delegates"]["byId"] - >["delegateProfile"]; + delegateProfile?: NonNullable; }) => { const formRef = useRef(null); const form = useForm({ diff --git a/apps/nextjs/src/app/account/profile/SignInSIWS.tsx b/apps/nextjs/src/app/account/profile/SignInSIWS.tsx index 5ab28903..d974a6dd 100644 --- a/apps/nextjs/src/app/account/profile/SignInSIWS.tsx +++ b/apps/nextjs/src/app/account/profile/SignInSIWS.tsx @@ -14,6 +14,7 @@ export const SignInSIWS = () => { const { address } = useAccount(); const { data: delegate } = api.delegates.byId.useQuery( { + // @ts-expect-error this is ok user: address, }, { diff --git a/apps/nextjs/src/app/bridge/Transfer.tsx b/apps/nextjs/src/app/bridge/Transfer.tsx index 4f667856..abae6d62 100644 --- a/apps/nextjs/src/app/bridge/Transfer.tsx +++ b/apps/nextjs/src/app/bridge/Transfer.tsx @@ -27,7 +27,7 @@ export const Transfer = ({ action }: { action: string }) => { const { address: l2Address } = useAccount(); // const [toastOpen, setToastOpen] = useState(false); const [amount, setAmount] = useState("0"); - const { balances, l2loading } = useWalletsProviderContext(); + const { balances } = useWalletsProviderContext(); const { sendAsync: iniateWithdrawal } = useWriteInitiateWithdrawLords({ amount, }); @@ -91,7 +91,7 @@ export const Transfer = ({ action }: { action: string }) => { : (balances.l1.lords ?? BigInt(0)) } symbol="Lords" - isLoading={isL2 ? l2loading && !balances.l2.lords : false} + isLoading={isL2 ? !balances.l2.lords : false} /> diff --git a/apps/nextjs/src/app/bridge/TransferLog.tsx b/apps/nextjs/src/app/bridge/TransferLog.tsx index a54eb8bf..512c8772 100644 --- a/apps/nextjs/src/app/bridge/TransferLog.tsx +++ b/apps/nextjs/src/app/bridge/TransferLog.tsx @@ -116,6 +116,7 @@ export const TransferLog = ({ disabled={!l1hash} asChild > + {/* @ts-expect-error button is disabled if l1hash is not defined */} {`${NetworkType.L1} Tx`} diff --git a/apps/nextjs/src/app/collection/[id]/(list)/L2ERC721Card.tsx b/apps/nextjs/src/app/collection/[id]/(list)/L2ERC721Card.tsx index dfeb111b..df9824d2 100644 --- a/apps/nextjs/src/app/collection/[id]/(list)/L2ERC721Card.tsx +++ b/apps/nextjs/src/app/collection/[id]/(list)/L2ERC721Card.tsx @@ -154,6 +154,9 @@ const Price = ({ const { lordsPrice } = useLordsPrice(); const listing = findLowestPriceActiveListing(token.listings, token.owner); + if (!listing) return null; + if (!listing.price) return null; + return (
{token.price && ( diff --git a/apps/nextjs/src/app/collection/[id]/(list)/mint/page.tsx b/apps/nextjs/src/app/collection/[id]/(list)/mint/page.tsx index d54e00ca..ebc3cb78 100644 --- a/apps/nextjs/src/app/collection/[id]/(list)/mint/page.tsx +++ b/apps/nextjs/src/app/collection/[id]/(list)/mint/page.tsx @@ -49,7 +49,8 @@ export default function Mint() { const { data: mintData, - write, + // FIX: this may wont work + send: write, isPending: isTxSubmitting, } = useSendTransaction({ calls: [ @@ -99,7 +100,7 @@ export default function Mint() { className="mr-4" disabled={isLoading} size={"lg"} - // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return + onClick={() => write()} > {isLoading && } @@ -125,21 +126,23 @@ export default function Mint() { high: (submittedData as any)?.events[1]?.data[3], }) .toString()} - + + View Tx Explorer + + + + } ) : ( diff --git a/apps/nextjs/src/app/collection/[id]/[tokenId]/ContractImage.tsx b/apps/nextjs/src/app/collection/[id]/[tokenId]/ContractImage.tsx index 92b9c568..d18d44b6 100644 --- a/apps/nextjs/src/app/collection/[id]/[tokenId]/ContractImage.tsx +++ b/apps/nextjs/src/app/collection/[id]/[tokenId]/ContractImage.tsx @@ -31,16 +31,13 @@ export const ContractImage = ({ functionName: "token_uri", args: [tokenId], abi: L2_C1ERC20, - address: tokenAddress, + address: tokenAddress as `0x${string}`, watch: true, }); const tokenUriData = useMemo(() => { - //@ts-expect-error data does have length if (data?.length) { const value = []; - //@ts-expect-error data does have length for (let i = 1; i < data.length; i++) { - //@ts-expect-error data does have length const result = shortString.decodeShortString(data[i]); value.push(result); } diff --git a/apps/nextjs/src/app/games/[id]/page.tsx b/apps/nextjs/src/app/games/[id]/page.tsx index 0c5e18aa..f05a27fb 100644 --- a/apps/nextjs/src/app/games/[id]/page.tsx +++ b/apps/nextjs/src/app/games/[id]/page.tsx @@ -244,7 +244,7 @@ export default async function Page({ params }: { params: { id: string } }) {
- {game.playable && ( + {game.playable && game.links.homepage && ( @@ -220,9 +221,9 @@ export const SwapTokens = ({ value={ quotes[0] ? formatUnits( - quotes[0].buyAmount, - selectedTokenObj?.decimals ?? 18, - ) + quotes[0].buyAmount, + selectedTokenObj?.decimals ?? 18, + ) : buyAmount } /> @@ -314,7 +315,7 @@ export const SwapTokens = ({ onClick={() => setSellAmount(formatEther(BigInt(sellBalance)))} balance={sellBalance} symbol="" - isLoading={l2loading && !balances.l2.lords} + isLoading={!balances.l2.lords} />
@@ -325,9 +326,8 @@ export const SwapTokens = ({ tabIndex={0} > )} @@ -345,7 +345,7 @@ export const SwapTokens = ({ disabled={ loading || !sellAmount || parseEther(sellAmount) > sellBalance } - onClick={handleSwap} + onClick={() => handleSwap} className="mt-2 w-full" > {buttonContent()} diff --git a/apps/nextjs/src/hooks/bridge/useWriteInitiateWithdrawLords.ts b/apps/nextjs/src/hooks/bridge/useWriteInitiateWithdrawLords.ts index 01a639a3..fc50a6b5 100644 --- a/apps/nextjs/src/hooks/bridge/useWriteInitiateWithdrawLords.ts +++ b/apps/nextjs/src/hooks/bridge/useWriteInitiateWithdrawLords.ts @@ -21,6 +21,7 @@ export const useWriteInitiateWithdrawLords = ({ const l2BridgeAddress = LORDS_BRIDGE_ADDRESS[SUPPORTED_L2_CHAIN_ID]; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { contract } = useContract({ + // @ts-expect-error check starknet-react type abi: L2BridgeABI, address: l2BridgeAddress as `0x${string}`, }); diff --git a/apps/nextjs/src/hooks/market/useBuyToken.tsx b/apps/nextjs/src/hooks/market/useBuyToken.tsx index 9d638bcd..f510d33b 100644 --- a/apps/nextjs/src/hooks/market/useBuyToken.tsx +++ b/apps/nextjs/src/hooks/market/useBuyToken.tsx @@ -20,11 +20,13 @@ export const useBuyToken = ({ }) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { contract } = useContract({ + // @ts-expect-error check starknet-react type abi: MarketplaceABI, address: MarketplaceContract[SUPPORTED_L2_CHAIN_ID] as `0x${string}`, }); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { contract: lordsContract } = useContract({ + // @ts-expect-error check starknet-react type abi: L2_C1ERC20, address: LORDS[SUPPORTED_L2_CHAIN_ID]?.address as `0x${string}`, }); diff --git a/apps/nextjs/src/hooks/market/useCancelListing.tsx b/apps/nextjs/src/hooks/market/useCancelListing.tsx index 174f0645..c4daf2e2 100644 --- a/apps/nextjs/src/hooks/market/useCancelListing.tsx +++ b/apps/nextjs/src/hooks/market/useCancelListing.tsx @@ -12,6 +12,7 @@ import { MarketplaceContract } from "@realms-world/constants"; export const useCancelListing = ({ listingId }: { listingId?: number }) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { contract } = useContract({ + // @ts-expect-error check starknet-react type abi: MarketplaceABI, address: MarketplaceContract[SUPPORTED_L2_CHAIN_ID] as `0x${string}`, }); diff --git a/apps/nextjs/src/hooks/market/useEditListing.tsx b/apps/nextjs/src/hooks/market/useEditListing.tsx index 0580aaa3..260a7bfa 100644 --- a/apps/nextjs/src/hooks/market/useEditListing.tsx +++ b/apps/nextjs/src/hooks/market/useEditListing.tsx @@ -19,6 +19,7 @@ export const useEditListing = ({ }) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { contract } = useContract({ + // @ts-expect-error check starknet-react type abi: MarketplaceABI, address: MarketplaceContract[SUPPORTED_L2_CHAIN_ID] as `0x${string}`, }); diff --git a/apps/nextjs/src/hooks/market/useListToken.tsx b/apps/nextjs/src/hooks/market/useListToken.tsx index 59954d32..4fdec556 100644 --- a/apps/nextjs/src/hooks/market/useListToken.tsx +++ b/apps/nextjs/src/hooks/market/useListToken.tsx @@ -29,12 +29,14 @@ export const useListToken = ({ }) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { contract } = useContract({ + // @ts-expect-error check starknet-react type abi: MarketplaceABI, address: MarketplaceContract[SUPPORTED_L2_CHAIN_ID] as `0x${string}`, }); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { contract: collectionContract } = useContract({ + // @ts-expect-error check starknet-react type abi: ERC721ABI, address: collectionId as `0x${string}`, }); diff --git a/apps/nextjs/src/hooks/staking/useCurrentDelegate.ts b/apps/nextjs/src/hooks/staking/useCurrentDelegate.ts index 86be253b..3f320127 100644 --- a/apps/nextjs/src/hooks/staking/useCurrentDelegate.ts +++ b/apps/nextjs/src/hooks/staking/useCurrentDelegate.ts @@ -9,7 +9,8 @@ import { Collections, getCollectionAddresses } from "@realms-world/constants"; export const useCurrentDelegate = () => { const { address } = useAccount(); - const l2RealmsAddress = getCollectionAddresses(Collections.REALMS)[ + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const l2RealmsAddress = getCollectionAddresses(Collections.REALMS)![ SUPPORTED_L2_CHAIN_ID ] as `0x${string}`; diff --git a/apps/nextjs/src/hooks/staking/useDelegateRealms.ts b/apps/nextjs/src/hooks/staking/useDelegateRealms.ts index c18f6ff5..8072680e 100644 --- a/apps/nextjs/src/hooks/staking/useDelegateRealms.ts +++ b/apps/nextjs/src/hooks/staking/useDelegateRealms.ts @@ -5,7 +5,8 @@ import { useContract, useSendTransaction } from "@starknet-react/core"; import { Collections, getCollectionAddresses } from "@realms-world/constants"; export const useDelegateRealms = ({ delegatee }: { delegatee?: string }) => { - const l2RealmsAddress = getCollectionAddresses(Collections.REALMS)[ + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const l2RealmsAddress = getCollectionAddresses(Collections.REALMS)![ SUPPORTED_L2_CHAIN_ID ] as `0x${string}`; diff --git a/apps/nextjs/src/hooks/token/starknet/useERC721Approval.ts b/apps/nextjs/src/hooks/token/starknet/useERC721Approval.ts index 09ca57d4..ffc608dc 100644 --- a/apps/nextjs/src/hooks/token/starknet/useERC721Approval.ts +++ b/apps/nextjs/src/hooks/token/starknet/useERC721Approval.ts @@ -20,6 +20,7 @@ export const useERC721Approval = ({ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { contract } = useContract({ + // @ts-expect-error check starknet-react type abi: ERC721ABI, address: contractAddress as `0x${string}`, }); diff --git a/apps/nextjs/src/hooks/useAirdropClaim.ts b/apps/nextjs/src/hooks/useAirdropClaim.ts index ec339c1c..12c0119b 100644 --- a/apps/nextjs/src/hooks/useAirdropClaim.ts +++ b/apps/nextjs/src/hooks/useAirdropClaim.ts @@ -18,7 +18,7 @@ import airdrop from "../constants/airdrop.json"; function generateLeaf(address: string, value: string): Buffer { return Buffer.from( // Hash in appropriate Merkle format - keccak256(encodePacked(["address", "uint256"], [address, value])).slice(2), + keccak256(encodePacked(["address", "uint256"], [address as `0x${string}`, BigInt(value)])).slice(2), "hex", ); } diff --git a/apps/nextjs/src/hooks/useStarkName.ts b/apps/nextjs/src/hooks/useStarkName.ts index 228ca3ab..4e25ae01 100644 --- a/apps/nextjs/src/hooks/useStarkName.ts +++ b/apps/nextjs/src/hooks/useStarkName.ts @@ -11,7 +11,7 @@ export function useStarkDisplayName(address?: string) { }, [address]); const { data: starkName, refetch } = useStarkName({ - address: address, + address: address as `0x${string}`, }); useEffect(() => { diff --git a/apps/nextjs/src/hooks/useTransactions.ts b/apps/nextjs/src/hooks/useTransactions.ts index aa924439..83af8cb8 100644 --- a/apps/nextjs/src/hooks/useTransactions.ts +++ b/apps/nextjs/src/hooks/useTransactions.ts @@ -77,13 +77,12 @@ export const useTransactions = () => { TransactionType.BRIDGE_REALMS_L2_TO_L1_CONFIRM; matchingTransaction.chainId = SUPPORTED_L1_CHAIN_ID; } else { + const hash = withdrawal.withdrawalEvents[0] === undefined ? "" : withdrawal.withdrawalEvents[0].finishedTxHash ?? withdrawal.withdrawalEvents[0].createdTxHash; map.set(BigInt(withdrawal.req_hash), { ...withdrawal, chainId: SUPPORTED_L1_CHAIN_ID, req_hash: withdrawal.req_hash.toString(), - hash: - withdrawal.withdrawalEvents[0]?.finishedTxHash ?? - withdrawal.withdrawalEvents[0]?.createdTxHash, + hash, l1Account: padAddress(address), l2Account: padAddress(l2Address), timestamp: new Date( @@ -116,7 +115,7 @@ export const useTransactions = () => { // Add transactions to the map, deduplicating by hash transactionsArray.forEach((tx) => { if (tx.hash && !transactionsMap.has(tx.hash)) { - transactionsMap.set(tx.hash, tx); + transactionsMap.set(tx.hash, tx as CombinedTransaction); } }); diff --git a/apps/nextjs/src/hooks/useTransferProgress.ts b/apps/nextjs/src/hooks/useTransferProgress.ts index 4a749dc6..8ddf04de 100644 --- a/apps/nextjs/src/hooks/useTransferProgress.ts +++ b/apps/nextjs/src/hooks/useTransferProgress.ts @@ -2,7 +2,7 @@ import { useMemo } from "react"; -const evaluate = (template: any, model: any) => { +const evaluateTemplateVars = (template: any, model: any) => { try { let reg_1; let res_1 = template; @@ -51,7 +51,7 @@ const transferProgressStrings = { export const useTransferProgress = () => { return useMemo( () => ({ - approval: (symbol: string, activeStep: number) => { + approval: (symbol: string, activeStep: string) => { const { approval } = transferProgressStrings; const message = approval.message; return { @@ -60,9 +60,9 @@ export const useTransferProgress = () => { activeStep, }; }, - deposit: (amount: string, symbol: string, activeStep: number) => { + deposit: (amount: string, symbol: string, activeStep: string) => { const { deposit } = transferProgressStrings; - const message = evaluate(deposit.message, { amount, symbol }); + const message = evaluateTemplateVars(deposit.message, { amount, symbol }); return { type: deposit.type, message, @@ -75,26 +75,26 @@ export const useTransferProgress = () => { activeStep: number, ) => { const { initiateWithdraw } = transferProgressStrings; - const message = evaluate(initiateWithdraw.message, { amount, symbol }); + const message = evaluateTemplateVars(initiateWithdraw.message, { amount, symbol }); return { type: initiateWithdraw.type, message, activeStep, }; }, - waitForConfirm: (walletName: string, activeStep: number) => { + waitForConfirm: (walletName: string, activeStep: string) => { const { waitForConfirm } = transferProgressStrings; - const type = evaluate(waitForConfirm.type, { walletName }); - const message = evaluate(waitForConfirm.message, { walletName }); + const type = evaluateTemplateVars(waitForConfirm.type, { walletName }); + const message = evaluateTemplateVars(waitForConfirm.message, { walletName }); return { type, message, activeStep, }; }, - withdraw: (amount: number, symbol: string, activeStep: number) => { + withdraw: (amount: number, symbol: string, activeStep: string) => { const { withdraw } = transferProgressStrings; - const message = evaluate(withdraw.message, { amount, symbol }); + const message = evaluateTemplateVars(withdraw.message, { amount, symbol }); return { type: withdraw.type, message, diff --git a/apps/nextjs/src/hooks/useTransferToL2.ts b/apps/nextjs/src/hooks/useTransferToL2.ts index 195112a2..72c78b0b 100644 --- a/apps/nextjs/src/hooks/useTransferToL2.ts +++ b/apps/nextjs/src/hooks/useTransferToL2.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access */ import { useCallback, useEffect, useState } from "react"; import { SUPPORTED_L1_CHAIN_ID } from "@/constants/env"; import { @@ -26,9 +26,16 @@ export const TransferError = { MAX_TOTAL_BALANCE_ERROR: 1, }; -export const stepOf = (step: any, steps: any): boolean => { +export const stepOf = (step: string, steps: string[]): boolean => { return steps.includes(step); }; +export const getStep = (step: string, steps: string[]): string => { + const activeStep = steps.find((s) => s === step); + if (!activeStep) { + throw new Error(`Step ${step} not found in steps ${steps.join(",")}`); + } + return activeStep; +} export const useTransferToL2 = () => { const [amount, setAmount] = useState(""); @@ -93,7 +100,7 @@ export const useTransferToL2 = () => { progressOptions.deposit( amount, "Lords", - stepOf(TransferStep.DEPOSIT, TransferToL2Steps), + getStep(TransferStep.DEPOSIT, TransferToL2Steps), ), ); } @@ -101,7 +108,7 @@ export const useTransferToL2 = () => { handleProgress( progressOptions.waitForConfirm( connector?.name ?? "Wallet", - stepOf(TransferStep.CONFIRM_TX, TransferToL2Steps), + getStep(TransferStep.CONFIRM_TX, TransferToL2Steps), ), ); const hash = l2Address @@ -143,7 +150,7 @@ export const useTransferToL2 = () => { handleProgress( progressOptions.approval( "Lords", - stepOf(TransferStep.APPROVE, TransferToL2Steps), + getStep(TransferStep.APPROVE, TransferToL2Steps), ), ); console.log("Current allow value", formatEther(allowance ?? BigInt(0))); diff --git a/apps/nextjs/src/lib/ark/ark-api.test.ts b/apps/nextjs/src/lib/ark/ark-api.test.ts index b1f87396..722df7cf 100644 --- a/apps/nextjs/src/lib/ark/ark-api.test.ts +++ b/apps/nextjs/src/lib/ark/ark-api.test.ts @@ -1,6 +1,7 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-explicit-any */ import { erc721Tokens } from "@/constants"; import { ChainType } from "@/constants/tokens"; +import type { Mock } from "vitest"; import { beforeEach, describe, expect, it, vi } from "vitest"; import type { Fetcher } from "./client"; @@ -56,13 +57,15 @@ vi.mock("mobula-sdk", () => { }); describe("ArkApi", () => { - let fetchMock: Fetcher; + let fetchMock: Mock>; let client: ArkClient; beforeEach(() => { + + // @ts-expect-error testing mock may not cause type errors... fetchMock = vi.fn(() => ({ json: () => Promise.resolve({}), - })) as Fetcher; - client = new ArkClient(fetchMock); + })); + client = new ArkClient(fetchMock, "http://localhost:9999"); }); it("should get collections", async () => { diff --git a/apps/nextjs/src/lib/ark/client.test.ts b/apps/nextjs/src/lib/ark/client.test.ts index 59cf7a7e..2437d55e 100644 --- a/apps/nextjs/src/lib/ark/client.test.ts +++ b/apps/nextjs/src/lib/ark/client.test.ts @@ -5,6 +5,7 @@ import { ArkClient } from "./client"; describe("ArkClient", () => { it("should work", async () => { const client = new ArkClient( + // @ts-expect-error testing mock may not cause type errors... () => ({ json: () => Promise.resolve({}) }), "http://localhost:9999", ); diff --git a/apps/nextjs/src/lib/ark/getPrices.ts b/apps/nextjs/src/lib/ark/getPrices.ts index 4116c147..8e62bc34 100644 --- a/apps/nextjs/src/lib/ark/getPrices.ts +++ b/apps/nextjs/src/lib/ark/getPrices.ts @@ -11,13 +11,16 @@ export async function getPrices(): Promise { const response = await mobula.fetchMultipleAssetMarketData({ assets: "ethereum,starknet", }); + return { // TODO: add lords price ethereum: { - price: response.multiDataResponse.data.ethereum?.price as number, + // @ts-expect-error check mobula type but if response is undefined I expect fetch to throw error + price: response.multiDataResponse.data.ethereum.price as number, }, starknet: { - price: response.multiDataResponse.data.starknet?.price as number, + // @ts-expect-error check mobula type but if response is undefined I expect fetch to throw error + price: response.multiDataResponse.data.starknet.price as number, }, }; // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/apps/nextjs/src/providers/WalletsProvider/WalletsProvider.tsx b/apps/nextjs/src/providers/WalletsProvider/WalletsProvider.tsx index 672f5807..5f2a8968 100644 --- a/apps/nextjs/src/providers/WalletsProvider/WalletsProvider.tsx +++ b/apps/nextjs/src/providers/WalletsProvider/WalletsProvider.tsx @@ -35,7 +35,6 @@ interface WalletsProviderContextValue { eth?: bigint; }; }; - l2loading: boolean; refetch: () => void; } @@ -126,7 +125,6 @@ export const WalletsProvider: React.FC = ({ accountHash, tokens, // updateTokenBalance, - //l2loading: l2LordsIsLoading || l2EthIsLoading, refetch: refetch, balances: { l1: { @@ -134,11 +132,9 @@ export const WalletsProvider: React.FC = ({ lords: l1LordsBalance?.value, }, l2: { - //@ts-expect-error incorrect SN react types // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access eth: l2EthBalance?.balance - ? //@ts-expect-error incorrect SN react types - + ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument uint256.uint256ToBN(l2EthBalance.balance) : 0n, diff --git a/apps/nextjs/src/providers/Web3Providers.tsx b/apps/nextjs/src/providers/Web3Providers.tsx index ef05707c..1c8c5041 100644 --- a/apps/nextjs/src/providers/Web3Providers.tsx +++ b/apps/nextjs/src/providers/Web3Providers.tsx @@ -26,8 +26,8 @@ import { TransferLogProvider } from "./TransferLogProvider"; const starkProvider = env.NEXT_PUBLIC_BLAST_API ? blastProvider({ - apiKey: env.NEXT_PUBLIC_BLAST_API, - }) + apiKey: env.NEXT_PUBLIC_BLAST_API, + }) : starkPublicProvider(); const starkConnectors = [ @@ -65,45 +65,48 @@ export function Web3Providers({ children }: { children: ReactElement }) { // Randomize the order of the connectors. order: "alphabetical", });*/ - return ( - - - - - - {children} - - - - - - ); + ] + } + provider={starkProvider} + // @ts-expect-error check starknet-react types + connectors={starkConnectors} + > + + + + + {children} + + + + + + ; } diff --git a/apps/nextjs/src/types/ark.ts b/apps/nextjs/src/types/ark.ts index ab2d8038..fe23eb1f 100644 --- a/apps/nextjs/src/types/ark.ts +++ b/apps/nextjs/src/types/ark.ts @@ -191,3 +191,16 @@ export interface TokenOffer { price: string; source: string; } + +export interface Token { + collection_image: string; + collection_name: string; + collection_address: string; + last_price?: string; + metadata?: TokenMetadata; + owner: string; + price?: string; + top_offer?: string; + token_id: string; +} +