Merge branch 'feature/network-calls-optimizations' into develop
This commit is contained in:
commit
1f8807fee6
|
@ -1,24 +1,31 @@
|
|||
import { BaseProvider } from "@ethersproject/providers";
|
||||
import { Contract } from "@ethersproject/contracts";
|
||||
import { Interface } from "@ethersproject/abi";
|
||||
import { IAddressResolver } from "./address-resolver";
|
||||
import erc20 from "../../erc20.json";
|
||||
import { TokenMeta } from "../../types";
|
||||
|
||||
const erc20Interface = new Interface(erc20);
|
||||
|
||||
export class ERCTokenResolver implements IAddressResolver<TokenMeta> {
|
||||
async resolveAddress(
|
||||
provider: BaseProvider,
|
||||
address: string
|
||||
): Promise<TokenMeta | undefined> {
|
||||
const erc20Contract = new Contract(address, erc20, provider);
|
||||
const erc20Contract = new Contract(address, erc20Interface, provider);
|
||||
try {
|
||||
const [name, symbol, decimals] = (await Promise.all([
|
||||
erc20Contract.name(),
|
||||
const name = (await erc20Contract.name()) as string;
|
||||
if (!name.trim()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const [symbol, decimals] = (await Promise.all([
|
||||
erc20Contract.symbol(),
|
||||
erc20Contract.decimals(),
|
||||
])) as [string, string, number];
|
||||
])) as [string, number];
|
||||
|
||||
// Prevent faulty tokens with empty name/symbol
|
||||
if (!name.trim() || !symbol.trim()) {
|
||||
if (!symbol.trim()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,8 @@ export const useMultipleETHUSDOracle = (
|
|||
const priceData = await ethFeed.latestRoundData({ blockTag });
|
||||
return BigNumber.from(priceData.answer);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
// Silently ignore on purpose; it means the network or block number does
|
||||
// not contain the chainlink feed contract
|
||||
return undefined;
|
||||
}
|
||||
})()
|
||||
|
|
Loading…
Reference in New Issue