Clean up ether store

Co-authored-by: brunoedcf <brest.dallacosta@outlook.com>
This commit is contained in:
RcleydsonR 2023-01-19 19:42:57 -03:00
parent 2b61625e1e
commit d7723ebf07
7 changed files with 41 additions and 75 deletions

View File

@ -60,8 +60,7 @@ const getValidDeposits = async (
const eventsDeposits = await p2pContract.queryFilter(filterDeposits);
const depositList = await Promise.all(
eventsDeposits
.map(async (deposit) => {
eventsDeposits.map(async (deposit) => {
const mappedDeposit = await p2pContract.mapDeposits(
deposit.args?.depositID
);

View File

@ -19,7 +19,7 @@ const handleInputEvent = (event: any): void => {
tokenValue.value = Number(value);
if (decimalCount(tokenValue.value) > 2) {
if (decimalCount(String(tokenValue.value)) > 2) {
validDecimals.value = false;
enableSelectButton.value = false;
return;

View File

@ -35,7 +35,10 @@ const handleInputEvent = (event: any): void => {
validDecimals.value = true;
};
const handleButtonClick = async (offer: string, pixKey: string): Promise<void> => {
const handleButtonClick = async (
offer: string,
pixKey: string
): Promise<void> => {
if (walletAddress.value) emit("approveTokens", { offer, pixKey });
else await connectProvider();
};

View File

@ -10,7 +10,7 @@ import polygonImage from "../assets/polygon.svg";
// Store reference
const etherStore = useEtherStore();
const { walletAddress, balance, sellerView } = storeToRefs(etherStore);
const { walletAddress, sellerView } = storeToRefs(etherStore);
const menuOpenToggle = ref<boolean>(false);
const menuHoverToggle = ref<boolean>(false);
@ -33,11 +33,6 @@ const formatWalletAddress = (): string => {
return `${initialText}...${finalText}`;
};
const formatWalletBalance = (): string => {
const fixed = Number(balance.value);
return fixed.toFixed(2);
};
const disconnectUser = (): void => {
etherStore.setWalletAddress("");
closeMenu();

View File

@ -1,6 +1,5 @@
import { NetworkEnum } from "@/model/NetworkEnum";
import type { ValidDeposit } from "@/model/ValidDeposit";
import type { Event } from "ethers";
import { defineStore } from "pinia";
export const useEtherStore = defineStore("ether", {
@ -9,23 +8,11 @@ export const useEtherStore = defineStore("ether", {
balance: "",
networkName: NetworkEnum.ethereum,
loadingLock: false,
loadingWalletTransactionHistory: false,
loadingWalletBids: false,
sellerView: false,
// Depósitos válidos para compra GOERLI
depositsValidListGoerli: [] as ValidDeposit[],
// Depósitos válidos para compra MUMBAI
depositsValidListMumbai: [] as ValidDeposit[],
// Depósitos adicionados na blockchain
depositsAddedList: [] as Event[],
// Depósitos expirados na blockchain
depositsExpiredList: [] as Event[],
// Locks adicionados na blockchain
locksAddedList: [] as Event[],
// Locks 'released' na blockchain
locksReleasedList: [] as Event[],
// Locks expirados na blockchain
locksExpiredList: [] as Event[],
}),
actions: {
setWalletAddress(walletAddress: string) {
@ -43,33 +30,12 @@ export const useEtherStore = defineStore("ether", {
setSellerView(sellerView: boolean) {
this.sellerView = sellerView;
},
setLoadingWalletTransactionHistory(loadingWalletTransactionHistory: boolean) {
this.loadingWalletTransactionHistory = loadingWalletTransactionHistory;
},
setLoadingWalletBids(loadingWalletBids: boolean) {
this.loadingWalletBids = loadingWalletBids;
},
setDepositsValidListGoerli(depositsValidList: ValidDeposit[]) {
this.depositsValidListGoerli = depositsValidList;
},
setDepositsValidListMumbai(depositsValidList: ValidDeposit[]) {
this.depositsValidListMumbai = depositsValidList;
},
setDepositsAddedList(depositsAddedList: Event[]) {
this.depositsAddedList = depositsAddedList;
},
setDepositsExpiredList(depositsExpiredList: Event[]) {
this.depositsExpiredList = depositsExpiredList;
},
setLocksAddedList(locksAddedList: Event[]) {
this.locksAddedList = locksAddedList;
},
setLocksReleasedList(locksReleasedList: Event[]) {
this.locksReleasedList = locksReleasedList;
},
setLocksExpiredList(locksExpiredList: Event[]) {
this.locksExpiredList = locksExpiredList;
},
},
// Alterar para integrar com mumbai
getters: {

View File

@ -10,7 +10,7 @@ import type { ValidDeposit } from "@/model/ValidDeposit";
const etherStore = useEtherStore();
const { walletAddress, networkName, loadingWalletBids } = storeToRefs(etherStore);
const { walletAddress, networkName } = storeToRefs(etherStore);
const depositList = ref<ValidDeposit[]>([]);
onMounted(async () => {
@ -21,7 +21,8 @@ onMounted(async () => {
if (walletDeposits) {
depositList.value = walletDeposits;
}
}})
}
});
const handleCancelDeposit = async (depositID: BigNumber, index: number) => {
const response = await cancelDeposit(depositID);
@ -49,9 +50,11 @@ watch(walletAddress, async () => {
});
watch(networkName, async () => {
await listValidDepositTransactionsByWalletAddress(walletAddress.value).then((res) => {
await listValidDepositTransactionsByWalletAddress(walletAddress.value).then(
(res) => {
if (res) depositList.value = res;
});
}
);
});
</script>

View File

@ -17,7 +17,7 @@ onMounted(async () => {
if (res) allUserTransactions.value = res;
});
}
})
});
watch(walletAddress, async (newValue) => {
await listAllTransactionByWalletAddress(newValue).then((res) => {