Adjust withdraw function and listing valid deposits by wallet address, also remove cancel deposit option and use a fixed amount to withdraw while there isn't a input to inform it

This commit is contained in:
RcleydsonR 2023-02-01 23:49:13 -03:00
parent 11499661ea
commit 3340155a3d
5 changed files with 23 additions and 33 deletions

View File

@ -84,10 +84,13 @@ const cancelDeposit = async (depositId: BigNumber): Promise<any> => {
return cancel;
};
const withdrawDeposit = async (depositId: BigNumber): Promise<any> => {
const withdrawDeposit = async (
depositId: BigNumber,
amount: string
): Promise<any> => {
const contract = getContract();
const withdraw = await contract.withdraw(depositId, []);
const withdraw = await contract.withdraw(depositId, amount, []);
await withdraw.wait();
return withdraw;

View File

@ -92,7 +92,8 @@ const getValidDeposits = async (
};
}
if (validDeposit) depositList[deposit.args?.seller + token] = validDeposit;
if (validDeposit)
depositList[deposit.args?.seller + token] = validDeposit;
})
);

View File

@ -35,7 +35,7 @@ const updateWalletStatus = async (): Promise<void> => {
const listValidDepositTransactionsByWalletAddress = async (
walletAddress: string
): Promise<ValidDeposit[]> => {
const walletDeposits = await getValidDeposits();
const walletDeposits = await getValidDeposits(getTokenAddress());
if (walletDeposits) {
return walletDeposits

View File

@ -20,7 +20,7 @@ const itemsToShow = ref<(Event | ValidDeposit)[]>([]);
const isValidDeposit = (
deposit: Event | ValidDeposit
): deposit is ValidDeposit => {
return (deposit as ValidDeposit).depositID !== undefined;
return (deposit as ValidDeposit).token !== undefined;
};
const showInitialItems = (): void => {
@ -72,7 +72,7 @@ watch(props, async (): Promise<void> => {
});
//emits
const emit = defineEmits(["cancelDeposit", "withdrawDeposit"]);
const emit = defineEmits(["withdrawDeposit"]);
// initial itemsToShow value
showInitialItems();
@ -83,6 +83,7 @@ showInitialItems();
<div
class="grid grid-cols-4 grid-flow-row w-full px-6"
v-if="itemsToShow.length != 0"
v-bind:class="{ 'grid-cols-3': props.isManageMode }"
>
<span class="text-xs text-gray-50 font-medium justify-self-center"
>Valor</span
@ -90,15 +91,19 @@ showInitialItems();
<span class="text-xs text-gray-50 font-medium justify-self-center"
>Data</span
>
<span class="text-xs text-gray-50 font-medium justify-self-center">{{
props.isManageMode ? "Cancelar oferta" : "Tipo de transação"
}}</span>
<span
v-if="!props.isManageMode"
class="text-xs text-gray-50 font-medium justify-self-center"
>
"Tipo de transação"
</span>
<span class="text-xs text-gray-50 font-medium justify-self-center">{{
props.isManageMode ? "Retirar tokens" : "Checar transação"
}}</span>
</div>
<div
class="grid grid-cols-4 grid-flow-row w-full bg-white px-6 py-4 rounded-lg"
v-bind:class="{ 'grid-cols-3': props.isManageMode }"
v-for="(item, index) in itemsToShow"
:key="item.blockNumber"
>
@ -129,18 +134,7 @@ showInitialItems();
<div
v-if="props.isManageMode"
class="flex gap-2 cursor-pointer items-center justify-self-center"
@click="emit('cancelDeposit', (item as ValidDeposit).depositID, index)"
>
<span class="last-release-info">Cancelar</span>
<img alt="Cancel image" src="@/assets/cancel.svg" />
</div>
<div
v-if="props.isManageMode"
class="flex gap-2 cursor-pointer items-center justify-self-center"
@click="
emit('withdrawDeposit', (item as ValidDeposit).depositID, index)
"
@click="emit('withdrawDeposit', (item as ValidDeposit).token, index)"
>
<span class="last-release-info">Retirar</span>
<img alt="Withdraw image" src="@/assets/withdraw.svg" />

View File

@ -4,7 +4,7 @@ import { storeToRefs } from "pinia";
import ListingComponent from "@/components/ListingComponent/ListingComponent.vue";
import type { BigNumber } from "ethers";
import { ref, watch, onMounted } from "vue";
import { cancelDeposit, withdrawDeposit } from "@/blockchain/buyerMethods";
import { withdrawDeposit } from "@/blockchain/buyerMethods";
import { listValidDepositTransactionsByWalletAddress } from "@/blockchain/wallet";
import type { ValidDeposit } from "@/model/ValidDeposit";
@ -24,16 +24,9 @@ onMounted(async () => {
}
});
const handleCancelDeposit = async (depositID: BigNumber, index: number) => {
const response = await cancelDeposit(depositID);
if (response) {
console.log("Depósito cancelado com sucesso.");
depositList.value.splice(index, 1);
}
};
const handleWithDrawDeposit = async (depositID: BigNumber, index: number) => {
const response = await withdrawDeposit(depositID);
const handleWithDrawDeposit = async (token: BigNumber, index: number) => {
const fixedAmount = "1"; // Need to ask user for amount
const response = await withdrawDeposit(token, fixedAmount);
if (response) {
console.log("Token retirado com sucesso.");
depositList.value.splice(index, 1);
@ -68,7 +61,6 @@ watch(networkName, async () => {
<ListingComponent
:wallet-transactions="depositList"
:is-manage-mode="true"
@cancel-deposit="handleCancelDeposit"
@withdraw-deposit="handleWithDrawDeposit"
></ListingComponent>
</div>