mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
restore add token / add network
This commit is contained in:
parent
b9b72f13c2
commit
1d65e5d727
@ -41,7 +41,6 @@ export function accountTruncate(account: string): string {
|
||||
}
|
||||
|
||||
export async function addCustomNetwork(
|
||||
web3Provider: any,
|
||||
network: EthereumListsChain
|
||||
): Promise<void> {
|
||||
// Always add explorer URL from ocean.js first, as it's null sometimes
|
||||
@ -59,13 +58,13 @@ export async function addCustomNetwork(
|
||||
blockExplorerUrls
|
||||
}
|
||||
try {
|
||||
await web3Provider.request({
|
||||
await window?.ethereum.request({
|
||||
method: 'wallet_switchEthereumChain',
|
||||
params: [{ chainId: newNetworkData.chainId }]
|
||||
})
|
||||
} catch (switchError) {
|
||||
if (switchError.code === 4902) {
|
||||
await web3Provider.request(
|
||||
await (window?.ethereum.request as any)(
|
||||
{
|
||||
method: 'wallet_addEthereumChain',
|
||||
params: [newNetworkData]
|
||||
@ -96,7 +95,6 @@ export async function addCustomNetwork(
|
||||
}
|
||||
|
||||
export async function addTokenToWallet(
|
||||
web3Provider: any,
|
||||
address: string,
|
||||
symbol: string,
|
||||
logo?: string
|
||||
@ -110,7 +108,7 @@ export async function addTokenToWallet(
|
||||
options: { address, symbol, image, decimals: 18 }
|
||||
}
|
||||
|
||||
web3Provider.sendAsync(
|
||||
;(window?.ethereum.request as any)(
|
||||
{
|
||||
method: 'wallet_watchAsset',
|
||||
params: tokenMetadata,
|
||||
@ -136,7 +134,7 @@ export async function getTokenBalance(
|
||||
accountId: string,
|
||||
decimals: number,
|
||||
tokenAddress: string,
|
||||
web3Provider: any
|
||||
web3Provider: ethers.providers.Provider
|
||||
): Promise<string> {
|
||||
try {
|
||||
const token = new ethers.Contract(tokenAddress, erc20ABI, web3Provider)
|
||||
|
@ -4,7 +4,6 @@ import { addTokenToWallet } from '@utils/web3'
|
||||
import Button from '@shared/atoms/Button'
|
||||
import OceanLogo from '@images/logo.svg'
|
||||
import styles from './index.module.css'
|
||||
import { useProvider } from 'wagmi'
|
||||
|
||||
const cx = classNames.bind(styles)
|
||||
|
||||
@ -23,8 +22,6 @@ export default function AddToken({
|
||||
className,
|
||||
minimal
|
||||
}: AddTokenProps): ReactElement {
|
||||
const web3Provider = useProvider()
|
||||
|
||||
const styleClasses = cx({
|
||||
button: true,
|
||||
minimal,
|
||||
@ -32,9 +29,9 @@ export default function AddToken({
|
||||
})
|
||||
|
||||
async function handleAddToken() {
|
||||
if (!web3Provider) return
|
||||
if (!window?.ethereum) return
|
||||
|
||||
await addTokenToWallet(web3Provider, address, symbol)
|
||||
await addTokenToWallet(address, symbol)
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -7,11 +7,10 @@ import useNetworkMetadata, {
|
||||
getNetworkDisplayName
|
||||
} from '@hooks/useNetworkMetadata'
|
||||
import { useAsset } from '@context/Asset'
|
||||
import { useNetwork, useProvider } from 'wagmi'
|
||||
import { useNetwork } from 'wagmi'
|
||||
|
||||
export default function WalletNetworkSwitcher(): ReactElement {
|
||||
const { chain } = useNetwork()
|
||||
const web3Provider = useProvider()
|
||||
const { asset } = useAsset()
|
||||
const { networksList } = useNetworkMetadata()
|
||||
|
||||
@ -29,7 +28,7 @@ export default function WalletNetworkSwitcher(): ReactElement {
|
||||
const networkNode = await networksList.find(
|
||||
(data) => data.chainId === asset.chainId
|
||||
)
|
||||
addCustomNetwork(web3Provider, networkNode)
|
||||
addCustomNetwork(networkNode)
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -4,7 +4,6 @@ import styles from './Network.module.css'
|
||||
import Button from '@shared/atoms/Button'
|
||||
import useNetworkMetadata from '@hooks/useNetworkMetadata'
|
||||
import { addCustomNetwork } from '@utils/web3'
|
||||
import { useProvider } from 'wagmi'
|
||||
|
||||
export default function Network({
|
||||
chainId
|
||||
@ -12,11 +11,10 @@ export default function Network({
|
||||
chainId: number
|
||||
}): ReactElement {
|
||||
const { networksList } = useNetworkMetadata()
|
||||
const web3Provider = useProvider()
|
||||
|
||||
function changeNetwork(chainId: number) {
|
||||
const networkNode = networksList.find((data) => data.chainId === chainId)
|
||||
addCustomNetwork(web3Provider, networkNode)
|
||||
addCustomNetwork(networkNode)
|
||||
}
|
||||
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user