Skip to content

Commit

Permalink
Fix various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zooqueen committed Jul 17, 2023
1 parent b1af7e6 commit 3ba2714
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 66 deletions.
18 changes: 9 additions & 9 deletions core/config/token-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const BA_LIST = 'https://raw.githubusercontent.com/The-Blockchain-Association/se
*/
export const UNSUPPORTED_LIST_URLS: string[] = [BA_LIST]

const YEARN_LIST = 'https://yearn.science/static/tokenlist.json'
const NFTX_LIST = 'https://nftx.ethereumdb.com/v2/tokenlist/'
//const YEARN_LIST = 'https://yearn.science/static/tokenlist.json'
//const NFTX_LIST = 'https://nftx.ethereumdb.com/v2/tokenlist/'
const SYNTHETIX_LIST = 'synths.snx.eth'
const OPYN_LIST = 'https://raw.githubusercontent.com/opynfinance/opyn-tokenlist/master/opyn-v1.tokenlist.json'
//const OPYN_LIST = 'https://raw.githubusercontent.com/opynfinance/opyn-tokenlist/master/opyn-v1.tokenlist.json'
const AAVE_LIST = 'tokenlist.aave.eth'
const CMC_ALL_LIST = 'defi.cmc.eth'
const CMC_STABLECOIN = 'stablecoin.cmc.eth'
Expand All @@ -20,7 +20,7 @@ const KLEROS_LIST = 't2crtokens.eth'
export const OPTIMISM_LIST = 'https://static.optimism.io/optimism.tokenlist.json'
const ROLL_LIST = 'https://app.tryroll.com/tokens.json'
const SET_LIST = 'https://raw.githubusercontent.com/SetProtocol/uniswap-tokenlist/main/set.tokenlist.json'
const UMA_LIST = 'https://umaproject.org/uma.tokenlist.json'
//const UMA_LIST = 'https://umaproject.org/uma.tokenlist.json'
const WRAPPED_LIST = 'wrapped.tokensoft.eth'
const DHEDGE_LIST = 'https://list.dhedge.eth.link/'

Expand All @@ -30,21 +30,21 @@ export const DEFAULT_LIST_OF_LISTS: string[] = [
AAVE_LIST,
CMC_ALL_LIST,
CMC_STABLECOIN,
UMA_LIST,
YEARN_LIST,
//UMA_LIST,
//YEARN_LIST,
SYNTHETIX_LIST,
WRAPPED_LIST,
SET_LIST,
ROLL_LIST,
COINGECKO_LIST,
KLEROS_LIST,
OPYN_LIST,
NFTX_LIST,
//OPYN_LIST,
//NFTX_LIST,
OPTIMISM_LIST,
GEMINI_LIST,
DHEDGE_LIST,
...UNSUPPORTED_LIST_URLS, // need to load unsupported tokens as well
]

