From adb32858de1c6e581caf1f8a6e0e56925463c086 Mon Sep 17 00:00:00 2001 From: fullstack12345 Date: Tue, 15 Feb 2022 23:56:26 +0900 Subject: [PATCH] it didn't detect the ELA balance from the wallet after buy prompt is displayed fix: error in getDiaTokenInfo function --- src/components/dialog/Purchase.js | 17 ++++------------- src/utils/common.js | 7 ++++--- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/components/dialog/Purchase.js b/src/components/dialog/Purchase.js index 0cfa0d1b..a58adf60 100644 --- a/src/components/dialog/Purchase.js +++ b/src/components/dialog/Purchase.js @@ -4,18 +4,7 @@ import Web3 from 'web3'; import { ethers } from 'ethers'; import * as math from 'mathjs'; import { useWeb3React } from '@web3-react/core'; -import { - Dialog, - DialogTitle, - DialogContent, - IconButton, - Typography, - Button, - Box, - Grid, - Stack, - Divider -} from '@mui/material'; +import { Dialog, DialogTitle, DialogContent, IconButton, Typography, Button, Box, Grid, Stack, Divider } from '@mui/material'; import CloseIcon from '@mui/icons-material/Close'; import { styled } from '@mui/material/styles'; import { useSnackbar } from 'notistack'; @@ -24,6 +13,7 @@ import { stickerContract as CONTRACT_ADDRESS, marketContract as MARKET_CONTRACT_ import { essentialsConnector } from '../signin-dlg/EssentialConnectivity'; import { walletconnect } from '../signin-dlg/connectors'; import TransLoadingButton from '../TransLoadingButton'; +import useSingin from '../../hooks/useSignin'; import { reduceHexAddress, getBalance, callContractMethod, sendIpfsDidJson, isInAppBrowser } from '../../utils/common'; export default function Purchase(props) { @@ -32,6 +22,7 @@ export default function Purchase(props) { const { enqueueSnackbar } = useSnackbar(); const [onProgress, setOnProgress] = React.useState(false); const context = useWeb3React(); + const { pasarLinkAddress } = useSingin() const { library, chainId, account } = context; const { isOpen, setOpen, info } = props; @@ -180,7 +171,7 @@ export default function Purchase(props) { setBalance(math.round(res / 1e18, 4)); }); } - }, [account, chainId]); + }, [account, chainId, pasarLinkAddress]); const price = info.Price / 1e18; const platformFee = math.round((price * 2) / 100, 4); diff --git a/src/utils/common.js b/src/utils/common.js index 887ea01e..8098891a 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -150,9 +150,10 @@ export function getDiaTokenInfo(strAddress, connectProvider = null) { let walletConnectWeb3 if(connectProvider) walletConnectWeb3 = new Web3(connectProvider) - else if(Web3.givenProvider) - walletConnectWeb3 = new Web3(Web3.givenProvider) - else reject(new Error) + else if(Web3.givenProvider || Web3.currentProvider) + walletConnectWeb3 = new Web3(Web3.givenProvider || Web3.currentProvider) + else resolve('0') + // else reject(new Error) // const web3 = new Web3(Web3.givenProvider); // const MyContract = new web3.eth.Contract(DIAMOND_CONTRACT_ABI, DIA_CONTRACT_ADDRESS); // MyContract.methods.balanceOf(strAddress).call().then(console.log);