Fixing provider state and wallet change listener, formatting balance

Co-authored-by: RcleydsonR <rafael.cleydson@gmail.com>
This commit is contained in:
brunoedcf
2022-11-16 17:15:56 -03:00
parent 85d76c9e42
commit d7f6294e6d
4 changed files with 52 additions and 34 deletions

View File

@@ -5,7 +5,7 @@ import ethers from "../utils/ethers";
const etherStore = useEtherStore();
const { walletAddress } = storeToRefs(etherStore);
const { walletAddress, balance } = storeToRefs(etherStore);
const connectMetaMask = () => {
ethers.connectProvider();
@@ -20,6 +20,13 @@ const formatWalletAddress = (): string => {
);
return `${initialText} ... ${finalText}`;
};
const formatWalletBalance = (): string => {
const formattedBalance = ethers.formatEther(balance.value);
const fixed = formattedBalance.substring(0, 8);
return fixed;
};
</script>
<template>
@@ -41,9 +48,12 @@ const formatWalletAddress = (): string => {
>
Conectar carteira
</button>
<span v-if="walletAddress" class="text-gray-50">
{{ formatWalletAddress() }}
</span>
<div v-if="walletAddress" class="flex gap-4">
<span class="text-gray-50">
{{ formatWalletAddress() }}
</span>
<span class="text-gray-50"> ETH: {{ formatWalletBalance() }} </span>
</div>
</div>
</header>
</template>