diff --git a/src/components/HeaderWallet.vue b/src/components/HeaderWallet.vue index c3e69cce..2b0fec0e 100644 --- a/src/components/HeaderWallet.vue +++ b/src/components/HeaderWallet.vue @@ -102,7 +102,7 @@ import {mapState, mapMutations, mapActions} from "vuex" import {ethAddressByAccountId} from "@/lib/polkadotProvider/query/userProfile" import {queryBalance} from "@/lib/polkadotProvider/query/balance" -import {getBalanceETH} from "@/lib/metamask/wallet.js" +import {getBalanceDAI} from "@/lib/metamask/wallet.js" import {fromEther} from "@/lib/balance-format" import Button from "@/components/Button" @@ -162,7 +162,8 @@ export default { this.$emit("showWalletBinding", true) }, - async checkMetamaskAddress() { + async checkMetamaskBalance() { + this.metamaskAddress = this.metamaskWalletAddress let address = "" if (this.metamaskWalletAddress == "") { const ethRegisterAddress = await ethAddressByAccountId( @@ -175,11 +176,9 @@ export default { } if (address != "") { - const balance = await getBalanceETH(address) + const balance = await getBalanceDAI(address) - this.setMetamaskAddress(address) this.setMetamaskBalance(balance) - this.metamaskAddress = address this.metamaskBalance = balance } }, @@ -201,6 +200,7 @@ export default { }, disconnectWallet() { + this.metamaskAddress = "" this.clearWallet() } }, @@ -212,6 +212,10 @@ export default { walletBalance() { this.getBalance(this.walletBalance) + }, + + metamaskWalletAddress() { + this.checkMetamaskBalance() } }, @@ -219,7 +223,8 @@ export default { this.polkadotAddress = this.wallet.address await this.fetchWalletBalance() - await this.checkMetamaskAddress() + + if (this.metamaskWalletAddress) await this.checkMetamaskBalance() } } diff --git a/src/components/WalletBinding.vue b/src/components/WalletBinding.vue index 6ecb344c..43c8e1ee 100644 --- a/src/components/WalletBinding.vue +++ b/src/components/WalletBinding.vue @@ -73,7 +73,7 @@
{{ account.name }} (...{{ account.lastAddr }})
-
{{ account.balance }} ETH
+
{{ account.balance }} DAI
mdi-check-bold @@ -102,7 +102,7 @@ {{ selectAccount.name }} (...{{ selectAccount.lastAddr }})
- {{ selectAccount.balance }} ETH + {{ selectAccount.balance }} DAI
@@ -158,7 +158,7 @@ /* eslint-disable */ import { mapState, mapMutations } from "vuex"; import { startApp } from "@/lib/metamask"; -import { getBalanceETH } from "@/lib/metamask/wallet.js"; +import { getBalanceETH, getBalanceDAI } from "@/lib/metamask/wallet.js"; import localStorage from "@/lib/local-storage" export default { @@ -223,7 +223,7 @@ export default { } else { this.accountList = []; for (let x = 0; x < this.ethAccount.accountList.length; x++) { - const balance = await getBalanceETH( + const balance = await getBalanceDAI( this.ethAccount.accountList[x] ); var lastAddr = this.ethAccount.accountList[x].substr( @@ -243,6 +243,7 @@ export default { active: isActive, }); } + this.putWallet = false; this.putAccount = true; } diff --git a/src/lib/metamask/wallet.js b/src/lib/metamask/wallet.js index 4b325ea0..f1180823 100644 --- a/src/lib/metamask/wallet.js +++ b/src/lib/metamask/wallet.js @@ -72,6 +72,16 @@ export async function getBalanceETH(address) { } } +export async function getBalanceDAI(address) { + const contractERC20Interface = store.getters["metamask/contracts/getERC20InterfaceContract"] + const web3 = store.getters["metamask/getWeb3"] + + let balance = await contractERC20Interface.methods.balanceOf(address).call() + let daiBalance = web3.utils.fromWei(balance, "ether") + + return daiBalance +} + export async function getBalanceUSDT() { const contractERC20Interface = store.getters["metamask/contracts/getERC20InterfaceContract"]; let balance = await contractERC20Interface.methods