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

Add improvements for typings #111

Merged
merged 3 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
env:
REPO_NAME_SLUG: idoux

CI: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not do this change, but rather change the linter configuration that it does not complain about todo's

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ok for me, I removed and changed the linter configuration

steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions src/api/AdditionalServicesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class AdditionalServicesApiImpl implements AdditionalServicesApi {
return url
}

public async getAllAuctionDetails(): Promise<AuctionInfo[] | null> {
public async getAllAuctionDetails(): Promise<Maybe<AuctionInfo[]>> {
try {
const promises: Promise<Response>[] = []
for (const networkId in this.urlsByNetwork) {
Expand All @@ -174,7 +174,7 @@ export class AdditionalServicesApiImpl implements AdditionalServicesApi {
}
public async getMostInterestingAuctionDetails(
params: InterestingAuctionParams,
): Promise<AuctionInfo[] | null> {
): Promise<Maybe<AuctionInfo[]>> {
try {
const url = await this.getMostInterestingAuctionDetailsUrl(params)

Expand Down Expand Up @@ -314,7 +314,7 @@ export class AdditionalServicesApiImpl implements AdditionalServicesApi {
}
}

private async query<T>(networkId: number, queryString: string): Promise<T | null> {
private async query<T>(networkId: number, queryString: string): Promise<Maybe<T>> {
const baseUrl = this._getBaseUrl(networkId)

const url = baseUrl + queryString
Expand Down
4 changes: 2 additions & 2 deletions src/components/AuctionHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const renderAuctionStatus = ({
initialAuctionOrder,
}: {
auctionState: AuctionState
auctioningToken: Token | null
initialAuctionOrder: SellOrder | null
auctioningToken: Maybe<Token>
initialAuctionOrder: Maybe<SellOrder>
}) => {
switch (auctionState) {
case AuctionState.ORDER_PLACING:
Expand Down
6 changes: 3 additions & 3 deletions src/components/CurrencyInputPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ interface CurrencyInputPanelProps {
showMaxButton: boolean
label?: string
onTokenSelection?: (tokenAddress: string) => void
token?: Token | null
token?: Maybe<Token>
disableTokenSelect?: boolean
hideBalance?: boolean
isExchange?: boolean
pair?: Pair | null
pair?: Maybe<Pair>
hideInput?: boolean
showSendWithSwap?: boolean
otherSelectedTokenAddress?: string | null
otherSelectedTokenAddress?: Maybe<string>
id: string
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/OrderbookChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface OrderBookChartProps {
/**
* price/volume data with asks and bids
*/
data: PricePointDetails[] | null
data: Maybe<PricePointDetails[]>
}

const Wrapper = styled.div`
Expand Down Expand Up @@ -94,10 +94,10 @@ export interface PricePointDetails {
priceFormatted: string
totalVolumeNumber: number
totalVolumeFormatted: string
askValueY: number | null
bidValueY: number | null
newOrderValueY: number | null
clearingPriceValueY: number | null
askValueY: Maybe<number>
bidValueY: Maybe<number>
newOrderValueY: Maybe<number>
clearingPriceValueY: Maybe<number>
}

export const createChart = (chartElement: HTMLElement): am4charts.XYChart => {
Expand Down Expand Up @@ -224,7 +224,7 @@ export const drawLabels = ({ baseToken, chart, quoteToken }: DrawLabelsParams):
const OrderBookChart: React.FC<OrderBookChartProps> = (props: OrderBookChartProps) => {
const { baseToken, data, networkId, quoteToken } = props
const mountPoint = useRef<HTMLDivElement>(null)
const chartRef = useRef<am4charts.XYChart | null>(null)
const chartRef = useRef<Maybe<am4charts.XYChart>>(null)

useEffect(() => {
if (!mountPoint.current) return
Expand Down
2 changes: 1 addition & 1 deletion src/components/OrderbookChartSmall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const Wrapper = styled.div`
const OrderBookChartSmall: React.FC<OrderBookChartProps> = (props: OrderBookChartProps) => {
const { baseToken, data, networkId, quoteToken } = props
const mountPoint = useRef<HTMLDivElement>(null)
const chartRef = useRef<am4charts.XYChart | null>(null)
const chartRef = useRef<Maybe<am4charts.XYChart>>(null)

useEffect(() => {
if (!mountPoint.current) return
Expand Down
2 changes: 1 addition & 1 deletion src/components/Popups/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function PoolPopup({
token0: { address?: string; symbol?: string }
token1: { address?: string; symbol?: string }
}) {
const pairAddress: string | null = useMemo(() => {
const pairAddress: Maybe<string> = useMemo(() => {
if (!token0 || !token1) return null
// just mock it out
return Pair.getAddress(
Expand Down
8 changes: 4 additions & 4 deletions src/components/PriceInputPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ interface CurrencyInputPanelProps {
showMaxButton: boolean
label?: string
onTokenSelection?: (tokenAddress: string) => void
biddingToken: Token | null
auctioningToken: Token | null
biddingToken: Maybe<Token>
auctioningToken: Maybe<Token>
disableTokenSelect?: boolean
hideBalance?: boolean
isExchange?: boolean
pair?: Pair | null
pair?: Maybe<Pair>
hideInput?: boolean
showSendWithSwap?: boolean
otherSelectedTokenAddress?: string | null
otherSelectedTokenAddress?: Maybe<string>
id: string
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/TransactionsModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const TransactionListWrapper = styled.div`
interface Props {
isOpen: boolean
maxHeight?: number
minHeight?: number | null
minHeight?: Maybe<number>
onDismiss: () => void
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/modals/WalletModal/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ export default function Option({
size = null,
subheader = null,
}: {
link?: string | null
link?: Maybe<string>
clickable?: boolean
size?: number | null
size?: Maybe<number>
onClick?: null | (() => void)
color: string
header: React.ReactNode
subheader: React.ReactNode | null
subheader: Maybe<React.ReactNode>
icon: string
active?: boolean
id: string
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useAllAuctionInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export interface AuctionInfo {
chainId: String
}

export function useAllAuctionInfo(): AuctionInfo[] | null {
const [auctionInfo, setAllAuctions] = useState<AuctionInfo[] | null>(null)
const [error, setError] = useState<Error | null>(null)
export function useAllAuctionInfo(): Maybe<AuctionInfo[]> {
const [auctionInfo, setAllAuctions] = useState<Maybe<AuctionInfo[]>>(null)
const [error, setError] = useState<Maybe<Error>>(null)

useEffect(() => {
let cancelled = false
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useCancelOrderCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function useCancelOrderCallback(
library,
account,
)
let estimate, method: Function, args: Array<number | string[]>, value: BigNumber | null
let estimate, method: Function, args: Array<number | string[]>, value: Maybe<BigNumber>
{
estimate = easyAuctionContract.estimateGas.cancelSellOrders
method = easyAuctionContract.cancelSellOrders
Expand Down
12 changes: 6 additions & 6 deletions src/hooks/useClaimOrderCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ export const queueStartElement =
export const queueLastElement = '0xffffffffffffffffffffffffffffffffffffffff000000000000000000000001'

export interface AuctionProceedings {
claimableBiddingToken: TokenAmount | null
claimableAuctioningToken: TokenAmount | null
claimableBiddingToken: Maybe<TokenAmount>
claimableAuctioningToken: Maybe<TokenAmount>
}

export interface ClaimInformation {
sellOrdersFormUser: string[]
}
export function useGetClaimInfo(): ClaimInformation | null {
export function useGetClaimInfo(): Maybe<ClaimInformation> {
const { account, chainId, library } = useActiveWeb3React()
const [claimInfo, setClaimInfo] = useState<ClaimInformation | null>(null)
const [error, setError] = useState<Error | null>(null)
const [claimInfo, setClaimInfo] = useState<Maybe<ClaimInformation>>(null)
const [error, setError] = useState<Maybe<Error>>(null)
const { auctionId } = useSwapState()

useMemo(() => {
Expand Down Expand Up @@ -157,7 +157,7 @@ export function useClaimOrderCallback(): null | (() => Promise<string>) {
let estimate,
method: Function,
args: Array<string | string[] | number>,
value: BigNumber | null
value: Maybe<BigNumber>
{
estimate = easyAuctionContract.estimateGas.claimFromParticipantOrder
method = easyAuctionContract.claimFromParticipantOrder
Expand Down
12 changes: 6 additions & 6 deletions src/hooks/useContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useContract(
address?: string,
ABI?: any,
withSignerIfPossible = true,
): Contract | null {
): Maybe<Contract> {
const { account, library } = useActiveWeb3React()

return useMemo(() => {
Expand All @@ -34,30 +34,30 @@ export function useContract(
}, [address, ABI, library, withSignerIfPossible, account])
}

export function useV1FactoryContract(): Contract | null {
export function useV1FactoryContract(): Maybe<Contract> {
const { chainId } = useActiveWeb3React()
return useContract(chainId === 1 ? V1_FACTORY_ADDRESS : undefined, V1_FACTORY_ABI, false)
}

export function useV1ExchangeContract(address: string): Contract | null {
export function useV1ExchangeContract(address: string): Maybe<Contract> {
return useContract(address, V1_EXCHANGE_ABI, false)
}

export function useTokenContract(
tokenAddress?: string,
withSignerIfPossible = true,
): Contract | null {
): Maybe<Contract> {
return useContract(tokenAddress, ERC20_ABI, withSignerIfPossible)
}

export function usePairContract(
pairAddress?: string,
withSignerIfPossible = true,
): Contract | null {
): Maybe<Contract> {
return useContract(pairAddress, IUniswapV2PairABI, withSignerIfPossible)
}

export function useMulticallContract(): Contract | null {
export function useMulticallContract(): Maybe<Contract> {
const { chainId } = useActiveWeb3React()
return useContract(MULTICALL_NETWORKS[chainId as ChainId], MULTICALL_ABI, false)
}
7 changes: 4 additions & 3 deletions src/hooks/useCurrentClearingOrderAndVolumeCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import { useSwapState } from '../state/orderPlacement/hooks'
import { additionalServiceApi } from './../api'
import { useActiveWeb3React } from './index'

export function useClearingPriceInfo(): ClearingPriceAndVolumeData | null {
export function useClearingPriceInfo(): Maybe<ClearingPriceAndVolumeData> {
const { account, chainId, library } = useActiveWeb3React()
const [clearingInfo, setClearingPriceAndVolume] = useState<ClearingPriceAndVolumeData | null>(
const [clearingInfo, setClearingPriceAndVolume] = useState<Maybe<ClearingPriceAndVolumeData>>(
null,
)
const [error, setError] = useState<Error | null>(null)
const [error, setError] = useState<Maybe<Error>>(null)
const { auctionId } = useSwapState()

useMemo(() => {
setClearingPriceAndVolume(null)
setError(null)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [auctionId, chainId])

useEffect(() => {
let cancelled = false

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useENSName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { useActiveWeb3React } from './index'
* Does a reverse lookup for an address to find its ENS name.
* Note this is not the same as looking up an ENS name to find an address.
*/
export default function useENSName(address?: string): string | null {
export default function useENSName(address?: string): Maybe<string> {
const { library } = useActiveWeb3React()

const [ENSName, setENSName] = useState<string | null>(null)
const [ENSName, setENSName] = useState<Maybe<string>>(null)

useEffect(() => {
if (!library || !address) return
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useInterestingAuctionDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { AuctionInfo } from './useAllAuctionInfos'
export function useInterestingAuctionInfo(
numberOfItems: number,
chainId: number,
): AuctionInfo[] | null {
const [auctionInfo, setMostInterestingAuctions] = useState<AuctionInfo[] | null>(null)
const [error, setError] = useState<Error | null>(null)
): Maybe<AuctionInfo[]> {
const [auctionInfo, setMostInterestingAuctions] = useState<Maybe<AuctionInfo[]>>(null)
const [error, setError] = useState<Maybe<Error>>(null)

useMemo(() => {
setMostInterestingAuctions(null)
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/usePlaceOrderCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function usePlaceOrderCallback(
const { auctionId, price, sellAmount } = useSwapState()
const { onNewBid } = useOrderbookActionHandlers()

const easyAuctionInstance: Contract | null = useContract(
const easyAuctionInstance: Maybe<Contract> = useContract(
EASY_AUCTION_NETWORKS[chainId as ChainId],
easyAuctionABI,
)
Expand Down Expand Up @@ -74,7 +74,7 @@ export function usePlaceOrderCallback(
let estimate,
method: Function,
args: Array<string | string[] | number>,
value: BigNumber | null
value: Maybe<BigNumber>
{
estimate = easyAuctionContract.estimateGas.placeSellOrders
method = easyAuctionContract.placeSellOrders
Expand Down
4 changes: 2 additions & 2 deletions src/state/application/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default function Updater() {
const dispatch = useDispatch()

const windowVisible = useIsWindowVisible()
const [maxBlockNumber, setMaxBlockNumber] = useState<number | null>(null)
const [maxBlockNumber, setMaxBlockNumber] = useState<Maybe<number>>(null)
// because blocks arrive in bunches with longer polling periods, we just want
// to process the latest one.
const debouncedMaxBlockNumber = useDebounce<number | null>(maxBlockNumber, 100)
const debouncedMaxBlockNumber = useDebounce<Maybe<number>>(maxBlockNumber, 100)

// update block number
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/state/multicall/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ export const updateMulticallResults = createAction<{
chainId: number
blockNumber: number
results: {
[callKey: string]: string | null
[callKey: string]: Maybe<string>
}
}>('updateMulticallResults')
2 changes: 1 addition & 1 deletion src/state/multicall/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface MulticallState {
callResults: {
[chainId: number]: {
[callKey: string]: {
data?: string | null
data?: Maybe<string>
blockNumber?: number
fetchingBlockNumber?: number
}
Expand Down
2 changes: 1 addition & 1 deletion src/state/multicall/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default function Updater() {
chainId,
results: outdatedCallKeys
.slice(firstCallKeyIndex, lastCallKeyIndex)
.reduce<{ [callKey: string]: string | null }>((memo, callKey, i) => {
.reduce<{ [callKey: string]: Maybe<string> }>((memo, callKey, i) => {
memo[callKey] = returnData[i] ?? null
return memo
}, {}),
Expand Down
Loading