partial commit (will be removed)

This commit is contained in:
RcleydsonR 2022-12-28 20:24:41 -03:00
parent c6067fb4eb
commit 59c9eabd30
5 changed files with 92 additions and 58 deletions

View File

@ -6,16 +6,16 @@ import { ref, watch } from "vue";
const props = defineProps<{ const props = defineProps<{
walletTransactions: any[]; walletTransactions: any[];
isManageMode: boolean; isManageMode: boolean;
walletAddress?: string;
}>(); }>();
const itemsToShow = ref<any[]>([]); const itemsToShow = ref<any[]>([]);
itemsToShow.value =
props.walletTransactions?.length > 3
? props.walletTransactions.slice(0, 3)
: props.walletTransactions;
// Methods // Methods
const showInitialItems = (items: any[]) => {
return items.length > 3 ? items.slice(0, 3) : items;
};
const formatEventsAmount = (amount: any) => { const formatEventsAmount = (amount: any) => {
try { try {
const formated = blockchain.formatBigNumber(amount); const formated = blockchain.formatBigNumber(amount);
@ -41,15 +41,21 @@ const loadMore = () => {
// watch props changes // watch props changes
watch(props, (newProps) => { watch(props, (newProps) => {
const itemsToShowQty = itemsToShow.value.length const itemsToShowQty = itemsToShow.value.length;
itemsToShow.value = if (itemsToShowQty == 0)
newProps?.walletTransactions.length > itemsToShowQty + 3 itemsToShow.value = showInitialItems(props.walletTransactions);
? newProps.walletTransactions.slice(itemsToShowQty, itemsToShowQty + 3) else
: newProps.walletTransactions; itemsToShow.value =
}) newProps?.walletTransactions.length > itemsToShowQty
? newProps.walletTransactions.slice(0, itemsToShowQty)
: newProps.walletTransactions;
});
//emits //emits
const emit = defineEmits(["cancelDeposit", "withdrawDeposit"]); const emit = defineEmits(["cancelDeposit", "withdrawDeposit"]);
// initial itemToShow value
itemsToShow.value = showInitialItems(props.walletTransactions);
</script> </script>
<template> <template>
@ -77,11 +83,14 @@ const emit = defineEmits(["cancelDeposit", "withdrawDeposit"]);
:key="item?.blockNumber" :key="item?.blockNumber"
> >
<span class="last-release-info"> <span class="last-release-info">
{{ formatEventsAmount(item?.args ? item?.args.amount : item?.remaining) }} BRZ {{
item?.args ? formatEventsAmount(item?.args.amount) : item?.remaining
}}
BRZ
</span> </span>
<!-- TODO: change this hardcoded date --> <!-- TODO: change this hardcoded date -->
<span class="last-release-info"> 20 out 2022 </span> <span class="last-release-info"> 20 out 2022 </span>
<div <div
v-if="props.isManageMode" v-if="props.isManageMode"
@ -133,18 +142,12 @@ const emit = defineEmits(["cancelDeposit", "withdrawDeposit"]);
<img alt="Redirect image" src="@/assets/redirect.svg" /> <img alt="Redirect image" src="@/assets/redirect.svg" />
</div> </div>
</div> </div>
<div <div class="flex justify-center w-full mt-2" v-if="itemsToShow.length != 0">
class="flex justify-center w-full mt-2"
v-if="itemsToShow.length != 0"
>
<button type="button" class="text-white" @click="loadMore()"> <button type="button" class="text-white" @click="loadMore()">
Carregar mais Carregar mais
</button> </button>
</div> </div>
<span <span class="font-bold text-gray-900" v-if="itemsToShow.length == 0">
class="font-bold text-gray-900"
v-if="itemsToShow.length == 0"
>
Não nenhuma transação anterior Não nenhuma transação anterior
</span> </span>
</div> </div>

View File

@ -47,4 +47,14 @@ export const useEtherStore = defineStore("ether", {
this.locksExpiredList = locksExpiredList; this.locksExpiredList = locksExpiredList;
}, },
}, },
getters: {
getValidDepositByWalletAddress: (state) => {
return (walletAddress: string) =>
state.depositsValidList
.filter((deposit) => deposit.seller == walletAddress)
.sort((a, b) => {
return b.blockNumber - a.blockNumber;
});
},
},
}); });

