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; return cancel;
}; };
const withdrawDeposit = async (depositId: BigNumber): Promise<any> => { const withdrawDeposit = async (
depositId: BigNumber,
amount: string
): Promise<any> => {
const contract = getContract(); const contract = getContract();
const withdraw = await contract.withdraw(depositId, []); const withdraw = await contract.withdraw(depositId, amount, []);
await withdraw.wait(); await withdraw.wait();
return withdraw; 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 ( const listValidDepositTransactionsByWalletAddress = async (
walletAddress: string walletAddress: string
): Promise<ValidDeposit[]> => { ): Promise<ValidDeposit[]> => {
const walletDeposits = await getValidDeposits(); const walletDeposits = await getValidDeposits(getTokenAddress());
if (walletDeposits) { if (walletDeposits) {
return walletDeposits return walletDeposits

View File

@ -20,7 +20,7 @@ const itemsToShow = ref<(Event | ValidDeposit)[]>([]);
const isValidDeposit = ( const isValidDeposit = (
deposit: Event | ValidDeposit deposit: Event | ValidDeposit
): deposit is ValidDeposit => { ): deposit is ValidDeposit => {
return (deposit as ValidDeposit).depositID !== undefined; return (deposit as ValidDeposit).token !== undefined;
}; };
const showInitialItems = (): void => { const showInitialItems = (): void => {
@ -72,7 +72,7 @@ watch(props, async (): Promise<void> => {
}); });
//emits //emits
const emit = defineEmits(["cancelDeposit", "withdrawDeposit"]); const emit = defineEmits(["withdrawDeposit"]);
// initial itemsToShow value // initial itemsToShow value
showInitialItems(); showInitialItems();
@ -83,6 +83,7 @@ showInitialItems();
<div <div
class="grid grid-cols-4 grid-flow-row w-full px-6" class="grid grid-cols-4 grid-flow-row w-full px-6"
v-if="itemsToShow.length != 0" 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" <span class="text-xs text-gray-50 font-medium justify-self-center"
>Valor</span >Valor</span
@ -90,15 +91,19 @@ showInitialItems();
<span class="text-xs text-gray-50 font-medium justify-self-center" <span class="text-xs text-gray-50 font-medium justify-self-center"
>Data</span >Data</span
> >
<span class="text-xs text-gray-50 font-medium justify-self-center">{{ <span
props.isManageMode ? "Cancelar oferta" : "Tipo de transação" v-if="!props.isManageMode"
}}</span> 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">{{ <span class="text-xs text-gray-50 font-medium justify-self-center">{{
props.isManageMode ? "Retirar tokens" : "Checar transação" props.isManageMode ? "Retirar tokens" : "Checar transação"
}}</span> }}</span>
</div> </div>
<div <div
class="grid grid-cols-4 grid-flow-row w-full bg-white px-6 py-4 rounded-lg" 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" v-for="(item, index) in itemsToShow"
:key="item.blockNumber" :key="item.blockNumber"
> >
@ -129,18 +134,7 @@ showInitialItems();
<div <div
v-if="props.isManageMode" v-if="props.isManageMode"
class="flex gap-2 cursor-pointer items-center justify-self-center" class="flex gap-2 cursor-pointer items-center justify-self-center"
@click="emit('cancelDeposit', (item as ValidDeposit).depositID, index)" @click="emit('withdrawDeposit', (item as ValidDeposit).token, 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)
"
> >
<span class="last-release-info">Retirar</span> <span class="last-release-info">Retirar</span>
<img alt="Withdraw image" src="@/assets/withdraw.svg" /> <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 ListingComponent from "@/components/ListingComponent/ListingComponent.vue";
import type { BigNumber } from "ethers"; import type { BigNumber } from "ethers";
import { ref, watch, onMounted } from "vue"; import { ref, watch, onMounted } from "vue";
import { cancelDeposit, withdrawDeposit } from "@/blockchain/buyerMethods"; import { withdrawDeposit } from "@/blockchain/buyerMethods";
import { listValidDepositTransactionsByWalletAddress } from "@/blockchain/wallet"; import { listValidDepositTransactionsByWalletAddress } from "@/blockchain/wallet";
import type { ValidDeposit } from "@/model/ValidDeposit"; import type { ValidDeposit } from "@/model/ValidDeposit";
@ -24,16 +24,9 @@ onMounted(async () => {
} }
}); });
const handleCancelDeposit = async (depositID: BigNumber, index: number) => { const handleWithDrawDeposit = async (token: BigNumber, index: number) => {
const response = await cancelDeposit(depositID); const fixedAmount = "1"; // Need to ask user for amount
if (response) { const response = await withdrawDeposit(token, fixedAmount);
console.log("Depósito cancelado com sucesso.");
depositList.value.splice(index, 1);
}
};
const handleWithDrawDeposit = async (depositID: BigNumber, index: number) => {
const response = await withdrawDeposit(depositID);
if (response) { if (response) {
console.log("Token retirado com sucesso."); console.log("Token retirado com sucesso.");
depositList.value.splice(index, 1); depositList.value.splice(index, 1);
@ -68,7 +61,6 @@ watch(networkName, async () => {
<ListingComponent <ListingComponent
:wallet-transactions="depositList" :wallet-transactions="depositList"
:is-manage-mode="true" :is-manage-mode="true"
@cancel-deposit="handleCancelDeposit"
@withdraw-deposit="handleWithDrawDeposit" @withdraw-deposit="handleWithDrawDeposit"
></ListingComponent> ></ListingComponent>
</div> </div>