Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChqrles committed May 1, 2024
1 parent 7d8a1fd commit 48efe28
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"g:test": "turbo run test",
"g:test:watch": "turbo run test:watch",
"g:prepare": "turbo run prepare",
"g:rm:local-packages": "rm -rf ./node_modules/core ./node_modules/hooks",
"g:rm:nodemodules": "rm -rf node_modules"
},
"workspaces": [
Expand Down
4 changes: 1 addition & 3 deletions packages/frontend/src/components/ImportTokenModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useCloseModal, useImportTokenModal } from 'src/hooks/useModal'
import Box from 'src/theme/components/Box'
import { Column } from 'src/theme/components/Flex'
import * as Text from 'src/theme/components/Text'
import { isValidL2Address } from 'src/utils/address'
import { address } from 'src/utils/zod'
import { z } from 'zod'

Expand Down Expand Up @@ -66,8 +65,7 @@ export function ImportTokenModal({ save = false }: ImportTokenModalProps) {
const debouncedTokenAddress = useDebounce(tokenAddress)

// token check
const tokenAddressToUse = isValidL2Address(debouncedTokenAddress) ? debouncedTokenAddress : undefined
const { data: memecoin, isLoading, ruggable } = useMemecoin(tokenAddressToUse)
const { data: memecoin, isLoading, ruggable } = useMemecoin(debouncedTokenAddress)

useEffect(() => {
if (memecoin && isOpen && chainId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useContractWrite, useWaitForTransaction } from '@starknet-react/core'
import { useEffect, useMemo, useState } from 'react'
import { STARKNET_POLLING } from 'src/constants/misc'
import { useCloseModal, useTransactionModal } from 'src/hooks/useModal'
import { useTransaction } from 'src/hooks/useTransactions'
import { InvokeTransactionDetails } from 'src/state/transaction'
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/hooks/useBalances.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAccount, useContractRead, UseContractReadResult } from '@starknet-react/core'
import { Fraction } from '@uniswap/sdk-core'
import { Token } from 'core'
import { compiledMulticall, MULTICALL_ADDRESSES, Entrypoint } from 'core/constants'
import { compiledMulticall, Entrypoint, MULTICALL_ADDRESSES } from 'core/constants'
import { useMemo } from 'react'
import { decimalsScale } from 'src/utils/decimals'
import { CallStruct, selector, uint256 } from 'starknet'
Expand Down
7 changes: 7 additions & 0 deletions packages/frontend/src/hooks/useMemecoin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { useAccount } from '@starknet-react/core'
import { useMemecoin as useSDKMemecoin } from 'hooks'
import { useMemo } from 'react'
import { isValidL2Address } from 'src/utils/address'
import { getChecksumAddress } from 'starknet'

export default function useMemecoin(tokenAddress?: string) {
// token address check
tokenAddress = useMemo(
() => (tokenAddress && isValidL2Address(tokenAddress) ? tokenAddress : undefined),
[tokenAddress],
)

// store
// memecoin, refreshMemecoin, setTokenAddress, ruggable, resetMemecoin
const memecoin = useSDKMemecoin({
Expand Down
1 change: 1 addition & 0 deletions packages/hooks/src/constants/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const STARKNET_BLOCK_POLLING = 5000 // 5s
2 changes: 2 additions & 0 deletions packages/hooks/src/hooks/internal/useInvalidateOnBlock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useBlockNumber } from '@starknet-react/core'
import { QueryKey, useQueryClient } from '@tanstack/react-query'
import { useEffect, useRef } from 'react'
import { STARKNET_BLOCK_POLLING } from 'src/constants/misc'

/**
* Invalidates the given query keys on every new block.
Expand All @@ -20,6 +21,7 @@ export function useInvalidateOnBlock({

const { data: blockNumber } = useBlockNumber({
enabled,
refetchInterval: STARKNET_BLOCK_POLLING,
})

useEffect(() => {
Expand Down
4 changes: 1 addition & 3 deletions packages/hooks/src/providers/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ export interface ProviderProps {

/** React-query client to use. */
queryClient?: QueryClient

children?: React.ReactNode
}

export function Provider({ factory, queryClient, children }: ProviderProps) {
export function Provider({ factory, queryClient, children }: React.PropsWithChildren<ProviderProps>) {
return (
<FactoryProvider factory={factory}>
<QueryProvider queryClient={queryClient}>{children}</QueryProvider>
Expand Down
5 changes: 2 additions & 3 deletions packages/hooks/src/providers/QueryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/reac

const defaultQueryClient = new QueryClient()

type QueryProviderProps = {
interface QueryProviderProps {
queryClient?: QueryClient
children?: React.ReactNode
}

export function QueryProvider({ queryClient, children }: QueryProviderProps) {
export function QueryProvider({ queryClient, children }: React.PropsWithChildren<QueryProviderProps>) {
const existingQueryClient = useQueryClient()

// There is already a QueryClientProvider higher up in the tree
Expand Down

0 comments on commit 48efe28

Please sign in to comment.