View File

@ -13,6 +13,7 @@ import { wallets } from "./smart_contract_files/wallets.json";
const updateWalletStatus = async () => { const updateWalletStatus = async () => {
const etherStore = useEtherStore(); const etherStore = useEtherStore();
const provider = getProvider(); const provider = getProvider();
if (!provider) return; if (!provider) return;
const signer = provider.getSigner(); const signer = provider.getSigner();
@ -94,23 +95,19 @@ const listDepositTransactionByWalletAddress = async (
}; };
// get wallet's deposit transactions // get wallet's deposit transactions
// const listValidDepositTransactionsByWalletAddress = async ( const listValidDepositTransactionsByWalletAddress = async (
// walletAddress: string walletAddress: string
// ): Promise<any[]> => { ): Promise<any[]> => {
// const provider = getProvider(); const walletDeposits = await getValidDeposits();
// const etherStore = useEtherStore(); if (walletDeposits) {
// if (!provider) return []; return walletDeposits
.filter((deposit) => deposit.seller == String(walletAddress))
// const signer = provider.getSigner(); .sort((a, b) => {
// const p2pContract = new ethers.Contract(addresses.p2pix, p2pix.abi, signer); return b.blockNumber - a.blockNumber;
});
// const filterDeposits = p2pContract.filters.DepositAdded([walletAddress]); }
// const eventsDeposits = await p2pContract.queryFilter(filterDeposits); return [];
};
// console.log()
// };
// get wallet's lock transactions // get wallet's lock transactions
const listLockTransactionByWalletAddress = async ( const listLockTransactionByWalletAddress = async (
@ -150,9 +147,8 @@ const listReleaseTransactionByWalletAddress = async (
}); });
}; };
// Update events at store methods //get valid deposits
const updateValidDeposits = async () => { const getValidDeposits = async (): Promise<any[] | undefined> => {
const etherStore = useEtherStore();
const window_ = window as any; const window_ = window as any;
const connection = window_.ethereum; const connection = window_.ethereum;
let provider: ethers.providers.Web3Provider | null = null; let provider: ethers.providers.Web3Provider | null = null;
@ -170,17 +166,23 @@ const updateValidDeposits = async () => {
const mappedDeposit = await mapDeposits(deposit.args?.depositID); const mappedDeposit = await mapDeposits(deposit.args?.depositID);
const validDeposit = { const validDeposit = {
blockNumber: deposit.blockNumber,
depositID: deposit.args?.depositID, depositID: deposit.args?.depositID,
remaining: formatBigNumber(mappedDeposit.remaining), remaining: formatBigNumber(mappedDeposit.remaining),
seller: mappedDeposit.seller, seller: mappedDeposit.seller,
pixKey: mappedDeposit.pixTarget, pixKey: mappedDeposit.pixTarget,
}; };
if (mappedDeposit.valid) if (mappedDeposit.valid) depositList.push(validDeposit);
depositList.push(validDeposit);
}); });
etherStore.setDepositsValidList(depositList); return depositList;
};
// Update events at store methods
const updateValidDeposits = async () => {
const etherStore = useEtherStore();
const deposits = await getValidDeposits();
if (deposits) etherStore.setDepositsValidList(deposits);
}; };
const updateDepositAddedEvents = async () => { const updateDepositAddedEvents = async () => {
@ -240,10 +242,10 @@ const connectProvider = async () => {
const connection = window_.ethereum; const connection = window_.ethereum;
await updateWalletStatus(); await updateWalletStatus();
await updateValidDeposits();
await updateDepositAddedEvents(); await updateDepositAddedEvents();
await updateLockAddedEvents(); await updateLockAddedEvents();
await updateLockReleasedEvents(); await updateLockReleasedEvents();
await updateValidDeposits();
connection.on("accountsChanged", async () => { connection.on("accountsChanged", async () => {
await updateWalletStatus(); await updateWalletStatus();
@ -290,8 +292,8 @@ const addDeposit = async (tokenQty: Number, pixKey: string) => {
await deposit.wait(); await deposit.wait();
await updateWalletStatus(); await updateWalletStatus();
await updateDepositAddedEvents();
await updateValidDeposits(); await updateValidDeposits();
await updateDepositAddedEvents();
}; };
// cancel a deposit by its Id // cancel a deposit by its Id
@ -436,6 +438,7 @@ export default {
formatEther, formatEther,
updateWalletStatus, updateWalletStatus,
splitTokens, splitTokens,
listValidDepositTransactionsByWalletAddress,
listAllTransactionByWalletAddress, listAllTransactionByWalletAddress,
listReleaseTransactionByWalletAddress, listReleaseTransactionByWalletAddress,
listDepositTransactionByWalletAddress, listDepositTransactionByWalletAddress,
@ -450,4 +453,5 @@ export default {
releaseLock, releaseLock,
updateLockAddedEvents, updateLockAddedEvents,
updateValidDeposits, updateValidDeposits,
getValidDeposits,
}; };

View File

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

View File

@ -7,30 +7,47 @@ import type { BigNumber } from "ethers";
import { ref } from "vue"; import { ref } from "vue";
const etherStore = useEtherStore(); const etherStore = useEtherStore();
const { walletAddress, depositsValidList } = storeToRefs(etherStore); const { walletAddress } = storeToRefs(etherStore);
const depositList = ref<any[]>([]); const depositList = ref<any[]>([]);
const listValidDepositTransactionsByWalletAddress = (walletAddress: string, deposits: any[]) => {
depositList.value = deposits.filter((deposit) => deposit.seller === walletAddress)
}
const handleCancelDeposit = async (depositID: BigNumber) => { const handleCancelDeposit = async (depositID: BigNumber) => {
const response = await blockchain.cancelDeposit(depositID); const response = await blockchain.cancelDeposit(depositID);
if (response == true) console.log("Depósito cancelado com sucesso."); if (response == true) {
console.log("Depósito cancelado com sucesso.");
await blockchain
.listValidDepositTransactionsByWalletAddress(walletAddress.value)
.then((deposits) => {
if (deposits) depositList.value = deposits;
});
}
}; };
const handleWithDrawDeposit = async (depositID: BigNumber) => { const handleWithDrawDeposit = async (depositID: BigNumber) => {
const response = await blockchain.withdrawDeposit(depositID); const response = await blockchain.withdrawDeposit(depositID);
if (response == true) console.log("Token retirado com sucesso."); if (response == true) {
console.log("Token retirado com sucesso.");
await blockchain
.listValidDepositTransactionsByWalletAddress(walletAddress.value)
.then((deposits) => {
if (deposits) depositList.value = deposits;
});
}
}; };
if (walletAddress.value) { if (walletAddress.value) {
listValidDepositTransactionsByWalletAddress(walletAddress.value, depositsValidList.value) depositList.value = etherStore.getValidDepositByWalletAddress(
walletAddress.value
);
} }
etherStore.$subscribe((_mutation, state) => { etherStore.$subscribe(async (_mutation, state) => {
if(state.walletAddress != "") if (state.walletAddress != "" && state.depositsValidList.length > 0) {
listValidDepositTransactionsByWalletAddress(state.walletAddress, state.depositsValidList) await blockchain
.listValidDepositTransactionsByWalletAddress(walletAddress.value)
.then((deposits) => {
if (deposits) depositList.value = deposits;
});
}
}); });
</script> </script>