Skip to content

Commit

Permalink
it didn't detect the ELA balance from the wallet after buy prompt is …
Browse files Browse the repository at this point in the history
…displayed

fix: error in getDiaTokenInfo function
  • Loading branch information
fullstack12345 committed Feb 15, 2022
1 parent ef65ec9 commit adb3285
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
17 changes: 4 additions & 13 deletions src/components/dialog/Purchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit adb3285

Please sign in to comment.