From c6b5ce84112ac13841dd64bd8564b9db70c61c4e Mon Sep 17 00:00:00 2001 From: Lucas Recoaro Date: Thu, 14 Oct 2021 21:33:11 +1300 Subject: [PATCH] Added button Add Token to Metamask --- src/App.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/App.js b/src/App.js index 468192dac..2a0bbca93 100644 --- a/src/App.js +++ b/src/App.js @@ -120,6 +120,34 @@ function App() { SHOW_BACKGROUND: false, }); + const addTokenToWallet= () => { + const tokenDecimals = 0; + const tokenImage = 'https://www.conreco.com.ar/abuelas-plaza-mayo/output-nft/hidden.png'; + + try { + window.ethereum.request({ + method: 'wallet_watchAsset', + params: { + type: 'ERC20', // Initially only supports ERC20, but eventually more! + options: { + address: CONFIG.CONTRACT_ADDRESS, // The address that the token is at. + symbol: CONFIG.SYMBOL, // A ticker symbol or shorthand, up to 5 chars. + decimals: tokenDecimals, // The number of decimals in the token + image: tokenImage, // A string url of the token logo + } + } + }).then(() => { + console.log('Thanks for your interest!'); + }).catch(() => { + console.log('Your loss!'); + }); + + + } catch (error) { + console.log(error); + } + } + const claimNFTs = () => { let cost = CONFIG.WEI_COST; let gasLimit = CONFIG.GAS_LIMIT; @@ -273,6 +301,16 @@ function App() { Excluding gas fees. + { + e.preventDefault(); + dispatch(addTokenToWallet); + getData(); + }} + > + Add to Metamask + + {blockchain.account === "" || blockchain.smartContract === null ? (