-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace library of useActiveWeb3React with signer or provider from wa…
…gmi hook
- Loading branch information
1 parent
e57a628
commit d24c959
Showing
40 changed files
with
8,059 additions
and
4,849 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
import { SUPPORTED_WALLETS, Token } from "../constants" | ||
import { useCallback, useState } from "react" | ||
import { useChainId, useConnect } from "wagmi" | ||
|
||
import { ChainId } from "../constants/networks" | ||
import { find } from "lodash" | ||
import { Token } from "../constants" | ||
import { getTokenIconPath } from "../utils" | ||
import { useAccount } from "wagmi" | ||
import { useActiveWeb3React } from "." | ||
|
||
// @dev https://eips.ethereum.org/EIPS/eip-747#wallet_watchasset | ||
export default function useAddTokenToMetamask(token: Token | undefined): { | ||
addToken: () => void | ||
success: boolean | undefined | ||
canAdd: boolean | ||
} { | ||
const chainId = useChainId() | ||
const connector = useConnect() | ||
const [success] = useState<boolean | undefined>() | ||
const { chainId } = useActiveWeb3React() | ||
const { connector: activeConnector } = useAccount() | ||
const [success, setSuccess] = useState<boolean | undefined>() | ||
|
||
const isMetaMask: boolean = | ||
find(SUPPORTED_WALLETS, ["connector", connector])?.name == "MetaMask" | ||
const canAdd = Boolean( | ||
isMetaMask && chainId && token?.addresses[chainId as ChainId], | ||
) | ||
const isMetaMask = activeConnector?.name === "MetaMask" | ||
const canAdd = Boolean(isMetaMask && chainId && token?.addresses[chainId]) | ||
|
||
const addToken = useCallback(() => { | ||
console.log("add") | ||
}, []) | ||
if (activeConnector && isMetaMask && token) { | ||
activeConnector | ||
.watchAsset?.({ | ||
address: token.addresses[chainId], | ||
symbol: token.symbol, | ||
decimals: token.decimals, | ||
image: getTokenIconPath(token.symbol), | ||
}) | ||
.then((success: boolean) => setSuccess(success)) | ||
.catch(() => setSuccess(false)) | ||
} | ||
}, [activeConnector, chainId, isMetaMask, token]) | ||
|
||
return { addToken, success, canAdd } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.