vega-frontend-monorepo/libs/web3/src/lib/use-token-contract.ts
Dexter Edwards 7bf753e6c2
fix: token dependency graph (#2371)
* chore: fix dependency graph

* fix: silly error

* fix: remove uneeded generics
2022-12-09 14:02:56 +00:00

24 lines
626 B
TypeScript

import { Token, TokenFaucetable } from '@vegaprotocol/smart-contracts';
import { useWeb3React } from '@web3-react/core';
import { useMemo } from 'react';
export const useTokenContract = (address?: string, faucetable = false) => {
const { provider } = useWeb3React();
const contract = useMemo(() => {
if (!provider || !address) {
return null;
}
const signer = provider.getSigner();
if (faucetable) {
return new TokenFaucetable(address, signer || provider);
} else {
return new Token(address, signer || provider);
}
}, [provider, address, faucetable]);
return contract;
};