implement logic to await all validDeposits correctly and improve state rendering from listing component

This commit is contained in:
RcleydsonR
2022-12-30 02:03:23 -03:00
parent 59c9eabd30
commit 6279acc20d
4 changed files with 94 additions and 65 deletions

View File

@@ -10,9 +10,9 @@ const { walletAddress } = storeToRefs(etherStore);
const allUserTransactions = ref<any[]>([]);
watch(walletAddress, async (newValue) => {
await blockchain
.listAllTransactionByWalletAddress(newValue)
.then((res) => {if(res) (allUserTransactions.value = res)});
await blockchain.listAllTransactionByWalletAddress(newValue).then((res) => {
if (res) allUserTransactions.value = res;
});
});
watch(walletAddress, async (newValue) => {

View File

@@ -4,49 +4,45 @@ import { storeToRefs } from "pinia";
import blockchain from "../utils/blockchain";
import ListingComponent from "@/components/ListingComponent.vue";
import type { BigNumber } from "ethers";
import { ref } from "vue";
import { ref, watch } from "vue";
const etherStore = useEtherStore();
const { walletAddress } = storeToRefs(etherStore);
const depositList = ref<any[]>([]);
const handleCancelDeposit = async (depositID: BigNumber) => {
const handleCancelDeposit = async (depositID: BigNumber, index: number) => {
const response = await blockchain.cancelDeposit(depositID);
if (response == true) {
console.log("Depósito cancelado com sucesso.");
await blockchain
.listValidDepositTransactionsByWalletAddress(walletAddress.value)
.then((deposits) => {
if (deposits) depositList.value = deposits;
});
depositList.value.splice(index, 1);
}
};
const handleWithDrawDeposit = async (depositID: BigNumber) => {
const handleWithDrawDeposit = async (depositID: BigNumber, index: number) => {
const response = await blockchain.withdrawDeposit(depositID);
if (response == true) {
console.log("Token retirado com sucesso.");
await blockchain
.listValidDepositTransactionsByWalletAddress(walletAddress.value)
.then((deposits) => {
if (deposits) depositList.value = deposits;
});
depositList.value.splice(index, 1);
}
};
if (walletAddress.value) {
depositList.value = etherStore.getValidDepositByWalletAddress(
walletAddress.value
);
const walletDeposits =
await blockchain.listValidDepositTransactionsByWalletAddress(
walletAddress.value
);
if (walletDeposits) {
depositList.value = walletDeposits;
}
}
etherStore.$subscribe(async (_mutation, state) => {
if (state.walletAddress != "" && state.depositsValidList.length > 0) {
await blockchain
.listValidDepositTransactionsByWalletAddress(walletAddress.value)
.then((deposits) => {
if (deposits) depositList.value = deposits;
});
watch(walletAddress, async () => {
const walletDeposits =
await blockchain.listValidDepositTransactionsByWalletAddress(
walletAddress.value
);
if (walletDeposits) {
depositList.value = walletDeposits;
}
});
</script>