// default lists to be 'active' aka searched across
export const DEFAULT_ACTIVE_LIST_URLS: string[] = [NFTX_LIST, YEARN_LIST, GEMINI_LIST]
export const DEFAULT_ACTIVE_LIST_URLS: string[] = [GEMINI_LIST]
4 changes: 2 additions & 2 deletions core/features/kashi/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function KashiProvider({ children }) {

const allPairAddresses = logPairs
.filter((pair) => {
const oracle = getOracle(pair, chainId, tokens);
const oracle = getOracle(pair, chainId, Object.values(tokens));

if (!oracle.valid) {
// console.log(pair, oracle.valid, oracle.error)
Expand Down Expand Up @@ -533,7 +533,7 @@ export function KashiProvider({ children }) {
"/" +
pair.collateral.tokenInfo.symbol;

pair.oracle = getOracle(pair, chainId, tokens);
pair.oracle = getOracle(pair, chainId, Object.values(tokens));

pair.interestPerYear = {
value: pair.interestPerYear,
Expand Down
9 changes: 6 additions & 3 deletions core/hooks/useActiveWeb3React.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@

import { ethers } from "ethers";
import { Web3Provider } from '@ethersproject/providers'
import { ChainId } from '@zoolabs/zdk'
/**
* Dummy for backwards compat
*/
export function useActiveWeb3React(): {
account: string
chainId: ChainId
library: any
library: Web3Provider
connector: any
} {

const provider = new ethers.providers.Web3Provider(window.ethereum)
return {
account: '0x0000000000000000000000',
chainId: 1,
library: {},
library: provider,
connector: null,
}
}
Expand Down
11 changes: 6 additions & 5 deletions core/hooks/useContract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AddressZero } from "@ethersproject/constants";
import { Web3Provider } from "@ethersproject/providers";
import { Contract } from "@ethersproject/contracts";
import {
AddressMap,
Expand Down Expand Up @@ -80,7 +81,7 @@ export function useContract(
): Contract | null {
const { library, account, chainId } = useActiveWeb3React();

const provider = ethers.getDefaultProvider()
//const provider = ethers.getDefaultProvider()

let address: string | AddressMap | undefined = nameOrAddress;
let chainIdStr = chainId ? chainId.toString() : "1";
Expand All @@ -93,22 +94,22 @@ export function useContract(
: null;
}

const newLibrary = library ?? (canUseDefaultProvider && provider);
//const newLibrary = library ?? (canUseDefaultProvider && provider);

return useMemo(() => {
if (!address || !ABI || !newLibrary) return null;
if (!address || !ABI || !library) return null;
try {
return getContract(
altAddress ?? address.toString(),
ABI,
newLibrary,
library,
withSignerIfPossible && account ? account : undefined
);
} catch (error) {
console.error("Failed to get contract", error);
return null;
}
}, [address, ABI, newLibrary, withSignerIfPossible, account]);
}, [address, ABI, library, withSignerIfPossible, account]);
}

export function useApp(): Contract | null {
Expand Down
3 changes: 2 additions & 1 deletion core/modals/BridgeSearchModal/sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function getTokenComparator(balances: Balance[]): (tokenA: Token, tokenB: Token)

export function useTokenComparator(inverted: boolean): (tokenA: Token, tokenB: Token) => number {
const balances = useAllTokenBalances()
const comparator = useMemo(() => getTokenComparator(balances ?? Balance[]), [balances])
const allBalances = Object.values(balances).flat();
const comparator = useMemo(() => getTokenComparator(allBalances), [balances])
return useMemo(() => {

if (inverted) {
Expand Down
1 change: 0 additions & 1 deletion core/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import NextNProgress from 'nextjs-progressbar'
// import Web3ReactManager from "../components/Web3ReactManager";
// import { Web3ReactProvider } from "@web3-react/core";
import dynamic from "next/dynamic";
import getLibrary from "../functions/getLibrary";
import { i18n } from "@lingui/core";
import { nanoid } from "@reduxjs/toolkit";
import { remoteLoader } from "@lingui/remote-loader";
Expand Down
45 changes: 0 additions & 45 deletions core/state/application/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,5 @@ export default function Updater(): null {
blockNumber: null,
})

const blockNumberCallback = useCallback(
(blockNumber: number) => {
setState((state) => {
if (chainId === state.chainId) {
if (typeof state.blockNumber !== 'number') return { chainId, blockNumber }
return {
chainId,
blockNumber: Math.max(blockNumber, state.blockNumber),
}
}
return state
})
},
[chainId, setState]
)

// attach/detach listeners
useEffect(() => {
if (!library || !chainId || !windowVisible) return undefined

setState({ chainId, blockNumber: null })

library
.getBlockNumber()
.then(blockNumberCallback)
.catch((error) => console.error(`Failed to get block number for chainId: ${chainId}`, error))

library.on('block', blockNumberCallback)
return () => {
library.removeListener('block', blockNumberCallback)
}
}, [dispatch, chainId, library, blockNumberCallback, windowVisible])

const debouncedState = useDebounce(state, 100)

useEffect(() => {
if (!debouncedState.chainId || !debouncedState.blockNumber || !windowVisible) return
dispatch(
updateBlockNumber({
chainId: debouncedState.chainId,
blockNumber: debouncedState.blockNumber,
})
)
}, [windowVisible, dispatch, debouncedState.blockNumber, debouncedState.chainId])

return null
}

1 comment on commit 3ba2714

@vercel
Copy link

@vercel vercel bot commented on 3ba2714 Jul 17, 2023

Choose a reason for hiding this comment

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

@zooqueen is attempting to deploy a commit to the Zoo Labs Team on Vercel.

To accomplish this, @zooqueen needs to request access to the Team.

Afterwards, an owner of the Team is required to accept their membership request.

If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account.

Please sign in to comment.