Refactor methods from blockchain to use new code structure
Co-authored-by: brunoedcf <brest.dallacosta@outlook.com>
This commit is contained in:
@@ -8,6 +8,8 @@ import { ref } from "vue";
|
||||
import { useEtherStore } from "@/store/ether";
|
||||
import QrCodeComponent from "../components/QrCodeComponent.vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { addLock, releaseLock } from "@/blockchain/methods";
|
||||
import { updateWalletStatus } from "@/blockchain/wallet";
|
||||
|
||||
enum Step {
|
||||
Search,
|
||||
@@ -40,10 +42,9 @@ const confirmBuyClick = async ({ selectedDeposit, tokenValue }: any) => {
|
||||
flowStep.value = Step.Buy;
|
||||
etherStore.setLoadingLock(true);
|
||||
|
||||
await blockchain
|
||||
.addLock(depositId, tokenValue)
|
||||
await addLock(depositId, tokenValue)
|
||||
.then((lock) => {
|
||||
lockTransactionHash.value = lock.hash;
|
||||
lockTransactionHash.value = lock.transactionHash;
|
||||
})
|
||||
.catch(() => {
|
||||
flowStep.value = Step.Search;
|
||||
@@ -66,7 +67,7 @@ const releaseTransaction = async ({ e2eId }: any) => {
|
||||
});
|
||||
|
||||
if (findLock && tokenAmount.value) {
|
||||
const release = await blockchain.releaseLock(
|
||||
const release = await releaseLock(
|
||||
pixTarget.value,
|
||||
tokenAmount.value,
|
||||
e2eId,
|
||||
@@ -81,7 +82,7 @@ const releaseTransaction = async ({ e2eId }: any) => {
|
||||
lastWalletReleaseTransactions.value = releaseTransactions;
|
||||
});
|
||||
|
||||
await blockchain.updateWalletStatus();
|
||||
await updateWalletStatus();
|
||||
loadingRelease.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import blockchain from "../utils/blockchain";
|
||||
import ListingComponent from "@/components/ListingComponent.vue";
|
||||
import type { BigNumber } from "ethers";
|
||||
import { ref, watch } from "vue";
|
||||
import { cancelDeposit, withdrawDeposit } from "@/blockchain/methods";
|
||||
|
||||
const etherStore = useEtherStore();
|
||||
|
||||
@@ -22,7 +23,7 @@ if (walletAddress.value) {
|
||||
}
|
||||
|
||||
const handleCancelDeposit = async (depositID: BigNumber, index: number) => {
|
||||
const response = await blockchain.cancelDeposit(depositID);
|
||||
const response = await cancelDeposit(depositID);
|
||||
if (response == true) {
|
||||
console.log("Depósito cancelado com sucesso.");
|
||||
depositList.value.splice(index, 1);
|
||||
@@ -30,7 +31,7 @@ const handleCancelDeposit = async (depositID: BigNumber, index: number) => {
|
||||
};
|
||||
|
||||
const handleWithDrawDeposit = async (depositID: BigNumber, index: number) => {
|
||||
const response = await blockchain.withdrawDeposit(depositID);
|
||||
const response = await withdrawDeposit(depositID);
|
||||
if (response == true) {
|
||||
console.log("Token retirado com sucesso.");
|
||||
depositList.value.splice(index, 1);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { formatEther } from "@ethersproject/units";
|
||||
import type { BigNumber } from "ethers";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { ref } from "vue";
|
||||
@@ -89,7 +90,7 @@ const mapLock = (lockId: string) => {
|
||||
@click="mapDeposit(deposit.args.depositID)"
|
||||
>
|
||||
Seller:<br />{{ formatWalletAddress(deposit.args.seller) }}<br />
|
||||
MRBZ: {{ blockchain.formatBigNumber(deposit.args.amount) }}
|
||||
MRBZ: {{ formatEther(deposit.args.amount) }}
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="flex flex-col justify-center items-center gap-4">
|
||||
@@ -100,7 +101,7 @@ const mapLock = (lockId: string) => {
|
||||
@click="mapLock(lock.args.lockID)"
|
||||
>
|
||||
Buyer:<br />{{ formatWalletAddress(lock.args.buyer) }}<br />
|
||||
MRBZ: {{ blockchain.formatBigNumber(lock.args.amount) }}
|
||||
MRBZ: {{ formatEther(lock.args.amount) }}
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="flex flex-col justify-center items-center gap-4">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import WantSellComponent from "../components/SellerSteps/WantSellComponent.vue";
|
||||
import SendNetwork from "../components/SellerSteps/SendNetwork.vue";
|
||||
import ValidationComponent from "../components/LoadingComponent.vue";
|
||||
import blockchain from "../utils/blockchain";
|
||||
import { approveTokens, addDeposit } from "../blockchain/methods";
|
||||
|
||||
import { ref } from "vue";
|
||||
import { useEtherStore } from "@/store/ether";
|
||||
@@ -28,10 +28,11 @@ const approveOffer = async ({ offer, pixKey }: any) => {
|
||||
try {
|
||||
offerValue.value = offer;
|
||||
pixKeyBuyer.value = pixKey;
|
||||
await blockchain.approveTokens(Number(offerValue.value));
|
||||
await approveTokens(String(offerValue.value));
|
||||
flowStep.value = Step.Network;
|
||||
loading.value = false;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
flowStep.value = Step.Sell;
|
||||
loading.value = false;
|
||||
}
|
||||
@@ -41,7 +42,7 @@ const sendNetwork = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
if (offerValue.value && pixKeyBuyer.value) {
|
||||
await blockchain.addDeposit(offerValue.value, pixKeyBuyer.value);
|
||||
await addDeposit(String(offerValue.value), pixKeyBuyer.value);
|
||||
flowStep.value = Step.Sell;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user